9 echo "Usage: $1 <shared dir>"
10 echo '(The shared directory is the "share" directory in the scratch' \
15 if [ -z "$shared_dir" ]; then
16 print_usage
"$0" 'Shared dir not given' >&2
22 # FIXME: This should not be necessary, but it is. In order for all
23 # submounts to be proper mount points, we need to visit them.
24 # (Before we visit them, they will not be auto-mounted, and so just
25 # appear as normal directories, with the catch that their st_ino will
26 # be the st_ino of the filesystem they host, while the st_dev will
27 # still be the st_dev of the parent.)
28 # `find` does not work, because it will refuse to touch the mount
29 # points as long as they are not mounted; their st_dev being shared
30 # with the parent and st_ino just being the root node's inode ID
31 # will practically ensure that this node exists elsewhere on the
32 # filesystem, and `find` is required to recognize loops and not to
34 # Thus, we have to manually visit all nodes first.
38 function recursively_visit
()
42 if [[ "$entry" == mnt
* ]]; then
44 printf "Triggering auto-mount $mnt_i...\r"
47 if [ -d "$entry" ]; then
48 recursively_visit
"$entry"
58 if [ -n "$(find -name not-mounted)" ]; then
59 echo "Error: not-mounted files visible on mount points:" >&2
60 find -name not-mounted
>&2
64 if [ ! -f some-file
-o "$(cat some-file)" != 'root' ]; then
65 echo "Error: Bad file in the share root" >&2
71 function check_submounts
()
76 printf "Checking submount %i...\r" "$((${#devs[@]} + 1))"
78 mp_i
=$
(echo "$mp" |
sed -e 's/mnt//')
79 dev
=$
(stat
-c '%D' "$mp")
81 if [ -n "${devs[mp_i]}" ]; then
82 echo "Error: $mp encountered twice" >&2
87 pushd "$mp" >/dev
/null
90 expected_content
="$(printf '%s\n%s\n' "$mp_i" "$path")"
91 if [ ! -f some-file
]; then
92 echo "Error: $PWD/some-file does not exist" >&2
96 if [ "$(cat some-file)" != "$expected_content" ]; then
97 echo "Error: Bad content in $PWD/some-file:" >&2
100 echo '--- expected ---'
101 echo "$expected_content"
104 if [ "$(stat -c '%D' some-file)" != "$dev" ]; then
105 echo "Error: $PWD/some-file has the wrong device ID" >&2
110 if [ "$(stat -c '%D' sub)" != "$dev" ]; then
111 echo "Error: $PWD/some-file has the wrong device ID" >&2
117 if [ -n "$(echo mnt*)" ]; then
118 check_submounts
"$path/"
127 root_dev
=$
(stat
-c '%D' some-file
)
132 reused_devs
=$
(echo "$root_dev ${devs[@]}" |
tr ' ' '\n' |
sort |
uniq -d)
133 if [ -n "$reused_devs" ]; then
134 echo "Error: Reused device IDs: $reused_devs" >&2
138 echo "Test passed for ${#devs[@]} submounts."