Unix System Overview part_2 Flashcards
describe utime function
the access time and the modifiaction time of a file can be changed with the utime function.
#include int utime(const char *pathname, const struct utimbuf *times); what can this function return?
Returns 0 if ok.
and -1 on error
what is the structure used by the utime function?
struct utimbuf { time_t actime; /* access time */ time_t modtime; /* modification time */ }
The operation of utime function, and the privileges required to execute it, depend on whether the times argument is NULL.
if it is not null then?
If times is a non-null pointer, the access time and the modification time are set to the values in the structure pointed to by times. For this case, the effective user ID of the process must equal the owner ID of the file, or the process must be a superuser process. Merely having write permission for the file is not adequate.
what field is automatically updated when the utime function is called.
we are unable to specify a value for the changed-status time, st_ctime—the time the i-node was last changed
what does this return? #include int mkdir(const char *pathname, mode_t mode);
return 0 if OK
and return -1 on error.
what function creates directories?
mkdir.
This function creates a new, empty directory. The entries for dot and dot-dot are automatically created. The specified file access permissions, mode, are modified by the file mode creation mask of the process.
what functions delete directories?
rmdir
An empty directory is deleted with the rmdir function. Recall that an empty directory is one that contains entries only for dot and dot-dot.
#include int rmdir(const char *pathname); what does this return?
Return 0 if OK
and return -1 on error
what is a common mistake that occurs sometimes from using mkdir?
A common mistake is to specify the same mode as for a file: read and write permissions only. But for a directory, we normally want at least one of the execute bits enabled, to allow access to filenames within the directory.
explain how rmdir works?
If the link count of the directory becomes 0 with this call, and if no other process has the directory open, then the space occupied by the directory is freed. If one or more processes have the directory open when the link count reaches 0, the last link is removed and the dot and dot-dot entries are removed before this function returns. Additionally, no new files can be created in the directory. The directory is not freed, however, until the last process closes it. (Even though some other process has the directory open, it can’t be doing much in the directory, as the directory had to be empty for the rmdir function to succeed.)
what does this return? #include int chdir(const char *pathname);
returns 0 if OK
returns -1 on Error
what does this return? #include int fchdir(int filedes)
returns 0 if OK
returns -1 on Error
what functions can change the current working directory of the calling process?
chdir or fchdir fucntions.
we can specify the new current working directory either as a pathname or through an open file descriptor
the fchdir function provides us with an easy way to accomplish a task?
The fchdir function provides us with an easy way to accomplish this task. Instead of calling getcwd, we can open the current directory and save the file descriptor before we change to a different location in the file system. When we want to return to where we started, we can simply pass the file descriptor to fchdir.
what does this return? #include DIR *opendir(const char *pathname);
return pointer if OK
return NULL if error
what does this return?
struct dirent *readdir(DIR *dp);
returns pointer if OK
returns Null at end of directory or error
what does this return? void rewinddir(DIR *dp);
returns 0 if OK
returns -1 of error
what does this return? int closedir(DIR *dp);
returns 0 if OK
returns -1 on error
what does this return? long telldir(DIR *dp);
returns current location in directory associated with dp
what does this return? void seekdir(DIR *dp, long loc);
nothing its void
what are the 3 streams that are predefined and automatically available to a process? and what header are they defined in?
standard input standard output standard error. defined in note: there streams refer to the same files as the file descriptors STDIN_FILENO, STDOUT_FILENO, and STDERR_FILENO,
what is the goal of buffering provided by the standard I/O library?
is to use the minimum number of read and write calls. (Recall Figure 3.5, where we showed the amount of CPU time required to perform I/O using various buffer sizes.) Also, it tries to do its buffering automatically for each I/O stream, obviating the need for the application to worry about it.
describe fully buffered
Fully buffered. In this case, actual I/O takes place when the standard I/O buffer is filled. Files residing on disk are normally fully buffered by the standard I/O library. The buffer used is usually obtained by one of the standard I/O functions calling malloc (Section 7.8) the first time I/O is performed on a stream.
The term flush describes the writing of a standard I/O buffer. A buffer can be flushed automatically by the standard I/O routines, such as when a buffer fills, or we can call the function fflush to flush a stream. Unfortunately, in the UNIX environment, flush means two different things. In terms of the standard I/O library, it means writing out the contents of a buffer, which may be partially filled. In terms of the terminal driver, such as the tcflush function in Chapter 18, it means to discard the data that’s already stored in a buffer.