|
|
|
Modern Operating Systems by Herbert Bos and Andrew S. Tanenb...
Modern_Operating_Systems_by_Herbert_Bos_and_Andrew_S._Tanenbaum_4th_Ed.pdf
Showing 814 out of 1137
Modern Operating Systems by Herbert Bos and Andrew...
Modern_Operating_Systems_by_Herbert_Bos_and_Andrew_S._Tanenbaum_4th_Ed.pdf-M ODERN O PERATING S YSTEMS
Modern Operating Systems by Herbert...
Modern_Operating_Systems_by_Herbert_Bos_and_Andrew_S._Tanenbaum_4th_Ed.pdf-M ODERN O PERATING S YSTEMS
Page 814
SEC. 10.6
THE LINUX FILE SYSTEM
783
being aware that these have been redirected.
If they have not been redirected,
sort
will automatically read from the keyboard and write to the screen (the default de-
vices). Similarly, when
head
reads from file descriptor 0, it is reading the data
sort
put into the pipe buffer without even knowing that a pipe is in use. This is a clear
example of how a simple concept (redirection) with a simple implementation (file
descriptors 0 and 1) can lead to a powerful tool (connecting programs in arbitrary
ways without having to modify them at all).
The last system call in Fig. 10-27 is
fcntl
.
It is used to lock and unlock files,
apply shared or exclusive locks, and perform a few other file-specific operations.
Now let us look at some system calls that relate more to directories or the file
system as a whole, rather than just to one specific file. Some common ones are list-
ed in Fig. 10-29. Directories are created and destroyed using
mkdir
and
rmdir
, re-
spectively.
A directory can be removed only if it is empty.
System call
Description
s = mkdir(path, mode)
Create a new directory
s = rmdir(path)
Remove a directory
s = link(oldpath, newpath)
Create a link to an existing file
s = unlink(path)
Unlink a file
s = chdir(path)
Change the working directory
dir = opendir(path)
Open a directory for reading
s = closedir(dir)
Close a directory
dirent = readdir(dir)
Read one directory entry
rewinddir(dir)
Rewind a directory so it can be reread
Figure 10-29.
Some system calls relating to directories. The return code
s
is
−
1
if an error has occurred;
dir
identifies a directory stream, and
dirent
is a directory
entry. The parameters should be self explanatory.
As we saw in Fig. 10-24, linking to a file creates a new directory entry that
points to an existing file. The
link
system call creates the link. The parameters spec-
ify the original and new names, respectively.
Directory entries are removed with
unlink
.
When the last link to a file is removed, the file is automatically deleted. For
a file that has never been linked, the first
unlink
causes it to disappear.
The working directory is changed by the
chdir
system call. Doing so has the ef-
fect of changing the interpretation of relative path names.
The last four calls of Fig. 10-29 are for reading directories. They can be open-
ed, closed, and read, analogous to ordinary files. Each call to
readdir
returns exact-
ly one directory entry in a fixed format. There is no way for users to write in a di-
rectory (in order to maintain the integrity of the file system).
Files can be added to
a directory using
creat
or
link
and removed using
unlink
.
There is also no way to
seek to a specific file in a directory, but
rewinddir
allows an open directory to be
read again from the beginning.
Ace your assessments! Get Better Grades
Browse thousands of Study Materials & Solutions from your Favorite Schools
Concordia University
Concordia_University
School:
Operating_Systems
Course:
Introducing Study Plan
Using AI Tools to Help you understand and remember your course concepts better and faster than any other resource.
Find the best videos to learn every concept in that course from Youtube and Tiktok without searching.
Save All Relavent Videos & Materials and access anytime and anywhere
Prepare Smart and Guarantee better grades
Students also viewed documents
lab 18.docx
lab_18.docx
Course
Course
3
Module5QuizSTA2023.d...
Module5QuizSTA2023.docx.docx
Course
Course
10
Week 7 Test Math302....
Week_7_Test_Math302.docx.docx
Course
Course
30
Chapter 1 Assigment ...
Chapter_1_Assigment_Questions.docx.docx
Course
Course
5
Week 4 tests.docx.do...
Week_4_tests.docx.docx
Course
Course
23
Week 6 tests.docx.do...
Week_6_tests.docx.docx
Course
Course
106