Implemented stat syscall
This commit is contained in:
27
lib/fs/fs.q
Normal file
27
lib/fs/fs.q
Normal file
@ -0,0 +1,27 @@
|
||||
import mem
|
||||
import sys
|
||||
|
||||
readFile(path []byte) -> (*byte, int) {
|
||||
stat := new(sys.file_stat)
|
||||
|
||||
if sys.stat(path, stat) < 0 {
|
||||
return 0, 0
|
||||
}
|
||||
|
||||
size := stat.st_size
|
||||
|
||||
if size < 512 {
|
||||
size = 512
|
||||
}
|
||||
|
||||
file := sys.open(path, 0, 0)
|
||||
|
||||
if file < 0 {
|
||||
return 0, 0
|
||||
}
|
||||
|
||||
contents := mem.alloc(size)
|
||||
length := sys.read(file, contents, size)
|
||||
sys.close(file)
|
||||
return contents, length
|
||||
}
|
@ -5,6 +5,29 @@ sockaddr_in {
|
||||
sin_zero int64
|
||||
}
|
||||
|
||||
file_stat {
|
||||
st_dev uint64
|
||||
st_ino uint64
|
||||
st_nlink uint64
|
||||
st_mode uint32
|
||||
st_uid uint32
|
||||
st_gid uint32
|
||||
_ uint32
|
||||
st_rdev uint64
|
||||
st_size int64
|
||||
st_blksize int64
|
||||
st_blocks int64
|
||||
st_atime int64
|
||||
st_atime_nsec int64
|
||||
st_mtime int64
|
||||
st_mtime_nsec int64
|
||||
st_ctime int64
|
||||
st_ctime_nsec int64
|
||||
_ int64
|
||||
_ int64
|
||||
_ int64
|
||||
}
|
||||
|
||||
timespec {
|
||||
seconds int64
|
||||
nanoseconds int64
|
||||
|
@ -22,6 +22,10 @@ close(fd int) -> int {
|
||||
return syscall(n.close, fd)
|
||||
}
|
||||
|
||||
stat(path *any, stat *file_stat) -> int {
|
||||
return syscall(n.newfstatat, -100, path, stat, 0)
|
||||
}
|
||||
|
||||
clone(flags uint, stack *any, parent *int, child *int, tls uint) -> int {
|
||||
return syscall(n.clone, flags, stack, parent, child, tls)
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ const {
|
||||
munmap 215
|
||||
openat 56
|
||||
close 57
|
||||
newfstatat 79
|
||||
clone 220
|
||||
execve 221
|
||||
exit 93
|
||||
|
@ -6,6 +6,7 @@ const {
|
||||
munmap 11
|
||||
openat 257
|
||||
close 3
|
||||
newfstatat 262
|
||||
clone 56
|
||||
execve 59
|
||||
exit 60
|
||||
|
Reference in New Issue
Block a user