@@ -159,12 +159,17 @@ export class OpenDirectory extends Fd {
159159 if ( cookie == 0n ) {
160160 return {
161161 ret : wasi . ERRNO_SUCCESS ,
162- dirent : new wasi . Dirent ( 1n , "." , wasi . FILETYPE_DIRECTORY ) ,
162+ dirent : new wasi . Dirent ( 1n , this . dir . ino , "." , wasi . FILETYPE_DIRECTORY ) ,
163163 } ;
164164 } else if ( cookie == 1n ) {
165165 return {
166166 ret : wasi . ERRNO_SUCCESS ,
167- dirent : new wasi . Dirent ( 2n , ".." , wasi . FILETYPE_DIRECTORY ) ,
167+ dirent : new wasi . Dirent (
168+ 2n ,
169+ this . dir . parent_ino ( ) ,
170+ ".." ,
171+ wasi . FILETYPE_DIRECTORY ,
172+ ) ,
168173 } ;
169174 }
170175
@@ -178,7 +183,12 @@ export class OpenDirectory extends Fd {
178183
179184 return {
180185 ret : 0 ,
181- dirent : new wasi . Dirent ( cookie + 1n , name , entry . stat ( ) . filetype ) ,
186+ dirent : new wasi . Dirent (
187+ cookie + 1n ,
188+ entry . ino ,
189+ name ,
190+ entry . stat ( ) . filetype ,
191+ ) ,
182192 } ;
183193 }
184194
@@ -501,7 +511,7 @@ export class File extends Inode {
501511 }
502512
503513 stat ( ) : wasi . Filestat {
504- return new wasi . Filestat ( wasi . FILETYPE_REGULAR_FILE , this . size ) ;
514+ return new wasi . Filestat ( this . ino , wasi . FILETYPE_REGULAR_FILE , this . size ) ;
505515 }
506516}
507517
@@ -547,6 +557,7 @@ class Path {
547557
548558export class Directory extends Inode {
549559 contents : Map < string , Inode > ;
560+ private parent : Directory | null = null ;
550561
551562 constructor ( contents : Map < string , Inode > | [ string , Inode ] [ ] ) {
552563 super ( ) ;
@@ -555,6 +566,19 @@ export class Directory extends Inode {
555566 } else {
556567 this . contents = contents ;
557568 }
569+
570+ for ( const entry of this . contents . values ( ) ) {
571+ if ( entry instanceof Directory ) {
572+ entry . parent = this ;
573+ }
574+ }
575+ }
576+
577+ parent_ino ( ) : bigint {
578+ if ( this . parent == null ) {
579+ return Inode . root_ino ( ) ;
580+ }
581+ return this . parent . ino ;
558582 }
559583
560584 // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -563,7 +587,7 @@ export class Directory extends Inode {
563587 }
564588
565589 stat ( ) : wasi . Filestat {
566- return new wasi . Filestat ( wasi . FILETYPE_DIRECTORY , 0n ) ;
590+ return new wasi . Filestat ( this . ino , wasi . FILETYPE_DIRECTORY , 0n ) ;
567591 }
568592
569593 get_entry_for_path ( path : Path ) : { ret : number ; entry : Inode | null } {
@@ -697,15 +721,18 @@ export class Directory extends Inode {
697721}
698722
699723export class ConsoleStdout extends Fd {
724+ private ino : bigint ;
700725 write : ( buffer : Uint8Array ) => void ;
701726
702727 constructor ( write : ( buffer : Uint8Array ) => void ) {
703728 super ( ) ;
729+ this . ino = Inode . issue_ino ( ) ;
704730 this . write = write ;
705731 }
706732
707733 fd_filestat_get ( ) : { ret : number ; filestat : wasi . Filestat } {
708734 const filestat = new wasi . Filestat (
735+ this . ino ,
709736 wasi . FILETYPE_CHARACTER_DEVICE ,
710737 BigInt ( 0 ) ,
711738 ) ;
0 commit comments