Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
COSC 1114 Operating Systems Principles
Semester 2, 2021 Programming Assignment 2 Assessment Type Individual assignment. Marks are awarded for meeting requirements as closely as possible. Clarifications/updates may be made via announcements/relevant discussion forums. Submission Policy Submit online to Canvas → Assignments → PrgAsg2 . 2 submissions are required . The first in week 13, and the final submission in start of week 14. Late final submissions are penalized at the rate of 10% per day, pro-rata to 1%. In other words, the formula is floor(hoursLate*10/24) as percentage of the mark received. So 12 hours late for a submission given the mark 20/30 will be penalized as per newMark = origMark * (1 – (floor(hoursLate*10/24) / 100)) = 20 * (1 – 0.05) = 19 to 19/30. NB. In any dispute over late submissions, GitHub commit dates (which can be falsified) will NOT be considered acceptable as evidence. Submission Due Date Start of week 14. Marks 30 (30% of semester) 1. Overview One of the other large areas in operating systems beyond process management is the domain of File Systems. As you can see in the Group Project title list, there are a lot of them. But they all have some features in common, and in this assignment, we will cover some of these common features. In this assignment, you will build a very simple file system (VSFS), which is essentially a large text file. You will write a program or script that will insert entries from outside into this FS and vice-versa, as well as many other common file actions. For documentation, you will reflect how certain additions, such as file blocking, FS compression, FS defragmentation, could be implemented into your code (without doing it). For higher marks, you will implement some of these 2. Learning Outcomes This assessment relates to all the learning outcomes of the course which are: • Summarise the full range of considerations in the design of file systems, summarise techniques for achieving synchronisation in an operation system, 3. Project Details 3.1 Command Line You must create a program, called, say, VSFS, that creates a file system called, say, FS, that can be called from the command line and will work as follows. (General format: “VSFS command FS rags…”, where command is {list copyin; copyout; mldir; rm; rmdir…}) 1. VSFS list FS List the contents of FS in “ls -lR” format a. Format: AAAAAAA NNN OOOOOOOO GGGGGGGG SSSSSSSS DATETIME [PATH/]FILENAME Where All elements are separated by a single space char. A = attribute. Use the same file attribute as the FS, except where d=”-” if the entry is a file, and “d” if a directory. Page 2 of 6 RMIT Classification: Trusted N = number of hard link if a file or number of subdirs if a fir. Use “ 1” (3 chars) for file as links not allowed, else use number of dirs. 1 level below. O,G = owner and group of the VSFS file Use the owner/group of the FS S = size of the file in bytes (optional, make size = nyuumber of lines in the file) Datetime = datetime of the FS file in “ls -l” format. Path/file = the note name Example: drwxr-xr-x+ 3 W8431514+ronvs W8431514+None 0 Oct 22 2020 usr/libexec/mc/extfs.d/ drwxr-xr-x+ 1 W8431514+ronvs W8431514+None 0 Oct 12 12:45 usr/libexec/mc/extfs.d/README As you can see, the owner/group strings can vary in length from the standard. 2. VSFS copyin FS EF IF Copy the external file, EF, into the FS as internal file named IF 3. VSFS copyout FS IF EF Copy the internal file IF within FS to external file EF 4. VSFS mkdir FS ID creates empty internal directory ID in FS 5. VSFS rm FS IF Remove internal file IF from FS 6. VSFS rmdir FS ID Remove internal directory ID from FS 7. VSFS defrag FS Defragment FS, removing all deleted entries 8. VSFS index FS (Re-)Create a global index for FS Where the parameters are defined as follows: • “IF” can be a path without the leading “/” and ending in a file name but not ending with a “/”. o The path referred to here is the internal path, NOT the Unix path. o IF should never be “.” Or “..” or “/” • For copyin and cioyout, the internal and external paths must already exist else error • For mkdir the ID must NOT already exist else error • For rm and rmdir, the IF / ID must/dir exist, else error. • “EF” can be a filename, or a path ending in a filename. If it is only a file, it is copied to the local directory. If OF is a path, then all folders along the path must already exist. The path is relative to the local directory unless preceded by a “/” • The command mkdir and rmdir require a directory, but in this case, the trailing “/” is optional o mkdir creates a file called “ID” o rmdir calls rm for each file within ID and dir containing that path, and then rmdir the ID • “FS” can be a standard Unix file (and can include a path). • “ID” is the same as “IF” except that it must be a directory. Think of the Unix program “zip” and its command line arguments. The ZIP file is the system, and you use “zip” and “unzip” to manipulate the FS, but there are also programs like “WinZIP” that do both. Suggestion for developers: Get all the above working for files first, then later put in the path handling. 3.2 File format In the list above, “VSFS” is the name of a Very Simple File System (VSFS) file. For this assignment, we will implement a notes file format, so the VSFS format will have a default extension of “.notes”. The notes file format is described as follows. 1. It is a text file with variable length records. 2. A record is terminated with “\n”, so a C function fgets() would return it as a string. 3. Maximum record length is 255 characters including “\n”. When using copyin, all longer records are truncated. 4. All records starting with “#” are ignored. 5. The first record in the VSFS file starts with “NOTES V1.0”. A valid notes file must contain this text in the first line. 6. A file name record starts with “@” as the first character followed by a “path/…/file” entry. If path is omitted, path = “”. That is, there is no leading “/” in the name. So a plain file “abc” is encoded as “@abc” 7. A directory record is a file record starting with “=” and ending with a path ending in “/”. 8. A content record contains a “ ” (space) in the first character and must succeed a file record. All subsequent content records go in the same file entry, until a non-content record is encountered. 9. A file may be deleted. In that case, the file record and any following content records will have the first character set to “#”. 10. A new file using copyin is always appended to the VSFS. Page 3 of 6 RMIT Classification: Trusted 11. If copyin is used to replace a file, that file is first deleted, and the new file appended. 12. When using copyin to insert a file, always prepend the content records with a “ ” (space). 13. When using copyout to extract a file, always remove the first character (“ ”) before saving. 14. Only records starting with one of the first characters described above are allowed in the VSFS file. Any other character should result in an error. 15. No two notes should have identical names at the same directory level. 16. All errors should result in a “Invalid VSFS” message to stderr, and exit code of 1 (eg. “exit(1)“ ( 17. When reading a FS, any deleted records should not be acted upon, but should also not be removed. This way deleted files should remain in the VSFS until explicitly removed. Sample file: 3.3 Midnight Commander, mc. The program mc (“Midnight Commander”) is a program that resembles Windows Explorer, or Finder on the Mac, except that it runs in text mode. The program is already installed on Titan, so just run it using “mc”. The program provides a wealth of capabilities for dealing with files and is commonly used to maintain broken Linux systems that are running in single-user mode with mc as a TUI in console mode. It opens with two screens, which can move independently through the Unix file system. Normally you press TAB to swap screens. You can press function keys such as F5 to copy the highlighted file to the directory in the other screen. This is somewhat equivalent to a drag-and-drop operation. mc has an interface that allows it to decompress ZIP, TAR.GZ and other compressed files, and render them just as it does on normal files. You simply cursor to a file (say, abc.zip) that contains folder A and B, with files a/aa and b/bb, then if you press return while on abc.zip, it will open up the window with two directories, a, b, and if you enter a, you will find aa. This functionality is called an external file system, or extfs, and mc allows new entries to be added. You can find all the configured file locations using the command “mc -F”, On titan, the extfs folder is “/usr/libexec/mc/extfs.d“. If you look at the files here, you will find script files that implement the same interface as the VSFS program described above – even a README that explains the interface. You might like to look at UZIP which uses zip and unzip to maintain zip files, and is written in Perl.