| 
 Welcome to
CEG4350/CEG5350 - Operating Systems
  
 | 
 
 | 
  
    
    
      
        
        P2: Subdirectories, and Moving Files
         | 
       
      
        | 
        
         | 
       
      
        | 
        
         | 
       
       
     | 
  
The project for the current term is to implement (on a simulated disk) a file system based on the design explored in the 
lectures.  This project is divided into four pieces.
  You must read and follow the
Project Expectations.  Study the grading 
sheet given below.
This is Part 0 of the project for this term.  You are expected to study and modify the 
source code files given in source.tbz and achieve the functionality described below.  Do not use source code files 
of others or even those of mine but from prior terms.  
Be Considerate. Do make sure that you are not using up too much space 
(say > 10 MB) in your home directory.  The following will show your disk 
space usage:  du -s ~
1. Studying a Program
By the time P2 is due, we would have covered the essentials of our
File Sys project.  
The tar ball source.tbz is a collection of files given so
that (i) you can get started quickly with our project, and (ii) you can see the style of how larger systems programs are written. Download source.tbz from the link
above.  In a Linux environment, it can be un-tar-ed as follows:  tar xvvfj source.tbz
The functionality of  source.tbz  is 
described in What Is Given.  Some details of the code are/were explained in the lectures and in
ReadMe.txt. Study the provided source code
so thoroughly that you could have written it. Then, answer the itemized questions below in a file named
answers.txt.
  - The following  are standard library routines:
    fopen, fclose, fread, fwrite, fstat, fscanf, fprintf,
sprintf
Look up their
functionality in both the Stevens' book and the on-line man
pages.  Describe their functionality briefly, one sentence each,
in your own words. 
  - List the names of 5 standard library routines other than the
above, and 5 system calls used by the code of P2.
 
-  In the file
simDisk.C, what is the point in verifying that
statBuf.st_size == nSectorsPerDisk * nBytesPerSector? -  Study the
	Notes 
	on Programming in C, by 
	Rob Pike.  All of it is "very" applicable to C++ also.    For five identifiers used in the given
source code, (i) either suggest better alternate names and defend why
they are better, or (ii) explain why you are comfortable with the
names as-they-are. 
 
- Write the pre- post conditions for 
uint FileVolume::read33file(byte 
 *fs33leaf, byte *unixFilePath)
uint FileVolume::write33file(byte *unixFilePath, byte 
*fs33leaf) 
2. Learn to Use GDB
Coming into the course, you are expected to be comfortable with gdb.
Debugging large programs requires the construction of (extra) observer
methods.  Using gdb or some other debugger is not as
effective as invoking observers and studying their output in a
peaceful place ("under a tree").  Nevertheless, gdb can be useful as a
last resort, and you must be able to use it well.
  - Start 
script. Make P2 as given. Run our program P2 through gdb. 
  - Set a breakpoint at immediately after 
setArgsGiven(buf, arg, types, nMax);  Examine the values of
  buf, arg, types, nMax. 
  - Type in a command to our shell to make a file volume. Trace the
execution from the above breakpoint onwards by single stepping until
after 
simDisk is initialized in mkSimDisk(). 
  - Set a breakpoint at the bottom of the 
SimDisk
constructor. Examine the value of  diskName. 
  - Type in a 
wrdisk request followed by a rddisk. 
Verify that the results match. 
  - End the script.  Turn in this script as a file named 
gdbSession.txt 
3. Additions and Improvements
Part of large program development is independently, but wisely,
deciding what to do for certain "erroneous" situations. Should we ask
the professor for what to do for every possible error you can think
of?  [Answer: No. You think about it. You take a reasonable
action. You document this in your source code, and in
ReadMe.txt. And, be ready to defend your choice should it
be questioned.]  Should SimDisk() constructor
printf or cout>> an error message? [No.]
When does/should mkSimDisk() return a zero?
[Think.]  Remember that one of the goals of CEG 433/633 is to
make you think about larger programs. Part of this is to supply
missing, but needed, details in the problem description.
As given, the files of source.tbz implement the following.  
  fs33% mkfs disknm  
  - creates an initially empty file volume on the simulated
