Podcast
Questions and Answers
The file with holes consumes only ______ disk blocks.
The file with holes consumes only ______ disk blocks.
8
The file without holes consumes ______ disk blocks.
The file without holes consumes ______ disk blocks.
20
The size of the offset address that lseek uses is represented by a ______.
The size of the offset address that lseek uses is represented by a ______.
off_t
Most platforms provide one set of interfaces that uses ______-bit file offsets.
Most platforms provide one set of interfaces that uses ______-bit file offsets.
Signup and view all the answers
The Single UNIX Specification allows applications to determine supported environments through the ______ function.
The Single UNIX Specification allows applications to determine supported environments through the ______ function.
Signup and view all the answers
The ______ compiler requires the use of the getconf command to map data size models.
The ______ compiler requires the use of the getconf command to map data size models.
Signup and view all the answers
To enable 64-bit offsets, applications can set the ______ constant to 64.
To enable 64-bit offsets, applications can set the ______ constant to 64.
Signup and view all the answers
Different flags and libraries might be needed, depending on the supported ______.
Different flags and libraries might be needed, depending on the supported ______.
Signup and view all the answers
When interrupted by a signal and a partial amount of data has already been ______.
When interrupted by a signal and a partial amount of data has already been ______.
Signup and view all the answers
The classic definition of the read function includes the prototype 'int read(int fd, char *buf, unsigned ______)'.
The classic definition of the read function includes the prototype 'int read(int fd, char *buf, unsigned ______)'.
Signup and view all the answers
POSIX.1 changed the prototype for the read function from char * to ______ *.
POSIX.1 changed the prototype for the read function from char * to ______ *.
Signup and view all the answers
The return value of the read function is required to be of type ______.
The return value of the read function is required to be of type ______.
Signup and view all the answers
Data is written to an open file with the ______ function.
Data is written to an open file with the ______ function.
Signup and view all the answers
The write function has a prototype that includes 'ssize_t write(int fd, const void *buf, size_t ______)'.
The write function has a prototype that includes 'ssize_t write(int fd, const void *buf, size_t ______)'.
Signup and view all the answers
The return value of a successful write operation is usually equal to the ______ argument.
The return value of a successful write operation is usually equal to the ______ argument.
Signup and view all the answers
If the O_APPEND option was specified when the file was opened, the file's offset is set to the current ______ of file before each write operation.
If the O_APPEND option was specified when the file was opened, the file's offset is set to the current ______ of file before each write operation.
Signup and view all the answers
Setting FILE_OFFSET_BITS to 32 enables 32-bit file offsets.
Setting FILE_OFFSET_BITS to 32 enables 32-bit file offsets.
Signup and view all the answers
The off_t data type is typically a 64-bit signed integer if defined appropriately.
The off_t data type is typically a 64-bit signed integer if defined appropriately.
Signup and view all the answers
Even when enabling 64-bit file offsets, creating a file larger than 2 GB depends on the file system.
Even when enabling 64-bit file offsets, creating a file larger than 2 GB depends on the file system.
Signup and view all the answers
The read function is used to read data from an open file.
The read function is used to read data from an open file.
Signup and view all the answers
If the end of file is encountered, read returns 0.
If the end of file is encountered, read returns 0.
Signup and view all the answers
Reading from a terminal device normally retrieves up to one line at a time.
Reading from a terminal device normally retrieves up to one line at a time.
Signup and view all the answers
Buffering within the network may cause less than the requested amount to be returned.
Buffering within the network may cause less than the requested amount to be returned.
Signup and view all the answers
When reading from a pipe or FIFO, read will return only what is available.
When reading from a pipe or FIFO, read will return only what is available.
Signup and view all the answers
Set the file descriptor flags for fd. The new flag value is set from the third argument taken as an ______.
Set the file descriptor flags for fd. The new flag value is set from the third argument taken as an ______.
Signup and view all the answers
The file status flags can be returned for fd by using the F_GETFL function, which describes the file status flags when we used the ______ function.
The file status flags can be returned for fd by using the F_GETFL function, which describes the file status flags when we used the ______ function.
Signup and view all the answers
The access-mode flags O_RDONLY, O_WRONLY, O_RDWR, O_EXEC, and O_SEARCH are mutually ______.
The access-mode flags O_RDONLY, O_WRONLY, O_RDWR, O_EXEC, and O_SEARCH are mutually ______.
Signup and view all the answers
First, we must use the O_ACCMODE mask to obtain the access-mode bits before comparing them against any of the five ______.
First, we must use the O_ACCMODE mask to obtain the access-mode bits before comparing them against any of the five ______.
Signup and view all the answers
Set the file status flags to the value of the third argument by using the ______ function.
Set the file status flags to the value of the third argument by using the ______ function.
Signup and view all the answers
The SIGIO and SIGURG signals can be received by a process ID or process group ID by using the F_______ function.
The SIGIO and SIGURG signals can be received by a process ID or process group ID by using the F_______ function.
Signup and view all the answers
A positive argument in F_SETOWN specifies a process ID, whereas a negative argument implies a process ______ ID.
A positive argument in F_SETOWN specifies a process ID, whereas a negative argument implies a process ______ ID.
Signup and view all the answers
The return value from fcntl depends on the command, with special return values for F_DUPFD, F_GETFD, F_GETFL, and F_GET______.
The return value from fcntl depends on the command, with special return values for F_DUPFD, F_GETFD, F_GETFL, and F_GET______.
Signup and view all the answers
Synchronous writes are far more expensive than _____ writes.
Synchronous writes are far more expensive than _____ writes.
Signup and view all the answers
The performance of each alternative will depend on many factors, including the underlying operating system implementation and the speed of the _____ drive.
The performance of each alternative will depend on many factors, including the underlying operating system implementation and the speed of the _____ drive.
Signup and view all the answers
The _____ function has always been the catchall for I/O operations.
The _____ function has always been the catchall for I/O operations.
Signup and view all the answers
The performance of fsync and fdatasync can be influenced by the type of _____ system.
The performance of fsync and fdatasync can be influenced by the type of _____ system.
Signup and view all the answers
With the fcntl function, we can modify the properties of a descriptor while knowing only the _____ for the open file.
With the fcntl function, we can modify the properties of a descriptor while knowing only the _____ for the open file.
Signup and view all the answers
The ioctl function was included in the Single UNIX Specification only as an extension for dealing with ______ devices.
The ioctl function was included in the Single UNIX Specification only as an extension for dealing with ______ devices.
Signup and view all the answers
The second argument of the ioctl function is declared as an ______ long in FreeBSD 8.0 and Mac OS X 10.6.8.
The second argument of the ioctl function is declared as an ______ long in FreeBSD 8.0 and Mac OS X 10.6.8.
Signup and view all the answers
Each device driver can define its own set of ______ commands.
Each device driver can define its own set of ______ commands.
Signup and view all the answers
The common FreeBSD ioctl operations include functions for handling ______ tape operations.
The common FreeBSD ioctl operations include functions for handling ______ tape operations.
Signup and view all the answers
The easiest way to handle mag tape devices has always been to access their operations using ______.
The easiest way to handle mag tape devices has always been to access their operations using ______.
Signup and view all the answers
The generic ioctl commands are supported in various categories of ______ devices.
The generic ioctl commands are supported in various categories of ______ devices.
Signup and view all the answers
For terminal I/O operations, specific ioctl commands require ______ header.
For terminal I/O operations, specific ioctl commands require ______ header.
Signup and view all the answers
The return value of the ioctl function is --1 on error, something else if ______.
The return value of the ioctl function is --1 on error, something else if ______.
Signup and view all the answers
Study Notes
3.1 Introduction
- Unix file I/O functions include open, read, write, Iseek, and close
- Unbuffered I/O involves system calls in the kernel for each read/write
- Atomic operations are important for resource sharing among processes
- File descriptors are non-negative integers representing open files
- Descriptors 0, 1, and 2 are typically associated with standard input, output, and error, respectively. This is a convention, not a kernel feature.
3.2 File Descriptors
- Kernel uses file descriptors to refer to open files
- Opening or creating a file returns a file descriptor to the process
- Reading or writing a file is done using the returned file descriptor
- Standard input (0), output (1), and error (2) are common shell associations
3.3 open and openat Functions
- Files are opened or created using open or openat
- The path parameter is the file name
- The oflag argument uses constants from the fcntl.h header to specify options
- Open for reading only (O_RDONLY)
- Open for writing only (O_WRONLY)
- Open for reading and writing (O_RDWR)
- Open for execute only (O_EXEC)
- Append to the end of file (O_APPEND)
- Create the file if it doesn't exist (O_CREAT)
- Generate an error if the path doesn't refer to a directory (O_DIRECTORY)
- Generate an error if the file already exists (O_EXCL)
- Do not allocate the device as the controlling terminal (O_NOCTTY)
3.4 creat Function
- Creates a new file (equivalent to open with O_WRONLY | O_CREAT | O_TRUNC)
3.5 close Function
- Closes an open file
- Returns 0 if successful, otherwise -1
3.6 Iseek Function
- Every open file has a current file offset
- Iseek changes the file offset
- SEEK_SET: Sets the offset to the given value from the beginning of the file
- SEEK_CUR: Sets the offset to the current offset plus the given value
- SEEK_END: Sets the offset to the end-of-file offset plus the given value
3.7 read Function
- Reads data from an open file
- Returns the number of bytes read (or 0 if end of file, or -1 on error)
3.8 write Function
- Writes data to an open file
- Returns the number of bytes written (or -1 if error)
- The offset advances by the number of bytes written for regular files
- O_APPEND sets the offset to the end-of-file before each write operation
3.9 I/O Efficiency
- Program examples illustrate file copying using read and write functions
3.10 File Sharing
- Kernel data structures for open files include process table entry, file table entry, and v-node
3.11 Atomic Operations
- Appending to files can be problematic if not handled correctly if multiple processes access the file
- The O_APPEND option when opening for writing ensures that the write is performed atomically
3.12 dup and dup2 Functions
- dup creates a new file descriptor that refers to the existing file descriptors
- dup2 creates a new file descriptor, replacing the existing file descriptor, if it exists
3.13 sync, fsync, and fdatasync Functions
- sync(void): queues write operations but doesn't wait
- fsync(int fd): waits for writes to complete
- fdatasync(int fd): waits for data to be written to disk, but not necessarily the file attributes
3.14 fcntl Function
- Changes the properties of an open file by setting or getting file descriptor flags or file status flags
3.15 ioctl Function
- Provides access to various I/O operations for devices
-
ioctl(int fd, int request, ...)
3.16 /dev/fd
-
/dev/fd
is a directory containing symbolic links to open files; useful for redirection mechanisms
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Related Documents
Description
This quiz covers the fundamental concepts of Unix file I/O operations, including functions such as open, read, and write. It also discusses the significance of file descriptors, standard input/output/error, and atomic operations in process resource sharing. Test your understanding of how files are managed in the Unix operating system!