Podcast
Questions and Answers
What is the return value of the symlink function when it executes successfully?
What is the return value of the symlink function when it executes successfully?
- 0 (correct)
- 1
- -1
- 3
Which function allows creating a symbolic link with a relative path based on a directory file descriptor?
Which function allows creating a symbolic link with a relative path based on a directory file descriptor?
- link
- linkat
- symlinkat (correct)
- symlink
What do readlink and readlinkat functions return when executed successfully?
What do readlink and readlinkat functions return when executed successfully?
- the content of the file
- -1
- the number of bytes read (correct)
- the path of the symbolic link
When using readlinkat, what happens if the fd argument points to a valid directory and pathname is absolute?
When using readlinkat, what happens if the fd argument points to a valid directory and pathname is absolute?
What is NOT a requirement for the actualpath when creating a symbolic link using symlink?
What is NOT a requirement for the actualpath when creating a symbolic link using symlink?
If symlink returns -1, what does it indicate?
If symlink returns -1, what does it indicate?
Which of the following is true about the contents returned by readlink and readlinkat?
Which of the following is true about the contents returned by readlink and readlinkat?
What determines the behavior of the symlinkat function when the fd argument is AT_FDCWD?
What determines the behavior of the symlinkat function when the fd argument is AT_FDCWD?
What is the purpose of the umask value in UNIX systems?
What is the purpose of the umask value in UNIX systems?
What happens to the umask value of a process when it creates a new file?
What happens to the umask value of a process when it creates a new file?
What does a umask of 022 prevent in terms of file permissions?
What does a umask of 022 prevent in terms of file permissions?
Which of the following is NOT a common umask value mentioned?
Which of the following is NOT a common umask value mentioned?
Which format allows specifying permissions to be allowed with the umask command?
Which format allows specifying permissions to be allowed with the umask command?
If a user wants to prevent everyone from writing to their files, which umask should they set?
If a user wants to prevent everyone from writing to their files, which umask should they set?
How is the umask value expressed in UNIX systems?
How is the umask value expressed in UNIX systems?
What does the set-user-ID bit do when applied to a file?
What does the set-user-ID bit do when applied to a file?
Which member of the stat structure specifies the owner of a file?
Which member of the stat structure specifies the owner of a file?
What is the primary risk associated with set-user-ID programs?
What is the primary risk associated with set-user-ID programs?
How many permission bits are there for each file, and how are they categorized?
How many permission bits are there for each file, and how are they categorized?
What happens to the effective group ID of a process when executing a file with the set-group-ID bit set?
What happens to the effective group ID of a process when executing a file with the set-group-ID bit set?
What are the constants used to test the set-user-ID and set-group-ID bits in the file's mode?
What are the constants used to test the set-user-ID and set-group-ID bits in the file's mode?
Why is the passwd program designed to have the set-user-ID bit set?
Why is the passwd program designed to have the set-user-ID bit set?
Which file types can have access permissions applied to them?
Which file types can have access permissions applied to them?
What type of link is referenced by the st_nlink member in the stat structure?
What type of link is referenced by the st_nlink member in the stat structure?
What is the primitive system data type for link counts?
What is the primitive system data type for link counts?
Which of the following accurately describes a symbolic link?
Which of the following accurately describes a symbolic link?
What does the POSIX.1 constant LINK_MAX represent?
What does the POSIX.1 constant LINK_MAX represent?
Which command cannot create a new directory entry for a file in a different file system?
Which command cannot create a new directory entry for a file in a different file system?
What must occur to rename a file within the same file system?
What must occur to rename a file within the same file system?
What is stored in the directory entry as items of interest?
What is stored in the directory entry as items of interest?
What data type is used for the i-node number in a directory entry?
What data type is used for the i-node number in a directory entry?
What does a leaf directory's link count equal?
What does a leaf directory's link count equal?
What increases a parent directory's link count?
What increases a parent directory's link count?
Which i-node has a link count of 2?
Which i-node has a link count of 2?
What is the return value of the link and linkat functions when successful?
What is the return value of the link and linkat functions when successful?
What is the minimum link count of an i-node if it is a subdirectory?
What is the minimum link count of an i-node if it is a subdirectory?
What happens if the newpath already exists when using link or linkat?
What happens if the newpath already exists when using link or linkat?
Which of the following statements is true about the link count of directories?
Which of the following statements is true about the link count of directories?
What determines whether linkat follows a symbolic link or links to it directly?
What determines whether linkat follows a symbolic link or links to it directly?
What happens when a new directory is created?
What happens when a new directory is created?
Under what condition can a hard link to a directory be created?
Under what condition can a hard link to a directory be created?
What is the role of the 'dot-dot' entry in a directory?
What is the role of the 'dot-dot' entry in a directory?
What type of information do i-nodes store?
What type of information do i-nodes store?
What is necessary for the creation of a new directory entry using link or linkat?
What is necessary for the creation of a new directory entry using link or linkat?
What happens to pathnames that are relative when using linkat?
What happens to pathnames that are relative when using linkat?
Which of the following statements is true about the implementation of link and linkat functions?
Which of the following statements is true about the implementation of link and linkat functions?
What is an atomic operation in the context of creating a new directory entry with link or linkat?
What is an atomic operation in the context of creating a new directory entry with link or linkat?
A symbolic link creates a direct pointer to the i-node of a file.
A symbolic link creates a direct pointer to the i-node of a file.
Only superusers can create symbolic links to directories.
Only superusers can create symbolic links to directories.
Symbolic links can point to files located on different file systems without any limitations.
Symbolic links can point to files located on different file systems without any limitations.
In modern systems, the chown command does not follow symbolic links.
In modern systems, the chown command does not follow symbolic links.
The functions mkdir and rmdir return an error if the pathname is a symbolic link.
The functions mkdir and rmdir return an error if the pathname is a symbolic link.
Symbolic links were first introduced in 4.4BSD.
Symbolic links were first introduced in 4.4BSD.
Chown in older versions of Linux (before version 2.1.81) follows symbolic links.
Chown in older versions of Linux (before version 2.1.81) follows symbolic links.
The lchown function is implemented across all major platforms to change the ownership of symbolic links.
The lchown function is implemented across all major platforms to change the ownership of symbolic links.
The -u option in the ls command indicates the use of access time.
The -u option in the ls command indicates the use of access time.
Using the -c option with the ls command causes the command to use the creation time of a file.
Using the -c option with the ls command causes the command to use the creation time of a file.
Adding a file in a directory does not affect the parent directory's timestamps.
Adding a file in a directory does not affect the parent directory's timestamps.
The futimens function allows timestamps to be set with nanosecond precision.
The futimens function allows timestamps to be set with nanosecond precision.
The access time of a file is only modified when the file itself is written to.
The access time of a file is only modified when the file itself is written to.
Creating a new file only affects the i-node of that specific file.
Creating a new file only affects the i-node of that specific file.
The timespec structure is used by both the stat family of functions and the futimens function.
The timespec structure is used by both the stat family of functions and the futimens function.
The ls command with the -u and -c options can be used simultaneously.
The ls command with the -u and -c options can be used simultaneously.
The function futimens can be used to reset both last-access and last-modification times of a file.
The function futimens can be used to reset both last-access and last-modification times of a file.
The code in Figure 4.21 will result in a file size increase for 'changemod' and 'times'.
The code in Figure 4.21 will result in a file size increase for 'changemod' and 'times'.
The changed-status times for a file will remain unchanged after executing the program from Figure 4.21.
The changed-status times for a file will remain unchanged after executing the program from Figure 4.21.
The function stat retrieves information about a file, including its access and modification times.
The function stat retrieves information about a file, including its access and modification times.
The command 'ls -lc' shows only the last-modification times of the specified files.
The command 'ls -lc' shows only the last-modification times of the specified files.
To check the last-access times of files, one can use the command 'ls -lu'.
To check the last-access times of files, one can use the command 'ls -lu'.
The structure statbuf holds information after calling the stat function but does not contain the file size.
The structure statbuf holds information after calling the stat function but does not contain the file size.
The return value of the open function used in the code indicates the file is successfully opened for reading and writing.
The return value of the open function used in the code indicates the file is successfully opened for reading and writing.
The lstat
function can detect symbolic links while the stat
function cannot.
The lstat
function can detect symbolic links while the stat
function cannot.
The S_ISDIR
macro is used to determine if a file is a regular file.
The S_ISDIR
macro is used to determine if a file is a regular file.
The printf
function is used to display the type of file for each command-line argument in the code.
The printf
function is used to display the type of file for each command-line argument in the code.
The output of the provided code will indicate 'fifo' for the file type of /dev/log
.
The output of the provided code will indicate 'fifo' for the file type of /dev/log
.
Using the incorrect mode macros will yield the correct file type identification.
Using the incorrect mode macros will yield the correct file type identification.
The loop in the code iterates over command-line arguments starting from index 0.
The loop in the code iterates over command-line arguments starting from index 0.
The struct stat
is used to obtain detailed information regarding various file types.
The struct stat
is used to obtain detailed information regarding various file types.
The code uses a backslash at the end of the command line to specify that the line continues on the next line.
The code uses a backslash at the end of the command line to specify that the line continues on the next line.
The symlink function requires that the actualpath exists when creating a symbolic link.
The symlink function requires that the actualpath exists when creating a symbolic link.
The readlink function returns a null-terminated string when reading the contents of a symbolic link.
The readlink function returns a null-terminated string when reading the contents of a symbolic link.
The symlinkat function behaves identically to the symlink function if the fd argument is AT_FDCWD.
The symlinkat function behaves identically to the symlink function if the fd argument is AT_FDCWD.
The readlinkat function can return a different number of bytes based on the fd argument provided.
The readlinkat function can return a different number of bytes based on the fd argument provided.
Both symlink and symlinkat functions return the same error code when an error occurs.
Both symlink and symlinkat functions return the same error code when an error occurs.
The symlink function allows creating a symbolic link only within the same file system.
The symlink function allows creating a symbolic link only within the same file system.
The readlinkat function can evaluate its pathname argument relative to an open directory specified by a file descriptor.
The readlinkat function can evaluate its pathname argument relative to an open directory specified by a file descriptor.
Creating a symbolic link with the symlink function does not imply access rights to the actualpath.
Creating a symbolic link with the symlink function does not imply access rights to the actualpath.
The truncate function can only reduce the size of a file and cannot increase it.
The truncate function can only reduce the size of a file and cannot increase it.
When a file is truncated to a size smaller than its current size, the data beyond the new size becomes inaccessible.
When a file is truncated to a size smaller than its current size, the data beyond the new size becomes inaccessible.
The Solaris operating system includes an extension that allows freeing any part of a file, not just the end.
The Solaris operating system includes an extension that allows freeing any part of a file, not just the end.
For BSD releases prior to 4.4BSD, it was possible to increase the size of a file using the truncate function.
For BSD releases prior to 4.4BSD, it was possible to increase the size of a file using the truncate function.
The ftruncate function can only be used on files that are already open.
The ftruncate function can only be used on files that are already open.
An ftruncate call will result in increasing the file size if the new size is greater than the current file size.
An ftruncate call will result in increasing the file size if the new size is greater than the current file size.
An empty file can be created using the O_TRUNC flag with the open function.
An empty file can be created using the O_TRUNC flag with the open function.
The contents of a file become zeroed out only if it is truncated to a size larger than its original size.
The contents of a file become zeroed out only if it is truncated to a size larger than its original size.
Flashcards
symlink function
symlink function
Creates a symbolic link (shortcut) that points from one file or directory to another.
symlinkat function
symlinkat function
Similar to symlink, but the target path is relative to an open directory.
actualpath argument
actualpath argument
The path to the target file or directory.
sympath argument
sympath argument
Signup and view all the flashcards
readlink function
readlink function
Signup and view all the flashcards
readlinkat function
readlinkat function
Signup and view all the flashcards
AT_FDCWD
AT_FDCWD
Signup and view all the flashcards
Return value (symlink/symlinkat)
Return value (symlink/symlinkat)
Signup and view all the flashcards
Effective User ID
Effective User ID
Signup and view all the flashcards
Real User ID
Real User ID
Signup and view all the flashcards
Set-user-ID bit
Set-user-ID bit
Signup and view all the flashcards
Set-group-ID bit
Set-group-ID bit
Signup and view all the flashcards
st_uid
st_uid
Signup and view all the flashcards
st_gid
st_gid
Signup and view all the flashcards
st_mode
st_mode
Signup and view all the flashcards
File Access Permissions
File Access Permissions
Signup and view all the flashcards
umask
umask
Signup and view all the flashcards
umask value
umask value
Signup and view all the flashcards
How does umask affect file permissions?
How does umask affect file permissions?
Signup and view all the flashcards
Common umask values
Common umask values
Signup and view all the flashcards
Symbolic format for umask
Symbolic format for umask
Signup and view all the flashcards
Default umask value
Default umask value
Signup and view all the flashcards
Why modify umask in programs?
Why modify umask in programs?
Signup and view all the flashcards
Changing umask in a program
Changing umask in a program
Signup and view all the flashcards
Hard Link
Hard Link
Signup and view all the flashcards
Symbolic Link (Symlink)
Symbolic Link (Symlink)
Signup and view all the flashcards
What is the i-node?
What is the i-node?
Signup and view all the flashcards
What is the link count?
What is the link count?
Signup and view all the flashcards
How does renaming a file work internally?
How does renaming a file work internally?
Signup and view all the flashcards
Directory Link Count
Directory Link Count
Signup and view all the flashcards
Can links cross filesystems?
Can links cross filesystems?
Signup and view all the flashcards
What is the ln(1)
command?
What is the ln(1)
command?
Signup and view all the flashcards
Leaf Directory Link Count
Leaf Directory Link Count
Signup and view all the flashcards
Parent Directory Link Count
Parent Directory Link Count
Signup and view all the flashcards
i-node Type
i-node Type
Signup and view all the flashcards
What does 'mkdir testdir' do?
What does 'mkdir testdir' do?
Signup and view all the flashcards
What is the significance of the entries '.' and '..' in a directory?
What is the significance of the entries '.' and '..' in a directory?
Signup and view all the flashcards
What is the link count of the i-node for a directory with one subdirectory?
What is the link count of the i-node for a directory with one subdirectory?
Signup and view all the flashcards
How does the link count of a parent directory change when a subdirectory is created?
How does the link count of a parent directory change when a subdirectory is created?
Signup and view all the flashcards
What is the purpose of the link
function?
What is the purpose of the link
function?
Signup and view all the flashcards
What does the linkat
function do?
What does the linkat
function do?
Signup and view all the flashcards
Hard link vs. Symbolic link
Hard link vs. Symbolic link
Signup and view all the flashcards
What is the AT_SYMLINK_FOLLOW
flag?
What is the AT_SYMLINK_FOLLOW
flag?
Signup and view all the flashcards
What makes a link atomic?
What makes a link atomic?
Signup and view all the flashcards
What's a common limitation of hard links?
What's a common limitation of hard links?
Signup and view all the flashcards
Why is creating hard links to directories restricted?
Why is creating hard links to directories restricted?
Signup and view all the flashcards
Can you have hard links on network filesystems?
Can you have hard links on network filesystems?
Signup and view all the flashcards
Symbolic Link
Symbolic Link
Signup and view all the flashcards
How does symlinkat differ from symlink?
How does symlinkat differ from symlink?
Signup and view all the flashcards
What's the purpose of readlink and readlinkat?
What's the purpose of readlink and readlinkat?
Signup and view all the flashcards
Why might we use symlinkat instead of symlink?
Why might we use symlinkat instead of symlink?
Signup and view all the flashcards
lstat function
lstat function
Signup and view all the flashcards
S_ISxxx macros
S_ISxxx macros
Signup and view all the flashcards
stat function
stat function
Signup and view all the flashcards
Hard Link vs. Symlink
Hard Link vs. Symlink
Signup and view all the flashcards
File Types
File Types
Signup and view all the flashcards
How do you know a file is a symlink?
How do you know a file is a symlink?
Signup and view all the flashcards
What is the output of the code in Figure 4.3?
What is the output of the code in Figure 4.3?
Signup and view all the flashcards
File Truncation
File Truncation
Signup and view all the flashcards
truncate() function
truncate() function
Signup and view all the flashcards
ftruncate() function
ftruncate() function
Signup and view all the flashcards
i-node
i-node
Signup and view all the flashcards
Directory Entry
Directory Entry
Signup and view all the flashcards
File System
File System
Signup and view all the flashcards
Link Count
Link Count
Signup and view all the flashcards
What are the -u and -c options for the 'ls' command?
What are the -u and -c options for the 'ls' command?
Signup and view all the flashcards
How do file operations affect file times?
How do file operations affect file times?
Signup and view all the flashcards
What are 'futimens', 'utimensat', and 'utimes' functions?
What are 'futimens', 'utimensat', and 'utimes' functions?
Signup and view all the flashcards
How is a directory represented internally?
How is a directory represented internally?
Signup and view all the flashcards
What is the difference between hard links and symbolic links?
What is the difference between hard links and symbolic links?
Signup and view all the flashcards
What is the purpose of the link(2)
and linkat(2)
system calls?
What is the purpose of the link(2)
and linkat(2)
system calls?
Signup and view all the flashcards
futimens function
futimens function
Signup and view all the flashcards
timespec structure
timespec structure
Signup and view all the flashcards
How does futimens()
use stat()
?
How does futimens()
use stat()
?
Signup and view all the flashcards
What does O_TRUNC
do in open()
?
What does O_TRUNC
do in open()
?
Signup and view all the flashcards
What does O_RDWR
do in open()
?
What does O_RDWR
do in open()
?
Signup and view all the flashcards
How does futimens()
work with file access times?
How does futimens()
work with file access times?
Signup and view all the flashcards
How does futimens()
work with modification times?
How does futimens()
work with modification times?
Signup and view all the flashcards
Symbolic Link vs. Hard Link
Symbolic Link vs. Hard Link
Signup and view all the flashcards
Why can't hard links point to directories?
Why can't hard links point to directories?
Signup and view all the flashcards
What is the purpose of lchown
?
What is the purpose of lchown
?
Signup and view all the flashcards
What is the difference between stat
and lstat
?
What is the difference between stat
and lstat
?
Signup and view all the flashcards
How does chown
follow symbolic links?
How does chown
follow symbolic links?
Signup and view all the flashcards
What are some functions that do not follow symbolic links?
What are some functions that do not follow symbolic links?
Signup and view all the flashcards
Study Notes
Files and Directories
- Files are fundamental units of data storage, categorized by their type (regular files, directories, symbolic links, etc.).
- Regular files contain data of various formats (text, binary, executable).
- Directories contain filenames and pointers to other files, allowing organization.
- Symbolic links are pointers to other files, which can exist in different file systems.
- The stat function provides file attributes (size, permissions, owner, etc.).
stat
,fstat
,fstatat
, andlstat
are functions that return information about a file or a file descriptor based on various parameters.stat
function returns information about a file by its name.fstat
function returns information about a file by its file descriptor.lstat
function acts similarly to stat, but if the file is a symbolic link, it returns information about the symbolic link itself.fstatat
returns information about a file based on a file descriptor and pathname.- All four functions return 0 for success and -1 for failure.
File Types
- Regular file: stores data (text or binary).
- Directory file: organizes other files and directories.
- Block special file: provides buffered I/O for fixed-size units (like disk drives).
- Character special file: provides unbuffered I/O for variable-sized units (like terminals, serial ports).
- FIFO (named pipe): facilitates communication between processes.
- Socket: facilitates communication between processes, especially across networks.
File Access Permissions
- File access permissions control who can read, write, execute a file or a directory .
- Permissions are grouped into three categories: User, Group and Other.
- The
st_mode
value encodes the access permission bits. - The
umask
function sets the file mode creation mask. chmod
,fchmod
, andfchmodat
functions allow changing file access permissions of an existing file.chown
,fchown
,fchownat
, andlchown
functions allow modifying the owner and group ownership of files and directories.
File Times
- File times (
st_atim
,st_mtim
,st_ctim
) indicate last access, modification, and status change times, respectively, in seconds and nanoseconds.
Other File System Functions
link
,linkat
: Creates a new directory entry that points to an existing one (hard links).unlink
,unlinkat
: Removes a directory entry.remove
: Removes a file or directory, it’s identical to ‘unlink’ for files.rename
,renameat
: Renames a file or directory.mkdir
,mkdirat
: Creates a new directory.rmdir
: Removes an empty directory.opendir
,fdopendir
,readdir
,rewinddir
,closedir
,telldir
,seekdir
: provide functions for reading and traversing directories.getcwd
: Retrieves the absolute pathname of the current working directory.access
,faccessat
: Test file access permissions (read, write, execute) based on real/effective UID/GID.symlink
,symlinkat
: Creates a symbolic link to an existing file (the symbolic link can be in a different file system).readlink
,readlinkat
: Reads the value of a symbolic link.truncate
,ftruncate
: Truncates a file to a specified length. This is often used as a way to reset a file's size.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.