Skip to content

Commit

Permalink
Add initial skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
pbui committed Nov 21, 2018
0 parents commit c35937e
Show file tree
Hide file tree
Showing 25 changed files with 2,969 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
bin/unit_*
bin/test_*
data/image.unit
lib/lib*.a
test.log
*.o
*.swp
76 changes: 76 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Configuration

CC = gcc
LD = gcc
AR = ar
CFLAGS = -g -std=gnu99 -Wall -Iinclude -fPIC
LDFLAGS = -Llib
LIBS = -lm
ARFLAGS = rcs

# Variables

SFS_LIB_HDRS = $(wildcard include/sfs/*.h)
SFS_LIB_SRCS = $(wildcard src/library/*.c)
SFS_LIB_OBJS = $(SFS_LIB_SRCS:.c=.o)
SFS_LIBRARY = lib/libsfs.a

SFS_SHL_SRCS = $(wildcard src/shell/*.c)
SFS_SHL_OBJS = $(SFS_SHL_SRCS:.c=.o)
SFS_SHELL = bin/sfssh

SFS_TEST_SRCS = $(wildcard src/tests/*.c)
SFS_TEST_OBJS = $(SFS_TEST_SRCS:.c=.o)
SFS_UNIT_TESTS = $(patsubst src/tests/%,bin/%,$(patsubst %.c,%,$(wildcard src/tests/unit_*.c)))

# Rules

all: $(SFS_LIBRARY) $(SFS_UNIT_TESTS) $(SFS_SHELL)

%.o: %.c $(SFS_LIB_HDRS)
@echo "Compiling $@"
@$(CC) $(CFLAGS) -c -o $@ $<

$(SFS_LIBRARY): $(SFS_LIB_OBJS)
@echo "Linking $@"
@$(AR) $(ARFLAGS) $@ $^

$(SFS_SHELL): $(SFS_SHL_OBJS) $(SFS_LIBRARY)
@echo "Linking $@"
@$(LD) $(LDFLAGS) -o $@ $^ $(LIBS)

bin/unit_%: src/tests/unit_%.o $(SFS_LIBRARY)
@echo "Linking $@"
@$(LD) $(LDFLAGS) -o $@ $^

test-unit: $(SFS_UNIT_TESTS)
@for test in bin/unit_*; do \
for i in $$(seq 0 $$($$test 2>&1 | tail -n 1 | awk '{print $$1}')); do \
echo "Running $$(basename $$test) $$i"; \
valgrind --leak-check=full $$test $$i > test.log 2>&1; \
grep -q 'ERROR SUMMARY: 0' test.log || cat test.log; \
! grep -q 'Assertion' test.log || cat test.log; \
done \
done

test-shell: $(SFS_SHELL)
@for test in bin/test_*.sh; do \
$$test; \
done

test: test-unit test-shell

clean:
@echo "Removing objects"
@rm -f $(SFS_LIB_OBJS) $(SFS_SHL_OBJS) $(SFS_TEST_OBJS)

@echo "Removing libraries"
@rm -f $(SFS_LIBRARY)

@echo "Removing programs"
@rm -f $(SFS_SHELL)

@echo "Removing tests"
@rm -f $(SFS_UNIT_TESTS) test.log

.PRECIOUS: %.o
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Project 06: Simple File System

This is [Project 06] of [CSE.30341.FA18].

## Members

1. Domer McDomerson ([email protected])
2. Belle Fleur ([email protected])

## Errata

> Describe any known errors, bugs, or deviations from the requirements.
## Extra Credit

> Describe what extra credit (if any) that you implemented.
[Project 06]: https://www3.nd.edu/~pbui/teaching/cse.30341.fa18/project06.html
[CSE.30341.FA18]: https://www3.nd.edu/~pbui/teaching/cse.30341.fa18/
80 changes: 80 additions & 0 deletions bin/test_00_debug.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/bin/bash

image-5-output() {
cat <<EOF
SuperBlock:
magic number is valid
5 blocks
1 inode blocks
128 inodes
Inode 1:
size: 965 bytes
direct blocks: 2
2 disk block reads
0 disk block writes
EOF
}

image-20-output() {
cat <<EOF
SuperBlock:
magic number is valid
20 blocks
2 inode blocks
256 inodes
Inode 2:
size: 27160 bytes
direct blocks: 4 5 6 7 8
indirect block: 9
indirect data blocks: 13 14
Inode 3:
size: 9546 bytes
direct blocks: 10 11 12
4 disk block reads
0 disk block writes
EOF
}

image-200-output() {
cat <<EOF
SuperBlock:
magic number is valid
200 blocks
20 inode blocks
2560 inodes
Inode 1:
size: 1523 bytes
direct blocks: 152
Inode 2:
size: 105421 bytes
direct blocks: 49 50 51 52 53
indirect block: 54
indirect data blocks: 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
Inode 9:
size: 409305 bytes
direct blocks: 22 23 24 25 26
indirect block: 28
indirect data blocks: 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 76 77 78 79 80 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
23 disk block reads
0 disk block writes
EOF
}

test-debug() {
DISK=$1
BLOCKS=$2
OUTPUT=$3

echo -n "Testing debug on $DISK ... "
if diff -u <(./bin/sfssh $DISK $BLOCKS <<<debug 2> /dev/null) <($OUTPUT) > test.log; then
echo "Success"
else
echo "Failure"
cat test.log
fi
rm -f test.log
}

test-debug data/image.5 5 image-5-output
test-debug data/image.20 20 image-20-output
test-debug data/image.200 200 image-200-output
67 changes: 67 additions & 0 deletions bin/test_01_format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/bash

image-5-output() {
cat <<EOF
disk formatted.
SuperBlock:
magic number is valid
5 blocks
1 inode blocks
128 inodes
2 disk block reads
5 disk block writes
EOF
}

image-20-output() {
cat <<EOF
disk formatted.
SuperBlock:
magic number is valid
20 blocks
2 inode blocks
256 inodes
3 disk block reads
20 disk block writes
EOF
}

image-200-output() {
cat <<EOF
disk formatted.
SuperBlock:
magic number is valid
200 blocks
20 inode blocks
2560 inodes
21 disk block reads
200 disk block writes
EOF
}

test-input() {
cat <<EOF
format
debug
EOF
}

test-format() {
DISK=$1
BLOCKS=$2
OUTPUT=$3

cp $DISK $DISK.formatted
echo -n "Testing format on $DISK.formatted ... "
if diff -u <(test-input | ./bin/sfssh $DISK.formatted $BLOCKS 2> /dev/null) <($OUTPUT) > test.log; then
echo "Success"
else
echo "Failure"
cat test.log
fi
rm -f $DISK.formatted test.log
}

test-format data/image.5 5 image-5-output
test-format data/image.20 20 image-20-output
test-format data/image.200 200 image-200-output
143 changes: 143 additions & 0 deletions bin/test_02_mount.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
#!/bin/bash

#!/bin/bash

mount-input() {
cat <<EOF
mount
EOF
}

mount-output() {
cat <<EOF
disk mounted.
2 disk block reads
0 disk block writes
EOF
}

mount-mount-input() {
cat <<EOF
mount
mount
EOF
}

mount-mount-output() {
cat <<EOF
disk mounted.
mount failed!
2 disk block reads
0 disk block writes
EOF
}

mount-format-input() {
cat <<EOF
mount
format
EOF
}

mount-format-output() {
cat <<EOF
disk mounted.
format failed!
2 disk block reads
0 disk block writes
EOF
}

test-mount () {
TEST=$1

echo -n "Testing $TEST on data/image.5 ... "
if diff -u <($TEST-input| ./bin/sfssh data/image.5 5 2> /dev/null) <($TEST-output) > test.log; then
echo "Success"
else
echo "Failure"
cat test.log
fi
rm -f test.log
}

test-mount mount
test-mount mount-mount
test-mount mount-format

SCRATCH=$(mktemp -d)
trap "rm -fr $SCRATCH" INT QUIT TERM EXIT

bad-mount-input() {
cat <<EOF
mount
EOF
}

bad-mount-output() {
cat <<EOF
mount failed!
1 disk block reads
0 disk block writes
EOF
}

echo -n -e $(printf '\\x%x\\x%x\\x%x\\x%x' 0x10 0x34 0xf1 0xf0) > $SCRATCH/image.5
echo -n -e $(printf '\\x%x\\x%x\\x%x\\x%x' 0x05 0x00 0x00 0x00) >> $SCRATCH/image.5
echo -n -e $(printf '\\x%x\\x%x\\x%x\\x%x' 0x01 0x00 0x00 0x00) >> $SCRATCH/image.5
echo -n -e $(printf '\\x%x\\x%x\\x%x\\x%x' 0x80 0x00 0x00 0x00) >> $SCRATCH/image.5
echo -n "Testing bad-mount on $SCRATCH/image.5 ... "
if diff -u <(bad-mount-input| ./bin/sfssh $SCRATCH/image.5 5 2> /dev/null) <(bad-mount-output) > $SCRATCH/test.log; then
echo "Success"
else
echo "Failure"
cat $SCRATCH/test.log
fi

echo -n -e $(printf '\\x%x\\x%x\\x%x\\x%x' 0x10 0x34 0xf1 0xf0) > $SCRATCH/image.5
echo -n -e $(printf '\\x%x\\x%x\\x%x\\x%x' 0x05 0x00 0x00 0x00) >> $SCRATCH/image.5
echo -n -e $(printf '\\x%x\\x%x\\x%x\\x%x' 0x01 0x00 0x00 0x00) >> $SCRATCH/image.5
echo -n -e $(printf '\\x%x\\x%x\\x%x\\x%x' 0x80 0x00 0x00 0x00) >> $SCRATCH/image.5
echo -n "Testing bad-mount on $SCRATCH/image.5 ... "
if diff -u <(bad-mount-input| ./bin/sfssh $SCRATCH/image.5 5 2> /dev/null) <(bad-mount-output) > $SCRATCH/test.log; then
echo "Success"
else
echo "Failure"
cat $SCRATCH/test.log
fi

echo -n -e $(printf '\\x%x\\x%x\\x%x\\x%x' 0x10 0x34 0xf0 0xf0) > $SCRATCH/image.5
echo -n -e $(printf '\\x%x\\x%x\\x%x\\x%x' 0x00 0x00 0x00 0x00) >> $SCRATCH/image.5
echo -n -e $(printf '\\x%x\\x%x\\x%x\\x%x' 0x01 0x00 0x00 0x00) >> $SCRATCH/image.5
echo -n -e $(printf '\\x%x\\x%x\\x%x\\x%x' 0x80 0x00 0x00 0x00) >> $SCRATCH/image.5
echo -n "Testing bad-mount on $SCRATCH/image.5 ... "
if diff -u <(bad-mount-input| ./bin/sfssh $SCRATCH/image.5 5 2> /dev/null) <(bad-mount-output) > $SCRATCH/test.log; then
echo "Success"
else
echo "Failure"
cat $SCRATCH/test.log
fi

echo -n -e $(printf '\\x%x\\x%x\\x%x\\x%x' 0x10 0x34 0xf0 0xf0) > $SCRATCH/image.5
echo -n -e $(printf '\\x%x\\x%x\\x%x\\x%x' 0x05 0x00 0x00 0x00) >> $SCRATCH/image.5
echo -n -e $(printf '\\x%x\\x%x\\x%x\\x%x' 0x02 0x00 0x00 0x00) >> $SCRATCH/image.5
echo -n -e $(printf '\\x%x\\x%x\\x%x\\x%x' 0x80 0x00 0x00 0x00) >> $SCRATCH/image.5
echo -n "Testing bad-mount on $SCRATCH/image.5 ... "
if diff -u <(bad-mount-input| ./bin/sfssh $SCRATCH/image.5 5 2> /dev/null) <(bad-mount-output) > $SCRATCH/test.log; then
echo "Success"
else
echo "Failure"
cat $SCRATCH/test.log
fi

echo -n -e $(printf '\\x%x\\x%x\\x%x\\x%x' 0x10 0x34 0xf0 0xf0) > $SCRATCH/image.5
echo -n -e $(printf '\\x%x\\x%x\\x%x\\x%x' 0x05 0x00 0x00 0x00) >> $SCRATCH/image.5
echo -n -e $(printf '\\x%x\\x%x\\x%x\\x%x' 0x01 0x00 0x00 0x00) >> $SCRATCH/image.5
echo -n -e $(printf '\\x%x\\x%x\\x%x\\x%x' 0x70 0x00 0x00 0x00) >> $SCRATCH/image.5
echo -n "Testing bad-mount on $SCRATCH/image.5 ... "
if diff -u <(bad-mount-input| ./bin/sfssh $SCRATCH/image.5 5 2> /dev/null) <(bad-mount-output) > $SCRATCH/test.log; then
echo "Success"
else
echo "Failure"
cat $SCRATCH/test.log
fi
Loading

0 comments on commit c35937e

Please sign in to comment.