From 20d0187e95be6ec8c131a9bb8691e7d939875e68 Mon Sep 17 00:00:00 2001 From: scjody Date: Wed, 9 May 2007 22:27:48 +0000 Subject: [PATCH] Branch b1_4 Update libsysio to latest version. b=12331 --- libsysio/AUTHORS | 5 + libsysio/Rules.make | 5 +- libsysio/config.guess | 67 +- libsysio/config.sub | 19 +- libsysio/configure.in | 73 +- libsysio/depcomp | 31 +- libsysio/drivers/incore/fs_incore.c | 88 +- libsysio/drivers/native/fs_native.c | 6 +- libsysio/drivers/sockets/sockets.c | 6 + libsysio/include/{namespace.h => creds.h} | 35 +- libsysio/include/file.h | 17 +- libsysio/include/inode.h | 23 +- libsysio/include/sysio-cmn.h | 15 +- libsysio/include/sysio.h | 5 + libsysio/misc/init-env.sh | 8 +- libsysio/missing | 6 +- libsysio/src/access.c | 208 ++- libsysio/src/chdir.c | 8 +- libsysio/src/fcntl.c | 3 +- libsysio/src/getdirentries.c | 32 +- libsysio/src/init.c | 216 ++- libsysio/src/inode.c | 24 +- libsysio/src/mkdir.c | 36 +- libsysio/src/mknod.c | 52 +- libsysio/src/namei.c | 28 +- libsysio/src/open.c | 9 +- libsysio/src/readlink.c | 3 - libsysio/src/rename.c | 5 +- libsysio/src/rmdir.c | 9 +- libsysio/src/rw.c | 4 +- libsysio/src/symlink.c | 16 +- libsysio/src/truncate.c | 7 + libsysio/src/unlink.c | 11 +- libsysio/tests/Makefile.am | 21 +- libsysio/tests/cleanup.pl | 96 - libsysio/tests/help.c | 551 ------ libsysio/tests/helper.pm | 147 -- libsysio/tests/populator.pl | 155 -- libsysio/tests/setup.pl | 104 -- libsysio/tests/sysio_stubs.c | 2706 ----------------------------- libsysio/tests/sysio_tests.c | 861 --------- libsysio/tests/test_all.pl | 232 --- libsysio/tests/test_chown.c | 143 ++ libsysio/tests/test_copy.bash | 129 -- libsysio/tests/test_copy.c | 3 +- libsysio/tests/test_copy.pl | 218 --- libsysio/tests/test_driver.c | 1085 ------------ libsysio/tests/test_driver.h | 301 ---- libsysio/tests/test_fcntl_lock.c | 145 ++ libsysio/tests/test_getcwd.c | 1 + libsysio/tests/test_getcwd.pl | 121 -- libsysio/tests/test_link.c | 1 + libsysio/tests/test_list.c | 3 +- libsysio/tests/test_list.pl | 237 --- libsysio/tests/test_mkdir.c | 163 ++ libsysio/tests/test_mknod.c | 162 ++ libsysio/tests/test_path.c | 5 +- libsysio/tests/test_path.pl | 188 -- libsysio/tests/test_regions.c | 18 +- libsysio/tests/test_rename.c | 3 +- libsysio/tests/test_rw.pl | 537 ------ libsysio/tests/test_stats.c | 3 +- libsysio/tests/test_stats.pl | 268 --- libsysio/tests/test_stdfd.pl | 242 --- libsysio/tests/test_strided.pl | 462 ----- libsysio/tests/test_symlink.c | 140 ++ libsysio/tests/test_symlink.pl | 247 --- libsysio/tests/test_unlink.c | 1 + libsysio/tests/verifier.pl | 161 -- 69 files changed, 1488 insertions(+), 9452 deletions(-) rename libsysio/include/{namespace.h => creds.h} (52%) delete mode 100755 libsysio/tests/cleanup.pl delete mode 100644 libsysio/tests/help.c delete mode 100644 libsysio/tests/helper.pm delete mode 100755 libsysio/tests/populator.pl delete mode 100755 libsysio/tests/setup.pl delete mode 100644 libsysio/tests/sysio_stubs.c delete mode 100644 libsysio/tests/sysio_tests.c delete mode 100755 libsysio/tests/test_all.pl create mode 100644 libsysio/tests/test_chown.c delete mode 100644 libsysio/tests/test_copy.bash delete mode 100755 libsysio/tests/test_copy.pl delete mode 100644 libsysio/tests/test_driver.c delete mode 100644 libsysio/tests/test_driver.h create mode 100644 libsysio/tests/test_fcntl_lock.c delete mode 100755 libsysio/tests/test_getcwd.pl delete mode 100755 libsysio/tests/test_list.pl create mode 100644 libsysio/tests/test_mkdir.c create mode 100644 libsysio/tests/test_mknod.c delete mode 100755 libsysio/tests/test_path.pl delete mode 100755 libsysio/tests/test_rw.pl delete mode 100755 libsysio/tests/test_stats.pl delete mode 100755 libsysio/tests/test_stdfd.pl delete mode 100755 libsysio/tests/test_strided.pl create mode 100644 libsysio/tests/test_symlink.c delete mode 100755 libsysio/tests/test_symlink.pl delete mode 100755 libsysio/tests/verifier.pl diff --git a/libsysio/AUTHORS b/libsysio/AUTHORS index 7293307..0dcc9cd 100644 --- a/libsysio/AUTHORS +++ b/libsysio/AUTHORS @@ -1 +1,6 @@ Lee Ward + +Various folks at: + +Cluster File Systems Incorporated. (www.clusterfs.com) +Cray Incorporated (www.cray.com) diff --git a/libsysio/Rules.make b/libsysio/Rules.make index e2558c9..e69c6a2 100644 --- a/libsysio/Rules.make +++ b/libsysio/Rules.make @@ -1,4 +1,3 @@ - if WITH_STDFD_DEV STDFD_DEV_CPPFLAGS =-DSTDFD_DEV=1 -I$(top_srcdir)/dev/stdfd else @@ -14,6 +13,6 @@ endif DEV_CPPFLAGS = $(STDFD_DEV_CPPFLAGS) AM_CPPFLAGS = \ - -D_POSIX_C_SOURCE=199506L -D_XOPEN_SOURCE=600 \ + $(TRACING) \ $(AUTOMOUNT) $(ZERO_SUM_MEMORY) $(DEV_CPPFLAGS) $(SOCKETS_CPPFLAGS) \ - $(DEFER_INIT_CWD) -I$(top_srcdir)/include + $(DEFER_INIT_CWD) $(SYSIO_LABEL_NAMES) -I$(top_srcdir)/include diff --git a/libsysio/config.guess b/libsysio/config.guess index c8fc683..500ee74 100755 --- a/libsysio/config.guess +++ b/libsysio/config.guess @@ -3,7 +3,7 @@ # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, # 2000, 2001, 2002, 2003 Free Software Foundation, Inc. -timestamp='2003-07-02' +timestamp='2003-10-03' # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by @@ -136,16 +136,6 @@ UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown -case "${UNAME_MACHINE}" in - i?86) - test -z "$VENDOR" && VENDOR=pc - ;; - *) - test -z "$VENDOR" && VENDOR=unknown - ;; -esac -test -f /etc/SuSE-release -o -f /.buildenv && VENDOR=suse - # Note: order is significant - the case branches are not exclusive. case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in @@ -744,7 +734,7 @@ EOF echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' exit 0 ;; *:UNICOS/mp:*:*) - echo nv1-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + echo nv1-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' exit 0 ;; F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` @@ -815,16 +805,16 @@ EOF echo ${UNAME_MACHINE}-pc-minix exit 0 ;; arm*:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-linux + echo ${UNAME_MACHINE}-unknown-linux-gnu exit 0 ;; cris:Linux:*:*) - echo cris-axis-linux + echo cris-axis-linux-gnu exit 0 ;; ia64:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-linux + echo ${UNAME_MACHINE}-unknown-linux-gnu exit 0 ;; m68*:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-linux + echo ${UNAME_MACHINE}-unknown-linux-gnu exit 0 ;; mips:Linux:*:*) eval $set_cc_for_build @@ -843,7 +833,7 @@ EOF #endif EOF eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^CPU=` - test x"${CPU}" != x && echo "${CPU}-${VENDOR}-linux" && exit 0 + test x"${CPU}" != x && echo "${CPU}-unknown-linux-gnu" && exit 0 ;; mips64:Linux:*:*) eval $set_cc_for_build @@ -862,13 +852,13 @@ EOF #endif EOF eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^CPU=` - test x"${CPU}" != x && echo "${CPU}-${VENDOR}-linux" && exit 0 + test x"${CPU}" != x && echo "${CPU}-unknown-linux-gnu" && exit 0 ;; ppc:Linux:*:*) - echo powerpc-${VENDOR}-linux + echo powerpc-unknown-linux-gnu exit 0 ;; ppc64:Linux:*:*) - echo powerpc64-${VENDOR}-linux + echo powerpc64-unknown-linux-gnu exit 0 ;; alpha:Linux:*:*) case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in @@ -881,34 +871,34 @@ EOF EV68*) UNAME_MACHINE=alphaev68 ;; esac objdump --private-headers /bin/sh | grep ld.so.1 >/dev/null - if test "$?" = 0 ; then LIBC="-libc1" ; else LIBC="" ; fi - echo ${UNAME_MACHINE}-${VENDOR}-linux${LIBC} + if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi + echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC} exit 0 ;; parisc:Linux:*:* | hppa:Linux:*:*) # Look for CPU level case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in - PA7*) echo hppa1.1-${VENDOR}-linux ;; - PA8*) echo hppa2.0-${VENDOR}-linux ;; - *) echo hppa-${VENDOR}-linux ;; + PA7*) echo hppa1.1-unknown-linux-gnu ;; + PA8*) echo hppa2.0-unknown-linux-gnu ;; + *) echo hppa-unknown-linux-gnu ;; esac exit 0 ;; parisc64:Linux:*:* | hppa64:Linux:*:*) - echo hppa64-${VENDOR}-linux + echo hppa64-unknown-linux-gnu exit 0 ;; s390:Linux:*:* | s390x:Linux:*:*) echo ${UNAME_MACHINE}-ibm-linux exit 0 ;; sh64*:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-linux + echo ${UNAME_MACHINE}-unknown-linux-gnu exit 0 ;; sh*:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-linux + echo ${UNAME_MACHINE}-unknown-linux-gnu exit 0 ;; sparc:Linux:*:* | sparc64:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-linux + echo ${UNAME_MACHINE}-unknown-linux-gnu exit 0 ;; x86_64:Linux:*:*) - echo x86_64-${VENDOR}-linux + echo x86_64-unknown-linux-gnu exit 0 ;; i*86:Linux:*:*) # The BFD linker knows what the default object file format is, so @@ -923,18 +913,18 @@ EOF p'` case "$ld_supported_targets" in elf32-i386) - TENTATIVE="${UNAME_MACHINE}-${VENDOR}-linux" + TENTATIVE="${UNAME_MACHINE}-pc-linux-gnu" ;; a.out-i386-linux) - echo "${UNAME_MACHINE}-${VENDOR}-linuxaout" + echo "${UNAME_MACHINE}-pc-linux-gnuaout" exit 0 ;; coff-i386) - echo "${UNAME_MACHINE}-${VENDOR}-linuxcoff" + echo "${UNAME_MACHINE}-pc-linux-gnucoff" exit 0 ;; "") - # Either a pre-BFD a.out linker (linuxoldld) or + # Either a pre-BFD a.out linker (linux-gnuoldld) or # one that does not give us useful --help. - echo "${UNAME_MACHINE}-${VENDOR}-linuxoldld" + echo "${UNAME_MACHINE}-pc-linux-gnuoldld" exit 0 ;; esac # Determine whether the default compiler is a.out or elf @@ -958,9 +948,12 @@ EOF LIBC=gnuaout #endif #endif + #ifdef __dietlibc__ + LIBC=dietlibc + #endif EOF eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=` - test x"${LIBC}" != x && echo "${UNAME_MACHINE}-${VENDOR}-linux-${LIBC}" | sed 's/linux-gnu/linux/' && exit 0 + test x"${LIBC}" != x && echo "${UNAME_MACHINE}-pc-linux-${LIBC}" && exit 0 test x"${TENTATIVE}" != x && echo "${TENTATIVE}" && exit 0 ;; i*86:DYNIX/ptx:4*:*) @@ -1174,7 +1167,7 @@ EOF *:QNX:*:4*) echo i386-pc-qnx exit 0 ;; - NSR-[DGKLNPTVW]:NONSTOP_KERNEL:*:*) + NSR-[DGKLNPTVWY]:NONSTOP_KERNEL:*:*) echo nsr-tandem-nsk${UNAME_RELEASE} exit 0 ;; *:NonStop-UX:*:*) diff --git a/libsysio/config.sub b/libsysio/config.sub index 9952c14..1f31816 100755 --- a/libsysio/config.sub +++ b/libsysio/config.sub @@ -3,7 +3,7 @@ # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, # 2000, 2001, 2002, 2003 Free Software Foundation, Inc. -timestamp='2003-07-04' +timestamp='2003-08-18' # This file is (in principle) common to ALL GNU software. # The presence of a machine in this file suggests that SOME GNU software @@ -118,7 +118,7 @@ esac # Here we must recognize all the valid KERNEL-OS combinations. maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'` case $maybe_os in - nto-qnx* | linux-gnu* | kfreebsd*-gnu* | netbsd*-gnu* | storm-chaos* | os2-emx* | rtmk-nova*) + nto-qnx* | linux-gnu* | linux-dietlibc | kfreebsd*-gnu* | netbsd*-gnu* | storm-chaos* | os2-emx* | rtmk-nova*) os=-$maybe_os basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'` ;; @@ -228,13 +228,14 @@ case $basic_machine in | a29k \ | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \ | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \ + | am33_2.0 \ | arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr \ | c4x | clipper \ | d10v | d30v | dlx | dsp16xx \ | fr30 | frv \ | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \ | i370 | i860 | i960 | ia64 \ - | ip2k \ + | ip2k | iq2000 \ | m32r | m68000 | m68k | m88k | mcore \ | mips | mipsbe | mipseb | mipsel | mipsle \ | mips16 \ @@ -247,6 +248,7 @@ case $basic_machine in | mipsisa32 | mipsisa32el \ | mipsisa32r2 | mipsisa32r2el \ | mipsisa64 | mipsisa64el \ + | mipsisa64r2 | mipsisa64r2el \ | mipsisa64sb1 | mipsisa64sb1el \ | mipsisa64sr71k | mipsisa64sr71kel \ | mipstx39 | mipstx39el \ @@ -304,7 +306,7 @@ case $basic_machine in | h8300-* | h8500-* \ | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \ | i*86-* | i860-* | i960-* | ia64-* \ - | ip2k-* \ + | ip2k-* | iq2000-* \ | m32r-* \ | m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \ | m88110-* | m88k-* | mcore-* \ @@ -319,6 +321,7 @@ case $basic_machine in | mipsisa32-* | mipsisa32el-* \ | mipsisa32r2-* | mipsisa32r2el-* \ | mipsisa64-* | mipsisa64el-* \ + | mipsisa64r2-* | mipsisa64r2el-* \ | mipsisa64sb1-* | mipsisa64sb1el-* \ | mipsisa64sr71k-* | mipsisa64sr71kel-* \ | mipstx39-* | mipstx39el-* \ @@ -1134,7 +1137,7 @@ case $os in | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \ | -chorusos* | -chorusrdb* \ | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ - | -mingw32* | -linux* | -uxpv* | -beos* | -mpeix* | -udk* \ + | -mingw32* | -linux-gnu* | -uxpv* | -beos* | -mpeix* | -udk* \ | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \ | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \ | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \ @@ -1164,6 +1167,12 @@ case $os in -mac*) os=`echo $os | sed -e 's|mac|macos|'` ;; + -linux-dietlibc) + os=-linux-dietlibc + ;; + -linux*) + os=`echo $os | sed -e 's|linux|linux-gnu|'` + ;; -sunos5*) os=`echo $os | sed -e 's|sunos5|solaris2|'` ;; diff --git a/libsysio/configure.in b/libsysio/configure.in index 7d24d86..a0e77f3 100644 --- a/libsysio/configure.in +++ b/libsysio/configure.in @@ -1,8 +1,10 @@ -AC_INIT(libsysio, 0.1) +AC_INIT(libsysio, 1.2) AC_CANONICAL_HOST case "$host_os" in + aix*) + ;; linux*) ;; *) @@ -11,9 +13,9 @@ case "$host_os" in esac AM_INIT_AUTOMAKE([subdir-objects]) +AC_PROG_CC AM_PROG_CC_C_O -AC_PROG_CC AC_PROG_RANLIB AC_PROG_MAKE_SET AC_HEADER_STDC @@ -112,6 +114,17 @@ AC_ARG_WITH(defer-init-cwd, [with_defer_init_cwd=no]) AC_SUBST(DEFER_INIT_CWD) +AC_ARG_WITH(tracing, + AC_HELP_STRING([--with-tracing], + [enable tracing support]), + [ case "${withval}" in + yes) TRACING=-DSYSIO_TRACING=1 ;; + no) ;; + *) AC_MSG_ERROR(bad value ${withval} for --with-tracing) ;; + esac], + [TRACING=-DSYSIO_TRACING=1]) +AC_SUBST(TRACING) + AC_ARG_WITH(cplant_yod, AC_HELP_STRING([--with-cplant-yod],[build cplant yod I/O driver]), [ case "${withval}" in @@ -169,6 +182,16 @@ if test x$with_lustre_hack = xyes; then AC_DEFINE(HAVE_LUSTRE_HACK) fi +AC_ARG_WITH(alternate-symbols, + AC_HELP_STRING([--with-alternate-symbols@<:@=@:>@], + [Prepend standard, public, symbols with a unique qualifer]), + [ case "${withval}" in + yes) SYSIO_LABEL_NAMES=-DSYSIO_LABEL_NAMES=sysio_ ;; + no) ;; + *) SYSIO_LABEL_NAMES=-DSYSIO_LABEL_NAMES="${withval}" ;; + esac]) +AC_SUBST(SYSIO_LABEL_NAMES) + # We keep the original values in `$config_*' and never modify them, so we # can write them unchanged into config.make. Everything else uses # $machine, $vendor, and $os, and changes them whenever convenient. @@ -209,6 +232,52 @@ if test "$machine" = rs6000; then machine="powerpc" fi +case "$host_os" in + gnu* | linux*) + AC_DEFINE(_XOPEN_SOURCE, 600) + ;; + aix*) + # ... and always needed... + AC_DEFINE(__USE_LARGEFILE64) + AC_DEFINE(_LARGE_FILES) + AC_DEFINE(_LARGE_FILE_API) + AC_DEFINE(_ALL_SOURCE) + AC_DEFINE(_XOPEN_SOURCE_EXTENDED) + ;; +esac + +AC_MSG_CHECKING(for symlink support) +AC_TRY_COMPILE([ +#include +#include +],[ +#ifndef S_ISLNK +#error +#endif +], + symlink_support="yes", + symlink_support="no" +) +AC_MSG_RESULT($symlink_support) + +if test x$symlink_support = xyes; then + AC_MSG_CHECKING(if readlink returns int) + AC_TRY_COMPILE([ +#include + ],[ + extern int readlink(const char *, char *, size_t); + ], + readlink_returns_int="yes", + readlink_returns_int="no" + ) + AC_MSG_RESULT($readlink_returns_int) + if test x$readlink_returns_int = no; then + AC_DEFINE(HAVE_POSIX_1003_READLINK, + 1, + [readlink returns ssize_t]) + fi +fi + AC_MSG_CHECKING(if readlink returns ssize_t) AC_TRY_COMPILE([ #include diff --git a/libsysio/depcomp b/libsysio/depcomp index aea3d00..edb5d38 100755 --- a/libsysio/depcomp +++ b/libsysio/depcomp @@ -1,7 +1,7 @@ #! /bin/sh # depcomp - compile a program generating dependencies as side-effects -# Copyright 1999, 2000 Free Software Foundation, Inc. +# Copyright 1999, 2000, 2003 Free Software Foundation, Inc. # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -172,19 +172,25 @@ sgi) aix) # The C for AIX Compiler uses -M and outputs the dependencies - # in a .u file. This file always lives in the current directory. - # Also, the AIX compiler puts `$object:' at the start of each line; - # $object doesn't have directory information. - stripped=`echo "$object" | sed -e 's,^.*/,,' -e 's/\(.*\)\..*$/\1/'` + # in a .u file. In older versions, this file always lives in the + # current directory. Also, the AIX compiler puts `$object:' at the + # start of each line; $object doesn't have directory information. + # Version 6 uses the directory in both cases. + stripped=`echo "$object" | sed 's/\(.*\)\..*$/\1/'` tmpdepfile="$stripped.u" - outname="$stripped.o" if test "$libtool" = yes; then "$@" -Wc,-M else "$@" -M fi - stat=$? + + if test -f "$tmpdepfile"; then : + else + stripped=`echo "$stripped" | sed 's,^.*/,,'` + tmpdepfile="$stripped.u" + fi + if test $stat -eq 0; then : else rm -f "$tmpdepfile" @@ -192,6 +198,7 @@ aix) fi if test -f "$tmpdepfile"; then + outname="$stripped.o" # Each line is of the form `foo.o: dependent.h'. # Do two passes, one to just change these to # `$object: dependent.h' and one to simply `dependent.h:'. @@ -278,8 +285,8 @@ tru64) fi if test -f "$tmpdepfile"; then sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile" - # That's a space and a tab in the []. - sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile" + # That's a tab and a space in the []. + sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile" else echo "#dummy" > "$depfile" fi @@ -292,7 +299,7 @@ tru64) dashmstdout) # Important note: in order to support this mode, a compiler *must* - # always write the proprocessed file to stdout, regardless of -o. + # always write the preprocessed file to stdout, regardless of -o. "$@" || exit $? # Remove the call to Libtool. @@ -388,7 +395,7 @@ makedepend) cpp) # Important note: in order to support this mode, a compiler *must* - # always write the proprocessed file to stdout. + # always write the preprocessed file to stdout. "$@" || exit $? # Remove the call to Libtool. @@ -430,7 +437,7 @@ cpp) msvisualcpp) # Important note: in order to support this mode, a compiler *must* - # always write the proprocessed file to stdout, regardless of -o, + # always write the preprocessed file to stdout, regardless of -o, # because we must use -o when running libtool. "$@" || exit $? IFS=" " diff --git a/libsysio/drivers/incore/fs_incore.c b/libsysio/drivers/incore/fs_incore.c index 26b1911..c2ce433 100644 --- a/libsysio/drivers/incore/fs_incore.c +++ b/libsysio/drivers/incore/fs_incore.c @@ -546,29 +546,40 @@ _sysio_incore_fsswop_mount(const char *source, * Source is a specification for the root attributes of this * new file system in the format: * - * ++ + * [+][-] */ ul = strtoul(source, &cp, 0); mode = (mode_t )ul & 07777; - if (*cp != '+' || - (ul == ULONG_MAX && errno == ERANGE) || - (unsigned long)mode != ul || - mode > 07777) - return -EINVAL; - source = cp; - l = strtol(source, &cp, 0); - uid = (uid_t )l; - if (*cp != '+' || - ((l == LONG_MIN || l == LONG_MAX) && errno == ERANGE) || - (long )uid != l) - return -EINVAL; - source = cp; - l = strtol(source, &cp, 0); - gid = (gid_t )l; - if (*cp || - ((l == LONG_MIN || l == LONG_MAX) && errno == ERANGE) || - (long )gid != l) - return -EINVAL; + uid = getuid(); /* default */ + gid = getgid(); /* default */ + if (*cp != '\0') { + /* + * Get user and/or group. + */ + if (*cp != '+' || + (ul == ULONG_MAX && errno == ERANGE) || + (unsigned long)mode != ul || + mode > 07777) + return -EINVAL; + source = cp; + l = strtol(source, &cp, 0); + uid = (uid_t )l; + if (((l == LONG_MIN || l == LONG_MAX) && + errno == ERANGE) || + (long )uid != l) + return -EINVAL; + if (*cp != '+') + return -EINVAL; + source = cp; + l = strtol(source, &cp, 0); + gid = (gid_t )l; + if (((l == LONG_MIN || l == LONG_MAX) && + errno == ERANGE) || + (long )gid != l) + return -EINVAL; + if (*cp != '\0') + return -EINVAL; + } err = 0; @@ -767,18 +778,29 @@ incore_directory_probe(void *data, static struct intnl_dirent * incore_directory_match(struct intnl_dirent *de, - size_t reclen __IS_UNUSED, + size_t reclen, struct lookup_data *ld) { + size_t len; #if defined(BSD) || defined(REDSTORM) if (IFTODT(de->d_type) == DT_WHT) return NULL; #endif - if ( #ifdef _DIRENT_HAVE_D_NAMLEN - ld->name->len == de->d_namlen && + len = de->d_namlen; +#else + { + const char *cp, *end; + + cp = de->d_name; + end = (const char *)de + reclen; + while (cp < end && *cp != '\0') + cp++; + len = cp - de->d_name; + } #endif + if (ld->name->len == len && strncmp(de->d_name, ld->name->name, ld->name->len) == 0) return de; ld->de = de; @@ -932,20 +954,29 @@ incore_directory_position(struct intnl_dirent *de, struct copy_info { void *data; size_t nbytes; + unsigned count; }; /* * Eumeration callback. * * Note: - * On those systems supporting white-out entries, they are returned. On - * systems without, they are not. + * Whiteout entries are never returned. */ static void * incore_directory_enumerate(struct intnl_dirent *de, size_t reclen, struct copy_info *cinfo) { +#ifdef DT_WHT + if (de->d_type == DT_WHT) { + /* + * Keep going but skip the copy. + */ + return NULL; + } +#endif + cinfo->count++; if (reclen > cinfo->nbytes) return de; (void *)memcpy(cinfo->data, de, reclen); @@ -984,6 +1015,7 @@ _sysio_incore_dirop_filldirentries(struct inode *ino, copy_info.data = buf; copy_info.nbytes = nbytes; + copy_info.count = 0; off = (char *)de - (char *)icino->ici_data; de = incore_directory_probe(de, @@ -992,10 +1024,14 @@ _sysio_incore_dirop_filldirentries(struct inode *ino, (probe_ty )incore_directory_enumerate, NULL, ©_info); - nbytes -= copy_info.nbytes; icino->ici_st.st_atime = time(NULL); + if (nbytes == copy_info.nbytes && copy_info.count) + return -EINVAL; + nbytes -= copy_info.nbytes; +#if 0 if (!nbytes) return -EOVERFLOW; +#endif *posp += nbytes; return (ssize_t )nbytes; } diff --git a/libsysio/drivers/native/fs_native.c b/libsysio/drivers/native/fs_native.c index 8f8f91a..75ae531 100644 --- a/libsysio/drivers/native/fs_native.c +++ b/libsysio/drivers/native/fs_native.c @@ -875,9 +875,11 @@ native_inop_setattr(struct pnode *pno, /* * Do the truncate last. It can't be undone. */ - (void )(fd < 0 + err = fd < 0 ? syscall(SYSIO_SYS_truncate, path, stat->st_size) - : syscall(SYSIO_SYS_ftruncate, fd, stat->st_size)); + : syscall(SYSIO_SYS_ftruncate, fd, stat->st_size); + if (err) + err = -errno; } if (!err) goto out; diff --git a/libsysio/drivers/sockets/sockets.c b/libsysio/drivers/sockets/sockets.c index d5d5c3c..d311ae1 100644 --- a/libsysio/drivers/sockets/sockets.c +++ b/libsysio/drivers/sockets/sockets.c @@ -523,7 +523,9 @@ SYSIO_INTERFACE_NAME(bind)(int sockfd, { int err; struct file *fil; +#ifdef SYSIO_SYS_socketcall unsigned long avec[3]; +#endif err = 0; @@ -559,7 +561,9 @@ SYSIO_INTERFACE_NAME(listen)(int s, int backlog) { int err; struct file *fil; +#ifdef SYSIO_SYS_socketcall unsigned long avec[2]; +#endif err = 0; @@ -595,7 +599,9 @@ SYSIO_INTERFACE_NAME(connect)(int sockfd, { int err; struct file *fil; +#ifdef SYSIO_SYS_socketcall unsigned long avec[3]; +#endif err = 0; diff --git a/libsysio/include/namespace.h b/libsysio/include/creds.h similarity index 52% rename from libsysio/include/namespace.h rename to libsysio/include/creds.h index 23c1f78..90305e1 100644 --- a/libsysio/include/namespace.h +++ b/libsysio/include/creds.h @@ -1,4 +1,22 @@ /* + * This Cplant(TM) source code is the property of Sandia National + * Laboratories. + * + * This Cplant(TM) source code is copyrighted by Sandia National + * Laboratories. + * + * The redistribution of this Cplant(TM) source code is subject to the + * terms of the GNU Lesser General Public License + * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) + * + * Cplant(TM) Copyright 1998-2003 Sandia Corporation. + * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive + * license for use of this work by or on behalf of the US Government. + * Export of this program may require a license from the United States + * Government. + */ + +/* * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either @@ -23,8 +41,19 @@ * lee@sandia.gov */ -/* - * Boot time namespace assembly function +#include + +#ifndef _CREDS_H_ +#define _CREDS_H_ + +/* + * Data structure for user credentials */ -extern int run_cmds(char *buf); +struct creds { + uid_t creds_uid; + gid_t *creds_gids; + int creds_ngids; +}; + +#endif diff --git a/libsysio/include/file.h b/libsysio/include/file.h index 161b887..ed5041f 100644 --- a/libsysio/include/file.h +++ b/libsysio/include/file.h @@ -9,7 +9,7 @@ * terms of the GNU Lesser General Public License * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) * - * Cplant(TM) Copyright 1998-2005 Sandia Corporation. + * Cplant(TM) Copyright 1998-2006 Sandia Corporation. * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive * license for use of this work by or on behalf of the US Government. * Export of this program may require a license from the United States @@ -112,6 +112,21 @@ struct file { (fil)->f_flags = (flags); \ } while (0) +/* + * Determine if a file may be read/written. + * + * Given a ptr to an open file table entry and a flag indicating desired + * access return non-zero if the file record indicates that the access is + * permitted or zero, if not. + * + * 'r' for read access check + * 'w' for write access check + */ + +#define F_CHKRW(_fil, _c) \ + (((_c) == 'r' && !((_fil)->f_flags & O_WRONLY)) || \ + ((_c) == 'w' && ((_fil)->f_flags & (O_WRONLY | O_RDWR)))) + struct ioctx; extern struct file *_sysio_fnew(struct inode *ino, int flags); diff --git a/libsysio/include/inode.h b/libsysio/include/inode.h index 7b2b9c6..baedc50 100644 --- a/libsysio/include/inode.h +++ b/libsysio/include/inode.h @@ -9,7 +9,7 @@ * terms of the GNU Lesser General Public License * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) * - * Cplant(TM) Copyright 1998-2003 Sandia Corporation. + * Cplant(TM) Copyright 1998-2006 Sandia Corporation. * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive * license for use of this work by or on behalf of the US Government. * Export of this program may require a license from the United States @@ -323,8 +323,9 @@ struct nameidata { /* * Values for nameidata flags field. */ -#define ND_NOFOLLOW 0x01 /* no follow symlinks */ -#define ND_NEGOK 0x02 /* last missing is ok */ +#define ND_NOFOLLOW 0x01 /* no follow symlinks */ +#define ND_NEGOK 0x02 /* last missing is ok */ +#define ND_NOPERMCHECK 0x04 /* don't check perms */ #ifdef AUTOMOUNT_FILE_NAME #define _ND_INIT_AUTOMOUNT(nd) ((nd)->nd_amcnt = 0) @@ -399,16 +400,10 @@ struct ioctx { } while (0) /* - * Return whether a pnode/inode is on a read-only mount or file system. + * Return whether access to a pnode is read-only. */ -#define IS_RDONLY(pno, ino) \ - ((((struct pnode *)(pno)) && \ - ((((struct pnode *)(pno))->p_mount->mnt_flags & MOUNT_F_RO) || \ - (((struct pnode *)(pno))->p_base->pb_ino && \ - (((struct pnode *)(pno))->p_base->pb_ino->i_fs->fs_flags & \ - FS_F_RO)))) || \ - (((struct inode *)(ino)) && \ - (((struct inode *)(ino))->i_fs->fs_flags & FS_F_RO))) +#define IS_RDONLY(pno) \ + ((pno)->p_mount->mnt_flags & MOUNT_F_RO) extern struct pnode *_sysio_root; @@ -463,7 +458,7 @@ extern int _sysio_path_walk(struct pnode *parent, struct nameidata *nd); #ifdef AUTOMOUNT_FILE_NAME extern void _sysio_next_component(const char *path, struct qstr *name); #endif -extern int _sysio_permitted(struct inode *ino, int amode); +extern int _sysio_permitted(struct pnode *pno, int amode); extern int _sysio_namei(struct pnode *pno, const char *path, unsigned flags, @@ -487,3 +482,5 @@ extern int _sysio_ioctx_done(struct ioctx *ioctx); extern ssize_t _sysio_ioctx_wait(struct ioctx *ioctx); extern void _sysio_ioctx_complete(struct ioctx *ioctx); extern int _sysio_open(struct pnode *pno, int flags, mode_t mode); +extern int _sysio_mkdir(struct pnode *where, mode_t mode); +extern int _sysio_mknod(struct pnode *where, mode_t mode, dev_t dev); diff --git a/libsysio/include/sysio-cmn.h b/libsysio/include/sysio-cmn.h index 3fd283e..2ada2e8 100644 --- a/libsysio/include/sysio-cmn.h +++ b/libsysio/include/sysio-cmn.h @@ -9,7 +9,7 @@ * terms of the GNU Lesser General Public License * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) * - * Cplant(TM) Copyright 1998-2005 Sandia Corporation. + * Cplant(TM) Copyright 1998-2006 Sandia Corporation. * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive * license for use of this work by or on behalf of the US Government. * Export of this program may require a license from the United States @@ -89,7 +89,9 @@ struct intnl_xtvec; struct iovec; - +/* + * Symbol composition. + */ #define _PREPEND_HELPER(p, x) \ p ## x #define PREPEND(p, x) \ @@ -160,7 +162,10 @@ extern void *_sysio_exit_trace_q; extern void *_sysio_register_trace(void *q, void (*)(const char *file, const char *func, - int line)); + int line, + void *data), + void *data, + void (*destructor)(void *data)); extern void _sysio_remove_trace(void *q, void *p); extern void _sysio_run_trace_q(void *q, const char *file, @@ -185,13 +190,13 @@ extern void _sysio_run_trace_q(void *q, do { } while (0) #endif -/* accounting for IO stats read and write char count */ +/* Accounting for IO stats; Read and write character count. */ #if defined(REDSTORM) #define _SYSIO_UPDACCT(w, cc) \ do { \ if ((cc) < 0) \ break; \ - if (!w) \ + if (w) \ _add_iostats(0, (size_t )(cc)); \ else \ _add_iostats((size_t )(cc), 0); \ diff --git a/libsysio/include/sysio.h b/libsysio/include/sysio.h index bae86c2..a8a528b 100644 --- a/libsysio/include/sysio.h +++ b/libsysio/include/sysio.h @@ -49,6 +49,7 @@ #include #include "sysio-cmn.h" +#include "creds.h" #if defined(_DIRENT_H) && _DIRENT_H /* @@ -122,6 +123,9 @@ extern mode_t _sysio_umask; extern int _sysio_init(void); extern void _sysio_shutdown(void); +#ifdef ZERO_SUM_MEMORY +extern void _sysio_access_shutdown(void); +#endif #if 0 struct _sysio_boot_ctl { @@ -175,6 +179,7 @@ extern int SYSIO_INTERFACE_NAME(fcntl64)(int fd, int cmd, ...); extern int SYSIO_INTERFACE_NAME(fstat)(int fd, struct stat *buf); #if _LARGEFILE64_SOURCE extern int SYSIO_INTERFACE_NAME(fstat64)(int fd, struct stat64 *buf); +extern int SYSIO_INTERFACE_NAME(lstat64)(const char *path, struct stat64 *buf); #endif extern int SYSIO_INTERFACE_NAME(fsync)(int fd); extern char *SYSIO_INTERFACE_NAME(getcwd)(char *buf, size_t size); diff --git a/libsysio/misc/init-env.sh b/libsysio/misc/init-env.sh index ea1c0ec..ae1f881 100644 --- a/libsysio/misc/init-env.sh +++ b/libsysio/misc/init-env.sh @@ -15,19 +15,19 @@ if [ "x${SYSIO_AUTOMOUNT}" == "xyes" ]; then # 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=04755,ow=0,gr=0} \ + {mnt, dev=\"incore:0755\",dir=\"/mnt\",fl=2} \ + {creat, ft=dir,nm=\"/mnt/home\",pm=04755} \ {creat, ft=file,nm=\"/mnt/home/.mount\",pm=0600, \ str=\"native:/home\"} \ " fi export SYSIO_NAMESPACE="\ {mnt, dev=\"native:/\",dir=/,fl=${_root_flags:-0}} \ - {mnt, dev=\"incore:0755+0+0\",dir=\"/dev\"} \ + {mnt, dev=\"incore:0755\",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=dir,nm=\"/dev/fd\",pm=0755} \ {creat, ft=chr,nm=\"/dev/fd/0\",pm=0400,mm=0+0} \ {open, nm=\"/dev/fd/0\",fd=0,m=0} \ {creat, ft=chr,nm=\"/dev/fd/1\",pm=0200,mm=0+1} \ diff --git a/libsysio/missing b/libsysio/missing index 6a37006..fc54c64 100755 --- a/libsysio/missing +++ b/libsysio/missing @@ -1,6 +1,6 @@ #! /bin/sh # Common stub for a few missing GNU programs while installing. -# Copyright (C) 1996, 1997, 1999, 2000, 2002 Free Software Foundation, Inc. +# Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003 Free Software Foundation, Inc. # Originally by Fran,cois Pinard , 1996. # This program is free software; you can redistribute it and/or modify @@ -165,7 +165,7 @@ WARNING: \`$1' is missing on your system. You should only need it if WARNING: \`$1' is needed, and you do not seem to have it handy on your system. You might have modified some files without having the proper tools for further handling them. - You can get \`$1Help2man' as part of \`Autoconf' from any GNU + You can get \`$1' as part of \`Autoconf' from any GNU archive site." file=`echo "$*" | sed -n 's/.*--output[ =]*\([^ ]*\).*/\1/p'` @@ -326,7 +326,7 @@ WARNING: I can't seem to be able to run \`tar' with the given arguments. WARNING: \`$1' is needed, and you do not seem to have it handy on your system. You might have modified some files without having the proper tools for further handling them. Check the \`README' file, - it often tells you about the needed prerequirements for installing + it often tells you about the needed prerequisites for installing this package. You may also peek at any GNU archive site, in case some other package would contain this missing \`$1' program." exit 1 diff --git a/libsysio/src/access.c b/libsysio/src/access.c index 6b92f64..80e8fcd 100644 --- a/libsysio/src/access.c +++ b/libsysio/src/access.c @@ -9,7 +9,7 @@ * terms of the GNU Lesser General Public License * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) * - * Cplant(TM) Copyright 1998-2003 Sandia Corporation. + * Cplant(TM) Copyright 1998-2006 Sandia Corporation. * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive * license for use of this work by or on behalf of the US Government. * Export of this program may require a license from the United States @@ -50,20 +50,31 @@ #include #include "sysio.h" +#include "mount.h" +#include "fs.h" #include "inode.h" #include "sysio-symbols.h" /* + * Use a persistent buffer for gids. No, not a cache. We just want to + * avoid calling malloc over, and over, and... + */ +static gid_t *gids = NULL; +static int gidslen = 0; + +/* * Check given access type on given inode. */ -static int -_sysio_check_permission(struct inode *ino, - uid_t uid, gid_t gid, - gid_t gids[], size_t ngids, - int amode) +int +_sysio_check_permission(struct pnode *pno, struct creds *crp, int amode) { mode_t mask; + struct inode *ino; + int err; struct intnl_stat *stat; + gid_t *gids; + int ngids; + int group_matched; /* * Check amode. @@ -82,76 +93,166 @@ _sysio_check_permission(struct inode *ino, if (amode & X_OK) mask |= S_IXUSR; + ino = pno->p_base->pb_ino; + assert(ino); + + err = -EACCES; /* assume error */ stat = &ino->i_stbuf; - if (stat->st_uid == uid && (stat->st_mode & mask) == mask) - return 0; + do { + /* + * Owner? + */ + if (stat->st_uid == crp->creds_uid) { + if ((stat->st_mode & mask) == mask) + err = 0; + break; + } - mask >>= 3; - if (stat->st_gid == gid && (stat->st_mode & mask) == mask) - return 0; + /* + * Group? + */ + mask >>= 3; + group_matched = 0; + gids = crp->creds_gids; + ngids = crp->creds_ngids; + while (ngids) { + ngids--; + if (stat->st_gid == *gids++) { + group_matched = 1; + if ((stat->st_mode & mask) == mask) + err = 0; + } + } + if (group_matched) + break; - while (ngids) { - ngids--; - if (stat->st_gid == *gids++ && (stat->st_mode & mask) == mask) - return 0; - } + /* + * Other? + */ + mask >>= 3; + if ((stat->st_mode & mask) == mask) + err = 0; + } while (0); + if (err) + return err; - mask >>= 3; - if ((stat->st_mode & mask) == mask) - return 0; + /* + * Check for RO access to the file due to mount + * options. + */ + if (amode & W_OK && IS_RDONLY(pno)) + return -EROFS; - return -EACCES; + return 0; } /* - * Determine if a given access is permitted to a give file. + * Cache groups. */ -int -_sysio_permitted(struct inode *ino, int amode) +static int +_sysio_ldgroups(gid_t gid0, gid_t **gidsp, int *gidslenp) { - int err; - gid_t *gids; - int n; + int n, i; void *p; - err = 0; - gids = NULL; + n = *gidslenp; + if (n < 8) { + *gidsp = NULL; + n = 8; + } for (;;) { - n = getgroups(0, NULL); - if (!n) - break; - p = realloc(gids, n * sizeof(gid_t)); - if (!p && gids) { - err = -ENOMEM; - break; + /* + * This is far more expensive than I would like. Each time + * called it has to go to some length to acquire the + * current uid and groups membership. We can't just cache + * the result, either. The caller could have altered something + * asynchronously. Wish we had easy access to this info. + */ + if (n > *gidslenp) { + p = realloc(*gidsp, (size_t )n * sizeof(gid_t)); + if (!p) + return -errno; + *gidsp = p; + *gidslenp = n; } - gids = p; - err = getgroups(n, gids); - if (err < 0) { - if (errno == EINVAL) - continue; - err = -errno; - break; + (*gidsp)[0] = gid0; + i = getgroups(n - 1, *gidsp + 1); + if (i < 0) { + if (errno != EINVAL) + return -errno; + if (INT_MAX / 2 < n) + return -EINVAL; + n *= 2; + continue; } - err = - _sysio_check_permission(ino, - geteuid(), getegid(), - gids, (size_t )n, - amode); break; } - if (!gids) + return i; +} + +/* + * Get current credentials. + */ +static int +_sysio_ldcreds(uid_t uid, gid_t gid, struct creds *crp) +{ + int n; + + n = _sysio_ldgroups(gid, &gids, &gidslen); + if (n < 0) + return n; + crp->creds_uid = uid; + crp->creds_gids = gids; + crp->creds_ngids = n; + + return 0; +} + +static int +_sysio_getcreds(struct creds *crp) +{ + + return _sysio_ldcreds(getuid(), getgid(), crp); +} + +/* + * Determine if a given access is permitted to a given file. + */ +int +_sysio_permitted(struct pnode *pno, int amode) +{ + struct creds cr; + int err; + + err = _sysio_ldcreds(geteuid(), getegid(), &cr); + if (err < 0) return err; - free(gids); + err = _sysio_check_permission(pno, &cr, amode); return err; } +#ifdef ZERO_SUM_MEMORY +/* + * Clean up persistent resource on shutdown. + */ +void +_sysio_access_shutdown() +{ + + if (gids) + free(gids); + gids = NULL; + gidslen = 0; +} +#endif + int SYSIO_INTERFACE_NAME(access)(const char *path, int amode) { struct intent intent; int err; struct pnode *pno; + struct creds cr; SYSIO_INTERFACE_DISPLAY_BLOCK; @@ -161,11 +262,12 @@ SYSIO_INTERFACE_NAME(access)(const char *path, int amode) err = _sysio_namei(_sysio_cwd, path, 0, &intent, &pno); if (err) SYSIO_INTERFACE_RETURN(-1, err); + err = _sysio_ldcreds(geteuid(), getegid(), &cr); + if (err < 0) + goto out; err = - _sysio_check_permission(pno->p_base->pb_ino, - getuid(), getgid(), - NULL, 0, - amode); + _sysio_check_permission(pno, &cr, amode); +out: P_RELE(pno); SYSIO_INTERFACE_RETURN(err ? -1 : 0, err); } diff --git a/libsysio/src/chdir.c b/libsysio/src/chdir.c index c943d8f..f48c0fe 100644 --- a/libsysio/src/chdir.c +++ b/libsysio/src/chdir.c @@ -9,7 +9,7 @@ * terms of the GNU Lesser General Public License * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) * - * Cplant(TM) Copyright 1998-2003 Sandia Corporation. + * Cplant(TM) Copyright 1998-2006 Sandia Corporation. * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive * license for use of this work by or on behalf of the US Government. * Export of this program may require a license from the United States @@ -101,10 +101,8 @@ _sysio_p_chdir(struct pnode *pno) return err; if (!(pno->p_base->pb_ino && S_ISDIR(pno->p_base->pb_ino->i_stbuf.st_mode))) - err = -ENOTDIR; - else - err = _sysio_permitted(pno->p_base->pb_ino, X_OK); - if (err) + return -ENOTDIR; + if ((err = _sysio_permitted(pno, X_OK)) != 0) return err; /* diff --git a/libsysio/src/fcntl.c b/libsysio/src/fcntl.c index 22e0bcd..703e09d 100644 --- a/libsysio/src/fcntl.c +++ b/libsysio/src/fcntl.c @@ -42,11 +42,12 @@ */ #include -#include #include #include #include #include +#include +#include #include #include diff --git a/libsysio/src/getdirentries.c b/libsysio/src/getdirentries.c index aa25cd8..70a1a28 100644 --- a/libsysio/src/getdirentries.c +++ b/libsysio/src/getdirentries.c @@ -17,28 +17,6 @@ */ /* - * ############################################################################# - * # - * # This Cplant(TM) source code is the property of Sandia National - * # Laboratories. - * # - * # This Cplant(TM) source code is copyrighted by Sandia National - * # Laboratories. - * # - * # The redistribution of this Cplant(TM) source code is subject to the - * # terms of the GNU Lesser General Public License - * # (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) - * # - * # Cplant(TM) Copyright 1998-2004 Sandia Corporation. - * # Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive - * # license for use of this work by or on behalf of the US Government. - * # Export of this program may require a license from the United States - * # Government. - * # - * ############################################################################# - */ - -/* * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either @@ -120,8 +98,9 @@ PREPEND(_, SYSIO_INTERFACE_NAME(getdirentries64))(int fd, SYSIO_INTERFACE_ENTER; fil = _sysio_fd_find(fd); - if (!(fil && fil->f_ino)) - return -EBADF; + if (!(fil && fil->f_ino)) { + SYSIO_INTERFACE_RETURN(-1, -EBADF); + } cc = filldirents(fil, buf, nbytes, basep); SYSIO_INTERFACE_RETURN(cc < 0 ? -1 : cc, cc < 0 ? (int )cc : 0); @@ -190,8 +169,9 @@ SYSIO_INTERFACE_NAME(getdirentries)(int fd, SYSIO_INTERFACE_ENTER; fil = _sysio_fd_find(fd); - if (!(fil && fil->f_ino)) - return -EBADF; + if (!(fil && fil->f_ino)) { + SYSIO_INTERFACE_RETURN(-1, -EBADF); + } count = cc = filldirents(fil, buf, nbytes, &b); d64p = (void *)buf; diff --git a/libsysio/src/init.c b/libsysio/src/init.c index 3441d81..c82d601 100644 --- a/libsysio/src/init.c +++ b/libsysio/src/init.c @@ -9,7 +9,7 @@ * terms of the GNU Lesser General Public License * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) * - * Cplant(TM) Copyright 1998-2005 Sandia Corporation. + * Cplant(TM) Copyright 1998-2006 Sandia Corporation. * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive * license for use of this work by or on behalf of the US Government. * Export of this program may require a license from the United States @@ -41,13 +41,15 @@ * lee@sandia.gov */ +#ifdef __linux__ #define _BSD_SOURCE +#endif #if SYSIO_TRACING #include #endif #include -#if SYSIO_TRACING +#ifdef _BSD_SOURCE #include #endif #include @@ -85,16 +87,23 @@ * Tracing callback record. */ struct trace_callback { - TAILQ_ENTRY(trace_callback) links; - void (*f)(const char *file, const char *func, int line); + TAILQ_ENTRY(trace_callback) links; /* trace list links */ + void (*f)(const char *file, /* callback function */ + const char *func, + int line, + void *data); + void *data; /* callback data */ + void (*destructor)(void *data); /* data destructor */ }; /* * Initialize a tracing callback record. */ -#define TCB_INIT(__tcb, __f) \ +#define TCB_INIT(__tcb, __f, __d, __destroy) \ do { \ (__tcb)->f = (__f); \ + (__tcb)->data = (__d); \ + (__tcb)->destructor = (__destroy); \ } while (0); /* @@ -131,6 +140,12 @@ void *_sysio_exit_trace_q = &_sysio_exit_trace_head; * In sysio_init we'll allow simple comments, strings outside {} * delimited by COMMENT_INTRO, and '\n' or '\0' */ +#define COMMENT_INTRO '#' + +/* + * In sysio_init we'll allow simple comments, strings outside {} + * delimited by COMMENT_INTRO, and '\n' or '\0' + */ #define COMMENT_INTRO '#' /* @@ -203,6 +218,7 @@ _sysio_shutdown() _sysio_fd_shutdown(); _sysio_i_shutdown(); _sysio_fssw_shutdown(); + _sysio_access_shutdown(); #if SYSIO_TRACING { struct trace_callback *tcb; @@ -210,14 +226,10 @@ _sysio_shutdown() /* * Empty the trace queues and free the entries. */ - while ((tcb = _sysio_entry_trace_head.tqh_first) != NULL) { - TAILQ_REMOVE(&_sysio_entry_trace_head, tcb, links); - free(tcb); - } - while ((tcb = _sysio_exit_trace_head.tqh_first) != NULL) { - TAILQ_REMOVE(&_sysio_exit_trace_head, tcb, links); - free(tcb); - } + while ((tcb = _sysio_entry_trace_head.tqh_first) != NULL) + _sysio_remove_trace(&_sysio_entry_trace_head, tcb); + while ((tcb = _sysio_exit_trace_head.tqh_first) != NULL) + _sysio_remove_trace(&_sysio_exit_trace_head, tcb); } #endif #endif @@ -316,14 +328,17 @@ void * _sysio_register_trace(void *q, void (*f)(const char *file, const char *func, - int line)) + int line, + void *data), + void *data, + void (*destructor)(void *data)) { struct trace_callback *tcb; tcb = malloc(sizeof(struct trace_callback)); if (!tcb) return NULL; - TCB_INIT(tcb, f); + TCB_INIT(tcb, f, data, destructor); TAILQ_INSERT_TAIL((struct trace_q *)q, tcb, links); return tcb; } @@ -334,9 +349,14 @@ _sysio_register_trace(void *q, void _sysio_remove_trace(void *q, void *p) { + struct trace_callback *tcb; - TAILQ_REMOVE((struct trace_q *)q, (struct trace_callback *)p, links); - free(p); + tcb = (struct trace_callback *)p; + + if (tcb->destructor) + (*tcb->destructor)(tcb->data); + TAILQ_REMOVE((struct trace_q *)q, tcb, links); + free(tcb); } void @@ -352,7 +372,7 @@ _sysio_run_trace_q(void *q, tcb = ((struct trace_q *)q)->tqh_first; while (tcb) { - (*tcb->f)(file, func, line); + (*tcb->f)(file, func, line, tcb->data); tcb = tcb->links.tqe_next; } } @@ -360,7 +380,8 @@ _sysio_run_trace_q(void *q, static void _sysio_trace_entry(const char *file __IS_UNUSED, const char *func, - int line __IS_UNUSED) + int line __IS_UNUSED, + void *data __IS_UNUSED) { _sysio_cprintf("+ENTER+ %s\n", func); @@ -369,7 +390,8 @@ _sysio_trace_entry(const char *file __IS_UNUSED, static void _sysio_trace_exit(const char *file __IS_UNUSED, const char *func, - int line __IS_UNUSED) + int line __IS_UNUSED, + void *data __IS_UNUSED) { _sysio_cprintf("+EXIT+ %s\n", func); @@ -526,6 +548,15 @@ do_creat(char *args) struct intent intent; dev_t dev; int err; + enum { + CREATE_DIR = 1, + CREATE_CHR = 2, + CREATE_BLK = 3, + CREATE_FILE = 4 + } op; + int intent_mode; + struct inode *ino; + int i; len = strlen(args); if (_sysio_get_args(args, v) - args != (ssize_t )len || @@ -558,69 +589,66 @@ do_creat(char *args) if (!(dir = _sysio_cwd) && !(dir = _sysio_root)) return -ENOENT; + + /* + * Init, get the operation, setup the intent. + */ err = 0; mode = perms; + op = 0; if (strcmp(v[0].ovi_value, "dir") == 0) { - INTENT_INIT(&intent, INT_CREAT, &mode, 0); - err = - _sysio_namei(dir, v[1].ovi_value, ND_NEGOK, &intent, &pno); - if (err) - return err; - if (pno->p_base->pb_ino) - err = -EEXIST; - else if (IS_RDONLY(pno->p_parent, - pno->p_parent->p_base->pb_ino)) - err = -EROFS; - else { - struct inode *ino; - - ino = pno->p_parent->p_base->pb_ino; - err = (*ino->i_ops.inop_mkdir)(pno, mode); - } - P_RELE(pno); + op = CREATE_DIR; + INTENT_INIT(&intent, INT_CREAT, &mode, NULL); } else if (strcmp(v[0].ovi_value, "chr") == 0) { - if (!(v[5].ovi_value && parse_mm(v[5].ovi_value, &dev) == 0)) - return -EINVAL; + op = CREATE_CHR; mode |= S_IFCHR; - INTENT_INIT(&intent, INT_CREAT, &mode, 0); - err = - _sysio_namei(dir, v[1].ovi_value, ND_NEGOK, &intent, &pno); - if (err) - return err; - if (pno->p_base->pb_ino) - err = -EEXIST; - else if (IS_RDONLY(pno->p_parent, - pno->p_parent->p_base->pb_ino)) - err = -EROFS; - else { - struct inode *ino; - - ino = pno->p_parent->p_base->pb_ino; - err = (*ino->i_ops.inop_mknod)(pno, mode, dev); - } - P_RELE(pno); + INTENT_INIT(&intent, INT_CREAT, &mode, NULL); + if (!(v[5].ovi_value && parse_mm(v[5].ovi_value, &dev) == 0)) + err = -EINVAL; } else if (strcmp(v[0].ovi_value, "blk") == 0) { - /* - * We don't support block special files yet. - */ - return -EINVAL; + op = CREATE_BLK; + mode |= S_IFBLK; + INTENT_INIT(&intent, INT_CREAT, &mode, NULL); + if (!(v[5].ovi_value && parse_mm(v[5].ovi_value, &dev) == 0)) + err = -EINVAL; } else if (strcmp(v[0].ovi_value, "file") == 0) { - int i; - struct inode *ino; + op = CREATE_FILE; + intent_mode = O_CREAT|O_EXCL; + INTENT_INIT(&intent, INT_CREAT, &mode, &intent_mode); + } else + err = -EINVAL; + if (err) + return err; - i = O_CREAT|O_EXCL; - INTENT_INIT(&intent, INT_CREAT, &mode, &i); - err = - _sysio_namei(dir, v[1].ovi_value, ND_NEGOK, &intent, &pno); - if (err) - return err; + /* + * Lookup the given path. + */ + err = + _sysio_namei(dir, + v[1].ovi_value, + ND_NEGOK|ND_NOPERMCHECK, + &intent, + &pno); + if (err) + return err; + + /* + * Perform. + */ + switch (op) { + case CREATE_DIR: + err = _sysio_mkdir(pno, mode); + break; + case CREATE_CHR: + case CREATE_BLK: + err = _sysio_mknod(pno, mode, dev); + break; + case CREATE_FILE: err = _sysio_open(pno, O_CREAT|O_EXCL, mode); - if (err) { - P_RELE(pno); - return err; - } + if (err) + break; ino = pno->p_base->pb_ino; - if (!err && v[6].ovi_value) { + if (v[6].ovi_value) { struct iovec iovec; struct intnl_xtvec xtvec; struct ioctx io_context; @@ -656,10 +684,12 @@ do_creat(char *args) i = (*ino->i_ops.inop_close)(ino); if (!err) err = i; - P_RELE(pno); - } else - err = -EINVAL; + break; + default: + abort(); + } + P_RELE(pno); return err; } @@ -744,8 +774,13 @@ do_cd(char *args) if (_sysio_get_args(args, v) - args != (ssize_t )len || !v[0].ovi_value) return -EINVAL; - if (!(dir = _sysio_cwd) && !(dir = _sysio_root)) + if (!(dir = _sysio_cwd) && !(dir = _sysio_root)) { + /* + * We have no namespace yet. They really need to give us + * something to work with. + */ return -ENOENT; + } err = _sysio_namei(dir, v[0].ovi_value, 0, NULL, &pno); if (err) return err; @@ -791,7 +826,7 @@ do_chmd(char *args) if (!(dir = _sysio_cwd) && !(dir = _sysio_root)) return -ENOENT; - err = _sysio_namei(dir, v[0].ovi_value, 0, NULL, &pno); + err = _sysio_namei(dir, v[0].ovi_value, ND_NOPERMCHECK, NULL, &pno); if (err) return err; err = _sysio_setattr(pno, pno->p_base->pb_ino, SETATTR_MODE, &stbuf); @@ -838,7 +873,7 @@ do_open(char *args) return -ENOENT; INTENT_INIT(&intent, INT_OPEN, &m, NULL); pno = NULL; - err = _sysio_namei(dir, v[0].ovi_value, 0, &intent, &pno); + err = _sysio_namei(dir, v[0].ovi_value, ND_NOPERMCHECK, &intent, &pno); if (err) return err; fil = NULL; @@ -917,13 +952,17 @@ _sysio_boot_tracing(const char *arg) if (entcb == NULL) entcb = _sysio_register_trace(_sysio_entry_trace_q, - _sysio_trace_entry); + _sysio_trace_entry, + NULL, + NULL); if (entcb == NULL) return -errno; if (exitcb == NULL) exitcb = _sysio_register_trace(_sysio_exit_trace_q, - _sysio_trace_exit); + _sysio_trace_exit, + NULL, + NULL); if (exitcb == NULL) return -errno; } else { @@ -963,13 +1002,16 @@ _sysio_boot_namespace(const char *arg) */ while ((c = *arg) != '\0' && strchr(IGNORE_WHITE, c)) arg++; - if (COMMENT_INTRO == c) { - while (*arg && (*arg != '\n')) { - ++arg; - } + if (COMMENT_INTRO == c) { + /* + * Discard comment. + */ + while (*arg && (*arg != '\n')) { + ++arg; + } + continue; + } - continue; - } if (c == '\0') break; if (c != '{') { diff --git a/libsysio/src/inode.c b/libsysio/src/inode.c index 3b4a1a4..8ab6236 100644 --- a/libsysio/src/inode.c +++ b/libsysio/src/inode.c @@ -9,7 +9,7 @@ * terms of the GNU Lesser General Public License * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) * - * Cplant(TM) Copyright 1998-2003 Sandia Corporation. + * Cplant(TM) Copyright 1998-2006 Sandia Corporation. * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive * license for use of this work by or on behalf of the US Government. * Export of this program may require a license from the United States @@ -869,15 +869,23 @@ _sysio_setattr(struct pnode *pno, unsigned mask, struct intnl_stat *stbuf) { - /* It is possible that pno is null (for ftruncate call). */ + /* + * It is possible that pno is null (for ftruncate call). + */ - if (pno) { - assert(!(pno->p_base->pb_ino && ino) || pno->p_base->pb_ino == ino); - if (IS_RDONLY(pno, ino)) - return -EROFS; - } - if (!ino && pno->p_base->pb_ino) + if (pno) + assert(!ino || pno->p_base->pb_ino == ino); + if (!ino) ino = pno->p_base->pb_ino; + assert(ino); + + if (pno && IS_RDONLY(pno)) + return -EROFS; + + /* + * Determining permission to change the attributes is + * difficult, at best. Just try it. + */ return (*ino->i_ops.inop_setattr)(pno, ino, mask, stbuf); } diff --git a/libsysio/src/mkdir.c b/libsysio/src/mkdir.c index ee59348..a23e014 100644 --- a/libsysio/src/mkdir.c +++ b/libsysio/src/mkdir.c @@ -9,7 +9,7 @@ * terms of the GNU Lesser General Public License * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) * - * Cplant(TM) Copyright 1998-2003 Sandia Corporation. + * Cplant(TM) Copyright 1998-2006 Sandia Corporation. * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive * license for use of this work by or on behalf of the US Government. * Export of this program may require a license from the United States @@ -41,11 +41,11 @@ * lee@sandia.gov */ -#include #include #include #include #include +#include #include #include "sysio.h" @@ -55,6 +55,24 @@ #include "sysio-symbols.h" int +_sysio_mkdir(struct pnode *pno, mode_t mode) +{ + int err; + struct inode *parenti; + + if (pno->p_base->pb_ino) + return -EEXIST; + + err = _sysio_permitted(pno->p_parent, W_OK); + if (err) + return err; + + parenti = pno->p_parent->p_base->pb_ino; + assert(parenti); + return (*parenti->i_ops.inop_mkdir)(pno, mode); +} + +int SYSIO_INTERFACE_NAME(mkdir)(const char *path, mode_t mode) { int err; @@ -67,19 +85,9 @@ SYSIO_INTERFACE_NAME(mkdir)(const char *path, mode_t mode) err = _sysio_namei(_sysio_cwd, path, ND_NEGOK, &intent, &pno); if (err) goto out; - if (pno->p_base->pb_ino) { - err = -EEXIST; - goto error; - } - if (IS_RDONLY(pno, pno->p_base->pb_ino)) { - err = -EROFS; - goto error; - } - mode |= S_IFDIR; - mode &= ~(_sysio_umask & 0777); /* apply umask */ - err = (*pno->p_parent->p_base->pb_ino->i_ops.inop_mkdir)(pno, mode); -error: + mode &= ~(_sysio_umask & 0777); /* apply umask */ + err = _sysio_mkdir(pno, mode); P_RELE(pno); out: SYSIO_INTERFACE_RETURN(err ? -1 : 0, err); diff --git a/libsysio/src/mknod.c b/libsysio/src/mknod.c index 35ca0f9..51e5f7f 100644 --- a/libsysio/src/mknod.c +++ b/libsysio/src/mknod.c @@ -41,10 +41,6 @@ * lee@sandia.gov */ -#if defined(__linux__) -#define _BSD_SOURCE -#endif - #include #include #include @@ -62,6 +58,30 @@ #undef mknod #undef __xmknod +/* + * Internal routine to make a device node. + */ +int +_sysio_mknod(struct pnode *pno, mode_t mode, dev_t dev) +{ + + if (pno->p_base->pb_ino) + return -EEXIST; + + /* + * Support only regular, character-special and fifos right now. + * (mode & S_IFMT) == 0 is the same as S_IFREG. + */ + if (!(S_ISREG(mode) || S_ISCHR(mode) || S_ISFIFO(mode))) + return -EINVAL; + + if (IS_RDONLY(pno)) + return -EROFS; + return (*pno->p_parent->p_base->pb_ino->i_ops.inop_mknod)(pno, + mode, + dev); +} + int PREPEND(__, SYSIO_INTERFACE_NAME(xmknod))(int __ver, const char *path, @@ -79,33 +99,17 @@ PREPEND(__, SYSIO_INTERFACE_NAME(xmknod))(int __ver, goto out; } - /* - * Support only regular, character-special and fifos right now. - * (mode & S_IFMT) == 0 is the same as S_IFREG. - */ - if ((mode & S_IFMT) && - !(S_ISREG(mode) || S_ISCHR(mode) || S_ISFIFO(mode))) { - err = -EINVAL; - goto out; - } - - mode &= ~(_sysio_umask & 0777); /* apply umask */ + mode &= ~(_sysio_umask & 0777); /* apply umask */ INTENT_INIT(&intent, INT_CREAT, &mode, NULL); err = _sysio_namei(_sysio_cwd, path, ND_NEGOK, &intent, &pno); if (err) goto out; - if (pno->p_base->pb_ino) { - err = -EEXIST; - goto error; - } - if (IS_RDONLY(pno, pno->p_base->pb_ino)) { - err = -EROFS; + err = _sysio_permitted(pno->p_parent, W_OK); + if (err) goto error; - } - err = - (*pno->p_parent->p_base->pb_ino->i_ops.inop_mknod)(pno, mode, *dev); + err = _sysio_mknod(pno, mode, *dev); error: P_RELE(pno); out: diff --git a/libsysio/src/namei.c b/libsysio/src/namei.c index f58713c..e339f04 100644 --- a/libsysio/src/namei.c +++ b/libsysio/src/namei.c @@ -9,7 +9,7 @@ * terms of the GNU Lesser General Public License * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) * - * Cplant(TM) Copyright 1998-2003 Sandia Corporation. + * Cplant(TM) Copyright 1998-2006 Sandia Corporation. * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive * license for use of this work by or on behalf of the US Government. * Export of this program may require a license from the United States @@ -41,10 +41,6 @@ * lee@sandia.gov */ -#if defined(AUTOMOUNT_FILE_NAME) && defined(__linux__) -#define _BSD_SOURCE -#endif - #include #include #include @@ -88,7 +84,8 @@ lookup(struct pnode *parent, struct qstr *name, struct pnode **pnop, struct intent *intnt, - const char *path) + const char *path, + int check_permissions) { int err; struct pnode *pno; @@ -96,9 +93,15 @@ lookup(struct pnode *parent, if (!parent->p_base->pb_ino) return -ENOTDIR; - err = _sysio_permitted(parent->p_base->pb_ino, X_OK); - if (err) - return err; + /* + * Sometimes we don't want to check permissions. At initialization + * time, for instance. + */ + if (check_permissions) { + err = _sysio_permitted(parent, X_OK); + if (err) + return err; + } /* * Short-circuit `.' and `..'; We don't cache those. @@ -151,6 +154,7 @@ lookup(struct pnode *parent, * ND_NOFOLLOW symbolic links are not followed * ND_NEGOK if terminal/leaf does not exist, return * path node (alias) anyway. + * ND_NOPERMCHECK do not check permissions */ int _sysio_path_walk(struct pnode *parent, struct nameidata *nd) @@ -297,7 +301,8 @@ _sysio_path_walk(struct pnode *parent, struct nameidata *nd) &_sysio_mount_file_name, &pno, NULL, - NULL); + NULL, + 1); if (pno) P_RELE(pno); if (!err && _sysio_automount(pno) == 0) { @@ -410,7 +415,8 @@ _sysio_path_walk(struct pnode *parent, struct nameidata *nd) (path || !next.len) ? nd->nd_intent : NULL, - (path && next.len) ? path : NULL); + (path && next.len) ? path : NULL, + !(nd->nd_flags & ND_NOPERMCHECK)); if (err) { if (err == -ENOENT && !next.len && diff --git a/libsysio/src/open.c b/libsysio/src/open.c index 2542d94..86426da 100644 --- a/libsysio/src/open.c +++ b/libsysio/src/open.c @@ -9,7 +9,7 @@ * terms of the GNU Lesser General Public License * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) * - * Cplant(TM) Copyright 1998-2003 Sandia Corporation. + * Cplant(TM) Copyright 1998-2006 Sandia Corporation. * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive * license for use of this work by or on behalf of the US Government. * Export of this program may require a license from the United States @@ -79,7 +79,7 @@ _sysio_open(struct pnode *pno, int flags, mode_t mode) int err; struct inode *ino; - ro = IS_RDONLY(pno, pno->p_base->pb_ino); + ro = IS_RDONLY(pno); w = flags & (O_WRONLY|O_RDWR); if (w == (O_WRONLY|O_RDWR)) { /* @@ -103,10 +103,7 @@ _sysio_open(struct pnode *pno, int flags, mode_t mode) if (!err) { ino = parent->p_base->pb_ino; assert(ino); - err = - !IS_RDONLY(parent, ino) - ? (*ino->i_ops.inop_open)(pno, flags, mode) - : -EROFS; + err = (*ino->i_ops.inop_open)(pno, flags, mode); } } else if ((flags & (O_CREAT|O_EXCL)) == (O_CREAT|O_EXCL)) err = -EEXIST; diff --git a/libsysio/src/readlink.c b/libsysio/src/readlink.c index 2497dfd..c8e7436 100644 --- a/libsysio/src/readlink.c +++ b/libsysio/src/readlink.c @@ -41,9 +41,6 @@ * lee@sandia.gov */ -#if defined(__linux__) -#define _BSD_SOURCE -#endif #include #include #include diff --git a/libsysio/src/rename.c b/libsysio/src/rename.c index 269516b8..c0f4967 100644 --- a/libsysio/src/rename.c +++ b/libsysio/src/rename.c @@ -127,7 +127,7 @@ SYSIO_INTERFACE_NAME(rename)(const char *oldpath, const char *newpath) * If old == new, we're done. */ if (old->p_base->pb_ino == new->p_base->pb_ino) - goto out; + goto short_out; if (new->p_base->pb_ino) { /* @@ -175,8 +175,10 @@ SYSIO_INTERFACE_NAME(rename)(const char *oldpath, const char *newpath) if (new->p_base->pb_ino) I_GONE(new->p_base->pb_ino); new->p_base->pb_ino = old->p_base->pb_ino; + old->p_base->pb_ino = NULL; I_REF(new->p_base->pb_ino); +short_out: error1: P_RELE(new); error2: @@ -184,7 +186,6 @@ error2: error3: if (err) goto out; - _sysio_p_gone(old); /* kill it! */ out: SYSIO_INTERFACE_RETURN(err ? -1 : 0, err); } diff --git a/libsysio/src/rmdir.c b/libsysio/src/rmdir.c index 36df40c..bf13fa2 100644 --- a/libsysio/src/rmdir.c +++ b/libsysio/src/rmdir.c @@ -9,7 +9,7 @@ * terms of the GNU Lesser General Public License * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) * - * Cplant(TM) Copyright 1998-2003 Sandia Corporation. + * Cplant(TM) Copyright 1998-2006 Sandia Corporation. * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive * license for use of this work by or on behalf of the US Government. * Export of this program may require a license from the United States @@ -72,10 +72,9 @@ SYSIO_INTERFACE_NAME(rmdir)(const char *path) err = -ENOTDIR; goto error; } - if (IS_RDONLY(pno, pno->p_base->pb_ino)) { - err = -EROFS; + err = _sysio_permitted(pno->p_parent, W_OK); + if (err) goto error; - } if (pno->p_ref > 1) { err = -EBUSY; goto error; @@ -85,7 +84,7 @@ SYSIO_INTERFACE_NAME(rmdir)(const char *path) * driver is implemented using differentiated inode operations based * on file type, such as incore does. */ - err = pno->p_parent->p_base->pb_ino->i_ops.inop_rmdir(pno); + err = (*pno->p_parent->p_base->pb_ino->i_ops.inop_rmdir)(pno); if (err) goto error; /* diff --git a/libsysio/src/rw.c b/libsysio/src/rw.c index e482379..328f076 100644 --- a/libsysio/src/rw.c +++ b/libsysio/src/rw.c @@ -105,9 +105,7 @@ _sysio_iiox(int (*f)(struct inode *, struct ioctx *), /* * Check that it was opened with flags supporting the operation. */ - if (!(wr - ? (fil->f_flags & (O_RDWR | O_WRONLY)) - : !(fil->f_flags & O_WRONLY))) + if (!F_CHKRW(fil, wr ? 'w' : 'r')) return -EBADF; ino = fil->f_ino; diff --git a/libsysio/src/symlink.c b/libsysio/src/symlink.c index ce988b0..2a31e37 100644 --- a/libsysio/src/symlink.c +++ b/libsysio/src/symlink.c @@ -9,7 +9,7 @@ * terms of the GNU Lesser General Public License * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) * - * Cplant(TM) Copyright 1998-2003 Sandia Corporation. + * Cplant(TM) Copyright 1998-2006 Sandia Corporation. * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive * license for use of this work by or on behalf of the US Government. * Export of this program may require a license from the United States @@ -64,18 +64,22 @@ SYSIO_INTERFACE_NAME(symlink)(const char *oldpath, const char *newpath) SYSIO_INTERFACE_ENTER; INTENT_INIT(&intent, INT_CREAT, NULL, NULL); - err = _sysio_namei(_sysio_cwd, newpath, ND_NOFOLLOW | ND_NEGOK, &intent, &pno); + err = + _sysio_namei(_sysio_cwd, + newpath, + ND_NOFOLLOW|ND_NEGOK, + &intent, + &pno); if (err) goto out; if (pno->p_base->pb_ino) { err = -EEXIST; goto error; } - - if (IS_RDONLY(pno, pno->p_base->pb_ino)) { - err = -EROFS; + err = _sysio_permitted(pno->p_parent, W_OK); + if (err) goto error; - } + /* * Use the parent node operations to request the task in case the * driver is implemented using differentiated inode operations based diff --git a/libsysio/src/truncate.c b/libsysio/src/truncate.c index abecb42..5846ad3 100644 --- a/libsysio/src/truncate.c +++ b/libsysio/src/truncate.c @@ -43,6 +43,7 @@ #include #include +#include #include #include #include @@ -52,6 +53,8 @@ #include "sysio.h" #include "inode.h" #include "file.h" +#include "fs.h" +#include "mount.h" #include "sysio-symbols.h" @@ -133,6 +136,10 @@ PREPEND(_, SYSIO_INTERFACE_NAME(ftruncate))(int fd, _SYSIO_OFF_T length) err = -EBADF; goto out; } + if (!F_CHKRW(fil, 'w')) { + err = -EBADF; + goto out; + } err = do_truncate(NULL, fil->f_ino, length); out: SYSIO_INTERFACE_RETURN(err ? -1 : 0, err); diff --git a/libsysio/src/unlink.c b/libsysio/src/unlink.c index c672651..8732efa4 100644 --- a/libsysio/src/unlink.c +++ b/libsysio/src/unlink.c @@ -9,7 +9,7 @@ * terms of the GNU Lesser General Public License * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) * - * Cplant(TM) Copyright 1998-2003 Sandia Corporation. + * Cplant(TM) Copyright 1998-2006 Sandia Corporation. * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive * license for use of this work by or on behalf of the US Government. * Export of this program may require a license from the United States @@ -68,11 +68,12 @@ SYSIO_INTERFACE_NAME(unlink)(const char *path) err = _sysio_namei(_sysio_cwd, path, ND_NOFOLLOW, &intent, &pno); if (err) goto out; - ino = pno->p_base->pb_ino; - if (IS_RDONLY(pno, ino)) { - err = -EROFS; + + err = _sysio_permitted(pno->p_parent, W_OK); + if (err) goto error; - } + + ino = pno->p_base->pb_ino; /* * Use the parent node operations to request the task in case the * driver is implemented using differentiated inode operations based diff --git a/libsysio/tests/Makefile.am b/libsysio/tests/Makefile.am index 0491ab0..2901e5a 100644 --- a/libsysio/tests/Makefile.am +++ b/libsysio/tests/Makefile.am @@ -1,6 +1,7 @@ noinst_PROGRAMS = test_copy test_stats test_path test_list \ - test_getcwd test_link test_unlink test_rename \ - test_regions test_stddir test_fcntl_lock + test_getcwd test_link test_unlink test_symlink test_rename \ + test_regions test_stddir test_fcntl_lock test_mknod test_mkdir \ + test_chown CLEANFILES=drv_data.c @@ -69,6 +70,10 @@ test_unlink_SOURCES=test_unlink.c $(CMNSRC) test_unlink_CFLAGS=$(CFL) test_unlink_DEPENDENCIES=$(LIBS) +test_symlink_SOURCES=test_symlink.c $(CMNSRC) +test_symlink_CFLAGS=$(CFL) +test_symlink_DEPENDENCIES=$(LIBS) + test_rename_SOURCES=test_rename.c $(CMNSRC) test_rename_CFLAGS=$(CFL) test_rename_DEPENDENCIES=$(LIBS) @@ -85,6 +90,18 @@ test_fcntl_lock_SOURCES=test_fcntl_lock.c $(CMNSRC) test_fcntl_lock_CFLAGS=$(CFL) test_fcntl_lock_DEPENDENCIES=$(LIBS) +test_mknod_SOURCES=test_mknod.c $(CMNSRC) +test_mknod_CFLAGS=$(CFL) +test_mknod_DEPENDENCIES=$(LIBS) + +test_mkdir_SOURCES=test_mkdir.c $(CMNSRC) +test_mkdir_CFLAGS=$(CFL) +test_mkdir_DEPENDENCIES=$(LIBS) + +test_chown_SOURCES=test_chown.c $(CMNSRC) +test_chown_CFLAGS=$(CFL) +test_chown_DEPENDENCIES=$(LIBS) + drv_data.c: $(CONFIG_DEPENDENCIES) $(top_srcdir)/tests/gendrvdata.sh test -z "drv_data.c" && rm -f drv_data.c; \ $(SHELL) $(top_srcdir)/tests/gendrvdata.sh $(DRIVERS) > drv_data.c diff --git a/libsysio/tests/cleanup.pl b/libsysio/tests/cleanup.pl deleted file mode 100755 index 029286d..0000000 --- a/libsysio/tests/cleanup.pl +++ /dev/null @@ -1,96 +0,0 @@ -#!/usr/bin/perl -w - -use IPC::Open2; - -use strict; -use FindBin; -use lib "$FindBin::Bin"; -use helper; - -sub usage -{ - print "Usage: ./cleanup.pl : Remove system directories used for test\n"; - exit(-1); -} - -sub do_remove -{ - my ($cmdfh, $outfh, $type, $cwd, $lastdir) = @_; - my $cmd; - if ($type eq "dir") { - $cmd = "rmdir"; - } else { - $cmd = "unlink"; - } - my $cmdstr = "CALL $cmd $cwd/$lastdir\n"; - - # Now remove the file/dir - helper::send_cmd($cmdfh, $outfh, $cmd, $cmdstr); - - # Verify the directory was made correctly - helper::verify_cmd($cmdfh, $outfh, $cmd); - } - - -my $currarg = 0; -my $is_alpha = 0; -my $alpha_arg = ""; -if (@ARGV == 0) { - usage(); -} -if ((@ARGV > 1) && ($ARGV[$currarg++] eq "-alpha")){ - $is_alpha = 1; - $alpha_arg = $ARGV[$currarg-1]; -} - -my $cwd = $ARGV[$currarg]; - -# Get tests directory -my $testdir = $FindBin::Bin; - -eval { - if ($is_alpha == 0) { - open2(\*OUTFILE, \*CMDFILE, "$testdir/test_driver --np"); - } else { - open2(\*OUTFILE, \*CMDFILE, - "yod -batch -quiet -sz 1 $testdir/test_driver --np"); - } -}; - -if ($@) { - if ($@ =~ /^open2/) { - warn "open2 failed: $!\n$@\n"; - return; - } - die; -} - -my $outfh = \*OUTFILE; -my $cmdfh = \*CMDFILE; - -if ($is_alpha == 0) { - helper::send_cmd($cmdfh, $outfh, "init", "CALL init\n"); -} - -# Remove the helper.pms -do_remove($cmdfh, $outfh, "file", $cwd, "tmp_dir/helper.pm"); -do_remove($cmdfh, $outfh, "file", $cwd, "tmp_dir/test1/helper.pm"); - -# Remove directories -do_remove($cmdfh, $outfh, "dir", $cwd, "tmp_dir/test1"); -do_remove($cmdfh, $outfh, "dir", $cwd, "tmp_dir/test2"); -do_remove($cmdfh, $outfh, "dir", $cwd, "tmp_dir"); - -print $cmdfh "exit\n"; -close $outfh; - -# Give test_driver time to finish -sleep 0.000001; - -print STDOUT "cleanup successful\n"; - -exit 0; - - - - diff --git a/libsysio/tests/help.c b/libsysio/tests/help.c deleted file mode 100644 index ad5a769..0000000 --- a/libsysio/tests/help.c +++ /dev/null @@ -1,551 +0,0 @@ -#include -#include "test_driver.h" - -void do_help() { - int i, d, count = 0; - - fprintf(outfp, "libsysio test harness\n"); - fprintf(outfp, "To get help on a specific command, use HELP \n"); - fprintf(outfp, "To exit, type exit or quit\n"); - - fprintf(outfp, "\nTo save the result from a function, use \"$res = CALL command\"\n"); - fprintf(outfp, "To later use that res, do \"comm $res\"\n"); - - fprintf(outfp, "\n\nAvailable commands are (always preceded by CALL):\n\n"); - - /* Get total number of commands */ - while (cmd_list[count].cmd) - count++; - - d = count/4; - if (count % 4) - d++; - for (i=0; i < d; i++) { - - if ( (i+d) < count ) { - if ( (i + 2*d) < count) { - if ( (i+3*d) < count) - fprintf(outfp, "%-15s %-15s %-15s %-15s\n", - cmd_list[i].cmd, cmd_list[i+d].cmd, cmd_list[i+2*d].cmd, - cmd_list[i+3*d].cmd); - else - fprintf(outfp, "%-15s %-15s %-15s\n", - cmd_list[i].cmd, cmd_list[i+d].cmd, cmd_list[i+2*d].cmd); - } else - fprintf(outfp, "%-15s %-15s\n", - cmd_list[i].cmd, cmd_list[i+d].cmd); - } else - fprintf(outfp, "%-15s\n", - cmd_list[i].cmd); - } - fprintf(outfp, "\n"); -} - -void usage_setdebug() -{ - fprintf(outfp, "setdebug [level]: Set debugging level to level\n"); -} - -void usage_setbuf() -{ - fprintf(outfp, "setbuf [val] [size] [buf] [off]: fill size bytes of buf with byte val\n"); -} - - -void usage_clear() -{ - fprintf(outfp, "clear buf: zero out the buffer\n"); -} - -void usage_printline() -{ - fprintf(outfp, "printline [0|1]: Turn off (0) or on (1) the printing of line number\n"); - fprintf(outfp, " : and file name with debug output\n"); -} - -void usage_endian() -{ - fprintf(outfp, "endian: returns 1 for bigendian machines and 0 for little endian machines\n"); -} - - -void usage_sizeof() -{ - fprintf(outfp, "sizeof [type]: returns the size of the data type. Currently \n"); - fprintf(outfp, " : supported types are char, int, long, flock, stat and \n"); - fprintf(outfp, " : statvfs\n"); -} - - -void usage_get_buffer() -{ - fprintf(outfp, "alloc [size] : allocates a buffer of size bytes aligned to align\n"); - fprintf(outfp, " : align is optional. If not there, buffer will be aligned on\n"); - fprintf(outfp, " : a one-byte boundary. returns an index into an array that \n"); - fprintf(outfp, " : holds the buffer\n"); -} - - - -void usage_free_buffer() -{ - fprintf(outfp, "free [bufidx]: frees buffer at bufidx. Returns 0 on success, -1 on failure\n"); -} - -void usage_do_fillbuff() -{ - fprintf(outfp, "fill [val] [type] [size] [offset] [buf] : Fills the buffer buf with size \n"); - fprintf(outfp, " : bytes of val starting at buf+offset\n"); - fprintf(outfp, " : The type of val is specified by type,\n"); - fprintf(outfp, " : which can be UINT, STR, or PTR\n"); -} - -void usage_do_printbuf() -{ - fprintf(outfp, "printbuf [buf] : print out contents of the buffer stored in buf\n"); - fprintf(outfp, " : Always returns 0\n"); -} - -void usage_cmpbufs() -{ - fprintf(outfp, "cmpstr [buf1] [buf2]: Compare the contents of buf1 with buf2 by issuing a \n"); - fprintf(outfp, " strcmp call. Returns 0 if the buffers match\n"); -} - - -void usage_init() -{ - fprintf(outfp, "init : Without any arguments, initilizes libsysio\n"); - fprintf(outfp, " : to default values for root directory and\n"); - fprintf(outfp, " : current directory. Accepts optional\n"); - fprintf(outfp, " : arguments for the root driver, the mount\n"); - fprintf(outfp, " : path, and the mount flags. Must be called\n"); - fprintf(outfp, " : before any other libsysio calls. Returns\n"); - fprintf(outfp," : 0 on success, -1 on failure\n"); -} - -void usage_list() -{ - fprintf(outfp, "list : lists contents of dir. If dir is ommitted, will list contents\n"); - fprintf(outfp, " : of the current working directory\n"); - fprintf(outfp, " : Returns 0 on success, -1 on failure\n"); -} - -void usage_chdir() -{ - fprintf(outfp, "chdir [dir]: change the current working directory to dir\n"); - fprintf(outfp, " : Returns 0 on success, -1 on failure\n"); -} - -void usage_chmod() -{ - fprintf(outfp, "chmod [newmode] [file]: change mode of file to newmode. newmode can be \n"); - fprintf(outfp, " : specifed symbolically (eg, a+x), numerically \n"); - fprintf(outfp, " : (eg, 0777), or using system defines \n"); - fprintf(outfp, " : (eg S_IRUSR|S_IWUSR|S_IRGRP)\n"); - fprintf(outfp, " : Returns 0 on success, -1 on failure\n"); - -} - -void usage_chown() -{ - fprintf(outfp, "chown [newown[:newgrp]] [file]: change the owner of file to newown, the group\n"); - fprintf(outfp, " : of file to newgrp, or both\n"); - fprintf(outfp, " : Returns 0 on success, -1 on failure\n"); -} - -void usage_open() -{ - fprintf(outfp, "open [file] [flags] : open file with given flags. The mode is optional\n"); - fprintf(outfp, " : can use defines for open, (eg, open foo O_RDONLY)\n"); - fprintf(outfp, " : If flags are 0, file will be opened with O_RDWR\n"); - fprintf(outfp, " : Returns the file descriptor for the opened file\n"); -} - -void usage_close() -{ - fprintf(outfp, "close [file]: closes the file. Returns 0 on success, -1 on failure\n"); -} - -void usage_mount() -{ - fprintf(outfp, "mount [fstype:source] [target]: mount source (which has fstype as its file\n"); - fprintf(outfp, " : system type) onto target.\n"); - fprintf(outfp, " : Returns 0 on success, -1 on failure\n"); -} - -void usage_dup() -{ - fprintf(outfp, "dup [oldfd]: Duplicate oldfd. Returns the duplicated file descriptor\n"); - fprintf(outfp, " : Returns -1 on failure\n"); -} - -void usage_dup2() -{ - fprintf(outfp, "dup2 [oldfd] [newfd]: Make newfd be a copy of oldfd. Returns newfd on \n"); - fprintf(outfp, " : success and -1 on failure\n"); -} - -void usage_fcntl() -{ - fprintf(outfp, "fcntl [fd] [cmd] : execute fcntl cmd on file with file descriptor fd\n"); - fprintf(outfp, " : using (optional) args. Accepted (but not \n"); - fprintf(outfp, " : necesarily working) commands are F_DUPFD, \n"); - fprintf(outfp, " : F_GETFD, F_GETFL, F_GETOWN, F_SETFD, F_SETFL,\n"); - fprintf(outfp, " : F_SETOWN, F_SETLK, F_SETLKW, and F_GETLK. \n"); -} - -void usage_fstat() -{ - fprintf(outfp, "fstat [fd] [buf]: Get the stat structure for file descriptor fd and place it\n"); - fprintf(outfp, " : in buf. Returns 0 on success, -1 on failure\n"); -} - -void usage_fsync() -{ - fprintf(outfp, "fsync [fd]: ensure all parts of file with file descriptor fd are output to\n"); - fprintf(outfp, " : stable storage. Returns 0 on success, -1 on failure\n"); -} - -void usage_fdatasync() -{ - fprintf(outfp, "fdatasync [fd]: ensure all parts of file with file descriptor fd except the \n"); - fprintf(outfp, " : metadata are output to stable storage. Returns 0 on \n"); - fprintf(outfp, " : success, -1 on failure\n"); -} - -void usage_ftruncate() -{ - fprintf(outfp, "ftruncate [fd] [len]: truncate file with file descriptor fd to have be \n"); - fprintf(outfp, " : len bytes in length. Returns 0 on success, -1 on \n"); - fprintf(outfp, " : failure\n"); -} - -void usage_getcwd() -{ - fprintf(outfp, "getcwd [buf] [size]: get the current working directory and store it in buf\n"); - fprintf(outfp, " : buf is size bytes in length. If buf is too short, an \n"); - fprintf(outfp, " : error of ERANGE is returned. Returns 0 on success, -1\n"); - fprintf(outfp, " : on failure\n"); -} - -void usage_lseek() -{ - fprintf(outfp, "lseek [fd] [offset] [whence]: Sets the offset of the file descriptor fd to\n"); - fprintf(outfp, " : either offset if whence is SEEK_SET or offset\n"); - fprintf(outfp, " : plus the current location if whence is SEEK_CUR\n"); - fprintf(outfp, " : or offset plus the size of the file if whence\n"); - fprintf(outfp, " : is SEEK_END. Returns 0 on success and -1 on \n"); - fprintf(outfp, " : failure\n"); -} - -void usage_lstat() -{ - fprintf(outfp, "lstat [filename] [buf]: Get the stat structure for filename and return it in\n"); - fprintf(outfp, " : buf. Returns 0 on success and -1 on failure\n"); -} - -void usage_getdirentries() -{ - fprintf(outfp, "getdirentries [fd] [buf] [nbytes] [basep]: Read dir entries from directory\n"); - fprintf(outfp, " : with file descriptor fd into buf\n"); - fprintf(outfp, " : At most nbytes are read. Reading\n"); - fprintf(outfp, " : starts at basep, and basep is set\n"); - fprintf(outfp, " : to new pos. Returns the number of \n"); - fprintf(outfp, " : bytes read on success or 0 on\n"); - fprintf(outfp, " : failure\n"); - fprintf(outfp, "Note that basep does not have to be pre-allocated. Executing cmd: \n"); - fprintf(outfp, "\"getdirentries $fd $buf 4096 $basep\", where $fd is the result of an open\n"); - fprintf(outfp, "and $buf is the result of an alloc (but $basep is totally new) will work\n"); - fprintf(outfp, "After the execution of the command, $basep holds the new offset and can be\n"); - fprintf(outfp, "used again for any further getdirentries calls\n"); -} - -void usage_mkdir() -{ - fprintf(outfp, "mkdir [newdir] [mode]: make a new directory, newdir, with the permissions \n"); - fprintf(outfp, " : specified in mode. Permissions can be symbolic \n"); - fprintf(outfp, " : (eg, a+x), numeric (eg, 0777), or can use defines\n"); - fprintf(outfp, " : (eg S_IRUSR|S_IWUSR|S_IRGRP). Returns 0 on success \n"); - fprintf(outfp, " : -1 on failure.\n"); -} - - -void usage_creat() -{ - fprintf(outfp, "creat [newfile] [mode]: create a new file, newfile, with the permissions \n"); - fprintf(outfp, " : specified in mode. Permissions can be symbolic \n"); - fprintf(outfp, " : (eg, a+x), numeric (eg, 0777), or can use defines\n"); - fprintf(outfp, " : (eg S_IRUSR|S_IWUSR|S_IRGRP). Returns 0 on success \n"); - fprintf(outfp, " : -1 on failure.\n"); -} - -void usage_stat() -{ - fprintf(outfp, "stat [filename] [buf]: Get the stat structure for filename and return it in\n"); - fprintf(outfp, " : buf. Returns 0 on success and -1 on failure\n"); -} - -void usage_statvfs() -{ - fprintf(outfp, "statvfs [filename] [buf]: Get the statvfs structure for filename and return\n"); - fprintf(outfp, " : it in buf. Returns 0 on success and -1 on failure\n"); -} - -void usage_fstatvfs() -{ - fprintf(outfp, "fstatvfs [fd] [buf]: Get the stat structure for file with file descriptor fd\n"); - fprintf(outfp, " : and return it in buf. Returns 0 on success and -1 on\n"); - fprintf(outfp, " : failure\n"); -} - -void usage_truncate() -{ - fprintf(outfp, "truncate [fname] [len]: truncate file with name fname to be exactly \n"); - fprintf(outfp, " : len bytes in length. Returns 0 on success, -1 on \n"); - fprintf(outfp, " : failure\n"); -} - -void usage_rmdir() -{ - fprintf(outfp, "rmdir [dirname]: Remove directory at dirname. Returns 0 on success, -1 on\n"); - fprintf(outfp, " : failure.\n"); -} - -void usage_symlink() -{ - fprintf(outfp, "symlink [path1] [path2]: Make a symbolic link from path1 to path2. Returns\n"); - fprintf(outfp, " : 0 on success, -1 on failure\n"); -} - -void usage_unlink() -{ - fprintf(outfp, "unlink [path]: Unlink path. If path is the last name to a file, the file is \n"); - fprintf(outfp, " : is removed. If it was a symbolic link, the link is removed. \n"); - fprintf(outfp, " : Returns 0 on success, -1 on failure\n"); -} - -void usage_ioctl() -{ - fprintf(outfp, "ioctl [fd] [cmd] : Issue the ioctl command cmd on the file with file\n"); - fprintf(outfp, " : descriptor fd. Any arguments are placed in args\n"); - fprintf(outfp, " : At the moment, the only commands understand are the \n"); - fprintf(outfp, " : ioctl commands found in /usr/include/linux/fs.h\n"); -} - -void usage_umask() -{ - fprintf(outfp, "ioctl [mask] : Sets the umask used by open to set initial file permissions on\n"); - fprintf(outfp, " : a newly created file. Returnds the previous value of the mask\n"); -} - -void usage_iodone() -{ - fprintf(outfp, "iodone [ioid] : Poll for completion of the asynchronous request identifed by\n"); - fprintf(outfp, " : ioid. Returns 1 if request finished\n"); -} - -void usage_iowait() -{ - fprintf(outfp, "iowait [ioid] : Wait for completion of the asynchronous request identifed by\n"); - fprintf(outfp, " : ioid. Returns result of asynchronous request \n"); -} - -void usage_ipreadv() -{ - fprintf(outfp, "ipreadv [fd] [buf] [count] [off]: Reads data asynchrously to file descriptor fd \n"); - fprintf(outfp, " : starting at offset off. Data comes from \n"); - fprintf(outfp, " : buffer described by buf, which is a pointer to\n"); - fprintf(outfp, " : an iovec strucutre. Number of buffers is \n"); - fprintf(outfp, " : specified by count. Returns an iod_t on \n"); - fprintf(outfp, " : success and -1 on failure\n"); -} - -void usage_ipread() -{ - fprintf(outfp, "ipread [fd] [buf] [count] [off]: Read asynchrously up to count bytes from file\n"); - fprintf(outfp, " : with file descriptor fd starting at offset off\n"); - fprintf(outfp, " : Read into buffer pointed at by buf. Returns\n"); - fprintf(outfp, " : an iod_t on success and -1 on failure\n"); -} - -void usage_preadv() -{ - fprintf(outfp, "preadv [fd] [buf] [count] [off]: Reads data from file descriptor fd starting at\n"); - fprintf(outfp, " : offset off. Data goes into buffer described\n"); - fprintf(outfp, " : by buf, which is a pointer to an iovec \n"); - fprintf(outfp, " : structure. Number of buffers is specified by\n"); - fprintf(outfp, " : count. Returns the number of bytes read\n"); -} - -void usage_pread() -{ - fprintf(outfp, "preadv [fd] [buf] [count] [off]: Reads count bytes of data from file descriptor\n"); - fprintf(outfp, " : fd starting at offset off. Data goes into buf.\n"); - fprintf(outfp, " : Returns number of bytes read or -1 on failure\n"); -} - -void usage_ireadv() -{ - fprintf(outfp, "ireadv [fd] [buf] [count] : Reads data asynchrously to file descriptor fd \n"); - fprintf(outfp, " : Data comes from buffer described by buf, which is \n"); - fprintf(outfp, " : an pointer to an iovec structure. Number of\n"); - fprintf(outfp, " : buffers is specified by count. Returns an iod_t\n"); - fprintf(outfp, " : on success and -1 on failure\n"); -} - -void usage_iread() -{ - fprintf(outfp, "iread [fd] [buf] [count]: Read asynchrously up to count bytes from file with\n"); - fprintf(outfp, " : file descriptor fd into buffer pointed at by buf\n"); - fprintf(outfp, " : Returns an iod_t on success and -1 on failure\n"); -} - -void usage_readv() -{ - fprintf(outfp, "readv [fd] [buf] [count] : Reads data from file descriptor fd. Data comes from\n"); - fprintf(outfp, " : the buffer described by buf, which is a pointer to an\n"); - fprintf(outfp, " : an iovec structure. Number of buffers is specified\n"); - fprintf(outfp, " : by count. Returns the number of bytes read on \n"); - fprintf(outfp, " : on success and -1 on failure\n"); -} - -void usage_read() -{ - fprintf(outfp, "read [fd] [buf] [count]: Read up to count bytes from file with file \n"); - fprintf(outfp, " : descriptor fd into buffer pointed at by buf\n"); - fprintf(outfp, " : Returns number of bytes read on success or 0 on \n"); - fprintf(outfp, " : on failure\n"); -} - -void usage_ipwritev() -{ - fprintf(outfp, "ipwritev [fd] [buf] [count] [off]: writes data asynchronously to file with file\n"); - fprintf(outfp, " : descriptor fd starting at offset off. Data \n"); - fprintf(outfp, " : comes from buffers described by buf, which\n"); - fprintf(outfp, " : is a pointer to an iovec structure. Number \n"); - fprintf(outfp, " : of buffers is specified by count. Returns\n"); - fprintf(outfp, " : an iod_t on success and -1 on failure\n"); -} - -void usage_ipwrite() -{ - fprintf(outfp, "ipwrite [fd] [buf] [count] [off]: writes count bytes of data asynchronously to\n"); - fprintf(outfp, " : file with file descriptor fd starting at \n"); - fprintf(outfp, " : offset off. Data comes from buf. Returns an\n"); - fprintf(outfp, " : iod_t on success and -1 on failure\n"); -} - -void usage_pwritev() -{ - fprintf(outfp, "pwritev [fd] [buf] [count] [off]: writes data to file with file descriptor fd\n"); - fprintf(outfp, " : starting at offset off. Data comes from \n"); - fprintf(outfp, " : buffers described by buf, which is a pointer\n"); - fprintf(outfp, " : to an iovec structure. Number of buffers is\n"); - fprintf(outfp, " : by count. Returns number of bytes read on \n"); - fprintf(outfp, " : success and -1 on failure\n"); -} - -void usage_pwrite() -{ - fprintf(outfp, "pwrite [fd] [buf] [count] [off]: writes count bytes of data to file with file \n"); - fprintf(outfp, " : descriptor fd starting at offset off. Data\n"); - fprintf(outfp, " : Data comes from buf. Returns number of bytes\n"); - fprintf(outfp, " : written on success and -1 on failure\n"); -} - -void usage_iwritev() -{ - fprintf(outfp, "iwritev [fd] [buf] [count] : writes data asynchronously to file with file\n"); - fprintf(outfp, " : descriptor fd. Data comes from buffers described\n"); - fprintf(outfp, " : by buf, which is a pointer to an iovec structure.\n"); - fprintf(outfp, " : Number of buffers is specified by count. Returns\n"); - fprintf(outfp, " : an iod_t on success and -1 on failure\n"); -} - -void usage_iwrite() -{ - fprintf(outfp, "iwrite [fd] [buf] [count] : writes count bytes of data asynchronously to\n"); - fprintf(outfp, " : file with file descriptor fd. Data comes from buf.\n"); - fprintf(outfp, " : Returns an iod_t on success and -1 on failure.\n"); -} - -void usage_writev() -{ - fprintf(outfp, "writev [fd] [buf] [count]: writes data to file descriptor fd. Data comes from\n"); - fprintf(outfp, " : buffers described by buf, which is a pointer to a \n"); - fprintf(outfp, " : iovec strucutre. Number of buffers is specified by \n"); - fprintf(outfp, " : count \n"); -} - -void usage_write() -{ - fprintf(outfp, "write [fd] [buf] [count] : writes count bytes of data to file with file \n"); - fprintf(outfp, " : descriptor fd. Data comes from buf. Returns number\n"); - fprintf(outfp, " : of bytes written on success and -1 on failure.\n"); -} - -void usage_mknod() -{ - fprintf(outfp, "mknod [path] [mode] [dev] : creates a filesystem node named path with \n"); - fprintf(outfp, " : specified mode using device special file dev\n"); - fprintf(outfp, " : Returns 0 on sucess and -1 on failure\n"); -} - - -void usage_umount() -{ - fprintf(outfp, "umount [path] : Umount file at path. Returns 0 on success and -1 on failure\n"); -} - -void usage_init_iovec() -{ - fprintf(outfp, "init_iovec buf offset len num iov_buf: Init iovector. iov_uf points to an array of\n"); - fprintf(outfp, " iovecs, num is the number of the iovec, \n"); - fprintf(outfp, " buf is the buffer to be used, offset \n"); - fprintf(outfp, " specifies how far into the buffer the iovec\n"); - fprintf(outfp, " should point and len is the iov length\n"); -} - -void usage_init_xtvec() -{ - fprintf(outfp, "init_xtvec offset len num buf: Init xtvector. Buf points to an array of\n"); - fprintf(outfp, " xtvecs, num is the number of the xtvec, offset\n"); - fprintf(outfp, " is xtv_off and len is the iov lenghth\n"); - fprintf(outfp, " the iov length\n"); -} - -void usage_writex() -{ - fprintf(outfp, "writex fd iovs iov_cnt xtvs xtvcnt: Write iov_cnt iovecs out to file using\n"); - fprintf(outfp, " xtvcnt xtvecs\n"); -} - -void usage_iwritex() -{ - fprintf(outfp, "iwritex fd iovs iov_cnt xtvs xtvcnt: Write iov_cnt iovecs out to file using\n"); - fprintf(outfp, " xtvcnt xtvecs\n"); -} - -void usage_readx() -{ - fprintf(outfp, "readx fd iovs iov_cnt xtvs xtvcnt: Read iov_cnt iovecs out from file using\n"); - fprintf(outfp, " xtvcnt xtvecs\n"); -} - -void usage_ireadx() -{ - fprintf(outfp, "ireadx fd iovs iov_cnt xtvs xtvcnt: Read iov_cnt iovecs out from file using\n"); - fprintf(outfp, " xtvcnt xtvecs\n"); -} - - -void usage_checkbuf() -{ - fprintf(outfp, "checkbuf [buf] [size] [val] [off]: Staring at offset off, checks to see\n"); - fprintf(outfp, " if val is in first size bytes of buf\n"); -} - -void usage_exit() -{ -} diff --git a/libsysio/tests/helper.pm b/libsysio/tests/helper.pm deleted file mode 100644 index f656867..0000000 --- a/libsysio/tests/helper.pm +++ /dev/null @@ -1,147 +0,0 @@ -#!/usr/bin/perl -w - -# -# Provides a set of helper routines for use in the Perl -# test scripts -# - -package helper; -use strict; -use POSIX; - -BEGIN{} - -# Print out a given error message, close the command file -# and exit -sub print_and_exit -{ - my ($cmdfh, $outfh, $exit_num, $exit_str) = @_; - - print STDOUT "$exit_str"; - - # Clean up - my $cmdstr = 'FREE $buf'; - $cmdstr = $cmdstr."\n"; - - print $cmdfh $cmdstr; - - my $res = <$outfh>; - if (defined $res) { - chop($res); - } - - - print $cmdfh "exit\n"; - close $outfh; - - # Give test_driver time to finish - sleep 0.000001; - - exit $exit_num; -} - - -# Output the given command and make sure that the exit -# code for the command was valid -sub send_cmd -{ - my ($cmdfh, $outfh, $cmd, $cmdstr) = @_; - - print $cmdfh $cmdstr; - - my $res = <$outfh>; - if (defined $res) { - chop($res); - } else { - print_and_exit($cmdfh, $outfh, 1, "ERROR! Cmd $cmdstr returned null value!\n"); - } - - if ($res ne "0000 ") { - print_and_exit($cmdfh, $outfh, 1, "ERROR! Command $cmd failed with code $res\n"); - } -} - -# Check the return value from the last libsysio call -sub verify_cmd -{ - - my ($cmdfh, $outfh, $cmd) = @_; - - # Verify the system call's output - my $cmdstr = 'PRINT $$'; - $cmdstr .= "\n"; - send_cmd($cmdfh, $outfh, "PRINT", $cmdstr); - - my $res = <$outfh>; - if (defined $res) { - chop($res); - } else { - print_and_exit($cmdfh, $outfh, 1, "ERROR! Cmd $cmdstr returned null value!\n"); - } - - if ($res eq "0xffffffff") { - - # Get the errno - $cmdstr = 'PRINT $errno'; - $cmdstr .= "\n"; - send_cmd($cmdfh, $outfh, "PRINT", $cmdstr); - - my $err = <$outfh>; - if (defined $err) { - chop($err); - } else { - print_and_exit($cmdfh, $outfh, 1, "ERROR! Cmd $cmdstr returned null value!\n"); - } - - print_and_exit($cmdfh, $outfh, 1, "ERROR! $cmd returned $err\n"); - } - return $res; -} - -# Compares two numbers. Output error message and exit if -# they differ -sub cmp_nums -{ - my ($cmdfh, $outfh, $ionum, $pnum, $desc) = @_; - - my $str; - if (!defined($ionum)) { - print_and_exit($cmdfh, $outfh, 1, "ERROR! ionum for $desc undefined"); - } elsif (!defined($pnum)) { - print_and_exit($cmdfh, $outfh, 1, "ERROR! pnum for $desc undefined"); - } - if ($ionum != $pnum) { - my $str = sprintf("ERROR! Sysio's number %x does not match Perl's (%x)\n", - $ionum, $pnum); - $str = sprintf("%s Numbers were %s\n", $str, $desc); - print_and_exit($cmdfh, $outfh, 1, $str); - } -} - -sub get_type -{ - my $mode = $_[0]; - my $t = '?'; - - if (S_ISDIR($mode)) { - $t = 'd'; - } elsif (S_ISCHR($mode)) { - $t = 'c'; - } elsif (S_ISBLK($mode)) { - $t = 'b'; - } elsif (S_ISREG($mode)) { - $t = 'f'; - } elsif (S_ISFIFO($mode)) { - $t = 'p'; - } elsif (S_ISLNK($mode)) { - $t = 'S'; - } elsif (S_ISSOCK($mode)) { - $t = 's'; - } - - return $t; -} - -END{} - -1; diff --git a/libsysio/tests/populator.pl b/libsysio/tests/populator.pl deleted file mode 100755 index b218519..0000000 --- a/libsysio/tests/populator.pl +++ /dev/null @@ -1,155 +0,0 @@ -#!/usr/bin/perl -w - -use IPC::Open2; - -use strict; -use helper; - -sub usage -{ - print "Usage: ./populator.pl <-seed seed> :\n"; - print " <-file filename> :\n"; - print " <-bytes bytes> : Create a file, filename, that\n"; - print " : is bytes long and populate with\n"; - print " : random numbers using the given\n"; - print " : seed. Will use defaults if args\n"; - print " : not given\n"; - exit(-1); -} - -sub get_buf -{ - my $MAX_SIZE = 2147483648; - - my $str; - my $num; - my $len = 0; - - while ($len < 512) { - $num = rand $MAX_SIZE; - my $tmpstr = sprintf("%d", $num); - $str .= $tmpstr; - $len += length $tmpstr; - } - - return ($len, $str); -} - -sub write_file -{ - my ($cmdfh, $outfh, $filename, $bytes) = @_; - - - # Allocate the read buffer - my $cmd = '$buf = ALLOC 1024'."\n"; - helper::send_cmd($cmdfh, $outfh, "alloc", $cmd); - - # Open (create) the new file - $cmd = '$fd = CALL open '."$filename O_RDWR|O_CREAT S_IRWXU\n"; - helper::send_cmd($cmdfh, $outfh, "open", $cmd); - - # Verify the system call's output - helper::verify_cmd($cmdfh, $outfh, "open"); - - my $left_bytes = $bytes; - while ($left_bytes > 0) { - # Get a buffer filled with random numbers - # Buffer will be no less than 512 bytes - my ($len, $buf) = get_buf; - if ($len > $left_bytes) { - $len = $left_bytes; - } - - # Need to fill $buf with the buffer - $cmd = "CALL fill $buf STR $len 0 ".'$buf'."\n"; - helper::send_cmd($cmdfh, $outfh, "fill", $cmd); - - # Write out $len bytes to $filename - $cmd = 'CALL write $fd $buf '."$len\n"; - - helper::send_cmd($cmdfh, $outfh, "write", $cmd); - - my $written_bytes = helper::verify_cmd($cmdfh, $outfh, "write"); - $written_bytes = oct($written_bytes); - if ($written_bytes != $len) { - helper::print_and_exit($cmdfh, $outfh, 1, - "ERROR! Meant to print out $len but only printed $written_bytes\n"); - } - - $left_bytes -= $len; - } -} - -sub populate_file -{ - my ($filename, $bytes, $is_alpha) = @_; - - eval { - if ($is_alpha == 0) { - open2(\*OUTFILE, \*CMDFILE, "./test_driver --np"); - } else { - open2(\*OUTFILE, \*CMDFILE, - "yod -batch -quiet -sz 1 ./test_driver --np"); - } - }; - - if ($@) { - if ($@ =~ /^open2/) { - warn "open2 failed: $!\n$@\n"; - return; - } - die; - - } - - my $outfh = \*OUTFILE; - my $cmdfh = \*CMDFILE; - - if ($is_alpha == 0) { - helper::send_cmd($cmdfh, $outfh, "init", "CALL init\n"); - } - - # Now write the file - write_file($cmdfh, $outfh, $filename, $bytes); - - # Close the file - my $cmd = 'CALL close $fd'."\n"; - helper::send_cmd($cmdfh, $outfh, "close", $cmd); - - helper::verify_cmd($cmdfh, $outfh, "close"); - - # All done - helper::print_and_exit($cmdfh, $outfh, 0, "File $filename successfully created\n"); -} - - -my $is_alpha = 0; -my $seed = time; -my $filename = "randfile.$seed.$$"; -my $bytes = 1024; -for (my $i = 0; $i < @ARGV; $i++) -{ - if ($ARGV[$i] eq "-file") { - $i++; - $filename = $ARGV[$i]; - } elsif ($ARGV[$i] eq "-seed") { - $i++; - $seed = $ARGV[$i]; - } elsif ($ARGV[$i] eq "-alpha") { - $is_alpha = 1; - } elsif ($ARGV[$i] eq "-bytes") { - $i++; - $bytes = $ARGV[$i]; - } -} - -# seed the randome number generator -srand $seed; - -populate_file($filename, $bytes, $is_alpha); - -exit $seed; - - - - diff --git a/libsysio/tests/setup.pl b/libsysio/tests/setup.pl deleted file mode 100755 index 4270f59..0000000 --- a/libsysio/tests/setup.pl +++ /dev/null @@ -1,104 +0,0 @@ -#!/usr/bin/perl -w - -use IPC::Open2; - -use strict; -use FindBin; -use lib "$FindBin::Bin"; -use helper; - -sub usage -{ - print "Usage: ./setup.pl : Setup initial system directories for test\n"; - exit(-1); -} - -sub do_makedir -{ - my ($cmdfh, $outfh, $cwd, $lastdir) = @_; - my $cmd = "CALL mkdir $cwd/$lastdir 0777\n"; - - # Now create newdir - helper::send_cmd($cmdfh, $outfh, "mkdir", $cmd); - - # Verify the directory was made correctly - helper::verify_cmd($cmdfh, $outfh, "mkdir"); - } - - -my $currarg = 0; -my $is_alpha = 0; -my $alpha_arg = ""; -if (@ARGV == 0) { - usage(); -} -if ((@ARGV > 1) && ($ARGV[$currarg++] eq "-alpha")){ - $is_alpha = 1; - $alpha_arg = $ARGV[$currarg-1]; -} - -my $cwd = $ARGV[$currarg]; - -# Get tests directory -my $testdir = $FindBin::Bin; - -eval { - if ($is_alpha == 0) { - open2(\*OUTFILE, \*CMDFILE, "$testdir/test_driver --np"); - } else { - open2(\*OUTFILE, \*CMDFILE, - "yod -batch -quiet -sz 1 $testdir/test_driver --np"); - } -}; - -if ($@) { - if ($@ =~ /^open2/) { - warn "open2 failed: $!\n$@\n"; - return; - } - die; -} - -my $outfh = \*OUTFILE; -my $cmdfh = \*CMDFILE; - -if ($is_alpha == 0) { - helper::send_cmd($cmdfh, $outfh, "init", "CALL init\n"); -} - - -# Create tmp_dir -do_makedir($cmdfh, $outfh, $cwd, "tmp_dir"); -do_makedir($cmdfh, $outfh, $cwd, "tmp_dir/test1"); -do_makedir($cmdfh, $outfh, $cwd, "tmp_dir/test2"); - -# Copy helper.pm -print STDERR "Copying $testdir/helper.pm to $cwd/tmp_dir/test1/helper.pm\n"; -my $res = `perl $testdir/test_copy.pl $alpha_arg $testdir/helper.pm $cwd/tmp_dir/test1/helper.pm`; -chop($res); - -if ($res ne "copy test successful") { - print STDERR "setup (copy test) failed with message: $res\n"; - print $cmdfh "exit\n"; - close $outfh; - - # Give test_driver time to finish - sleep 0.000001; - - print STDOUT "Copying of helper.pm failed\n"; - exit 1; -} - - print $cmdfh "exit\n"; -close $outfh; - -# Give test_driver time to finish -sleep 0.000001; - -print STDOUT "setup successful\n"; - -exit 0; - - - - diff --git a/libsysio/tests/sysio_stubs.c b/libsysio/tests/sysio_stubs.c deleted file mode 100644 index 439804d..0000000 --- a/libsysio/tests/sysio_stubs.c +++ /dev/null @@ -1,2706 +0,0 @@ -#define _BSD_SOURCE - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "xtio.h" -#include "sysio.h" -#include "test_driver.h" - -/* - * ################################################ - * # Function stubs # - * # These allow all of the different commands # - * # to be called with the same format # - * ################################################ - */ - -int test_do_setdebug(int argc, char **argv) -{ - int level; - - if (argc != 1) { - DBG(2, fprintf(outfp, "Invalid number of args (%d) for setdebug\n", - argc)); - return INVALID_ARGS; - } - - level = atoi(argv[0]); - - if (level < 0) { - DBG(2, fprintf(outfp, "Invalid debug level %d\n", level)); - return INVALID_ARGS; - } - - debug_level = level; - return SUCCESS; -} - -int test_do_printline(int argc, char **argv) -{ - int on; - - - if (argc != 1) { - DBG(2, fprintf(outfp, "Invalid number of args (%d) for printline\n", - argc)); - return INVALID_ARGS; - } - - on = atoi(argv[0]); - if (on) - print_line = 1; - else - print_line = 0; - - return SUCCESS; -} - -/* -int test_do_setoutput(int argc, char **argv) -{ - FILE *newfp; - - if (argc != 1) { - fprintf(outfp, "Invalid number of args (%d) for setoutput\n", - argc); - return -1; - } - - newfp = fopen(argv[0], "w"); - if (!newfp) { - fprintf(outfp, "Unable to open new output file %s\n", argv[0]); - return -1; - } - - outfp = newfp; - - return 0; -} - -*/ - - -int test_do_fillbuff(int argc, char **argv) -{ - char *typestr, *buf; - void *valptr; - int size, type, index, offset; - - if (argc != 5) { - DBG(2, - fprintf(outfp, - "fillbuff requires a value, a type, a size, an offset, and the target buffer\n")); - fprintf(stderr, "fillbuff requires 5 args, you gave %d\n", argc); - return INVALID_ARGS; - } - - offset = get_obj(argv[3]); - if (offset < 0) { - DBG(2, fprintf(outfp, "Do not understand offset %s\n", argv[3])); - return INVALID_VAR; - } - - index = get_obj(argv[4]); - if (index < 0) { - DBG(2, fprintf(outfp, "Can't find buffer at %s\n", argv[4])); - return INVALID_VAR; - } - buf = (char *)(buflist[index]->buf)+offset; - - DBG(4, fprintf(outfp, "Buffer start is at %p\n", (void *)buflist[index])); - - typestr = argv[1]; - size = get_obj(argv[2]); - if (size < 0) { - DBG(2, fprintf(outfp, "Unable to understand size %s\n", argv[2])); - return INVALID_VAR; - } - - if ( (!strcmp(typestr, "UINT")) || (!strcmp(typestr, "SINT")) ){ - int val = get_obj(argv[0]); - valptr = &val; - type = UINT; - if (val < 0) { /* FIX THIS */ - DBG(2, fprintf(outfp, "Can't understand value %s\n", argv[0])); - return INVALID_VAR; - } - DBG(4, fprintf(outfp, "Copying %d bytes from %p. Val is %x\n", - size, buf, *((int *)valptr))); - memcpy(buf, valptr, size); - - } else if (!strcmp(typestr,"STR")) { - type = STR; - valptr = argv[0]; - DBG(4, fprintf(outfp, "Copying %d bytes from %p. Val is %s\n", - size, buf, (char *)valptr)); - memcpy(buf, valptr, size); - } else if (!strcmp(typestr, "PTR")) { - unsigned long val; - int index = get_obj(argv[0]); - if (index < 0) { - DBG(2, fprintf(outfp, "Unable to find buffer at %s\n", argv[0])); - return INVALID_VAR; - } - - val = (unsigned long)buflist[index]->buf; - valptr = &val; - DBG(4, fprintf(outfp, "Copying %d bytes from %p. Val is %p\n", - size, buf, valptr)); - memcpy(buf, valptr, size); - } else { - DBG(2, fprintf(outfp, "Unknown type %s. Valid types are UINT, STR, and PTR\n", - typestr)); - fprintf(stderr, "Unknown type %s. Valid types are UINT, STR, and PTR\n", - typestr); - return INVALID_ARGS; - } - - return SUCCESS; -} - - -#define STR_TYPE 1 -#define INT_TYPE 2 -#define SHORT_TYPE 3 -#define CHAR_TYPE 4 -#define LONG_TYPE 5 - -void print_partial(char *buf, int offset, int len, int type) -{ - int i; - - if (type == STR_TYPE) { - sprintf(output, "%s%s", output, (char *)(buf+offset)); - DBG(4, fprintf(outfp, "Printing str %s\n", (char *)(buf+offset))); - } else { - if (type == SHORT_TYPE) { - for (i = 0; i < len; i+= 2) { - short *ibuf = (short *)(buf + offset + i); - sprintf(output, "%s%#04x ", output, *ibuf); - DBG(4, fprintf(outfp, "Printing short %#04x\n", *ibuf)); - } - } else if (type == CHAR_TYPE) { - for (i = 0; i < len; i++) { - short *ibuf = (short *)(buf+offset+i); - sprintf(output, "%s%#02x ", output, (*ibuf & 0x00ff)); - DBG(4, fprintf(outfp, "Printing char %c\n", (*ibuf & 0x00ff))); - } - } else if (type == INT_TYPE) { - for (i = 0; i < len; i+= 4) { - int *ibuf = (int *)(buf + offset + i); - sprintf(output, "%s%#08x ", output, *ibuf); - DBG(4, fprintf(outfp, "Printing int %#08x\n", *ibuf)); - } - } else { - for (i = 0; i < len; i += 8) { - unsigned long *lbuf = (unsigned long *)(buf + offset +i); - sprintf(output, "%s%#08lx ", output, *lbuf); - DBG(4, fprintf(outfp, "Printing int %#016lx\n", *lbuf)); - } - } - } -} - -int test_do_printbuf(int argc, char **argv) -{ - int index, i, type, offset, len; - struct buf_t *buf_st; - void *buf; - char *typestr; - struct var_mapping *mobj; - - if (argv[0][0] == '$') { - if (argv[0][1] == '$') { - sprintf(output, "\n%#010x", (unsigned int)last_ret_val); - return SUCCESS; - } else if (!strcmp("errno", &argv[0][1])) { - sprintf(output, "\n%#010x", my_errno); - return SUCCESS; - } - } - - mobj = get_map(argv[0]); - if (mobj == NULL) { - DBG(2, fprintf(outfp, "Can't get var at %s\n", argv[0])); - return INVALID_VAR; - } - - if (mobj->type == UINT) - sprintf(output, "\n%#010x", mobj->obj); - else if (mobj->type == SINT) - sprintf(output, "%d", mobj->obj); - else if ((mobj->type == STR) || (mobj->type == PTR)) { - index = mobj->obj; - - buf_st = buflist[index]; - DBG(2, fprintf(outfp, "buf_st is %p:\n", (void *)buf_st)); - buf = buf_st->buf; - DBG(2, fprintf(outfp, "buf %s:\n", argv[0])); - if (mobj->type == STR) { - sprintf(output, "\n%s", (char *)buf); - } else { - sprintf(output,"%s\n", output); - DBG(2, fprintf(outfp, "buf_st->len is %d, buf is %p\n", buf_st->len, buf)); - if (argc == 1) { - for (i = 0; i < buf_st->len/4; i++) - DBG(2, fprintf(outfp, "%#x ", ((int *)buf)[i])); - sprintf(output, "%s%#x ", output, ((int *)buf)[i]); - - } - - for (i = 1; i < argc; i++) { - offset = get_obj(argv[i++]); - len = get_obj(argv[i++]); - if ((offset < 0) || (len < 0)) { - DBG(2, fprintf(outfp, "Invalid offset (%s) or len (%s)\n", - argv[i-2], argv[i-1])); - return INVALID_VAR; - } - typestr = argv[i]; - if (!strcmp("STR", typestr)) - type = STR_TYPE; - else if (!strcmp("INT", typestr)) - type = INT_TYPE; - else if (!strcmp("SHORT", typestr)) - type = SHORT_TYPE; - else if (!strcmp("CHAR", typestr)) - type = CHAR_TYPE; - else if (!strcmp("LONG", typestr)) - type = LONG_TYPE; - else { - DBG(2, fprintf(outfp, "Unable to understand type %s\n", - typestr)); - return INVALID_ARGS; - } - print_partial(buf, offset, len, type); - } - } - } - DBG(3, fprintf(outfp, "output: %s \n", output)); - return SUCCESS; -} - -int test_do_mount(int argc, char **argv) -{ - if (argc != 2) { - DBG(2, fprintf(outfp, "Invalid number of args (%d) for test_do_mount\n", - argc)); - return INVALID_ARGS; - } - - DBG(4, fprintf(outfp, "Calling mount with from %s and to %s\n", - argv[0], argv[1])); - last_ret_val = sysio_mount(argv[0], argv[1]); - my_errno = errno; - last_type = SINT; - return SUCCESS; -} - -int test_do_clear(int argc, char **argv) -{ - int index; - struct buf_t *buf; - - if (argc != 1) { - DBG(2, fprintf(outfp, "Invalid number of args (%d) for clear\n", - argc)); - return INVALID_ARGS; - } - index = get_obj(argv[0]); - if (index < 0) { - fprintf(outfp, "Unable to locate buffer %s\n", - argv[0]); - return -1; - } - buf = buflist[index]; - bzero(buf->buf, buf->len); - - return SUCCESS; -} - -int test_do_list(int argc, char **argv) -{ - char *buf; - - if ((argc) && (argc != 1)) { - DBG(2, fprintf(outfp, "Invalid number of args (%d) for list\n", - argc)); - return INVALID_ARGS; - } - - DBG(5,fprintf(outfp, "In test_do_list with args %p\n", (void *)argv)); - if (!argv) { - buf = getcwd(NULL, 0); - DBG(4, fprintf(outfp, "Calling list with dir of %s\n", buf)); - last_ret_val = sysio_list(buf); - my_errno = errno; - free(buf); - return SUCCESS; - } - - last_type = SINT; - return sysio_list(*argv); -} - -/* - * Initlizes sysio library. Will use default initlization - * unless arguments are given - */ -int test_do_init(int argc, char **argv) -{ - if (argc > 0) { - char *rdriver; - char *mpath; - int mflags, rsize, msize; - if (argc != 3) { - DBG(2, fprintf(outfp, "Invalid number of args (%d) for init\n", - argc)); - return INVALID_ARGS; - } - - rdriver = get_str(argv[0]); - rsize = strlen(rdriver)+1; - if (rsize > 75) { - DBG(2, fprintf(outfp, "%s too long for root driver\n", rdriver)); - return INVALID_ARGS; - } - bzero(root_driver, 75); - memcpy(root_driver, rdriver, rsize); - - mpath = get_str(argv[1]); - msize = strlen(mpath)+1; - if (msize > 250) { - DBG(2, fprintf(outfp, "%s too long for mount path\n", mpath)); - return INVALID_ARGS; - } - bzero(mntpath, 250); - memcpy(mntpath, mpath, msize); - - mflags = get_obj(argv[2]); - if (mflags == -1) { - DBG(2, fprintf(outfp, "Invalid flags argument %s\n", argv[2])); - return INVALID_ARGS; - } - } - - DBG(5, fprintf(outfp, "In test_do_init\n")); - last_type = SINT; - DBG(3, fprintf(outfp, "initializing\n")); - return initilize_sysio(); -} - - -/* - * Returns 1 if the machine is big-endian, 0 - * otherwise - */ -int get_endian(int argc, char **argv) -{ - int x = 1; - - if ((argc) || (argv)) { - DBG(2, fprintf(outfp, "Expected no args for test_do_endian\n")); - return INVALID_ARGS; - } - - if(*(char *)&x == 1) { - /* little-endian, return 0 */ - last_ret_val= 0; - } else { - /* big endian, return 1 */ - last_ret_val= 1; - } - last_type = UINT; - return SUCCESS; -} - -int do_setbuf(int argc, char **argv) -{ - int val, size, index, offset; - void *buf; - - if (argc != 4) { - DBG(2, fprintf(outfp, "Need val, size, buffer, and offset for setbuf\n")); - return INVALID_ARGS; - } - val = get_obj(argv[0]); - if (val < 0) { - DBG(2, fprintf(outfp, "Unable to understand val of %s\n", - argv[0])); - return INVALID_VAR; - } - - size = get_obj(argv[1]); - if( size <=0 ) { - DBG(2, fprintf(outfp, "Size of %s is invalid\n", argv[1])); - return INVALID_VAR; - } - - index = get_obj(argv[2]); - if (index < 0) { - DBG(2, fprintf(outfp, "Unable to find buffer assocated with %s\n", - argv[2])); - return INVALID_VAR; - } - - buf = buflist[index]->buf; - - offset = get_obj(argv[3]); - - if (offset < 0) { - DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[3])); - return INVALID_ARGS; - } - - buf = (void *)((char *)buf +offset); - - memset(buf, val, size); - - return SUCCESS; -} - - -int get_sizeof(int argc, char **argv) -{ - char *type; - int size; - - if (argc != 1) { - DBG(2, fprintf(outfp, "Number of args (%d) invalid for sizeof\n", - argc)); - return INVALID_ARGS; - } - - type = argv[0]; - - if (!strcmp(type, "char")) - size = sizeof(char); - else if (!strcmp(type, "int")) - size = sizeof(int); - else if (!strcmp(type, "long")) - size = sizeof(long); - else if (!strcmp(type, "flock")) - size = sizeof(struct flock); - else if (!strcmp(type, "stat")) - size = sizeof(struct stat); - else if (!strcmp(type, "statvfs")) - size = sizeof(struct statvfs); - else if (!strcmp(type, "iovec")) - size = sizeof(struct iovec); - else if (!strcmp(type, "xtvec")) - size = sizeof(struct xtvec); - else - return INVALID_ARGS; - - DBG(2, fprintf(outfp, "Size is %d\n", size)); - - last_type = UINT; - last_ret_val = size; - return SUCCESS; -} - -int test_do_exit(int argc, char **argv) -{ - int val = 0; - - if (argc) { - /* - * If argc is given, need to return the value of - * the passed in variable - */ - val = get_obj(argv[0]); - } - - /* - * Clean up. - */ - _sysio_shutdown(); - - if (argc) - DBG(3, printf("Exiting with %d from %s\n", val, argv[0])); - - exit(val); - - return 0; -} - -int get_buffer(int argc, char **argv) -{ - int size, align; - struct buf_t *buf; - - if (argc == 1) /* Just put size, not alignment */ - align = 16; - else if (argc == 2) - align = get_obj(argv[1]); - else { - DBG(2, fprintf(outfp, "Number of args (%d) invalid for alloc\n", - argc)); - return INVALID_ARGS; - } - - size = get_obj(argv[0]); - if (size < 0) { - DBG(2, fprintf(outfp, "Invalid size %s\n", argv[0])); - return INVALID_ARGS; - } - - DBG(3, fprintf(outfp, "Getting buffer of size %d and aligned at %d\n", - size, align)); - buf = (struct buf_t *)malloc(sizeof(struct buf_t)); - buf->buf = alloc_buff32(size, align); - buf->len = size; - buflist[next] = buf; - DBG(3, fprintf(outfp, "Your buffer (%p) (%p) is at index %d\n", - (void *)buf, buf->buf, next)); - next++; - - last_type = PTR; - last_ret_val = next-1; - return SUCCESS; -} - -int free_buffer(int argc, char **argv) -{ - int index; - char *name = argv[0]; - - if (argc != 1) { - DBG(2, fprintf(outfp, "Number of args (%d) invalid for free\n", - argc)); - return INVALID_ARGS; - } - - /* - * Assume that there is one arg and it - * is a variable name which maps to an - * index into the buffer array - */ - index = get_obj(name); - if (index < 0) { - DBG(2, fprintf(outfp, "Can't find buffer %s\n", - name)); - return INVALID_VAR; - } - DBG(4, fprintf(outfp, "Freeing buffer at index %d\n", index)); - free(buflist[index]); - - free_obj(name); - return SUCCESS; -} - -int cmp_bufs(int argc, char **argv) -{ - int res, index1, index2; - char *buf1, *buf2; - - if (argc != 2) { - fprintf(outfp, "Need two buffers to compare\n"); - return INVALID_ARGS; - } - - index1 = get_obj(argv[0]); - if (index1 < 0) { - fprintf(outfp, "Unable to locate buffer %s\n", - argv[0]); - return INVALID_VAR; - } - buf1 = buflist[index1]->buf; - - index2 = get_obj(argv[1]); - if (index2 < 0) { - fprintf(outfp, "Unable to locate buffer %s\n", - argv[1]); - return INVALID_VAR; - } - - buf2 = buflist[index2]->buf; - last_ret_val = strcmp(buf1, buf2); - - DBG(3, fprintf(outfp, "strcmp returned %d\n", res)); - return SUCCESS; -} - -int test_do_chdir(int argc, char **argv) -{ - if (argc != 1) { - DBG(2, fprintf(outfp, "Number of args (%d) invalid for chdir\n", - argc)); - return INVALID_ARGS; - } - last_type = SINT; - return sysio_chdir(argv[0]); -} - - -int test_do_chmod(int argc, char **argv) -{ - if (argc != 2) { - DBG(2, fprintf(outfp, "Number of args (%d) invalid for chmod\n", - argc)); - return INVALID_ARGS; - } - last_type = SINT; - return sysio_chmod(argv[0], argv[1]); -} - -int test_do_chown(int argc, char **argv) -{ - if (argc != 2) { - DBG(2, fprintf(outfp, "Number of args (%d) invalid for chown\n", - argc)); - return INVALID_ARGS; - } - last_type = SINT; - return sysio_chown(argv[0], argv[1]); -} - -int test_do_open(int argc, char **argv) -{ - char *name = argv[0]; - int flags = O_RDWR; - - if (argc > 1) - flags = get_obj(argv[1]); - - if (name[0] == '$') { - int index = get_obj(name); - - if (index < 0) { - DBG(2, fprintf(outfp, "Unable to find buffer at %s\n", - name)); - return INVALID_VAR; - } - - name = buflist[index]->buf; - } - - DBG(4, fprintf(outfp, "Opening file %s with flags %d\n", name, flags)); - if (argc == 2) - return sysio_open(name, flags); - else if (argc == 3) - return sysio_open3(name, flags, argv[2]); - else { - DBG(2, fprintf(outfp, "Invalid number of arguments (%d)\n", argc)); - return INVALID_ARGS; - } - last_type = UINT; - return SUCCESS; -} - -int test_do_close(int argc, char **argv) -{ - int fd; - char *name = argv[0]; - - if (argc != 1) { - DBG(2, fprintf(outfp, "Number of args (%d) invalid for close\n", - argc)); - return INVALID_ARGS; - } - - /* - * Assume that there is one arg and it - * is a variable name which maps to a file - * descriptor - */ - fd = get_obj(name); - if (fd < 0) { - DBG(2, fprintf(outfp, "Unable to map var %s to anything\n", name)); - return INVALID_VAR; - } - sysio_close(fd); - free_obj(name); - return SUCCESS; -} - -int test_do_dup(int argc, char **argv) -{ - int fd; - char *var_name = argv[0]; - - if (argc != 1) { - DBG(2, fprintf(outfp, "Number of args (%d) invalid for dup\n", - argc)); - return INVALID_ARGS; - } - - - fd = get_obj(var_name); - if (fd < 0) { - DBG(2, fprintf(outfp, "Unable to map var %s to any file\n", var_name)); - return INVALID_VAR; - } - - last_ret_val = dup(fd); - my_errno = errno; - last_type = SINT; - - return SUCCESS; -} - -int test_do_dup2(int argc, char **argv) -{ - int fd1, fd2; - char *var_name1 = argv[0]; - char *var_name2 = argv[1]; - - if (argc != 2) { - DBG(2, fprintf(outfp, "Number of args (%d) invalid for dup2\n", - argc)); - return INVALID_ARGS; - } - - fd1 = get_obj(var_name1); - if (fd1 < 0) { - DBG(2, fprintf(outfp, "Unable to map var %s to any file\n", var_name1)); - return INVALID_VAR; - } - - fd2 = get_obj(var_name2); - if (fd2 < 0) { - DBG(2, fprintf(outfp, "Unable to map var %s to any file\n", var_name2)); - return INVALID_VAR; - } - - last_ret_val = dup2(fd1, fd2); - my_errno = errno; - last_type = SINT; - - return SUCCESS; -} - -struct cmd_map fcntl_cmds[] = { - { "F_DUPFD", F_DUPFD, 3 }, - { "F_GETFD", F_GETFD, 2 }, - { "F_SETFD", F_SETFD, 3 }, - { "F_GETFL", F_GETFL, 2 }, - { "F_SETFL", F_SETFL, 3 }, - { "F_SETLK", F_SETLK, 3 }, - { "F_SETLKW", F_SETLKW, 3 }, - { "F_GETLK", F_GETLK, 3 }, -#if defined __USE_BSD || defined __USE_XOPEN2K - { "F_GETOWN", F_GETOWN, 2 }, - { "F_SETOWN", F_SETOWN, 3 }, -#endif -#ifdef __USE_GNU - { "F_GETSIG", F_GETSIG, 2 }, - { "F_SETSIG", F_SETSIG, 3 }, - { "F_SETLEASE", F_SETLEASE, 3}, - { "F_GETLEASE", F_GETLEASE, 2}, - { "F_NOTIFY", F_NOTIFY, 3} , -#endif - { NULL, -1, 0 } -}; - -struct cmd_map* get_cmd(char *cmd_name, int argc) -{ - int i =0; - - while (fcntl_cmds[i].cmd_name) { - if (!strcmp(fcntl_cmds[i].cmd_name, cmd_name)) { - if (fcntl_cmds[i].num_args == argc) - return &fcntl_cmds[i]; - else - return NULL; - } - i++; - } - return NULL; -} - -int test_do_fcntl(int argc, char **argv) -{ - - struct cmd_map *cmd; - int fd; - - /* - * get_cmd translates a symbolic command into - * into its numerical equivalent. It also - * verifies that the number of args is the - * correct number for the command. It returns - * NULL on failure - */ - cmd = get_cmd(argv[1], argc); - if (!cmd) { - DBG(2, fprintf(outfp, "Unable to get command %s\n", argv[1])); - return INVALID_ARGS; - } - - fd = get_obj(argv[0]); - if (fd < 0) { - DBG(2, fprintf(outfp, "Unable to map %s to file descriptor \n", argv[0])); - return INVALID_VAR; - } - - if (argc > 2) - last_ret_val = sysio_fcntl(fd, cmd, argv[2]); - else - last_ret_val = sysio_fcntl(fd, cmd, NULL); - DBG(4, fprintf(outfp, "Got return value of %d\n", (int)last_ret_val)); - my_errno = errno; - last_type = SINT; - - return SUCCESS; -} - -int test_do_fstat(int argc, char **argv) -{ - int fd, index; - void *buf; - - if (argc != 2) { - DBG(2, fprintf(outfp, "Invalid number of arguments (%d) for fstat\n", - argc)); - return INVALID_ARGS; - } - - fd = get_obj(argv[0]); - - if (fd < 0) { - DBG(2, fprintf(outfp, "Unable to find file assocated with %s\n", - argv[0])); - return INVALID_VAR; - } - - index = get_obj(argv[1]); - if (index < 0) { - DBG(2, fprintf(outfp, "Unable to find buffer assocated with %s\n", - argv[1])); - return INVALID_VAR; - } - - buf = buflist[index]->buf; - - last_ret_val = sysio_fstat(fd, buf); - my_errno = errno; - last_type = SINT; - - return SUCCESS; -} - -int test_do_lstat(int argc, char **argv) -{ - char *name = argv[0]; - int index; - void *buf; - - if (argc != 2) { - DBG(2, fprintf(outfp, "Invalid number of arguments (%d) for lstat\n", - argc)); - return INVALID_ARGS; - } - - index = get_obj(argv[1]); - if (index < 0) { - DBG(2, fprintf(outfp, "Unable to find buffer assocated with %s\n", - argv[1])); - return INVALID_VAR; - } - - buf = buflist[index]->buf; - last_type = SINT; - - return sysio_lstat(name, buf); -} - -int test_do_fsync(int argc, char **argv) -{ - int fd; - - if (argc != 1) { - DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to fsync\n", argc)); - return INVALID_ARGS; - } - - - fd = get_obj(argv[0]); - - if (fd < 0) { - DBG(2, fprintf(outfp, "Unable to find file assocated with %s\n", - argv[0])); - return INVALID_VAR; - } - - last_ret_val = fsync(fd); - my_errno = errno; - last_type = SINT; - - return SUCCESS; -} - - -int test_do_fdatasync(int argc, char **argv) -{ - int fd; - - if (argc != 1) { - DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to fdatasync\n", argc)); - return INVALID_ARGS; - } - - - fd = get_obj(argv[0]); - - if (fd < 0) { - DBG(2, fprintf(outfp, "Unable to find file assocated with %s\n", - argv[0])); - return INVALID_VAR; - } - - last_ret_val = fdatasync(fd); - my_errno = errno; - last_type = SINT; - - return SUCCESS; -} - - -int test_do_ftruncate(int argc, char **argv) -{ - int fd; - off_t length; - - if (argc != 2) { - DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to ftruncate\n", argc)); - return INVALID_ARGS; - } - - - fd = get_obj(argv[0]); - - if (fd < 0) { - DBG(2, fprintf(outfp, "Unable to find file assocated with %s\n", - argv[0])); - return INVALID_VAR; - } - - length = (off_t)get_obj(argv[1]); - - DBG(3, fprintf(outfp, "Setting file %d to %d\n", fd, (int) length)); - - last_ret_val = ftruncate(fd, length); - my_errno = errno; - last_type = SINT; - - return SUCCESS; -} - -int test_do_getcwd(int argc, char **argv) -{ - char *buf; - int size, index; - - if (argc != 2) { - DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to getcwd\n", argc)); - return INVALID_ARGS; - } - - index = get_obj(argv[0]); - if (index < 0) { - DBG(2, fprintf(outfp, "Unable to find buffer assocated with %s\n", - argv[1])); - return INVALID_VAR; - } - - buf = buflist[index]->buf; - - size = get_obj(argv[1]); - - DBG(4, fprintf(outfp, "Getting cwd with buffer size of %d\n", size)); - - last_ret_val = 0; - if (!getcwd(buf, size)) { - last_ret_val = -1; - if (errno == ERANGE) { - DBG(2, fprintf(outfp, "Need a bigger buffer!\n")); - } - } - - my_errno = errno; - - - DBG(3, fprintf(outfp, "cwd: %s\n", buf)); - last_type = SINT; - - return SUCCESS; -} - -int test_do_lseek(int argc, char **argv) -{ - int fd, whence; - off_t offset; - - - if (argc != 3) { - DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to lseek\n", argc)); - return INVALID_ARGS; - } - - - fd = get_obj(argv[0]); - - if (fd < 0) { - DBG(2, fprintf(outfp, "Unable to find file assocated with %s\n", - argv[0])); - return INVALID_VAR; - } - - offset = (off_t)get_obj(argv[1]); - whence = get_obj(argv[2]); - - if (whence < 0 ) { - DBG(2, fprintf(outfp, "Not familiar with whence of %s\n", - argv[2])); - return INVALID_ARGS; - } - - last_ret_val = lseek(fd, offset, whence); - my_errno = errno; - last_type = SINT; - - return SUCCESS; -} - -int test_do_getdirentries(int argc, char **argv) -{ - int fd, nbytes; - int bufindex; - off_t basep; - char *buf; - struct var_mapping *base_map; - - if (argc != 4) { - DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to getdirentries\n", argc)); - return INVALID_ARGS; - } - - fd = get_obj(argv[0]); - - if (fd < 0) { - DBG(2, fprintf(outfp, "Unable to find file assocated with %s\n", - argv[0])); - return INVALID_VAR; - } - - bufindex = get_obj(argv[1]); - - if (bufindex < 0) { - DBG(2, fprintf(outfp, "Unable to find buffer assocated with %s\n", - argv[1])); - return INVALID_VAR; - } - - buf = buflist[bufindex]->buf; - - nbytes = get_obj(argv[2]); - - if (nbytes < 0) { - DBG(2, fprintf(outfp, "I don't understand %s\n", - argv[2])); - return INVALID_ARGS; - } - - base_map = get_map(argv[3]); - if (!base_map) { - DBG(3, fprintf(outfp, "Resetting basep\n")); - /* - * Assume that this is the first getdirentries call - * and we need to setup the base pointer - */ - basep = 0; - } else - basep = base_map->obj; - - DBG(3, fprintf(outfp, "basep is (starting) %d\n", (int) basep)); - last_ret_val = sysio_getdirentries(fd, buf, nbytes, &basep); - if (base_map) - base_map->obj = basep; - else - store_result(argv[3]+1, basep); - DBG(3, fprintf(outfp, "basep is (ending) %d\n", (int) basep)); - my_errno = errno; - last_type = SINT; - - return SUCCESS; -} - -int test_do_mkdir(int argc, char **argv) -{ - if (argc !=2) { - DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to mkdir\n", argc)); - return INVALID_ARGS; - } - - last_type = SINT; - return sysio_mkdir(argv[0], argv[1]); -} - -int test_do_creat(int argc, char **argv) -{ - if (argc !=2) { - DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to creat\n", argc)); - return INVALID_ARGS; - } - - last_type = UINT; - return sysio_creat(argv[0], argv[1]); -} - -int test_do_stat(int argc, char **argv) -{ - int index; - void *buf; - char *str; - - if (argc != 2) { - fprintf(outfp, "Invalid number of arguments (%d) for stat\n", - argc); - return -1; - } - - - index = get_obj(argv[1]); - if (index < 0) { - fprintf(outfp, "Unable to find buffer assocated with %s\n", - argv[1]); - } - - buf = buflist[index]->buf; - last_type = SINT; - - str = get_str(argv[0]); - return sysio_stat(str, buf); -} - -int test_do_statvfs(int argc, char **argv) -{ - int index; - void *buf; - - if (argc != 2) { - fprintf(outfp, "Invalid number of arguments (%d) for statvfs\n", - argc); - return -1; - } - - - index = get_obj(argv[1]); - if (index < 0) { - fprintf(outfp, "Unable to find buffer assocated with %s\n", - argv[1]); - } - - buf = buflist[index]->buf; - last_type = SINT; - - return sysio_statvfs(argv[0], buf); -} - -int test_do_fstatvfs(int argc, char **argv) -{ - int index, fd; - void *buf; - - if (argc != 2) { - fprintf(outfp, "Invalid number of arguments (%d) for fstatvfs\n", - argc); - return -1; - } - - - fd = get_obj(argv[0]); - - if (fd < 0) { - fprintf(outfp, "Unable to find file assocated with %s\n", - argv[0]); - } - - - index = get_obj(argv[1]); - if (index < 0) { - fprintf(outfp, "Unable to find buffer assocated with %s\n", - argv[1]); - } - - buf = buflist[index]->buf; - last_type = SINT; - - return sysio_fstatvfs(fd, buf); -} - -int test_do_truncate(int argc, char **argv) -{ - off_t length; - - if (argc != 2) { - DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to truncate\n", argc)); - return INVALID_ARGS; - } - - length = (off_t)get_obj(argv[1]); - - DBG(3, fprintf(outfp, "Setting file %s to %d\n", argv[0], (int) length)); - - last_ret_val = truncate(argv[0], length); - my_errno = errno; - last_type = SINT; - - return SUCCESS; -} - -int test_do_rmdir(int argc, char **argv) -{ - - if (argc != 1) { - DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to rmdir\n", argc)); - return INVALID_ARGS; - } - - DBG(3, fprintf(outfp, "Removing dir %s\n", argv[0])); - - last_ret_val = rmdir(argv[0]); - my_errno = errno; - last_type = SINT; - - return SUCCESS; -} - -int test_do_symlink(int argc, char **argv) -{ - if (argc != 2) { - DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to symlink\n", argc)); - return INVALID_ARGS; - } - - DBG(3, fprintf(outfp, "Linking %s to %s\n", argv[0], argv[1])); - - last_ret_val = symlink(argv[0], argv[1]); - if (last_ret_val) { - if (errno < 0) - errno = errno*-1; - my_perror("symlink"); - } - my_errno = errno; - last_type = SINT; - - return SUCCESS; -} - - -struct cmd_map ioctl_cmds[] = { -#if 0 - { "BLKROSET", BLKROSET, 3 }, - { "BLKROGET", BLKROGET, 3 }, - { "BLKRRPART", BLKRRPART, 3 }, - { "BLKGETSIZE", BLKGETSIZE, 3 }, - { "BLKRASET", BLKRASET, 3 }, - { "BLKRAGET", BLKRAGET, 3 }, - { "BLKSECTSET", BLKSECTSET, 3 }, - { "BLKSECTGET", BLKSECTGET, 3 }, - { "BLKSSZGET", BLKSSZGET, 3 }, - { "BLKGETLASTSECT", BLKGETLASTSECT, 3 }, - { "BLKSETLASTSECT", BLKSETLASTSECT, 3 }, - { "BLKBSZGET", BLKBSZGET, 3 }, - { "BLKBSZSET", BLKBSZSET, 3 }, - { "FIBMAP", FIBMAP, 3 }, - { "FIGETBSZ", FIGETBSZ, 3}, -#endif - { NULL, -1, 0 } -}; - -int get_ioctl_cmd(char *cmd) -{ - int i = 0; - - while (ioctl_cmds[i].cmd_name != NULL) { - if (strcmp(ioctl_cmds[i].cmd_name, cmd)) - i++; - else - return ioctl_cmds[i].cmd; - } - - return -1; -} - -int test_do_ioctl(int argc, char **argv) -{ - int fd, cmd; - - if (argc != 3) { - DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to ioctl\n", argc)); - return INVALID_ARGS; - } - - - fd = get_obj(argv[0]); - if (fd < 0) { - DBG(2, fprintf(outfp, "Unable to find file %s\n", argv[0])); - return INVALID_VAR; - } - - cmd = get_ioctl_cmd(argv[1]); - if (cmd == -1) { - DBG(2, fprintf(outfp, "Do not understand command %s\n", argv[1])); - return INVALID_ARGS; - } - - DBG(3, fprintf(outfp, "Executing command %s\n", argv[1])); - - last_ret_val = ioctl(fd, cmd, argv[2]); - my_errno = errno; - if (last_ret_val) - my_perror("ioctl"); - last_type = SINT; - - return SUCCESS; -} - -int test_do_unlink(int argc, char **argv) -{ - if (argc != 1) { - DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to unlink\n", argc)); - return INVALID_ARGS; - } - - DBG(4, fprintf(outfp, "Unlinking %s\n", argv[0])); - - last_ret_val = unlink(argv[0]); - my_errno = errno; - if (last_ret_val) - my_perror("unlink"); - last_type = SINT; - - return SUCCESS; -} - -int test_do_umask(int argc, char **argv) -{ - mode_t old_mask; - - if (argc != 1) { - DBG(2, fprintf(outfp, "Incorrect number of args (%d) for umask\n", argc)); - return INVALID_ARGS; - } - - last_ret_val = old_mask = sysio_umask(argv[0]); - my_errno = errno; - DBG(3, fprintf(outfp, "Previous umask was %o\n", old_mask)); - last_type = UINT; - - return SUCCESS; -} - -int test_do_iowait(int argc, char **argv) -{ - long err; - ioid_t ioid; - - if (argc != 1) { - DBG(2, fprintf(outfp, "Incorrect amount of args (%d) for iowait\n", argc)); - return INVALID_ARGS; - } - - err = get_obj(argv[0]); - if (err < 0) { - DBG(2, fprintf(outfp, "Cannot find ioid at %s\n", argv[0])); - return INVALID_VAR; - } - - ioid = (ioid_t)err; - - last_ret_val = iowait(ioid); - my_errno = errno; - if (last_ret_val < 0) { - my_perror("iowait"); - } - last_type = SINT; - - return SUCCESS; -} - -int test_do_iodone(int argc, char **argv) -{ - long err; - ioid_t ioid; - - if (argc != 1) { - DBG(2, fprintf(outfp, "Incorrect amount of args (%d) for iodone\n", argc)); - return INVALID_ARGS; - } - - err = get_obj(argv[0]); - if (err < 0) { - DBG(2, fprintf(outfp, "Cannot find ioid at %s\n", argv[0])); - return INVALID_VAR; - } - ioid = (ioid_t)err; - - last_ret_val = iowait(ioid); - if (last_ret_val < 0) { - my_perror("iodone"); - } - my_errno = errno; - last_type = SINT; - - return SUCCESS; - -} - -int test_do_ipread(int argc, char **argv) -{ - int fd, index, count, offset; - char *buf; - - if (argc != 4) { - DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to ipread\n", argc)); - return INVALID_ARGS; - } - - fd = get_obj(argv[0]); - if (fd < 0) { - DBG(2, fprintf(outfp, "Unable to find file at %s\n", argv[0])); - return INVALID_VAR; - } - - index = get_obj(argv[1]); - if (index < 0) { - DBG(2, fprintf(outfp, "Unable to find buffer at %s\n", argv[1])); - return INVALID_VAR; - } - - buf = buflist[index]->buf; - - count = get_obj(argv[2]); - if (count < 0) { - DBG(2, fprintf(outfp, "Do not understand count %s\n", argv[2])); - return INVALID_ARGS; - } - - offset = get_obj(argv[3]); - if (offset < 0) { - DBG(2, fprintf(outfp, "Unable to understand offset of %s\n", argv[3])); - return INVALID_ARGS; - } - - last_ret_val = (long)ipread(fd, buf, count, offset); - if (last_ret_val < 0) { - my_perror("ipread"); - } - my_errno = errno; - last_type = SINT; - - return SUCCESS; -} - -int test_do_iread(int argc, char **argv) -{ - int fd, index, count; - char *buf; - - if (argc != 3) { - DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to iread\n", argc)); - return INVALID_ARGS; - } - - fd = get_obj(argv[0]); - if (fd < 0) { - DBG(2, fprintf(outfp, "Unable to find file at %s\n", argv[0])); - return INVALID_VAR; - } - - index = get_obj(argv[1]); - if (index < 0) { - DBG(2, fprintf(outfp, "Unable to find buffer at %s\n", argv[1])); - return INVALID_VAR; - } - - buf = buflist[index]->buf; - - count = get_obj(argv[2]); - if (count < 0) { - DBG(2, fprintf(outfp, "Do not understand count %s\n", argv[2])); - return INVALID_ARGS; - } - - last_ret_val = (long) iread(fd, buf, count); - if (last_ret_val < 0) { - my_perror("iread"); - } - my_errno = errno; - last_type = SINT; - - return SUCCESS; -} - - -int test_do_ipreadv(int argc, char **argv) -{ - int fd, count, index; - off_t offset; - char *buf; - struct iovec *iov; - - if (argc != 4) { - DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to ipreadv\n", argc)); - return INVALID_ARGS; - } - - fd = get_obj(argv[0]); - - if (fd < 0) { - DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0])); - return INVALID_VAR; - } - - index = get_obj(argv[1]); - - if (index < 0) { - DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1])); - return INVALID_VAR; - } - - buf = buflist[index]->buf; - - iov = (struct iovec *)buf; - count = get_obj(argv[2]); - - if (count < 0) { - DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[2])); - return INVALID_ARGS; - } - - offset = get_obj(argv[3]); - if (offset < 0) { - DBG(2, fprintf(outfp, "Unable to understand offset value %s\n", argv[3])); - return INVALID_ARGS; - } - - DBG(3, fprintf(outfp, "ipreadv(fd: %d vector:{iov_base: %p iov_len %d} count: %d offset: %d\n", - fd, iov->iov_base, (int)iov->iov_len, count, (int) offset)); - - last_ret_val = (long) ipreadv(fd, iov, count, offset); - if (last_ret_val < 0) - my_perror("ipreadv"); - my_errno = errno; - last_type = SINT; - - return SUCCESS; -} - - -int test_do_preadv(int argc, char **argv) -{ - int fd, count, index; - off_t offset; - char *buf; - struct iovec *iov; - - if (argc != 4) { - DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to preadv\n", argc)); - return INVALID_ARGS; - } - - fd = get_obj(argv[0]); - - if (fd < 0) { - DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0])); - return INVALID_VAR; - } - - index = get_obj(argv[1]); - - if (index < 0) { - DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1])); - return INVALID_VAR; - } - - buf = buflist[index]->buf; - - iov = (struct iovec *)buf; - count = get_obj(argv[2]); - - if (count < 0) { - DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[2])); - return INVALID_ARGS; - } - - offset = get_obj(argv[3]); - if (offset < 0) { - DBG(2, fprintf(outfp, "Unable to understand offset value %s\n", argv[3])); - return INVALID_ARGS; - } - - DBG(3, fprintf(outfp, "preadv(fd: %d vector:{iov_base: %p iov_len %d} count: %d offset: %d\n", - fd, iov->iov_base, (int) iov->iov_len, count, (int) offset)); - - last_ret_val = preadv(fd, iov, count, offset); - my_errno = errno; - if (last_ret_val < 0) - my_perror("preadv"); - last_type = SINT; - - return SUCCESS; -} - - -int test_do_pread(int argc, char **argv) -{ - int fd, count, index, numbytes, offset; - char *buf; - - if (argc != 4) { - DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to pread\n", argc)); - return INVALID_ARGS; - } - - - fd = get_obj(argv[0]); - - if (fd < 0) { - DBG(2, fprintf(outfp, "Unable to find file assocated with %s\n", - argv[0])); - return INVALID_VAR; - } - - index = get_obj(argv[1]); - - if (index < 0) { - DBG(2, fprintf(outfp, "Unable to find buffer assocated with %s\n", - argv[1])); - return INVALID_VAR; - } - - buf = buflist[index]->buf; - - count = get_obj(argv[2]); - if (count < 0) { - DBG(2, fprintf(outfp, "Unable to understand count of %s\n", argv[1])); - return INVALID_ARGS; - } - - offset = get_obj(argv[3]); - if (count < 0) { - DBG(2, fprintf(outfp, "Unable to understand offset of %s\n", argv[2])); - return INVALID_ARGS; - } - - - last_ret_val = numbytes = (int) pread(fd, buf, count, offset); - my_errno = errno; - DBG(4, fprintf(outfp, "Read %d bytes out of %d starting at offset %x\n", - numbytes, count, offset)); - DBG(3, fprintf(outfp, "Got %s\n", buf)); - last_type = SINT; - - return SUCCESS; -} - - -int test_do_ireadv(int argc, char **argv) -{ - int fd, count, index; - char *buf; - struct iovec *iov; - - if (argc != 3) { - DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to ireadv\n", argc)); - return INVALID_ARGS; - } - - fd = get_obj(argv[0]); - - if (fd < 0) { - DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0])); - return INVALID_VAR; - } - - index = get_obj(argv[1]); - - if (index < 0) { - DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1])); - return INVALID_VAR; - } - - buf = buflist[index]->buf; - - iov = (struct iovec *)buf; - count = get_obj(argv[2]); - - if (count < 0) { - DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[2])); - return INVALID_ARGS; - } - - DBG(3, fprintf(outfp, "ireadv (fd: %d, vector:{ iov_base: %p iov_len %d }, count: %d\n", - fd, iov->iov_base, (int)iov->iov_len, count)); - - last_ret_val = (long) ireadv(fd, iov, count); - if (last_ret_val < 0) - my_perror("ireadv"); - my_errno = errno; - last_type = SINT; - - return SUCCESS; -} - -int test_do_readv(int argc, char **argv) -{ - int fd, count, index; - char *buf; - struct iovec *iov; - - if (argc != 3) { - DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to readv\n", argc)); - return INVALID_ARGS; - } - - fd = get_obj(argv[0]); - - if (fd < 0) { - DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0])); - return INVALID_VAR; - } - - index = get_obj(argv[1]); - - if (index < 0) { - DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1])); - return INVALID_VAR; - } - - buf = buflist[index]->buf; - - iov = (struct iovec *)buf; - count = get_obj(argv[2]); - - if (count < 0) { - DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[2])); - return INVALID_ARGS; - } - - DBG(3, fprintf(outfp, "ireadv (fd: %d, vector:{ iov_base: %p iov_len %d }, count: %d\n", - fd, iov->iov_base, (int)iov->iov_len, count)); - - last_ret_val = readv(fd, iov, count); - if (last_ret_val < 0) - my_perror("readv"); - my_errno = errno; - last_type = SINT; - - return SUCCESS; -} - -int test_do_read(int argc, char **argv) -{ - int fd, count, index, numbytes=0; - char *buf; - - if (argc < 3) { - DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to read\n", argc)); - return INVALID_ARGS; - } - - - fd = get_obj(argv[0]); - - if (fd < 0) { - DBG(2, fprintf(outfp, "Unable to find file assocated with %s\n", - argv[0])); - return INVALID_VAR; - } - - index = get_obj(argv[1]); - - - if (index < 0) { - DBG(2, fprintf(outfp, "Unable to find buffer assocated with %s\n", - argv[1])); - return INVALID_VAR; - } - - buf = buflist[index]->buf; - - count = get_obj(argv[2]); - - if ( (argc == 4) && (!strcmp(argv[3], "delay")) ){ - int i; - /* Wait a little while for input */ - for (i=0; i < count; i++) { - sleep(0.005); - numbytes += (int) read(fd, buf, 1); - last_ret_val = numbytes; - - } - } else { - last_ret_val = numbytes = (int) read(fd, buf, count); - } - my_errno = errno; - - DBG(3, fprintf(outfp, "Read %d bytes out of %d\n", numbytes, count)); - DBG(3, fprintf(outfp, "Got %s\n", buf)); - last_type = SINT; - - return SUCCESS; -} - -int test_do_ipwritev(int argc, char **argv) -{ - int fd, count, index, offset; - char *buf; - struct iovec *iov; - - if (argc != 4) { - DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to ipwritev\n", argc)); - return INVALID_ARGS; - } - - fd = get_obj(argv[0]); - - if (fd < 0) { - DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0])); - return INVALID_VAR; - } - - index = get_obj(argv[1]); - - if (index < 0) { - DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1])); - return INVALID_VAR; - } - - buf = buflist[index]->buf; - - iov = (struct iovec *)buf; - - count = get_obj(argv[2]); - if (count < 0) { - DBG(2, fprintf(outfp, "Unable to understand count %s\n", argv[2])); - return INVALID_ARGS; - } - - offset = get_obj(argv[3]); - if (offset < 0) { - DBG(2, fprintf(outfp, "Unable to understand offset %s\n", argv[3])); - return INVALID_ARGS; - } - - DBG(3, fprintf(outfp, - "ipwritev(fd: %d, vector: { iov_base: %p iov_len %d }, count: %d, offset: %d\n", - fd, iov->iov_base, (int)iov->iov_len, count, offset)); - - last_ret_val = (long) ipwritev(fd, iov, count, offset); - my_errno = errno; - if (last_ret_val < 0) - my_perror("ipwritev"); - last_type = SINT; - - return SUCCESS; -} - -int test_do_ipwrite(int argc, char **argv) -{ - int fd, count, index, offset; - char *buf; - - if (argc != 4) { - DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to ipwrite\n", argc)); - return INVALID_ARGS; - } - - fd = get_obj(argv[0]); - - if (fd < 0) { - DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0])); - return INVALID_VAR; - } - - index = get_obj(argv[1]); - - if (index < 0) { - DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1])); - return INVALID_VAR; - } - - buf = buflist[index]->buf; - - count = get_obj(argv[2]); - if (count < 0) { - DBG(2, fprintf(outfp, "Unable to understand count %s\n", argv[2])); - return INVALID_ARGS; - } - - offset = get_obj(argv[3]); - if (offset < 0) { - DBG(2, fprintf(outfp, "Unable to understand offset %s\n", argv[3])); - return INVALID_ARGS; - } - - last_ret_val = (long) ipwrite(fd, buf, count, offset); - if (last_ret_val < 0) - my_perror("ipwrite"); - my_errno = errno; - last_type = SINT; - - return SUCCESS; -} - -int test_do_pwritev(int argc, char **argv) -{ - int fd, count, index, offset; - char *buf; - struct iovec *iov; - - if (argc != 4) { - DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to pwritev\n", argc)); - return INVALID_ARGS; - } - - fd = get_obj(argv[0]); - - if (fd < 0) { - DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0])); - return INVALID_VAR; - } - - index = get_obj(argv[1]); - - if (index < 0) { - DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1])); - return INVALID_VAR; - } - - buf = buflist[index]->buf; - - iov = (struct iovec *)buf; - - count = get_obj(argv[2]); - if (count < 0) { - DBG(2, fprintf(outfp, "Unable to understand count %s\n", argv[2])); - return INVALID_ARGS; - } - - offset = get_obj(argv[3]); - if (offset < 0) { - DBG(2, fprintf(outfp, "Unable to understand offset %s\n", argv[3])); - return INVALID_ARGS; - } - - - DBG(3, fprintf(outfp, - "pwritev(fd: %d, vector: { iov_base: %p iov_len %d }, count: %d, offset: %d\n", - fd, iov->iov_base, (int)iov->iov_len, count, offset)); - - last_ret_val = (long) pwritev(fd, iov, count, offset); - if (last_ret_val < 0) - my_perror("ipwritev"); - my_errno = errno; - last_type = SINT; - - return SUCCESS; -} - -int test_do_pwrite(int argc, char **argv) -{ - int fd, count, index, offset; - char *buf; - - if (argc != 4) { - DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to pwrite\n", argc)); - return INVALID_ARGS; - } - - fd = get_obj(argv[0]); - - if (fd < 0) { - DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0])); - return INVALID_VAR; - } - - index = get_obj(argv[1]); - - if (index < 0) { - DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1])); - return INVALID_VAR; - } - - buf = buflist[index]->buf; - - count = get_obj(argv[2]); - if (count < 0) { - DBG(2, fprintf(outfp, "Unable to understand count %s\n", argv[2])); - return INVALID_ARGS; - } - - offset = get_obj(argv[3]); - if (offset < 0) { - DBG(2, fprintf(outfp, "Unable to understand offset %s\n", argv[3])); - return INVALID_ARGS; - } - - last_ret_val = pwrite(fd, buf, count, offset); - my_errno = errno; - if (last_ret_val < 0) - my_perror("pwrite"); - last_type = SINT; - - return SUCCESS; -} - - -int test_do_iwritev(int argc, char **argv) -{ - int fd, count, index; - char *buf; - struct iovec *iov; - - if (argc != 3) { - DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to iwritev\n", argc)); - return INVALID_ARGS; - } - - fd = get_obj(argv[0]); - - if (fd < 0) { - DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0])); - return INVALID_VAR; - } - - index = get_obj(argv[1]); - - if (index < 0) { - DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1])); - return INVALID_VAR; - } - - buf = buflist[index]->buf; - - iov = (struct iovec *)buf; - - count = get_obj(argv[2]); - if (count < 0) { - DBG(2, fprintf(outfp, "Unable to understand count %s\n", argv[2])); - return INVALID_ARGS; - } - - DBG(3, fprintf(outfp, "iwritev(fd: %d, vector: { iov_base: %p iov_len %d }, count: %d\n", - fd, iov->iov_base, (int)iov->iov_len, count)); - - last_ret_val = (long) iwritev(fd, iov, count); - my_errno = errno; - if (last_ret_val < 0) - my_perror("iwritev"); - last_type = SINT; - - return SUCCESS; -} - -int test_do_iwrite(int argc, char **argv) -{ - int fd, count, index; - char *buf; - - if (argc != 3) { - DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to iwrite\n", argc)); - return INVALID_ARGS; - } - - fd = get_obj(argv[0]); - - if (fd < 0) { - DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0])); - return INVALID_VAR; - } - - index = get_obj(argv[1]); - - if (index < 0) { - DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1])); - return INVALID_VAR; - } - - buf = buflist[index]->buf; - - count = get_obj(argv[2]); - if (count < 0) { - DBG(2, fprintf(outfp, "Unable to understand count %s\n", argv[2])); - return INVALID_ARGS; - } - - last_ret_val = (long) iwrite(fd, buf, count); - my_errno = errno; - if (last_ret_val < 0) - my_perror("iwrite"); - last_type = SINT; - - return SUCCESS; -} - - -int test_do_write(int argc, char **argv) -{ - int fd, count, index, err; - char *buf; - - if (argc != 3) { - DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to write\n", argc)); - return INVALID_ARGS; - } - - fd = get_obj(argv[0]); - - if (fd < 0) { - DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0])); - return INVALID_VAR; - } - - index = get_obj(argv[1]); - - if (index < 0) { - DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1])); - return INVALID_VAR; - } - - buf = buflist[index]->buf; - - count = get_obj(argv[2]); - if (count < 0) { - DBG(2, fprintf(outfp, "Unable to understand count %s\n", argv[2])); - return INVALID_ARGS; - } - - DBG(4, fprintf(outfp, "Writing out %d bytes (%s) using fd of %x\n", - count, buf, fd)); - err = write(fd, buf, count); - if (err < 0) - my_perror("write"); - - last_ret_val = err; - my_errno = errno; - last_type = SINT; - - return SUCCESS; -} - - -int test_do_writev(int argc, char **argv) -{ - int fd, count, index; - char *buf; - struct iovec *iov; - - if (argc != 3) { - DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to writev\n", argc)); - return INVALID_ARGS; - } - - fd = get_obj(argv[0]); - - if (fd < 0) { - DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0])); - return INVALID_ARGS; - } - - index = get_obj(argv[1]); - - if (index < 0) { - DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1])); - return INVALID_VAR; - } - - buf = buflist[index]->buf; - - iov = (struct iovec *)buf; - count = get_obj(argv[2]); - - if (count < 0) { - DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[2])); - return INVALID_ARGS; - } - - DBG(3, fprintf(outfp, "writev(fd: %d, vector: { iov_base: %p iov_len %d }, count: %d\n", - fd, iov->iov_base, (int)iov->iov_len, count)); - - last_ret_val = writev(fd, iov, count); - if (last_ret_val < 0) - my_perror("writev"); - my_errno = errno; - last_type = SINT; - - return SUCCESS; -} - -int test_do_mknod(int argc, char **argv) -{ - int dev; - - if (argc != 3) { - DBG(2, fprintf(outfp, "Invalid number of args (%d) for mknod\n", argc)); - return INVALID_ARGS; - } - - dev = get_obj(argv[2]); - if (dev < 0) { - DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[2])); - return INVALID_ARGS; - } - last_type = SINT; - - - return sysio_mknod(argv[0], argv[1], (dev_t) dev); -} - -int test_do_umount(int argc, char **argv) -{ - int err; - - if (argc != 1) { - DBG(2, fprintf(outfp, "Invalid number (%d) of args for umount\n", argc)); - return INVALID_ARGS; - } - - err = umount(argv[0]); - if (err) - my_perror("umount"); - - my_errno = errno; - last_ret_val = err; - last_type = SINT; - - return SUCCESS; -} - -int test_do_init_iovec(int argc, char **argv) -{ - int iov_index, buf_index; - int offset, len, pos; - struct iovec *iov_ptr; - char *base_ptr; - - if (argc != 5) { - DBG(2, fprintf(outfp, "Need buffer, offset, len, array pos, and iov pointer\n")); - return INVALID_ARGS; - } - - if ((buf_index = get_obj(argv[0])) < 0) { - DBG(2, fprintf(outfp, "Unable to find object %s\n", argv[0])); - return INVALID_VAR; - } - base_ptr = buflist[buf_index]->buf; - - if ((offset = get_obj(argv[1])) < 0) { - DBG(2, fprintf(outfp, "Cannot understand offset of %s\n", argv[1])); - return INVALID_VAR; - } - - if ((len = get_obj(argv[2])) < 0) { - DBG(2, fprintf(outfp, "Cannot understand len of %s\n", argv[2])); - return INVALID_VAR; - } - - if ((pos = get_obj(argv[3])) < 0) { - DBG(2, fprintf(outfp, "Cannot understand array pos of %s\n", argv[3])); - return INVALID_VAR; - } - - if ((iov_index = get_obj(argv[4])) < 0) { - DBG(2, fprintf(outfp, "Unable to find object %s\n", argv[4])); - return INVALID_VAR; - } - iov_ptr = (struct iovec *)(buflist[iov_index]->buf); - - iov_ptr[pos].iov_len = len; - iov_ptr[pos].iov_base = (void *)(base_ptr + offset); - - DBG(3, fprintf(outfp, "iov_ptr.len is %d and base is %p\n", - (int)iov_ptr[pos].iov_len, iov_ptr[pos].iov_base)); - my_errno = errno; - last_type = PTR; - - return SUCCESS; -} - - -int test_do_init_xtvec(int argc, char **argv) -{ - int xtv_index; - int offset, len, pos; - struct xtvec *xtv_ptr; - - if (argc != 4) { - DBG(2, fprintf(outfp, "Need offset, len, array pos, and xtv pointer\n")); - return INVALID_ARGS; - } - - if ((offset = get_obj(argv[0])) < 0) { - DBG(2, fprintf(outfp, "Cannot understand offset of %s\n", argv[0])); - return INVALID_VAR; - } - - if ((len = get_obj(argv[1])) < 0) { - DBG(2, fprintf(outfp, "Cannot understand len of %s\n", argv[1])); - return INVALID_VAR; - } - - if ((pos = get_obj(argv[2])) < 0) { - DBG(2, fprintf(outfp, "Cannot understand array pos of %s\n", argv[2])); - return INVALID_VAR; - } - - if ((xtv_index = get_obj(argv[3])) < 0) { - DBG(2, fprintf(outfp, "Unable to find object %s\n", argv[3])); - return INVALID_VAR; - } - xtv_ptr = (struct xtvec *)(buflist[xtv_index]->buf); - - xtv_ptr[pos].xtv_len = len; - xtv_ptr[pos].xtv_off = offset; - - DBG(3, fprintf(outfp, "xtv_ptr.len is %d and offset is %d\n", - (int)xtv_ptr[pos].xtv_len, (int)xtv_ptr[pos].xtv_off)); - - my_errno = errno; - last_type = PTR; - - return SUCCESS; -} - -int test_do_writex(int argc, char **argv) -{ - int fd, iov_count, xtv_count,index; - char *buf; - struct iovec *iov; - struct xtvec *xtv; - - if (argc != 5) { - DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to writex\n", argc)); - return INVALID_ARGS; - } - - fd = get_obj(argv[0]); - - if (fd < 0) { - DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0])); - return INVALID_ARGS; - } - - index = get_obj(argv[1]); - - if (index < 0) { - DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1])); - return INVALID_VAR; - } - - buf = buflist[index]->buf; - - iov = (struct iovec *)buf; - iov_count = get_obj(argv[2]); - - if (iov_count < 0) { - DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[2])); - return INVALID_ARGS; - } - - index = get_obj(argv[3]); - - if (index < 0) { - DBG(2, fprintf(outfp, "Unable to find xtvs described by %s\n", argv[3])); - return INVALID_VAR; - } - - buf = buflist[index]->buf; - - xtv = (struct xtvec *)buf; - xtv_count = get_obj(argv[4]); - - if (xtv_count < 0) { - DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[4])); - return INVALID_ARGS; - } - - DBG(3, fprintf(outfp, "writex(fd: %d, iov: %p iov_cnt: %d, xtv: %p, xtv_cnt: %d\n", - fd, (void *)iov, iov_count, (void *)xtv, xtv_count)); - - last_ret_val = writex(fd, iov, iov_count, xtv, xtv_count); - if (last_ret_val < 0) - my_perror("writex"); - my_errno = errno; - last_type = SINT; - - return SUCCESS; -} - - -int test_do_iwritex(int argc, char **argv) -{ - int fd, iov_count, xtv_count,index; - char *buf; - struct iovec *iov; - struct xtvec *xtv; - - if (argc != 5) { - DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to iwritex\n", argc)); - return INVALID_ARGS; - } - - fd = get_obj(argv[0]); - - if (fd < 0) { - DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0])); - return INVALID_ARGS; - } - - index = get_obj(argv[1]); - - if (index < 0) { - DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1])); - return INVALID_VAR; - } - - buf = buflist[index]->buf; - - iov = (struct iovec *)buf; - iov_count = get_obj(argv[2]); - - if (iov_count < 0) { - DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[2])); - return INVALID_ARGS; - } - - index = get_obj(argv[3]); - - if (index < 0) { - DBG(2, fprintf(outfp, "Unable to find xtvs described by %s\n", argv[3])); - return INVALID_VAR; - } - - buf = buflist[index]->buf; - - xtv = (struct xtvec *)buf; - xtv_count = get_obj(argv[4]); - - if (xtv_count < 0) { - DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[4])); - return INVALID_ARGS; - } - - DBG(3, fprintf(outfp, "iwritex(fd: %d, iov: %p iov_cnt: %d, xtv: %p, xtv_cnt: %d\n", - fd, (void *)iov, iov_count, (void *)xtv, xtv_count)); - - last_ret_val = (long) iwritex(fd, iov, iov_count, xtv, xtv_count); - if (last_ret_val < 0) - my_perror("iwritex"); - my_errno = errno; - last_type = SINT; - - return SUCCESS; -} - - -int test_do_readx(int argc, char **argv) -{ - int fd, iov_count, xtv_count,index; - char *buf; - struct iovec *iov; - struct xtvec *xtv; - - if (argc != 5) { - DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to readx\n", argc)); - return INVALID_ARGS; - } - - fd = get_obj(argv[0]); - - if (fd < 0) { - DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0])); - return INVALID_ARGS; - } - - index = get_obj(argv[1]); - - if (index < 0) { - DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1])); - return INVALID_VAR; - } - - buf = buflist[index]->buf; - - iov = (struct iovec *)buf; - iov_count = get_obj(argv[2]); - - if (iov_count < 0) { - DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[2])); - return INVALID_ARGS; - } - - index = get_obj(argv[3]); - - if (index < 0) { - DBG(2, fprintf(outfp, "Unable to find xtvs described by %s\n", argv[3])); - return INVALID_VAR; - } - - buf = buflist[index]->buf; - - xtv = (struct xtvec *)buf; - xtv_count = get_obj(argv[4]); - - if (xtv_count < 0) { - DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[4])); - return INVALID_ARGS; - } - - DBG(3, fprintf(outfp, "readx(fd: %d, iov: %p iov_cnt: %d, xtv: %p, xtv_cnt: %d\n", - fd, (void *)iov, iov_count, (void *)xtv, xtv_count)); - - last_ret_val = readx(fd, iov, iov_count, xtv, xtv_count); - if (last_ret_val < 0) - my_perror("readx"); - my_errno = errno; - last_type = SINT; - - return SUCCESS; -} - - -int test_do_ireadx(int argc, char **argv) -{ - int fd, iov_count, xtv_count,index; - char *buf; - struct iovec *iov; - struct xtvec *xtv; - - if (argc != 5) { - DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to ireadx\n", argc)); - return INVALID_ARGS; - } - - fd = get_obj(argv[0]); - - if (fd < 0) { - DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0])); - return INVALID_ARGS; - } - - index = get_obj(argv[1]); - - if (index < 0) { - DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1])); - return INVALID_VAR; - } - - buf = buflist[index]->buf; - - iov = (struct iovec *)buf; - iov_count = get_obj(argv[2]); - - if (iov_count < 0) { - DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[2])); - return INVALID_ARGS; - } - - index = get_obj(argv[3]); - - if (index < 0) { - DBG(2, fprintf(outfp, "Unable to find xtvs described by %s\n", argv[3])); - return INVALID_VAR; - } - - buf = buflist[index]->buf; - - xtv = (struct xtvec *)buf; - xtv_count = get_obj(argv[4]); - - if (xtv_count < 0) { - DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[4])); - return INVALID_ARGS; - } - - DBG(3, fprintf(outfp, "ireadx(fd: %d, iov: %p iov_cnt: %d, xtv: %p, xtv_cnt: %d\n", - fd, (void *)iov, iov_count, (void *)xtv, xtv_count)); - - last_ret_val = (long) ireadx(fd, iov, iov_count, xtv, xtv_count); - if (last_ret_val < 0) - my_perror("ireadx"); - my_errno = errno; - last_type = SINT; - - return SUCCESS; -} - - -int do_checkbuf(int argc, char **argv) -{ - int size, val, index, i, offset; - int *ref_buf, *buf; - - if (argc != 4) { - DBG(2, fprintf(outfp, "Need buffer, val, and offset for checkbuf\n")); - return INVALID_ARGS; - } - - index = get_obj(argv[0]); - - if (index < 0) { - DBG(2, fprintf(outfp, "Unable to find buf described by %s\n", argv[0])); - return INVALID_VAR; - } - - buf = (int *)buflist[index]->buf; - - - size = get_obj(argv[1]); - - if (size < 0) { - DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[1])); - return INVALID_ARGS; - } - - val = get_obj(argv[2]); - - if (val < 0) { - DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[2])); - return INVALID_ARGS; - } - - - offset = get_obj(argv[3]); - - if (offset < 0) { - DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[3])); - return INVALID_ARGS; - } - - - ref_buf = (int *)malloc(size); - memset((void *)ref_buf, val, size); - - last_ret_val =0; - buf = (int *)((char *)buf + offset); - for (i=0; (unsigned)i < size/sizeof(int); i++) { - if (buf[i] != ref_buf[i]) { - DBG(2, fprintf(stderr, "At pos %d I found a 0x%08x instead of 0x%08x\n", - i, buf[i], ref_buf[i])); - fprintf(stderr, "At pos %d I found a 0x%08x instead of 0x%08x (val was %d)\n", - i, buf[i], ref_buf[i], val); - last_ret_val = 1; - break; - } - } - - my_errno = errno; - last_type = SINT; - - return SUCCESS; -} diff --git a/libsysio/tests/sysio_tests.c b/libsysio/tests/sysio_tests.c deleted file mode 100644 index 4077996..0000000 --- a/libsysio/tests/sysio_tests.c +++ /dev/null @@ -1,861 +0,0 @@ -#define _BSD_SOURCE - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "xtio.h" -#include "mount.h" -#include "test.h" -#include "test_driver.h" - -/* - * ################################################### - * # Test functions # - * # These functions are used to test libsysio. # - * # Eventually, there should be one of these for # - * # every function document in sysio.h # - * ################################################### - */ -int initilize_sysio() -{ - char *wd; - - /* - * Attempt to set the cwd by getting it out of the - * user's environment. If that does not work, set - * it to / - */ - wd = getenv("PWD"); - if (wd == NULL) { - wd = malloc(5); - strcpy(wd, "/"); - } - if (chdir(wd) != 0) { - DBG(5, sprintf(output, "%schdir: errno %d\n", output, errno)); - my_perror(wd); - my_errno = errno; - last_ret_val = errno; - return SUCCESS; - } - - DBG(3, sprintf(output, "Your current working directory is %s\n", wd)); - last_ret_val = 0; - return SUCCESS; -} - - -int sysio_list(char *path) -{ - int fd; - size_t n; - struct dirent *buf, *dp; - __off_t base; - ssize_t cc; - int numfiles = 0; - - fd = open(path, O_RDONLY); - if (fd < 0) { - my_errno = errno; - last_ret_val = fd; - my_perror(path); - return SUCCESS; - } - - n = 16 * 1024; - buf = malloc(n); - if (!buf) { - my_perror(path); - cc = -1; - goto out; - } - base = 0; - DBG(5, sprintf(output, "About to call getdirentries\n")); - while ((cc = getdirentries(fd, (char *)buf, n, &base)) > 0) { - dp = buf; - while (cc > 0) { - DBG(4, fprintf(outfp, "\t%s: ino %#08x off %#08x type %#08x\n", - dp->d_name, - (unsigned int)dp->d_ino, - (unsigned int)dp->d_off, - (int )dp->d_type)); - - sprintf(output, "%s\n", dp->d_name); - cc -= dp->d_reclen; - dp = (struct dirent *)((char *)dp + dp->d_reclen); - numfiles++; - } - printf("Out of inner loop\n"); - if (!base) - break; - } - - out: - if (cc < 0) { - DBG(2, sprintf(output, "cc barfed\n")); - my_perror(path); - } - - free(buf); - { - int oerrno = errno; - - if (close(fd) != 0) { - DBG(2,sprintf(output, "close barfed\n")); - my_perror(path); - if (cc < 0) - errno = oerrno; - else - cc = -1; - } - } - - last_ret_val = numfiles; - my_errno = errno; - - return SUCCESS; -} - -int sysio_mount(char *from, char *to) -{ - int err; - char *s; - char *buf; - char *cp; - char *fstype, *source, *opts, *target; - - err = 0; - - /* - * Copy everything to a buffer we can modify. - */ - s = buf = malloc(strlen(from) + 1); - if (!buf) { - my_perror(from); - last_ret_val = -1; - my_errno = errno; - return SUCCESS; - } - (void )strcpy(s, from); - - /* - * Eat leading white. - */ - while (*s && *s == ' ' && *s == '\t') - s++; - /* - * Get fstype. - */ - fstype = cp = s; - while (*cp && *cp != ':' && *cp != ' ' && *cp != '\t') - cp++; - if (fstype == cp || *cp != ':') { - DBG(1, sprintf(output, "%s: Missing FS type\n", from)); - err = -1; - goto out; - } - *cp++ = '\0'; - - s = cp; - /* - * Eat leading white. - */ - while (*s && *s == ' ' && *s == '\t') - s++; - /* - * Get source. - */ - source = cp = s; - while (*cp && *cp != ' ' && *cp != '\t') - cp++; - if (source == cp) { - DBG(1, sprintf(output, "%s: Missing source\n", from)); - err = -1; - goto out; - } - if (*cp) - *cp++ = '\0'; - - s = to; - /* - * Eat leading white. - */ - while (*s && *s == ' ' && *s == '\t') - s++; - /* - * Get opts. - */ - opts = cp = s; - while (*cp && *cp != ' ' && *cp != '\t') - cp++; - if (opts == cp) { - DBG(1,sprintf(output, "%s: Missing target\n", to)); - err = -1; - goto out; - } - if (*cp) - *cp++ = '\0'; - - s = cp; - /* - * Eat leading white. - */ - while (*s && *s == ' ' && *s == '\t') - s++; - /* - * Get target - */ - target = cp = s; - while (*cp && *cp != ' ' && *cp != '\t') - cp++; - if (target == cp) { - target = opts; - opts = NULL; - } - if (*cp) - *cp++ = '\0'; - - err = mount(source, target, fstype, 0, opts); - if (err) - my_perror(from); - -out: - free(buf); - last_ret_val = err; - my_errno = errno; - return SUCCESS; -} - -int sysio_chdir(char *newdir) -{ - - if (chdir(newdir) != 0) { - my_perror(newdir); - return -1; - } - /* - buf = getcwd(NULL, 0); - if (!buf) { - my_perror(newdir); - last_ret_val = -1; - my_errno = errno; - return SUCCESS; - } - DBG(4, sprintf(output, "New dir is %s\n", buf)); - - free(buf); - */ - return SUCCESS; -} - -static mode_t get_mode(char *arg, int type, int start_mode); - -#define SYMBOLIC 0 -#define DEFINED 1 -#define NUMERIC 2 -/* - * Change the permissions on a given file - * - * sysio_chmod - * - */ -int sysio_chmod(char *mode_arg, const char *path) -{ - int err; - mode_t mode; - struct stat st; - - /* Get the current mode */ - err = stat(path, &st); - - /* Is the new mode symbolic? */ - if (isalpha(mode_arg[0])) { - /* Could be specifying defines */ - if (mode_arg[0] == 'S') - mode = get_mode(mode_arg, DEFINED, st.st_mode); - else - mode = get_mode(mode_arg, SYMBOLIC, st.st_mode); - } else - mode = get_mode(mode_arg, NUMERIC, st.st_mode); - DBG(3,sprintf(output, "Using a mode of %o and a file of %s\n", mode, path)); - - if (mode == 0) { - DBG(2,sprintf(output, "Invalid mode\n")); - return INVALID_ARGS; - } - - last_ret_val = chmod(path, mode); - my_errno = errno; - return SUCCESS; - -} - - -#define USER_STATE 0 /* Specifies that the users are still being listed */ -#define MODE_STATE_ADD 1 -#define MODE_STATE_REMOVE 2 - -#define READ 00444 -#define WRITE 00222 -#define EXECUTE 00111 - -#define OWNER 00700 -#define GROUP 00070 -#define OTHER 00007 - - -mode_t -get_mode(char *arg, int type, int start_mode) -{ - int i, j,digit, total; - char c; - int state = USER_STATE; - int len = strlen(arg); - unsigned int users = 0; - unsigned int modes = 0; - - - if (type == DEFINED) { - char curr_word[10]; - - total = digit = 0; - j = 0; - DBG(4, sprintf(output, "len is %d\n", len)); - for (i=0; i < len; i++) { - if (arg[i] == '|') { - curr_word[j] = '\0'; - DBG(3, sprintf(output, "Got mode word %s\n", curr_word)); - digit = get_obj(curr_word); - if (digit < 0 ) { - DBG(2, sprintf(output, "Unable to understand mode arg %s\n", - curr_word)); - return -1; - } - total |= digit; - j = 0; - } else - curr_word[j++] = arg[i]; - } - curr_word[j] = '\0'; - DBG(3, sprintf(output, "Got mode word %s\n", curr_word)); - digit = get_obj(curr_word); - if (digit < 0 ) { - DBG(3, sprintf(output, "Unable to understand mode arg %s\n", - curr_word)); - return -1; - } - total |= digit; - return total; - } - - if (type == SYMBOLIC) { - for (i=0; i < len; i++) { - c = arg[i]; - if (state == USER_STATE) { - switch(c){ - case 'u': - users |= OWNER; - break; - case 'g': - users |= GROUP; - break; - case 'o': - users |= OTHER; - break; - case 'a': - users |= (OWNER|GROUP|OTHER); - break; - case '+': - state = MODE_STATE_ADD; - break; - case '-': - state = MODE_STATE_REMOVE; - break; - default: - return 0; - } - } else { - - switch(c){ - case 'r': - modes |= READ; - break; - case 'w': - modes |= WRITE; - break; - case 'x': - modes |= EXECUTE; - break; - default: - return 0; - } - } - } - - if (state == MODE_STATE_ADD) { - return (start_mode | (users & modes)); - } else { - return (start_mode & ~(users & modes)); - } - - } else { - /* Digits should be octal digits, so should convert */ - total = 0; - for (i=0; i < len; i++) { - c = arg[i]; - digit = atoi(&c); - if (digit > 7) - return 0; - for (j=len-i-1; j >0; j--) - digit *= 8; - total += digit; - } - return total; - } - -} - -/* - * Changes the ownership of the file. The new_id - * is of the format owner:group. Either the owner - * or the group may be omitted, but, in order to - * change the group, the : must preced the group. - */ -int sysio_chown(char *new_id, char *file) -{ - char *owner = NULL; - char *group = NULL; - uid_t o_id=-1, g_id=-1; - int len, j, i=0; - int state = 0; /* Correspond to getting owner name */ - - len = strlen(new_id); - for (i=0; i < len; i++) { - - if (new_id[i] == ':') { - /* Group name */ - if (!group) - group = malloc(strlen(new_id) -i +2); - state = 1; /* Now getting group name */ - j = 0; - if (owner) - owner[i] = '\0'; - } - - if (!state) { - /* Getting owner name */ - if (!owner) - owner = malloc(strlen(new_id) +1 ); - owner[i] = new_id[i]; - } else { - /* Group name */ - group[j] = new_id[i]; - j++; - } - } - if (group) - group[i] = '\0'; - else - owner[i] = '\0'; - - /* Are the owner and/or group symbolic or numeric? */ - if (owner) { - if (isdigit(owner[0])) { - /* Numeric -- just convert */ - o_id = (uid_t) atoi(owner); - - } else { - /* No longer support non-numeric ids */ - - DBG(2, sprintf(output, "Error: non-numeric ids unsupported\n")); - return INVALID_ARGS; - } - } - - - - if (group) { - if (isdigit(group[0])) { - /* Numeric -- just convert */ - g_id = (uid_t) atoi(group); - } else { - /* Don't support group names either */ - DBG(2, sprintf(output, "Error: non-numeric ids unsupported\n")); - return INVALID_ARGS; - } - } - - /* Now issue the syscall */ - DBG(4, sprintf(output, "Changing owner of file %s to %d (group %d)\n", - file, o_id, g_id)); - - last_ret_val = chown(file, o_id, g_id); - my_errno = errno; - return SUCCESS; -} - -int sysio_open(char *path, int flags) -{ - last_ret_val = open(path, flags); - my_errno = errno; - DBG(3, sprintf(output, "Returning with errno set to %s (ret val is %d)\n", - strerror(my_errno), (int)last_ret_val)); - return SUCCESS; -} - -int sysio_open3(char *path, int flags, char *mode_arg) -{ - mode_t mode; - - /* Is the new mode symbolic? */ - if (isalpha(mode_arg[0])) { - /* Could be specifying defines */ - if (mode_arg[0] == 'S') - mode = get_mode(mode_arg, DEFINED, 0); - else - mode = get_mode(mode_arg, SYMBOLIC, 0); - } else - mode = get_mode(mode_arg, NUMERIC, 0); - - last_ret_val = open(path, flags, mode); - my_errno = errno; - - return SUCCESS; -} - -int sysio_close(int fd) -{ - - last_ret_val = close(fd); - my_errno = errno; - return SUCCESS; -} - -int sysio_fcntl(int fd, struct cmd_map* cmdptr, char *arg) -{ - int fd_new, index, cmd, flag; - char *cmdname; - void *buf; - - cmd = cmdptr->cmd; - cmdname = cmdptr->cmd_name; - - switch(cmd) { - case F_DUPFD: - fd_new = get_obj(arg); - last_ret_val = fcntl(fd, F_DUPFD, fd_new); - my_errno = errno; - return SUCCESS; - break; - - case F_GETFD: - case F_GETFL: - case F_GETOWN: - /* case F_GETSIG: - case F_GETLEASE: */ - - last_ret_val= fcntl(fd, cmd); - my_errno = errno; - return SUCCESS; - break; - - case F_SETFD: - case F_SETFL: - case F_SETOWN: - /*case F_SETSIG: - case F_SETLEASE: - case F_NOTIFY: */ - flag = atoi(arg); - last_ret_val = fcntl(fd, cmd, flag); - my_errno = errno; - return SUCCESS; - break; - - case F_SETLK: - case F_SETLKW: - case F_GETLK: - - /* Get the buffer to hold the lock structure */ - index = get_obj(arg); - if (index < 0) { - sprintf(output, "Unable to find buffer %s\n", arg+1); - return INVALID_VAR; - } - - buf = buflist[index]; - if (!buf) { - sprintf(output, "Buffer at index %d (mapped by %s) is null\n", - index, arg); - return INVALID_VAR; - } - - last_ret_val = fcntl(fd, cmd, (struct flock *)buf); - my_errno = errno; - return SUCCESS; - default: - /* THis should be impossible */ - return INVALID_ARGS; - } - - return INVALID_ARGS; -} - -void print_stat(struct stat *st) -{ - DBG(3, sprintf(output, "%sstruct stat: \n", output)); - DBG(3, sprintf(output, "%s st_dev: %#16x\n", output, (unsigned int)st->st_dev)); - DBG(3, sprintf(output, "%s st_ino: %#16x\n", output, (unsigned int) st->st_ino)); - DBG(3, sprintf(output, "%s st_mode: %#16x\n", output, st->st_mode)); - DBG(3, sprintf(output, "%s st_nlink: %#16x\n", output, (int)st->st_nlink)); - DBG(3, sprintf(output, "%s st_uid: %#16x\n", output, st->st_uid)); - DBG(3, sprintf(output, "%s st_gid: %#16x\n", output, st->st_gid)); - DBG(3, sprintf(output, "%s st_rdev: %#16x\n", output, (int)st->st_rdev)); - DBG(3, sprintf(output, "%s st_size: %#16x\n", output, (int) st->st_size)); - DBG(3, sprintf(output, "%s st_blksize: %#16x\n", output, (int) st->st_blksize)); - DBG(3, sprintf(output, "%s st_blocks: %#16x\n", output, (int) st->st_blocks)); - DBG(3, sprintf(output, "%s st_atime: %#16x\n", output, (unsigned int) st->st_atime)); - DBG(3, sprintf(output, "%s st_mtime: %#16x\n", output, (unsigned int) st->st_mtime)); - DBG(3, sprintf(output, "%s st_ctime: %#16x", output, (unsigned int) st->st_ctime)); -} - -int sysio_fstat(int fd, void *buf) -{ - int err; - struct stat *st = (struct stat *)buf; - err = fstat(fd, st); - if (err < 0) { - my_perror("fstat"); - } - my_errno = errno; - last_ret_val = err; - print_stat(st); - - return SUCCESS; -} - -int sysio_lstat(char *filename, void *buf) -{ - int err; - struct stat *st = (struct stat *)buf; - err = lstat(filename, st); - if (err < 0) { - my_perror("lstat"); - } - - my_errno = errno; - last_ret_val = err; - print_stat(st); - return SUCCESS; -} - - -int sysio_stat(char *filename, void *buf) -{ - int err; - struct stat *st = (struct stat *)buf; - - err = stat(filename, st); - if (err < 0) { - my_perror("stat"); - } - - my_errno = errno; - last_ret_val = err; - print_stat(st); - return SUCCESS; -} - - -int sysio_getdirentries(int fd, char *buf, size_t nbytes, off_t *basep) -{ - int err; - struct dirent *dp; - - err = getdirentries(fd, buf, nbytes, basep); - last_ret_val = err; - - DBG(4, sprintf(output, "%sRead %d bytes\n", output, err)); - - dp = (struct dirent *)buf; - while (err > 0) { - DBG(3, sprintf(output, "%s\t%s: ino %llu off %llu len %x type %c\n", - output, - dp->d_name, - (unsigned long long )dp->d_ino, - (unsigned long long )dp->d_off, - dp->d_reclen, - (char )dp->d_type)); - err -= dp->d_reclen; - dp = (struct dirent *)((char *)dp + dp->d_reclen); - } - - my_errno = errno; - return last_ret_val; -} - - -int sysio_mkdir(char *path, char *mode_arg) -{ - int err; - mode_t mode; - struct stat st; - - /* Is the new mode symbolic? */ - if (isalpha(mode_arg[0])) { - /* Could be specifying defines */ - if (mode_arg[0] == 'S') - mode = get_mode(mode_arg, DEFINED, st.st_mode); - else - mode = get_mode(mode_arg, SYMBOLIC, st.st_mode); - } else - mode = get_mode(mode_arg, NUMERIC, st.st_mode); - - DBG(3, sprintf(output, "Using a mode of %o and a file of %s\n", mode, path)); - - if (mode == 0) { - DBG(2, sprintf(output, "Invalid mode\n")); - return INVALID_ARGS; - } - - err = mkdir(path, mode); - my_errno = errno; - last_ret_val = err; - return SUCCESS; - -} - -int sysio_creat(char *path, char *mode_arg) -{ - mode_t mode; - int err; - - /* Is the new mode symbolic? */ - if (isalpha(mode_arg[0])) { - /* Could be specifying defines */ - if (mode_arg[0] == 'S') - mode = get_mode(mode_arg, DEFINED, 0); - else - mode = get_mode(mode_arg, SYMBOLIC, 0); - } else - mode = get_mode(mode_arg, NUMERIC, 0); - - DBG(3, sprintf(output, "Using a mode of %o and a file of %s\n", mode, path)); - - if (mode == 0) { - DBG(2, sprintf(output, "Invalid mode\n")); - return INVALID_ARGS; - } - - err = creat(path, mode); - my_errno = errno; - last_ret_val = err; - return SUCCESS; -} - -void print_statvfs(struct statvfs *st) -{ - DBG(3, sprintf(output, "%sstruct statvfs: \n", output)); - DBG(3, sprintf(output, "%s f_bsize: %x\n", output, (unsigned int) st->f_bsize)); - DBG(3, sprintf(output, "%s f_frsize: %x\n", output, (unsigned int) st->f_frsize)); - DBG(3, sprintf(output, "%s f_blocks: %x\n", output, (unsigned int) st->f_blocks)); - DBG(3, sprintf(output, "%s f_bfree: %x\n", output, (unsigned int) st->f_bfree)); - DBG(3, sprintf(output, "%s f_bavail: %x\n", output, (unsigned int) st->f_bavail)); - DBG(3, sprintf(output, "%s f_files: %x\n", output, (unsigned int) st->f_files)); - DBG(3, sprintf(output, "%s f_ffree: %x\n", output, (unsigned int) st->f_ffree)); - DBG(3, sprintf(output, "%s f_favail: %x\n", output, (unsigned int) st->f_favail)); - DBG(3, sprintf(output, "%s f_files: %x\n", output, (unsigned int) st->f_files)); -#if (__GLIBC__ == 2 && __GLIBC_MINOR__ == 1) - DBG(3, sprintf(output, "%s f_fsid: %x\n", output, (unsigned int) st->f_fsid.__val[1])); -#else - DBG(3, sprintf(output, "%s f_fsid: %x\n", output, (unsigned int) st->f_fsid)); -#endif - DBG(3, sprintf(output, "%s f_flag: %x\n", output, (unsigned int) st->f_flag)); - DBG(3, sprintf(output, "%s f_fnamemax: %x\n", output, (unsigned int) st->f_namemax)); -} - - -int sysio_statvfs(char *filename, void *buf) -{ - int err; - struct statvfs *st = (struct statvfs *)buf; - - err = statvfs(filename, st); - if ( err == -1) { - my_perror("statvfs"); - } - - my_errno = errno; - last_ret_val = err; - - print_statvfs(st); - return SUCCESS; -} - -int sysio_fstatvfs(int fd, void *buf) -{ - int err; - struct statvfs *st = (struct statvfs *)buf; - - err = fstatvfs(fd, st); - if (err == -1) { - my_perror("fstatvfs"); - } - - my_errno = errno; - last_ret_val = err; - - print_statvfs(st); - return SUCCESS; -} - -int sysio_umask(char *mode_arg) -{ - mode_t mode; - - /* Is the new mode symbolic? */ - if (isalpha(mode_arg[0])) { - /* Could be specifying defines */ - if (mode_arg[0] == 'S') - mode = get_mode(mode_arg, DEFINED, 0); - else - mode = get_mode(mode_arg, SYMBOLIC, 0); - } else - mode = get_mode(mode_arg, NUMERIC, 0); - - last_ret_val = umask(mode); - my_errno = errno; - return SUCCESS; -} - -int sysio_mknod(char *path, char *mode_arg, dev_t dev) -{ - int err; - int mode; - - mode = get_obj(mode_arg); - - if (mode < 0) { - DBG(2,sprintf(output, "Cant get mode from %s\n", mode_arg)); - fprintf(stderr, "Cant get mode from %s\n", mode_arg); - return INVALID_VAR; - } - - err = mknod(path, (mode_t) mode, dev); - if (err < 0) - my_perror("mknod"); - - last_ret_val = err; - my_errno = errno; - return SUCCESS; -} diff --git a/libsysio/tests/test_all.pl b/libsysio/tests/test_all.pl deleted file mode 100755 index b5f7b86..0000000 --- a/libsysio/tests/test_all.pl +++ /dev/null @@ -1,232 +0,0 @@ -#!/usr/bin/perl -w - -# -# VERY basic functionality test for sysio. To run, just type ./test_all.pl -# Absolutely no guarantees for running on alpha/cplant -# - -use strict; -use FindBin; - -use Cwd 'abs_path'; - -my $alpha_arg = ""; -my $use_system = 1; -my $is_broke = 1; # Don't test certain areas known to not work on Cplant -my $arg_count = @ARGV; -foreach my $arg (@ARGV) { - if ($arg eq "-alpha") { - $alpha_arg = "-alpha"; - } elsif ($arg eq "-nosystem") { - $use_system = 0; - } -} -my $alpha_env = $ENV{"IS_ALPHA"}; -# Check the environment vars -if (defined($alpha_env) && ($alpha_env eq "yes")) { - $alpha_arg = "-alpha"; -} - -my $failures = 0; -my $success = 0; -# Get cwd.. -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 eq "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} \ - {open, nm=\"/dev/fd/0\",fd=0,m=0} \ - {creat, ft=chr,nm=\"/dev/fd/1\",pm=0200,mm=0+1} \ - {open, nm=\"/dev/fd/1\",fd=1,m=1} \ - {creat, ft=chr,nm=\"/dev/fd/2\",pm=0200,mm=0+2} \ - {open, nm=\"/dev/fd/2\",fd=2,m=1} \ - {cd, dir=\"$home\"} \ - $extras "; - -my $res; - -if ($use_system == 1) { - # Test for tmp_dir. If it exists, fail - # The tmp_dir should be removed after a successful - # test run, but is kept if anything fails - if (-e "$cwd/tmp_dir") { - print STDERR "ERROR! tmp_dir already exists.\n"; - print STDERR "Need to remove tmp_dir for test to run properly\n"; - exit 1; - } - - # Will use this directory... - system("mkdir -p $cwd/tmp_dir"); - - # Create a couple of files and subdirectories for use in the tests - system("mkdir -p $cwd/tmp_dir/test1"); - system("mkdir -p $cwd/tmp_dir/test2"); - - system("cp $testdir/helper.pm $cwd/tmp_dir/test1"); -} else { - $res = `perl $testdir/setup.pl $alpha_arg $cwd`; - chop($res); - if ($res ne "setup successful") { - print "Test setup failed with $res, bailing out\n"; - exit 1; - } -} - - -if (($alpha_arg eq "") || ($is_broke == 0)) { - # Test getdirentries - $res = `perl $testdir/test_list.pl $alpha_arg $cwd/tmp_dir`; - chop($res); - if ($res ne "list test successful") { - print "Basic getdirentries test failed with message: $res\n"; - $failures++; - } else { - print "test_list finished successfully\n"; - $success++; - } -} - -# Test path -my $path1 = abs_path($testdir); -my @resarr = `perl $testdir/test_path.pl $alpha_arg $path1 $cwd $cwd/tmp_dir`; -$res = $path1.": d\n"; -if ($resarr[0] ne $res) { - print "path test returned $resarr[0] instead of $res\n"; - $failures++; -} else { - $res = $cwd.": d\n"; - if ($resarr[1] ne $res) { - print "path test returned $resarr[1] instead of $res\n"; - $failures++; - } else { - $res = $cwd."/tmp_dir: d\n"; - if ($resarr[2] ne $res) { - print "path test returned $resarr[2] instead of $res\n"; - $failures++; - } else { - print "test_path finished successfully\n"; - $success++; - } - } -} - -# Test getcwd -$res = `perl $testdir/test_getcwd.pl $alpha_arg $cwd/tmp_dir/test1`; -chop($res); -if ($res ne "getcwd test successful") { - print "getcwd test failed with message: $res\n"; - $failures++; -} else { - $success++; - print "test_getcwd finished successfully\n"; -} - -# Test copy -$res = `perl $testdir/test_copy.pl $alpha_arg $cwd/tmp_dir/test1/helper.pm $cwd/tmp_dir/helper.pm`; -chop($res); -if ($res ne "copy test successful") { - print "copy test failed with message: $res\n"; - $failures++; -} else { - $success++; - print "test_copy finished successfully\n"; -} - -# Test stats -$res = `perl $testdir/test_stats.pl $alpha_arg $use_system $cwd/tmp_dir/test1/helper.pm`; -chop($res); -if ($res ne "stat test successful") { - print "stat test failed with message: $res\n"; - $failures++; -} else { - $success++; - print "test_stats finished successfully\n"; -} - -# Test stdfd -$res = `echo "foobar" | perl $testdir/test_copy.pl $alpha_arg -o /dev/stdin /dev/stdout`; -chop($res); -if ($res ne "copy test successful") { - print "stdfd test failed with message: $res\n"; - $failures++; -} else { - $success++; - print "test_stdfd finished successfully\n"; -} - -# Test symlink -$res = `perl $testdir/test_symlink.pl $alpha_arg $cwd/tmp_dir/test1/helper.pm $cwd/tmp_dir/helper.foo`; -chop($res); -if ($res ne "Symlink test successful") { - print "symlink test failed with message: $res\n"; - $failures++; -} else { - $success++; - print "test_symlink finished successfully\n"; -} - -# Test r/w calls -$res = `perl $testdir/test_rw.pl $alpha_arg $cwd/tmp_dir/tmp.foo`; -chop($res); -if ($res ne "rw test successful") { - print "rw test failed with message: $res\n"; - $failures++; -} else { - $success++; - print "rw test finished successfully\n"; -} - -# Test strided I/O -$res = `perl $testdir/test_strided.pl $alpha_arg $cwd/tmp_dir/tmp2.foo`; -chop($res); -if ($res ne "strided IO test successful") { - print "strided IO test failed with message: $res\n"; - $failures++; -} else { - $success++; - print "strided IO test finished successfully\n"; -} - -print "$failures tests failed and $success tests succeeded\n"; - -# cleanup -- only if no failures -if ($failures == 0) { - if ($use_system == 1) { - system(`rm -rf $cwd/tmp_dir`); - } else { - $res = `perl $testdir/cleanup.pl $alpha_arg $cwd`; - chop($res); - if ($res ne "cleanup successful") { - print "Test cleanup failed with $res, bailing out\n"; - exit 1; - } - } -} -exit $failures; diff --git a/libsysio/tests/test_chown.c b/libsysio/tests/test_chown.c new file mode 100644 index 0000000..251f299 --- /dev/null +++ b/libsysio/tests/test_chown.c @@ -0,0 +1,143 @@ +/* + * This Cplant(TM) source code is the property of Sandia National + * Laboratories. + * + * This Cplant(TM) source code is copyrighted by Sandia National + * Laboratories. + * + * The redistribution of this Cplant(TM) source code is subject to the + * terms of the GNU Lesser General Public License + * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) + * + * Cplant(TM) Copyright 1998-2007 Sandia Corporation. + * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive + * license for use of this work by or on behalf of the US Government. + * Export of this program may require a license from the United States + * Government. + */ + +/* + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Questions or comments about this library should be sent to: + * + * Lee Ward + * Sandia National Laboratories, New Mexico + * P.O. Box 5800 + * Albuquerque, NM 87185-1110 + * + * lee@sandia.gov + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#if defined(SYSIO_LABEL_NAMES) +#include "sysio.h" +#endif +#include "test.h" + +/* + * Test chown call + * + * Usage: chown + * + */ + +static void usage(void); + +int +main(int argc, char *const argv[]) +{ + int (*chown_func)(const char *, uid_t, gid_t); + int (*stat_func)(const char *, struct stat *); + int i; + int err; + int n; + char *path; + uid_t uid; + gid_t gid; + struct stat stbuf; + extern int _test_sysio_startup(void); + + chown_func = SYSIO_INTERFACE_NAME(chown); + stat_func = SYSIO_INTERFACE_NAME(stat); + + /* + * Parse command line arguments. + */ + while ((i = getopt(argc, argv, "")) != -1) + switch (i) { + + default: + usage(); + } + + /* + * Init sysio lib. + */ + err = _test_sysio_startup(); + if (err) { + errno = -err; + perror("sysio startup"); + exit(1); + } + + n = argc - optind; + if (n < 3) usage(); + + path = argv[optind++]; + uid = atoi(argv[optind++]); + gid = atoi(argv[optind++]); + + do { + err = (*chown_func)(path, uid, gid); + if (err != 0) { + perror(path); + break; + } + err = (*stat_func)(path, &stbuf); + if (err != 0) { + perror(path); + break; + } + (void )printf("uid now %ld, gid now %ld\n", + (long )stbuf.st_uid, (long )stbuf.st_gid); + } while (0); + + /* + * Clean up. + */ + _test_sysio_shutdown(); + + return err ? -1 : 0; +} + +static void +usage() +{ + + (void )fprintf(stderr, + "Usage: chown" + " \n"); + + exit(1); +} diff --git a/libsysio/tests/test_copy.bash b/libsysio/tests/test_copy.bash deleted file mode 100644 index 7217ba0..0000000 --- a/libsysio/tests/test_copy.bash +++ /dev/null @@ -1,129 +0,0 @@ -#!/bin/bash -############################################################################# -# -# This Cplant(TM) source code is the property of Sandia National -# Laboratories. -# -# This Cplant(TM) source code is copyrighted by Sandia National -# Laboratories. -# -# The redistribution of this Cplant(TM) source code is subject to the -# terms of the GNU Lesser General Public License -# (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) -# -# Cplant(TM) Copyright 1998-2003 Sandia Corporation. -# Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive -# license for use of this work by or on behalf of the US Government. -# Export of this program may require a license from the United States -# Government. -# -############################################################################# - - -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# Questions or comments about this library should be sent to: -# -# Lee Ward -# Sandia National Laboratories, New Mexico -# P.O. Box 5800 -# Albuquerque, NM 87185-1110 -# -# lee@sandia.gov - -############################################################################ -# -# File: test_copy.bash -# -# Description: Script to exercise the sysio library. -# -# Usage: -# test_copy.bash -# -# Limitations: -# 1. Doesn't exercise all of sysio. -# 2. Uses hardcoded /native prefix for file names which may not be the -# final solution. -# -############################################################################ - -# defaults - change as necessary for local system -SCRATCH=test_copy.$$ -CWD=`pwd` -SRC=${CWD}/test_copy.src -DEST=${CWD}/test_copy.dest -PREFIX=/native - -# main processing logic follows -cp /dev/null $SCRATCH -rm -f $SRC $DEST -if [ -f $SRC ] -then - echo "Could not remove $SRC - test INDETERMINATE" >> $SCRATCH - exit 5 -fi -if [ -f $DEST ] -then - echo "Could not remove $DEST - test INDETERMINATE" >> $SCRATCH - exit 5 -fi - -if ( ! cp /usr/include/stdio.h $SRC ) # just picked something handy -then - echo "Could not create source file - test INDETERMINATE" >> $SCRATCH - exit 5 -fi - - -# -# Run the test -# -./test_copy ${PREFIX}/${SRC} ${PREFIX}/${DEST} -SRC_VERF=`cksum $SRC | awk '{ print $1 }'` -DEST_VERF=`cksum $DEST | awk '{ print $1 }'` -if [ "$SRC_VERF" -ne "$DEST_VERF" ] -then - echo "The source and destination files did not match; test FAILED" >> $SCRATCH 2>&1 -else - echo "The source and destination files matched; test PASSED" >> $SCRATCH 2>&1 -fi - -# -# Report test results -# -echo "" -PASSCNT=1 -if grep "FAILED" $SCRATCH > /dev/null -then - echo "TEST $0 FAILED - found failed" - cat $SCRATCH - RC=8 -elif test `grep -c "PASSED" $SCRATCH` -ne $PASSCNT > /dev/null -then - echo "TEST $0 FAILED - wrong pass count" - cat $SCRATCH - RC=4 -else - echo "TEST $0 PASSED" - RC=0 - -fi - -if [ -z "$NOCLEANUP" ] -then - rm -f $SCRATCH $SRC $DEST -fi - -exit $RC diff --git a/libsysio/tests/test_copy.c b/libsysio/tests/test_copy.c index bff098a..e1954ff 100644 --- a/libsysio/tests/test_copy.c +++ b/libsysio/tests/test_copy.c @@ -41,8 +41,6 @@ * lee@sandia.gov */ -#define _BSD_SOURCE - #include #include #include @@ -52,6 +50,7 @@ #include #include #include +#include #if defined(SYSIO_LABEL_NAMES) #include "sysio.h" diff --git a/libsysio/tests/test_copy.pl b/libsysio/tests/test_copy.pl deleted file mode 100755 index 6912dcc..0000000 --- a/libsysio/tests/test_copy.pl +++ /dev/null @@ -1,218 +0,0 @@ -#!/usr/bin/perl -w - -# -# copy test: Copy a file from src to dest and verify that the new file -# : is the same as the old -# - -use IPC::Open2; - -use strict; -use FindBin; -use lib "$FindBin::Bin"; -use helper; - -sub usage -{ - print "Usage: ./test_copy.pl [-alpha] : Copy a file from src to dest\n"; - exit(-1); -} - -sub process_cmd -{ - my ($src, $dest, $overwrite, $is_alpha) = @_; - -# Get tests directory - my $testdir = $FindBin::Bin; - - eval { - if ($is_alpha == 0) { - open2(\*OUTFILE, \*CMDFILE, "$testdir/test_driver --np"); - } else { - open2(\*OUTFILE, \*CMDFILE, "yod -quiet -sz 1 $testdir/test_driver --np"); - } - }; - - if ($@) { - if ($@ =~ /^open2/) { - warn "open2 failed: $!\n$@\n"; - return; - } - die; - - } - - my $outfh = \*OUTFILE; - my $cmdfh = \*CMDFILE; - - - - if ($is_alpha == 0) { - helper::send_cmd($cmdfh, $outfh, "init", "CALL init\n"); - } - - # Get the filesize of src - my $size = -s $src; - my $bufsize; - - # If reading from stdin, just read one line - my $line; - if ($src eq "/dev/stdin") { - $line = ; - $size = length($line); - } - - if ( $size > 1024) { # Arbitrary limit - $bufsize = 1024; - } else { - $bufsize = $size; - } - - my $cmdstr; - # Open src - if ($src ne "/dev/stdin") { - $cmdstr = '$src = CALL open '."$src O_RDONLY\n"; - helper::send_cmd($cmdfh, $outfh, "open", $cmdstr); - helper::verify_cmd($cmdfh, $outfh, "open $src"); - } - if ($dest ne "/dev/stdout") { - # Open dest - my $flags = "O_WRONLY|O_CREAT"; - if ($overwrite == 0) { - $flags .= "|O_EXCL"; - } - $cmdstr = '$dest = CALL open '."$dest $flags 0777\n"; - helper::send_cmd($cmdfh, $outfh, "open", $cmdstr); - my $destfile = helper::verify_cmd($cmdfh, $outfh, "open $dest"); - } - - # Allocate buffer - $cmdstr = '$buf = ALLOC '."$bufsize\n"; - helper::send_cmd($cmdfh, $outfh, "ALLOC", $cmdstr); - - # 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 ".'0 $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"); - } - - if ($dest eq "/dev/stdout") { - $cmdstr = "CALL write ".'1 $buf '."$readb\n"; - } else { - $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); - - $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"); - - if ($readb != oct($res)) { - print STDOUT "ERROR! Read $readb bytes but got back $res bytes\n"; - exit 1; - } - - $bytes -= $readb; - } - - # Clean up - if ($src ne "/dev/stdin") { - $cmdstr = 'CALL close $src'."\n"; - helper::send_cmd($cmdfh, $outfh, "close", $cmdstr); - } - if ($dest ne "/dev/stdout") { - $cmdstr = 'CALL close $dest'."\n"; - helper::send_cmd($cmdfh, $outfh, "close", $cmdstr); - } - if ($src ne "/dev/stdin") { - my $cmd = "cmp $src $dest " . '2>&1'; - my $cmpstr = qx($cmd); - my $exitval = $? >> 8; - if ($exitval != 0) { - if ($exitval == 1) { - print STDOUT "ERROR! File $src differs from $dest\n"; - print STDOUT "Comparison returned $cmpstr"; - } else { - print STDOUT "ERROR! File comparison failed with msg $cmpstr"; - } - 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; -} - -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[$i++]; -my $dest = $ARGV[$i]; - - -process_cmd($src, $dest, $overwrite, $is_alpha); - - -exit 0; diff --git a/libsysio/tests/test_driver.c b/libsysio/tests/test_driver.c deleted file mode 100644 index cbc6415..0000000 --- a/libsysio/tests/test_driver.c +++ /dev/null @@ -1,1085 +0,0 @@ -#ifndef _BSD_SOURCE -#define _BSD_SOURCE -#endif -#ifndef _XOPEN_SOURCE -#define _XOPEN_SOURCE 500 -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "xtio.h" -#include "mount.h" -#include "test.h" -#include "test_driver.h" - - -struct queue_t; - -typedef struct cmd_tree_t { - char *res_name; - char *val; - int arg_count; - struct queue_t *children; -} cmd_tree; - -struct queue_t { - char *val; - cmd_tree *cmd; - struct queue_t *next; -}; - -struct cmd_t cmd_list[] = { - {"alloc", get_buffer, usage_get_buffer}, - {"chdir", test_do_chdir, usage_chdir}, - {"checkbuf", do_checkbuf, usage_checkbuf}, - {"chmod", test_do_chmod, usage_chmod}, - {"chown", test_do_chown, usage_chown}, - {"clear", test_do_clear, usage_clear}, - {"close", test_do_close, usage_close}, - {"cmpstr", cmp_bufs, usage_cmpbufs}, - {"creat", test_do_creat, usage_creat}, - {"debug", test_do_setdebug, usage_setdebug}, - {"dup", test_do_dup, usage_dup}, - {"dup2", test_do_dup2, usage_dup2}, - {"endian", get_endian, usage_endian}, - {"exit", test_do_exit, usage_exit}, - {"fcntl", test_do_fcntl, usage_fcntl}, - {"fdatasync", test_do_fdatasync, usage_fdatasync}, - {"fill", test_do_fillbuff, usage_do_fillbuff}, - {"free", free_buffer, usage_free_buffer}, - {"fstat", test_do_fstat, usage_fstat}, - {"fstatvfs", test_do_fstatvfs, usage_fstatvfs}, - {"fsync", test_do_fsync, usage_fsync}, - {"ftruncate", test_do_ftruncate, usage_ftruncate}, - {"getcwd", test_do_getcwd, usage_getcwd}, - {"getdirentries", test_do_getdirentries, usage_getdirentries}, - {"init", test_do_init, usage_init}, - {"init_iovec", test_do_init_iovec, usage_init_iovec}, - {"init_xtvec", test_do_init_xtvec, usage_init_xtvec}, - {"ioctl", test_do_ioctl, usage_ioctl}, - {"iodone", test_do_iodone, usage_iodone}, - {"iowait", test_do_iowait, usage_iowait}, - {"ipread", test_do_ipread, usage_ipread}, - {"ipreadv", test_do_ipreadv, usage_ipreadv}, - {"ipwrite", test_do_ipwrite, usage_ipwrite}, - {"ipwritev", test_do_ipwritev, usage_ipwritev}, - {"iread", test_do_iread, usage_iread}, - {"ireadv", test_do_ireadv, usage_ireadv}, - {"ireadx", test_do_ireadx, usage_ireadx}, - {"iwrite", test_do_iwrite, usage_iwrite}, - {"iwritev", test_do_iwritev, usage_iwritev}, - {"iwritex", test_do_iwritex, usage_iwritex}, - {"list", test_do_list, usage_list}, - {"lseek", test_do_lseek, usage_lseek}, - {"lstat", test_do_lstat, usage_lstat}, - {"mkdir", test_do_mkdir, usage_mkdir}, - {"mknod", test_do_mknod, usage_mknod}, - {"mount", test_do_mount, usage_mount}, - {"open", test_do_open, usage_open}, - {"printbuf", test_do_printbuf, usage_do_printbuf}, - {"printline", test_do_printline, usage_printline}, - {"pread", test_do_pread, usage_pread}, - {"preadv", test_do_preadv, usage_preadv}, - {"pwritev", test_do_pwritev, usage_pwritev}, - {"pwrite", test_do_pwrite, usage_pwrite}, - {"quit", test_do_exit, usage_exit}, - {"read", test_do_read, usage_read}, - {"readv", test_do_readv, usage_readv}, - {"readx", test_do_readx, usage_readx}, - {"rmdir", test_do_rmdir, usage_rmdir}, - {"setbuf", do_setbuf, usage_setbuf}, - {"sizeof", get_sizeof, usage_sizeof}, - /* {"setoutput", test_do_setoutput, usage_setoutput}, */ - {"stat", test_do_stat, usage_stat}, - {"statvfs", test_do_statvfs, usage_statvfs}, - {"symlink", test_do_symlink, usage_symlink}, - {"truncate", test_do_truncate, usage_truncate}, - {"umask", test_do_umask, usage_umask}, - {"umount", test_do_umount, usage_umount}, - {"unlink", test_do_unlink, usage_unlink}, - {"write", test_do_write, usage_write}, - {"writev", test_do_writev, usage_writev}, - {"writex", test_do_writex, usage_writex}, - {NULL, NULL, NULL} -}; - -int run_cmd(cmd_tree *cmd_arg); -cmd_tree* build_tree(char **cmd, int *length, int total); -/* - * ################################################## - * # Memory functions # - * # Intended to allow users to gain access to # - * # buffers of memory to be manipulated later # - * ################################################## - */ - -void * alloc_buff32(unsigned int size, int align) -{ - void* buf; - long buf_ptr; - - /* - if ((err = memalign(&buf, align, size)) != 0) { - perror("memalign"); - return 0; - } - */ - size += align; - buf = malloc(size); - align--; - DBG(3, fprintf(outfp, "Buf is at %p\n", (void *)buf)); - buf_ptr = (long)buf + ((long)buf & align); - - DBG(3, fprintf(outfp, "Buf is at %p\n", (void *)buf_ptr)); - return (void *)buf_ptr; -} - -void free_buf32(void * ptr) -{ - free(ptr); -} - -long alloc_buff64(unsigned int size, int align) -{ - char * buf; - long ret_value; - - /* - if (memalign((void **)&buf, align, size)) - return 0; - */ - size += align; - buf = malloc(size); - align--; - ret_value = (long)buf + ((long)buf & align); - return ret_value; -} - -void free_buf64(long ptr) -{ - free((char *)ptr); -} - - -/* - * Hash function for variables. Shamelessly stolen - * from the ext3 code - */ -unsigned int dx_hack_hash (const char *name, int len) -{ - unsigned int hash0 = 0x12a3fe2d, hash1 = 0x37abe8f9; - while (len--) - { - unsigned int hash = hash1 + (hash0 ^ (*name++ * 7152373)); - if (hash & 0x80000000) hash -= 0x7fffffff; - hash1 = hash0; - hash0 = hash; - } - return hash0; -} - -struct var_mapping *get_map(char *var_name) -{ - int index; - struct var_mapping_list *curr; - - - if (var_name[0] == '$') { - /* It is a name--chop off the initial and get the mapping $ */ - var_name++; - } - - index = dx_hack_hash(var_name, strlen(var_name)); - index %= MAX_VARS -1; - - DBG(5, fprintf(outfp, "Got index of %d for %s\n", index, var_name)); - curr = &map[index]; - - while ((curr) && (curr->map.obj != -1) ) { - if ( (curr->map.name == NULL) || (strcmp(curr->map.name, var_name)) ) - curr = curr->next; - else - return &curr->map; - } - - return NULL; -} - -char *get_str(char *var_name) -{ - /* See if it is a quoted string */ - if (var_name[0] == '"') { - /* Chop off the beginning and end quotes and return the string */ - int len = strlen(var_name); - var_name[len-1] = '\0'; - 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 did_alloc=0; - int obj=0, got_obj=0; - - DBG(5, fprintf(outfp, "Getting object for %s\n", var_name)); - - /* If var_name is a digit, we assume it is a literal */ - if (isdigit(var_name[0])) - return atoi(var_name); - - /* - * Check for '|', indicates that one or more values are or'd - * together - */ - 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); - } else - obj |= atoi(str1); - } else { - var_map = get_map(str1); - if (!var_map) { - if (did_alloc) - free(str1); - return -1; - } - obj |= var_map->obj; - } - - if (did_alloc) { - did_alloc = 0; - free(str1); - } - got_obj++; - } - - if (got_obj) - return obj; - - var_map = get_map(var_name); - if (!var_map) - return -1; - else - return var_map->obj; -} - - -void store_result(char *var_name, int result) -{ - int index = dx_hack_hash(var_name, strlen(var_name)); - struct var_mapping_list *map_obj; - struct var_mapping_list *new_map; - index %= MAX_VARS -1 ; - - if (map[index].map.obj >= 0) { - - /* Got a collision --just chain it*/ - new_map = malloc(sizeof(struct var_mapping_list)); - - map_obj = &map[index]; - while (map_obj->next != NULL) - map_obj = map_obj->next; - - map_obj->next = new_map; - } else - new_map = &map[index]; - - new_map->map.name = malloc(strlen(var_name) + 1); - strcpy(new_map->map.name, var_name); - new_map->map.obj = result; - new_map->map.type = last_type; - new_map->next = NULL; - DBG(3, fprintf(outfp, "Stored %d in index %d hashed with %s\n", - result, index, var_name)); -} - -void free_obj(char *obj_name) -{ - int index; - struct var_mapping_list *prev, *curr; - - - /* See if it is a variable name */ - if (obj_name[0] == '$') { - /* It is a name--chop off the initial $ */ - obj_name++; - } - index = dx_hack_hash(obj_name, strlen(obj_name)); - index %= MAX_VARS -1; - - DBG(5, fprintf(outfp, "Got index of %d\n", index)); - curr = &map[index]; - - prev = NULL; - - while ((curr) && (curr->map.obj != -1) ) { - if (strcmp(curr->map.name, obj_name)) { - prev = curr; - curr = curr->next; - } else - break; - } - - /* Remove the object from the chain */ - if (prev) - prev->next = curr->next; - - curr->map.obj = -1; - free(curr->map.name); - if (prev) - free(curr); -} - - -/* - * Given a long string, returns the string divided into - * whitespace seperated words in list. Returns the number - * of words - */ -int parser(char *str, char** list) -{ - int len, i=0, j=0, counter=-1; - int in_quotes = 0; - char *new_str; - - - len = strlen(str); - DBG(5, fprintf(outfp, "str is %s len is %d\n", str, len)); - while (i < len) { - - if ((i==0) || ((str[i] == ' ') && (in_quotes == 0)) ) { - if (i != 0) { - new_str[j] = '\0'; - DBG(5, fprintf(outfp, "Got word %s\n", list[counter])); - i++; - } - while ((str[i] == ' ') && (in_quotes == 0)) - i++; - counter++; - new_str = list[counter] = malloc(MAX_WORD); - j = 0; - - } - - new_str[j] = str[i]; - if (str[i] == '"') { - if (in_quotes) - in_quotes = 0; - else - in_quotes = 1; - } - if ((str[i] == ' ') && (in_quotes==0)){ - while (str[i+1] == ' ') - i++; - new_str[j] = '\0'; - } - i++; - j++; - - } - new_str[j] = '\0'; - DBG(5, fprintf(outfp, "Got word %s\n", list[counter])); - return counter +1; -} - - -int execute_cmd(char *cmd, char **args, int arg_count) -{ - int i = 0; - - if (!strcmp(cmd, "help")) { - if (arg_count > 0) { - while(cmd_list[i].cmd != NULL) { - if (!strcmp(cmd_list[i].cmd, args[0])) { - (cmd_list[i].usage)(); - return 0; - } - i++; - } - } else { - do_help(); - return 0; - } - return -1; - } - while(cmd_list[i].cmd != NULL) { - if (!strcmp(cmd_list[i].cmd, cmd)) { - return (cmd_list[i].func)(arg_count, args); - } - i++; - } - DBG(2, fprintf(outfp, "Command %s was invalid\n", cmd)); - return INVALID_CMD; -} - -int get_args(struct queue_t *child, char** list, int num_args, int argnum) -{ - char *argval; - - if (child->val != NULL) { - argval = child->val; - } else if (child->cmd != NULL) { - run_cmd(child->cmd); - if (child->cmd->res_name != NULL) - argval = child->cmd->res_name; - else { - char tmpstr[50]; - int val = last_ret_val; - sprintf(tmpstr, "%x", val); - argval = tmpstr; - } - } else { - DBG(2, fprintf(outfp, "I am confused\n")); - return INVALID_ARGS; - } - - list[argnum] = malloc(strlen(argval) + 1); - strcpy(list[argnum], argval); - argnum++; - - if (argnum == num_args) - return SUCCESS; - else if (child->next == NULL) { - DBG(2, fprintf(outfp, "Only on arg number %d out of %d, but ran out of children\n", - argnum, num_args)); - return INVALID_ARGS; - } else - return get_args(child->next, list, num_args, argnum); - - return SUCCESS; -} - -int run_cmd(cmd_tree *cmd_arg) -{ - char cmdstr[MAX_COMMAND]; - char *cmdptr; - char **args; - int res, i; - struct buf_t *buf; - char *cmd; - struct queue_t *child; - - if (cmd_arg == NULL) - return INVALID_CMD; - - cmd = cmd_arg->val; - cmdptr = cmdstr; - child = cmd_arg->children; - if ( (!strcmp("exit", cmd)) || (!strcmp("quit", cmd)) || - (!strcmp("EXIT", cmd)) || (!strcmp("QUIT", cmd)) ) - strcpy(cmdstr, "exit"); - else if (!strcmp("ALLOC", cmd)) - strcpy(cmdstr, "alloc"); - else if (!strcmp("FREE", cmd)) - strcpy(cmdstr, "free"); - else if (!strcmp("HELP", cmd)) - strcpy(cmdstr, "help"); - else if (!strcmp("CALL", cmd)) { - if (cmd_arg->arg_count < 1) { - DBG(2, fprintf(outfp, "Need at least one command\n")); - return INVALID_CMD; - } - - cmd_arg->arg_count--; - if (child->val != NULL) - cmdptr = child->val; - else { - DBG(2, fprintf(outfp, "Need to specify command\n")); - return INVALID_CMD; - } - - DBG(3, fprintf(outfp, "Got cmd %s\n", child->val)); - if (cmd_arg->arg_count != 0) - child = child->next; - - - } else if (!strcmp("DEPOSIT", cmd)) - strcpy(cmdstr, "fill"); - else if (!strcmp("PRINT", cmd)) - strcpy(cmdstr, "printbuf"); - else { - if (cmd_arg->res_name != NULL) { - /* - * If the cmd is not a valid command, just store it - */ - res = get_obj(cmd_arg->children->val); - last_type = UINT; - if (res < 0) { - /* Just store it as a string */ - buf = (struct buf_t *)malloc(sizeof(struct buf_t)); - buf->len = strlen(cmd); - buf->buf = (char *)malloc(buf->len+1); - strcpy(buf->buf, cmd_arg->children->val); - buflist[next] = buf; - res = next; - DBG(3, fprintf(outfp, "Stored %s in index %d\n", (char *)buf->buf, next)); - next++; - last_type = STR; - } - store_result(cmd_arg->res_name, res); - return SUCCESS; - } else - return INVALID_CMD; - } - - - if (cmd_arg->arg_count == 0) - args = NULL; - else { - args = (char **)malloc(sizeof(char *)*cmd_arg->arg_count); - get_args(child, args, cmd_arg->arg_count, 0); - } - - DBG(3, fprintf(outfp, "CMD: %s\n ARGS: ",cmdptr)); - for (i=0; i < cmd_arg->arg_count; i++) - DBG(3, fprintf(outfp, "%s ", args[i])); - DBG(3, fprintf(outfp, "\n")); - res = execute_cmd(cmdptr, args, cmd_arg->arg_count); - if (cmd_arg->res_name != NULL) - store_result(cmd_arg->res_name, last_ret_val); - - return res; -} - - -int is_command(char *name) -{ - if ( (strcmp(name, "CALL")) && (strcmp(name, "FILL")) && - (strcmp(name, "ALLOC")) && (strcmp(name, "PRINT")) && - (strcmp(name, "FREE")) && (strcmp(name, "exit")) && - (strcmp(name, "HELP")) && (strcmp(name, "help")) && - (strcmp(name, "quit")) && (strcmp(name, "EXIT")) && - (strcmp(name, "QUIT")) && (strcmp(name, "DEPOSIT")) ) - return 0; - - return 1; -} - -#define ARGS 1 -int get_type(char *arg0) -{ - if ((arg0[0] == '(') || (is_command(arg0)) ){ - return 2; - } - - return ARGS; -} - - -int add_args(char **cmd, int length, int total, cmd_tree *tree) -{ - int new_len, type; - struct queue_t *old, *new; - - old = tree->children; - while ((old) && (old->next)) - old = old->next; - new = (struct queue_t *)malloc(sizeof(struct queue_t)); - if (old) - old->next = new; - else - tree->children = new; - new->next = NULL; - - type = get_type(cmd[0]); - if (type < 0) { - DBG(2, fprintf(outfp, "Don't understand %s\n", cmd[0])); - return INVALID_CMD; - } - if (type == ARGS) { - new->val = (char *)malloc(strlen(cmd[0])+1); - strcpy(new->val, cmd[0]); - new->cmd = NULL; - total = 1; - } else { - new_len = length; - if (cmd[0][0] == '(') { - new_len--; - } - - new->val = NULL; - new->cmd = build_tree(&cmd[1], &new_len, total); - if (new->cmd == NULL) { /* Invalid command */ - return length; /* Pretend we used everything up */ - } - total = (length - new_len); - DBG(4, fprintf(outfp, "Used %d bytes\n", total)); - } - - return total; -} - -void free_tree(cmd_tree* tree) -{ - if (!tree) - return; - - if (tree->children) { - struct queue_t *child = tree->children; - struct queue_t *next; - do { - next = child->next; - if (child->cmd) - free_tree(child->cmd); - free(child->val); - free(child); - child = next; - } while (child); - } - - if (tree->res_name) - free(tree->res_name); - - if (tree->val) - free(tree->val); - - free(tree); -} - -cmd_tree* build_tree(char **cmd, int *length, int total) -{ - int index = 0, used_args = 0; - cmd_tree *tree; - if ((*length < 0) || (!cmd) || (*cmd == NULL)) - return NULL; - - - DBG(4, fprintf(outfp, "length is %d\n", *length)); - tree = (cmd_tree *)malloc(sizeof(cmd_tree)); - tree->res_name = NULL; - tree->children = NULL; - if (cmd[index][0] == '$') { - tree->res_name = (char *)malloc(strlen(cmd[index])+1); - strcpy(tree->res_name, (char*)(cmd[index]+1)); - index++; - if (cmd[index][0] == '=') - index++; - } else - tree->res_name = NULL; - - if (is_command(cmd[index]) == 0) { - if (tree->res_name == NULL) { - DBG(2, fprintf(outfp, "command %s is invalid \n", cmd[index])); - return NULL; - } - } - - tree->val = (char *)malloc(strlen(cmd[index])+1); - strcpy(tree->val, cmd[index]); - index++; - *length -= index; - tree->arg_count = 0; - - if (*length == 0) { - /* All done! */ - return tree; - } - - /* Got to get the arguments */ - while (*length > 0) { - - if (cmd[index][0] == ')') { - *length = *length-1; - DBG(4, fprintf(outfp, "and now len is %d\n", *length)); - return tree; - } - - used_args = add_args(&cmd[index], *length, total, tree); - tree->arg_count++; - *length -= used_args; - index += used_args; - } - - return tree; -} - -char *line; -char *getline(char *prompt) -{ - int i=-1; - int count=0; - - line = malloc(MAX_LINE); - if ((do_prompt) && (infp == stdin)) - printf(prompt); - - do { - /* If we get an end of file, just wait */ - if (feof(infp)) { - while (feof(infp) && (line[i] != '\n')) { - clearerr(infp); - count++; - fseek(infp, 0, SEEK_CUR); - } - } else { - i++; - } - fread(&line[i], 1, 1, infp); - } while(line[i] != '\n'); - - line[i] = '\0'; - - /* fprintf(stderr, "Got word %s\n", line); */ - DBG(5, fprintf(outfp, "Got word %s\n", line)); - return line; -} - -void my_perror(char *msg) -{ - char *errmsg = strerror(errno); - - DBG(2, fprintf(outfp, "%s: %s\n", msg, errmsg)); -} - -/* Static list of flag names */ -struct var_mapping flags_map[] = { - {"O_RDONLY", O_RDONLY, UINT }, - {"O_WRONLY", O_WRONLY, UINT }, - {"O_RDWR", O_RDWR, UINT }, - {"O_CREAT", O_CREAT, UINT }, - {"O_EXCL", O_EXCL, UINT }, - {"O_NOCTTY", O_NOCTTY, UINT }, - {"O_TRUNC", O_TRUNC, UINT }, - {"O_APPEND", O_APPEND, UINT }, - {"O_SYNC", O_NONBLOCK, UINT }, - {"O_NDELAY", O_NDELAY, UINT }, - {"O_SYNC", O_SYNC, UINT }, - {"O_FSYNC", O_FSYNC, UINT }, - {"O_ASYNC", O_ASYNC, UINT }, - {"SEEK_SET", SEEK_SET, UINT }, - {"SEEK_CUR", SEEK_CUR, UINT }, - {"SEEK_END", SEEK_END, UINT }, - {"S_ISUID", S_ISUID, UINT }, - {"S_ISGID", S_ISGID, UINT }, - {"S_ISVTX", S_ISVTX, UINT }, - {"S_IRWXU", S_IRWXU, UINT }, - {"S_IRUSR", S_IRUSR, UINT }, - {"S_IREAD", S_IREAD, UINT }, - {"S_IWUSR", S_IWUSR, UINT }, - {"S_IWRITE", S_IWRITE, UINT }, - {"S_IXUSR", S_IXUSR, UINT }, - {"S_IEXEC", S_IEXEC, UINT }, - {"S_IRWXG", S_IRWXG, UINT }, - {"S_IRGRP", S_IRGRP, UINT }, - {"S_IWGRP", S_IWGRP, UINT }, - {"S_IXGRP", S_IXGRP, UINT }, - {"S_IRWXO", S_IRWXO, UINT }, - {"S_IROTH", S_IROTH, UINT }, - {"S_IWOTH", S_IWOTH, UINT }, - {"S_IXOTH", S_IXOTH, UINT }, - {"S_IFCHR", S_IFCHR, UINT }, - {"S_IFMT", S_IFMT, UINT }, - {"S_IFBLK", S_IFBLK, UINT }, - {"S_IFREG", S_IFREG, UINT }, - {"S_IFIFO", S_IFIFO, UINT }, - {"S_IFLNK", S_IFLNK, UINT }, - { NULL, -1, SINT } -}; - -void init_map() -{ - int index = 0; - - while (flags_map[index].obj != -1) { - store_result(flags_map[index].name, flags_map[index].obj); - index++; - } -} - -int getquotedlen(char *str) -{ - int i; - - if (str[0] != '"' && str[0] != '\'') - return -1; - - for (i=1; str[i] != '\0' && str[i] != '"' && str[i] != '\''; i++); - - return i; -} - -int perform_op(int num1, int num2, char op) -{ - switch(op) { - - case '+': - return num1 + num2; - break; - - case '*': - return num1 * num2; - break; - - case '/': - return num1 / num2; - break; - - case '-': - return num1 - num2; - break; - - case '%': - return num1%num2; - break; - - default: - return num1; - } - return 0; -} - -int get_constant_val(char **str_ptr, int type) -{ - struct buf_t *buf; - char *buf_ptr; - char *str = *str_ptr; - char ch; - int i, j, num1, num2, size; - - printf("Getting constant val from %s\n", str); - switch(type) { - case 1: - size = getquotedlen(str); - buf = (struct buf_t *)malloc(sizeof(struct buf_t)); - buf->buf = alloc_buff32(size, 8); - buf->len = size; - buf_ptr = buf->buf; - buflist[next] = buf; - j=0; - for (i=1; i < size; i++) { - buf_ptr[j] = str[i]; - j++; - } - buf_ptr[j] = '\0'; - - DBG(3, fprintf(outfp, "Your buffer (%p) (%p) is at index %d\n", - (void *)buf, buf->buf, next)); - next++; - - last_type = PTR; - last_ret_val = next-1; - return last_ret_val; - break; - - case 2: - if (str[0] == '$') { - num1 = get_obj(str); - } else { - num1 = atoi(str); - } - str = str_ptr[1]; - ch = str_ptr[1][0]; - if ((ch == '+') || (ch == '/') || (ch == '*') || - (ch == '-') || (ch == '%')) { - if (str_ptr[2][0] == '$') - num2 = get_obj(str_ptr[2]); - else - num2 = atoi(str_ptr[2]); - num1 = perform_op(num1, num2, ch); - } - - last_type = UINT; - last_ret_val = num1; - - break; - - default: - DBG(2, fprintf(outfp, "Can't understand type of %d\n", type)); - return INVALID_ARGS; - } - - return last_ret_val; -} - -int is_constant(char *str) -{ - if ((str[0] == '"') || (str[0] == '\'')) - return 1; - - - if ( (str[0] == '$') || - ( ((int)str[0] > 47) && ((int)str[0] < 57) ) ) - return 2; - - return 0; -} - -int main(int argc, char *argv[]) -{ - int count, err, i, orig_count; - char *input, *name; - char **cmd; - cmd_tree *tree; - extern int _test_sysio_startup(void); - - /* - * Init sysio lib. - */ - err = _test_sysio_startup(); - - infp = stdin; - outfp = stdout; - - do_prompt = 1; - - errno = 0; - /* Get the input/output streams */ - for (i = 1; i < argc; i++) { - if (!strcmp(argv[i], "--input")) { - i++; - infp = fopen(argv[i], "r"); - if (!infp) { - fprintf(outfp, "Unable to open file %s for reading\n", argv[i]); - return -1; - } - } else if (!strcmp(argv[i], "--output")) { - i++; - outfp = fopen(argv[i], "w"); - if (!outfp) { - fprintf(stderr, "Unable to open file %s for writing\n", argv[i]); - return -1; - } - } else if (!strcmp(argv[i], "--np")) { - do_prompt = 0; - } else { - fprintf(stderr, "%s: Invalid arg\n", argv[i]); - return -1; - } - } - /* Initilize the mapping */ - for (i=0; i < MAX_VARS; i++) - map[i].map.obj = -1; - - /* Debug defaults */ - debug_level = 1; - print_line = 0; - - -#if 0 - /* sysio defaults */ - strcpy(root_driver, DEFAULT_DRIVER); - strcpy(mntpath, "/"); - mntflgs = 0; -#endif - - my_errno = 0; - - /* Set up line buffering */ - setlinebuf(outfp); - setlinebuf(infp); - - /* - * This sets up some common flags so that the string - * names can be used (for instance 0_RDWR, SEEK_SET, etc - */ - init_map(); - i=0; - next = 0; - while (1) { - bzero(output, 4096); - - input = getline("> "); - cmd = malloc(MAX_COMMAND * sizeof(char *)); - count = orig_count = parser(input, cmd); - name = NULL; - if ((!count) || (count > MAX_COMMAND)){ - fprintf(outfp, "%s: invalid command\n", input); - } else { - i = 0; - if (cmd[0][0] == '$') { - /* Need to store output of command in var name */ - name = cmd[0]+1; - DBG(4, fprintf(outfp, "name is %s\n", name)); - count--; - /* The '=' is not necessary, but available */ - if (!strcmp(cmd[1], "=")){ - i++; - count--; - } - i++; - if ((err=is_constant(cmd[i])) != 0) { - store_result((char *)(&cmd[0][1]), get_constant_val(&cmd[i], err)); - tree = NULL; - err = 0; - } else { - - tree = build_tree(&cmd[i], &count, 0); - if (tree != NULL) { - err = run_cmd(tree); - store_result((char *)(&cmd[0][1]), last_ret_val); - } - } - } else { - - tree = build_tree(cmd, &count, 0); - if (tree != NULL) - err = run_cmd(tree); - } - /* Print out return code and any string from command */ - fprintf(outfp, "%#04x %s\n", err, output); - if (tree) - free_tree(tree); - /* fprintf(stderr, "%#04x %s\n", err, output); */ - for (i=0; i < count; i++) - free(cmd[i]); - } - free(cmd); - free(line); - } -} diff --git a/libsysio/tests/test_driver.h b/libsysio/tests/test_driver.h deleted file mode 100644 index d8fabaf..0000000 --- a/libsysio/tests/test_driver.h +++ /dev/null @@ -1,301 +0,0 @@ -/* - * I feel like I should be putting a comment here... - */ -#include -#include "test.h" - -/* Debugging stuff.. */ -#define PRINT_LINE 0 -int debug_level; -int print_line; - -FILE *outfp; /* output file */ -FILE *infp; - -#define DBG(level, _x) \ - do { \ -if (((level) <= (debug_level))) { \ - if (print_line) \ - fprintf(outfp, "From file %s line %d: \n", __FILE__, __LINE__); \ - (void)((_x)); \ -} \ -} while(0) - -/* Maximum size of a command or command argument */ -#define MAX_WORD 150 - -/* Maximum size of an input line */ -#define MAX_LINE 300 - -/* Structure to hold commands in */ -struct cmd_t { - char *cmd; - int (*func)(int, char **); - void (*usage)(); -}; - -extern struct cmd_t cmd_list[]; - -/* Maximum number of words in a command (command + command args) */ -#define MAX_COMMAND 50 - -/* - * Holds list of allocated buffers. To use a pre-allocated - * buffer, the index number needs to be passed in. This should - * probably be smarter--perhaps a hash table could store the - * list, with the hash being sent back to the user - */ -#define MAX_BUFFERS 50 -struct buf_t { - void *buf; - int len; -}; - -struct buf_t *buflist[MAX_BUFFERS]; - -int next; /* Next available buffer slot */ - - -/* Defaults for libsysio */ -char root_driver[75]; -char mntpath[250]; -unsigned int mntflgs; - - - -#define MAX_VARS 250 - -/* - * Valid types for fill buff and variables. - */ -#define UINT 0 -#define SINT 1 -#define STR 2 -#define PTR 3 -/* - * This defines a mapping from a variable name to - * some object known by the test harness. Variable - * names are distinguished by '$'. Variables are used - * in two possible ways: to capture the output of - * a function, as in $my_fd = open name, or to gain - * access to that variable, as in open $my_fd. Variables - * do not necessarily have to be initilized before use - */ -struct var_mapping { - char *name; /* Variable name */ - int obj; /* Object will always be an integer -- either a - file descriptor or an index into the buffer - array - */ - int type; -}; - -int last_type; - -struct var_mapping_list { - struct var_mapping map; - struct var_mapping_list *next; -}; - -/* - * Again, I am lazy and just use a static array - * This should be dynamically remappable - */ -struct var_mapping_list map[MAX_VARS]; -char output[4096]; -int pos; /* Pos in output string */ - -struct cmd_map { - char *cmd_name; - int cmd; - int num_args; -}; - -extern struct cmd_map fcntl_cmds[]; - -/* Return code information */ -#define SUCCESS 0x000 -#define INVALID_ARGS 0x001 -#define INVALID_CMD 0x002 -#define INVALID_VAR 0x004 - -int do_prompt; /* Prompt for interactive run? */ -int last_ret_val; /* Last return value returned by libsysio call */ -extern int errno; -int my_errno; /* Not sure what the difference will be */ - -/* Functions defined in test_driver.c */ -extern unsigned int dx_hack_hash (const char *name, int len); -extern int get_obj(char *var_name); -extern void *alloc_buff32(unsigned int size, int align); -extern void store_result(char *var_name, int result); -extern struct var_mapping *get_map(char *var_name); -extern void free_obj(char *obj_name); -extern void my_perror(char *msg); -extern char *get_str(char *var_name); - -/* Stub functions defined in sysio_stubs.c */ -extern int test_do_setdebug(int argc, char **argv); -extern int test_do_printline(int argc, char **argv); -extern int cmp_bufs(int argc, char **argv); -extern int test_do_printbuf(int argc, char **argv); -extern int test_do_fillbuff(int argc, char **argv); -extern int test_do_mount(int argc, char **args); -extern int test_do_list(int argc, char **args); -extern int test_do_init(int argc, char **args); -extern int get_endian(int argc, char **args); -extern int get_sizeof(int argc, char **args); -extern int do_setbuf(int argc, char **argv); -extern int test_do_exit(int argc, char **args); -extern int get_buffer(int argc, char **args); -extern int free_buffer(int argc, char **args); -extern int test_do_chdir(int argc, char **args); -extern int do_checkbuf(int argc, char **argv); -extern int test_do_chmod(int argc, char **args); -extern int test_do_chown(int argc, char **args); -extern int test_do_open(int argc, char **args); -extern int test_do_close(int argc, char **args); -extern int test_do_clear(int argc, char **argv); -extern int test_do_dup(int argc, char **args); -extern int test_do_dup2(int argc, char **args); -extern int test_do_fcntl(int argc, char **args); -extern int test_do_fstat(int argc, char **argv); -extern int test_do_fsync(int argc, char **argv); -extern int test_do_ftruncate(int argc, char **argv); -extern int test_do_getcwd(int argc, char **argv); -extern int test_do_init_iovec(int argc, char **argv); -extern int test_do_init_xtvec(int argc, char **argv); -extern int test_do_lseek(int argc, char **argv); -extern int test_do_lstat(int argc, char **argv); -extern int test_do_getdirentries(int argc, char **argv); -extern int test_do_mkdir(int argc, char **argv); -extern int test_do_creat(int argc, char **argv); -extern int test_do_stat(int argc, char **argv); -extern int test_do_statvfs(int argc, char **argv); -extern int test_do_fstatvfs(int argc, char **argv); -extern int test_do_truncate(int argc, char **argv); -extern int test_do_rmdir(int argc, char **argv); -extern int test_do_symlink(int argc, char **argv); -extern int test_do_unlink(int argc, char **argv); -extern int test_do_fdatasync(int argc, char **argv); -extern int test_do_ioctl(int argc, char **argv); -extern int test_do_umask(int argc, char **argv); -extern int test_do_iodone(int argc, char **argv); -extern int test_do_iowait(int argc, char **argv); -extern int test_do_ipreadv(int argc, char **argv); -extern int test_do_ipread(int argc, char **argv); -extern int test_do_preadv(int argc, char **argv); -extern int test_do_pread(int argc, char **argv); -extern int test_do_ireadv(int argc, char **argv); -extern int test_do_ireadx(int argc, char **argv); -extern int test_do_iread(int argc, char **argv); -extern int test_do_readv(int argc, char **argv); -extern int test_do_readx(int argc, char **argv); -extern int test_do_read(int argc, char **argv); -extern int test_do_ipwritev(int argc, char **argv); -extern int test_do_ipwrite(int argc, char **argv); -extern int test_do_pwritev(int argc, char **argv); -extern int test_do_pwrite(int argc, char **argv); -extern int test_do_iwritev(int argc, char **argv); -extern int test_do_iwrite(int argc, char **argv); -extern int test_do_iwritex(int argc, char **argv); -extern int test_do_writev(int argc, char **argv); -extern int test_do_writex(int argc, char **argv); -extern int test_do_write(int argc, char **argv); -extern int test_do_mknod(int argc, char **argv); -extern int test_do_umount(int argc, char **argv); - - -/* Functions defined in sysio_tests.c */ -extern int sysio_mount(char *from, char *to); -extern int sysio_list(char *path); -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); -extern int sysio_open(char *path, int flags); -extern int sysio_open3(char *path, int flags, char *mode_arg); -extern int sysio_close(int fd); -extern int sysio_fcntl(int fd, struct cmd_map* cmdptr, char *arg); -extern int sysio_fstat(int fd, void *buf); -extern int sysio_lstat(char *filename, void *buf); -extern int sysio_getdirentries(int fd, char *buf, size_t nbytes, off_t *basep); -extern int sysio_mkdir(char *path, char *mode); -extern int sysio_creat(char *path, char *mode_arg); -extern int sysio_stat(char *filename, void *buf); -extern int sysio_statvfs(char *filename, void *buf); -extern int sysio_fstatvfs(int fd, void *buf); -extern int sysio_umask(char *mode_arg); -extern int sysio_mknod(char *path, char *mode_arg, dev_t dev); - -/* Usage functions defined in help.c */ -extern void do_help(); -extern void usage_setdebug(); -extern void usage_printline(); -extern void usage_endian(); -extern void usage_sizeof(); -extern void usage_get_buffer(); -extern void usage_free_buffer(); -extern void usage_do_printbuf(); -extern void usage_do_fillbuff(); -extern void usage_init(); -extern void usage_list(); -extern void usage_chdir(); -extern void usage_chmod(); -extern void usage_chown(); -extern void usage_open(); -extern void usage_close(); -extern void usage_clear(); -extern void usage_mount(); -extern void usage_dup(); -extern void usage_dup2(); -extern void usage_fcntl(); -extern void usage_fstat(); -extern void usage_fsync(); -extern void usage_ftruncate(); -extern void usage_getcwd(); -extern void usage_init_iovec(); -extern void usage_init_xtvec(); -extern void usage_lseek(); -extern void usage_lstat(); -extern void usage_getdirentries(); -extern void usage_mkdir(); -extern void usage_checkbuf(); -extern void usage_cmpbufs(); -extern void usage_creat(); -extern void usage_setbuf(); -extern void usage_stat(); -extern void usage_statvfs(); -extern void usage_fstatvfs(); -extern void usage_truncate(); -extern void usage_rmdir(); -extern void usage_symlink(); -extern void usage_unlink(); -extern void usage_fdatasync(); -extern void usage_ioctl(); -extern void usage_umask(); -extern void usage_iowait(); -extern void usage_iodone(); -extern void usage_ipreadv(); -extern void usage_ipread(); -extern void usage_preadv(); -extern void usage_pread(); -extern void usage_ireadv(); -extern void usage_iread(); -extern void usage_ireadx(); -extern void usage_readv(); -extern void usage_readx(); -extern void usage_read(); -extern void usage_ipwritev(); -extern void usage_ipwrite(); -extern void usage_pwritev(); -extern void usage_pwrite(); -extern void usage_iwritev(); -extern void usage_iwrite(); -extern void usage_iwritex(); -extern void usage_writev(); -extern void usage_write(); -extern void usage_writex(); -extern void usage_mknod(); -extern void usage_umount(); -extern void usage_exit(); diff --git a/libsysio/tests/test_fcntl_lock.c b/libsysio/tests/test_fcntl_lock.c new file mode 100644 index 0000000..c5e79b5 --- /dev/null +++ b/libsysio/tests/test_fcntl_lock.c @@ -0,0 +1,145 @@ +/* + * This Cplant(TM) source code is the property of Sandia National + * Laboratories. + * + * This Cplant(TM) source code is copyrighted by Sandia National + * Laboratories. + * + * The redistribution of this Cplant(TM) source code is subject to the + * terms of the GNU Lesser General Public License + * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) + * + * Cplant(TM) Copyright 1998-2005 Sandia Corporation. + * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive + * license for use of this work by or on behalf of the US Government. + * Export of this program may require a license from the United States + * Government. + */ + +/* + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Questions or comments about this library should be sent to: + * + * Lee Ward + * Sandia National Laboratories, New Mexico + * P.O. Box 5800 + * Albuquerque, NM 87185-1110 + * + * lee@sandia.gov + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if defined(SYSIO_LABEL_NAMES) +#include "sysio.h" +#endif +#include "xtio.h" +#include "test.h" + +/* + * fcntl lock tests + * + * Usage: test_fcnt_lock [ ...] + */ + +void usage(void); +void do_tests(const char *path); + +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, "")) != -1) + switch (i) { + + default: + usage(); + } + + err = _test_sysio_startup(); + if (err) { + errno = -err; + perror("sysio startup"); + exit(1); + } + + while (optind < argc) + do_tests(argv[optind++]); + + /* + * Clean up. + */ + _test_sysio_shutdown(); + + return 0; +} + +void +usage() +{ + + (void )fprintf(stderr, + "Usage: test_fcntl_lock" + " source...\n"); + exit(1); +} + +void +do_tests(const char *path) +{ + int fd; + int err; + struct flock flock; + + fd = SYSIO_INTERFACE_NAME(open)(path, O_RDONLY); + if (fd < 0) { + perror(path); + return; + } + do { + flock.l_type = F_RDLCK; + flock.l_whence = SEEK_CUR; + flock.l_start = 0; + flock.l_len = 0; + flock.l_pid = 0; + err = SYSIO_INTERFACE_NAME(fcntl)(fd, F_SETLK, &flock); + if (err) + break; + flock.l_type = F_UNLCK; + err = SYSIO_INTERFACE_NAME(fcntl)(fd, F_SETLK, &flock); + if (err) + break; + } while (0); + + if (err) + perror(path); + if (SYSIO_INTERFACE_NAME(close)(fd) != 0) + perror(path); +} diff --git a/libsysio/tests/test_getcwd.c b/libsysio/tests/test_getcwd.c index 888c9a6..fb56c24 100644 --- a/libsysio/tests/test_getcwd.c +++ b/libsysio/tests/test_getcwd.c @@ -52,6 +52,7 @@ #include #include #include +#include #if defined(SYSIO_LABEL_NAMES) #include "sysio.h" diff --git a/libsysio/tests/test_getcwd.pl b/libsysio/tests/test_getcwd.pl deleted file mode 100755 index 4255a32..0000000 --- a/libsysio/tests/test_getcwd.pl +++ /dev/null @@ -1,121 +0,0 @@ -#!/usr/bin/perl -w - -use IPC::Open2; - -use strict; -use FindBin; -use lib "$FindBin::Bin"; -use helper; -use Fcntl; - - -sub usage -{ - print "Usage: ./test_getcwd.pl [-alpha] : Test getcwd by verifying that it \n"; - print " : setting the directory to dir and \n"; - print " : verifying that getcwd reflects \n"; - print " : the change\n"; - exit(-1); -} - -sub check_wkdir -{ - my ($wdir, $outfh, $cmdfh) = @_; - - - # Get cwd from libsysio - my $cmdstr = 'CALL getcwd ( $buf = ALLOC 512 ) 512'."\n"; - helper::send_cmd($cmdfh, $outfh, "getcwd", $cmdstr); - - # Verify the system call's output - helper::verify_cmd($cmdfh, $outfh, "getcwd"); - - # Print out the buffer - $cmdstr = 'PRINT $buf 0 1 STR'."\n"; - helper::send_cmd($cmdfh, $outfh, "PRINT", $cmdstr); - - my $iodir = <$outfh>; - chop($iodir); - - # Only compare the last portion of the working directory - my @iodirs = split(/\//, $iodir); - my @wdirs = split(/\//, $wdir); - - if ($iodirs[-1] ne $wdirs[-1]) { - helper::print_and_exit - ($cmdfh, - $outfh, 0, - "ERROR! topmost wdir ($wdirs[-1]) does not match sysio's ($iodirs[-1])\n"); - } -} - -sub process_cmd -{ - my ($dir, $is_alpha) = @_; - - # Get tests directory - my $testdir = $FindBin::Bin; - - eval { - if ($is_alpha == 0) { - open2(\*OUTFILE, \*CMDFILE, "$testdir/test_driver --np"); - } else { - open2(\*OUTFILE, \*CMDFILE, - "yod -batch -quiet -sz 1 $testdir/test_driver --np"); - } - }; - - if ($@) { - if ($@ =~ /^open2/) { - warn "open2 failed: $!\n$@\n"; - return; - } - die; - - } - - my $outfh = \*OUTFILE; - my $cmdfh = \*CMDFILE; - - if ($is_alpha == 0) { - helper::send_cmd($cmdfh, $outfh, "init", "CALL init\n"); - - # Get current working directory from environment - my $cwd = $ENV{PWD}; - - - } - - # Now change to dir - helper::send_cmd($cmdfh, $outfh, "chdir", "CALL chdir $dir\n"); - - # Verify the system call's output - helper::verify_cmd($cmdfh, $outfh, "PRINT"); - - check_wkdir($dir, $outfh, $cmdfh); - - # Clean up - helper::print_and_exit($cmdfh, $outfh, 0, "getcwd test successful\n"); -} - - -my $currarg = 0; -my $is_alpha = 0; - -if (@ARGV < 1) { - usage; -} elsif (@ARGV > 1) { - if ($ARGV[$currarg++] eq "-alpha") { - $is_alpha = 1; - } -} - -my $dir = $ARGV[$currarg]; - -process_cmd($dir, $is_alpha); - -exit 0; - - - - diff --git a/libsysio/tests/test_link.c b/libsysio/tests/test_link.c index 2ec1786..317bc5e 100644 --- a/libsysio/tests/test_link.c +++ b/libsysio/tests/test_link.c @@ -53,6 +53,7 @@ #endif #include #include +#include #if defined(SYSIO_LABEL_NAMES) #include "sysio.h" diff --git a/libsysio/tests/test_list.c b/libsysio/tests/test_list.c index a539314..b9e4c0d 100644 --- a/libsysio/tests/test_list.c +++ b/libsysio/tests/test_list.c @@ -41,8 +41,6 @@ * lee@sandia.gov */ -#define _BSD_SOURCE - #include #include #include @@ -54,6 +52,7 @@ #include #include #include +#include #if defined(SYSIO_LABEL_NAMES) #include "sysio.h" diff --git a/libsysio/tests/test_list.pl b/libsysio/tests/test_list.pl deleted file mode 100755 index 5be13d2..0000000 --- a/libsysio/tests/test_list.pl +++ /dev/null @@ -1,237 +0,0 @@ -#!/usr/bin/perl -w - -# -# getdirentries test: Tests the equivalent of a ls. Note that this is not -# the most robust test in the world; it simply verifies -# that libsysio returns all the entries in the directory -# -# - -use IPC::Open2; - -use strict; - -use FindBin; -use lib "$FindBin::Bin"; -use helper; - -sub usage -{ - print "Usage: ./test_list.pl [-p|-alpha] \n"; - print " ./test_list.pl -m [-p|-alpha] fstype:mdir dir\n"; - print " In the first form, will attempt to verify libsysio's\n"; - print " getdirentries. If no dir is given, will use the \n"; - print " current working directory\n"; - print " In the second form, will mount the given mdir (of type fstype) in dir.\n"; - print " It will then verify the output of libsysio's getdirentries. It will \n"; - print " then umount the directory and verify that the umount worked\n"; - print " The -p option will print the directory listing\n"; - print " The -alpha option is for alpha architecture \n"; - exit(-1); -} - - -sub write_print -{ - my ($offset, $outfh, $cmdfh, $do_print, $is_alpha) = @_; - my $bytes = 0; - - my $intsize = 8; - my $intcmd = "INT"; - if ($is_alpha == 1) { - $intsize = 16; - $intcmd = "LONG" - } - my $shortoffset = $offset+$intsize; - my $charoffset = $shortoffset+2; - my $stroffset = $charoffset+1; - my $cmdstr = 'PRINT $buf '. - "$offset $intsize $intcmd $shortoffset 2 SHORT $charoffset 1 CHAR $stroffset 1 STR\n"; - helper::send_cmd($cmdfh, $outfh, "PRINT", $cmdstr); - - my $res = <$outfh>; - chop($res); - my ($inode, $foffset, $size, $type, @names) = split(' ',$res); - $size = oct($size); - if ($size == 0) { - return -1; - } - my $name = join(' ', @names); - - if ($do_print == 1) { - printf(STDOUT "%-35s %-14s %-14s %-6s %-4s\n", $name, $inode, $foffset, $size, $type); - } - - return $size; -} - -sub do_print_cmds -{ - my ($numbytes, $outfh, $cmdfh, $start, $do_print, $is_alpha) = @_; - - my $offset = 0; - my $bytes = 0; - my $numfiles = 0; - my $i = $start; - - if ($numbytes == 0) { - $numbytes = 8192; - } - while ($bytes < $numbytes) { - my $len = write_print($offset, $outfh, $cmdfh, $do_print, $is_alpha); - if ($len <= 0) { - # write_print saw a 0 length record, indicating end of dir - return $numfiles; - } - $numfiles++; - if ($is_alpha == 0) { - $len += $len%4; - } else { - $len += $len%8; - } - $offset += $len; - $bytes += $len; - $i++; - } - return $numfiles; -} - -sub print_dir_cmd -{ - - my ($outfh, $cmdfh, $start, $mdir, $do_print, $is_alpha) = @_; - - my $cmdstr = "CALL getdirentries ( ".'$fd = CALL open '."$mdir O_RDONLY ) ( "; - $cmdstr .= '$buf = ALLOC 8192 ) 8192 $basep'."\n"; - helper::send_cmd($cmdfh, $outfh, "getdirentries", $cmdstr); - - # Verify that the sysio call succeeded - my $res = helper::verify_cmd($cmdfh, $outfh, "getdirentries"); - my $numbytes = oct($res); - - while ($numbytes > 0) { - - do_print_cmds($numbytes, $outfh, $cmdfh, $start, $do_print, $is_alpha); - - $cmdstr = "CALL getdirentries ".'$fd $buf 8192 $basep'."\n"; - helper::send_cmd($cmdfh, $outfh, "getdirentries", $cmdstr); - - # Verify that the sysio call succeeded - my $res = helper::verify_cmd($cmdfh, $outfh, "getdirentries"); - $numbytes = oct($res); - } -} - -sub process_cmd -{ - my ($mdir, $tdir, $do_mount, $is_alpha, $do_print) = @_; - my $size = 8192; - my $done_files = 0; - - # Get tests directory - my $testdir = $FindBin::Bin; - - eval { - if ($is_alpha == 1) { - open2(\*OUTFILE, \*CMDFILE, "yod -quiet -sz 1 $testdir/test_driver --np"); - } else { - open2(\*OUTFILE, \*CMDFILE, "$testdir/test_driver --np"); - } - }; - - if ($@) { - if ($@ =~ /^open2/) { - warn "open2 failed: $!\n$@\n"; - return; - } - die; - - } - - my $outfh = \*OUTFILE; - my $cmdfh = \*CMDFILE; - - if ($is_alpha == 0) { - helper::send_cmd($cmdfh, $outfh, "init", "CALL init\n"); - } - - my $start = 0; - - if ($do_mount == 1) { - helper::send_cmd($cmdfh, $outfh, "mount", "CALL mount $mdir $tdir\n"); - print_dir_cmd($outfh, $cmdfh, $start, $tdir, $do_print, $is_alpha); - } else { - print_dir_cmd($outfh, $cmdfh, $start, $mdir, $do_print, $is_alpha); - } - - # Attempt to unmount and verify the contents - if ($do_mount == 1) { - - # Close the dir before we umount - my $cmdstr = 'CALL close $fd'."\n"; - helper::send_cmd($cmdfh, $outfh, "close", $cmdstr); - - # umount dir - helper::send_cmd($cmdfh, $outfh, "umount", "CALL umount $tdir\n"); - - - # Verify it is umounted - $cmdstr = "CALL getdirentries ( ".'$fd2 = CALL open '."$tdir O_RDONLY ) "; - $cmdstr .= '$buf 8192 $newp'."\n"; - helper::send_cmd($cmdfh, $outfh, "getdirentries", $cmdstr); - my $res = helper::verify_cmd($cmdfh, $outfh, "getdirentries"); - - my $numbytes = oct($res); - # The only entries should be . and .., so should return 32 - if ($numbytes != 32) { - helper::print_and_exit($cmdfh, $outfh, 1, "ERROR! Read in $numbytes bytes\n"); - } - # Clean up - $cmdstr = 'CALL close $fd2'."\n"; - helper::send_cmd($cmdfh, $outfh, "close", $cmdstr); - - } else { - my $cmdstr = 'CALL close $fd'."\n"; - helper::send_cmd($cmdfh, $outfh, "getdirentries", $cmdstr); - } - - helper::print_and_exit($cmdfh, $outfh, 0, "list test successful\n"); -} - - -# Default dir is cwd -my @mydir; -$mydir[0] = "./"; -my $do_mount = 0; -my $is_alpha = 0; -my $do_print = 0; -my $dircnt = 0; -for (my $i = 0; $i < @ARGV; $i++) -{ - if ($ARGV[$i] eq "-p") { - $do_print = 1; - } elsif ($ARGV[$i] eq "-m") { - $do_mount = 1; - } elsif ($ARGV[$i] eq "-alpha") { - $is_alpha = 1; - } else { - $mydir[$dircnt] = $ARGV[$i]; - $dircnt++; - } -} - -if ( ($dircnt == 0) || ($dircnt > 2) || - (($do_mount==1) && ($dircnt < 2)) || - (($do_mount == 0) && ($dircnt > 1)) ) { - usage(); -} - -my $dir = $mydir[0]; -if ($do_mount == 1) { - my $fstype; - ($fstype, $dir) = split(/:/, $mydir[0]); -} - -process_cmd($mydir[0], $mydir[1], $do_mount, $is_alpha, $do_print); - -exit 0; diff --git a/libsysio/tests/test_mkdir.c b/libsysio/tests/test_mkdir.c new file mode 100644 index 0000000..e8711f8 --- /dev/null +++ b/libsysio/tests/test_mkdir.c @@ -0,0 +1,163 @@ +/* + * This Cplant(TM) source code is the property of Sandia National + * Laboratories. + * + * This Cplant(TM) source code is copyrighted by Sandia National + * Laboratories. + * + * The redistribution of this Cplant(TM) source code is subject to the + * terms of the GNU Lesser General Public License + * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) + * + * Cplant(TM) Copyright 1998-2006 Sandia Corporation. + * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive + * license for use of this work by or on behalf of the US Government. + * Export of this program may require a license from the United States + * Government. + */ + +/* + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Questions or comments about this library should be sent to: + * + * Lee Ward + * Sandia National Laboratories, New Mexico + * P.O. Box 5800 + * Albuquerque, NM 87185-1110 + * + * lee@sandia.gov + */ + +#include +#include +#include +#include +#include +#include +#if 0 +#include +#endif +#include + +#if defined(SYSIO_LABEL_NAMES) +#include "sysio.h" +#endif +#include "test.h" + +/* + * Make directories. + * + * Usage: mkdir [path...] + * + * Without any path arguments, the program creates directories named + * by the command line args. + */ + +static int do_mkdir(const char *path); +static void usage(void); + +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, "")) != -1) + switch (i) { + + default: + usage(); + } + + /* + * Init sysio lib. + */ + err = _test_sysio_startup(); + if (err) { + errno = -err; + perror("sysio startup"); + exit(1); + } + + n = argc - optind; + + /* + * Try path(s) listed on command-line. + */ + while (optind < argc) { + const char *path; + + path = argv[optind++]; + (void )do_mkdir(path); + } + + /* + * If no command-line arguments, read from stdin until EOF. + */ + if (!n) { + int doflush; + static char buf[4096]; + size_t len; + char *cp; + char c; + + doflush = 0; + while (fgets(buf, sizeof(buf), stdin) != NULL) { + len = strlen(buf); + cp = buf + len - 1; + c = *cp; + *cp = '\0'; + if (!doflush) + do_mkdir(buf); + doflush = c == '\n' ? 0 : 1; + } + } + + /* + * Clean up. + */ + _test_sysio_shutdown(); + + return 0; +} + +static int +do_mkdir(const char *path) +{ + + if (SYSIO_INTERFACE_NAME(mkdir)(path, 777) != 0) { + perror(path); + return -1; + } + + return 0; +} + +static void +usage() +{ + + (void )fprintf(stderr, + "Usage: mkdir" + " [ ...\n]"); + + exit(1); +} diff --git a/libsysio/tests/test_mknod.c b/libsysio/tests/test_mknod.c new file mode 100644 index 0000000..7f1d937 --- /dev/null +++ b/libsysio/tests/test_mknod.c @@ -0,0 +1,162 @@ +/* + * This Cplant(TM) source code is the property of Sandia National + * Laboratories. + * + * This Cplant(TM) source code is copyrighted by Sandia National + * Laboratories. + * + * The redistribution of this Cplant(TM) source code is subject to the + * terms of the GNU Lesser General Public License + * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) + * + * Cplant(TM) Copyright 1998-2006 Sandia Corporation. + * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive + * license for use of this work by or on behalf of the US Government. + * Export of this program may require a license from the United States + * Government. + */ + +/* + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Questions or comments about this library should be sent to: + * + * Lee Ward + * Sandia National Laboratories, New Mexico + * P.O. Box 5800 + * Albuquerque, NM 87185-1110 + * + * lee@sandia.gov + */ + +/* + * Can't provoke a definition of the S_IFMT macros without a little extra work. + */ +#define _BSD_SOURCE + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if defined(SYSIO_LABEL_NAMES) +#include "sysio.h" +#endif +#include "test.h" + +/* + * Create a node. + * + * Usage: mknod path {f|b|c} [dev] + * + * The dev argument should not be present for regular file and FIFO object + * creation. + */ + +static int do_mknod(const char *path, mode_t mode, dev_t dev); +static void usage(void); + +int +main(int argc, char *const argv[]) +{ + int i; + int err; + mode_t mode; + dev_t dev; + extern int _test_sysio_startup(void); + + /* + * Parse command line arguments. + */ + while ((i = getopt(argc, argv, "")) != -1) + switch (i) { + + default: + usage(); + } + + /* + * Init sysio lib. + */ + err = _test_sysio_startup(); + if (err) { + errno = -err; + perror("sysio startup"); + exit(1); + } + + if (argc - optind < 2) + usage(); + if (strlen(argv[optind + 1]) != 1) + usage(); + mode = 0666; + switch (*argv[optind + 1]) { + + case 'f': + mode |= S_IFREG; + break; + case 'b': + mode |= S_IFBLK; + break; + case 'c': + mode |= S_IFCHR; + break; + case 'p': + mode |= S_IFIFO; + break; + default: + usage(); + } + dev = 0; + if (!(S_ISREG(mode) || S_ISFIFO(mode))) + dev = atoi(argv[optind + 2]); + else if (argc - optind != 2) { + (void )fprintf(stderr, "Too many arguments\n"); + usage(); + } + (void )do_mknod(argv[optind + 0], mode, dev); + + /* + * Clean up. + */ + _test_sysio_shutdown(); + + return 0; +} + +static int +do_mknod(const char *path, mode_t mode, dev_t dev) +{ + + if (SYSIO_INTERFACE_NAME(mknod)(path, mode, dev) != 0) { + perror(path); + return -1; + } + + return 0; +} + +static void +usage() +{ + + (void )fprintf(stderr, "Usage: mknod path {f|b|c|p} dev\n"); + exit(1); +} diff --git a/libsysio/tests/test_path.c b/libsysio/tests/test_path.c index 518dbfe..8776b6e 100644 --- a/libsysio/tests/test_path.c +++ b/libsysio/tests/test_path.c @@ -41,8 +41,6 @@ * lee@sandia.gov */ -#define _BSD_SOURCE - #include #include #include @@ -51,6 +49,7 @@ #include #include #include +#include #if defined(SYSIO_LABEL_NAMES) #include "sysio.h" @@ -208,7 +207,7 @@ statit(const char *path) } (void )printf("%s: %c", path, t); if (S_ISLNK(stbuf.st_mode) && (size_t )cc < sizeof(buf)) - (void )printf(" %.*s", cc, buf); + (void )printf(" %.*s", (int )cc, buf); (void )putchar('\n'); return 0; diff --git a/libsysio/tests/test_path.pl b/libsysio/tests/test_path.pl deleted file mode 100755 index 67bdf73..0000000 --- a/libsysio/tests/test_path.pl +++ /dev/null @@ -1,188 +0,0 @@ -#!/usr/bin/perl -w - -# -# path test: reads paths from stdin and prints out the path along with its -# : type -# - -use IPC::Open2; - -use strict; -use FindBin; -use lib "$FindBin::Bin"; -use helper; -use POSIX; -use Fcntl; - -sub usage -{ - print "Usage ./test_path.pl [path1 path2...] : Print each path listed and its type\n"; - print " : If no paths are given, stdin is read\n"; - exit(-1); -} - -sub get_type -{ - my $mode = $_[0]; - my $t = '?'; - - if (S_ISDIR($mode)) { - $t = 'd'; - } elsif (S_ISCHR($mode)) { - $t = 'c'; - } elsif (S_ISBLK($mode)) { - $t = 'b'; - } elsif (S_ISREG($mode)) { - $t = 'f'; - } elsif (S_ISFIFO($mode)) { - $t = 'p'; - } elsif (S_ISLNK($mode)) { - $t = 'S'; - } elsif (S_ISSOCK($mode)) { - $t = 's'; - } - - return $t; -} - -sub print_path -{ - my ($mode, $path) = @_; - - my $typechar = get_type($mode); - print STDOUT "$path: $typechar\n"; -} - -sub process_path -{ - my ($cmdfh, $outfh, $bits, $path) = @_; - - # Issue the stat command - my $cmdstr = 'CALL stat "'; - $cmdstr = sprintf("%s%s%s\n", $cmdstr, $path, '" $buf'); - - helper::send_cmd($cmdfh, $outfh, "stat", $cmdstr); - helper::verify_cmd($cmdfh, $outfh, "stat"); - - # Print out the stat buffer - if ($bits == 32) { - $cmdstr = 'PRINT $buf 0 8 LONG 12 24 INT 44 8 LONG 52 8 INT 64 24 LONG'; - } else { - $cmdstr = 'PRINT $buf 0 24 LONG 24 16 INT 48 32 LONG 88 8 LONG 104 8 LONG'; - } - $cmdstr .= "\n"; - helper::send_cmd($cmdfh, $outfh, "PRINT", $cmdstr); - - my $res = <$outfh>; - chop($res); - my ( $iodev, $ioino, $iomode, $ionlink, $iouid, $iogid, $iordev, - $iosize, $ioblksize, $ioblks, $ioatime, $iomtime, $ioctime ) - = split(' ', $res); - if ($bits == 64) { - ( $iodev, $ioino, $ionlink, $iomode, $iouid, $iogid, $iordev, - $iosize, $ioblksize, $ioblks, $ioatime, $iomtime, $ioctime ) - = split(' ', $res); - } - $iomode = oct($iomode); - - # Print out the path - print_path($iomode, $path); -} - -sub process_cmd -{ - my ($usestdin, $isalpha, @paths) = @_; - - my $path; - - # Get tests directory - my $testdir = $FindBin::Bin; - - eval { - if ($isalpha == 0) { - open2(\*OUTFILE, \*CMDFILE, "$testdir/test_driver --np"); - } else { - open2(\*OUTFILE, \*CMDFILE, - "yod -batch -quiet -sz 1 $testdir/test_driver --np"); - } - }; - - if ($@) { - if ($@ =~ /^open2/) { - warn "open2 failed: $!\n$@\n"; - return; - } - die; - - } - my $outfh = \*OUTFILE; - my $cmdfh = \*CMDFILE; - - if ($isalpha == 0) { - helper::send_cmd($cmdfh, $outfh, "init", "CALL init\n"); - } - - # Allocate the stat buffer - my $cmdstr = '$buf = ALLOC ( $size = CALL sizeof stat )'; - $cmdstr .= "\n"; - helper::send_cmd($cmdfh, $outfh, "alloc", $cmdstr); - - # Attempt to determine type - $cmdstr = 'PRINT $size'."\n"; - helper::send_cmd($cmdfh, $outfh, "print", $cmdstr); - my $statsize = <$outfh>; - chop($statsize); - $statsize = oct($statsize); - my $bits = 32; - if ($statsize == 144) { - $bits = 64; - } - - my $i=0; - if ($usestdin) { - $path = ; - if (defined($path)) { - chop($path); - } - } else { - $path = $paths[$i++]; - } - - # Enter a loop, reading a path argument and processing it with each - # phase of loop. - while (defined($path)) { - - process_path($cmdfh, $outfh, $bits, $path); - if ($usestdin) { - $path = ; - - if (defined($path)) { - chop($path); - } - if ($path eq "quit") { - helper::print_and_exit($cmdfh, $outfh, 0, "path test successful\n"); - } - } else { - $path = $paths[$i++]; - } - } - helper::print_and_exit($cmdfh, $outfh, 0, "path test successful\n"); -} - - -my $usestdin = 0; -my $isalpha = 0; - -# The -alpha arg must be before the paths -# (if they exist) -if ( (@ARGV > 0) && ($ARGV[0] eq "-alpha")) { - $isalpha = 1; - shift(@ARGV); -} - -if (@ARGV == 0) { - $usestdin = 1; -} - -process_cmd($usestdin, $isalpha, @ARGV); - diff --git a/libsysio/tests/test_regions.c b/libsysio/tests/test_regions.c index ded2c83..e253a30 100644 --- a/libsysio/tests/test_regions.c +++ b/libsysio/tests/test_regions.c @@ -41,19 +41,6 @@ * lee@sandia.gov */ -#define _BSD_SOURCE - -#if (_LARGEFILE64_SOURCE && \ - ((defined(__STDC_VERSION__) && __STDC_VERSION__ == 199901L))) -#define GO64 -#else -#warning Cannot prompt the 64-bit interface -#endif - -#if defined(GO64) && defined(__GLIBC__) -#define _ISOC99_SOURCE 1 -#endif - #include #include #include @@ -64,6 +51,7 @@ #include #include #include +#include #if defined(SYSIO_LABEL_NAMES) #include "sysio.h" @@ -80,9 +68,7 @@ * Destination will not be overwritten if it already exist. */ -#if (_LARGEFILE64_SOURCE && \ - ((defined(__STDC_VERSION__) && __STDC_VERSION__ == 199901L) || \ - (defined(_ISOC99_SOURCE) && _ISOC99_SOURCE))) +#if defined(_LARGEFILE64_SOURCE) && _LARGEFILE64_SOURCE #define GO64 #else #warning Cannot prompt the 64-bit interface diff --git a/libsysio/tests/test_rename.c b/libsysio/tests/test_rename.c index dbb0d92..13aa1ee 100644 --- a/libsysio/tests/test_rename.c +++ b/libsysio/tests/test_rename.c @@ -41,8 +41,6 @@ * lee@sandia.gov */ -#define _BSD_SOURCE - #include #include #include @@ -51,6 +49,7 @@ #include #include #include +#include #if defined(SYSIO_LABEL_NAMES) #include "sysio.h" diff --git a/libsysio/tests/test_rw.pl b/libsysio/tests/test_rw.pl deleted file mode 100755 index 74a7fa0..0000000 --- a/libsysio/tests/test_rw.pl +++ /dev/null @@ -1,537 +0,0 @@ -#!/usr/bin/perl -w - -# -# rw test: Write a buffer out using all the different writes, read it back -# and make sure it matches -# -# - -use IPC::Open2; - -use strict; -use FindBin; -use lib "$FindBin::Bin"; -use helper; - -sub usage -{ - print "Usage: ./test_rw.pl [-alpha] : Write to/read from file\n"; - exit(-1); -} - -sub verify_result -{ - my ($cmdfh, $outfh, $cmdstr, $exp_val, $eq_op) = @_; - my $print_err = 0; - - my $res = helper::verify_cmd($cmdfh, $outfh, $cmdstr); - $res = oct($res); - - if ($eq_op eq "!=") { - if ($res != $exp_val) { - print STDOUT "Error! $cmdstr returned $res insted of $exp_val\n"; - exit 1; - } - } else { - if ($eq_op eq ">") { - if ($res > $exp_val) { - $print_err = 1; - } - } elsif ($eq_op eq "<") { - if ($res < $exp_val) { - $print_err = 1; - } - } elsif ($eq_op eq "==") { - if ($res == $exp_val) { - $print_err = 1; - } - } - if ($print_err == 1) { - helper::print_and_exit($cmdfh, $outfh, 1, "Error! $cmdstr returned $res\n"); - } - } -} - -sub do_iowait -{ - my ($cmdfh, $outfh, $id, $rwcmd, $exp_size) = @_; - - my $cmdstr = "CALL iowait $id\n"; - helper::send_cmd($cmdfh, $outfh, "iowait", $cmdstr); - - my $descstr = "iowait:$rwcmd"; - verify_result($cmdfh, $outfh, $descstr, $exp_size, "!="); -} - -sub set_iovecs -{ - my ($cmdfh, $outfh, $callnum) = @_; - my $NUMVECS = 8; - my $VECLEN = $NUMVECS * 1024; - - my $varname = "iovbuf$callnum"; - - # Get size of iovecs - my $cmdstr = '$iovsize = CALL sizeof iovec'."\n"; - helper::send_cmd($cmdfh, $outfh, "sizeof", $cmdstr); - my $size = helper::verify_cmd($cmdfh, $outfh, "sizeof iovec"); - $size = oct($size); - $size = $size * $NUMVECS; - - # Allocate iovec buffer - $cmdstr = '$'."$varname = ALLOC $size\n"; - helper::send_cmd($cmdfh, $outfh, "alloc", $cmdstr); - - - # Now initilize all of them - my $off = 0; - for (my $i=0; $i < $NUMVECS; $i++) { - $cmdstr = 'CALL init_iovec $buf '."$off $VECLEN $i ". '$'."$varname\n"; - helper::send_cmd($cmdfh, $outfh, "init_iovec", $cmdstr); - helper::verify_cmd($cmdfh, $outfh, "init_iovec"); - $off += $VECLEN; - } - - return $varname; -} - - -sub set_xtvecs -{ - my ($cmdfh, $outfh, $callnum, $startoff) = @_; - my $VECLEN = 4 * 8 * 1024; - - my $varname = "xtvbuf$callnum"; - - # Get size of iovecs - my $cmdstr = '$xtvsize = CALL sizeof xtvec'."\n"; - helper::send_cmd($cmdfh, $outfh, "sizeof", $cmdstr); - my $size = helper::verify_cmd($cmdfh, $outfh, "sizeof xtvec"); - $size = oct($size); - $size = $size * 2; - - # Allocate iovec buffer - $cmdstr = '$'."$varname = ALLOC $size\n"; - helper::send_cmd($cmdfh, $outfh, "alloc", $cmdstr); - - - # Now initilize all of them - my $off = $startoff; - for (my $i=0; $i < 2; $i++) { - $cmdstr = "CALL init_xtvec $off $VECLEN $i ". '$'."$varname\n"; - helper::send_cmd($cmdfh, $outfh, "init_xtvec", $cmdstr); - helper::verify_cmd($cmdfh, $outfh, "init_xtvec"); - $off += $VECLEN; - } - - return $varname; -} - -sub check_buf -{ - - my ($cmdfh, $outfh, $bufsize, $readcmd) = @_; - my $i; - my $digit = 0; - my $offset = 0; - my $cmdstr; - - for ($i =0; $i < 64; $i++) { - $cmdstr = 'CALL checkbuf $buf'. " 1024 $digit $offset\n"; - helper::send_cmd($cmdfh, $outfh, "checkbuf", $cmdstr); - my $res = helper::verify_cmd($cmdfh, $outfh, "checkbuf"); - $res = oct($res); - - if ($res != 0) { - print STDOUT "Checkbuf returned $res\n"; - helper::print_and_exit($cmdfh, $outfh, 1, "$readcmd did not return all $digit 's\n"); - } - - $offset += 1024; - $digit++; - if ($digit == 10) { - $digit = 0; - } - } - - # Now fill the buffer with 0s - $cmdstr = '$buf = CALL setbuf 0 '."$bufsize ".'$buf'." 0\n"; - helper::send_cmd($cmdfh, $outfh, "setbuf", $cmdstr); - -} - -sub fill_buf -{ - my ($cmdfh, $outfh) = @_; - my $i; - my $digit=0; - my $cmdstr; - my $offset = 0; - - # Fill up the buffer with alternating digits - # from 0-9 - - for ($i=0; $i < 64 ; $i++) { - my $cmdstr = "CALL setbuf $digit 1024 ".'$buf'." $offset\n"; - helper::send_cmd($cmdfh, $outfh, "setbuf", $cmdstr); - $offset += 1024; - $digit++; - if ($digit == 10) { - $digit = 0; - } - } -} - -sub do_rwcalls -{ - my ($cmdfh, $outfh, $bufsize) = @_; - my $IOID_FAIL = 0; - my $NUMVECS = 8; - - # Initilize buffer - fill_buf($cmdfh, $outfh); - - # write 64K bytes at pos 0 - my $cmdstr = 'CALL write $fd $buf '."$bufsize\n"; - helper::send_cmd($cmdfh, $outfh, "write", $cmdstr); - verify_result($cmdfh, $outfh, "write", $bufsize, "!="); - - # Initilize buffer - fill_buf($cmdfh, $outfh); - - # iwrite 64K bytes at pos 64K - $cmdstr = '$id1 = CALL iwrite $fd $buf '."$bufsize\n"; - helper::send_cmd($cmdfh, $outfh, "iwrite", $cmdstr); - verify_result($cmdfh, $outfh, "iwrite", $IOID_FAIL, "=="); - do_iowait($cmdfh, $outfh, '$id1', "iwrite", $bufsize); - - # Set up the iovecs - my $iovcnt = 0; - my $iovname = set_iovecs($cmdfh, $outfh, $iovcnt); - - # Initilize buffer - fill_buf($cmdfh, $outfh); - - # writev 64K bytes using 8 iovecs at pos 128K - $cmdstr = 'CALL writev $fd $'."$iovname $NUMVECS\n"; - helper::send_cmd($cmdfh, $outfh, "writev", $cmdstr); - verify_result($cmdfh, $outfh, "writev", $bufsize, "!="); - - # Initilize buffer - fill_buf($cmdfh, $outfh); - - # iwritev 64K bytes using 8 iovecs at pos 192K - $cmdstr = '$id2 = CALL iwritev $fd $'."$iovname $NUMVECS\n"; - helper::send_cmd($cmdfh, $outfh, "iwritev", $cmdstr); - verify_result($cmdfh, $outfh, "iwritev", $IOID_FAIL, "=="); - do_iowait($cmdfh, $outfh, '$id2', "iwritev", $bufsize); - - # Initilize buffer - fill_buf($cmdfh, $outfh); - - # pwrite 64K bytes starting at pos 256K - my $offset = 256 * 1024; - $cmdstr = 'CALL pwrite $fd $buf '."$bufsize $offset\n"; - helper::send_cmd($cmdfh, $outfh, "pwrite", $cmdstr); - verify_result($cmdfh, $outfh, "pwrite", $bufsize, "!="); - - # Initilize buffer - fill_buf($cmdfh, $outfh); - - # ipwrite 64K bytes starting at pos 320K - $offset = 320 * 1024; - $cmdstr = '$id3 = CALL ipwrite $fd $buf '."$bufsize $offset\n"; - helper::send_cmd($cmdfh, $outfh, "ipwrite", $cmdstr); - verify_result($cmdfh, $outfh, "ipwrite", $IOID_FAIL, "=="); - do_iowait($cmdfh, $outfh, '$id3', "ipwrite", $bufsize); - - $iovcnt++; - - # Initilize buffer - fill_buf($cmdfh, $outfh); - - # pwritev using 8 8K buffers at offset 384 - $offset = 384 * 1024; - $cmdstr = 'CALL pwritev $fd $'."$iovname $NUMVECS $offset\n"; - helper::send_cmd($cmdfh, $outfh, "pwritev", $cmdstr); - verify_result($cmdfh, $outfh, "pwritev", $bufsize, "!="); - - # Initilize buffer - fill_buf($cmdfh, $outfh); - - # ipwritev using 8 8k buffers at offset 448 - $offset = 448 * 1024; - $cmdstr = '$id4 = CALL ipwritev $fd $'."$iovname $NUMVECS $offset\n"; - helper::send_cmd($cmdfh, $outfh, "ipwritev", $cmdstr); - verify_result($cmdfh, $outfh, "ipwritev", $IOID_FAIL, "=="); - do_iowait($cmdfh, $outfh, '$id4', "ipwritev", $bufsize); - - # Set up the xtvecs. Starting offset is 512K - my $xtvcnt = 0; - my $xtvname = set_xtvecs($cmdfh, $outfh, $xtvcnt, 512 * 1024); - - $iovcnt++; - - # Initilize buffer - fill_buf($cmdfh, $outfh); - - # Call writex using 8 8k buffers at offset 512 - $cmdstr = 'CALL writex $fd $'."$iovname $NUMVECS ".'$'."$xtvname 2\n"; - helper::send_cmd($cmdfh, $outfh, "writex", $cmdstr); - verify_result($cmdfh, $outfh, "writex", $bufsize, "!="); - - # Call iwritex using 8 8k buffers starting at offset 576 - # Re-setup xtvs since I am lazy. This is leaking memory like - # a seive... - $xtvcnt++; - $xtvname = set_xtvecs($cmdfh, $outfh, $xtvcnt, 576 * 1024); - - $iovcnt++; - - # Initilize buffer - fill_buf($cmdfh, $outfh); - - $cmdstr = '$id5 = CALL iwritex $fd $'."$iovname $NUMVECS ".'$'."$xtvname 2\n"; - helper::send_cmd($cmdfh, $outfh, "iwritex", $cmdstr); - verify_result($cmdfh, $outfh, "iwritex", $IOID_FAIL, "=="); - do_iowait($cmdfh, $outfh, '$id5', "iwritex", $bufsize); - - # Now do the reads - - # Lseek back to pos 0 - $cmdstr = 'CALL lseek $fd 0 SEEK_SET'."\n"; - helper::send_cmd($cmdfh, $outfh, "sizeof", $cmdstr); - helper::verify_cmd($cmdfh, $outfh, "sizeof xtvec"); - - # fill the buffer with 0's - $cmdstr = '$buf = CALL setbuf 0 '."$bufsize ".'$buf'." 0\n"; - helper::send_cmd($cmdfh, $outfh, "setbuf", $cmdstr); - - # read 64K bytes from pos 0 - $cmdstr = 'CALL read $fd $buf '."$bufsize\n"; - helper::send_cmd($cmdfh, $outfh, "read", $cmdstr); - verify_result($cmdfh, $outfh, "read", $bufsize, "!="); - - # Check the buffer to make sure it matches - check_buf($cmdfh, $outfh, $bufsize, "read"); - - # iread 64K bytes at pos 64K - $cmdstr = '$id6 = CALL iread $fd $buf '."$bufsize\n"; - helper::send_cmd($cmdfh, $outfh, "iread", $cmdstr); - verify_result($cmdfh, $outfh, "iread", $IOID_FAIL, "=="); - do_iowait($cmdfh, $outfh, '$id6', "iread", $bufsize); - check_buf($cmdfh, $outfh, $bufsize, "iread"); - - $iovcnt++; - - # readv 64K bytes using 8 iovecs at pos 128K - $cmdstr = 'CALL readv $fd $'."$iovname $NUMVECS\n"; - helper::send_cmd($cmdfh, $outfh, "readv", $cmdstr); - verify_result($cmdfh, $outfh, "readv", $bufsize, "!="); - check_buf($cmdfh, $outfh, $bufsize, "readv"); - - # ireadv 64K bytes using 8 iovecs at pos 192K - $cmdstr = '$id7 = CALL ireadv $fd $'."$iovname $NUMVECS\n"; - helper::send_cmd($cmdfh, $outfh, "ireadv", $cmdstr); - verify_result($cmdfh, $outfh, "ireadv", $IOID_FAIL, "=="); - do_iowait($cmdfh, $outfh, '$id7', "ireadv", $bufsize); - check_buf($cmdfh, $outfh, $bufsize, "ireadv"); - - # pread64K bytes starting at pos 256K - $offset = 256 * 1024; - $cmdstr = 'CALL pread $fd $buf '."$bufsize $offset\n"; - helper::send_cmd($cmdfh, $outfh, "pread", $cmdstr); - verify_result($cmdfh, $outfh, "pread", $bufsize, "!="); - check_buf($cmdfh, $outfh, $bufsize, "pread"); - - # ipread 64K bytes starting at pos 320K - $offset = 320 * 1024; - $cmdstr = '$id8 = CALL ipread $fd $buf '."$bufsize $offset\n"; - helper::send_cmd($cmdfh, $outfh, "ipread", $cmdstr); - verify_result($cmdfh, $outfh, "ipread", $IOID_FAIL, "=="); - do_iowait($cmdfh, $outfh, '$id8', "ipread", $bufsize); - check_buf($cmdfh, $outfh, $bufsize, "ipread"); - - - $iovcnt++; - - # preadv using 8 8K buffers at offset 384 - $offset = 384 * 1024; - $cmdstr = 'CALL preadv $fd $'."$iovname $NUMVECS $offset\n"; - helper::send_cmd($cmdfh, $outfh, "preadv", $cmdstr); - verify_result($cmdfh, $outfh, "preadv", $bufsize, "!="); - check_buf($cmdfh, $outfh, $bufsize, "preadv"); - - # ipreadv using 8 8k buffers at offset 448 - $offset = 448 * 1024; - $cmdstr = '$id9 = CALL ipreadv $fd $'."$iovname $NUMVECS $offset\n"; - helper::send_cmd($cmdfh, $outfh, "ipreadv", $cmdstr); - verify_result($cmdfh, $outfh, "ipreadv", $IOID_FAIL, "=="); - do_iowait($cmdfh, $outfh, '$id9', "ipreadv", $bufsize); - check_buf($cmdfh, $outfh, $bufsize, "ipreadv"); - - # Set up the xtvecs. Starting offset is 512K - $xtvcnt++; - $xtvname = set_xtvecs($cmdfh, $outfh, $xtvcnt, 512 * 1024); - - $iovcnt++; - - # Call readx using 8 8k buffers at offset 512 - $cmdstr = 'CALL readx $fd $'."$iovname $NUMVECS ".'$'."$xtvname 2\n"; - helper::send_cmd($cmdfh, $outfh, "readx", $cmdstr); - verify_result($cmdfh, $outfh, "readx", $bufsize, "!="); - check_buf($cmdfh, $outfh, $bufsize, "readx"); - - # Call ireadx using 8 8k buffers starting at offset 576 - # Re-setup xtvs since I am lazy. This is leaking memory like - # a seive... - $xtvcnt++; - $xtvname = set_xtvecs($cmdfh, $outfh, $xtvcnt, 576 * 1024); - - $iovcnt++; - - $cmdstr = '$id10 = CALL ireadx $fd $'."$iovname $NUMVECS ".'$'."$xtvname 2\n"; - helper::send_cmd($cmdfh, $outfh, "ireadx", $cmdstr); - verify_result($cmdfh, $outfh, "ireadx", $IOID_FAIL, "=="); - do_iowait($cmdfh, $outfh, '$id10', "ireadx", $bufsize); - check_buf($cmdfh, $outfh, $bufsize, "ireadx"); -} - - -sub check_array -{ - my ($exp_digit, @arr) = @_; - my $exp_char; - my $pos = 0; - - if ($exp_digit == 0) { - $exp_char = "\\0"; - } elsif ($exp_digit < 7) { - $exp_char = "00".$exp_digit; - } elsif ($exp_digit == 7) { - $exp_char = "\\a"; - } elsif ($exp_digit == 8) { - $exp_char = "\\b"; - } elsif ($exp_digit == 9) { - $exp_char = "\\t"; - } else { - print STDERR "Invalid expected digit $exp_digit\n"; - return(1); - } - - foreach my $str (@arr) { - if ($str ne $exp_char) { - print STDERR "At pos $pos got digit $str instead of $exp_char\n"; - return(1); - } - $pos++; - } - - return(0); -} - -# Perform an od on the output and verify that the output makes -# sense -sub od_verify -{ - my ($cmdfh, $outfh, $file) = @_; - my $exp_digit = 0; - - # Do an od in order to verify the contents of the file - system("od -c $file > tmp.out.$$"); - open(ODFILE, ") { - if (/^\*/) { - # Do nothing... - } else { - my ($lineno, @nums) = split($_); - if (check_array($exp_digit, @nums) != 0) { - helper::print_and_exit($cmdfh, $outfh, 1, "At line $lineno, got unexpected result\n"); - } - if ($exp_digit < 9) { - $exp_digit ++; - } else { - $exp_digit = 0; - } - } - } - - close(ODFILE); - system("rm -f tmp.out.$$"); -} - -sub process_cmd -{ - my ($file, $is_alpha) = @_; - - # Get tests directory - my $testdir = $FindBin::Bin; - my $bufsize = 65536; - - eval { - if ($is_alpha == 0) { - open2(\*OUTFILE, \*CMDFILE, "$testdir/test_driver --np"); - } else { - open2(\*OUTFILE, \*CMDFILE, "yod -quiet -sz 1 $testdir/test_driver --np"); - } - }; - - if ($@) { - if ($@ =~ /^open2/) { - warn "open2 failed: $!\n$@\n"; - return; - } - die; - - } - - my $outfh = \*OUTFILE; - my $cmdfh = \*CMDFILE; - - if ($is_alpha == 0) { - helper::send_cmd($cmdfh, $outfh, "init", "CALL init\n"); - } - - # Open file - my $cmdstr = '$fd = CALL open '."$file O_RDWR|O_CREAT 0777\n"; - helper::send_cmd($cmdfh, $outfh, "open", $cmdstr); - helper::verify_cmd($cmdfh, $outfh, $cmdstr); - - - # Allocate buffer - $cmdstr = '$buf = ALLOC '."$bufsize\n"; - helper::send_cmd($cmdfh, $outfh, "ALLOC", $cmdstr); - - - do_rwcalls($cmdfh, $outfh, $bufsize); - - # Clean up - $cmdstr = 'CALL close $fd'."\n"; - helper::send_cmd($cmdfh, $outfh, "close", $cmdstr); - - # Verify it worked - od_verify($cmdfh, $outfh, $file); - - system("rm -f $file"); - helper::print_and_exit($cmdfh, $outfh, 0, "rw test successful\n"); -} - -my $currarg = 0; -my $is_alpha = 0; - -if (@ARGV < 1) { - usage; -} elsif (@ARGV > 1 ) { - if ($ARGV[$currarg++] eq "-alpha") { - $is_alpha = 1; - } -} - -my $file = $ARGV[$currarg]; - -process_cmd($file, $is_alpha); - - -exit 0; diff --git a/libsysio/tests/test_stats.c b/libsysio/tests/test_stats.c index dac7b8d..e604d9d 100644 --- a/libsysio/tests/test_stats.c +++ b/libsysio/tests/test_stats.c @@ -41,8 +41,6 @@ * lee@sandia.gov */ -#define _BSD_SOURCE - #include #include #include @@ -54,6 +52,7 @@ #include #endif #include +#include #if defined(SYSIO_LABEL_NAMES) #include "sysio.h" diff --git a/libsysio/tests/test_stats.pl b/libsysio/tests/test_stats.pl deleted file mode 100755 index fee6a32..0000000 --- a/libsysio/tests/test_stats.pl +++ /dev/null @@ -1,268 +0,0 @@ -#!/usr/bin/perl -w - -# -# stats test: Verifies that the set of stat calls (stat, fstat, fstatvfs, and -# statvfs) return the same items and that the calls return the -# same items as Perl's stat call (which would use a native library -# and not libsysio) -# -# - -use IPC::Open2; - -use strict; -use FindBin; -use lib "$FindBin::Bin"; -use helper; - -sub usage -{ - print "Usage ./test_stats.pl file : Verifies that the set of stat calls (stat, \n"; - print " : fstat, fstatvfs, statvfs) return the same set\n"; - print " : of stats for file and that the calls return \n"; - print " : the same items as Perl's stat call (which \n"; - print " : would use a native library and not libsysio)\n"; - exit(-1); -} - -# Compares the output of Perl's stat function with the output -# from libsysio's stat -sub cmp_stats -{ - - my ( $cmdfh, $outfh, $is_alpha, $bits, @stats) = @_; - - - my ($iodev, $ioino, $iomode, $ionlink, $iouid, $iogid, $iordev, - $iosize, $ioblksize, $ioblks, $ioatime, $iomtime, $ioctime, @pstats) = - @stats; - - if ($is_alpha == 1) { - ($iodev, $ioino, $iomode, $ionlink, $iouid, $iogid, $iordev, - $iosize, $ioatime, $iomtime, $ioctime, $ioblks, $ioblksize, @pstats) = - @stats; - } - if ($bits == 64) { - ($iodev, $ioino, $ionlink, $iomode, $iouid, $iogid, $iordev, - $iosize, $ioblksize, $ioblks, $ioatime, $iomtime, $ioctime,@pstats) = - @stats; - } - my ($pdev, $pino, $pmode, $pnlink, $puid, $pgid, $prdev, - $psize, $patime, $pmtime, $pctime, $pblksize, $pblks) = @pstats; - -# helper::cmp_nums($cmdfh, $outfh, $iodev, $pdev, "device numbers"); - helper::cmp_nums($cmdfh, $outfh, $ioino, $pino, "inode numbers"); - helper::cmp_nums($cmdfh, $outfh, $iomode, $pmode, "file modes"); - helper::cmp_nums($cmdfh, $outfh, $ionlink, $pnlink, "number of links"); - helper::cmp_nums($cmdfh, $outfh, $iouid, $puid, "user ids"); - helper::cmp_nums($cmdfh, $outfh, $iogid, $pgid, "group ids"); - helper::cmp_nums($cmdfh, $outfh, $iordev, $prdev, "device ids"); - helper::cmp_nums($cmdfh, $outfh, $iosize, $psize, "file sizes"); - helper::cmp_nums($cmdfh, $outfh, $ioatime, $patime, "access times"); - helper::cmp_nums($cmdfh, $outfh, $iomtime, $pmtime, "modification times"); - helper::cmp_nums($cmdfh, $outfh, $ioctime, $pctime, "inode change times"); - helper::cmp_nums($cmdfh, $outfh, $ioblksize, $pblksize, "block sizes"); - helper::cmp_nums($cmdfh, $outfh, $ioblks, $pblks, "blocks allocated"); -} - - -# Prints out the stat buffer and verifies that it matches -# Perl's output -sub verify_stat -{ - my ($cmdfh, $outfh, $cmd, $is_alpha, $bits, @stats) = @_; - my $i=0; - - my $cmdstr; - # Print out the stat buffer - if ($is_alpha == 1) { - $cmdstr = 'PRINT $buf 0 16 LONG 16 16 INT 32 8 LONG 40 4 INT 48 40 LONG'."\n"; - } elsif ($bits == 32) { - $cmdstr = 'PRINT $buf 0 8 LONG 12 24 INT 44 8 LONG 48 8 INT 56 24 LONG'."\n"; - } else { - $cmdstr = 'PRINT $buf 0 24 LONG 24 16 INT 48 32 LONG 88 8 LONG 104 8 LONG'."\n"; - } - - helper::send_cmd($cmdfh, $outfh, "PRINT", $cmdstr); - - my $res = <$outfh>; - chop($res); - - my @iostats = split(' ', $res); - foreach my $iostat (@iostats) { - $iostats[$i] = oct($iostat); - $i++; - } - - cmp_stats($cmdfh, $outfh, $is_alpha, $bits, @iostats, @stats); - -} - -sub process_cmd -{ - my ($file, $use_system, $is_alpha) = @_; - -# Get tests directory - my $testdir = $FindBin::Bin; - - eval { - if ($is_alpha == 0) { - open2(\*OUTFILE, \*CMDFILE, "$testdir/test_driver --np"); - } else { - open2(\*OUTFILE, \*CMDFILE, - "yod -batch -quiet -sz 1 $testdir/test_driver --np"); - } - }; - - if ($@) { - if ($@ =~ /^open2/) { - warn "open2 failed: $!\n$@\n"; - return; - } - die; - - } - - my $outfh = \*OUTFILE; - my $cmdfh = \*CMDFILE; - - if ($is_alpha == 0) { - helper::send_cmd($cmdfh, $outfh, "init", "CALL init\n"); - } - - my @stats; - if ($use_system == 1) { - # Get stats for file - @stats = stat($file); - } - - # Allocate the buffer - my $cmdstr = '$buf = ALLOC ( $size = CALL sizeof stat )'."\n"; - helper::send_cmd($cmdfh, $outfh, "alloc", $cmdstr); - - - # Issue the stat command - $cmdstr = 'CALL stat '."$file ".'$buf'."\n"; - helper::send_cmd($cmdfh, $outfh, "stat", $cmdstr); - helper::verify_cmd($cmdfh, $outfh, "stat"); - - # Attempt to determine type - $cmdstr = 'PRINT $size'."\n"; - helper::send_cmd($cmdfh, $outfh, "print", $cmdstr); - my $statsize = <$outfh>; - chop($statsize); - $statsize = oct($statsize); - my $bits = 32; - if ($statsize == 144) { - $bits = 64; - } - - if ($use_system == 1) { - # Now print the buffer out and verify that it matches - # what Perl has - verify_stat($cmdfh, $outfh, "stat", $is_alpha, $bits, @stats); - } - - # Open the file - $cmdstr = '$fd = CALL open '."$file O_RDONLY\n"; - helper::send_cmd($cmdfh, $outfh, "open", $cmdstr); - helper::verify_cmd($cmdfh, $outfh, "open"); - - - # Now issue an fstat call - $cmdstr = 'CALL fstat $fd $buf'."\n"; - helper::send_cmd($cmdfh, $outfh, "fstat", $cmdstr); - helper::verify_cmd($cmdfh, $outfh, "fstat"); - - if ($use_system == 1) { - verify_stat($cmdfh, $outfh, "fstat", $is_alpha, $bits, @stats); - } - - # Test lstat - if ($use_system == 1) { - @stats = lstat($file); - } - - $cmdstr = 'CALL lstat '."$file ".'$buf'."\n"; - helper::send_cmd($cmdfh, $outfh, "lstat", $cmdstr); - helper::verify_cmd($cmdfh, $outfh, "lstat"); - - if ($use_system == 1) { - verify_stat($cmdfh, $outfh, "lstat", $is_alpha, $bits, @stats); - } - - if (0) { - # Now do statvfs functions - $cmdstr = '$buf2 = ALLOC ( $size2 = CALL sizeof statvfs )'."\n"; - helper::send_cmd($cmdfh, $outfh, "alloc", $cmdstr); - - # Clear out the buffer - $cmdstr = 'CALL clear $buf2'."\n"; - helper::send_cmd($cmdfh, $outfh, "CLEAR", $cmdstr); - - $cmdstr = 'CALL statvfs '."$file ".'$buf2'."\n"; - helper::send_cmd($cmdfh, $outfh, "statvfs", $cmdstr); - helper::verify_cmd($cmdfh, $outfh, "statvfs"); - - # Print out the statvfs buffer - $cmdstr = 'PRINT $buf2 0 16 LONG 16 32 INT 48 16 LONG'."\n"; - helper::send_cmd($cmdfh, $outfh, "PRINT", $cmdstr); - - my $res = <$outfh>; - chop($res); - my @vfsstats1 = split(' ', $res); - - # Clear out the buffer - $cmdstr = 'CALL clear $buf2'."\n"; - helper::send_cmd($cmdfh, $outfh, "CLEAR", $cmdstr); - - # Now do fstatvfs - $cmdstr = 'CALL fstatvfs $fd $buf2'."\n"; - helper::send_cmd($cmdfh, $outfh, "fstatvfs", $cmdstr); - helper::verify_cmd($cmdfh, $outfh, "fstatvfs"); - - # Print out the statvfs buffer - $cmdstr = 'PRINT $buf2 0 16 LONG 16 32 INT 48 16 LONG'."\n"; - helper::send_cmd($cmdfh, $outfh, "PRINT", $cmdstr); - - $res = <$outfh>; - chop($res); - my @vfsstats2 = split(' ', $res); - - # Verify the two vfsstats arrays match - if (@vfsstats1 != @vfsstats2) { - helper::print_and_exit($cmdfh, $outfh, 1, "Two vfsstat arrays unequal lengths\n"); - } - - my $i=0; - - foreach my $stat1 (@vfsstats1) { - if ($stat1 ne $vfsstats2[$i++]) { - my $str = sprintf("vfsstats field %d are not equal (%s != %s)\n", - $i-1, $stat1, $vfsstats2[$i-1]); - helper::print_and_exit($cmdfh, $outfh, 1, $str); - } - } - } - - helper::print_and_exit($cmdfh, $outfh, 0, "stat test successful\n"); -} - - - - -my $currarg = 0; -my $is_alpha = 0; -if (@ARGV < 2) { - usage; -} elsif (@ARGV > 2) { - if ($ARGV[$currarg++] eq "-alpha") { - $is_alpha = 1; - } -} - -my $use_system= $ARGV[$currarg++]; -my $file = $ARGV[$currarg]; - -process_cmd($file, $use_system, $is_alpha); - diff --git a/libsysio/tests/test_stdfd.pl b/libsysio/tests/test_stdfd.pl deleted file mode 100755 index afd5548..0000000 --- a/libsysio/tests/test_stdfd.pl +++ /dev/null @@ -1,242 +0,0 @@ -#!/usr/bin/perl -w - -# -# stdfd test: Verifies that stdin, stdout, and stderr can be opened and -# either written to or read from (in the case of stdin) - -use IPC::Open2; - -use strict; -use FindBin; -use lib "$FindBin::Bin"; -use helper; - -sub usage -{ - print "Usage ./test_stdfd : Verifies that stdin, stdout, and stderr can be opened and "; - print " : either written to or read from (in the case of stdin)"; - exit(-1); -} - -sub mkdev -{ - my ($major, $minor) = @_; - my $devno = ( (($major & 0xff) << 8) | ($minor & 0xff) ); - - return $devno; -} - -sub statit -{ - my ($cmdfh, $outfh, $do_print, $name) = @_; - - my $cmd = "CALL stat $name ".'$buf'."\n"; - - helper::send_cmd($cmdfh, $outfh, "stat", $cmd); - helper::verify_cmd($cmdfh, $outfh, "stat $name"); - - # Print out the stat buffer - $cmd = 'PRINT $buf 0 8 LONG 12 24 INT 44 8 LONG 52 8 INT 64 24 LONG'; - $cmd .= "\n"; - helper::send_cmd($cmdfh, $outfh, "PRINT", $cmd); - - my $res = <$outfh>; - chop($res); - my ( $iodev, $ioino, $iomode, $ionlink, $iouid, $iogid, $iordev, - $iosize, $ioblksize, $ioblks, $ioatime, $iomtime, $ioctime ) - = split(' ', $res); - - $iomode = oct($iomode); - - if ($do_print == 1) { - # Print out the path - my $typechar = helper::get_type($iomode); - print STDOUT "$name: $typechar\n"; - } - return 0; -} - -sub do_open -{ - - my ($cmdfh, $outfh, $name, $mode, $num) = @_; - - helper::send_cmd($cmdfh, $outfh, "open", "CALL open $name $mode\n"); - - my $res = helper::verify_cmd($cmdfh, $outfh, "open $name"); - - #chop($res); - $res = oct($res); - if ($res < 0) { - helper::print_and_exit($cmdfh, $outfh, 1, "Unable to open $name\n"); - } - - - if ($res == $num) { - return $res; - } - - helper::send_cmd($cmdfh, $outfh, "dup2", "CALL dup2 $res $num\n"); - $res = helper::verify_cmd($cmdfh, $outfh, "dup2"); - $res = oct($res); - - if ($res != $num) { - helper::print_and_exit($cmdfh, $outfh, 1, "Unable to dup $name (res was $res)\n"); - } -} - -sub do_mknod -{ - - my ($cmdfh, $outfh, $do_print, $name, $perm_num, $minor) = @_; - - my $perm = 'S_IFCHR|'.$perm_num; - my $devno = mkdev(0, $minor); - - helper::send_cmd($cmdfh, $outfh, "mknod", "CALL mknod $name $perm $devno\n"); - - helper::verify_cmd($cmdfh, $outfh, "mknod $name"); - - my $statres = statit($cmdfh, $outfh, $do_print, $name); - if ($statres != 0) { - helper::print_and_exit($cmdfh, $outfh, 1, "stat on $name failed\n"); - } -} - -sub process_cmd -{ - my ($dirname, $do_print, $is_alpha) = @_; - -# Get tests directory -my $testdir = $0; -$testdir =~ s/\/\w+.pl$//; - - eval { - if ($is_alpha == 1) { - open2(\*OUTFILE, \*CMDFILE, "yod -sz 1 -quiet -batch $testdir/test_driver --np"); - } else { - open2(\*OUTFILE, \*CMDFILE, "$testdir/test_driver --np"); - } - }; - - if ($@) { - if ($@ =~ /^open2/) { - warn "open2 failed: $!\n$@\n"; - return; - } - die; - - } - - my $outfh = \*OUTFILE; - my $cmdfh = \*CMDFILE; - - if ($is_alpha == 0) { - helper::send_cmd($cmdfh, $outfh, "init", "CALL init incore ".'"0777+0+0"'." 0\n"); - helper::verify_cmd($cmdfh, $outfh, "init incore"); - } - - - # Get a stat buffer - my $cmd = '$buf = ALLOC ( $size = CALL sizeof stat )'."\n"; - helper::send_cmd($cmdfh, $outfh, "alloc", $cmd); - - if ($is_alpha == 0) { - # Make the test directory - $cmd = "CALL mkdir $dirname 0777\n"; - helper::send_cmd($cmdfh, $outfh, "mkdir", $cmd); - helper::verify_cmd($cmdfh, $outfh, "mkdir"); - - - # Change working dir to test dir - $cmd = "CALL chdir $dirname\n"; - helper::send_cmd($cmdfh, $outfh, "chdir", $cmd); - helper::verify_cmd($cmdfh, $outfh, "chdir"); - - - # Create the 3 special files - do_mknod($cmdfh, $outfh, $do_print, "stdin", "0444", 0); - do_mknod($cmdfh, $outfh, $do_print, "stdout", "0222", 1); - do_mknod($cmdfh, $outfh, $do_print, "stderr", "0222", 2); - - # Open the 3 files - do_open($cmdfh, $outfh, "stdin", "O_RDONLY", 0); - do_open($cmdfh, $outfh, "stdout", "O_WRONLY", 1); - do_open($cmdfh, $outfh, "stderr", "O_WRONLY", 2); - } - #helper::send_cmd($cmdfh, $outfh, "debug", "CALL debug 5\n"); - - # Read from stdin, write to stdout and stderr - - # Send "delay" option to read which will give us time to - # put something in stdin (since we can't send an eof) - $cmd = "CALL read 0 ".'$buf 38'." delay\n"; - print $cmdfh $cmd; - # Give time to process command - sleep 1; - - # Send random junk... - print $cmdfh "This message is exactly 38 bytes long\n"; - sleep 0.5; - - # Make sure read was OK - my $res = <$outfh>; - chop($res); - if ($res ne "0000 ") { - helper::print_and_exit($cmdfh, $outfh, 1, "ERROR! Command $cmd failed with code $res\n"); - } - - # See how many bytes we got... - my $bytes = helper::verify_cmd($cmdfh, $outfh, "read"); - $bytes = oct($bytes); - if ($bytes == 0) { - helper::print_and_exit($cmdfh, $outfh, 0, "test_stdfd successful but read nothing\n"); - } - - if ($bytes < 0) { - helper::print_and_exit($cmdfh, $outfh, 0, "test_stdfd unsuccessful\n"); - } - - $cmd = "CALL write 1 ".'$buf '."$bytes\n"; - print $cmdfh $cmd; - - # 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! Command $cmd failed with code $res\n"); - } - - helper::verify_cmd($cmdfh, $outfh, "write stdout"); - - $cmd = "CALL write 2 ".'$buf '."$bytes\n"; - helper::send_cmd($cmdfh, $outfh, "write stderr", $cmd); - helper::verify_cmd($cmdfh, $outfh, "write stderr"); - - helper::print_and_exit($cmdfh, $outfh, 0, "test_stdfd successful\n"); -} - - -my $is_alpha = 0; -my $do_print = 0; -my $i; -for ($i=0; $i < @ARGV; $i++) { - if ($ARGV[$i] eq "-alpha") { - $is_alpha =1; - } elsif ($ARGV[$i] eq "-print") { - $do_print = 1; - } -} - -$i--; -my $dirname = $ARGV[$i]; - -process_cmd($dirname, $do_print, $is_alpha); - -exit 0; - diff --git a/libsysio/tests/test_strided.pl b/libsysio/tests/test_strided.pl deleted file mode 100755 index 5468d9b..0000000 --- a/libsysio/tests/test_strided.pl +++ /dev/null @@ -1,462 +0,0 @@ -#!/usr/bin/perl -w - -# -# strided IO test: Perform a series of different reads/writes -# using readx and writex with different buffer -# configurations -# - -use IPC::Open2; - -use strict; -use FindBin; -use lib "$FindBin::Bin"; -use helper; - -sub usage -{ - print "Usage: ./test_rw.pl [-alpha] : Write to/read from file\n"; - exit(-1); -} - -sub verify_result -{ - my ($cmdfh, $outfh, $cmdstr, $exp_val, $eq_op) = @_; - my $print_err = 0; - - my $res = helper::verify_cmd($cmdfh, $outfh, $cmdstr); - $res = oct($res); - - if ($eq_op eq "!=") { - if ($res != $exp_val) { - print STDOUT "Error! $cmdstr returned $res insted of $exp_val\n"; - system("killall test_driver"); - exit(1); - } - } else { - if ($eq_op eq ">") { - if ($res > $exp_val) { - $print_err = 1; - } - } elsif ($eq_op eq "<") { - if ($res < $exp_val) { - $print_err = 1; - } - } elsif ($eq_op eq "==") { - if ($res == $exp_val) { - $print_err = 1; - } - } - if ($print_err == 1) { - print STDOUT "Error! $cmdstr returned $res\n"; - } - } - -} - -# Initilize the iovec number $vecnum -# in the iovec buffer $vecname with buffer -# pos $buf and using len $veclen -sub set_iovec -{ - my ($cmdfh, $outfh, $vecname, $vecnum, $buf, $veclen) = @_; - - my $cmdstr = 'CALL init_iovec $'.$buf." 0 $veclen "; - $cmdstr .= "$vecnum ".'$'."$vecname\n"; - - helper::send_cmd($cmdfh, $outfh, "init_iovec", $cmdstr); - helper::verify_cmd($cmdfh, $outfh, "init_iovec"); -} - - -sub setup_xtvecs -{ - my ($cmdfh, $outfh) = @_; - - # Get size of iovecs - my $cmdstr = '$xtvsize = CALL sizeof xtvec'."\n"; - helper::send_cmd($cmdfh, $outfh, "sizeof", $cmdstr); - my $size = helper::verify_cmd($cmdfh, $outfh, "sizeof xtvec"); - $size = oct($size); - $size = $size * 2; - - # Allocate iovec buffer - $cmdstr = '$xtvbuf'." = ALLOC $size\n"; - helper::send_cmd($cmdfh, $outfh, "alloc", $cmdstr); - - - # Now initilize xtvbuf - $cmdstr = "CALL init_xtvec 0 100 0 ". '$xtvbuf'."\n"; - helper::send_cmd($cmdfh, $outfh, "init_xtvec", $cmdstr); - helper::verify_cmd($cmdfh, $outfh, "init_xtvec"); - - $cmdstr = "CALL init_xtvec 1000 100 1 ". '$xtvbuf'."\n"; - helper::send_cmd($cmdfh, $outfh, "init_xtvec", $cmdstr); - helper::verify_cmd($cmdfh, $outfh, "init_xtvec"); -} - -sub check_buf -{ - - my ($cmdfh, $outfh, $bufsize, $bufname, - $readcmd, $digit, $offset) = @_; - - my $cmdstr = 'CALL checkbuf $'. "$bufname $bufsize $digit $offset\n"; - helper::send_cmd($cmdfh, $outfh, "checkbuf", $cmdstr); - my $res = helper::verify_cmd($cmdfh, $outfh, "checkbuf"); - $res = oct($res); - - if ($res != 0) { - print STDOUT "$readcmd did not return all $digit 's\n"; -} -} - -# Fill given buffer with $digit up to $size -# starting at $offset -sub fill_buf -{ - my ($cmdfh, $outfh, $buf, $digit, $size, $off) = @_; - - my $cmdstr = "CALL setbuf $digit $size ".'$'."$buf $off\n"; - helper::send_cmd($cmdfh, $outfh, "setbuf", $cmdstr); -} - -sub alloc_iovbuf -{ - my ($cmdfh, $outfh, $numbufs, $num) = @_; - - # Get size of iovecs - my $cmdstr = '$iovsize = CALL sizeof iovec'."\n"; - helper::send_cmd($cmdfh, $outfh, "sizeof", $cmdstr); - my $size = helper::verify_cmd($cmdfh, $outfh, "sizeof iovec"); - $size = oct($size); - $size = $size * $numbufs; - - # Allocate iovec buffer - $cmdstr = '$iovbuf'."$num = ALLOC $size\n"; - helper::send_cmd($cmdfh, $outfh, "alloc", $cmdstr); - - my $retstr = "iovbuf".$num; - - return $retstr; -} - -sub do_rwcalls -{ - my ($cmdfh, $outfh, $fh) = @_; - - # Allocate and initilize xtvecs - setup_xtvecs($cmdfh, $outfh); - - # Allocate 2 different iovecs, one for cases - # (a) and (d) and one for cases (b) and (c) - my $iovbuf1 = alloc_iovbuf($cmdfh, $outfh, 3, 0); - my $iovbuf2 = alloc_iovbuf($cmdfh, $outfh, 1, 1); - - # Allocate four buffers, each 200 bytes long - my $cmdstr = '$buf1 '. "= ALLOC 200\n"; - helper::send_cmd($cmdfh, $outfh, "alloc", $cmdstr); - $cmdstr = '$buf2 '. "= ALLOC 200\n"; - helper::send_cmd($cmdfh, $outfh, "alloc", $cmdstr); - $cmdstr = '$buf3 '. "= ALLOC 200\n"; - helper::send_cmd($cmdfh, $outfh, "alloc", $cmdstr); - $cmdstr = '$buf4 '. "= ALLOC 200\n"; - helper::send_cmd($cmdfh, $outfh, "alloc", $cmdstr); - - # Case (a): - # xtvec[] = { { 0, 100 }, {1000, 100} } - # iovec[] = { { buf1, 50}, {buf2, 50}, {buf3, 100} - - # Fill each of the 3 buffers of. They will be filled - # as follows: - # buf1 --> 0- 49: 1 - # --> 49-200: 2 - # buf2 --> 0- 49: 3 - # --> 49-200: 4 - # buf3 --> 0-100: 5 - # --> 100-200: 6 - fill_buf($cmdfh, $outfh, "buf1", 1, 50, 0); - fill_buf($cmdfh, $outfh, "buf1", 2, 150, 50); - fill_buf($cmdfh, $outfh, "buf2", 3, 50, 0); - fill_buf($cmdfh, $outfh, "buf2", 4, 150, 50); - fill_buf($cmdfh, $outfh, "buf3", 5, 100, 0); - fill_buf($cmdfh, $outfh, "buf3", 6, 100, 100); - - # Initiize iovecs - set_iovec($cmdfh, $outfh, $iovbuf1, 0, "buf1", 50); - set_iovec($cmdfh, $outfh, $iovbuf1, 1, "buf2", 50); - set_iovec($cmdfh, $outfh, $iovbuf1, 2, "buf3", 100); - - # Write out to $fh - $cmdstr = 'CALL writex $'."$fh $iovbuf1 3 ".'$xtvbuf '."2\n"; - helper::send_cmd($cmdfh, $outfh, "writex", $cmdstr); - verify_result($cmdfh, $outfh, "writex (case a)", 200, "!="); - - # Clear out the buffers - fill_buf($cmdfh, $outfh, "buf1", 0, 200, 0); - fill_buf($cmdfh, $outfh, "buf2", 0, 200, 0); - fill_buf($cmdfh, $outfh, "buf3", 0, 200, 0); - - # Read it back - $cmdstr = 'CALL readx $'."$fh $iovbuf1 3 ".'$xtvbuf '."2\n"; - helper::send_cmd($cmdfh, $outfh, "readx", $cmdstr); - verify_result($cmdfh, $outfh, "readx (case a)", 200, "!="); - - # Make sure we got what we expected... - check_buf($cmdfh, $outfh, 50, "buf1", "readx (case a)", 1, 0); - check_buf($cmdfh, $outfh, 50, "buf2", "readx (case a)", 3, 0); - check_buf($cmdfh, $outfh, 100, "buf3", "readx (case a)", 5, 0); - - # Case (b): - # xtvec[] = { { 0, 100 }, {1000, 100} } - # iovec[] = { { buf4, 200} } - - - # Fill buf4 with 7's... - fill_buf($cmdfh, $outfh, "buf4", 7, 200, 0); - - # Initiize iovecs - set_iovec($cmdfh, $outfh, $iovbuf2, 0, "buf4", 200); - - # Write out to $fh - $cmdstr = 'CALL writex $'."$fh ".'$'."$iovbuf2 1 ".'$xtvbuf '."2\n"; - helper::send_cmd($cmdfh, $outfh, "writex", $cmdstr); - verify_result($cmdfh, $outfh, "writex (case b)", 200, "!="); - - # Clear out the buffer - fill_buf($cmdfh, $outfh, "buf4", 0, 200, 0); - - # Read it back - $cmdstr = 'CALL readx $'."$fh $iovbuf2 1 ".'$xtvbuf '."2\n"; - helper::send_cmd($cmdfh, $outfh, "readx", $cmdstr); - verify_result($cmdfh, $outfh, "readx (case b)", 200, "!="); - - # Make sure we got what we expected... - check_buf($cmdfh, $outfh, 200, "buf4", "readx (case b)", 7, 0); - - - # Case (c): - # xtvec[] = { { 0, 100 }, {1000, 100} } - # iovec[] = { { buf4, 40} } - - # Fill buf4 with 8's... - fill_buf($cmdfh, $outfh, "buf4", 8, 200, 0); - - # Initiize iovecs - set_iovec($cmdfh, $outfh, $iovbuf2, 0, "buf4", 40); - - # Write out to $fh - $cmdstr = 'CALL writex $'."$fh $iovbuf2 1 ".'$xtvbuf '."2\n"; - helper::send_cmd($cmdfh, $outfh, "writex", $cmdstr); - verify_result($cmdfh, $outfh, "writex (case c)", 40, "!="); - - # Clear out the buffer - fill_buf($cmdfh, $outfh, "buf4", 0, 200, 0); - - # Read it back - $cmdstr = 'CALL readx $'."$fh $iovbuf2 1 ".'$xtvbuf '."2\n"; - helper::send_cmd($cmdfh, $outfh, "readx", $cmdstr); - verify_result($cmdfh, $outfh, "readx (case c)", 40, "!="); - - # Make sure we got what we expected... - check_buf($cmdfh, $outfh, 40, "buf4", "readx (case c)", 8, 0); - - - # Case (d): - # xtvec[] = { { 0, 100 }, {1000, 100} } - # iovec[] = { { buf1, 40}, {buf2, 150}, {buf3, 200} } - - # Fill each of the 3 buffers of. They will be filled - # as follows: - # buf1 --> 0- 39: 1 - # --> 39-200: 2 - # buf2 --> 0-150: 3 - # --> 150-200: 4 - # buf3 --> 0- 9: 5 - # --> 10-200: 6 - fill_buf($cmdfh, $outfh, "buf1", 1, 40, 0); - fill_buf($cmdfh, $outfh, "buf1", 2, 160, 40); - fill_buf($cmdfh, $outfh, "buf2", 3, 150, 0); - fill_buf($cmdfh, $outfh, "buf2", 4, 50, 150); - fill_buf($cmdfh, $outfh, "buf3", 5, 10, 0); - fill_buf($cmdfh, $outfh, "buf3", 6, 190, 10); - - # Initiize iovecs - set_iovec($cmdfh, $outfh, $iovbuf1, 0, "buf1", 40); - set_iovec($cmdfh, $outfh, $iovbuf1, 1, "buf2", 150); - set_iovec($cmdfh, $outfh, $iovbuf1, 2, "buf3", 200); - - # Write out to $fh - $cmdstr = 'CALL writex $'."$fh $iovbuf1 3 ".'$xtvbuf '."2\n"; - helper::send_cmd($cmdfh, $outfh, "writex", $cmdstr); - verify_result($cmdfh, $outfh, "writex (case d)", 200, "!="); - - # Clear out the buffers - fill_buf($cmdfh, $outfh, "buf1", 0, 200, 0); - fill_buf($cmdfh, $outfh, "buf2", 0, 200, 0); - fill_buf($cmdfh, $outfh, "buf3", 0, 200, 0); - - # Read it back - $cmdstr = 'CALL readx $'."$fh $iovbuf1 3 ".'$xtvbuf '."2\n"; - helper::send_cmd($cmdfh, $outfh, "readx", $cmdstr); - verify_result($cmdfh, $outfh, "readx (case d)", 200, "!="); - - # Make sure we got what we expected... - check_buf($cmdfh, $outfh, 40, "buf1", "readx (case d)", 1, 0); - check_buf($cmdfh, $outfh, 150, "buf2", "readx (case d)", 3, 0); - check_buf($cmdfh, $outfh, 10, "buf3", "readx (case d)", 5, 0); - - # Case (e): - # xtvec[] = { { 0, 100 }, {1000, 100} } - # iovec[] = { { buf1, 30}, {buf2, 30}, {buf3, 30} } - - # Fill each of the 3 buffers as follows: - # buf1 --> 0- 30: 1 - # --> 30-200: 2 - # buf2 --> 0- 30: 3 - # --> 30-200: 4 - # buf3 --> 0- 30: 5 - # --> 30-200: 6 - fill_buf($cmdfh, $outfh, "buf1", 1, 30, 0); - fill_buf($cmdfh, $outfh, "buf1", 2, 170, 30); - fill_buf($cmdfh, $outfh, "buf2", 3, 30, 0); - fill_buf($cmdfh, $outfh, "buf2", 4, 170, 30); - fill_buf($cmdfh, $outfh, "buf3", 5, 30, 0); - fill_buf($cmdfh, $outfh, "buf3", 6, 170, 30); - - # Initiize iovecs - set_iovec($cmdfh, $outfh, $iovbuf1, 0, "buf1", 30); - set_iovec($cmdfh, $outfh, $iovbuf1, 1, "buf2", 30); - set_iovec($cmdfh, $outfh, $iovbuf1, 2, "buf3", 30); - - # Write out to $fh - $cmdstr = 'CALL writex $'."$fh $iovbuf1 3 ".'$xtvbuf '."2\n"; - helper::send_cmd($cmdfh, $outfh, "writex", $cmdstr); - verify_result($cmdfh, $outfh, "writex (case e)", 90, "!="); - - # Clear out the buffers - fill_buf($cmdfh, $outfh, "buf1", 0, 200, 0); - fill_buf($cmdfh, $outfh, "buf2", 0, 200, 0); - fill_buf($cmdfh, $outfh, "buf3", 0, 200, 0); - - # Read it back - $cmdstr = 'CALL readx $'."$fh $iovbuf1 3 ".'$xtvbuf '."2\n"; - helper::send_cmd($cmdfh, $outfh, "readx", $cmdstr); - verify_result($cmdfh, $outfh, "readx (case e)", 90, "!="); - - # Make sure we got what we expected... - check_buf($cmdfh, $outfh, 30, "buf1", "readx (case e)", 1, 0); - check_buf($cmdfh, $outfh, 30, "buf2", "readx (case e)", 3, 0); - check_buf($cmdfh, $outfh, 30, "buf3", "readx (case e)", 5, 0); - - # Case (f): - # xtvec[] = { { 0, 100 }, {1000, 100} } - # iovec[] = { { buf1, 30}, {buf2, 90}, {buf3, 200} } - - # Fill each of the 3 buffers as follows: - # buf1 --> 0- 30: 1 - # --> 30-200: 2 - # buf2 --> 0- 70: 3 - # --> 70- 90: 4 - # --> 90-200: 5 - # buf3 --> 0-200: 6 - fill_buf($cmdfh, $outfh, "buf1", 1, 30, 0); - fill_buf($cmdfh, $outfh, "buf1", 2, 170, 30); - fill_buf($cmdfh, $outfh, "buf2", 3, 70, 0); - fill_buf($cmdfh, $outfh, "buf2", 4, 90, 70); - fill_buf($cmdfh, $outfh, "buf2", 5, 110, 90); - fill_buf($cmdfh, $outfh, "buf3", 6, 200, 0); - - # Initiize iovecs - set_iovec($cmdfh, $outfh, $iovbuf1, 0, "buf1", 30); - set_iovec($cmdfh, $outfh, $iovbuf1, 1, "buf2", 90); - set_iovec($cmdfh, $outfh, $iovbuf1, 2, "buf3", 200); - - # Write out to $fh - $cmdstr = 'CALL writex $'."$fh $iovbuf1 3 ".'$xtvbuf '."2\n"; - helper::send_cmd($cmdfh, $outfh, "writex", $cmdstr); - verify_result($cmdfh, $outfh, "writex (case f)", 200, "!="); - - # Clear out the buffers - fill_buf($cmdfh, $outfh, "buf1", 0, 200, 0); - fill_buf($cmdfh, $outfh, "buf2", 0, 200, 0); - fill_buf($cmdfh, $outfh, "buf3", 0, 200, 0); - - # Read it back - $cmdstr = 'CALL readx $'."$fh $iovbuf1 3 ".'$xtvbuf '."2\n"; - helper::send_cmd($cmdfh, $outfh, "readx", $cmdstr); - verify_result($cmdfh, $outfh, "readx (case f)", 200, "!="); - - # Make sure we got what we expected... - check_buf($cmdfh, $outfh, 30, "buf1", "readx (case f)", 1, 0); - check_buf($cmdfh, $outfh, 70, "buf2", "readx (case f)", 3, 0); - check_buf($cmdfh, $outfh, 20, "buf2", "readx (case f)", 4, 70); - check_buf($cmdfh, $outfh, 70, "buf3", "readx (case f)", 6, 0); - -} - - -sub process_cmd -{ - my ($file, $is_alpha) = @_; - - # Get tests directory - my $testdir = $FindBin::Bin; - - eval { - if ($is_alpha == 0) { - open2(\*OUTFILE, \*CMDFILE, "$testdir/test_driver --np"); - } else { - open2(\*OUTFILE, \*CMDFILE, - "yod -quiet -sz 1 $testdir/test_driver --np"); - } - }; - - if ($@) { - if ($@ =~ /^open2/) { - warn "open2 failed: $!\n$@\n"; - return; - } - die; - - } - - my $outfh = \*OUTFILE; - my $cmdfh = \*CMDFILE; - - if ($is_alpha == 0) { - helper::send_cmd($cmdfh, $outfh, "init", "CALL init\n"); - } - - # Open file - my $cmdstr = '$fd = CALL open '."$file O_RDWR|O_CREAT|O_TRUNC S_IRWXU\n"; - helper::send_cmd($cmdfh, $outfh, "open", $cmdstr); - helper::verify_cmd($cmdfh, $outfh, $cmdstr); - - - do_rwcalls($cmdfh, $outfh, "fd"); - - # Clean up - $cmdstr = 'CALL close $fd'."\n"; - helper::send_cmd($cmdfh, $outfh, "close", $cmdstr); - -# system("rm -f $file"); - helper::print_and_exit($cmdfh, $outfh, 0, "strided IO test successful\n"); -} - -my $currarg = 0; -my $is_alpha = 0; - -if (@ARGV < 1) { - usage; -} elsif (@ARGV > 1 ) { - if ($ARGV[$currarg++] eq "-alpha") { - $is_alpha = 1; - } -} - -my $file = $ARGV[$currarg]; - -process_cmd($file, $is_alpha); - -exit 0; diff --git a/libsysio/tests/test_symlink.c b/libsysio/tests/test_symlink.c new file mode 100644 index 0000000..a8e134a2 --- /dev/null +++ b/libsysio/tests/test_symlink.c @@ -0,0 +1,140 @@ +/* + * This Cplant(TM) source code is the property of Sandia National + * Laboratories. + * + * This Cplant(TM) source code is copyrighted by Sandia National + * Laboratories. + * + * The redistribution of this Cplant(TM) source code is subject to the + * terms of the GNU Lesser General Public License + * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) + * + * Cplant(TM) Copyright 1998-2006 Sandia Corporation. + * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive + * license for use of this work by or on behalf of the US Government. + * Export of this program may require a license from the United States + * Government. + */ + +/* + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Questions or comments about this library should be sent to: + * + * Lee Ward + * Sandia National Laboratories, New Mexico + * P.O. Box 5800 + * Albuquerque, NM 87185-1110 + * + * lee@sandia.gov + */ + +#include +#include +#include +#include +#include +#include +#include +#if 0 +#include +#endif +#include +#include +#include + +#if defined(SYSIO_LABEL_NAMES) +#include "sysio.h" +#endif +#include "xtio.h" +#include "test.h" + +/* + * Test soft links + * + * Usage: symlink oldpath newpath + * + */ + +static void usage(void); + +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, "")) != -1) + switch (i) { + + default: + usage(); + } + + /* + * Init sysio lib. + */ + err = _test_sysio_startup(); + if (err) { + errno = -err; + perror("sysio startup"); + exit(1); + } + + n = argc - optind; + if (n < 2) usage(); + + /* + * Try paths listed on command-line. + */ + while (optind < argc) { + const char *old, *new; + struct stat stbuf; + + old = argv[optind++]; + new = argv[optind++]; + if ((err = SYSIO_INTERFACE_NAME(symlink)(old, new)) != 0) { + perror("link"); + break; + } + if ((err = SYSIO_INTERFACE_NAME(lstat)(new, &stbuf)) != 0) { + perror(new); + break; + } + } + + /* + * Clean up. + */ + _test_sysio_shutdown(); + + return err ? -1 : 0; +} + +static void +usage() +{ + + (void )fprintf(stderr, + "Usage: symlink" + " oldpath newpath\n"); + + exit(1); +} diff --git a/libsysio/tests/test_symlink.pl b/libsysio/tests/test_symlink.pl deleted file mode 100755 index 23d5185..0000000 --- a/libsysio/tests/test_symlink.pl +++ /dev/null @@ -1,247 +0,0 @@ -#!/usr/bin/perl -w - -# -# symlink test: Verify that symbolic links work -# - -use IPC::Open2; - -use strict; -use FindBin; -use lib "$FindBin::Bin"; -use helper; - -sub usage -{ - print "Usage: ./test_symlink.pl [-alpha] : Create a symlink from src to dest\n"; - exit(-1); -} - -sub clean_exit -{ - my ($cmdfh, $outfh, $exit_num, $exit_str) = @_; - - print STDOUT "$exit_str"; - - # Free buffers - my $cmdstr = 'FREE $srcbuf'."\n"; - - print $cmdfh $cmdstr; - - my $res = <$outfh>; - chop($res); - if ($res ne "0000 ") { - print STDOUT "ERROR! Failed to free srcbuf (code $res)\n"; - } - - $cmdstr = 'FREE $destbuf'."\n"; - - print $cmdfh $cmdstr; - - $res = <$outfh>; - chop($res); - if ($res ne "0000 ") { - print STDOUT "ERROR! Failed to free destbuf (code $res)\n"; - } - - print $cmdfh "exit\n"; - close $outfh; - - # Give test_driver time to finish - sleep 0.000001; - - exit $exit_num; -} - -sub process_cmd -{ - my ($src, $dest, $is_alpha) = @_; - - # Get tests directory - my $testdir = $FindBin::Bin; - - eval { - if ($is_alpha == 0) { - open2(\*OUTFILE, \*CMDFILE, "$testdir/test_driver --np"); - } else { - open2(\*OUTFILE, \*CMDFILE, "yod -quiet -sz 1 $testdir/test_driver --np"); - } - }; - - if ($@) { - if ($@ =~ /^open2/) { - warn "open2 failed: $!\n$@\n"; - return; - } - die; - - } - - my $outfh = \*OUTFILE; - my $cmdfh = \*CMDFILE; - - if ($is_alpha == 0) { - helper::send_cmd($cmdfh, $outfh, "init", "CALL init\n"); - } - - # Get the filesize of src - my $size = -s $src; - my $bufsize; - - if ( $size > 1024) { # Arbitrary limit - $bufsize = 1024; - } else { - $bufsize = $size; - } - - # Create the symbolic link from src to dest - my $cmdstr = "CALL symlink $src $dest\n"; - helper::send_cmd($cmdfh, $outfh, "open", $cmdstr); - - helper::verify_cmd($cmdfh, $outfh, "symlink"); - - # Open src - $cmdstr = '$src = CALL open '."$src O_RDONLY\n"; - helper::send_cmd($cmdfh, $outfh, "open", $cmdstr); - - # Open dest - $cmdstr = '$dest = CALL open '."$dest O_RDONLY\n"; - helper::send_cmd($cmdfh, $outfh, "open", $cmdstr); - - my $res = helper::verify_cmd($cmdfh, $outfh, "open $dest"); - - # Allocate buffer for src - $cmdstr = '$srcbuf = ALLOC '."$bufsize\n"; - helper::send_cmd($cmdfh, $outfh, "ALLOC", $cmdstr); - - # Allocate buffer for dest - $cmdstr = '$destbuf = ALLOC '."$bufsize\n"; - helper::send_cmd($cmdfh, $outfh, "ALLOC", $cmdstr); - - - # Read size bytes from src and dest, then compare them and verify they - # are the same - $cmdstr = 'CALL read $src $srcbuf '."$bufsize\n"; - helper::send_cmd($cmdfh, $outfh, "read $src", $cmdstr); - - $res = helper::verify_cmd($cmdfh, $outfh, "read $src"); - my $readb = oct($res); - - # Now read $readb from dest - $cmdstr = 'CALL read $dest $destbuf '."$readb\n"; - helper::send_cmd($cmdfh, $outfh, "read $dest", $cmdstr); - - $res = helper::verify_cmd($cmdfh, $outfh, "read $dest"); - - my $errstr; - if ($readb != oct($res)) { - $errstr = "ERROR! Read $readb bytes from src but only $res bytes from dest\n"; - clean_exit($cmdfh, $outfh, 1, $errstr); - } - - # Compare the two buffers - $cmdstr = 'CALL cmpstr $srcbuf $destbuf'."\n"; - helper::send_cmd($cmdfh, $outfh, "cmpstr", $cmdstr); - - # Verify that it returned an error - $cmdstr = 'PRINT $$'; - $cmdstr .= "\n"; - helper::send_cmd($cmdfh, $outfh, "PRINT", $cmdstr); - - $res = <$outfh>; - chop($res); - - $res = helper::verify_cmd($cmdfh, $outfh, "cmpstr"); - $res = oct($res); - if ($res != 0) { - $errstr = "ERROR! Buffers from $src and $dest do not match\n"; - clean_exit($cmdfh, $outfh, 1, $errstr); - } - - # Clean up - $cmdstr = 'CALL close $src'."\n"; - helper::send_cmd($cmdfh, $outfh, "close", $cmdstr); - $cmdstr = 'CALL close $dest'."\n"; - helper::send_cmd($cmdfh, $outfh, "close", $cmdstr); - - # Clear out destbuf - $cmdstr = 'CALL clear $destbuf'."\n"; - helper::send_cmd($cmdfh, $outfh, "CLEAR", $cmdstr); - - # Now remove the symbolic link and make sure everything stays the same - - # Remove the link (this assumes the link is not in incore) - $cmdstr = "CALL unlink $dest\n"; - helper::send_cmd($cmdfh, $outfh, "unlink", $cmdstr); - helper::verify_cmd($cmdfh, $outfh, "unlink"); - - # Attempt to open the symbolic link. This should return an error - $cmdstr = 'CALL open '."$dest O_RDONLY\n"; - helper::send_cmd($cmdfh, $outfh, "open", $cmdstr); - - # Verify that it returned an error - $cmdstr = 'PRINT $$'; - $cmdstr .= "\n"; - helper::send_cmd($cmdfh, $outfh, "PRINT", $cmdstr); - - $res = <$outfh>; - chop($res); - - if ($res ne "0xffffffff") { - $errstr = "ERROR! Open on $dest succeeded (should have failed)\n"; - clean_exit($cmdfh, $outfh, 1, $errstr); - } - - # Now read from the src again and make sure it matches the original - - # Open src - $cmdstr = '$src2 = CALL open '."$src O_RDONLY\n"; - helper::send_cmd($cmdfh, $outfh, "open", $cmdstr); - helper::verify_cmd($cmdfh, $outfh, "open $src(2)"); - - $cmdstr = 'CALL read $src2 $destbuf '."$readb\n"; - helper::send_cmd($cmdfh, $outfh, "read $src(2)", $cmdstr); - - $res = helper::verify_cmd($cmdfh, $outfh, "read $src(2)"); - - if ($readb != oct($res)) { - $errstr = "ERROR! Read $readb bytes from src originally but now only $res bytes\n"; - clean_exit($cmdfh, $outfh, 1, $errstr); - } - - # Compare the two buffers - $cmdstr = 'CALL cmpstr $srcbuf $destbuf'."\n"; - helper::send_cmd($cmdfh, $outfh, "cmpstr", $cmdstr); - $res = helper::verify_cmd($cmdfh, $outfh, "cmpstr"); - $res = oct($res); - if ($res != 0) { - $errstr = "ERROR! Original buffers from $src and new buf do not match\n"; - clean_exit($cmdfh, $outfh, 1, $errstr); - } - - # Clean up - $cmdstr = 'CALL close $src2'."\n"; - helper::send_cmd($cmdfh, $outfh, "close", $cmdstr); - - clean_exit($cmdfh, $outfh, 0, "Symlink test successful\n"); - exit 0; -} - -my $currarg = 0; -my $is_alpha = 0; - -if (@ARGV < 2) { - usage; -} elsif (@ARGV > 2 ) { - if ($ARGV[$currarg++] eq "-alpha") { - $is_alpha = 1; - } -} - -my $src = $ARGV[$currarg++]; -my $dest = $ARGV[$currarg]; - -process_cmd($src, $dest, $is_alpha); - - -exit 0; diff --git a/libsysio/tests/test_unlink.c b/libsysio/tests/test_unlink.c index 99f634b..3b02a9f 100644 --- a/libsysio/tests/test_unlink.c +++ b/libsysio/tests/test_unlink.c @@ -51,6 +51,7 @@ #include #endif #include +#include #if defined(SYSIO_LABEL_NAMES) #include "sysio.h" diff --git a/libsysio/tests/verifier.pl b/libsysio/tests/verifier.pl deleted file mode 100755 index 3afc51b..0000000 --- a/libsysio/tests/verifier.pl +++ /dev/null @@ -1,161 +0,0 @@ -#!/usr/bin/perl -w - -# Verifies that the contents of a given file produced by producer.pl with the given -# seed are good - -use IPC::Open2; - -use strict; -use helper; - -sub usage -{ - print "Usage: ./verifier.pl <-seed seed> <-file fname> : Verifies that file fname,\n"; - print " : produced with the given \n"; - print " : seed matches\n"; - exit(-1); -} - -sub get_buf -{ - my $MAX_SIZE = 2147483648; - - my $str; - my $num; - my $len = 0; - - while ($len < 512) { - $num = rand $MAX_SIZE; - my $tmpstr = sprintf("%d", $num); - $str .= $tmpstr; - $len += length $tmpstr; - } - - return ($len, $str); -} - - -sub check_file -{ - my ($cmdfh, $outfh, $filename) = @_; - - - # Allocate the read buffer - my $cmd = '$buf = ALLOC 1024'."\n"; - helper::send_cmd($cmdfh, $outfh, "alloc", $cmd); - - # Open the file - $cmd = '$fd = CALL open '."$filename O_RDONLY\n"; - helper::send_cmd($cmdfh, $outfh, "open", $cmd); - - # Verify the system call's output - helper::verify_cmd($cmdfh, $outfh, "open"); - - my $total = 0; - my $bytes = 0; - - # Read all of the file in 1024 byte chunks - do { - - # Clear the buffer - $cmd = 'CALL clear $buf'."\n"; - helper::send_cmd($cmdfh, $outfh, "clear", $cmd); - - my ($len, $buf) = get_buf; - - $cmd = 'CALL read $fd $buf '."$len\n"; - helper::send_cmd($cmdfh, $outfh, "read", $cmd); - $bytes = helper::verify_cmd($cmdfh, $outfh, "read"); - $bytes = oct($bytes); - $total += $bytes; - if ($bytes > 0) { - - # Print out the buffer - $cmd = 'PRINT $buf 0 1 STR'."\n"; - helper::send_cmd($cmdfh, $outfh, "print", $cmd); - my $str = <$outfh>; - chop($str); - if ($bytes > $len) { - $str = substr($str, 0, $len-1); - } elsif ($len > $bytes) { - $buf = substr($buf, 0, $bytes); - } - if ($str ne $buf) { - my $errstr = "ERROR! Str $str is not equal to str $buf\n"; - helper::print_and_exit($cmdfh, $outfh, 1, $errstr); - } - } - } while ($bytes > 0); - -} - -sub verify_file -{ - my ($filename, $is_alpha) = @_; - - eval { - if ($is_alpha == 0) { - open2(\*OUTFILE, \*CMDFILE, "./test_driver --np"); - } else { - open2(\*OUTFILE, \*CMDFILE, - "yod -batch -quiet -sz 1 ./test_driver --np"); - } - }; - - if ($@) { - if ($@ =~ /^open2/) { - warn "open2 failed: $!\n$@\n"; - return; - } - die; - - } - - my $outfh = \*OUTFILE; - my $cmdfh = \*CMDFILE; - - if ($is_alpha == 0) { - helper::send_cmd($cmdfh, $outfh, "init", "CALL init\n"); - } - - # Now check the file - check_file($cmdfh, $outfh, $filename); - - # Close the file - my $cmd = 'CALL close $fd'."\n"; - helper::send_cmd($cmdfh, $outfh, "close", $cmd); - - helper::verify_cmd($cmdfh, $outfh, "close"); - - # All done - helper::print_and_exit($cmdfh, $outfh, 0, "File $filename valid\n"); -} - - -my $is_alpha = 0; -my $seed = time; -my $filename = "randfile.$seed.$$"; -my $bytes = 1024; -for (my $i = 0; $i < @ARGV; $i++) -{ - if ($ARGV[$i] eq "-file") { - $i++; - $filename = $ARGV[$i]; - } elsif ($ARGV[$i] eq "-seed") { - $i++; - $seed = $ARGV[$i]; - } elsif ($ARGV[$i] eq "-alpha") { - $is_alpha = 1; - } -} - -# seed the randome number generator -srand $seed; - -verify_file($filename, $is_alpha); - -exit 0; - - - - -- 1.8.3.1