Lecture 02 Flashcards
Give some properties of files and directories
- Owner
- Group
- Size
- Permissions (User, Group, Other)
- Times (Accessed, Modified, Changed (metadata))
What functions are used to access the meta-data of files and directories.
stat, fstat, and lstat
How is the file/directory metadata returned from the ‘stat’ function?
In a C structure called ‘stat’
In a ‘stat’ structure, what is the name of the protection variable?
st_mode
This is a mode_t variable.
Which macro function checks if a file is a regular file or not from a mode_t variable?
S_ISREG(m)
Which macro function checks if a file is a directory or not from a mode_t variable?
S_ISDIR(m)
Which macro function checks if a file is a block special file or not from a mode_t variable?
S_ISBLK(m)
Which macro function checks if a file is a character special file or not from a mode_t variable?
S_ISCHR(m)
Which macro function checks if a file is First In First Out or not from a mode_t variable?
S_ISFIFO(m)
Which macro function checks if a file is a socket or not from a mode_t variable?
S_ISSOCK(m)
Which macro function checks if a file is a symbolic link or not from a mode_t variable?
S_ISLNK(m)
Do you need read permission on a file to call ‘stat’ on it?
No
What permissions do you need to open a file?
Permissions on the file itself, along with ‘execute’ permission on every directory in the path.
How many bits are used to represent permissions?
9.
What are the three permission groups: User,..,..
User, Group, Other
What do Unix systems use to store file and directory metadata?
inodes
Do inodes contain filenames and contents?
No
How are inodes addressed?
Via an index in the inode table. inode n is the nth inode in the table.
Directories map _s to _s
names to inode numbers
Where is the root directory ‘/’ stored?
In some known inode.
Can you explicitly make a hard link to a directory?
No
Can you explicitly make a hard link to a file?
Yes
What are directory entries known as?
Hard Links
What are symbolic links stored as instead of an inode?
A text string
What is a symbolic link?
A special file that points to another file or directory
What function is used to open a directory for reading?
What does it return?
opendir.
It returns a DIR*
What is the function prototype for opendir?
DIR* opendir(const char *name);
What function is used to read from a directory?
What does it return.
readdir.
It returns a struct dirent
What is the function prototype for readdir?
struct dirent* readdir(DIR *dir);
What two fields will every struct dirent have?
The inode number and the filename.
What function gets the current working directory?
getcwd()
What function changes the current working directory?
chdir()
What directory is used as the root for relative file paths?
The current working directory
Which function is used to change the owner of a file?
chown()
Which function is used to change the permissions of a file?
chmod()
Which function is used to change the group of a file?
chgrp()
Which function is used to change the size of a file?
trucate()
Which function is used to remove a directory?
rmdir()
Which function is used to make a directory?
mkdir()
Which function is used to create a link?
link
Which function is used to delete a link?
unlink