CSC 660: Lab #9: Filesystems | |||||||
|
|||||||
We'll start by building and testing the wrapfs stackable filesytem. This filesystem layer simply passes filenames and file data to and from the user and VFS layers without making any changes. Building wrapfs and reading the code for it will help you understand how the stackable filesystem layer works, so that you can add capabilities to your filesystem in the second part of the lab.
tar zxf wrapfs.tar.gz cd wrapfs make
ctags *.[ch]
cat /proc/filesystems # List of supported filesystems insmod wrapfs.ko # Load wrapfs kernel module cat /proc/filesystems # Old list of filesystems + wrapfs
mkdir /mnt/lower mount /dev/sda5 /mnt/lower df
mkdir /mnt/wrapfs mount -t wrapfs -o dir=/mnt/lower,debug=1 /mnt/lower /mnt/wrapfs df
echo "abbabaab" >/mnt/wrapfs/a
ls -l /mnt/wrapfs /mnt/lower cat /mnt/wrapfs/a cat /mnt/lower/a diff /mnt/wrapfs/a /mnt/lower/a
mkdir /mnt/wrapfs/dir1
ls -l /mnt/wrapfs /mnt/lower
echo "baababba" >/mnt/wrapfs/dir1/a ls -l /mnt/wrapfs/dir1 /mnt/lower/dir1
Now let's modify wrapfs to create caesarfs, a filesystem that encrypts file data using a Caesar cipher. The Caesar cipher encrypts each character individually by substituting each letter of the alphabet with a later letter of the alphabet. For example, in Caesar's original cipher, each letter was replaced with a letter three places later in the alphabet, with letters at the end of the alphabet being rotated to the beginning as follows:
Plaintext Alphabet: abcdefghijklmnopqrstuvwxyz Ciphertext Alphabet: defghijklmnopqrstuvwxyzabcThe encryption and decryption functions can be given as
E(x) = (x + n) % 26 D(x) = (x - n) % 26where x is a the number of a letter from 0 ('a') through 25 ('z') and n is the key of the cipher (3 in the example above.) Only uppercase and lowercase letters are encrypted. Non-alphabetic characters are left unchanged by the cipher.
umount /mnt/wrapfs
make clean
gvim -t wrapfs_encode_block
grep -2 wrapfs_encode_block *.[ch] grep -2 wrapfs_decode_block *.[ch]
mv ... ... # One mv per file with wrapfs in the filename perl -pi -e 's/wrapfs/caesarfs/g' *.[ch] Makefile
gvim fist_caesarfs.c
make su insmod caesarfs.ko cat /proc/filesystems
mount -t caesarfs -o dir=/mnt/lower,debug=1 /mnt/lower /mnt/caesarfs
echo "abbabaab" >/mnt/caesarfs/a ls -l /mnt/caesarfs /mnt/lower cat /mnt/caesarfs/a cat /mnt/lower/a
echo "abcdefghijklmnopqrstuvwxyz" >/mnt/caesarfs/alphabet cat /mnt/caesarfs/alphabet cat /mnt/lower/alphabet