#!/bin/sh
-# XXX: fill in
+#
+# This script creates an idmapped mount of an ext4 file system and tries to
+# stack wrapfs on top of it. It creates a third user called luser if they do
+# not exist and sets the following idmap:
+# root -> ubuntu
+# ubuntu -> luser
+# luser -> root
+# Files are created belonging to each user on the original mount of the ext4
+# filesystem. They should show up as different users on the id mapped mount and
+# also on the wrapfs mount if wrapfs correctly supports idmapped mounts on the
+# lower fs.
SCRATCH_DEV=/dev/sdb
SCRATCH_DIR=/n/scratch
LOWER_DIR=/n/lower
TMP_DIR=/n/tmp
+TMP_DIR=/n/tmp
FS_TYPE=ext4
function runcmd
fi
}
+if ! id luser &>/dev/null; then
+ runcmd adduser --disabled-password -q --gecos luser luser
+fi
+
dirs="$TMP_DIR $LOWER_DIR $SCRATCH_DIR"
for d in $dirs; do
echo checking dir $d
runcmd chown luser $SCRATCH_DIR/luser
ls1=$(ls -l $SCRATCH_DIR)
-runcmd ./mount-idmapped --map-mount b:0:1000:1 --map-mount b:1000:1001:1 --map-mount b:1001:0:1 $SCRATCH_DIR $LOWER_DIR
+ubuntu=$(id -u ubuntu)
+luser=$(id -u luser)
+
+runcmd ./mount-idmapped --map-mount b:0:$ubuntu:1 --map-mount b:$ubuntu:$luser:1 --map-mount b:$luser:0:1 $SCRATCH_DIR $LOWER_DIR
runcmd mount -t wrapfs $LOWER_DIR $TMP_DIR
if test $ret != 32; then
echo wrapfs returned unexpected error: $ret