Add failed try
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
import { Logger } from "../../../libs/logger";
|
||||
import { Path } from "../../../libs/path";
|
||||
import { sysfs, sysfs_mkdir, sysfs_writeFile } from "../../filesystem/sysfs";
|
||||
|
||||
export function kdriver_dev_pci_init() {}
|
||||
export function kdriver_dev_pci_init() {
|
||||
sysfs_mkdir("/pci");
|
||||
}
|
||||
|
||||
export function kdriver_dev_pci_detectDevices() {
|
||||
Logger.log("[PCI] Scanning...");
|
||||
@@ -51,6 +55,15 @@ export function kdriver_dev_pci_checkDevice(
|
||||
subclass.toString(16) +
|
||||
")"
|
||||
);
|
||||
|
||||
const dirname = Path.join("/pci", filename);
|
||||
|
||||
sysfs_mkdir(dirname);
|
||||
sysfs_writeFile(Path.join(dirname, "vendor"), "Intel");
|
||||
/*sysfs_writeFile(Path.join(dirname, "vendor"), vendorId.toString(16));
|
||||
sysfs_writeFile(Path.join(dirname, "device"), deviceId.toString(16));
|
||||
sysfs_writeFile(Path.join(dirname, "class"), classCode.toString(16));
|
||||
sysfs_writeFile(Path.join(dirname, "subclass"), subclass.toString(16));*/
|
||||
}
|
||||
|
||||
export function kdriver_dev_pci_getDeviceId(
|
||||
|
||||
106
os/src/kernel/filesystem/sysfs.ts
Normal file
106
os/src/kernel/filesystem/sysfs.ts
Normal file
@@ -0,0 +1,106 @@
|
||||
import { Logger } from "../../libs/logger";
|
||||
import { Path } from "../../libs/path";
|
||||
import {
|
||||
FilesystemType,
|
||||
type Filesystem,
|
||||
type FilesystemEntity,
|
||||
} from "../../types/kernel/filesystem";
|
||||
|
||||
const sysfs_data: FilesystemEntity[] = [];
|
||||
|
||||
export function sysfs(): Filesystem {
|
||||
return {
|
||||
type: FilesystemType.SYSFS,
|
||||
mkdir: sysfs_mkdir,
|
||||
ls: sysfs_ls,
|
||||
writeFile(path, content) {
|
||||
throw new Error("Cannot write to sysfs");
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function sysfs_root(): FilesystemEntity {
|
||||
/*return {
|
||||
name: "$root",
|
||||
path: "/",
|
||||
size: 0,
|
||||
isDirectory: true,
|
||||
contents: null,
|
||||
};*/
|
||||
}
|
||||
|
||||
export function sysfs_get(path: string): FilesystemEntity | null {
|
||||
if (path == "" || path == "/") return sysfs_root();
|
||||
|
||||
for (let i = 0; i < sysfs_data.length; i++) {
|
||||
Logger.log(sysfs_data[i]);
|
||||
|
||||
if (sysfs_data[i]!.path === path) {
|
||||
return sysfs_data[i]!;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export function sysfs_mkdir(path: string) {
|
||||
if (sysfs_get(path)) return;
|
||||
|
||||
const parent = sysfs_get(Path.dirname(path));
|
||||
if (!parent || !parent.isDirectory) return;
|
||||
|
||||
Logger.log(path);
|
||||
|
||||
/*sysfs_data.push({
|
||||
name: Path.filename(path),
|
||||
path: path,
|
||||
size: 0,
|
||||
isDirectory: true,
|
||||
contents: 0,
|
||||
});*/
|
||||
}
|
||||
|
||||
export function sysfs_ls(path: string): FilesystemEntity[] | null {
|
||||
/*const entity = sysfs_get(path);
|
||||
if (!entity || !entity.isDirectory) return null;
|
||||
|
||||
const result: FilesystemEntity[] = [];
|
||||
const prefix = path + "/";
|
||||
|
||||
for (let i = 0; i < globalThis.sysfs_data.length; i++) {
|
||||
const itemPath = globalThis.sysfs_data[i]!.path;
|
||||
|
||||
// Only include direct children (no additional slashes after the prefix)
|
||||
if (
|
||||
itemPath.startsWith(prefix) &&
|
||||
!itemPath.substring(prefix.length).includes("/")
|
||||
) {
|
||||
result.push(globalThis.sysfs_data[i]!);
|
||||
}
|
||||
}
|
||||
|
||||
return result;*/
|
||||
}
|
||||
|
||||
export function sysfs_createFile(path: string, content: string) {
|
||||
if (sysfs_get(path)) return;
|
||||
|
||||
/*const parent = sysfs_getParent(path);
|
||||
if (!parent || !parent.isDirectory) return;
|
||||
|
||||
globalThis.sysfs_data.push({
|
||||
name: Path.filename(path),
|
||||
path: path,
|
||||
size: content.length,
|
||||
isDirectory: false,
|
||||
contents: content,
|
||||
});*/
|
||||
}
|
||||
|
||||
export function sysfs_writeFile(path: string, content: string) {
|
||||
const entity = sysfs_get(path);
|
||||
/*if (!entity) return sysfs_createFile(path, content);
|
||||
if (entity.isDirectory) return;
|
||||
|
||||
entity.contents = content;*/
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Logger } from "../libs/logger";
|
||||
import { kdriver_dev_pci_detectDevices } from "./drivers/dev/pci.kdriver";
|
||||
import { sysfs_ls } from "./filesystem/sysfs";
|
||||
import {
|
||||
kmod_console_clearScreen,
|
||||
kmod_console_outputString,
|
||||
@@ -15,5 +16,11 @@ export function kmain() {
|
||||
|
||||
kdriver_dev_pci_detectDevices();
|
||||
|
||||
/*const files = sysfs_ls("/");
|
||||
|
||||
files!.forEach(function (file) {
|
||||
Logger.log(file.name);
|
||||
});*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
12
os/src/libs/path.ts
Normal file
12
os/src/libs/path.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
export const Path = {
|
||||
join(p1: string, p2: string): string {
|
||||
if (p1.endsWith("/")) return p1 + p2;
|
||||
else return p1 + "/" + p2;
|
||||
},
|
||||
filename(path: string): string {
|
||||
return path.split("/").pop()!;
|
||||
},
|
||||
dirname(path: string): string {
|
||||
return path.split("/").slice(0, -1).join("/");
|
||||
},
|
||||
};
|
||||
18
os/src/types/kernel/filesystem.ts
Normal file
18
os/src/types/kernel/filesystem.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
export enum FilesystemType {
|
||||
SYSFS,
|
||||
}
|
||||
|
||||
export interface Filesystem {
|
||||
type: FilesystemType;
|
||||
mkdir(path: string): void;
|
||||
ls(path: string): FilesystemEntity[] | null;
|
||||
writeFile(path: string, content: string): void;
|
||||
}
|
||||
|
||||
export type FilesystemEntity = {
|
||||
name: string;
|
||||
path: string;
|
||||
size: number;
|
||||
isDirectory: boolean;
|
||||
contents: string | number | number[] | null;
|
||||
};
|
||||
Reference in New Issue
Block a user