Files and Directories Quiz
95 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

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?

  • link
  • linkat
  • symlinkat (correct)
  • symlink
  • 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?

    <p>It behaves like readlink. (B)</p> Signup and view all the answers

    What is NOT a requirement for the actualpath when creating a symbolic link using symlink?

    <p>It must exist. (D)</p> Signup and view all the answers

    If symlink returns -1, what does it indicate?

    <p>There was an error in creating the symbolic link. (A)</p> Signup and view all the answers

    Which of the following is true about the contents returned by readlink and readlinkat?

    <p>They are not null terminated. (B)</p> Signup and view all the answers

    What determines the behavior of the symlinkat function when the fd argument is AT_FDCWD?

    <p>It behaves like symlink. (B)</p> Signup and view all the answers

    What is the purpose of the umask value in UNIX systems?

    <p>To control default file creation permissions (A)</p> Signup and view all the answers

    What happens to the umask value of a process when it creates a new file?

    <p>It does not affect the umask of the parent shell. (C)</p> Signup and view all the answers

    What does a umask of 022 prevent in terms of file permissions?

    <p>Group members from writing files (B)</p> Signup and view all the answers

    Which of the following is NOT a common umask value mentioned?

    <p>030 (B)</p> Signup and view all the answers

    Which format allows specifying permissions to be allowed with the umask command?

    <p>Symbolic format (C)</p> Signup and view all the answers

    If a user wants to prevent everyone from writing to their files, which umask should they set?

    <p>022 (B)</p> Signup and view all the answers

    How is the umask value expressed in UNIX systems?

    <p>As an octal number (C)</p> Signup and view all the answers

    What does the set-user-ID bit do when applied to a file?

    <p>It sets the effective user ID of the process to the file's owner when executed. (C)</p> Signup and view all the answers

    Which member of the stat structure specifies the owner of a file?

    <p>st_uid (D)</p> Signup and view all the answers

    What is the primary risk associated with set-user-ID programs?

    <p>They can grant unauthorized permissions if not written carefully. (C)</p> Signup and view all the answers

    How many permission bits are there for each file, and how are they categorized?

    <p>Nine permission bits, divided into user, group, and others. (A)</p> 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?

    <p>It becomes the group owner of the file being executed. (C)</p> 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?

    <p>S_ISUID and S_ISGID (D)</p> Signup and view all the answers

    Why is the passwd program designed to have the set-user-ID bit set?

    <p>To allow the program to write new passwords to restricted files. (B)</p> Signup and view all the answers

    Which file types can have access permissions applied to them?

    <p>All file types including directories and character special files. (D)</p> Signup and view all the answers

    What type of link is referenced by the st_nlink member in the stat structure?

    <p>Hard link (A)</p> Signup and view all the answers

    What is the primitive system data type for link counts?

    <p>nlink_t (C)</p> Signup and view all the answers

    Which of the following accurately describes a symbolic link?

    <p>Its file type in the i-node is S_IFLNK. (A)</p> Signup and view all the answers

    What does the POSIX.1 constant LINK_MAX represent?

    <p>The maximum link count a file can have (B)</p> Signup and view all the answers

    Which command cannot create a new directory entry for a file in a different file system?

    <p>ln(1) (C)</p> Signup and view all the answers

    What must occur to rename a file within the same file system?

    <p>Only a new directory entry needs to be added. (B)</p> Signup and view all the answers

    What is stored in the directory entry as items of interest?

    <p>Filename and i-node number (A)</p> Signup and view all the answers

    What data type is used for the i-node number in a directory entry?

    <p>ino_t (D)</p> Signup and view all the answers

    What does a leaf directory's link count equal?

    <p>2 (C)</p> Signup and view all the answers

    What increases a parent directory's link count?

    <p>Adding a subdirectory (B)</p> Signup and view all the answers

    Which i-node has a link count of 2?

    <p>The i-node for the testdir directory (B)</p> Signup and view all the answers

    What is the return value of the link and linkat functions when successful?

    <p>0 (B)</p> Signup and view all the answers

    What is the minimum link count of an i-node if it is a subdirectory?

    <p>3 (C)</p> Signup and view all the answers

    What happens if the newpath already exists when using link or linkat?

    <p>An error is returned. (B)</p> Signup and view all the answers

    Which of the following statements is true about the link count of directories?

    <p>Directories can have a variable link count based on their subdirectories. (B)</p> Signup and view all the answers

    What determines whether linkat follows a symbolic link or links to it directly?

    <p>The flag argument provided. (C)</p> Signup and view all the answers

    What happens when a new directory is created?

    <p>The new directory's i-node gets a link count of 2. (A)</p> Signup and view all the answers

    Under what condition can a hard link to a directory be created?

    <p>When the superuser creates it. (C)</p> Signup and view all the answers

    What is the role of the 'dot-dot' entry in a directory?

    <p>To reference the parent directory (A)</p> Signup and view all the answers

    What type of information do i-nodes store?

    <p>File metadata such as size and type (D)</p> Signup and view all the answers

    What is necessary for the creation of a new directory entry using link or linkat?

    <p>The rest of the newpath must already exist. (D)</p> Signup and view all the answers

    What happens to pathnames that are relative when using linkat?

    <p>They are evaluated relative to the file descriptor. (B)</p> Signup and view all the answers

    Which of the following statements is true about the implementation of link and linkat functions?

    <p>Both pathnames must be on the same file system. (D)</p> Signup and view all the answers

    What is an atomic operation in the context of creating a new directory entry with link or linkat?

    <p>The increment of the link count and entry creation must succeed or fail together. (C)</p> Signup and view all the answers

    A symbolic link creates a direct pointer to the i-node of a file.

    <p>False (B)</p> Signup and view all the answers

    Only superusers can create symbolic links to directories.

    <p>False (B)</p> Signup and view all the answers

    Symbolic links can point to files located on different file systems without any limitations.

    <p>True (A)</p> Signup and view all the answers

    In modern systems, the chown command does not follow symbolic links.

    <p>False (B)</p> Signup and view all the answers

    The functions mkdir and rmdir return an error if the pathname is a symbolic link.

    <p>True (A)</p> Signup and view all the answers

    Symbolic links were first introduced in 4.4BSD.

    <p>False (B)</p> Signup and view all the answers

    Chown in older versions of Linux (before version 2.1.81) follows symbolic links.

    <p>False (B)</p> Signup and view all the answers

    The lchown function is implemented across all major platforms to change the ownership of symbolic links.

    <p>True (A)</p> Signup and view all the answers

    The -u option in the ls command indicates the use of access time.

    <p>True (A)</p> 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.

    <p>False (B)</p> Signup and view all the answers

    Adding a file in a directory does not affect the parent directory's timestamps.

    <p>False (B)</p> Signup and view all the answers

    The futimens function allows timestamps to be set with nanosecond precision.

    <p>True (A)</p> Signup and view all the answers

    The access time of a file is only modified when the file itself is written to.

    <p>False (B)</p> Signup and view all the answers

    Creating a new file only affects the i-node of that specific file.

    <p>False (B)</p> Signup and view all the answers

    The timespec structure is used by both the stat family of functions and the futimens function.

    <p>True (A)</p> Signup and view all the answers

    The ls command with the -u and -c options can be used simultaneously.

    <p>True (A)</p> Signup and view all the answers

    The function futimens can be used to reset both last-access and last-modification times of a file.

    <p>True (A)</p> Signup and view all the answers

    The code in Figure 4.21 will result in a file size increase for 'changemod' and 'times'.

    <p>False (B)</p> Signup and view all the answers

    The changed-status times for a file will remain unchanged after executing the program from Figure 4.21.

    <p>False (B)</p> Signup and view all the answers

    The function stat retrieves information about a file, including its access and modification times.

    <p>True (A)</p> Signup and view all the answers

    The command 'ls -lc' shows only the last-modification times of the specified files.

    <p>False (B)</p> Signup and view all the answers

    To check the last-access times of files, one can use the command 'ls -lu'.

    <p>True (A)</p> Signup and view all the answers

    The structure statbuf holds information after calling the stat function but does not contain the file size.

    <p>False (B)</p> 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.

    <p>True (A)</p> Signup and view all the answers

    The lstat function can detect symbolic links while the stat function cannot.

    <p>True (A)</p> Signup and view all the answers

    The S_ISDIR macro is used to determine if a file is a regular file.

    <p>False (B)</p> 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.

    <p>True (A)</p> Signup and view all the answers

    The output of the provided code will indicate 'fifo' for the file type of /dev/log.

    <p>False (B)</p> Signup and view all the answers

    Using the incorrect mode macros will yield the correct file type identification.

    <p>False (B)</p> Signup and view all the answers

    The loop in the code iterates over command-line arguments starting from index 0.

    <p>False (B)</p> Signup and view all the answers

    The struct stat is used to obtain detailed information regarding various file types.

    <p>True (A)</p> 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.

    <p>True (A)</p> Signup and view all the answers

    The symlink function requires that the actualpath exists when creating a symbolic link.

    <p>False (B)</p> Signup and view all the answers

    The readlink function returns a null-terminated string when reading the contents of a symbolic link.

    <p>False (B)</p> Signup and view all the answers

    The symlinkat function behaves identically to the symlink function if the fd argument is AT_FDCWD.

    <p>True (A)</p> Signup and view all the answers

    The readlinkat function can return a different number of bytes based on the fd argument provided.

    <p>True (A)</p> Signup and view all the answers

    Both symlink and symlinkat functions return the same error code when an error occurs.

    <p>True (A)</p> Signup and view all the answers

    The symlink function allows creating a symbolic link only within the same file system.

    <p>False (B)</p> Signup and view all the answers

    The readlinkat function can evaluate its pathname argument relative to an open directory specified by a file descriptor.

    <p>True (A)</p> Signup and view all the answers

    Creating a symbolic link with the symlink function does not imply access rights to the actualpath.

    <p>True (A)</p> Signup and view all the answers

    The truncate function can only reduce the size of a file and cannot increase it.

    <p>False (B)</p> 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.

    <p>True (A)</p> 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.

    <p>True (A)</p> 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.

    <p>False (B)</p> Signup and view all the answers

    The ftruncate function can only be used on files that are already open.

    <p>True (A)</p> 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.

    <p>True (A)</p> Signup and view all the answers

    An empty file can be created using the O_TRUNC flag with the open function.

    <p>True (A)</p> 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.

    <p>False (B)</p> Signup and view all the answers

    Flashcards

    symlink function

    Creates a symbolic link (shortcut) that points from one file or directory to another.

    symlinkat function

    Similar to symlink, but the target path is relative to an open directory.

    actualpath argument

    The path to the target file or directory.

    sympath argument

    The path to the symbolic link itself.

    Signup and view all the flashcards

    readlink function

    Reads the target path of a symbolic link.

    Signup and view all the flashcards

    readlinkat function

    Similar to readlink, but the path is relative to an open directory.

    Signup and view all the flashcards

    AT_FDCWD

    Special value for the fd argument, treating the pathname as absolute.

    Signup and view all the flashcards

    Return value (symlink/symlinkat)

    0 for success, -1 for failure.

    Signup and view all the flashcards

    Effective User ID

    The user ID a process uses when accessing resources.

    Signup and view all the flashcards

    Real User ID

    The actual user ID of the user running the program.

    Signup and view all the flashcards

    Set-user-ID bit

    A flag in a file's mode that changes the effective user ID during execution.

    Signup and view all the flashcards

    Set-group-ID bit

    Similar to set-user-ID, but for group permissions.

    Signup and view all the flashcards

    st_uid

    The owner's user ID of a file (stored in stat struct).

    Signup and view all the flashcards

    st_gid

    The group owner's ID of a file (in stat struct).

    Signup and view all the flashcards

    st_mode

    File's mode word containing access permissions and special flags.

    Signup and view all the flashcards

    File Access Permissions

    Rules governing who can read, write, and execute a file.

    Signup and view all the flashcards

    umask

    A file creation mask used to control the default permissions of new files. It specifies which permissions are denied.

    Signup and view all the flashcards

    umask value

    The octal value representing the file creation mask. Each bit corresponds to a specific permission to be masked off.

    Signup and view all the flashcards

    How does umask affect file permissions?

    The umask value is subtracted from the default permissions of a new file to determine its final permissions.

    Signup and view all the flashcards

    Common umask values

    002: Prevents others from writing. 022: Prevents group members and others from writing. 027: Prevents group members from writing and others from reading, writing, or executing.

    Signup and view all the flashcards

    Symbolic format for umask

    Specifies which permissions are allowed instead of which ones are denied, using operators like 'a', 'u', 'g', 'o', '+', '-', '='.

    Signup and view all the flashcards

    Default umask value

    Usually set once on login by the shell's start-up file and rarely changed.

    Signup and view all the flashcards

    Why modify umask in programs?

    To ensure specific access permissions are granted for newly created files, especially if default permissions are restrictive.

    Signup and view all the flashcards

    Changing umask in a program

    Changing the process's umask only affects the process itself, not its parent (like the shell).

    Signup and view all the flashcards

    Hard Link

    A direct pointer to a file's i-node, allowing multiple names for the same file data.

    Signup and view all the flashcards

    Symbolic Link (Symlink)

    A special file that stores the path to another file, making it a shortcut to the linked file.

    Signup and view all the flashcards

    What is the i-node?

    A data structure containing information about a file, including its type, permissions, size, and data block pointers.

    Signup and view all the flashcards

    What is the link count?

    The number of directory entries that point to a file's i-node, indicating how many names it has.

    Signup and view all the flashcards

    How does renaming a file work internally?

    Renaming a file on the same filesystem only requires updating directory entries, not moving the file data itself.

    Signup and view all the flashcards

    Directory Link Count

    Indicates the number of files and subdirectories within a directory, including itself.

    Signup and view all the flashcards

    Can links cross filesystems?

    Hard links can't cross filesystems, but symbolic links can link to files on different filesystems.

    Signup and view all the flashcards

    What is the ln(1) command?

    The ln(1) command is used to create a hard link to an existing file, making a new directory entry pointing to its i-node.

    Signup and view all the flashcards

    Leaf Directory Link Count

    A leaf directory is a directory that doesn't contain any subdirectories. It always has a link count of 2, one for itself (.) and another for its parent (.).

    Signup and view all the flashcards

    Parent Directory Link Count

    Each subdirectory you create inside a parent directory increases the parent's link count by 1. This is because each subdirectory points to the parent directory.

    Signup and view all the flashcards

    i-node Type

    A field in the i-node that identifies what kind of file or directory it is.

    Signup and view all the flashcards

    What does 'mkdir testdir' do?

    Creates a new directory named 'testdir' within the current working directory.

    Signup and view all the flashcards

    What is the significance of the entries '.' and '..' in a directory?

    The '.' entry represents the current directory, while the '..' entry points to the parent directory. They are crucial for navigating the file system.

    Signup and view all the flashcards

    What is the link count of the i-node for a directory with one subdirectory?

    The link count would be at least 3. This includes the entry for itself (.), its parent directory (..), and the entry for the subdirectory.

    Signup and view all the flashcards

    How does the link count of a parent directory change when a subdirectory is created?

    The parent directory's link count increases by 1 because the newly created subdirectory points to the parent.

    Signup and view all the flashcards

    What is the purpose of the link function?

    The link function creates a hard link, a new directory entry that points to an existing file. If the new path already exists, an error is returned. Only the last component of the new path is created. The rest of the path must already exist.

    Signup and view all the flashcards

    What does the linkat function do?

    The linkat function is similar to link, but it uses file descriptors to specify the existing and new paths. It allows for more flexibility, like specifying paths relative to an open directory. It also lets you control whether a link is created to a symbolic link or its target.

    Signup and view all the flashcards

    Hard link vs. Symbolic link

    A hard link creates a new directory entry that references the same file inode as the original. If the original file is deleted, the hard link will still point to the data. A symbolic link (symlink) creates a file that contains the path to the original file. If the original file is deleted, the symlink will become broken.

    Signup and view all the flashcards

    What is the AT_SYMLINK_FOLLOW flag?

    This flag for the linkat function determines the behavior when creating a link to a symlink. If set, the link will point to the target of the symlink. If not, the link will point to the symlink itself.

    Signup and view all the flashcards

    What makes a link atomic?

    The creation of the new directory entry and the increment of the link count are an atomic operation meaning it happens all at once or not at all. This prevents inconsistencies if an error occurs. In simpler terms, the link is either fully created or not at all.

    Signup and view all the flashcards

    What's a common limitation of hard links?

    Typically, hard links must be created within the same file system. This is because different file systems have their own way of managing files and linking between different file systems is often not supported.

    Signup and view all the flashcards

    Why is creating hard links to directories restricted?

    Creating a hard link to a directory can create loops in the file system which can lead to inconsistencies and break file system utilities. These loops can cause the system to think that a directory is both a parent and child of itself. This can result in infinite recursion when trying to read or write data to these directories.

    Signup and view all the flashcards

    Can you have hard links on network filesystems?

    It depends on the specific network filesystem implementation. Some network filesystems may allow creating hard links across different machines. This can be problematic because hard links are a very low-level concept and may not work well with how files are handled on network filesystems.

    Signup and view all the flashcards

    Symbolic Link

    A file that points to another file or directory. It's like a shortcut.

    Signup and view all the flashcards

    How does symlinkat differ from symlink?

    symlinkat lets you create symbolic links relative to an open directory, while symlink creates them based on absolute paths.

    Signup and view all the flashcards

    What's the purpose of readlink and readlinkat?

    They help reveal the target path hidden behind a symbolic link, acting like a 'look-behind-the-shortcut' function.

    Signup and view all the flashcards

    Why might we use symlinkat instead of symlink?

    Symlinkat is useful for creating links relative to an open directory, providing finer control over link creation location.

    Signup and view all the flashcards

    lstat function

    The lstat() function provides information about a file, including its type, size, permissions, and ownership. It handles symbolic links differently than the stat() function, returning information for the link itself, not its target.

    Signup and view all the flashcards

    S_ISxxx macros

    These macros (e.g., S_ISREG, S_ISDIR) help determine the type of file. They extract the file type and compare it to a predefined value, allowing you to identify whether a file is a regular file, directory, symbolic link, etc.

    Signup and view all the flashcards

    stat function

    The stat() function provides information about a file, including its type, size, permissions, and ownership. It follows symbolic links and returns information about the linked file's target.

    Signup and view all the flashcards

    Hard Link vs. Symlink

    A hard link creates a direct reference to a file's data. A symbolic link stores the path to another file. If the original file is deleted, a hard link still points to the data. A symbolic link becomes broken.

    Signup and view all the flashcards

    File Types

    Files on a Unix system can be classified into different types, including regular files, directories, symbolic links, character special files, block special files, FIFOs, and sockets, each serving a different purpose.

    Signup and view all the flashcards

    How do you know a file is a symlink?

    You can determine if a file is a symbolic link by looking at its file type. This can be achieved using the stat() or lstat() functions, which provide information about a file, including its type.

    Signup and view all the flashcards

    What is the output of the code in Figure 4.3?

    The code in Figure 4.3 prints the type of each file passed as a command-line argument. It uses the lstat() function to identify the file type and then prints the corresponding description (regular, directory, symbolic link, etc.). The output is a list of the file names followed by their respective file types.

    Signup and view all the flashcards

    File Truncation

    The process of reducing the size of a file by removing data from the end, making the data beyond the new length inaccessible.

    Signup and view all the flashcards

    truncate() function

    A function that truncates a file to a specified length, reducing the file's size.

    Signup and view all the flashcards

    ftruncate() function

    This function is similar to truncate(), but it operates on an open file descriptor instead of a file path.

    Signup and view all the flashcards

    i-node

    A data structure that holds crucial information about a file, such as its permissions, size, and location on disk.

    Signup and view all the flashcards

    Directory Entry

    A record within a directory that points to an i-node, effectively linking a filename to its file.

    Signup and view all the flashcards

    File System

    A hierarchical structure that organizes files and directories, enabling efficient storage and retrieval.

    Signup and view all the flashcards

    Link Count

    The number of directory entries that point to a file's i-node, representing the number of names a file has.

    Signup and view all the flashcards

    What are the -u and -c options for the 'ls' command?

    The -u option tells 'ls' to display the access time of files, while the -c option displays the changed-status time. These options provide more detailed information about file modification.

    Signup and view all the flashcards

    How do file operations affect file times?

    Operations like creating, deleting, or modifying file entries in a directory affect the access, modification, and changed-status times of both the file and the parent directory. Reading or writing a file only affects the file's i-node.

    Signup and view all the flashcards

    What are 'futimens', 'utimensat', and 'utimes' functions?

    These functions allow you to modify the access and modification times of files. They use the 'timespec' structure to provide nanosecond precision.

    Signup and view all the flashcards

    How is a directory represented internally?

    A directory is essentially a file that holds entries. Each entry lists a filename and its corresponding i-node number, which points to the data for that file.

    Signup and view all the flashcards

    What is the difference between hard links and symbolic links?

    Hard links point directly to the i-node of the file, allowing the same file data to be accessed through multiple file names. Symbolic links are files containing a path to another file, creating a shortcut. Deleting the original file breaks a symbolic link, but doesn't affect a hard link.

    Signup and view all the flashcards

    What is the purpose of the link(2) and linkat(2) system calls?

    The link(2) call creates a hard link to an existing file. The linkat(2) call is similar but uses file descriptors, offering more flexibility to specify paths relative to an open directory. Both ensure atomicity, meaning the link is created fully or not at all.

    Signup and view all the flashcards

    futimens function

    The futimens() function is a system call that allows you to set the access and modification times of a file. It uses two timespec structures to provide both access and modification times, giving precise control.

    Signup and view all the flashcards

    timespec structure

    The timespec structure is used to represent a point in time, containing two fields: tv_sec (seconds) and tv_nsec (nanoseconds). It's used to specify the timestamp for the access and modification times.

    Signup and view all the flashcards

    How does futimens() use stat()?

    The futimens() function first uses the stat() function to retrieve the current access and modification times of a file. Then, it updates these times using the new times provided in its parameters.

    Signup and view all the flashcards

    What does O_TRUNC do in open()?

    The O_TRUNC flag in the open() function ensures that if the file already exists when you open it, it will be truncated (emptied) and its size will be set to 0.

    Signup and view all the flashcards

    What does O_RDWR do in open()?

    The O_RDWR flag in the open() function allows you to open a file for both reading and writing. This grants you full access to modify its data.

    Signup and view all the flashcards

    How does futimens() work with file access times?

    The futimens() function sets the access time (the last time the file was accessed) of a file without actually accessing it. This means you can update the time stamp without the file being read or written.

    Signup and view all the flashcards

    How does futimens() work with modification times?

    The futimens() function sets the modification time (the last time the file was modified) of a file. If you only want to set the modification time, the utime() function is an alternative option.

    Signup and view all the flashcards

    Symbolic Link vs. Hard Link

    Symbolic links point to a file's location while hard links point to the file's i-node. Symbolic links can be broken if the target file is deleted, while hard links preserve access even if the original file is deleted.

    Signup and view all the flashcards

    Why can't hard links point to directories?

    Creating hard links to directories can cause loops in the file system, leading to potential errors and inconsistencies. File system utilities might break.

    Signup and view all the flashcards

    What is the purpose of lchown?

    The lchown function changes the ownership of a symbolic link itself, not the file it points to. This allows you to modify the permissions of the symbolic link file.

    Signup and view all the flashcards

    What is the difference between stat and lstat?

    stat follows symbolic links and returns information about the linked file. lstat returns information about the symbolic link itself.

    Signup and view all the flashcards

    How does chown follow symbolic links?

    The chown function follows symbolic links to change the ownership of the linked file. This means, changing the owner of the file pointed by the symbolic link.

    Signup and view all the flashcards

    What are some functions that do not follow symbolic links?

    Functions like mkdir, mkfifo, mknod, and rmdir return an error when given a symbolic link as a pathname argument. Also, the functions that take a file descriptor argument like fstat and fchmod 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, and lstat 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, and fchmodat functions allow changing file access permissions of an existing file.
    • chown, fchown, fchownat , and lchown 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.

    Quiz Team

    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.

    More Like This

    Use Quizgecko on...
    Browser
    Browser