|
| 1 | +#![allow(dead_code)] |
| 2 | +#![allow(unused_variables)] |
| 3 | + |
| 4 | +// Root directory for Lind filesystem |
| 5 | +pub const LIND_ROOT: &str = "/home/lind/lind-wasm/src/RawPOSIX/tmp"; |
| 6 | + |
| 7 | +// ===== Standard File Descriptors ===== |
| 8 | +pub const STDIN_FILENO: i32 = 0; // File descriptor for standard input |
| 9 | +pub const STDOUT_FILENO: i32 = 1; // File descriptor for standard output |
| 10 | +pub const STDERR_FILENO: i32 = 2; // File descriptor for standard error |
| 11 | + |
| 12 | +// ===== Directory Entry Constant ===== |
| 13 | +// Source: include/dirent.h |
| 14 | +pub const DT_UNKNOWN: u8 = 0; |
| 15 | + |
| 16 | +// ===== File Access Permission Flags ===== |
| 17 | +pub const F_OK: u32 = 0; // Test for existence |
| 18 | +pub const X_OK: u32 = 1; // Test for execute permission |
| 19 | +pub const W_OK: u32 = 2; // Test for write permission |
| 20 | +pub const R_OK: u32 = 4; // Test for read permission |
| 21 | + |
| 22 | +// ===== File Access Modes ===== |
| 23 | +// Source: include/uapi/asm-generic/fcntl.h |
| 24 | +pub const O_RDONLY: i32 = 0o0; // Open read-only |
| 25 | +pub const O_WRONLY: i32 = 0o1; // Open write-only |
| 26 | +pub const O_RDWR: i32 = 0o2; // Open read-write |
| 27 | +pub const O_RDWRFLAGS: i32 = 0o3; // Mask for access modes |
| 28 | + |
| 29 | +// ===== File Creation and Status Flags ===== |
| 30 | +// Source: include/linux/coda.h |
| 31 | +pub const O_CREAT: i32 = 0o100; // Create file if it doesn't exist |
| 32 | +pub const O_EXCL: i32 = 0o200; // Error if O_CREAT and file exists |
| 33 | +pub const O_NOCTTY: i32 = 0o400; // Don't assign controlling terminal |
| 34 | +pub const O_TRUNC: i32 = 0o1000; // Truncate file to zero length |
| 35 | +pub const O_APPEND: i32 = 0o2000; // Append mode - writes always at end |
| 36 | +pub const O_NONBLOCK: i32 = 0o4000; // Non-blocking mode |
| 37 | +pub const O_SYNC: i32 = 0o10000; // Synchronous writes |
| 38 | +pub const O_ASYNC: i32 = 0o20000; // Signal-driven I/O |
| 39 | +pub const O_CLOEXEC: i32 = 0o2000000; // Close on exec |
| 40 | + |
| 41 | +// ===== File Permissions ===== |
| 42 | +// Source: include/uapi/linux/stat.h |
| 43 | +pub const S_IRWXA: u32 = 0o777; // All permissions for all users |
| 44 | +pub const S_IRWXU: u32 = 0o700; // User read, write, execute |
| 45 | +pub const S_IRUSR: u32 = 0o400; // User read |
| 46 | +pub const S_IWUSR: u32 = 0o200; // User write |
| 47 | +pub const S_IXUSR: u32 = 0o100; // User execute |
| 48 | +pub const S_IRWXG: u32 = 0o070; // Group read, write, execute |
| 49 | +pub const S_IRGRP: u32 = 0o040; // Group read |
| 50 | +pub const S_IWGRP: u32 = 0o020; // Group write |
| 51 | +pub const S_IXGRP: u32 = 0o010; // Group execute |
| 52 | +pub const S_IRWXO: u32 = 0o007; // Others read, write, execute |
| 53 | +pub const S_IROTH: u32 = 0o004; // Others read |
| 54 | +pub const S_IWOTH: u32 = 0o002; // Others write |
| 55 | +pub const S_IXOTH: u32 = 0o001; // Others execute |
| 56 | + |
| 57 | +//Commands for FCNTL |
| 58 | +// Source: include/linux/fcntl.h |
| 59 | +pub const F_DUPFD: i32 = 0; |
| 60 | +pub const F_GETFD: i32 = 1; |
| 61 | +pub const F_SETFD: i32 = 2; |
| 62 | +pub const F_GETFL: i32 = 3; |
| 63 | +pub const F_SETFL: i32 = 4; |
| 64 | +pub const F_GETLK: i32 = 5; |
| 65 | +pub const F_GETLK64: i32 = 5; |
| 66 | +pub const F_SETLK: i32 = 6; |
| 67 | +pub const F_SETLK64: i32 = 6; |
| 68 | +pub const F_SETLKW: i32 = 7; |
| 69 | +pub const F_SETLKW64: i32 = 7; |
| 70 | +pub const F_SETOWN: i32 = 8; |
| 71 | +pub const F_GETOWN: i32 = 9; |
| 72 | +pub const F_SETSIG: i32 = 10; |
| 73 | +pub const F_GETSIG: i32 = 11; |
| 74 | +pub const F_SETLEASE: i32 = 1024; |
| 75 | +pub const F_GETLEASE: i32 = 1025; |
| 76 | +pub const F_NOTIFY: i32 = 1026; |
| 77 | + |
| 78 | +//Commands for IOCTL |
| 79 | +pub const FIONBIO: u32 = 21537; |
| 80 | +pub const FIOASYNC: u32 = 21586; |
| 81 | + |
| 82 | +//File types for open/stat etc. |
| 83 | +// Source: include/linux/stat.h |
| 84 | +pub const S_IFBLK: i32 = 0o60000; |
| 85 | +pub const S_IFCHR: i32 = 0o20000; |
| 86 | +pub const S_IFDIR: i32 = 0o40000; |
| 87 | +pub const S_IFIFO: i32 = 0o10000; |
| 88 | +pub const S_IFLNK: i32 = 0o120000; |
| 89 | +pub const S_IFREG: i32 = 0o100000; |
| 90 | +pub const S_IFSOCK: i32 = 0o140000; |
| 91 | +pub const S_FILETYPEFLAGS: i32 = 0o170000; |
| 92 | + |
| 93 | +//for flock syscall |
| 94 | +pub const LOCK_SH: i32 = 1; |
| 95 | +pub const LOCK_EX: i32 = 2; |
| 96 | +pub const LOCK_UN: i32 = 8; |
| 97 | +pub const LOCK_NB: i32 = 4; |
| 98 | +//for mmap/munmap syscall |
| 99 | +pub const MAP_FIXED: u32 = 16; |
| 100 | +pub const MAP_ANONYMOUS: u32 = 32; |
| 101 | +pub const MAP_HUGE_SHIFT: i32 = 26; |
| 102 | +pub const MAP_HUGETLB: i32 = 262144; |
| 103 | + |
| 104 | +// Source: include/linux/fs.h |
| 105 | +pub const SEEK_SET: i32 = 0; // Seek from beginning of file |
| 106 | +pub const SEEK_CUR: i32 = 1; // Seek from current position |
| 107 | +pub const SEEK_END: i32 = 2; // Seek from end of file |
| 108 | + |
| 109 | +// Source: include/linux/ipc.h |
| 110 | +pub const IPC_PRIVATE: i32 = 0o0; |
| 111 | +pub const IPC_CREAT: i32 = 0o1000; |
| 112 | +pub const IPC_EXCL: i32 = 0o2000; |
| 113 | + |
| 114 | +pub const IPC_RMID: i32 = 0; |
| 115 | +pub const IPC_SET: i32 = 1; |
| 116 | +pub const IPC_STAT: i32 = 2; |
| 117 | + |
| 118 | +// Source: linux/bits/shm.h |
| 119 | +pub const SHM_DEST: i32 = 0o1000; // Destroy segment when last process detaches |
| 120 | +pub const SHM_LOCKED: i32 = 0o2000; // Lock segment in memory |
| 121 | +pub const SHM_HUGETLB: i32 = 0o4000; // Use huge TLB pages |
| 122 | + |
| 123 | +pub const SHM_R: i32 = 0o400; // Read permission |
| 124 | +pub const SHM_W: i32 = 0o200; // Write permission |
| 125 | +pub const SHM_RDONLY: i32 = 0o10000; // Read-only access |
| 126 | +pub const SHM_RND: i32 = 0o20000; // Round attach address to SHMLBA |
| 127 | +pub const SHM_REMAP: i32 = 0o40000; // Take-over region on attach |
| 128 | +pub const SHM_EXEC: i32 = 0o100000; // Execute permission |
| 129 | + |
| 130 | +pub const SHMMIN: u32 = 1; // Minimum shared memory segment size |
| 131 | +pub const SHMMNI: u32 = 4096; // Maximum number of segments system wide |
| 132 | +pub const SHMMAX: u32 = 4278190079; // Maximum shared memory segment size |
| 133 | +pub const SHMALL: u32 = 4278190079; // Maximum total shared memory system wide |
| 134 | +pub const SHMSEG: u32 = SHMMNI; // Maximum segments per process |
| 135 | + |
| 136 | +pub const SEM_VALUE_MAX: u32 = 2147483647; // Maximum value for a semaphore |
| 137 | + |
| 138 | +// ===== Memory Protection Flags ===== |
| 139 | +// Source: include/uapi/asm-generic/mman-common.h |
| 140 | +pub const PROT_NONE: i32 = 0x0; // Page cannot be accessed |
| 141 | +pub const PROT_READ: i32 = 0x1; // Page can be read |
| 142 | +pub const PROT_WRITE: i32 = 0x2; // Page can be written |
| 143 | +pub const PROT_EXEC: i32 = 0x4; // Page can be executed |
| 144 | + |
| 145 | +// Mask for all protection bits |
| 146 | +// Note: Some architectures may support additional bits |
| 147 | +pub const PROT_MASK: u32 = 0x7; |
| 148 | + |
| 149 | +// ===== Memory Mapping Flags ===== |
| 150 | +// Source: include/uapi/asm-generic/mman.h |
| 151 | +pub const MAP_SHARED: u32 = 0x01; // Share changes with other processes |
| 152 | +pub const MAP_PRIVATE: u32 = 0x02; // Changes are private to this process |
| 153 | +pub const MAP_SHARING_MASK: u32 = 0x03; // Mask to isolate sharing bits |
| 154 | + |
| 155 | +pub const MAP_ANON: u32 = 0x20; // Don't use a file descriptor |
| 156 | + |
| 157 | +// ===== Page Size Constants ===== |
| 158 | +// Note: These values are architecture-dependent |
| 159 | +// Current values are for x86_64 Linux |
| 160 | +pub const PAGESHIFT: u32 = 12; // 4KB pages (1 << 12 = 4096) |
| 161 | +pub const PAGESIZE: u32 = 1 << PAGESHIFT; |
| 162 | + |
| 163 | +// ===== Memory Mapping Error Value ===== |
| 164 | +// Source: include/uapi/asm-generic/mman-common.h |
| 165 | +pub const MAP_FAILED: *mut std::ffi::c_void = (-1isize) as *mut std::ffi::c_void; |
| 166 | + |
| 167 | +// ===== Memory Remapping Flags ===== |
| 168 | +// Source: include/uapi/asm-generic/mman-common.h |
| 169 | +pub const MREMAP_MAYMOVE: u32 = 0x01; // Can relocate mapping |
| 170 | +pub const MREMAP_FIXED: u32 = 0x02; // New address is specified exactly |
| 171 | + |
| 172 | +// ===== File Access Modes ===== |
| 173 | +// Source: include/uapi/asm-generic/fcntl.h |
| 174 | +pub const O_ACCMODE: i32 = 0o003; // Mask for file access modes |
0 commit comments