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.</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.</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.</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.</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.</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</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.</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</p> Signup and view all the answers

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

    <p>030</p> Signup and view all the answers

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

    <p>Symbolic format</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</p> Signup and view all the answers

    How is the umask value expressed in UNIX systems?

    <p>As an octal number</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.</p> Signup and view all the answers

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

    <p>st_uid</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.</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.</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.</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</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.</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.</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</p> Signup and view all the answers

    What is the primitive system data type for link counts?

    <p>nlink_t</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.</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</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)</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.</p> Signup and view all the answers

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

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

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

    <p>ino_t</p> Signup and view all the answers

    What does a leaf directory's link count equal?

    <p>2</p> Signup and view all the answers

    What increases a parent directory's link count?

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

    Which i-node has a link count of 2?

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

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

    <p>0</p> Signup and view all the answers

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

    <p>3</p> Signup and view all the answers

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

    <p>An error is returned.</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.</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.</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.</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.</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</p> Signup and view all the answers

    What type of information do i-nodes store?

    <p>File metadata such as size and type</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.</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.</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.</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.</p> Signup and view all the answers

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

    <p>False</p> Signup and view all the answers

    Only superusers can create symbolic links to directories.

    <p>False</p> Signup and view all the answers

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

    <p>True</p> Signup and view all the answers

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

    <p>False</p> Signup and view all the answers

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

    <p>True</p> Signup and view all the answers

    Symbolic links were first introduced in 4.4BSD.

    <p>False</p> Signup and view all the answers

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

    <p>False</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</p> Signup and view all the answers

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

    <p>True</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</p> Signup and view all the answers

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

    <p>False</p> Signup and view all the answers

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

    <p>True</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</p> Signup and view all the answers

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

    <p>False</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</p> Signup and view all the answers

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

    <p>True</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</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</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</p> Signup and view all the answers

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

    <p>True</p> Signup and view all the answers

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

    <p>False</p> Signup and view all the answers

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

    <p>True</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</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</p> Signup and view all the answers

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

    <p>True</p> Signup and view all the answers

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

    <p>False</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</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</p> Signup and view all the answers

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

    <p>False</p> Signup and view all the answers

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

    <p>False</p> Signup and view all the answers

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

    <p>True</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</p> Signup and view all the answers

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

    <p>False</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</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</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</p> Signup and view all the answers

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

    <p>True</p> Signup and view all the answers

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

    <p>False</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</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</p> Signup and view all the answers

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

    <p>False</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</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</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</p> Signup and view all the answers

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

    <p>True</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</p> Signup and view all the answers

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

    <p>True</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</p> 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, 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