You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/syscalls.md
+76Lines changed: 76 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -381,3 +381,79 @@ Close an open socket.
381
381
382
382
File I/O and filesystem-related functionality. This subsystem is separated out from the general-purpose io subsystem for security reasons.
383
383
384
+
## file_open
385
+
386
+
```
387
+
u64 file_open(const char* path, u64 flags)
388
+
```
389
+
390
+
**Returns:**`u64 handle`
391
+
392
+
Open the file at the given path. The flags argument is a bitfield combining OPEN_READ, OPEN_WRITE, OPEN_CREATE and OPEN_TRUNC. All access is binary (byte-exact) with no newline translation. Returns a nonzero file handle on success, or 0 on failure (for example if the path is rejected by the sandbox or does not exist).
393
+
394
+
## file_close
395
+
396
+
```
397
+
void file_close(u64 handle)
398
+
```
399
+
400
+
Close a file handle previously returned by file_open. Has no effect if the handle is not open.
401
+
402
+
## file_read
403
+
404
+
```
405
+
i64 file_read(u64 handle, u8* buf, u64 num_bytes)
406
+
```
407
+
408
+
**Returns:**`i64 num_bytes`
409
+
410
+
Read up to num_bytes from the file into the buffer. Returns the number of bytes actually read, 0 at end of file, or -1 on error.
// Open the file at the given path. The flags argument is a bitfield combining OPEN_READ, OPEN_WRITE, OPEN_CREATE and OPEN_TRUNC. All access is binary (byte-exact) with no newline translation. Returns a nonzero file handle on success, or 0 on failure (for example if the path is rejected by the sandbox or does not exist).
Copy file name to clipboardExpand all lines: spec/syscalls.json
+160-2Lines changed: 160 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -918,7 +918,165 @@
918
918
{
919
919
"subsystem": "fs",
920
920
"description": "File I/O and filesystem-related functionality. This subsystem is separated out from the general-purpose io subsystem for security reasons.",
921
-
"syscalls": [],
922
-
"constants": []
921
+
"syscalls": [
922
+
{
923
+
"name": "file_open",
924
+
"args": [
925
+
[
926
+
"const char*",
927
+
"path"
928
+
],
929
+
[
930
+
"u64",
931
+
"flags"
932
+
]
933
+
],
934
+
"returns": [
935
+
"u64",
936
+
"handle"
937
+
],
938
+
"permission": "file_open",
939
+
"const_idx": 15,
940
+
"description": "Open the file at the given path. The flags argument is a bitfield combining OPEN_READ, OPEN_WRITE, OPEN_CREATE and OPEN_TRUNC. All access is binary (byte-exact) with no newline translation. Returns a nonzero file handle on success, or 0 on failure (for example if the path is rejected by the sandbox or does not exist)."
941
+
},
942
+
{
943
+
"name": "file_close",
944
+
"args": [
945
+
[
946
+
"u64",
947
+
"handle"
948
+
]
949
+
],
950
+
"returns": [
951
+
"void",
952
+
""
953
+
],
954
+
"permission": "file_io",
955
+
"const_idx": 19,
956
+
"description": "Close a file handle previously returned by file_open. Has no effect if the handle is not open."
957
+
},
958
+
{
959
+
"name": "file_read",
960
+
"args": [
961
+
[
962
+
"u64",
963
+
"handle"
964
+
],
965
+
[
966
+
"u8*",
967
+
"buf"
968
+
],
969
+
[
970
+
"u64",
971
+
"num_bytes"
972
+
]
973
+
],
974
+
"returns": [
975
+
"i64",
976
+
"num_bytes"
977
+
],
978
+
"permission": "file_io",
979
+
"const_idx": 32,
980
+
"description": "Read up to num_bytes from the file into the buffer. Returns the number of bytes actually read, 0 at end of file, or -1 on error."
981
+
},
982
+
{
983
+
"name": "file_write",
984
+
"args": [
985
+
[
986
+
"u64",
987
+
"handle"
988
+
],
989
+
[
990
+
"const u8*",
991
+
"buf"
992
+
],
993
+
[
994
+
"u64",
995
+
"num_bytes"
996
+
]
997
+
],
998
+
"returns": [
999
+
"i64",
1000
+
"num_bytes"
1001
+
],
1002
+
"permission": "file_io",
1003
+
"const_idx": 33,
1004
+
"description": "Write num_bytes from the buffer to the file. Returns the number of bytes actually written, or -1 on error."
1005
+
},
1006
+
{
1007
+
"name": "file_seek",
1008
+
"args": [
1009
+
[
1010
+
"u64",
1011
+
"handle"
1012
+
],
1013
+
[
1014
+
"u64",
1015
+
"pos"
1016
+
]
1017
+
],
1018
+
"returns": [
1019
+
"u64",
1020
+
"new_pos"
1021
+
],
1022
+
"permission": "file_io",
1023
+
"const_idx": 34,
1024
+
"description": "Seek to an absolute byte offset measured from the start of the file. Returns the new absolute position."
1025
+
},
1026
+
{
1027
+
"name": "file_tell",
1028
+
"args": [
1029
+
[
1030
+
"u64",
1031
+
"handle"
1032
+
]
1033
+
],
1034
+
"returns": [
1035
+
"u64",
1036
+
"pos"
1037
+
],
1038
+
"permission": "file_io",
1039
+
"const_idx": 35,
1040
+
"description": "Return the current absolute byte offset, measured from the start of the file."
1041
+
},
1042
+
{
1043
+
"name": "file_size",
1044
+
"args": [
1045
+
[
1046
+
"u64",
1047
+
"handle"
1048
+
]
1049
+
],
1050
+
"returns": [
1051
+
"u64",
1052
+
"num_bytes"
1053
+
],
1054
+
"permission": "file_io",
1055
+
"const_idx": 36,
1056
+
"description": "Return the total size of the file in bytes. Does not change the current file position."
0 commit comments