File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed
packages/wasi-preview1/src Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,21 @@ export function writeFilestat(
35
35
view . setBigUint64 ( 56 , ctim , true ) ;
36
36
}
37
37
38
+ export function writeFdstat (
39
+ memory : ArrayBuffer ,
40
+ ptr : number ,
41
+ filetype : number ,
42
+ fs_flags : number ,
43
+ fs_rights_base : bigint ,
44
+ fs_rights_inheriting : bigint
45
+ ) {
46
+ const view = new DataView ( memory , ptr , 24 ) ;
47
+ view . setUint8 ( 0 , filetype ) ;
48
+ view . setUint16 ( 2 , fs_flags , true ) ;
49
+ view . setBigUint64 ( 8 , fs_rights_base , true ) ;
50
+ view . setBigUint64 ( 16 , fs_rights_inheriting , true ) ;
51
+ }
52
+
38
53
export function generateOneReaddirEntry (
39
54
ent : DirEntry ,
40
55
index : number
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import * as error from "./error.js";
5
5
import {
6
6
generateOneReaddirEntry ,
7
7
getFiletypeOfStat ,
8
+ writeFdstat ,
8
9
writeFilestat ,
9
10
writePrestatDir ,
10
11
} from "./dataStructure.js" ;
@@ -304,7 +305,26 @@ export function initWASI(config: WASIConfig): WASIAPI & WASIMeta {
304
305
}
305
306
} ,
306
307
fd_fdstat_get : ( fd , ret_buf ) => {
307
- throw new Error ( "Function not implemented." ) ;
308
+ const fdObj = fs . get ( fd ) ;
309
+ if ( fdObj === undefined ) {
310
+ return error . badf ;
311
+ }
312
+ try {
313
+ const stat = fs . stat ( fdObj ) ;
314
+ // fd_write | path_create_directory | path_open | fd_readdir | path_filestat_get | fd_filestat_get
315
+ const fs_flags = 0b0001_0010_0011_0001_0010_0000n ;
316
+ writeFdstat (
317
+ memory ( ) ,
318
+ ret_buf ,
319
+ getFiletypeOfStat ( stat ) ,
320
+ 0 ,
321
+ fs_flags ,
322
+ fs_flags
323
+ ) ;
324
+ return 0 ;
325
+ } catch ( e ) {
326
+ return handleFsError ( e , debug ) ;
327
+ }
308
328
} ,
309
329
random_get : ( buf , buf_len ) : number => {
310
330
crypto . randomFillSync ( new Uint8Array ( memory ( ) , buf , buf_len ) ) ;
You can’t perform that action at this time.
0 commit comments