41 Function for initializing or creating a filesystem void mkfsFilesystem files

41 function for initializing or creating a filesystem

This preview shows page 3 - 5 out of 14 pages.

any case where these differ. 4.1 Function for initializing or creating a filesystem void mkfs(Filesystem *files); This function should initialize its Filesystem parameter, but exactly what that will do depends upon the way you decide to represent and store the components of a filesystem. This function must be called to initialize any Filesystem variable, before any other operations are performed on that variable. After calling this function, the initialized Filesystem should contain or consist of only a root directory. The result of calling any of the other functions on a Filesystem variable before mkfs() is called on it is undefined. The result of calling any of the other functions is also undefined if mkfs() was initially called, but its argument was just NULL . After calling mkfs() with a non– NULL parameter any of the other functions can be called. Therefore it’s up to the user of your functions (which includes any of our tests) to call itmkfs() on any Filesystem variables that are declared or created before calling any of the other functions on them, if they want them to be properly initialized. © 2013 Larry Herman; all rights reserved 3
Image of page 3
Every call to mkfs() must initialize the Filesystem that its parameter files points to in such a way that calling mkfs() on different Filesystem variables causes each one to be a different filesystem. In other words, calling mkfs several times on different Filesystem variables will not cause them to share any files or directories. 4.2 Functions for creating files and directories int touch(Filesystem *files, const char arg[]); This function’s usual effect is to create a file, if it does not already exist. In real UNIX, if the touch command is given with the name of a file that does not exist, a new, empty file will be created with that name; the usual effect of this function in your project is analogous. In real UNIX, if touch is given the name of an already–existing file, it will update that file’s timestamp, however, this project has no notion of file or directory modification times or timestamps. • If the function’s argument arg is a name that does not refer to an existing file or directory located in the current directory at the time the function is called, its effect is to create a file with that name in the current directory (the current directory is mentioned further below). • If arg is the name of a subdirectory or a file that already exists in the current directory, or is . (a single period), .. , or / (a single forward slash), this function should have no effect. • If arg does not consist solely of a forward–slash character, yet it contains a forward–slash character anywhere, the function should return the value - 1 without making any modification to anything in its Filesystem parameter. In the real UNIX shell a command like “ touch rodent/hamster ” would create a file named hamster in the subdirectory rodent of the current directory (if it existed), because the forward slash is a directory separator. However, for simplicity in this project, such a command argument will just be invalid.
Image of page 4
Image of page 5

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture