Carnegie Mellon

Computer Science Department |
 |
 |
 |
 |
 |
 |
 |
 |
|
|
|
15-410 File System Interface
Your file system should support the following interface. The system call
numbers are defined in syscall_nums.h. Please continue to
use the same system call convention as in Project 3.
- int create(char *pathname)
Creates and opens the new file named pathname. If the file
can be created and opened, create sets the file position to
the beginning of the empty file and returns a file descriptor number
that can be used for future operations on this open file. Otherwise,
create returns ERROR. Note that create should return
ERROR if pathname already exists, or if its parent directory
does not exist, and also if pathname is a relative path but
the process' current directory has not yet been set with
chdir.
-
int unlink(char* pathname)
Removes the directory entry for pathname, and, if
pathname is the last reference to a file, also deletes the
file itself by freeing all data and metadata used by the file. The
file pathname must not be a directory. If pathname
is a symbolic link, the unlink operation is attempted on the
symbolic link itself, and not on the file the symbolic link points
to. On success, unlink returns SUCCESS, and it returns ERROR
otherwise.
-
int mkdir(char *pathname)
Creates a new directory named pathname and creates the ``.''
and ``..'' entries in the new directory. If pathname exists
and/or any other error occurs, mkdir returns ERROR. It
returns SUCCESS otherwise.
-
int rmdir(char *pathname)
Deletes the existing directory named
pathname. pathname must be a directory, and it must
contain no valid entries other than ``.'' and ``..''. rmdir
returns ERROR if any error occurs, and returns SUCCESS otherwise.
-
int chdir(char *pathname)
Changes the current directory of the current process to
pathname. The notion of current directory is maintained by
the file system for processes that use the file system, and is not
reflected on disk. Before a process calls chdir, or if all
previous calls from a process to chdir have returned ERROR,
the current directory for that process is undefined, and all pathnames
given to file system calls must be absolute paths (paths starting with
' /'.) After a successful call to chdir, the process may
specify relative paths, that is, paths that do not start with ' /'.
chdir returns ERROR if any error occurs (if pathname
does not exist, for example), and returns SUCCESS otherwise.
-
int dirsize(char *pathname)
Returns the number of entries in the directory pathname,
including the entries for ``.'' and ``..''. Returns ERROR if
pathname does not exist, if pathname is not a
directory, or if any other error occurs.
-
int direntry(char *pathname, int entrypos, char *entryname)
Sets entryname to the name of the entrypos'th entry within
the directory specified by pathname. The entries within a
directory can be returned in any order, but the order must remain the
same for as long as no files are created or unlinked
within it. 0 is a valid value for entrypos. direntry
returns ERROR if pathname refers to a regular file, if
pathname does not exist, if the directory has fewer than
entrypos + 1 entries, or if any other error occurs. It
returns SUCCESS otherwise. If direntry returns ERROR, the
value of entryname is undefined. entryname is an
address in the caller's memory space to which at least
MAXFILENAMESIZE bytes have been allocated by the caller.
-
int link(char *oldname, char *newname)
Creates a hard link from the new file newname to the existing
file oldname. The files oldname and newname
need not be in the same directory. The file oldname must not
be a directory. If newname exists, oldname does not
exist, or if any file system limit prevents the completion of the
operation, link returns ERROR, and it returns SUCCESS
otherwise.
-
int symlink(char *oldname, char *newname)
Creates a symbolic link from the new file newname to the
existing file oldname. The files oldname and
newname need not be in the same directory. The file
oldname may be a directory and may not even exist. If
newname exists or if any file system limit prevents the
completion of the operation, symlink returns ERROR, and it
returns SUCCESS otherwise.
-
int sync()
Writes all ``dirty'' cached metadata and data to the disk, thus
ensuring that the disk contains a consistent copy of the file
system. ``Dirty'' data (or metadata) is data whose value on disk is
stale because the buffer cache's write-behind policy has not yet
updated it. sync returns ERROR if any file system error
prevents the sync operation from proceeding. Otherwise sync
returns SUCCESS.
-
int mkfs(int max_inodes)
Initializes the file system such that max_inodes inodes are
available. This parameter determines the maximum number of files and
directories that may be present on your file system. If
max_inodes is 0, mkfs estimates a reasonable number
for max_inodes based on the size of the disk. If
max_inodes is less than 0 or greater than 8192, or if any
error prevents the initialization from completing, ERROR is
returned. Otherwise mkfs returns SUCCESS.
|