CS 3113: Project 4

File System Implementation (Files and Pipes)

Introduction

With project 3, you implemented a hierarchical directory structure on top of a set of fixed-size blocks on a virtual disk. For this project, you will augment your implementation to include the representation of files and a form of pipe, including their content. Files may occupy multiple blocks on the disk, and will rely on the linked-list structure that the blocks already support to connect these blocks together. A pipe in MYFS connects to a file in your Linux file system.

We provide functionality that allows:

You will add functionality to:

Objectives

By the end of this project, you should be able to:

Overview

Files in MYFS are represented using an index node (the meta-data for the file) and some number of data blocks, the latter of which contain the byte-level data that make up the content of a file. As in Unix, there are standard file operations: open/close/read/write. For this project, these operations are provided for you.

Pipes in MYFS act like Unix named pipes in the sense that they appear as files in the file system: they are named entities in the MYFS file system (and hence can be listed), and they can be manipulated using the same file open/close/read/write operations. The key difference is that a MYFS pipe stores its content within a designated file contained in the host operating system. Within MYFS, a pipe is represented using:

You are responsible for augmenting the file open/close/read/write operations to also handle pipes.

A hard link (or link for short) is the mapping from a directory entry to an index node. For directories, there is a one-to-one mappings from directory entry to directory index node (the exceptions are: the root index node and the names . and ..). For files and pipes, there can be any number of directory entries that refer to a single index node. There is an application program that allows the user to create new links to existing index nodes

Your Responsibilities

The key new pieces that you are implementing / augmenting are:


Proper Academic Conduct

The code solution to this project must be done individually. Do not copy solutions to this problem from the network and do not look at or copy solutions from others. However, you may use the net for inspiration and you may discuss your general approach with others. These sources must be documented in your README file.


Representing File Content

The rules for representing file content are:

Representing A Pipe

The data associated with a pipe are stored within a separate file in the host operating system (Linux, in our case). A pipe is represented using:

Representing Open Files/Pipes

myfs.h provides a definition of the MYFILE structure. This structure is used to capture the details of a file that is already opened by a program. In particular:
/**********************************************************************/
// Representing files (project 4!)

#define MAX_BLOCKS_IN_FILE 1000

typedef struct
{
  INDEX_NODE_REFERENCE index_node_reference;
  char mode;
  int offset;
  int fd_external;

  // Cache for file content details.  Use of these is optional
  int n_data_blocks;
  BLOCK_REFERENCE block_reference_cache[MAX_BLOCKS_IN_FILE];
} MYFILE;

The properties are as follows:

MYFILE is exclusively an in-memory data structure. It only exists for the duration of the process that opened the file. This structure is all about providing the process the information that it needs to access an already-opened file.

Hard Links

The rules for hard links are as follows:


MYFS File/Pipe Manipulation API

myfs_fopen()

MYFILE* myfs_fopen(char *cwd, char *path, char *mode);
Open a file or a pipe. path is either absolute or relative. If it is relative, then it is taken to be relative to cwd.

mode is one of:

If the file is opened successfully, then a dynamically allocated MYFILE structure is returned that contains all of the meta data associated with the open file.

myfs_fclose()

void myfs_fclose(MYFILE* fp);

Close the MYFS file or pipe and deallocate the MYFILE structure.

myfs_fread()

int myfs_fread(MYFILE *fp, unsigned char * buf, int len);
Read a specified number of bytes from a file/pipe that is open.

myfs_fwrite()

int myfs_fwrite(MYFILE *fp, unsigned char * buf, int len);
Write a specified number of bytes to a file/pipe that is open.


Additional System Calls

int myfs_link(char *cwd, char *path_src, char *path_dst) (implement)

Create a new hard link from a new directory entry to an existing index node.

int myfs_delete_file(char *cwd, char *path) (augment)

Delete a file/pipe from a directory. Part of this implementation is provided to you. You are adding functionality to allow for more than one reference to an index node

int myfs_move(char *cwd, char *src_path, char *dest_path) (implement)

Move a directory entry for a file or pipe to another directory/name.

int myfs_mkp(char *cwd, char *path_host, char *path_myfs) (implement)

Create a new pipe. The location of the pipe in MYFS is path_myfs (relative to cwd, if necessary). The location of the file in the host operating system is determined by path_host


MYFS Application Programs (new ones)

The high-level implementation of most of the MYFS application programs is given. You will be responsible for implementing/modifying some of the underlying system calls.

Note that although all of the application programs are described below in terms of files, they operate on both files and pipes.

myfs_touch <fname> (provided)

myfs_create <fname> (provided)

myfs_append <fname> (provided)

myfs_more <fname> (provided)

myfs_copy <SRC> <DEST> (provided)

myfs_link <SRC> <DEST> (provided)

myfs_rm <name> (provided)

myfs_mkp <path_host> <path_myfst> (provided)

myfs_move <src> <dest> (provided)

Move a file or pipe from one location to another.

Three cases:

  1. src and dest are within the same containing directory. In this case, the name in the directory listing is changed.

  2. src and dest specify an existing source file/pipe and a non-existent destination file/pipe, respectively. The directory entry in src is removed; and a new directory entry is added to the parent of dest. The new entity name is specified by dest

  3. src and dest specify an existing source file/pipe and an existing destination directory. The directory entry in src is removed; and a new directory entry is added to dest. The entity name stays the same.

myfs_lc <name> (to be implemented)


Deallocation


Data Structure Examples

The following is an example of creating a hard link to an existing file:

The following is an example of creating a pipe and storing data in the pipe:


Examples

Example Interactions


Checklist

Write / Implement the following files / functions.

Supporting Materials

MYFS API (Library)

The documentation for the following can be found in the skeleton file.

Application Programs

Implement:

The supplied application programs must be compiled and work properly:


Submitting Your Program


Grading Criteria


Downloads

The following file contains several header and C files: project4_skel.tar.

Notes:


Hints


Addenda


andrewhfagg at gmail.com

Last modified: Tue Dec 8 15:06:18 2020