@@ -686,7 +686,16 @@ pub unsafe extern "C" fn path_create_directory(
686
686
path_ptr : * const u8 ,
687
687
path_len : usize ,
688
688
) -> Errno {
689
- unreachable ( )
689
+ let path = slice:: from_raw_parts ( path_ptr, path_len) ;
690
+
691
+ match Descriptor :: get ( fd) {
692
+ Descriptor :: File ( file) => match wasi_filesystem:: create_directory_at ( file. fd , path) {
693
+ Ok ( ( ) ) => ERRNO_SUCCESS ,
694
+ Err ( err) => errno_from_wasi_filesystem ( err) ,
695
+ } ,
696
+ Descriptor :: Closed => ERRNO_BADF ,
697
+ Descriptor :: Log => ERRNO_NOTDIR ,
698
+ }
690
699
}
691
700
692
701
/// Return the attributes of a file or directory.
@@ -699,7 +708,42 @@ pub unsafe extern "C" fn path_filestat_get(
699
708
path_len : usize ,
700
709
buf : * mut Filestat ,
701
710
) -> Errno {
702
- unreachable ( )
711
+ let path = slice:: from_raw_parts ( path_ptr, path_len) ;
712
+ let at_flags = at_flags_from_lookupflags ( flags) ;
713
+
714
+ match Descriptor :: get ( fd) {
715
+ Descriptor :: File ( file) => match wasi_filesystem:: stat_at ( file. fd , at_flags, path) {
716
+ Ok ( stat) => {
717
+ let filetype = match stat. type_ {
718
+ wasi_filesystem:: Type :: Unknown => FILETYPE_UNKNOWN ,
719
+ wasi_filesystem:: Type :: Directory => FILETYPE_DIRECTORY ,
720
+ wasi_filesystem:: Type :: BlockDevice => FILETYPE_BLOCK_DEVICE ,
721
+ wasi_filesystem:: Type :: RegularFile => FILETYPE_REGULAR_FILE ,
722
+ // TODO: Add a way to disginguish between FILETYPE_SOCKET_STREAM and
723
+ // FILETYPE_SOCKET_DGRAM.
724
+ wasi_filesystem:: Type :: Socket => unreachable ( ) ,
725
+ wasi_filesystem:: Type :: SymbolicLink => FILETYPE_SYMBOLIC_LINK ,
726
+ wasi_filesystem:: Type :: CharacterDevice => FILETYPE_CHARACTER_DEVICE ,
727
+ // preview1 never had a FIFO code.
728
+ wasi_filesystem:: Type :: Fifo => FILETYPE_UNKNOWN ,
729
+ } ;
730
+ * buf = Filestat {
731
+ dev : stat. dev ,
732
+ ino : stat. ino ,
733
+ filetype,
734
+ nlink : stat. nlink ,
735
+ size : stat. size ,
736
+ atim : stat. atim ,
737
+ mtim : stat. mtim ,
738
+ ctim : stat. ctim ,
739
+ } ;
740
+ ERRNO_SUCCESS
741
+ }
742
+ Err ( err) => errno_from_wasi_filesystem ( err) ,
743
+ } ,
744
+ Descriptor :: Closed => ERRNO_BADF ,
745
+ Descriptor :: Log => ERRNO_NOTDIR ,
746
+ }
703
747
}
704
748
705
749
/// Adjust the timestamps of a file or directory.
@@ -741,8 +785,8 @@ pub unsafe extern "C" fn path_filestat_set_times(
741
785
Err ( err) => errno_from_wasi_filesystem ( err) ,
742
786
}
743
787
}
744
- Descriptor :: Log => ERRNO_SPIPE ,
745
788
Descriptor :: Closed => ERRNO_BADF ,
789
+ Descriptor :: Log => ERRNO_NOTDIR ,
746
790
}
747
791
}
748
792
@@ -758,7 +802,20 @@ pub unsafe extern "C" fn path_link(
758
802
new_path_ptr : * const u8 ,
759
803
new_path_len : usize ,
760
804
) -> Errno {
761
- unreachable ( )
805
+ let old_path = slice:: from_raw_parts ( old_path_ptr, old_path_len) ;
806
+ let new_path = slice:: from_raw_parts ( new_path_ptr, new_path_len) ;
807
+ let at_flags = at_flags_from_lookupflags ( old_flags) ;
808
+
809
+ match ( Descriptor :: get ( old_fd) , Descriptor :: get ( new_fd) ) {
810
+ ( Descriptor :: File ( old_file) , Descriptor :: File ( new_file) ) => {
811
+ match wasi_filesystem:: link_at ( old_file. fd , at_flags, old_path, new_file. fd , new_path) {
812
+ Ok ( ( ) ) => ERRNO_SUCCESS ,
813
+ Err ( err) => errno_from_wasi_filesystem ( err) ,
814
+ }
815
+ }
816
+ ( _, Descriptor :: Closed ) | ( Descriptor :: Closed , _) => ERRNO_BADF ,
817
+ _ => ERRNO_NOTDIR ,
818
+ }
762
819
}
763
820
764
821
/// Open a file or directory.
@@ -879,8 +936,8 @@ pub unsafe extern "C" fn path_remove_directory(
879
936
Ok ( ( ) ) => ERRNO_SUCCESS ,
880
937
Err ( err) => errno_from_wasi_filesystem ( err) ,
881
938
} ,
882
- Descriptor :: Log => ERRNO_SPIPE ,
883
939
Descriptor :: Closed => ERRNO_BADF ,
940
+ Descriptor :: Log => ERRNO_NOTDIR ,
884
941
}
885
942
}
886
943
0 commit comments