disk named 
disknm.dsk.  
	The maxfnm, the number of i-nodes, and the i-node height are 
	all given in the 
  diskparams.dat file 
	corresponding to the line for disknm.  The file volume so
constructed is the current file volume as used
below.    The height does include the fileSize
field.  If disknm.dsk is not already created, do so now.
  
  The names of 433-files are at most maxfnm characters long.  Valid 
	characters in file names are a-z, A-Z, 0-9, hyphen (minus), and period ('.'); all other 
	characters (spaces, slashes, control characters, etc.) are illegal.  maxfnm is given 
    in diskparams.dat.Here is an example diskparams.dat. Lines starting with # are comments.   
  For clarity, I have lined-up the columns, but the actual diskparams.dat 
  may not do so.
  
# diskName nBlocks nBytesPerSector maxFnm nInodes iNodeHt
D1             128             512      8      20       3
D2            1024             256     16     100       8
 
  fs33% cp @P0/test0.cpp myfile.txt  
  - copies 
P0/test0.cpp from your Linux (indicated by the @ sign) 
	current working directory to the current (for now, root) directory of the current file volume, as a file named myfile.txt  and
prints to stdout the i-node number of  myfile.txt. 
If  myfile.txt already exists, the new content silently
replaces it.  (In the cp commands, we need to simultaneously deal with path names of files in 433-file-volume and Linux.  
  Only in such cases,  the latter are prefixed with the @ symbol.) 
  fs33% cp myfile.txt @P0/test1.cpp
      
  - copies 
myfile.txt of the current file volume to P0/test1.cpp of your Linux current directory and prints to stdout
the i-node number of  myfile.txt.  If 
  P0/test1.cpp already exists, it is silently replaced.   
  fs33% cp myfile.txt file2.txt  
  - copies 
myfile.txt of the current file volume to file2.txt
of the current volume and prints to stdout the i-node
number of file2.txt.  If  file2.txt
already exists, the new content replaces it. 
  fs33% ls  
  - prints a listing, much like the Unix 
ls -lisa, of
all the files in the root directory of the current file
volume.  
  fs33% rm myfile.txt  
  - remove the file named 
myfile.txt from the root directory and 
  prints to stdout
the i-node number that  myfile.txt  had.   If 
  the file named myfile.txt does not exist, be quiet and print  0. 
  - fs33% inode 4 
 
  - prints the contents of i-node numbered 4,  if it exists, of the current file volume. 
 
Here is a stdTestScriptP2.txt.  Use it as in ./P2 < stdTestScriptP2.txt 
with the above diskparams.dat as well as with this one.
3.1 Improvements
You will find that P2, as given, is "functional" but fragile (not robust).  Improve it so that it is crash-proof no matter what inputs 
are given. Describe the changes you made in a file named improvements.txt. 
In later project phases, we (you and I) will replace invocations of TODO by working code. 
3.2 Nested Directories
This P2 deals with only one file volume at a time.  No mounting is 
    involved.  Thus, we have only one file volume to deal with at 
     any time.  Our goal in this part of the project is to add hierarchical 
directories.  Our shell should now have mkdir, rmdir 
    and chdir commands.  It must, of course, have a
single anonymous directory that is the root.
3.3 Moving Files
Unix command mv does two things: (i) when the last argument given is a directory already existing, it moves the 
files or directories given in the rest of the arguments from where they are into this target directory, or (ii) renames the first 
argument file or directory into the second argument.  Look up the man page for more details.
3.4 A Simple Test Session
 Only the additional elements compared to the given P2 are described below.   Add 
these appropriately to the test script.  Our path name syntax is 
the same as Unix path names.   Obviously, 
not every arbitrary string is a valid path or name.  Also, the dot and the 
dot-dot are not permissible as arguments in some contexts below.  
Nevertheless these commands must be robust.   In the following, all 
meta-variable names that end in pnm are pathnames that are either 
relative to the current directory or are full/absolute pathnames.
  - fs33% mkdir dnm
 
  - creates a new empty directory named 
