Skip to content

Commit 51d336d

Browse files
rsjordanVladimir Kotal
authored and
Vladimir Kotal
committed
Typos and grammar tweaks through page 75. (#42)
1 parent 458be7c commit 51d336d

File tree

2 files changed

+109
-109
lines changed

2 files changed

+109
-109
lines changed

file-api.tex

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
\begin{slide}
66
\sltitle{File API}
77
\begin{itemize}
8-
\item before working with a file, it must be first open via
8+
\item before working with a file, it must be first opened via
99
\funnm{open}() or \funnm{creat}()
1010
\item open files are accessible via \emph{file descriptors}, numbered from 0.
1111
More descriptors can share the same file opening (read/write mode, position).
@@ -112,12 +112,12 @@
112112
current mask that can be changed via a shell command \texttt{umask} -- those
113113
bits in \emph{mode}, also set in the process umask, are nullified. The
114114
default umask value is typically (and historically) \texttt{022}. We recommend
115-
you to always set it to \texttt{077} in your profile script. Never do that for
115+
that you always set it to \texttt{077} in your profile script. Never do that for
116116
root though otherwise you will end up with a system in a non-supported
117117
configuration -- installed software will not be possible to run by
118118
non-privileged users, what worked before may stop working, etc.
119119
\item If the \emph{mode} argument is required and not specified, you get
120-
whatever is on the stack. Both flags and the mode are stored in the system file
120+
whatever is on the stack. Both flags and mode are stored in the system file
121121
table, see page \pageref{OPENFILETABLES}.
122122
\item Macros for use with \emph{mode} can be usually found in the manual page
123123
for \texttt{chmod(2)}, and you can find them also in the \texttt{stat.h} header
@@ -142,8 +142,8 @@
142142
as historically, implementations used 0 for the read-only flag. The standard
143143
defines that only one of those three flags may be used.
144144
\item Is is possible to open and create a file for writing so that writing is
145-
disallowed by its mode. It will work for that file opening but any other file
146-
opening for writing will fail.
145+
disallowed by its mode. It will work for the initial file opening but any subsequent
146+
attempts to write will fail.
147147
\item You need write permission to use \texttt{O\_TRUNC}.
148148
\item The behavior of \texttt{O\_EXCL} without using \texttt{O\_CREAT} at the
149149
same is undefined.
@@ -179,10 +179,10 @@
179179
\label{CREAT}
180180

181181
\begin{itemize}
182-
\item The \texttt{open} call allows to open a regular file, a device, or a named
182+
\item The \texttt{open} call allows opening of a regular file, device, or named
183183
pipe. However, it (and \texttt{creat} as well) can only create a regular file,
184184
so you need the other two calls for non-regular files.
185-
\item The test of a file existence using the flag \texttt{O\_EXCL} and its
185+
\item The test of a file's existence using the flag \texttt{O\_EXCL} and its
186186
subsequent creation if it did not exist, is an atomic operation. You can use
187187
that for lock files but only with the \texttt{open} call, not \texttt{creat}.
188188
\item You need extra privileges to create device special files (e.g. to be a
@@ -223,7 +223,7 @@
223223
\setlength{\itemsep}{0.8\itemsep}
224224
\item For any Unix system, a file is just a sequence of bytes without any inner
225225
structure.
226-
\item \emsl{Behavior of \texttt{read} and \texttt{write} depends on the type of
226+
\item The \emsl{behavior of \texttt{read} and \texttt{write} depends on the type of
227227
the file} (regular, device, pipe, or socket) and whether the file is in a
228228
blocking or non-blocking mode (flag \texttt{O\_NONBLOCK} on file opening, see
229229
page \pageref{O_NONBLOCK}).
@@ -236,7 +236,7 @@
236236
\texttt{read} will block unless some data gets available, a non-blocking
237237
\texttt{read} returns -1 and sets \texttt{errno} to \texttt{EAGAIN}.
238238
\item \texttt{write} returns a non-zero number of bytes less than \emph{nbyte}
239-
if less then \emph{nbyte} bytes can fit the file (e.g. disk full), if the call
239+
if less then \emph{nbyte} bytes can fit into the file (e.g. disk full), if the call
240240
was interrupted by a signal, or if \verb#O_NONBLOCK# was set and only part of
241241
the data fits into a pipe, socket, or a device; without \verb#O_NONBLOCK#
242242
the call will block until all the data can be written. If nothing can be
@@ -268,9 +268,9 @@
268268
\begin{itemize}
269269
\item releases \texttt{fildes}, if it was the last descriptor for a file
270270
opening, closes the file
271-
\item if number of links is 0, the file data is released
272-
\item if the last pipe descriptor is closed, remaining data is lost
273-
\item on a process termination, implicit \texttt{close} is called on all
271+
\item if the number of links is 0, the file data is released
272+
\item if the last pipe descriptor is closed, any remaining data is lost
273+
\item on process termination, an implicit \texttt{close} is called on all
274274
descriptors
275275
\end{itemize}
276276
\end{slide}
@@ -391,8 +391,8 @@
391391
\item When writing to a pipe without a consumer (i.e. the producer opened the
392392
pipe when there was at least one existing consumer), the kernel will send the
393393
producer a signal \texttt{SIGPIPE} (``broken pipe''). See the following
394-
example. For simplicity, we are using an unnamed pipe but that does not matter
395-
as it would have behaved in the same manner. The \texttt{date(1)} command never
394+
example. For simplicity, we are using an unnamed pipe but a named pipe
395+
would behave in the same manner. The \texttt{date(1)} command never
396396
reads anything from its standard input so it is guaranteed that the producer,
397397
\texttt{dd(1)}, will be writing to a pipe without a consumer. If a process is
398398
killed by a signal, the shell provides a signal number added to 128 as its
@@ -409,17 +409,17 @@
409409

410410
\item When opening a pipe for writing only with \texttt{O\_NONBLOCK} and without
411411
an existing consumer, the call returns -1 and \texttt{errno} is set to
412-
\texttt{ENXIO}. This asymmetry to opening a pipe for reading in a non-blocking
412+
\texttt{ENXIO}. This asymmetry in opening a pipe for reading in non-blocking
413413
mode is due to the fact that it is not desirable to have data in a pipe that may
414414
not be read in a short period of time. The Unix system does not allow for
415-
storing pipe data for arbitrary length of time. Without the
415+
storing pipe data for an arbitrary length of time. Without the
416416
\texttt{O\_NONBLOCK} flag, the process will block while waiting for a consumer.
417-
By asymmetry we mean that the system does not mind to keep consumers without
417+
By asymmetry, we mean that the system allows consumers without
418418
producers but it tries to avoid writers without existing readers.
419419
\item If you want to create a process that sits on a named pipe and processes
420420
data from producers, you need to open it with the flag \texttt{O\_RDWR} even
421-
that you do not intend to write it. If you do not use the flag, you might end
422-
up with \texttt{read} returning 0 after all producers, perhaps temporarily only,
421+
if you do not intend to write to it. If you do not use the flag, you might end
422+
up with \texttt{read} returning 0 after all producers, perhaps only temporarily,
423423
disappear, which could be solved by busy waiting. A much better solution would
424424
be to use the \texttt{select} call, see page \pageref{SELECT}.
425425
\item Writing data of length \texttt{PIPE\_BUF} bytes or less
@@ -486,29 +486,29 @@
486486

487487
\begin{itemize}
488488
\item \label{LSEEK} The first byte is at position 0. If it makes sense, you may
489-
use a negative number for setting \emph{offset}. Example:
489+
use a negative number for setting the \emph{offset}. Example:
490490
\example{read/lseek.c}.
491-
\item If it legal to move beyond the end of the file. If data is written there,
491+
\item It is legal to move beyond the end of the file. If data is written there,
492492
the file size will be set accordingly, the ``holes'' will be read as zeros.
493493
Note that just changing the file position will not increase the file size.
494494
\item You can get the file size via \texttt{lseek(fildes, 0, SEEK\_END)}.
495495
\item The most common operations with \texttt{lseek} are three: setting the
496496
position from the beginning of a file, setting the position to the end of a
497497
file, and getting the current file position (0 with \texttt{SEEK\_CUR}).
498498
\item There is no I/O involved when calling \texttt{lseek}.
499-
\item You can obviously use \texttt{lseek} not only for subsequent calls
499+
\item You can obviously use \texttt{lseek} not only for subsequent calls to
500500
\texttt{read} and \texttt{write} but also for another call to \texttt{lseek}.
501501
\item \label{BIG_FILE} Beware of files with holes as it may lead to problems
502502
with backing up the data. Example: \example{read/big-file.c} demonstrates that
503-
moving a sparse file may end up in the actual storage data occupation increase.
504-
It greatly depends on the system you run, what an archiving utility is used, and
505-
their versions. Some utilities provide means to preserve holes, for example,
503+
moving a sparse file may end up in an actual storage data occupation increase.
504+
It greatly depends on the system you run, what archiving utility is used, and
505+
their versions. Some utilities provide the means to preserve holes, for example,
506506
\texttt{dd} with \texttt{conv=sparse}, \texttt{tar} with \texttt{-S},
507507
\texttt{rsync} with \texttt{--sparse}, etc.
508508
\item Beware of confusing the parameters. The second line below looks OK but
509509
the arguments are in reversed order. What is more, \texttt{SEEK\_SET} is
510510
defined as 0 and \texttt{SEEK\_CUR} is 1, so the file position is not moved
511-
which is not by itself a disastrous thing, and makes it more difficult to find
511+
which is not by itself a disastrous thing, which makes it more difficult to find
512512
it:
513513

514514
\begin{verbatim}
@@ -529,13 +529,13 @@
529529
\item causes the regular file to be truncated to a size of precisely
530530
\emph{length} bytes.
531531
\item if the file was larger than \emph{length}, the extra data is lost
532-
\item if the file previously was shorter, it is extended, and the extended part
532+
\item if the file was previously shorter, it is extended, and the extended part
533533
reads as null bytes
534534
\end{itemize}
535535
\end{slide}
536536

537537
\begin{itemize}
538-
\item To truncate the file when opening it can be achieved via using the
538+
\item Truncating the file when opening it can be achieved via the
539539
\texttt{O\_TRUNC} flag in \texttt{open}, see page \pageref{OPEN}.
540540
\end{itemize}
541541

@@ -605,13 +605,13 @@
605605
\texttt{>>}.
606606
\item \label{REDIRECT} Another example of \texttt{dup} use will be provided when
607607
we start working with pipes. The first redirection example from the slide
608-
(without \texttt{stderr}) is in \example{read/redirect.c}. The call
609-
\texttt{execl} in that example replaces the current process image with the
610-
program passed as the first argument. We got ahead of ourselves here though, we
608+
(without \texttt{stderr}) is in \example{read/redirect.c}. In that example, the
609+
\texttt{execl} call replaces the current process image with the
610+
program passed in the first argument. We got ahead of ourselves here though, we
611611
will learn about the \texttt{exec} calls on page \pageref{EXEC}.
612612
\item To fully understand how redirection works it is good to draw the file
613-
descriptor table for each step and where the slots point to. For example, for
614-
the \nth{2} example in the slide, we have the initial state, after
613+
descriptor table for each step and where the slots point to. In
614+
the \nth{2} example in the slide above, we have the initial state, after
615615
\texttt{close(1)} and \texttt{open("out", ...)}, and the final state, as
616616
follows:
617617

@@ -626,7 +626,7 @@
626626
\end{verbatim}
627627

628628
\item You need to pay attention to the state of descriptors. The \nth{2} example
629-
will not work if the descriptor 0 is already closed, as
629+
above will not work if the descriptor 0 is already closed, as
630630
\texttt{open} returns 0 (the first available descriptor) and \texttt{dup} fails
631631
while trying to duplicate an already closed descriptor. Possible
632632
solutions:
@@ -765,15 +765,15 @@
765765
data itself, neither the filename as the file data can be accesses through
766766
several different hard links and those hardlinks are in the data of directories.
767767
In other words, metadata is data about the actual file data.
768-
\item Metadata can be read even when the process has not rights to read the file
768+
\item Metadata can be read even when the process has no rights to read the file
769769
data.
770770
\item These functions do not provide file descriptor flags or flags from the
771771
system file table. These functions are about file information as stored on some
772772
mountable media.
773773
\item \texttt{st\_ctime} is not the creation time but the change time -- the
774774
last modification of the inode.
775775
\item The UNIX norm does not specify the ordering of the \texttt{struct stat}
776-
members, neither it prohibits adding new.
776+
members, nor does it prohibit adding new ones.
777777
\item \label{STAT} Example: \example{stat/stat.c}
778778
\item You can call \texttt{fstat} on file descriptors 0,1,2 as well. Unless
779779
redirected before, you will get information on the underlying terminal device

0 commit comments

Comments
 (0)