-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix constants fs #98
Closed
Closed
Fix constants fs #98
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
//! File System Constants Module | ||
//! These constants define file system-related flags and parameters | ||
//! | ||
//! Primary Source References: | ||
//! - Linux kernel v6.5: include/uapi/asm-generic/fcntl.h | ||
//! - Linux kernel v6.5: include/uapi/linux/stat.h | ||
//! - POSIX.1-2017 (IEEE Std 1003.1-2017) | ||
|
||
#![allow(dead_code)] | ||
#![allow(unused_variables)] | ||
|
||
use crate::interface; | ||
|
||
// ===== File Descriptor Constants ===== | ||
pub const DT_UNKNOWN: u8 = 0; | ||
|
||
pub const STARTINGFD: i32 = 0; // Starting file descriptor number | ||
pub const MAXFD: i32 = 1024; // Maximum number of file descriptors | ||
pub const STARTINGPIPE: i32 = 0; // Starting pipe descriptor number | ||
pub const MAXPIPE: i32 = 1024; // Maximum number of pipes | ||
|
||
// ===== Inode Constants ===== | ||
pub const ROOTDIRECTORYINODE: usize = 1; // Root directory inode number | ||
pub const STREAMINODE: usize = 2; // Stream inode number | ||
|
||
// ===== Pipe Constants ===== | ||
pub const PIPE_CAPACITY: usize = 65536; // Maximum pipe buffer size | ||
|
||
// ===== File Access Permission Flags ===== | ||
pub const F_OK: u32 = 0; // Test for existence | ||
pub const X_OK: u32 = 1; // Test for execute permission | ||
pub const W_OK: u32 = 2; // Test for write permission | ||
pub const R_OK: u32 = 4; // Test for read permission | ||
|
||
// ===== File Access Modes ===== | ||
// Source: include/uapi/asm-generic/fcntl.h | ||
pub const O_RDONLY: i32 = 0o0; // Open read-only | ||
pub const O_WRONLY: i32 = 0o1; // Open write-only | ||
pub const O_RDWR: i32 = 0o2; // Open read-write | ||
pub const O_RDWRFLAGS: i32 = 0o3; // Mask for access modes | ||
|
||
// ===== File Creation and Status Flags ===== | ||
pub const O_CREAT: i32 = 0o100; // Create file if it doesn't exist | ||
pub const O_EXCL: i32 = 0o200; // Error if O_CREAT and file exists | ||
pub const O_NOCTTY: i32 = 0o400; // Don't assign controlling terminal | ||
pub const O_TRUNC: i32 = 0o1000; // Truncate file to zero length | ||
pub const O_APPEND: i32 = 0o2000; // Append mode - writes always at end | ||
pub const O_NONBLOCK: i32 = 0o4000; // Non-blocking mode | ||
// O_NDELAY=O_NONBLOCK | ||
pub const O_SYNC: i32 = 0o10000; // Synchronous writes | ||
// O_FSYNC=O_SYNC | ||
pub const O_ASYNC: i32 = 0o20000; // Signal-driven I/O | ||
pub const O_CLOEXEC: i32 = 0o2000000; // Close on exec | ||
|
||
pub const DEFAULTTIME: u64 = 1323630836; // Default timestamp value | ||
|
||
// ===== File Permissions ===== | ||
// Source: include/uapi/linux/stat.h | ||
pub const S_IRWXA: u32 = 0o777; // All permissions for all users | ||
pub const S_IRWXU: u32 = 0o700; // User read, write, execute | ||
pub const S_IRUSR: u32 = 0o400; // User read | ||
pub const S_IWUSR: u32 = 0o200; // User write | ||
pub const S_IXUSR: u32 = 0o100; // User execute | ||
pub const S_IRWXG: u32 = 0o070; // Group read, write, execute | ||
pub const S_IRGRP: u32 = 0o040; // Group read | ||
pub const S_IWGRP: u32 = 0o020; // Group write | ||
pub const S_IXGRP: u32 = 0o010; // Group execute | ||
pub const S_IRWXO: u32 = 0o007; // Others read, write, execute | ||
pub const S_IROTH: u32 = 0o004; // Others read | ||
pub const S_IWOTH: u32 = 0o002; // Others write | ||
pub const S_IXOTH: u32 = 0o001; // Others execute | ||
|
||
//Commands for FCNTL | ||
pub const F_DUPFD: i32 = 0; | ||
pub const F_GETFD: i32 = 1; | ||
pub const F_SETFD: i32 = 2; | ||
pub const F_GETFL: i32 = 3; | ||
pub const F_SETFL: i32 = 4; | ||
pub const F_GETLK: i32 = 5; | ||
pub const F_GETLK64: i32 = 5; | ||
pub const F_SETLK: i32 = 6; | ||
pub const F_SETLK64: i32 = 6; | ||
pub const F_SETLKW: i32 = 7; | ||
pub const F_SETLKW64: i32 = 7; | ||
pub const F_SETOWN: i32 = 8; | ||
pub const F_GETOWN: i32 = 9; | ||
pub const F_SETSIG: i32 = 10; | ||
pub const F_GETSIG: i32 = 11; | ||
pub const F_SETLEASE: i32 = 1024; | ||
pub const F_GETLEASE: i32 = 1025; | ||
pub const F_NOTIFY: i32 = 1026; | ||
|
||
//Commands for IOCTL | ||
pub const FIONBIO: u32 = 21537; | ||
pub const FIOASYNC: u32 = 21586; | ||
|
||
//File types for open/stat etc. | ||
pub const S_IFBLK: i32 = 0o60000; | ||
pub const S_IFCHR: i32 = 0o20000; | ||
pub const S_IFDIR: i32 = 0o40000; | ||
pub const S_IFIFO: i32 = 0o10000; | ||
pub const S_IFLNK: i32 = 0o120000; | ||
pub const S_IFREG: i32 = 0o100000; | ||
pub const S_IFSOCK: i32 = 0o140000; | ||
pub const S_FILETYPEFLAGS: i32 = 0o170000; | ||
|
||
//for flock syscall | ||
pub const LOCK_SH: i32 = 1; | ||
pub const LOCK_EX: i32 = 2; | ||
pub const LOCK_UN: i32 = 8; | ||
pub const LOCK_NB: i32 = 4; | ||
//for mmap/munmap syscall | ||
pub const MAP_SHARED: i32 = 1; | ||
pub const MAP_PRIVATE: i32 = 2; | ||
pub const MAP_FIXED: i32 = 16; | ||
pub const MAP_ANONYMOUS: i32 = 32; | ||
pub const MAP_HUGE_SHIFT: i32 = 26; | ||
pub const MAP_HUGETLB: i32 = 262144; | ||
|
||
pub const PROT_NONE: i32 = 0; | ||
pub const PROT_READ: i32 = 1; | ||
pub const PROT_WRITE: i32 = 2; | ||
pub const PROT_EXEC: i32 = 4; | ||
|
||
pub const SEEK_SET: i32 = 0; // Seek from beginning of file | ||
pub const SEEK_CUR: i32 = 1; // Seek from current position | ||
pub const SEEK_END: i32 = 2; // Seek from end of file | ||
|
||
pub const IPC_PRIVATE: i32 = 0o0; | ||
pub const IPC_CREAT: i32 = 0o1000; | ||
pub const IPC_EXCL: i32 = 0o2000; | ||
|
||
pub const IPC_RMID: i32 = 0; | ||
pub const IPC_SET: i32 = 1; | ||
pub const IPC_STAT: i32 = 2; | ||
|
||
pub const SHM_DEST: i32 = 0o1000; // Destroy segment when last process detaches | ||
pub const SHM_LOCKED: i32 = 0o2000; // Lock segment in memory | ||
pub const SHM_HUGETLB: i32 = 0o4000; // Use huge TLB pages | ||
|
||
pub const SHM_R: i32 = 0o400; // Read permission | ||
pub const SHM_W: i32 = 0o200; // Write permission | ||
pub const SHM_RDONLY: i32 = 0o10000; // Read-only access | ||
pub const SHM_RND: i32 = 0o20000; // Round attach address to SHMLBA | ||
pub const SHM_REMAP: i32 = 0o40000; // Take-over region on attach | ||
pub const SHM_EXEC: i32 = 0o100000; // Execute permission | ||
|
||
pub const SHMMIN: u32 = 1; // Minimum shared memory segment size | ||
pub const SHMMNI: u32 = 4096; // Maximum number of segments system wide | ||
pub const SHMMAX: u32 = 4278190079; // Maximum shared memory segment size | ||
pub const SHMALL: u32 = 4278190079; // Maximum total shared memory system wide | ||
pub const SHMSEG: u32 = SHMMNI; // Maximum segments per process | ||
|
||
pub const SEM_VALUE_MAX: u32 = 2147483647; // Maximum value for a semaphore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
//! RawPOSIX Constants Module | ||
//! | ||
//! Primary Source References: | ||
//! - Linux kernel v6.5: include/uapi/asm-generic/mman-common.h | ||
//! - Linux kernel v6.5: include/uapi/asm-generic/fcntl.h | ||
//! - Linux kernel v6.5: include/uapi/linux/stat.h | ||
//! - Linux kernel v6.5: include/uapi/asm-generic/errno-base.h | ||
//! - POSIX.1-2017 (IEEE Std 1003.1-2017) | ||
|
||
// Change these from private to public modules | ||
pub mod fs_constants; | ||
pub mod net_constants; | ||
pub mod sys_constants; | ||
pub mod vmmap_constants; | ||
|
||
// Re-export all constants from their respective modules | ||
pub use fs_constants::*; | ||
pub use net_constants::*; | ||
pub use sys_constants::*; | ||
pub use vmmap_constants::*; | ||
|
||
// ===== Memory Protection Flags ===== | ||
// Source: include/uapi/asm-generic/mman-common.h | ||
// These flags control memory segment permissions for mmap and mprotect | ||
pub const PROT_NONE: i32 = 0x0; // No permissions - pages may not be accessed | ||
pub const PROT_READ: i32 = 0x1; // Pages may be read | ||
pub const PROT_WRITE: i32 = 0x2; // Pages may be written | ||
pub const PROT_EXEC: i32 = 0x4; // Pages may be executed | ||
pub const PROT_MASK: u32 = 0x7; // Mask for all permission bits | ||
// Note: Some platforms may support additional bits | ||
|
||
// ===== Memory Mapping Flags ===== | ||
// Source: include/uapi/asm-generic/mman.h, include/uapi/asm-generic/mman-common.h | ||
// These flags control the behavior of mmap operations | ||
pub const MAP_SHARED: i32 = 0x01; // Share changes with other processes | ||
pub const MAP_PRIVATE: i32 = 0x02; // Changes are private to this process | ||
pub const MAP_FIXED: i32 = 0x10; // Interpret address exactly | ||
pub const MAP_ANON: i32 = 0x20; // Don't use a file descriptor | ||
pub const MAP_ANONYMOUS: i32 = MAP_ANON; // Synonym for MAP_ANON | ||
pub const MAP_SHARING_MASK: i32 = 0x03; // Mask to isolate sharing bits | ||
// Note: Values may differ on BSD systems | ||
|
||
// ===== Memory Mapping Error Values ===== | ||
// Source: include/uapi/asm-generic/mman-common.h | ||
// Standard error return value for mmap | ||
pub const MAP_FAILED: *mut std::ffi::c_void = (-1_isize as *mut std::ffi::c_void); | ||
|
||
// ===== Memory Page Size Constants ===== | ||
// Note: These values are architecture-dependent | ||
// Current values are for x86_64 Linux | ||
pub const PAGESHIFT: u32 = 12; // 4KB pages (1 << 12 = 4096) | ||
pub const PAGESIZE: u32 = 1 << PAGESHIFT; | ||
pub const MAP_PAGESHIFT: u32 = 16; // Custom value for Lind | ||
pub const MAP_PAGESIZE: u32 = 1 << MAP_PAGESHIFT; | ||
|
||
// ===== Memory Remapping Flags ===== | ||
// Source: include/uapi/asm-generic/mman-common.h | ||
pub const MREMAP_MAYMOVE: u32 = 0x01; // Can relocate mapping | ||
pub const MREMAP_FIXED: u32 = 0x02; // New address is specified exactly | ||
|
||
// ===== File Access Modes ===== | ||
// Source: include/uapi/asm-generic/fcntl.h | ||
// These flags control how files are opened and accessed | ||
pub const O_ACCMODE: i32 = 0o003; // Mask for file access modes | ||
pub const O_RDONLY: i32 = 0o0; // Open read-only | ||
pub const O_WRONLY: i32 = 0o1; // Open write-only | ||
pub const O_RDWR: i32 = 0o2; // Open read-write | ||
pub const O_CREAT: i32 = 0o100; // Create file if it doesn't exist | ||
pub const O_EXCL: i32 = 0o200; // Error if O_CREAT and file exists | ||
pub const O_TRUNC: i32 = 0o1000; // Truncate file to zero length | ||
pub const O_APPEND: i32 = 0o2000; // Append mode - writes always at end | ||
|
||
// ===== File Types ===== | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a bit confused why we keep those here instead of moving to corresponding files? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed them from mod.rs |
||
// Source: include/uapi/linux/stat.h | ||
// These constants define the different types of files in the filesystem | ||
pub const S_IFMT: u32 = 0o170000; // Bit mask for file type | ||
pub const S_IFREG: u32 = 0o100000; // Regular file | ||
pub const S_IFDIR: u32 = 0o040000; // Directory | ||
pub const S_IFCHR: u32 = 0o020000; // Character device | ||
pub const S_IFBLK: u32 = 0o060000; // Block device | ||
pub const S_IFIFO: u32 = 0o010000; // FIFO (named pipe) | ||
pub const S_IFLNK: u32 = 0o120000; // Symbolic link | ||
pub const S_IFSOCK: u32 = 0o140000; // Socket | ||
|
||
// ===== File Permissions ===== | ||
// Source: include/uapi/linux/stat.h | ||
// Standard UNIX permission bits | ||
pub const S_IRWXU: u32 = 0o700; // User read, write, execute | ||
pub const S_IRUSR: u32 = 0o400; // User read | ||
pub const S_IWUSR: u32 = 0o200; // User write | ||
pub const S_IXUSR: u32 = 0o100; // User execute | ||
|
||
pub const S_IRWXG: u32 = 0o070; // Group read, write, execute | ||
pub const S_IRGRP: u32 = 0o040; // Group read | ||
pub const S_IWGRP: u32 = 0o020; // Group write | ||
pub const S_IXGRP: u32 = 0o010; // Group execute | ||
|
||
pub const S_IRWXO: u32 = 0o007; // Others read, write, execute | ||
pub const S_IROTH: u32 = 0o004; // Others read | ||
pub const S_IWOTH: u32 = 0o002; // Others write | ||
pub const S_IXOTH: u32 = 0o001; // Others execute | ||
|
||
// ===== Error Numbers ===== | ||
// Source: include/uapi/asm-generic/errno-base.h | ||
// Standard POSIX error codes | ||
pub const EPERM: i32 = 1; // Operation not permitted | ||
pub const ENOENT: i32 = 2; // No such file or directory | ||
pub const EINTR: i32 = 4; // Interrupted system call | ||
pub const EIO: i32 = 5; // I/O error | ||
pub const EBADF: i32 = 9; // Bad file descriptor | ||
pub const EAGAIN: i32 = 11; // Resource temporarily unavailable | ||
pub const ENOMEM: i32 = 12; // Cannot allocate memory | ||
pub const EACCES: i32 = 13; // Permission denied | ||
pub const EFAULT: i32 = 14; // Bad address | ||
pub const EEXIST: i32 = 17; // File exists | ||
pub const ENOTDIR: i32 = 20; // Not a directory | ||
pub const EINVAL: i32 = 22; // Invalid argument |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better to move those to vmmap_constant.rs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed them from mod.rs