dnm in the current
	directory, and prints its i-node number.  If a file or directory named
  dnm already exists in the current directory, it creates nothing 
  new and returns 0.  The i-node now needs to have a field that indicates that 
  it is or is not a directory.  Assume that dnm does not contain slashes. 
  - fs33% rmdir dnm 
 
  - If the directory 
dnm is empty, deletes it.  If dnm 
  is non-empty, no change is made in the file system. In either case, it prints 
  the number of directory entries in dnm (not counting the dot and 
  dot-dot). 
  - fs33% mv da db
 
  - The 
da is either a normal file or a directory. If da 
  does not exist, return 0 and nothing is altered in the file volume.  If
  db does not exist in the current directory, da is renamed as
  db.  If db is an existing directory  in 
  the current directory, the da is moved (along with all its 
  contents) inside db as a subdirectory of db.  
  If db is an existing but ordinary file, return 0. Carefully 
  consider if da and db can be pathnames. 
  - fs33% chdir pnm 
 
  - changes the current directory to pnm.   If it begins with 
  slash, it is an absolute path name. and the new current directory is pnm.  
  If 
pnm does not begin with a slash, the new current directory is
  pnm relative to the present current directory.  In either 
  case, print the absolute full path name of the new current directory.   
  Current directory is initially established as the root of a newly created/ 
  found file volume. 
  - fs33% pwd 
 
  - prints the full path name of current directory.  
 
  - fs33% 
ls pnm 
  - prints the contents of directory 
pnm in the "long" 
  format as in Unix ls -l. 
  - fs33% inode myfile.txt 
 
  - is an overload of the above command.  It first discovers the i-number 
  of file 
myfile.txt  located in the current directory of the 
  current volume and then invokes the inode command above. 
4. Turn In
 All projects need to be submitted via 
Pilot.
 
  
    | 
    
     | 
  
  
    | Extra credit points are awarded in recognition of good work and 
		extra work, in addition to the max possible points.  Quality is 
		subjectively judged.  Merely turning in a file will not receive 
		full score.  Some items have a cascading effect. | 
  
  
    | Item description | 
    Max | 
    Points | 
  
  
      ReadMe.txt exists with content as described in Project Expectations | 
      5 | 
        | 
    
  
    Your testscript.txt is designed so that all the functionality 
    is demonstrated, including robustness.  | 
    5 | 
      | 
  
  
    Your program successfully navigates your own testscript.txt.  
    ( If yours is too simple, we may run it through our script that you 
    will get to see only after the due date.) | 
    5 | 
      | 
  
  
      answers.txt | 
      5 | 
        | 
    
  
      gdbSession.txt | 
      10 | 
        | 
    
  
      | Improvement | 
      5 | 
        | 
    
  
    mkdir dnm  | 
    10 | 
      | 
  
  
    chdir pnm  | 
    10 | 
      | 
  
  
    rmdir dnm  | 
    10 | 
      | 
  
  
    ls dnm  | 
    10 | 
      | 
  
  
    mv da db (db may not exist, but if it does, it is an ordinary 
    file) | 
    5 | 
      | 
  
  
    mv da db (db exists, and is a directory; da may or may not 
    exist inside db) | 
    5 | 
      | 
  
  
    mv da db (both are path names) | 
    5 | 
      | 
  
  
    pwd  | 
    5 | 
      | 
  
  
    inode printing for both i-numbers and 
    file names | 
    5 | 
      | 
  
  
    Bonus points 25, if you implement rm -fr directory-name (Look up: man rm) | 
    B25 | 
      | 
  
  
    Bonus points 25, if you implement ls -lR directory-name (Look up: man ls) | 
    B25 | 
      | 
  
  
    Files were not submitted using pilot = minus 10 
    points | 
    -10 | 
      | 
  
  
    | Total | 
    100 | 
      |