FileRecovery-nyufile / src / test / ms4.sh
ms4.sh
Raw
#!/bin/bash
# This is the test for Milestone 4

# [root@... cs202]# mount fat32.disk /mnt/disk
# [root@... cs202]# ls -p /mnt/disk
# DIR/  EMPTY  HELLO.TXT
# [root@... cs202]# cat /mnt/disk/HELLO.TXT
# Hello, world.
# [root@... cs202]# rm /mnt/disk/HELLO.TXT
# rm: remove regular file '/mnt/disk/HELLO.TXT'? y
# [root@... cs202]# ls -p /mnt/disk
# DIR/  EMPTY
# [root@... cs202]# umount /mnt/disk
# [root@... cs202]# ./nyufile fat32.disk -l
# DIR/ (size = 0, starting cluster = 4)
# EMPTY (size = 0, starting cluster = 0)
# Total number of entries = 2
# [root@... cs202]# ./nyufile fat32.disk -r HELLO
# HELLO: file not found
# [root@... cs202]# ./nyufile fat32.disk -r HELLO.TXT
# HELLO.TXT: successfully recovered
# [root@... cs202]# ./nyufile fat32.disk -l
# HELLO.TXT (size = 14, starting cluster = 3)
# DIR/ (size = 0, starting cluster = 4)
# EMPTY (size = 0, starting cluster = 0)
# Total number of entries = 3
# [root@... cs202]# mount fat32.disk /mnt/disk
# [root@... cs202]# ls -p /mnt/disk
# DIR/  EMPTY  HELLO.TXT
# [root@... cs202]# cat /mnt/disk/HELLO.TXT
# Hello, world.

echo -e "\033[0;32mInitializing disk...\033[0m"
cd ../../
dd if=/dev/zero of=fat32.disk bs=256k count=1
mkfs.fat -F 32 -f 2 -S 512 -s 1 -R 32 fat32.disk

echo -e "\033[0;32mMounting disk...\033[0m"
rm -rf /mnt/disk
mkdir /mnt/disk
mount fat32.disk /mnt/disk
echo "Hello, world." > /mnt/disk/HELLO.TXT
mkdir /mnt/disk/DIR
touch /mnt/disk/EMPTY
sync
ls -p /mnt/disk
cat /mnt/disk/HELLO.TXT
echo -e "\033[0;33m"
xxd -s 20480 -l 96 fat32.disk
echo -e "\033[0m"

echo -e "\033[0;32mDeleting file...\033[0m"
rm -f /mnt/disk/HELLO.TXT
ls -p /mnt/disk
umount /mnt/disk

cd src/main
echo -e "\033[0;32mListing deleted version...\033[0m"
./nyufile ../../fat32.disk -l
echo -e "\033[0;32mFaulty recovery command...\033[0m"
./nyufile ../../fat32.disk -r HELLO
echo -e "\033[0;32mProper recovery command...\033[0m"
./nyufile ../../fat32.disk -r HELLO.TXT
echo -e "\033[0;32mListing undeleted version...\033[0m"
./nyufile ../../fat32.disk -l

echo -e "\033[0;32mChecking...\033[0m"
cd ../../
mount fat32.disk /mnt/disk
ls -p /mnt/disk
cat /mnt/disk/HELLO.TXT
umount fat32.disk

echo -e "\033[0;32mDone.\033[0m"
echo -e "\033[0;33m"
xxd -s 20480 -l 96 fat32.disk
echo -e "\033[0m"
cd src/test