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?
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?
What do readlink and readlinkat functions return when executed successfully?
What do readlink and readlinkat functions return when executed successfully?
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?
Signup and view all the answers
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?
Signup and view all the answers
If symlink returns -1, what does it indicate?
If symlink returns -1, what does it indicate?
Signup and view all the answers
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?
Signup and view all the answers
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?
Signup and view all the answers
What is the purpose of the umask value in UNIX systems?
What is the purpose of the umask value in UNIX systems?
Signup and view all the answers
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?
Signup and view all the answers
What does a umask of 022 prevent in terms of file permissions?
What does a umask of 022 prevent in terms of file permissions?
Signup and view all the answers
Which of the following is NOT a common umask value mentioned?
Which of the following is NOT a common umask value mentioned?
Signup and view all the answers
Which format allows specifying permissions to be allowed with the umask command?
Which format allows specifying permissions to be allowed with the umask command?
Signup and view all the answers
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?
Signup and view all the answers
How is the umask value expressed in UNIX systems?
How is the umask value expressed in UNIX systems?
Signup and view all the answers
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?
Signup and view all the answers
Which member of the stat structure specifies the owner of a file?
Which member of the stat structure specifies the owner of a file?
Signup and view all the answers
What is the primary risk associated with set-user-ID programs?
What is the primary risk associated with set-user-ID programs?
Signup and view all the answers
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?
Signup and view all the answers
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?
Signup and view all the answers
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?
Signup and view all the answers
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?
Signup and view all the answers
Which file types can have access permissions applied to them?
Which file types can have access permissions applied to them?
Signup and view all the answers
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?
Signup and view all the answers
What is the primitive system data type for link counts?
What is the primitive system data type for link counts?
Signup and view all the answers
Which of the following accurately describes a symbolic link?
Which of the following accurately describes a symbolic link?
Signup and view all the answers
What does the POSIX.1 constant LINK_MAX represent?
What does the POSIX.1 constant LINK_MAX represent?
Signup and view all the answers
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?
Signup and view all the answers
What must occur to rename a file within the same file system?
What must occur to rename a file within the same file system?
Signup and view all the answers
What is stored in the directory entry as items of interest?
What is stored in the directory entry as items of interest?
Signup and view all the answers
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?
Signup and view all the answers
What does a leaf directory's link count equal?
What does a leaf directory's link count equal?
Signup and view all the answers
What increases a parent directory's link count?
What increases a parent directory's link count?
Signup and view all the answers
Which i-node has a link count of 2?
Which i-node has a link count of 2?
Signup and view all the answers
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?
Signup and view all the answers
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?
Signup and view all the answers
What happens if the newpath already exists when using link or linkat?
What happens if the newpath already exists when using link or linkat?
Signup and view all the answers
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?
Signup and view all the answers
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?
Signup and view all the answers
What happens when a new directory is created?
What happens when a new directory is created?
Signup and view all the answers
Under what condition can a hard link to a directory be created?
Under what condition can a hard link to a directory be created?
Signup and view all the answers
What is the role of the 'dot-dot' entry in a directory?
What is the role of the 'dot-dot' entry in a directory?
Signup and view all the answers
What type of information do i-nodes store?
What type of information do i-nodes store?
Signup and view all the answers
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?
Signup and view all the answers
What happens to pathnames that are relative when using linkat?
What happens to pathnames that are relative when using linkat?
Signup and view all the answers
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?
Signup and view all the answers
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?
Signup and view all the answers
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.
Signup and view all the answers
Only superusers can create symbolic links to directories.
Only superusers can create symbolic links to directories.
Signup and view all the answers
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.
Signup and view all the answers
In modern systems, the chown command does not follow symbolic links.
In modern systems, the chown command does not follow symbolic links.
Signup and view all the answers
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.
Signup and view all the answers
Symbolic links were first introduced in 4.4BSD.
Symbolic links were first introduced in 4.4BSD.
Signup and view all the answers
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.
Signup and view all the answers
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.
Signup and view all the answers
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.
Signup and view all the answers
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.
Signup and view all the answers
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.
Signup and view all the answers
The futimens function allows timestamps to be set with nanosecond precision.
The futimens function allows timestamps to be set with nanosecond precision.
Signup and view all the answers
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.
Signup and view all the answers
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.
Signup and view all the answers
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.
Signup and view all the answers
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.
Signup and view all the answers
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.
Signup and view all the answers
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'.
Signup and view all the answers
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.
Signup and view all the answers
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.
Signup and view all the answers
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.
Signup and view all the answers
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'.
Signup and view all the answers
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.
Signup and view all the answers
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.
Signup and view all the answers
The lstat
function can detect symbolic links while the stat
function cannot.
The lstat
function can detect symbolic links while the stat
function cannot.
Signup and view all the answers
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.
Signup and view all the answers
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.
Signup and view all the answers
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
.
Signup and view all the answers
Using the incorrect mode macros will yield the correct file type identification.
Using the incorrect mode macros will yield the correct file type identification.
Signup and view all the answers
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.
Signup and view all the answers
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.
Signup and view all the answers
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.
Signup and view all the answers
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.
Signup and view all the answers
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.
Signup and view all the answers
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.
Signup and view all the answers
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.
Signup and view all the answers
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.
Signup and view all the answers
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.
Signup and view all the answers
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.
Signup and view all the answers
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.
Signup and view all the answers
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.
Signup and view all the answers
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.
Signup and view all the answers
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.
Signup and view all the answers
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.
Signup and view all the answers
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.
Signup and view all the answers
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.
Signup and view all the answers
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.
Signup and view all the answers
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.
Signup and view all the answers
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.
Related Documents
Description
Test your knowledge of files and directories, including their types such as regular files, directories, and symbolic links. This quiz covers important functions like stat, fstat, and lstat that provide key file attributes. Dive into the essential concepts of data organization and storage in computing.