|
31 | 31 | \item A process inherits file descriptors from its parent so it does not have to |
32 | 32 | open already open files. Usually at least file descriptors 0, 1, and 2 are |
33 | 33 | provided. |
34 | | -\item Functions from a header file \texttt{stdio.h} (eg. \funnm{fopen}(), |
| 34 | +\item Functions from a header file \texttt{stdio.h} (e.g. \funnm{fopen}(), |
35 | 35 | \funnm{fprintf}(), and \funnm{fscanf}()), and their file handle \texttt{FILE} |
36 | 36 | are defined in the standard libc library and use standard system calls like |
37 | 37 | \funnm{open}(), \funnm{write}(), and \funnm{read}(). From those functions, we |
|
181 | 181 | \item The test of a file existence using the flag \texttt{O\_EXCL} and its |
182 | 182 | subsequent creation if it did not exist, is an atomic operation. You can use |
183 | 183 | that for lock files but only with the \texttt{open} call, not \texttt{creat}. |
184 | | -\item You need extra privileges to create device special files (eg. to be a |
| 184 | +\item You need extra privileges to create device special files (e.g. to be a |
185 | 185 | root). |
186 | 186 | \end{itemize} |
187 | 187 |
|
|
232 | 232 | \texttt{read} will block unless some data gets available, a non-blocking |
233 | 233 | \texttt{read} returns -1 and sets \texttt{errno} to \texttt{EAGAIN}. |
234 | 234 | \item \texttt{write} returns a non-zero number of bytes less than \emph{nbyte} |
235 | | -if less then \emph{nbyte} bytes can fit the file (eg. disk full), if the call |
| 235 | +if less then \emph{nbyte} bytes can fit the file (e.g. disk full), if the call |
236 | 236 | was interrupted by a signal, or if \verb#O_NONBLOCK# was set and only part of |
237 | 237 | the data fits into a pipe, socket, or a device; without \verb#O_NONBLOCK# |
238 | 238 | the call will block until all the data can be written. If nothing can be |
|
250 | 250 | manages to read or write, respectively, at least one byte -- see the paragraphs |
251 | 251 | above. |
252 | 252 | \item \texttt{O\_APPEND} guarantees an atomic write to the end of a file on a |
253 | | -local filesystem, ie. \emsl{every} write will add data to the file end (so |
| 253 | +local filesystem, i.e. \emsl{every} write will add data to the file end (so |
254 | 254 | called \emph{append-only} file). |
255 | 255 | \end{itemize} |
256 | 256 |
|
|
347 | 347 | \sltitle{Working with a named pipe (FIFO)} |
348 | 348 |
|
349 | 349 | \begin{itemize} |
350 | | -\item it may not be possible to create a FIFO on a distributed filesystem (eg. |
| 350 | +\item it may not be possible to create a FIFO on a distributed filesystem (e.g. |
351 | 351 | NFS or AFS) |
352 | 352 | \item you need to know the semantics of opening a FIFO |
353 | 353 | \begin{itemize} |
|
384 | 384 | results in a return value of 0, indicating the end of file -- the process will |
385 | 385 | not block waiting for a producer. It is irrelevant whether the pipe was opened |
386 | 386 | in a blocking or non-blocking mode. |
387 | | -\item When writing to a pipe without a consumer (ie. the producer opened the |
| 387 | +\item When writing to a pipe without a consumer (i.e. the producer opened the |
388 | 388 | pipe when there was at least one existing consumer), the kernel will send the |
389 | 389 | producer a signal \texttt{SIGPIPE} (``broken pipe''). See the following |
390 | 390 | example. For simplicity, we are using an unnamed pipe but that does not matter |
|
419 | 419 | disappear, which could be solved by busy waiting. A much better solution would |
420 | 420 | be to use the \texttt{select} call, see page \pageref{SELECT}. |
421 | 421 | \item Writing data of length \texttt{PIPE\_BUF} bytes or less |
422 | | -(\texttt{limits.h}) is guaranteed as atomic, ie. data will not be intermingled |
| 422 | +(\texttt{limits.h}) is guaranteed as atomic, i.e. data will not be intermingled |
423 | 423 | with data written by other writers. For example, on Linux kernel 4.x it is 4096 |
424 | 424 | bytes, on Solaris 11 it is 5120 bytes, and on FreeBSD 8.2 it is only 512 bytes. |
425 | 425 | It is obvious from the above that if you write less or equal than |
|
474 | 474 | \item \texttt{SEEK\_CUR} \dots{} current position plus \emph{offset} |
475 | 475 | \item \texttt{SEEK\_END} \dots{} size of the file plus \emph{offset} |
476 | 476 | \end{itemize} |
477 | | -\item returns the resulting offset (ie. from the file beginning) |
| 477 | +\item returns the resulting offset (i.e. from the file beginning) |
478 | 478 | \item \texttt{lseek(fildes, 0, SEEK\_CUR)} only returns the current file |
479 | 479 | position |
480 | 480 | \end{itemize} |
|
561 | 561 | \item We already know that the first available file descriptor is used when |
562 | 562 | opening and creating file, see page \pageref{OPEN}. |
563 | 563 | \item The original and duplicated file descriptors share the same slot in the |
564 | | -system file table (see page \pageref{OPENFILETABLES}), ie. they share the file |
| 564 | +system file table (see page \pageref{OPENFILETABLES}), i.e. they share the file |
565 | 565 | position and read/write mode. |
566 | 566 | \item The equivalent for \texttt{dup2} is not fully equivalent. If |
567 | 567 | \emph{fildes} is equal to \emph{fildes2}, \texttt{close(fildes2)} does not |
|
695 | 695 | descriptor, having \texttt{FD} in the macro names (only one such exists -- |
696 | 696 | \texttt{FD\_CLOEXEC}), and flags associated with the slot in the system file |
697 | 697 | table of opened files, having \texttt{FL} in the \texttt{fcntl} command macros |
698 | | -(ie. \texttt{F\_GETFL}). See also the picture on page \pageref{OPENFILETABLES}. |
| 698 | +(i.e. \texttt{F\_GETFL}). See also the picture on page \pageref{OPENFILETABLES}. |
699 | 699 | \item Devices may support reading and writing using \texttt{read} and |
700 | 700 | \texttt{write}, and mapping files to memory (\texttt{mmap}, see page |
701 | | -\pageref{MMAP}), all other operations on devices (eg. setting parameters, |
| 701 | +\pageref{MMAP}), all other operations on devices (e.g. setting parameters, |
702 | 702 | locking, or eject) are performed using the \texttt{ioctl} system call. |
703 | 703 | \item When setting flags, always get the present flags first. Even when you |
704 | 704 | know the flags are zero, you never know how the code is modified in the future, |
|
767 | 767 | \item \label{STAT} Example: \example{stat/stat.c} |
768 | 768 | \item You can call \texttt{fstat} on file descriptors 0,1,2 as well. Unless |
769 | 769 | redirected before, you will get information on the underlying terminal device |
770 | | -(eg. \texttt{/dev/ttys011} on macOS). Example: \example{stat/stat012.c}. |
| 770 | +(e.g. \texttt{/dev/ttys011} on macOS). Example: \example{stat/stat012.c}. |
771 | 771 | \end{itemize} |
772 | 772 |
|
773 | 773 |
|
|
828 | 828 |
|
829 | 829 | \begin{itemize} |
830 | 830 | \item This call is mostly used by copy/move and also archive utilities to make |
831 | | -sure the times are the same for the originals and copies. (eg. \texttt{tar} or |
| 831 | +sure the times are the same for the originals and copies. (e.g. \texttt{tar} or |
832 | 832 | \texttt{rsync}). |
833 | 833 | \item The shell interface for \texttt{utime} is the command \texttt{touch}. As |
834 | 834 | mentioned in the slide, you cannot change the time of the i-node modification. |
|
842 | 842 | \sltitle{File name manipulations} |
843 | 843 | \texttt{int \funnm{link}(const char *\emph{path1}, const char *\emph{path2});} |
844 | 844 | \begin{itemize} |
845 | | -\item creates a new link (aka hard link), ie. a directory entry, named |
| 845 | +\item creates a new link (aka hard link), i.e. a directory entry, named |
846 | 846 | \emph{path2} to file \emph{path1}. Hard links cannot span filesystems (use |
847 | 847 | \funnm{symlink} for that). |
848 | 848 | \end{itemize} |
849 | 849 | \texttt{ int \funnm{unlink}(const char *\emph{path});} |
850 | 850 | \begin{itemize} |
851 | | -\item deletes a name (ie. a directory entry) and after deleting the last link to |
| 851 | +\item deletes a name (i.e. a directory entry) and after deleting the last link to |
852 | 852 | the file and after closing the file by all processes, delete the file data. |
853 | 853 | \end{itemize} |
854 | 854 | \texttt{int \funnm{rename}(const char *\emph{old}, const char *\emph{new});} |
855 | 855 | \begin{itemize} |
856 | | -\item change the file name (ie. one specific link) from \emph{old} to |
| 856 | +\item change the file name (i.e. one specific link) from \emph{old} to |
857 | 857 | \emph{new}. Works within the same filesystem only. |
858 | 858 | \end{itemize} |
859 | 859 | \end{slide} |
860 | 860 |
|
861 | 861 | \begin{itemize} |
862 | 862 | \item It is better said again -- \emsl{Unix does not have a delete call for |
863 | 863 | files}. Details are on page \pageref{FILEDELETE}. |
864 | | -\item The call \texttt{link} creates hardlinks, ie. a relation between a file |
| 864 | +\item The call \texttt{link} creates hardlinks, i.e. a relation between a file |
865 | 865 | name and an i-node number. I-node numbers are unique within a filesystem so for |
866 | 866 | links between filesystems, symlinks are needed. A number of hardlinks to a |
867 | 867 | specific file is only limited by the size of the \texttt{st\_nlink} member of |
|
1030 | 1030 |
|
1031 | 1031 | \begin{itemize} |
1032 | 1032 | \item The descriptor for \texttt{fchdir} is from \texttt{open} called on the |
1033 | | -directory (ie. not from \texttt{opendir}). |
| 1033 | +directory (i.e. not from \texttt{opendir}). |
1034 | 1034 | \item There is also a function \texttt{chroot} which allows to change the root |
1035 | 1035 | directory of a calling process to a new one. It is often used in various server |
1036 | 1036 | implementations to limit access to the specific subtree. For example, for an |
|
0 commit comments