1- import { FileSystem , Sync } from '@zenfs/core' ;
1+ import { FileSystem , Inode , Sync } from '@zenfs/core' ;
22import type { InodeLike } from '@zenfs/core' ;
33import { withErrno } from 'kerium' ;
4- import { kobj_find , KObject } from '../kobject.js' ;
4+ import { kobj_find , KObject , sysfs_root } from '../kobject.js' ;
5+ import { S_IFDIR } from '@zenfs/core/constants' ;
56
67/**
78 * @todo
89 */
910export class SysFS extends Sync ( FileSystem ) {
1011 protected readonly initTime = Date . now ( ) ;
1112
13+ protected readonly _rootInode = new Inode ( { mode : S_IFDIR | 0o555 } ) ;
14+
1215 public constructor ( ) {
1316 super ( 0x62656572 , 'sysfs' ) ;
1417 }
@@ -21,6 +24,7 @@ export class SysFS extends Sync(FileSystem) {
2124 * @todo
2225 */
2326 statSync ( path : string ) : InodeLike {
27+ if ( path === '/' ) return this . _rootInode ;
2428 const node = kobj_find ( path ) ;
2529 if ( ! node ) throw withErrno ( 'ENOENT' ) ;
2630 throw withErrno ( 'ENOSYS' ) ;
@@ -50,6 +54,7 @@ export class SysFS extends Sync(FileSystem) {
5054 }
5155
5256 readdirSync ( path : string ) : string [ ] {
57+ if ( path === '/' ) return Array . from ( sysfs_root . keys ( ) ) ;
5358 const obj = kobj_find ( path ) ;
5459 if ( ! ( obj instanceof KObject ) ) throw withErrno ( 'ENOTDIR' ) ;
5560 return [ ...obj . children . keys ( ) , ...obj . attributes . keys ( ) ] ;
0 commit comments