Page MenuHomeFreeBSD
Authored By
jlduran
Thu, Jan 8, 4:52 AM
Size
3 KB
Referenced Files
None
Subscribers
None

makefs_times.sh

#!/bin/sh
#set -x
tmpdir=$(mktemp -d)
trap 'rm -rf $tmpdir' EXIT INT TERM
doctor_metalog_time()
{
case "$(uname -s)" in
FreeBSD)
sed -i "" "s/time=.*$/time=1234567899.1234567/g" "${tmpdir}/metalog"
;;
NetBSD|OpenBSD)
sed -i"" "s/time=.*$/time=1234567899.1234567/g" "${tmpdir}/metalog"
;;
esac
}
makefs_cmd()
{
case "$1" in
ffs)
shift
makefs -s 1m -t ffs -o version=2 "$@"
;;
msdos)
makefs -s 1m -t "$@"
;;
*)
makefs -t "$@"
;;
esac
}
mount_t()
{
case "$1" in
cd9660|msdos)
mount -t "$@"
;;
*)
shift
mount "$@"
;;
esac
}
mount_image()
{
case "$(uname -s)" in
FreeBSD)
dev=$(mdconfig -a -f "${tmpdir}/${1}.img")
mount_t "$1" "/dev/${dev}" "${tmpdir}/mnt"
echo "$dev"
;;
NetBSD)
vnconfig vnd0 "${tmpdir}/${1}.img"
mount_t "$1" /dev/vnd0a "${tmpdir}/mnt"
;;
OpenBSD)
vnconfig vnd0 "${tmpdir}/${1}.img"
mount_t "$1" /dev/vnd0c "${tmpdir}/mnt"
esac
}
umount_image()
{
case "$(uname -s)" in
FreeBSD)
umount -f "/dev/${1}"
mdconfig -d -u "$1"
;;
NetBSD|OpenBSD)
umount "${tmpdir}/mnt"
vnconfig -u vnd0
;;
esac
}
awk_attributes='{ print $9,$10,$11,$12 }'
if [ "$(uname -s)" = "OpenBSD" ]; then
awk_attributes='{ print $9,$10,$11 }'
fi
# Create structure
mkdir ${tmpdir}/mnt
mkdir ${tmpdir}/foo
touch ${tmpdir}/foo/bar
echo "none:"
for type in cd9660 ffs msdos; do
# Create images
makefs_cmd ${type} ${tmpdir}/${type}.img ${tmpdir}/foo >/dev/null
# Mount image
dev=$(mount_image $type)
# Check times
printf "%7s " "$type"
stat -s ${tmpdir}/mnt/bar | awk "$awk_attributes"
# Unmount image
umount_image "$dev"
done
echo
echo "-F metalog time=1234567899.1234567:"
if [ "$(uname -s)" != "OpenBSD" ]; then
for type in cd9660 ffs msdos; do
# Create images
mtree -c -k time -p ${tmpdir}/foo | mtree -C > ${tmpdir}/metalog
doctor_metalog_time
makefs_cmd ${type} -F ${tmpdir}/metalog ${tmpdir}/${type}.img ${tmpdir}/foo >/dev/null
# Mount image
dev=$(mount_image $type)
# Check times
printf "%7s " "$type"
stat -s ${tmpdir}/mnt/bar | awk "$awk_attributes"
# Unmount image
umount_image "$dev"
done
else
echo "N/A"
fi
echo
time_flag="-T 1234567899"
echo "${time_flag}:"
for type in cd9660 ffs msdos; do
# Create images
makefs_cmd ${type} ${time_flag} ${tmpdir}/${type}.img ${tmpdir}/foo >/dev/null
# Mount image
dev=$(mount_image $type)
# Check times
printf "%7s " "$type"
stat -s ${tmpdir}/mnt/bar | awk "$awk_attributes"
# Unmount image
umount_image "$dev"
done
echo
echo "metalog time=1234567899.1234567:"
if [ "$(uname -s)" = "FreeBSD" ]; then
for type in cd9660 ffs msdos; do
# Create images
mtree -c -k time -p ${tmpdir}/foo | mtree -C > ${tmpdir}/metalog
doctor_metalog_time
cd "$tmpdir/foo"
makefs_cmd ${type} ${tmpdir}/${type}.img ${tmpdir}/metalog >/dev/null
cd -
# Mount image
dev=$(mount_image $type)
# Check times
printf "%7s " "$type"
stat -s ${tmpdir}/mnt/bar | awk "$awk_attributes"
# Unmount image
umount_image "$dev"
done
else
echo "N/A"
fi
echo
echo "-F metalog time=1234567899.1234567 -T 2222222222:"
if [ "$(uname -s)" != "OpenBSD" ]; then
for type in cd9660 ffs msdos; do
# Create images
mtree -c -k time -p ${tmpdir}/foo | mtree -C > ${tmpdir}/metalog
doctor_metalog_time
makefs_cmd ${type} -F ${tmpdir}/metalog -T 2222222222 ${tmpdir}/${type}.img ${tmpdir}/foo >/dev/null
# Mount image
dev=$(mount_image $type)
# Check times
printf "%7s " "$type"
stat -s ${tmpdir}/mnt/bar | awk "$awk_attributes"
# Unmount image
umount_image "$dev"
done
else
echo "N/A"
fi

File Metadata

Mime Type
text/x-shellscript
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
27575580
Default Alt Text
makefs_times.sh (3 KB)

Event Timeline