showfiles.sh
John Ogness <[email protected]> Fri, 07 Nov 2008 22:55:58 +0100
| Newsgroups | gmane.linux.dazuko.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi, Just for fun I created a shell script that prints out all the files being accessed in DazukoFS. It is essentially the same as the "showfiles.c" example program, but is implemented in shell script. The script makes use of a few external tools (sh, ls, grep, sed, echo) so it is critical that these tools are _not_ stacked with DazukoFS. (They are most likely located in /bin.) The script is quite inefficient. But the fact that you can write a shell script with some very basic UNIX tools to interact with DazukoFS shows how simple the new userspace<->kernel protocol really is. Of course, using libdazukofs.so is far more efficient and much simpler. I just wanted to create the script to show that it can be done. ;) John Ogness -- Dazuko Maintainer _______________________________________________ Dazuko-devel mailing list [email protected] http://lists.nongnu.org/mailman/listinfo/dazuko-devel
showfiles.sh
(application/x-sh, 649 B)
#!/bin/sh
GROUPNAME="shell_showfiles"
goodbye1()
{
exit 1
}
goodbye2()
{
echo ""
echo "del=$GROUPNAME" >> /dev/dazukofs.ctrl
echo "Goodbye."
exit 0
}
if [ $# -ge 1 ]; then
trap goodbye1 1 2 15
GROUPID=$1
read RESPONSE < /dev/dazukofs.$GROUPID
if [ $? -ne 0 ]; then
exit 1
fi
eval $RESPONSE
FILENAME=`ls -l /proc/$$/fd/3 | sed -e 's/.*-> //'`
echo "file:$FILENAME"
echo "id=$id r=0" >> /dev/dazukofs.$GROUPID
exit 0
fi
trap goodbye2 1 2 15
echo "add=$GROUPNAME" >> /dev/dazukofs.ctrl
GROUPID=`grep $GROUPNAME /dev/dazukofs.ctrl | sed -e 's/:.*//'`
while true; do
sh $0 $GROUPID
if [ $? -ne 0 ]; then
goodbye2
fi
done