Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
File types
stat functions for file information
File permissions
suid and sgid
Sticky bit
Hard link and soft link
Directory operations
Device special files
File system
File Types
Regular file
Directory file
Character special file (unbuffered I/O
access)
Block special file (buffered I/O)
Named Pipe (a type of IPC) - FIFO
Socket (a network form of IPC)
Symbolic Link (a file that just points to
another file)
stat structure
Definition on page
88
st_mode
st_ino
st_dev
st_rdev
st_nlink
st_uid
st_gid
st_size
st_blocks
st_blksize
st_atime
st_mtime
st_ctime
Real user ID
Real group ID
Effective user ID
Effective group ID
Supplementary group IDs
Saved set-user-ID
Saved set-group-ID
set-user-ID bit
set-group-ID bit
access function
Tests to see if the real user ID and real
group ID allow access to a file
Useful if a program that may be running as
another user (ex root) wants to be sure
that the person that started the program
has permissions to access some file
int access(const char *pathname, int mode);
Returns 0 if ok, -1 otherwise
R_OK
W_OK
X_OK
F_OK
umask function
mode_t umask(mode_t mask);
Sets the file mode creation mask
file mode creation mask is used to
specify the default permissions of newly
created files
Since we are dealing with a mask it is the
complement of what we want. So we set
the bits corresponding to the permissions
we dont want.
umask function
File Size
Sticky Bit
Historically
Sticky Bit
Currently
chmod +t mydir
link
int link(const char *oldpath, const char *newpath);
unlink
int unlink(const char *pathname);
remove
int remove(const char *pathname);
rename
int rename(const char *oldpath, const char *newpath);
Symbolic Links
symlink
readlink
File Times
st_atime
st_mtime
st_ctime
utime
int utime(const char *filename, const struct utimbuf *buf);
struct utimbuf {
time_t actime;
time_t modtime;
}
Directory Operations
Reading Directories
DIR *opendir(const char *name);
struct dirent *readdir(DIR *dir);
void rewinddir(DIR *dir);
int closedir(DIR *dir);
off_t telldir(DIR *dir);
void seekdir(DIR *dir, off_t offset);
struct dirent {
ino_t d_ino;
char d_name[NAME_MAX + 1];
}
major(st_dev)
minor(st_dev)