Information Technology Reference
In-Depth Information
Creating and deleting files
create(pathName)
Create a new file with the specified name
link(existingName,newName)
Create a hard link|a new path name that refers
to the same underlying file as an existing path
name
unlink(pathName)
Remove the specified name for a file from its direc-
tory; if that was the only name for the underlying
file, then remove the file and free its resources.
Create a new directory with the specified name
mkdir(pathName)
Remove the directory with the specified name
rmdir(pathName)
Open and close
Prepare the calling process for access to the speci-
fied file (e.g., check access permissions and initial-
ize kernel data structures for tracking per-process
state of open files)
close(fileDescriptor)
Release resources associated with the specified
open file
fileDescriptor=
open(pathName)
File access
read(fileDescriptor,buf,len)
Read
len
bytes from the process's current position
in the open file
fileDescriptor
and copy the re-
sults to a
b
uer buf in the application's memory
write(fileDescriptor,len,buf)
Write
len
bytes of data from a buffer
buf
in the
process's memory to the process's current position
in the open file
fileDescriptor
.
seek(fileDescriptor,offset)
Change the process's current position in the open
le
fileDescriptor
to the specified
offset
Set up a mapping between the data in the file
fileDescriptor
from
off
to
off+len
and an
area in the application's virtual memory from
dataPtr
to
dataPtr+len
.
munmap(dataPtr,len)
Remove the mapping between the application's
virtual memory and a mapped file
fsync(fileDescriptor)
Force to disk all buffered, dirty pages for the file
associated with
fileDescriptor
.
dataPtr=
mmap(fileDescriptor,off,len)
Figure11.6: A simple API for accessing files.