Question

Introduction

File management is one of the most visible components of an operating system. A file is a collection of related information as defined by its creator. Commonly, files represent programs (both source and object forms) and data. Data files may be numeric, alphabetic, alphanumeric, or binary. Files may be free-form (for example, text files), or they may be formatted rigidly (for example, fixed fields). This just shows how complex and expansive the concept of file management is. The operating system is responsible for the following activities in connection with file management:
• Creating and deleting files
• Creating and deleting directories to organize files
• Supporting primitives for manipulating files and directories
• Mapping files onto secondary storage
• Backing up files on stable (nonvolatile) storage media
Thus a well-designed file management structure at a minimum should be able to do the following:

◦ create file, delete file
◦ open, close
◦ read, write, reposition
◦ get file attributes, set file attributes

Design:
The most well suited data structures for these functionalities fits that of a hashtable and linkedlist. Each hash entry from the hashtable would correspond to directories, while each node from a linkedlist would comprise a given file. An alternative to the linkedlist would be a B-tree. Our hashtable implements a quadratic probing strategy to handle collisions. Discussion of which is beyond the scope of this paper.

Development

The functionalities we require our file management system are as follows;

createDirectory:
Creates a directory at the path specified by the user

Input: User specifies the directory name to be created along with the complete path.

Failure Conditions:
If any of the below conditions is true, the operation fails and an appropriate error response is sent.

a) No path corresponding to the parent exists in the file system
b) Parent does not have write permission (since the new file cannot be created under it)
c) If another directory already exists in file system with the same name specified by the user.

Otherwise, the directory is created is created successfully at the specified path and linked to its parents. Appropriate attributes are set and SUCCESS code is sent back.

deleteDirectory:
Deletes a directory at the path specified by the user

Failure Conditions:
If any of the below conditions is true, the operation fails and an appropriate error response is sent.

a) Attempt to delete root directory.
b) User specified directory is not in our file system.
c) Node returned by FindNode() is a file. (DeleteDir is invalid on files)
d) The particular directory has subdirectories
e) Node is not writable.
f) Node's parent is not writable.

Otherwise, the directory is delinked from its parent and the attributes are set to appropriate values. A success code is sent back.

createFile:
Creates a file at the path specified by the user

Input: User specifies the file name to be created along with the complete path.

Failure Conditions:
If any of the below conditions is true, the operation fails and an appropriate error response is sent.

a) No path corresponding to the parent exists in the file system
b) Parent does not have write permission (since the new file cannot be created under it)

Otherwise, hash function computes the key for the file name.
Appropriate location is indexed using the key value. If there are no children in the particular index, a new file will be created (Linked List Implementation). If the indexed location has children already, the linked list is traversed to find a match for the file name specified by the user. On finding a match, a failure message is returned since there can't be files with duplicate names. If there is no match, new file entry is created at the particular index and the file is linked to the parent as necessary.

Appropriate values for the attributes are set and success code is returned.

deleteFile:
Deletes a file at the path specified by the user

Input: User specifies the name of the file to be deleted along with the complete path.

Failure Conditions:
If any of the below conditions is true, the delete operation fails and an appropriate error response is sent.

a) File/node is not present in the file system.
b) Node is a directory (deleteFile becomes an invalid option for
directories)
c) Node is not modifiable.
d) Delete a file which is in open status.

Otherwise, hash value for the file name is computed. Appropriate location is indexed to locate the file. The file is then delinked from its parent.

The attributes are updated appropriately and a success code is returned.

OpenFile:
Opens a file for either Read or Write operation

Input: User specifies the path of the file to be opened and the access mode (read/write)

Failure Conditions:
If any of the below conditions is true, open operation fails and an appropriate error response is sent.

a) File doesn't exist in file system.
b) The required node is a directory instead of a file.

(deleteFile is invalid for directories)

Otherwise file can be opened in one of the following access modes:
Open for Read: If the file is readable and is not open, then the file is successfully opened for reading and status is set to READ indicating that a read operation is in progress. A success message is sent.

Open for Write: If the file has writable and is not currently open, the file is opened successfully for writing status is set to WRITE indicating that a write operation is in progress. A success message is sent.

closeFile:
Closes a file that is currently open in the file system

Input: User issues a close request to close an open file.

