Properties of Files and Directories
Three Main Functions
File Types
File Types
- Regular Files: text, binary, etc.
- Directory Files: can be only update by kernel -
{(filename, pointer)} - Character Special Files: tty, audio, etc.
- Block Special Files: disks, etc
- Symbolic Links
Macros
| Macro | Type of File |
|---|---|
S_ISREG() | regular file |
S_ISDIR() | directory file |
S_ISCHR() | character of special file |
S_ISFIFO() | block of special file |
S_ISLNK() | pipe of FIFO |
S_ISLNK() | symbolic link |
S_ISSOCK() | socket |
The argument to these macros is the st_mode from stat structure
Access Permission
Real/Effective User ID
Ownership of a New File
Functions: access / umask / chmod & fchmod
Sticky Bit
Function: chown, fchown, lchown
Compiler-time and Run-time Limits
Compile-time Limits
The limitation enforced during compilation - when source code is changed into executable code
e.g., array size limits, largest size of int, etc
Run-time Limits
The limitation enforced during program execution - when we actually run the program
e.g., memory limits, stack size limits, time limits, etc
File Size
File Sizes - st_size
The “logical” size of the file. File holes won’t actually occupy physical disks but will be count in st_size
File Holes
When we lseek() or truncate() beyond file size, we create “file holes”. These holes read as zeros but don’t consume physical disk space
However, when copying a file with holes, the copy operation writes actual zeros to disk, so the new file occupies full physical space without holes
Using st_blocks (actual blocks allocated), we can calculate real disk usage: st_blocks × st_blksize. This differs from st_size (logical file size) when holes exist