Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow non-directories to be exported (issue 113)

Add test user/t16 which mounts a regular file and reads from it.
  • Loading branch information...
commit 024aa7a0432427e5384b2a981b03ee694c05de76 1 parent 7174154
@garlick garlick authored
View
7 diod/ops.c
@@ -278,10 +278,9 @@ diod_attach (Npfid *fid, Npfid *afid, Npstr *aname)
np_uerror (errno);
goto error;
}
- if (!S_ISDIR (sb.st_mode)) {
- np_uerror (ENOTDIR);
- goto error;
- }
+ /* N.B. removed S_ISDIR (sb.st_mode) || return ENOTDIR check.
+ * Allow a regular file or a blcok device to be exported.
+ */
diod_ustat2qid (&sb, &qid);
if ((ret = np_create_rattach (&qid)) == NULL) {
np_uerror (ENOMEM);
View
2  tests/user/Makefile.am
@@ -13,7 +13,7 @@ TESTS_ENVIRONMENT += "PATH_DIOD=$(top_builddir)/diod/diod"
TESTS_ENVIRONMENT += "PATH_DIODCONF=$(top_builddir)/etc/diod.conf"
TESTS_ENVIRONMENT += "./runtest"
-TESTS = t01 t02 t03 t04 t05 t06 t07 t08 t09 t10 t11 t12 t13 t15
+TESTS = t01 t02 t03 t04 t05 t06 t07 t08 t09 t10 t11 t12 t13 t15 t16
$(TESTS): exp.d
View
1  tests/user/README
@@ -21,6 +21,7 @@ t11(*) Attach to server with N threads, M users (N > M)
t12(+) Attach to user A's private server with user B
t13(*) Attach to server with N threads, M users (N < M)
t15 Check that flush works the way it ought to.
+t16 Attach directly to a file and perform I/O
(*) requires root (else NOTRUN)
View
11 tests/user/runtest
@@ -1,5 +1,7 @@
#!/bin/bash
+umask 022
+
PATH=/sbin:/usr/sbin:/bin:/usr/bin:$PATH
if [ $# -ne 1 ]; then
echo "Usage runtest test" 2>&1
@@ -13,6 +15,7 @@ if [ -z "$PATH_DIOD" ]; then
exit 1
fi
+
# some tests require root, some require non-root
case $(basename $TEST) in
t12)
@@ -31,13 +34,17 @@ case $(basename $TEST) in
exit 77
fi
;;
+ t16) # PATH_EXPDIR is a regular file for this test
+ umask 022
+ PATH_EXPDIR=$(mktemp) || exit 1
+ dd if=/dev/zero count=1 bs=1024k of=$PATH_EXPDIR oflag=append >/dev/null 2>&1
+ ;;
esac
rm -f $TEST.diod $TEST.out
ulimit -c unlimited
-umask 022
-PATH_EXPDIR=$(mktemp -d) || exit 1
+test -n "$PATH_EXPDIR" || PATH_EXPDIR=$(mktemp -d) || exit 1
chmod 777 $PATH_EXPDIR
export PATH_EXPDIR
View
4 tests/user/t03
@@ -4,9 +4,9 @@ echo creating testfile
cp $PATH_DIOD $PATH_EXPDIR/testfile
tmpfile=`mktemp`
echo reading testfile
-./tread "$@" testfile $tmpfile
+./tread "$@" $tmpfile testfile
echo comparing result
-if ! cmp $PATH_EXPDIR/testfile $tmpfile; then
+if ! cmp $tmpfile $PATH_EXPDIR/testfile; then
echo results differ
exit 1
fi
View
2  tests/user/t04
@@ -2,6 +2,6 @@
tmpfile=`mktemp`
echo reading testfile
-./tread "$@" bogusfile $tmpfile || : # should fail
+./tread "$@" $tmpfile bogusfile || : # should fail
rm -f $tmpfile
exit 0
View
15 tests/user/t16
@@ -0,0 +1,15 @@
+#!/bin/bash -e
+
+# In this test PATH_EXPDIR is a regular file
+test -f $PATH_EXPDIR
+
+tmpfile=`mktemp`
+echo reading mounted file
+./tread "$@" $tmpfile
+echo comparing result
+if ! cmp $tmpfile $PATH_EXPDIR; then
+ echo results differ
+ exit 1
+fi
+rm -f $tmpfile
+exit 0
View
4 tests/user/t16.exp
@@ -0,0 +1,4 @@
+reading mounted file
+comparing result
+conjoin: t16 exited with rc=0
+conjoin: diod exited with rc=0
View
32 tests/user/tread.c
@@ -26,7 +26,8 @@
static void
usage (void)
{
- fprintf (stderr, "Usage: tread aname infile outfile\n");
+ fprintf (stderr, "Usage: tread aname outfile [infile]\n");
+ fprintf (stderr, " If no infile, try to read directly from aname\n");
exit (1);
}
@@ -55,28 +56,35 @@ int
main (int argc, char *argv[])
{
Npcfid *root, *fid;
- char *aname, *infile, *outfile;
+ char *aname, *outfile, *infile = NULL;
int fd;
diod_log_init (argv[0]);
- if (argc != 4)
+ if (argc != 4 && argc != 3)
usage ();
aname = argv[1];
- infile = argv[2];
- outfile = argv[3];
+ outfile = argv[2]; /* UNIX */
+ if (argc == 4)
+ infile = argv[3]; /* userland 9p */
if ((fd = open (outfile, O_WRONLY | O_CREAT, 0644)) < 0)
err_exit ("open");
-
if (!(root = npc_mount (0, 0, 65536+24, aname, diod_auth)))
errn_exit (np_rerror (), "npc_mount");
- if ((fid = npc_open_bypath (root, infile, O_RDONLY))) {
- _copy_from9 (fid, fd);
- if (npc_clunk (fid) < 0)
- errn (np_rerror (), "npc_clunk");
- } else
- errn (np_rerror (), "npc_open_bypath");
+ if (infile) {
+ if ((fid = npc_open_bypath (root, infile, O_RDONLY))) {
+ _copy_from9 (fid, fd);
+ if (npc_clunk (fid) < 0)
+ errn (np_rerror (), "npc_clunk");
+ } else
+ errn (np_rerror (), "npc_open_bypath");
+ } else {
+ if ((npc_open (root, O_RDONLY)) == 0) {
+ _copy_from9 (root, fd);
+ } else
+ errn (np_rerror (), "npc_open");
+ }
npc_umount (root);
if (close (fd) < 0)
Please sign in to comment.
Something went wrong with that request. Please try again.