Last lab we got used to communicating with your pi via messages. Today we hook it up to the FUSE file system so that you can start controlling it easily from your laptop.
Useful hints:
- If you get rid of the
-d
option there is a lot less printed out to the screen. Can make it easier to debug. - If you get some kind of transport error, do
make unmount
. - To run the fuse command do
make fuse.run
(you might want to modify the make target). - Swap in the
main
in3-fs/patch.c
into yourpi-fs.c
.
Checkoff:
-
Your pi-FS works as a standard file system.
make test
should execute as expected. When the user writes values to/pi/echo
,/pi/reboot
,/pi/run
the relevant command is sent to the pi and all pi output is written to/pi/console
. -
Change
4-hello-fixed.sys
to use system calls to send characters rather than the gross hack we did. This should be a fairly quick repurposing of your lab 7 system call code. -
Your pi-FS works as a standard file system.
make part0
wil run some simple tests. You should be able to run the usual Unix file programs, have them work as expected, and have all output appear in/pi/console
. For example:% echo "hello world." > /pi/echo % cat /pi/echo hello world. % echo "bye world." > /pi/echo % cat /pi/console hello world. bye world.
Extensions:
- Add directories.
- Add
/pi/dev/led
so that writes turn the led on/off and that reads give the current state. - Add a
pthread
thread to your FS that will pull output from the pi in the background.
Different things needed for the system calls:
- Truncate can both extend (zero-fill) or shrink a file (change its size down).
- The
flags
field of the directory has the permission flags needed. st_mode
will beS_IFREG
(for a regular file) bit-wise or'd with the entriesflags
.st_nlink
is the number of pointers to this entry. Since we don't have hardlinks, files will have 1 link (their parent dir) and a directory will have two (its parent and.
). When we add subdirectories, this link count will go up+1
for each subdirectory (since..
points to it).- Both
read
andwrite
have anoffset
parameter. This indicates where to start reading or writing in the file. Reads do not go beyond the end of the file, writes will extend the file if need be and, if the offset is beyond the current end of the file, you need to zero fill everything up to that point.
I'd try simple steps:
-
First make sure you can handle file writes:
% echo "hello world." > /pi/echo.cmd % cat /pi/echo.cmd hello world. % echo "bye world." > /pi/echo.cmd % cat /pi/console hello world. bye world.
-
Then start with just reboot.
% echo 1 > /pi/reboot.cmd
Should cause a reboot.
-
Then make sure you can send code:
% cat hello-fixed.bin > /pi/run.cmd
Should run as expected.
You should have already done this for the prelab! But just to make sure you can
debug: Run the hello
example in lab11-fuse-fs/part0-hello
:
make
make mount
will mount thehello
file system; it will do so single-threaded (the-s
option) and in the fore-ground (the-f
option).make run
(in another terminal). Will do a trivial test to show it is up and running.
This code comes from (https://github.com/libfuse/libfuse/tree/master/example). There are a bunch of other examples there. Change the code so that it prints out:
hello cs140e: today let us do a short lab!
If you look in 3-pi-fs/
:
-
pi-fs.c
: starter code to implement a simple FUSE file system.
You are more than welcome to start with your hello file system if you prefer. We've defined a bunch of the methods you will need. They are likely a bit opeque, so look in thefuse.h
in your install or in many -
your file system just needs a single root directory and files, no subdirectories, so you can do a pretty simple data structure to track this. Again: you're welcome to kill all of our code.
-
make mount
: will mount your file system. -
make unmount
: will forcibly unmount if it gets stuck. -
make test
: will execute simple Unix commands to check if your system is broken.
You'll have to implement six methods:
-
getattr
get attributes of the file: its size, permissions, and number of hardlinks to it. -
open
: -
read
: read from the file at aoffset
ofsize
bytes. -
write
: write to the file at aoffset
ofsize
bytes. -
readdir
: return the directory entries in the given directory. -
ftruncate
: truncate the file.
Other than getattr
(which we already defined), these are more-or-less
identical to Unix calls, so you can just man page them to figure stuff
out. If you run FUSE with debugging output (which we do) you can see
where it is failing and why (usually permission errors).
Now you'll combine everything together.
- Implement the
do_echo
,do_reboot
,do_run
by using the code from part 1.
Break this down into steps.
- reboot:
echo 1 > ./pi/reboot
should cause a reboot. Make sure you can do multiple times. - echo:
echo hello > ./pi/echo
should echo the output. - Get the console working.
- Loading a program is a bit annoying. We didn't think to put a size field in the binary, so we don't actually know how big it is. We assume all the bytes are there for a write. This is ridiculous, but works for our simple program.
You are done!