2121
2222//Provides: caml_current_dir
2323var caml_current_dir = "/" ;
24+ //Provides: file_inode
25+ var file_inode = 0
2426
2527//Provides: MlDir
26- function MlDir ( ) { this . content = { } ; }
28+ //Requires: file_inode, unix_time
29+ function MlDir ( ) { this . content = { } ;
30+ this . inode = file_inode ++ ;
31+ var now = unix_time ( ) ;
32+ this . atime = now ;
33+ this . mtime = now ;
34+ this . ctime = now ;
35+ }
2736MlDir . prototype = {
2837 exists :function ( name ) { return this . content [ name ] ?1 :0 ; } ,
2938 mk :function ( name , c ) { this . content [ name ] = c } ,
@@ -38,10 +47,24 @@ MlDir.prototype = {
3847}
3948
4049//Provides: MlFile
41- //Requires: caml_create_string
42- function MlFile ( content ) { this . data = content }
50+ //Requires: caml_create_string, file_inode, unix_time
51+ function MlFile ( content ) { this . data = content ;
52+ this . inode = file_inode ++ ;
53+ var now = unix_time ( ) ;
54+ this . atime = now ;
55+ this . mtime = now ;
56+ this . ctime = now ;
57+ }
4358MlFile . prototype = {
44- truncate :function ( ) { this . data = caml_create_string ( 0 ) }
59+ truncate :function ( ) {
60+ this . data = caml_create_string ( 0 ) ;
61+ this . modified ( ) ;
62+ } ,
63+ modified :function ( ) {
64+ var now = unix_time ( ) ;
65+ this . atime = now ;
66+ this . mtime = now ;
67+ }
4568}
4669
4770//Provides: caml_root_dir
@@ -265,3 +288,49 @@ function caml_ba_map_file(vfd, kind, layout, shared, dims, pos) {
265288function caml_ba_map_file_bytecode ( argv , argn ) {
266289 return caml_ba_map_file ( argv [ 0 ] , argv [ 1 ] , argv [ 2 ] , argv [ 3 ] , argv [ 4 ] , argv [ 5 ] ) ;
267290}
291+
292+
293+ //Provides: unix_stat_file
294+ //Requires: caml_make_path, caml_fs_content, MlFile, MlDir,caml_ml_string_length
295+ function unix_stat_file ( f ) {
296+ if ( f instanceof MlDir ) {
297+ var kind = 1 ; //S_DIR
298+ var size = 0 ;
299+ }
300+ if ( f instanceof MlFile ) {
301+ var kind = 0 ; //S_REG
302+ var size = caml_ml_string_length ( f . data ) ;
303+ }
304+
305+ return [ 0 ,
306+ 0 , //st_dev
307+ f . inode , // st_ino
308+ kind , // st_kind
309+ 436 , //st_perm 0o664
310+ 1 , //st_nlink
311+ 1 , //st_uid
312+ 1 , //st_gid
313+ 0 , //st_rdev
314+ size , //st_size
315+ + f . atime ,
316+ + f . mtime ,
317+ + f . ctime
318+ ]
319+ }
320+
321+ //Provides: unix_stat
322+ //Requires: caml_fs_content, caml_make_path, unix_stat_file
323+ function unix_stat ( name ) {
324+ var f = caml_fs_content ( caml_make_path ( name ) ) ;
325+ return unix_stat_file ( f )
326+ }
327+
328+ //Provides: unix_lstat
329+ //Requires: unix_stat
330+ var unix_lstat = unix_stat
331+
332+ //Provides: unix_fstat
333+ //Requires: unix_stat_file, caml_global_data
334+ function unix_fstat ( idx ) {
335+ return unix_stat_file ( caml_global_data . fds [ idx ] . file )
336+ }
0 commit comments