Failure Condition:
If any of the below conditions is true, close operation fails and an appropriate error response is sent. If no file is in open status, the close option becomes invalid and an error response is returned. Otherwise, the corresponding file is closed successfully.

The open status is set to "CLOSED" indicating that there are no files open in the system. Also, open_file which points to file that is currently open is set to null.

readFile:
Reads the contents of file for the length specified by the user

Input: User specifies start position, number of bytes to be read and the buffer to place the data read
Failure Condition:
If any of the below conditions is true, read operation fails and an appropriate error response is sent.

a) No open files in the file system
b) File is open for writing and does not have read permissions enabled.

Otherwise, the contents of the file are read for the required length and the data is placed in the buffer. A Success code is sent.

writeFile:
Writes the contents of buffer into file

Input: User specifies the data buffer, start position and the length

Failure Condition:
If any of the below conditions is true, write operation fails and an appropriate error response is sent.

c) No open files in the file system
d) File is open for reading and does not have write permission enabled.

Otherwise, the contents of data buffer are written to the file and a success code is sent.

getInfo
Gets the information about specified file system object

Input: User specifies the name of the file to be shown its information.

Failure Condition:
If any of the below conditions is true, the operation fails and an appropriate error response is sent.

a) No path to the specified object (File/Directory)

Otherwise, the node information is returned successfully.

Rename
Renames a file that is currently open in the file system

Input: User specifies the path of the file to be renamed and a new filename.

Failure Condition:
If any of the below conditions is true, rename operation fails and an appropriate error response is sent.

a) No path exists
b) Root directory is the node which has to be renamed.
c) Parent does not have write permission.

Otherwise, the corresponding file is renamed successfully.

setInfo
Sets the attributes of the node to new values specified by the user.

Input: User specifies the name of the file whose attributes is to be set.

Failure Condition
No path to the object exists.

Otherwise, the required information is updated successfully to the node.

Analysis: Some functionalities were eliminated due to the design of the file management system.


FILE OPERATIONS
When designing a file management system, your overall goal is to design a system that enables you to find files quickly and easily.

In order to manage a file properly, you have to be familiar with the operations that can be performed on the file. The six basic file operations for a file, which are supported by the operating system by providing system calls, are given below:


Creating a file.
Two steps are necessary to create a file. First, space in the file system must be found for the file. Secondly, an entry for the new file must be made in the directory.

Writing a file. To write a file, we make a system call specifying both the name of the file and the information to be written to the file. Given the name of the file, the system searches the directory to find the file’s location. The system must keep a write pointer to the location in the file where the next write is to take place. The write pointer must be updated whenever a write occurs.

Reading a file. To read from a file, we use a system call that specifies the name of the file and where (in memory) the next block of the file shouldbe put. Again, the directory is searched for the associated entry, and the system needs to keep a read pointer to the location in the file where the next read is to take place. Once the read has taken place, the read pointer is updated. Because a process is usually either reading from or writing to a file, the current operation location can be kept as a per-process currentfile-
position pointer. Both the read and write operations use this same pointer, saving space and reducing system complexity.

Repositioning within a file. The directory is searched for the appropriate entry, and the current-file-position pointer is repositioned to a given value. Repositioning within a file need not involve any actual I/O. This file operation is also known as a file seek.

• Deleting a file. To delete a file, we search the directory for the named file. Having found the associated directory entry, we release all file space, so that it can be reused by other files, and erase the directory entry.

• Truncating a file. The user may want to erase the contents of a file but keep its attributes. Rather than forcing the user to delete the file and then recreate it, this function allows all attributes to remain unchanged—except for file length—but lets the file be reset to length zero and its file space released. These six basic operations comprise the minimal set of required file operations. Other common operations include appending new information to the end of an existing file and renaming an existing file. These primitive operations can then be combined to perform other file operations. For instance, we can create a copy of a file—or copy the file to another I/O device, such as a printer or a display—by creating a new file and then reading from the old and writing to the new. There are also other operations that allow a user to get and set the various attributes of a file. Most of the file operations mentioned involve searching the directory for the entry associated with the named file. To avoid this constant searching, many systems require that an open() system call be made before a file is first used. The operating system keeps a table, called the open-file table, containing information about all open files. When a file operation is requested, the file is specified via an index into this table, so no searching is required. When the file is no longer being actively used, it is closed by the process, and the operating system removes its entry from the open-file table. create() and delete() are system calls that work with closed rather than open files. The implementation of the open() and close() operations is more

