-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
137 lines (130 loc) · 5.7 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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
# Echoing into /dev/urandom is needed to prevent read errors. Excuse the fact
# that there are so much of them, but any less wouldn't cut it. What a bloody
# mess.
RANDOMIZE := echo abcedfghijklmnopqrstuvwxyz > /dev/urandom
# In the following comments, "----" is a block and the default 1 block/zone is
# assumed, since there is no way to modify it with /mkfs.mfs.
# Block size is assumed to be 4096 bytes.
all: mntflag
@echo "You really should pipe the output to less : 'make 2 &>1 | less'"
@echo "You now have 4 seconds to cancel (C-c) if you haven't."
@sleep 4
@$(RANDOMIZE)
@$(RANDOMIZE)
@$(RANDOMIZE)
@dd if=/dev/urandom of=/mnt/disk/file1 bs=4096 count=2 |> /dev/null
@$(RANDOMIZE)
@dd if=/dev/urandom of=/mnt/disk/file2 bs=4096 count=1 |> /dev/null
@$(RANDOMIZE)
@dd if=/dev/urandom of=/mnt/disk/file3 bs=4096 count=1 |> /dev/null
@$(RANDOMIZE)
@dd if=/dev/urandom of=/mnt/disk/file4 bs=4096 count=1 |> /dev/null
@$(RANDOMIZE)
@dd if=/dev/urandom of=/mnt/disk/file5 bs=4096 count=1 |> /dev/null
@$(RANDOMIZE)
@rm /mnt/disk/file1 /mnt/disk/file3
@$(RANDOMIZE)
@dd if=/dev/urandom of=/mnt/disk/file6 bs=4096 count=4 |> /dev/null
@cp /mnt/disk/file6 file6
################################################################################
# file6 file2 file6 file4 file5 file6
# ---- ---- | ---- | ---- | ---- | ---- | ----
################################################################################
@echo "--- test common case"
@echo "expecting 3:"
@./prog_test defrag /mnt/disk/file6
@echo "expecting 1:"
@./prog_test nfrags /mnt/disk/file6
@echo "no message regarding binary file difference should be displayed"
@diff /mnt/disk/file6 file6
@rm file6
################################################################################
# empty file2 empty file4 file5 empty file6
# ---- ---- | ---- | ---- | ---- | ---- | ---- | ---- ---- ---- ----
################################################################################
@$(RANDOMIZE)
@dd if=/dev/urandom of=/mnt/disk/file7 bs=4096 count=3 |> /dev/null
@cp /mnt/disk/file7 file7
@rm /mnt/disk/file4 /mnt/disk/file5
################################################################################
# file7 file2 file7 empty file6
# ---- ---- | ---- | ---- | ---- ---- ---- | ---- ---- ---- ----
################################################################################
@echo "--- test reusing space freed by a defragmentation"
@./prog_test defrag /mnt/disk/file7
@echo "expecting 1:"
@./prog_test nfrags /mnt/disk/file7
@echo "no message regarding binary file difference should be displayed"
@diff /mnt/disk/file7 file7
@rm file7
################################################################################
# empty file2 empty file7 file6
# ---- ---- | ---- | ---- | ---- ---- ---- | ---- ---- ---- ----
################################################################################
@echo "--- test defragmenting a non-existing file"
@echo "expecting -1:"
@./prog_test defrag /mnt/disk/file-not-exists
################################################################################
@echo "--- test defragmenting an empty file"
@touch /mnt/disk/file9
@echo "expecting 0:"
@./prog_test defrag /mnt/disk/file9
@rm /mnt/disk/file9
################################################################################
@echo "--- test defragmenting a directory"
@mkdir /mnt/disk/dir1
@echo "expecting -1:"
@./prog_test defrag /mnt/disk/dir1
@rm -rf /mnt/disk/dir1
################################################################################
# The bit 0 is inaccessible, the bit 1 is taken by the root directory. The first
# block of our schema is then at index 2 and the last at index 12.
@echo "--- test defragmentation with copy on a bitmap chunk boundary"
@$(RANDOMIZE)
@dd if=/dev/urandom of=/mnt/disk/file10 bs=4096 count=4 |> /dev/null
@cp /mnt/disk/file10 file10
################################################################################
# file10 file2 file10 file7 file6 file10
# ---- ---- | ---- | ---- | ---- ---- ---- | ---- ---- ---- ---- | ----
################################################################################
# The file will be put on a chunk boundary (chunk = 16 bits)
# from bit 14 to bit 17.
@echo "expecting 3:"
@./prog_test defrag /mnt/disk/file10
@echo "no message regarding binary file difference should be displayed"
@diff /mnt/disk/file10 file10
@rm file10
################################################################################
# empty file2 empty file7 file6 empty file10
# ---- ---- | ---- | ---- | ---- ---- ---- | ---- ---- ---- ---- | ---- | ...
################################################################################
# This is to verifiy the file went where we expected it to.
@$(RANDOMIZE)
@dd if=/dev/urandom of=/mnt/disk/file11 bs=4096 count=5 |> /dev/null
@echo "expecting 4:"
@./prog_test nfrags /mnt/disk/file11
################################################################################
@echo "there should be no error, 1 directory and 5 files :"
@/sbin/fsck.mfs /dev/c0d1
@rm /mnt/disk/*
@umount /mnt/disk
@rm mntflag
prog_test : test.c
$(CC) -o $@ $?
# fsflag is a file whose presence indicate that the fs has been created on
# /dev/c0d1. It is touched when a new filesystem is made.
fsflag:
/sbin/mkfs.mfs /dev/c0d1 && touch fsflag
@sleep 2
# mntflag is a file whose presence indicate that the fs on /dev/c0d1 has been
# mounted on /mnt/disk.
mntflag: fsflag
@mkdir -p /mnt/disk
@mount /dev/c0d1 /mnt/disk && touch mntflag
@sleep 2
# Remove the flags (use after or before reboot in case of filesystem
# corruption).
clean:
@rm -f /mnt/disk/*
@rm -f mntflag fsflag
.PHONY: all clean