Adds lstat()

This commit is contained in:
2025-07-27 16:25:23 +02:00
parent 0c5bbde4a4
commit c40a59b4ff
3 changed files with 214 additions and 101 deletions

View File

@@ -1,73 +1,75 @@
section .rodata
; Open flags
O_ACCMODE equ 00000003q
O_RDONLY equ 00000000q
O_WRONLY equ 00000001q
O_RDWR equ 00000002q
O_CREAT equ 00000100q ;create if not exist
O_EXCL equ 00000200q ;fail if file exists and O_EXCL+O_CREAT set
O_NOCTTY equ 00000400q
O_TRUNC equ 00001000q
O_APPEND equ 00002000q
O_NONBLOCK equ 00004000q
O_DSYNC equ 00010000q
FASYNC equ 00020000q
O_DIRECT equ 00040000q
O_LARGEFILE equ 00100000q
O_DIRECTORY equ 00200000q
O_NOFOLLOW equ 00400000q
O_NOATIME equ 01000000q
O_CLOEXEC equ 02000000q
__O_SYNC equ 04000000q
O_SYNC equ (__O_SYNC | O_DSYNC)
O_PATH equ 01000000q
__O_TMPFILE equ 02000000q
O_TMPFILE equ (__O_TMPFILE | O_DIRECTORY)
O_NDELAY equ O_NONBLOCK
O_ACCMODE equ 00000003q
O_RDONLY equ 00000000q
O_WRONLY equ 00000001q
O_RDWR equ 00000002q
O_CREAT equ 00000100q ;create if not exist
O_EXCL equ 00000200q ;fail if file exists and O_EXCL+O_CREAT set
O_NOCTTY equ 00000400q
O_TRUNC equ 00001000q
O_APPEND equ 00002000q
O_NONBLOCK equ 00004000q
O_DSYNC equ 00010000q
FASYNC equ 00020000q
O_DIRECT equ 00040000q
O_LARGEFILE equ 00100000q
O_DIRECTORY equ 00200000q
O_NOFOLLOW equ 00400000q
O_NOATIME equ 01000000q
O_CLOEXEC equ 02000000q
__O_SYNC equ 04000000q
O_SYNC equ (__O_SYNC | O_DSYNC)
O_PATH equ 01000000q
__O_TMPFILE equ 02000000q
O_TMPFILE equ (__O_TMPFILE | O_DIRECTORY)
O_NDELAY equ O_NONBLOCK
; Permission flags
S_IXOTH equ 00001q ;o=x
S_IWOTH equ 00002q ;o=w
S_IROTH equ 00004q ;o=r
S_IRWXO equ 00007q ;o=rwx
S_IXGRP equ 00010q ;g=x
S_IWGRP equ 00020q ;g=w
S_IRGRP equ 00040q ;g=r
S_IRWXG equ 00070q ;g=rwx
S_IXUSR equ 00100q ;u=x
S_IWUSR equ 00200q ;u=w
S_IRUSR equ 00400q ;u=r
S_IRWXU equ 00700q ;u=rwx
S_ISVTX equ 0001000q ;sticky bit
S_ISGID equ 0002000q ;set-group-ID bit
S_ISUID equ 0004000q ;set-user-ID bit
S_IXOTH equ 00001q ;o=x
S_IWOTH equ 00002q ;o=w
S_IROTH equ 00004q ;o=r
S_IRWXO equ 00007q ;o=rwx
S_IXGRP equ 00010q ;g=x
S_IWGRP equ 00020q ;g=w
S_IRGRP equ 00040q ;g=r
S_IRWXG equ 00070q ;g=rwx
S_IXUSR equ 00100q ;u=x
S_IWUSR equ 00200q ;u=w
S_IRUSR equ 00400q ;u=r
S_IRWXU equ 00700q ;u=rwx
S_ISVTX equ 0001000q ;sticky bit
S_ISGID equ 0002000q ;set-group-ID bit
S_ISUID equ 0004000q ;set-user-ID bit
; Stat buffer fields
ST_DEV equ 0 ; Device unsigned
ST_INO equ 8 ; File serial number unsigned
ST_NLINK equ 16 ; Number of links unsigned
ST_MODE equ 24 ; File mode unsigned, 4 bytes
ST_UID equ 28 ; User ID of the file's owner unsigned, 4 bytes
ST_GID equ 32 ; Group ID of the file's group unsigned, 4 bytes
ST__PAD0 equ 36
ST_RDEV equ 40 ; Device number, if device unsigned
ST_SIZE equ 48 ; Size of file, in bytes signed
ST_BLKSIZE equ 56 ; Optimal block size for I/O signed
ST_BLOCKS equ 64 ; Number 512-byte blocks allocated signed
ST_ATIME equ 72 ; Time of last access unsigned
ST_ATIME_NSEC equ 80 ; unsigned
ST_MTIME equ 88 ; Time of last modification unsigned
ST_MTIME_NSEC equ 96 ; unsigned
ST_CTIME equ 104 ; Time of last status change unsigned
ST_CTIME_NSEC equ 112 ; unsigned
ST__UNUSED equ 120
ST__END equ 128 ; End of stat buffer
STATBUFF_SIZE equ ST__END
ST_DEV equ 0 ; Device unsigned
ST_INO equ 8 ; File serial number unsigned
ST_NLINK equ 16 ; Number of links unsigned
ST_MODE equ 24 ; File mode unsigned, 4 bytes
ST_UID equ 28 ; User ID of the file's owner unsigned, 4 bytes
ST_GID equ 32 ; Group ID of the file's group unsigned, 4 bytes
ST__PAD0 equ 36
ST_RDEV equ 40 ; Device number, if device unsigned
ST_SIZE equ 48 ; Size of file, in bytes signed
ST_BLKSIZE equ 56 ; Optimal block size for I/O signed
ST_BLOCKS equ 64 ; Number 512-byte blocks allocated signed
ST_ATIME equ 72 ; Time of last access unsigned
ST_ATIME_NSEC equ 80 ; unsigned
ST_MTIME equ 88 ; Time of last modification unsigned
ST_MTIME_NSEC equ 96 ; unsigned
ST_CTIME equ 104 ; Time of last status change unsigned
ST_CTIME_NSEC equ 112 ; unsigned
ST__UNUSED equ 120
ST__END equ 128 ; End of stat buffer
STATBUFF_SIZE equ ST__END
AT_FDCWD equ -100
AT_FDCWD equ -100
AT_SYMLINK_NOFOLLOW equ 0x100
AT_SYMLINK_FOLLOW equ 0x400
; File types
S_IFDIR equ 0040000q ; Directory
S_IFCHR equ 0020000q ; Character device
S_IFBLK equ 0060000q ; Block device
S_IFREG equ 0100000q ; Regular file
S_IFIFO equ 0010000q ; FIFO
S_IFLNK equ 0120000q ; Symbolic link
S_IFSOCK equ 0140000q ; Socket
S_IFDIR equ 0040000q ; Directory
S_IFCHR equ 0020000q ; Character device
S_IFBLK equ 0060000q ; Block device
S_IFREG equ 0100000q ; Regular file
S_IFIFO equ 0010000q ; FIFO
S_IFLNK equ 0120000q ; Symbolic link
S_IFSOCK equ 0140000q ; Socket