Analysis:

Evaluation:

File attributes:

File Access:
There are two primary methods of accessing information within a file: sequential and direct.
In a sequential access, the information in the file must be accessed in the order in which it is stored in the file. The Operation to read or write to the file does not need to speicify the logical location within the file. The system maintains a file pointer that determines the location of the next access.
On the other hand, with direct access, any logical location within the file may be accessed at any time by doing the following:
Stating the logical location to be accessed as a parameter to the read or write operation;
and identifying the location in a seek operation to be called before the read or write.

Protection:
Users may need to protect the integrity of their files as well protect their folders from unauthorized access. Thus, there is a need for some form of access control. Ideally access should be granted on as need basis. Several different types of operations may be controlled. This may include:
Read: read information contained in the file.
Write: write new information into a file or overwrite existing information in a file.

Append: write new information at the end of a file.
Delete: delete a file and release its storage space.
List: read the names contained in a directory.
Execute: load the contents of a file into main memory and create a process to execute it.
Change access: change some user’s access rights for some controlled operation.

Directory structure:
Sometimes the system stores thousands of the files on hundreds of gigabytes of disk. To manage all these data, we need to organize them. This is done in two parts.
First, the file system is broken into partitions, known as volumes or minidisks. This is the low level structure of file in which files and directories reside.
Second, each partition contains information about files within it. This information is kept in entries in a device directory or volume table of contents. The device directory records information such as name, size and type for all files on that partition.

There are also some operations which can be performed on a directory.
Search for the file: we need to search the directory structure for the particular file.
Create a file: new files created needs to be added in the directory.
Delete a file: when a file is no longer needed we want to remove it from the directory.
List a directory: we need to be able to list the file in the directory and also contents of the directory entry for each file in the list.
Rename a file: the file name must be changeable when the contents or user of the file changes. Renaming the file may allow its position in the directory to be changed.
Traverse the file system: it is useful to access every file and the directory within the structure. For reliability it is a good idea to save the contents and the structure of the entire file system at regular interval. This provides the backup copy in case of the file system failure.

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

public static myFile<Directory> Directories = new myFile<Directory>();

public static Directory createDirectory(String name, Directory path, boolean wPermission, boolean rPermission)
{
if ((path == null) || (Directories.contains(path))) //path exist or is root
{
if ((path == null) || (path.writePermission)) //check parent write permission
{
Directory dir = fileManagementSystem.new Directory();

dir.name = name;
dir.path = path;
dir.writePermission = wPermission;
dir.readPermission = rPermission;
System.out.print(dir.name);
if (Directories.insert(dir)) //Check if insert is posibble or there isnt a same directory already
{
File file = new File(getFilePath(dir));
if (!file.exists())
{
file.mkdir();
}
System.out.println(" created.");
return dir;
}
else
{
System.out.println("creation failed.");
return null;
}
}
else
{
return null;
}
}
else
{
return null;
}
}...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Assisting Tutor

Related Homework Solutions

Graph Theory: Gale-Shapely Algorithm Implementation
Homework Solution
$45.00
Computer Science
Programming
Java
Gale-Shapely Algorithm
Graph Theory
Mathematics
Complete Bi-Partite Graphs
Vertices
Edges
Statements
Variables
Loops
Input Values
Output Values
Benchmarking Bellman-Ford's Algorithm
Homework Solution
$38.00
Bellman Ford
Algorithm
Graph
Single Source
Shortest Path
Critical Operation
Big-O
Analysis
Documentation
Test Plan
Complexity
Benchmark
Approach
Improvement
Dijkstra
Relaxation
Edge
Node
Lessons Learned
Dynamic Programming Model for A Version of Job Scheduling Problem
Homework Solution
$30.00
Knapsack
Reduction
Algorithm
Complexity
Problem
Job
Scheduling
Dynamic
Programming
OPT
Optimal
Swapping
Exchange
Argument
Playful
Subset
Deadline
Value
Size
Profit
Function
Solution
Set
Array
Two
Dimensional
Selection
Reorder
M
Get help from a qualified tutor
Live Chats