In this assignment you will create an undoable memory based user space ﬁle system for a Linux
Do the assignment on Ubuntu from ﬂexit.auckland.ac.nz . You can use your own machine (virtual
machines work too, including the Windows subsystem for Linux version 2) but the markers will
run your code on the ﬂexit system and it must work there to get the marks.
You need to have libfuse-dev installed, but it probably already is. The ﬂexit version is already
The Python interface is called fuse.py and it also may already be installed. It was originally
written for Python 2, but I have successfully used it with Python 3. The code distributed with the
assignment uses Python 3.
You can either use the Python package system called pip3 to install it or fuse.py can be
downloaded from https://github.com/fusepy/fusepy.
To install using pip3:
sudo apt install python3-pip (you don’t need to do this on ﬂexit, in fact you can’t)
pip3 install fusepy
Create a new directory e.g. mkdir A2 . Ensure this is in the Linux area if you are using WSL (i.e.
not in the C drive).
Download the memundo.py ﬁle from the assignment page into this directory. This is a very
slightly modiﬁed version of the memory.py example in GitHub.
In the same directory create another directory called memdir.
Try this to ensure your environment is set up correctly. The undoshell prompt is expected.
undoshell: ls -al
You should see something like:
drwxr-xr-x 2 root root 0 Aug 3 11:45 .
drwxrwxr-x 4 robert robert 4096 Aug 3 10:59 ..
As mentioned in class and tutorials this directory is now showing ﬁles from the memdir user space
The working directory for all commands you give at the undoshell prompt is always memdir.
This means that cd does not work (you can examine the code to see why this is the case).
Try the following commands (after running each command you should run ls -al):
echo “hello” > hi
cat > file1
now just type anything and finish with ctrl-D
cat hi file1 > file2
cat hi >> file2
chmod u-w file2
ln -s hi hisym
mv hi hi2
cp hi2 hi
Read and understand the memundo.py program. This is really important, you cannot make
changes until you understand what is happening here.
Step 1 [2 marks]
Currently the . directory (i.e. the base directory of the user space ﬁle system) has root for the
owner and group. Modify the program to use the current user’s id and the current group.
Also change the size to something more meaningful using sys.getsizeof. This size should
change as the number of ﬁles increases and should decrease as the number of ﬁles decreases. (See
Ensure that all ﬁles, including symbolic links, created in the directory have the correct times and
user and group information.
Hint: os.getuid(), os.getgid()
Step 2 [6 marks]
Add a single step undo command to your ﬁle system. If the user types the command undo then
the most recent changes made by another command line command (like those above) in your ﬁle
system are undone. That is, the result is as if the last command which changed something didn’t
happen. (Remove the current place holder print statement as well.)
What counts as a change? A modiﬁcation to the data structures associated with the ﬁle system. It
includes actions from the following functions:
create (can be called via touch, echo, cat etc…)
mkdir (you don’t have to make the directory hold ﬁles but this command should work)
unlink (rm calls this)
rename (mv calls this)
changed. You must therefore only save the relevant information in your undo state. The markers
will examine your source code for this.
It is possible that a single command could cause more than one state change. The undo should
reverse all of the state changes caused by the command.
Not all commands make changes to the ﬁle system. e.g. ls -al, cat file. So if the user creates
a ﬁle, lists the directory and then executes undo, the newly created ﬁle should disappear.
Step 3 [2 marks]
Add the redo command to your ﬁle system. If the user types the command redo the most recent
undo is undone. That is, the result is as if the undo did not happen. (Remove the current place
holder print statement as well.)
N.B. If a change has occurred in the ﬁle system since the last undo command was performed the
redo command does nothing and you should report “redo not possible”. Do this even if the
change had nothing to do with the ﬁles affected by the last undo command.