[Libsysio-commit] HEAD: libsysio/tests startup.c Makefile.am sysio_stubs.c sysio_tests.c test.h test
Brought to you by:
lward
|
From: Lee W. <lw...@us...> - 2004-02-14 19:49:44
|
Update of /cvsroot/libsysio/libsysio/tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16325/tests Modified Files: Makefile.am sysio_stubs.c sysio_tests.c test.h test_all.pl test_copy.c test_copy.pl test_driver.c test_driver.h test_getcwd.c test_link.c test_list.c test_path.c test_regions.c test_rename.c test_stats.c test_unlink.c Added Files: startup.c Removed Files: test_mounts.c test_stdfd.c Log Message: + Merged in changes from namespace_assembly branch (see .../misc/init-env.sh) This provoked a bunch of bugs. See below. + Fixed a bug in _sysio_enumerate_extents(). If the IO operation was short, it would go round the loop again, mistakenly trying to fill more of the extent. + In rw.c, fixed bugs in [p]{read,write}[vx] (all the synchronous routines) that improperly propagated error returns. They were returning -errno instead of setting errno and returning -1. + In fs_native.c:doiov, fixed a bug where a zero-length IO was improperly thought to be an error. + In lseek.c:_sysio_lseek, fixed final position check to properly determine {under,over}flow. + In link.c:link, fixed the existence check. No error is returned for nonexistent files when ND_NEGOK is specified. We're supposed to check whether it's a negative entry or not. + A new macro, I_GONE, was added to inode.h. This will *try* to kill an inode but if it can't, it becomes a zombie instead. + In unlink.c:unlink, link.c:link, rename.c:rename, the driver ops were being called but the actual operation in the internal path tree was not reflected. Also, for unlink and rename, use the new I_GONE macro on the destroyed inode. + In fs_native.c:native_inop_gone, close() was always called, even when the fildes was -1. + In fs_native.c:native_inop_gone, close() was called. We really meant to call syscal(SYS_close, ...); + In namei.c:_sysio_path_walk, fixed broken symlink handling. It wasn't following symlinks anywhere if ND_NOFOLLOW was set. That flag only means that the *last* component should not be followed. + In namei.c:_sysio_path_walk, fixed buffer overrun problem for very long symlinks. + In fs_incore.c, fixed dirop_{link,rename,unlink,rmdir} because they were manipulating the system path cache and shouldn't. + In mount.c:_sysio_unmount_all we were mistakenly releasing an FS root after a failed unmount attempt. + Fixes in test_regions.c free allocated memory at the end so valgrind doesn't show a leak. Index: Makefile.am =================================================================== RCS file: /cvsroot/libsysio/libsysio/tests/Makefile.am,v retrieving revision 1.18 retrieving revision 1.19 diff -u -w -b -B -p -r1.18 -r1.19 --- Makefile.am 6 Feb 2004 20:07:30 -0000 1.18 +++ Makefile.am 14 Feb 2004 19:42:59 -0000 1.19 @@ -1,12 +1,5 @@ - -if WITH_STDFD_DEV -STDFD_DEV_TEST = test_stdfd -else -STDFD_DEV_TEST = -endif - -noinst_PROGRAMS = test_copy test_stats test_path test_mounts test_list \ - test_getcwd $(STDFD_DEV_TEST) test_link test_unlink test_rename \ +noinst_PROGRAMS = test_copy test_stats test_path test_list \ + test_getcwd test_link test_unlink test_rename \ test_regions test_driver CLEANFILES=drv_data.c @@ -27,14 +20,6 @@ INCORE_DRIVER_NAME= INCORE_DRIVER_CFLAGS= endif -if WITH_STDFD_DEV -STDFD_DEV_NAME=stdfd -STDFD_DEV_CFLAGS= -I$(top_srcdir)/dev/stdfd -else -STDFD_DEV_NAME= -STDFD_DEV_CFLAGS= -endif - if WITH_CPLANT_YOD YOD_DRIVER_NAME=yod YOD_DRIVER_CFLAGS= -DCPLANT_YOD @@ -54,7 +39,7 @@ endif DRIVERS=$(NATIVE_DRIVER_NAME) $(INCORE_DRIVER_NAME) $(YOD_DRIVER_NAME) \ $(STFD_DEV_NAME) $(SOCKETS_DRIVER_NAME) -CMNSRC=drv_init_all.c drv_data.c +CMNSRC=startup.c drv_init_all.c drv_data.c BUILT_SOURCES=drv_data.c check_PROGRAMS=test_driver @@ -86,11 +71,6 @@ test_path_CFLAGS=$(CFL) test_path_LDADD=$(LIBS) test_path_DEPENDENCIES=$(LIBS) -test_mounts_SOURCES=test_mounts.c $(CMNSRC) -test_mounts_CFLAGS=$(CFL) -test_mounts_LDADD=$(LIBS) -test_mounts_DEPENDENCIES=$(LIBS) - test_list_SOURCES=test_list.c $(CMNSRC) test_list_CFLAGS=$(CFL) test_list_LDADD=$(LIBS) @@ -101,11 +81,6 @@ test_getcwd_CFLAGS=$(CFL) test_getcwd_LDADD=$(LIBS) test_getcwd_DEPENDENCIES=$(LIBS) -test_stdfd_SOURCES=test_stdfd.c $(CMNSRC) -test_stdfd_CFLAGS=$(CFL) -test_stdfd_LDADD=$(LIBS) -test_stdfd_DEPENDENCIES=$(LIBS) - test_link_SOURCES=test_link.c $(CMNSRC) test_link_CFLAGS=$(CFL) test_link_LDADD=$(LIBS) Index: sysio_stubs.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/tests/sysio_stubs.c,v retrieving revision 1.8 retrieving revision 1.9 diff -u -w -b -B -p -r1.8 -r1.9 --- sysio_stubs.c 6 Feb 2004 20:07:31 -0000 1.8 +++ sysio_stubs.c 14 Feb 2004 19:42:59 -0000 1.9 @@ -394,9 +394,8 @@ int test_do_init(int argc, char **argv) DBG(5, fprintf(outfp, "In test_do_init\n")); last_type = SINT; - DBG(3, fprintf(outfp, "Using driver %s, path %s, flags %x\n", - root_driver, mntpath, mntflgs)); - return initilize_sysio(root_driver, mntpath, mntflgs); + DBG(3, fprintf(outfp, "initializing\n")); + return initilize_sysio(); } Index: sysio_tests.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/tests/sysio_tests.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -w -b -B -p -r1.4 -r1.5 --- sysio_tests.c 21 Jan 2004 15:38:45 -0000 1.4 +++ sysio_tests.c 14 Feb 2004 19:43:00 -0000 1.5 @@ -29,37 +29,23 @@ * # every function document in sysio.h # * ################################################### */ -int initilize_sysio(char *root_driver, char *root_path, int mntflgs) +int initilize_sysio() { int err; char *wd; + extern int _test_sysio_startup(void); /* * Init sysio lib. */ - _sysio_init(); - - /* - * Init native file system driver and request mount of specified - * source directory. - */ - err = drv_init_all(); - DBG(5, sprintf(output, "%sdrv_init_all: err %d\n", output, err)); + err = _test_sysio_startup(); + DBG(5, sprintf(output, "%s_test_sysio_startup: err %d\n", output, err)); if (err) { my_errno = err; - my_perror("drv_init_all"); + my_perror("sysio startup"); last_ret_val = errno; return SUCCESS; } - err = _sysio_mount_root(root_path, root_driver, mntflgs, NULL); - DBG(5, sprintf(output, "%ssysio_mount_root: err %d\n", output, err)); - if (err) { - my_errno = errno; - my_perror("_sysio_mount_root"); - perror("_sysio_mount_root"); - last_ret_val = err; - return SUCCESS; - } /* * Attempt to set the cwd by getting it out of the Index: test.h =================================================================== RCS file: /cvsroot/libsysio/libsysio/tests/test.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -w -b -B -p -r1.1 -r1.2 --- test.h 22 Feb 2003 20:30:20 -0000 1.1 +++ test.h 14 Feb 2004 19:43:00 -0000 1.2 @@ -41,8 +41,6 @@ * le...@sa... */ -#define DEFAULT_DRIVER "native" - extern int (*drvinits[])(void); extern int drv_init_all(void); Index: test_all.pl =================================================================== RCS file: /cvsroot/libsysio/libsysio/tests/test_all.pl,v retrieving revision 1.8 retrieving revision 1.9 diff -u -w -b -B -p -r1.8 -r1.9 --- test_all.pl 6 Feb 2004 20:07:31 -0000 1.8 +++ test_all.pl 14 Feb 2004 19:43:00 -0000 1.9 @@ -35,6 +35,38 @@ my $cwd = $ENV{PWD}; # Get tests directory my $testdir = $FindBin::Bin; +my $namespace_env = "SYSIO_NAMESPACE"; +my $home = $ENV{"HOME"}; +my $auto_mount = $ENV{"SYSIO_AUTOMOUNT"}; +my $root_flags = "0"; +my $extras = ""; +if ((defined($auto_mount)) && ($auto_mount == "xyes")) { + $root_flags = "2"; + + # + # Add a /auto directory for automounted file systems. We + # craft one automount that mounts /usr/home from the native + # file system. Further automounts in the sub-mounts are not enabled. + # + $extras=" \ + {mnt, dev=\"incore:0755+0+0\",dir=\"/mnt\",fl=2} \ + {creat, ft=dir,nm=\"/mnt/home\",pm=0755,ow=0,gr=0} \ + {creat, ft=file,nm=\"/mnt/home/.mount\",pm=0600, \ + str=\"native:/usr/home\"}"; +} +$ENV{$namespace_env} = "\ + {mnt, dev=\"native:/\",dir=/,fl=$root_flags} \ + {mnt, dev=\"incore:0755+0+0\",dir=\"/dev\"} \ + {creat, ft=chr,nm=\"/dev/stdin\",pm=0400,mm=0+0} \ + {creat, ft=chr,nm=\"/dev/stdout\",pm=0200,mm=0+1} \ + {creat, ft=chr,nm=\"/dev/stderr\",pm=0200,mm=0+2} \ + {creat, ft=dir,nm=\"/dev/fd\",pm=0755,ow=0,gr=0} \ + {creat, ft=chr,nm=\"/dev/fd/0\",pm=0400,mm=0+0} \ + {creat, ft=chr,nm=\"/dev/fd/1\",pm=0200,mm=0+1} \ + {creat, ft=chr,nm=\"/dev/fd/2\",pm=0200,mm=0+2} \ + {cd, dir=\"$home\"} \ + $extras "; + my $res; if ($use_system == 1) { @@ -93,19 +125,6 @@ if ($resarr[0] ne $res) { } } -if (($alpha_arg eq "") || ($is_broke == 0)) { - # Test mount - $res = `perl $testdir/test_list.pl $alpha_arg -m native:$testdir $cwd/tmp_dir/test2`; - chop($res); - if ($res ne "list test successful") { - print "Mount test failed with message: $res\n"; - $failures++; - } else { - $success++; - print "test_mount finished successfully\n"; - } - -} # Test getcwd $res = `perl $testdir/test_getcwd.pl $alpha_arg $cwd/tmp_dir/test1`; chop($res); @@ -140,9 +159,9 @@ if ($res ne "stat test successful") { } # Test stdfd -$res = `perl $testdir/test_stdfd.pl $alpha_arg foo_dir`; +$res = `echo "foobar" | perl $testdir/test_copy.pl $alpha_arg -o /dev/stdin /dev/stdout`; chop($res); -if ($res ne "test_stdfd successful") { +if ($res ne "copy test successful") { print "stdfd test failed with message: $res\n"; $failures++; } else { @@ -185,5 +204,4 @@ if ($use_system == 1) { exit 1; } } - exit $failures; Index: test_copy.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/tests/test_copy.c,v retrieving revision 1.8 retrieving revision 1.9 diff -u -w -b -B -p -r1.8 -r1.9 --- test_copy.c 10 Oct 2003 18:50:31 -0000 1.8 +++ test_copy.c 14 Feb 2004 19:43:00 -0000 1.9 @@ -65,14 +65,12 @@ /* * Copy one file to another. * - * Usage: test_copy [-a] [-r <source>] [-m <root-driver>] <src> <dest> + * Usage: test_copy [-o] <src> <dest> * * Destination will not be overwritten if it already exist. */ -char *root_driver = DEFAULT_DRIVER; -char *mntpath = "/"; -unsigned mntflgs = 0; +static int overwrite = 0; /* over-write? */ void usage(void); int copy_file(const char *spath, const char *dpath); @@ -83,28 +81,19 @@ main(int argc, char * const argv[]) int i; int err; const char *spath, *dpath; + extern int _test_sysio_startup(void); /* * Parse command-line args. */ while ((i = getopt(argc, argv, -#ifdef AUTOMOUNT_FILE_NAME - "a" -#endif - "r:m:")) != -1) + "o" + )) != -1) switch (i) { -#ifdef AUTOMOUNT_FILE_NAME - case 'a': - mntflgs |= MOUNT_F_AUTO; - break; -#endif - case 'r': /* set working dir */ - mntpath = optarg; - break; - case 'm': - root_driver = optarg; + case 'o': + overwrite = 1; break; default: usage(); @@ -112,24 +101,12 @@ main(int argc, char * const argv[]) if (!(argc - optind)) usage(); -#ifndef CPLANT_YOD - if (_sysio_init() != 0) { - perror("init sysio"); - exit(1); - } - err = drv_init_all(); - if (err) { - perror("init drivers"); - exit(1); - } - err = _sysio_mount_root(mntpath, root_driver, mntflgs, NULL); + err = _test_sysio_startup(); if (err) { errno = -err; - perror(root_driver); + perror("sysio startup"); exit(1); } -#endif - (void )umask(022); /* * Source @@ -146,9 +123,7 @@ main(int argc, char * const argv[]) err = copy_file(spath, dpath); -#ifndef CPLANT_YOD _sysio_shutdown(); -#endif return err; } @@ -159,10 +134,6 @@ usage() (void )fprintf(stderr, "Usage: test_copy " -#ifdef AUTOMOUNT_FILE_NAME - "[-a] " -#endif - "[-r <source>] [-m <fsname>]" " source destination\n"); exit(1); } @@ -183,6 +154,7 @@ int copy_file(const char *spath, const char *dpath) { int sfd, dfd; + int flags; int rtn; static char buf[1024]; ssize_t cc, wcc; @@ -193,7 +165,10 @@ copy_file(const char *spath, const char sfd = open_file(spath, O_RDONLY, 0); if (sfd < 0) goto out; - dfd = open_file(dpath, O_CREAT|O_EXCL|O_WRONLY, 0666); + flags = O_CREAT|O_WRONLY; + if (!overwrite) + flags |= O_EXCL; + dfd = open_file(dpath, flags, 0666); if (dfd < 0) goto out; Index: test_copy.pl =================================================================== RCS file: /cvsroot/libsysio/libsysio/tests/test_copy.pl,v retrieving revision 1.4 retrieving revision 1.5 diff -u -w -b -B -p -r1.4 -r1.5 --- test_copy.pl 21 Jan 2004 15:13:56 -0000 1.4 +++ test_copy.pl 14 Feb 2004 19:43:00 -0000 1.5 @@ -20,7 +20,7 @@ sub usage sub process_cmd { - my ($src, $dest, $is_alpha) = @_; + my ($src, $dest, $overwrite, $is_alpha) = @_; # Get tests directory my $testdir = $FindBin::Bin; @@ -53,6 +55,13 @@ sub process_cmd my $size = -s $src; my $bufsize; + # If reading from stdin, just read one line + my $line; + if ($src eq "/dev/stdin") { + $line = <STDIN>; + $size = length($line); + } + if ( $size > 1024) { # Arbitrary limit $bufsize = 1024; } else { @@ -63,10 +72,16 @@ sub process_cmd # Open src my $cmdstr = '$src = CALL open '."$src O_RDONLY\n"; helper::send_cmd($cmdfh, $outfh, "open", $cmdstr); + helper::verify_cmd($cmdfh, $outfh, "open $src"); # Open dest - $cmdstr = '$dest = CALL open '."$dest O_RDWR|O_CREAT 7777\n"; + my $flags = "O_WRONLY|O_CREAT"; + if ($overwrite == 0) { + $flags .= "|O_EXCL"; + } + $cmdstr = '$dest = CALL open '."$dest $flags 0666\n"; helper::send_cmd($cmdfh, $outfh, "open", $cmdstr); + my $destfile = helper::verify_cmd($cmdfh, $outfh, "open $dest"); # Allocate buffer $cmdstr = '$buf = ALLOC '."$bufsize\n"; @@ -75,15 +90,60 @@ sub process_cmd # Read size bytes from src and write them out to dest my $bytes = $size; while ($bytes > 0) { + + my $readb; + my $res; + if ($src eq "/dev/stdin") { + # Send "delay" option to read which will give us time to + # put something in stdin (since we can't send an eof) + my $cmdstr = "CALL read ".'$src $buf '."$bytes delay\n"; + print $cmdfh $cmdstr; + # Give time to process command + sleep 1; + + # Send line from stdin + print $cmdfh $line; + sleep 0.5; + + # Make sure read was OK + $res = <$outfh>; + chop($res); + if ($res ne "0000 ") { + helper::print_and_exit($cmdfh, $outfh, 1, "ERROR! Read failed with code $res\n"); + } + + # See how many bytes we got... + $readb = helper::verify_cmd($cmdfh, $outfh, "read"); + $readb = oct($readb); + if ($readb != $bytes) { + helper::print_and_exit($cmdfh, $outfh, 0, "Short read\n"); + } + + $cmdstr = "CALL write ".'$dest $buf '."$readb\n"; + print $cmdfh $cmdstr; + + # Suck up the stdout... + $res = <$outfh>; + chop($res); + + $res = <$outfh>; + chop($res); + $res = oct($res); + + if ($res != 0) { + helper::print_and_exit($cmdfh, $outfh, 1, "ERROR! Write failed with code $res\n"); + } + } else { $cmdstr = 'CALL read $src $buf '."$bufsize\n"; helper::send_cmd($cmdfh, $outfh, "read", $cmdstr); - my $res = helper::verify_cmd($cmdfh, $outfh, "read"); - my $readb = oct($res); + $res = helper::verify_cmd($cmdfh, $outfh, "read"); + $readb = oct($res); # Now write $readb back out to dest $cmdstr = 'CALL write $dest $buf '."$readb\n"; helper::send_cmd($cmdfh, $outfh, "write", $cmdstr); + } $res = helper::verify_cmd($cmdfh, $outfh, "write"); @@ -101,31 +161,41 @@ sub process_cmd $cmdstr = 'CALL close $dest'."\n"; helper::send_cmd($cmdfh, $outfh, "close", $cmdstr); + if ($src ne "/dev/stdin") { my $cmpres = system("cmp -s $src $dest"); if ($cmpres != 0) { print STDOUT "ERROR! File $src differs from $dest\n"; exit 1; } - + } helper::print_and_exit($cmdfh, $outfh, 0, "copy test successful\n"); } my $currarg = 0; my $is_alpha = 0; +my $overwrite = 0; + +my $len = @ARGV-2; if (@ARGV < 2) { usage; -} elsif (@ARGV > 2 ) { - if ($ARGV[$currarg++] eq "-alpha") { +} + +my $i; +for ($i=0; $i < $len; $i++ ) { + if ($ARGV[$i] eq "-alpha") { $is_alpha = 1; } + if ($ARGV[$i] eq "-o") { + $overwrite = 1; + } } -my $src = $ARGV[$currarg++]; -my $dest = $ARGV[$currarg]; +my $src = $ARGV[$i++]; +my $dest = $ARGV[$i]; -process_cmd($src, $dest, $is_alpha); +process_cmd($src, $dest, $overwrite, $is_alpha); exit 0; Index: test_driver.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/tests/test_driver.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -w -b -B -p -r1.6 -r1.7 --- test_driver.c 6 Feb 2004 20:07:31 -0000 1.6 +++ test_driver.c 14 Feb 2004 19:43:00 -0000 1.7 @@ -227,10 +227,47 @@ char *get_str(char *var_name) return var_name; } +static char* +get_or_part(char **str, int* did_alloc) +{ + char *tmp_str = *str; + int i, norm_str=0; + + if (tmp_str == NULL) + return NULL; + + if (tmp_str[0] == '|') { + tmp_str++; + norm_str=1; + } + + for (i=0; (unsigned int)i < strlen(tmp_str); i++) { + if (tmp_str[i] == '|') { + char *new_str = (char *)malloc(i+1); + memcpy(new_str, tmp_str, i); + new_str[i] = '\0'; + *did_alloc = 1; + *str = &tmp_str[i]; + return new_str; + } + } + + if (norm_str) { + *did_alloc = 0; + *str = NULL; + return tmp_str; + } + + return NULL; +} + int get_obj(char *var_name) { + char** str = &var_name; + char *str1; struct var_mapping *var_map; - int i; + int did_alloc=0; + int obj=0, got_obj=0; DBG(5, fprintf(outfp, "Getting object for %s\n", var_name)); @@ -242,53 +279,33 @@ int get_obj(char *var_name) * Check for '|', indicates that one or more values are or'd * together */ - for (i=0; (unsigned int)i < strlen(var_name); i++) { - if (var_name[i] == '|') { - char *str1 = malloc(i+1); - char *str2 = malloc(strlen(var_name)-i+1); - int obj; - struct var_mapping *tmp_map; - - memcpy(str1, var_name, i); - str1[i] = '\0'; - memcpy(str2, (char *)&var_name[i+1], strlen(var_name)-i); + while ((str1 = get_or_part(str, &did_alloc)) != NULL) { if (isdigit(str1[0])) { if (str1[0] == '0') { /* Assume octal format */ - obj = strtol(str1, NULL, 8); + obj |= strtol(str1, NULL, 8); } else - obj = atoi(str1); + obj |= atoi(str1); } else { - tmp_map = get_map(str1); - if (!tmp_map) { + var_map = get_map(str1); + if (!var_map) { + if (did_alloc) free(str1); - free(str2); return -1; } - obj = tmp_map->obj; + obj |= var_map->obj; } - if (isdigit(str2[0])) { - if (str2[0] == '0') { - /* Assume octal format */ - obj |= strtol(str2, NULL, 8); - } else - obj = atoi(str2); - } else { - tmp_map = get_map(str2); - if (!tmp_map) { + if (did_alloc) { + did_alloc = 0; free(str1); - free(str2); - return -1; } - obj |= tmp_map->obj; + got_obj++; } - free(str1); - free(str2); + + if (got_obj) return obj; - } - } var_map = get_map(var_name); if (!var_map) @@ -983,10 +1000,12 @@ int main(int argc, char *argv[]) print_line = 0; +#if 0 /* sysio defaults */ strcpy(root_driver, DEFAULT_DRIVER); strcpy(mntpath, "/"); mntflgs = 0; +#endif my_errno = 0; Index: test_driver.h =================================================================== RCS file: /cvsroot/libsysio/libsysio/tests/test_driver.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -w -b -B -p -r1.4 -r1.5 --- test_driver.h 6 Feb 2004 20:07:31 -0000 1.4 +++ test_driver.h 14 Feb 2004 19:43:00 -0000 1.5 @@ -209,7 +209,7 @@ extern int test_do_umount(int argc, char /* Functions defined in sysio_tests.c */ extern int sysio_mount(char *from, char *to); extern int sysio_list(char *path); -extern int initilize_sysio(char *root_driver, char *root_path, int mntflgs); +extern int initilize_sysio(void); extern int sysio_chdir(char *newdir); extern int sysio_chmod(char *mode_arg, const char *path); extern int sysio_chown(char *new_id, char *file); Index: test_getcwd.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/tests/test_getcwd.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -w -b -B -p -r1.3 -r1.4 --- test_getcwd.c 10 Oct 2003 18:50:31 -0000 1.3 +++ test_getcwd.c 14 Feb 2004 19:43:00 -0000 1.4 @@ -64,7 +64,7 @@ /* * Test getcwd() * - * Usage: test_cwd [-a] [-m <fsname>] [-r <mntpath>] [<working-dir>...] + * Usage: test_cwd [<working-dir>...] * * Without any path arguments, the program reads from standard-in, dealing with * each line as an absolute or relative path until EOF. @@ -73,68 +73,32 @@ static int doit(const char *path); static void usage(void); -static const char *root_driver = DEFAULT_DRIVER; -static const char *mntpath = "/"; -static unsigned mntflgs = 0; - -#ifdef AUTOMOUNT_FILE_NAME -#define EXTRA_AUTOMOUNT_OPT "a" -#else -#define EXTRA_AUTOMOUNT_OPT -#endif - -const char *opts = EXTRA_AUTOMOUNT_OPT "m:r:"; - int main(int argc, char *const argv[]) { int i; int err; int n; + extern int _test_sysio_startup(void); /* * Parse command line arguments. */ - while ((i = getopt(argc, argv, opts)) != -1) + while ((i = getopt(argc, argv, "")) != -1) switch (i) { -#ifdef AUTOMOUNT_FILE_NAME - case 'a': - mntflgs |= MOUNT_F_AUTO; - break; -#endif - case 'm': - root_driver = optarg; - break; - case 'r': - mntpath = optarg; - break; default: usage(); } -#ifndef CPLANT_YOD /* * Init sysio lib. */ - _sysio_init(); - - /* - * Init native file system driver and request mount of specified - * source directory. - */ - err = drv_init_all(); - if (err) { - errno = -err; - perror("drv_init_all"); - exit(1); - } - err = _sysio_mount_root(mntpath, root_driver, mntflgs, NULL); + err = _test_sysio_startup(); if (err) { errno = -err; - perror("_sysio_mount_root"); + perror("sysio startup"); exit(1); } -#endif n = argc - optind; @@ -170,12 +134,10 @@ main(int argc, char *const argv[]) } } -#ifndef CPLANT_YOD /* * Clean up. */ _sysio_shutdown(); -#endif return 0; } @@ -205,10 +167,6 @@ usage() (void )fprintf(stderr, "Usage: test_getcwd " -#ifdef AUTOMOUNT_FILE_NAME - "[-a] " -#endif - "[-m <driver>] [-r <mntpath>]" " [<path> ...\n]"); exit(1); Index: test_link.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/tests/test_link.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -w -b -B -p -r1.1 -r1.2 --- test_link.c 20 Oct 2003 16:32:29 -0000 1.1 +++ test_link.c 14 Feb 2004 19:43:00 -0000 1.2 @@ -46,11 +46,11 @@ #include <string.h> #ifndef REDSTORM #include <getopt.h> -#else -#include <unistd.h> #endif +#include <unistd.h> #include <errno.h> #include <sys/types.h> +#include <sys/stat.h> #include <sys/queue.h> #if 0 #include <dirent.h> @@ -64,49 +64,26 @@ /* * Test hard link * - * Usage: link [-a] [-m <fsname>] [-r <mntpath>] oldpath newpath + * Usage: link oldpath newpath * */ -static int linkit(const char *old, const char *new); static void usage(void); -static const char *root_driver = DEFAULT_DRIVER; -static const char *mntpath = "/"; -static unsigned mntflgs = 0; - -#ifdef AUTOMOUNT_FILE_NAME -#define EXTRA_AUTOMOUNT_OPT "a" -#else -#define EXTRA_AUTOMOUNT_OPT -#endif - -const char *opts = EXTRA_AUTOMOUNT_OPT "m:r:"; - int main(int argc, char *const argv[]) { int i; int err; int n; + extern int _test_sysio_startup(void); /* * Parse command line arguments. */ - while ((i = getopt(argc, argv, opts)) != -1) + while ((i = getopt(argc, argv, "")) != -1) switch (i) { -#ifdef AUTOMOUNT_FILE_NAME - case 'a': - mntflgs |= MOUNT_F_AUTO; - break; -#endif - case 'm': - root_driver = optarg; - break; - case 'r': - mntpath = optarg; - break; default: usage(); } @@ -114,22 +91,10 @@ main(int argc, char *const argv[]) /* * Init sysio lib. */ - _sysio_init(); - - /* - * Init native file system driver and request mount of specified - * source directory. - */ - err = drv_init_all(); + err = _test_sysio_startup(); if (err) { errno = -err; - perror("drv_init_all"); - exit(1); - } - err = _sysio_mount_root(mntpath, root_driver, mntflgs, NULL); - if (err) { - errno = -err; - perror("_sysio_mount_root"); + perror("sysio startup"); exit(1); } @@ -141,10 +106,18 @@ main(int argc, char *const argv[]) */ while (optind < argc) { const char *old, *new; + struct stat stbuf; old = argv[optind++]; new = argv[optind++]; - (void )linkit(old, new); + if ((err = link(old, new)) != 0) { + perror("link"); + break; + } + if ((err = lstat(new, &stbuf)) != 0) { + perror(new); + break; + } } /* @@ -152,19 +125,7 @@ main(int argc, char *const argv[]) */ _sysio_shutdown(); - return 0; -} - -static int -linkit(const char *old, const char *new) -{ - unlink(new); - if (link(old, new) < 0) { - perror(old); - return -1; - } - - return 0; + return err ? -1 : 0; } static void @@ -172,7 +133,7 @@ usage() { (void )fprintf(stderr, - "Usage: unlink [-a] [-m <driver>] [-r <mntpath>]" + "Usage: unlink" " oldpath newpath\n"); exit(1); Index: test_list.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/tests/test_list.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -w -b -B -p -r1.6 -r1.7 --- test_list.c 10 Oct 2003 18:50:31 -0000 1.6 +++ test_list.c 14 Feb 2004 19:43:00 -0000 1.7 @@ -64,7 +64,7 @@ /* * Stat files. * - * Usage: test_list [-a] [-m <fsname>] [-r <mntpath>] [path...] + * Usage: test_list [path...] * * Without any path arguments, the program reads from standard-in, dealing with * each line as an absolute or relative path until EOF. @@ -73,69 +73,34 @@ static int listit(const char *path); static void usage(void); -static const char *root_driver = DEFAULT_DRIVER; -static const char *mntpath = "/"; -static unsigned mntflgs = 0; - -#ifdef AUTOMOUNT_FILE_NAME -#define EXTRA_AUTOMOUNT_OPT "a" -#else -#define EXTRA_AUTOMOUNT_OPT -#endif - -const char *opts = EXTRA_AUTOMOUNT_OPT "m:r:"; - int main(int argc, char *const argv[]) { int i; int err; int n; + extern int _test_sysio_startup(void); /* * Parse command line arguments. */ - while ((i = getopt(argc, argv, opts)) != -1) + while ((i = getopt(argc, argv, "")) != -1) switch (i) { -#ifdef AUTOMOUNT_FILE_NAME - case 'a': - mntflgs |= MOUNT_F_AUTO; - break; -#endif - case 'm': - root_driver = optarg; - break; - case 'r': - mntpath = optarg; - break; default: usage(); } -#ifndef CPLANT_YOD /* * Init sysio lib. */ - _sysio_init(); - - /* - * Init native file system driver and request mount of specified - * source directory. - */ - err = drv_init_all(); - if (err) { - errno = -err; - perror("drv_init_all"); - exit(1); - } - err = _sysio_mount_root(mntpath, root_driver, mntflgs, NULL); + err = _test_sysio_startup(); if (err) { errno = -err; - perror("_sysio_mount_root"); + perror("sysio startup"); exit(1); } -#endif + n = argc - optind; /* @@ -170,12 +135,10 @@ main(int argc, char *const argv[]) } } -#ifndef CPLANT_YOD /* * Clean up. */ _sysio_shutdown(); -#endif return 0; } @@ -243,7 +206,7 @@ usage() { (void )fprintf(stderr, - "Usage: list_path [-a] [-m <driver>] [-r <mntpath>]" + "Usage: list_path" " [<path> ...\n]"); exit(1); Index: test_path.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/tests/test_path.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -w -b -B -p -r1.6 -r1.7 --- test_path.c 10 Oct 2003 18:50:31 -0000 1.6 +++ test_path.c 14 Feb 2004 19:43:00 -0000 1.7 @@ -64,7 +64,7 @@ /* * Stat files. * - * Usage: test_path [-a] [-m <fsname>] [-r <mntpath>] [path...] + * Usage: test_path [path...] * * Without any path arguments, the program reads from standard-in, dealing with * each line as an absolute or relative path until EOF. @@ -73,69 +73,33 @@ static int statit(const char *path); static void usage(void); -static const char *root_driver = DEFAULT_DRIVER; -static const char *mntpath = "/"; -static unsigned mntflgs = 0; - -#ifdef AUTOMOUNT_FILE_NAME -#define EXTRA_AUTOMOUNT_OPT "a" -#else -#define EXTRA_AUTOMOUNT_OPT -#endif - -const char *opts = EXTRA_AUTOMOUNT_OPT "m:r:"; - int main(int argc, char *const argv[]) { int i; int err; int n; + extern int _test_sysio_startup(void); /* * Parse command line arguments. */ - while ((i = getopt(argc, argv, opts)) != -1) + while ((i = getopt(argc, argv, "")) != -1) switch (i) { -#ifdef AUTOMOUNT_FILE_NAME - case 'a': - mntflgs |= MOUNT_F_AUTO; - break; -#endif - case 'm': - root_driver = optarg; - break; - case 'r': - mntpath = optarg; - break; default: usage(); } -#ifndef CPLANT_YOD /* * Init sysio lib. */ - _sysio_init(); - - /* - * Init native file system driver and request mount of specified - * source directory. - */ - err = drv_init_all(); + err = _test_sysio_startup(); if (err) { errno = -err; - perror("drv_init_all"); + perror("sysio startup"); exit(1); } - err = _sysio_mount_root(mntpath, root_driver, mntflgs, NULL); - if (err) { - errno = -err; - perror("_sysio_mount_root"); - exit(1); - } -#endif n = argc - optind; @@ -171,12 +135,10 @@ main(int argc, char *const argv[]) } } -#ifndef CPLANT_YOD /* * Clean up. */ _sysio_shutdown(); -#endif return 0; } @@ -248,7 +210,7 @@ usage() { (void )fprintf(stderr, - "Usage: test_path [-a] [-m <driver>] [-r <mntpath>]" + "Usage: test_path" " [<path> ...\n]"); exit(1); Index: test_regions.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/tests/test_regions.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -w -b -B -p -r1.2 -r1.3 --- test_regions.c 6 Feb 2004 20:07:31 -0000 1.2 +++ test_regions.c 14 Feb 2004 19:43:00 -0000 1.3 @@ -76,7 +76,7 @@ /* * Copy one file to another. * - * Usage: test_regions [-a] [-r <source>] [-m <root-driver>] [-x] \ + * Usage: test_regions [-x] \ * {r,w} <off> <count> <path> * * Destination will not be overwritten if it already exist. @@ -90,10 +90,6 @@ #warning Cannot prompt the 64-bit interface #endif -char *root_driver = DEFAULT_DRIVER; -char *mntpath = "/"; -unsigned mntflgs = 0; - char which; #ifdef GO64 int use64 = 0; /* 64-bit interface? */ @@ -119,6 +115,7 @@ main(int argc, char * const argv[]) int flags; int fd; ssize_t cc; + extern int _test_sysio_startup(void); /* * Parse command-line args. @@ -128,26 +125,12 @@ main(int argc, char * const argv[]) #ifdef __GLIBC__ "+" #endif -#ifdef AUTOMOUNT_FILE_NAME - "a" -#endif #ifdef GO64 "x" #endif - "r:m:")) != -1) + "")) != -1) switch (i) { -#ifdef AUTOMOUNT_FILE_NAME - case 'a': - mntflgs |= MOUNT_F_AUTO; - break; -#endif - case 'r': /* set working dir */ - mntpath = optarg; - break; - case 'm': - root_driver = optarg; - break; #ifdef GO64 case 'x': use64 = 1; @@ -196,30 +179,22 @@ main(int argc, char * const argv[]) usage(); path = argv[optind++]; -#ifndef CPLANT_YOD - if (_sysio_init() != 0) { - perror("init sysio"); - exit(1); - } - err = drv_init_all(); - if (err) { - perror("init drivers"); - exit(1); - } - err = _sysio_mount_root(mntpath, root_driver, mntflgs, NULL); + err = _test_sysio_startup(); if (err) { errno = -err; - perror(root_driver); + perror("sysio startup"); exit(1); } -#endif + (void )umask(022); buf = malloc(nbytes); if (!buf) { perror("malloc"); - exit(1); + err = 1; + goto out; } + (void )memset(buf, 0, nbytes); err = 0; flags = which == 'r' ? O_RDONLY : (O_WRONLY|O_CREAT|O_EXCL); @@ -231,7 +206,7 @@ main(int argc, char * const argv[]) if (fd < 0) { perror(path); err = 1; - goto out; + goto error; } #ifdef GO64 if (use64) @@ -243,12 +218,14 @@ main(int argc, char * const argv[]) #ifdef GO64 if ((use64 && off64 < 0) || (!use64 && off < 0)) { perror(use64 ? "lseek64" : "lseek"); - exit(1); + err = 1; + goto error; } #else if (off < 0) { perror("lseek"); - exit(1); + err = 1; + goto error; } #endif if (which == 'r') @@ -297,12 +274,11 @@ main(int argc, char * const argv[]) ); error: - if (close(fd) != 0) + if (fd > 0 && close(fd) != 0) perror(path); + free(buf); out: -#ifndef CPLANT_YOD _sysio_shutdown(); -#endif return err; } @@ -313,13 +289,9 @@ usage() (void )fprintf(stderr, "Usage: test_regions " -#ifdef AUTOMOUNT_FILE_NAME - "[-a] " -#endif #ifdef GO64 "[-x] " #endif - "[-r <source>] [-m <fsname>]" " {r,w} <offset> <nbytes> <path>\n"); exit(1); } Index: test_rename.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/tests/test_rename.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -w -b -B -p -r1.3 -r1.4 --- test_rename.c 28 Oct 2003 18:54:19 -0000 1.3 +++ test_rename.c 14 Feb 2004 19:43:00 -0000 1.4 @@ -65,13 +65,9 @@ /* * Rename a file system object. * - * Usage: test_rename [-a] [-r <source>] [-m <root-driver>] <src> <dest> + * Usage: test_rename <src> <dest> */ -char *root_driver = DEFAULT_DRIVER; -char *mntpath = "/"; -unsigned mntflgs = 0; - void usage(void); int rename_file(const char *spath, const char *dpath); @@ -81,52 +77,31 @@ main(int argc, char * const argv[]) int i; int err; const char *spath, *dpath; + extern int _test_sysio_startup(void); /* * Parse command-line args. */ while ((i = getopt(argc, argv, -#ifdef AUTOMOUNT_FILE_NAME - "a" -#endif - "r:m:")) != -1) + "" + )) != -1) switch (i) { -#ifdef AUTOMOUNT_FILE_NAME - case 'a': - mntflgs |= MOUNT_F_AUTO; - break; -#endif - case 'r': /* set working dir */ - mntpath = optarg; - break; - case 'm': - root_driver = optarg; - break; default: usage(); } if (!(argc - optind)) usage(); -#ifndef CPLANT_YOD - if (_sysio_init() != 0) { - perror("init sysio"); - exit(1); - } - err = drv_init_all(); - if (err) { - perror("init drivers"); - exit(1); - } - err = _sysio_mount_root(mntpath, root_driver, mntflgs, NULL); + + err = _test_sysio_startup(); if (err) { errno = -err; - perror(root_driver); + perror("sysio startup"); exit(1); } -#endif + (void )umask(022); /* @@ -146,9 +121,7 @@ main(int argc, char * const argv[]) if (err) perror("rename"); -#ifndef CPLANT_YOD _sysio_shutdown(); -#endif return err; } @@ -159,10 +132,6 @@ usage() (void )fprintf(stderr, "Usage: test_rename " -#ifdef AUTOMOUNT_FILE_NAME - "[-a] " -#endif - "[-r <source>] [-m <fsname>]" " source destination\n"); exit(1); } Index: test_stats.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/tests/test_stats.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -w -b -B -p -r1.5 -r1.6 --- test_stats.c 10 Oct 2003 18:50:31 -0000 1.5 +++ test_stats.c 14 Feb 2004 19:43:00 -0000 1.6 @@ -66,79 +66,45 @@ /* * Get stats of file and file system. * - * Usage: test_stats [-a] [-r <root-path>] [-m <root-driver>] [<path> ...] + * Usage: test_stats [<path> ...] */ -char *root_driver = DEFAULT_DRIVER; -char *root_path = "/"; -unsigned mntflgs = 0; - void usage(void); void do_stats(const char *path); -#ifdef AUTOMOUNT_FILE_NAME -#define EXTRA_AUTOMOUNT_OPT "a" -#else -#define EXTRA_AUTOMOUNT_OPT -#endif - -const char *opts = EXTRA_AUTOMOUNT_OPT "m:r:"; - int main(int argc, char * const argv[]) { int i; int err; + extern int _test_sysio_startup(void); /* * Parse command-line args. */ - while ((i = getopt(argc, argv, opts)) != -1) + while ((i = getopt(argc, argv, "")) != -1) switch (i) { -#ifdef AUTOMOUNT_FILE_NAME - case 'a': - mntflgs |= MOUNT_F_AUTO; - break; -#endif - case 'r': - root_path = optarg; - break; - case 'm': - root_driver = optarg; - break; default: usage(); } -#ifndef CPLANT_YOD - if (_sysio_init() != 0) { - perror("init sysio"); - exit(1); - } - err = drv_init_all(); - if (err) { - perror("init drivers"); - exit(1); - } - err = _sysio_mount_root(root_path, root_driver, mntflgs, NULL); + err = _test_sysio_startup(); if (err) { errno = -err; - perror(root_driver); + perror("sysio startup"); exit(1); } -#endif + (void )umask(022); while (optind < argc) do_stats(argv[optind++]); -#ifndef CPLANT_YOD /* * Clean up. */ _sysio_shutdown(); -#endif return 0; } @@ -148,7 +114,7 @@ usage() { (void )fprintf(stderr, - "Usage: test_stats [-a] [-m <fsname>] [-r <root-path>]" + "Usage: test_stats" " source destination\n"); exit(1); } Index: test_unlink.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/tests/test_unlink.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -w -b -B -p -r1.2 -r1.3 --- test_unlink.c 10 Oct 2003 18:50:32 -0000 1.2 +++ test_unlink.c 14 Feb 2004 19:43:00 -0000 1.3 @@ -64,7 +64,7 @@ /* * Unlink files. * - * Usage: unlink [-a] [-m <fsname>] [-r <mntpath>] [path...] + * Usage: unlink [path...] * * Without any path arguments, the program unlinks files named * by the ocmmand line args. @@ -73,42 +73,20 @@ static int unlinkit(const char *path); static void usage(void); -static const char *root_driver = DEFAULT_DRIVER; -static const char *mntpath = "/"; -static unsigned mntflgs = 0; - -#ifdef AUTOMOUNT_FILE_NAME -#define EXTRA_AUTOMOUNT_OPT "a" -#else -#define EXTRA_AUTOMOUNT_OPT -#endif - -const char *opts = EXTRA_AUTOMOUNT_OPT "m:r:"; - int main(int argc, char *const argv[]) { int i; int err; int n; + extern int _test_sysio_startup(void); /* * Parse command line arguments. */ - while ((i = getopt(argc, argv, opts)) != -1) + while ((i = getopt(argc, argv, "")) != -1) switch (i) { -#ifdef AUTOMOUNT_FILE_NAME - case 'a': - mntflgs |= MOUNT_F_AUTO; - break; -#endif - case 'm': - root_driver = optarg; - break; - case 'r': - mntpath = optarg; - break; default: usage(); } @@ -116,22 +94,10 @@ main(int argc, char *const argv[]) /* * Init sysio lib. */ - _sysio_init(); - - /* - * Init native file system driver and request mount of specified - * source directory. - */ - err = drv_init_all(); - if (err) { - errno = -err; - perror("drv_init_all"); - exit(1); - } - err = _sysio_mount_root(mntpath, root_driver, mntflgs, NULL); + err = _test_sysio_startup(); if (err) { errno = -err; - perror("_sysio_mount_root"); + perror("sysio startup"); exit(1); } @@ -194,7 +160,7 @@ usage() { (void )fprintf(stderr, - "Usage: unlink [-a] [-m <driver>] [-r <mntpath>]" + "Usage: unlink" " [<path> ...\n]"); exit(1); --- test_mounts.c DELETED --- --- test_stdfd.c DELETED --- |