Home

This document is a cache from http://www.nobius.org/~dbg/practical-file-system-design.pdf


Practical File System Design

Document source : www.nobius.org


1 0 . 4
H O W I T R E A L LY W O R K S
173
create()
Creating files is perhaps the most important function of a file system;
without it, the file system would always be empty. The two primary argu-
ments of
create()
are the directory in which to create the file, and the name
of the file to create. The vnode layer also passes the mode in which the file is
being opened, the initial permissions for the file, and pointers to a vnid and a
cookie that the file system should fill in.
The
create()
function should create an empty file that has the name given
and that lives in the specified directory. If the file name already exists in the
directory, the file system should call
get vnode()
to load the vnode associated
with the file. Once the vnode is loaded, the mode bits specified may affect
the behavior of the open. If
O EXCL
is specified in the mode bits, then
create()
should fail with
EEXIST
. If the name exists but is a directory,
create()
should
return
EISDIR
. If the name exists and
O TRUNC
is set, then the file must be
truncated. If the name exists and all the other criteria are met, the file system
can fill in the vnid and allocate the cookie for the existing file and return to
the vnode layer.
In the normal case, the name does not exist in the directory, and the file
system must do whatever is necessary to create the file. Usually this en-
tails allocating an i-node, initializing the fields of the i-node, and inserting
the name and i-node number pair into the directory. Further, if the file sys-
tem supports indexing, the name should be entered into a name index if one
exists.
File systems such as BFS must be careful when inserting the new file name
into any indices. This action may cause updates to live queries, which in
turn may cause programs to open the new file even before it is completely
created. Care must be taken to ensure that the file is not accessed until
it is completely created. The method of protection that BFS uses involves
marking the i-node as being in a virgin state and blocking in
read vnode()
until the virgin bit is clear (the virgin bit is cleared by
create()
when the file
is fully created). The virgin bit is also set and then cleared by the
mkdir()
and
symlink()
operations.
The next step in the process of creating a file is for the file system to call
new vnode()
to inform the vnode layer of the new vnid and its associated data
pointer. The file system should also fill in the vnid pointer passed as an
argument to
create()
as well as allocating a cookie for the file. The final step
in the process of creating a file is to inform any interested parties of the new
file by calling
notify listener()
. Once these steps are complete, the new file
is considered complete, and the vnode layer associates the new vnode with a
file descriptor for the calling thread.
mkdir()
Similar to
create()
, the
mkdir()
operation creates a new directory. The
difference at the user level is that creating a directory does not return a file
handle; it simply creates the directory. The semantics from the point of view
Practical File System Design:The Be File System
, Dominic Giampaolo
page 173







Summary :

The vnode layer also passes the mode in which the file is being opened, the initial permissions for the file, and pointers to a vnid and a cookie that the file system should fill in. If the file name already exists in the directory, the file system should call get vnode() to load the vnode associated with the file. The next step in the process of creating a file is for the file system to call new vnode() to inform the vnode layer of the new vnid and its associated data pointer.


Tags : directory,new,exists,inode,irgin,nid,creating,layer,file,which,cookie,created,mkdir





Terms    |    Link pdf-search-files.com    |    Site Map
   |    Content Removal Notice   
   |    Contact   

All books are the property of their respective owners.
Please respect the publisher and the author for their creations if their books copyrighted