[Libsysio-commit] HEAD: libsysio/tests test_fhipath.c Makefile.am module.mk
Brought to you by:
lward
From: Lee W. <lw...@us...> - 2009-02-04 20:07:36
|
Update of /cvsroot/libsysio/libsysio/tests In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv1058/tests Modified Files: Makefile.am module.mk Added Files: test_fhipath.c Log Message: A new API, built when --with-file-handle-interface is set to yes, is available with this deposit. The API allows operation by handles derived from exported volumes. At this point, it's not incredibly well tested. What is tested is the export/unexport functionality and the root_of, lookup, and stat functions. Hopefully, this will mature quickly. Not yet included is the ability to use credentials other than the caller's from it's process credentials. That ability should be here soon. --- NEW FILE --- /* * 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 * * le...@sa... */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <errno.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <sys/uio.h> #include <getopt.h> #include <sys/statvfs.h> #if defined(SYSIO_LABEL_NAMES) #include "sysio.h" #endif #include "xtio.h" #include "test.h" #include "../misc/fhi.h" /* * Stat files. * * Usage: test_path [export-path] [path...] * * Without any path arguments, the program reads from standard-in, dealing with * each line as an absolute or relative path until EOF. */ static int key; static char root_handle_data[128]; static struct file_handle_info root_handle = { NULL, root_handle_data, sizeof(root_handle_data) }; static int statit(const char *path); static void usage(void); int main(int argc, char *const argv[]) { int i; int err; ssize_t cc; 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); } if (!(argc - optind)) usage(); key = 1; err = SYSIO_INTERFACE_NAME(fhi_export)(&key, sizeof(key), argv[optind], 0, &root_handle.fhi_export); if (err) { perror(argv[optind]); exit(1); } cc = SYSIO_INTERFACE_NAME(fhi_root_of)(root_handle.fhi_export, &root_handle); if (cc < 0) { perror(argv[optind]); exit(1); } if ((size_t )cc >= sizeof(root_handle_data)) { (void )fprintf(stderr, "%s: handle data too large\n", argv[optind]); exit(1); } optind++; n = argc - optind; /* * Try path(s) listed on command-line. */ while (optind < argc) { const char *path; path = argv[optind++]; (void )statit(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) statit(buf); doflush = c == '\n' ? 0 : 1; } } /* * Clean up. */ err = SYSIO_INTERFACE_NAME(fhi_unexport)(root_handle.fhi_export); if (err) { perror("FHI unexport"); exit(1); } _test_sysio_shutdown(); return 0; } static int statit(const char *path) { char handle_data[128]; struct file_handle_info handle = { NULL, handle_data, sizeof(handle_data) }; int err; struct stat64 stbuf; char t; static char buf[4096]; ssize_t cc; /* * Get file attrs. */ cc = SYSIO_INTERFACE_NAME(fhi_lookup)(&root_handle, path, 0, &handle); if (cc < 0) { perror(path); return -1; } if ((size_t )cc >= sizeof(root_handle_data)) { (void )fprintf(stderr, "%s: handle data too large\n", path); exit(1); } err = SYSIO_INTERFACE_NAME(fhi_getattr)(&handle, &stbuf); if (err) { perror(path); return -1; } /* * Get readable representation of file type. */ if (S_ISDIR(stbuf.st_mode)) t = 'd'; else if (S_ISCHR(stbuf.st_mode)) t = 'c'; else if (S_ISBLK(stbuf.st_mode)) t = 'b'; else if (S_ISREG(stbuf.st_mode)) t = 'f'; #ifdef S_ISFIFO else if (S_ISFIFO(stbuf.st_mode)) t = 'p'; #endif #ifdef S_ISLNK else if (S_ISLNK(stbuf.st_mode)) t = 'S'; #endif #ifdef S_ISSOCK else if (S_ISSOCK(stbuf.st_mode)) t = 's'; #endif #ifdef S_TYPEISMQ else if (S_TYPEISMQ(&stbuf)) t = 'q'; #endif #ifdef S_TYPEISSEM else if (S_TYPEISSEM(&stbuf)) t = 'M'; #endif #ifdef S_TYPEISSHM else if (S_TYPEISSHM(&stbuf)) t = 'm'; #endif else t = '?'; /* * Print path and type. */ if (S_ISLNK(stbuf.st_mode)) { cc = SYSIO_INTERFACE_NAME(readlink)(path, buf, sizeof(buf)); if (cc < 0) { perror(path); return -1; } } (void )printf("%s: %c", path, t); if (S_ISLNK(stbuf.st_mode) && (size_t )cc < sizeof(buf)) (void )printf(" %.*s", (int )cc, buf); (void )putchar('\n'); return 0; } static void usage() { (void )fprintf(stderr, "Usage: test_path" "<export-path> " " [<path>...]\n"); exit(1); } Index: Makefile.am =================================================================== RCS file: /cvsroot/libsysio/libsysio/tests/Makefile.am,v retrieving revision 1.34 retrieving revision 1.35 diff -u -w -b -B -p -r1.34 -r1.35 --- Makefile.am 28 Jan 2009 16:17:20 -0000 1.34 +++ Makefile.am 4 Feb 2009 20:07:23 -0000 1.35 @@ -4,10 +4,16 @@ else STATVFS_PROG= endif +if WITH_FILE_HANDLE_INTERFACE +FHI_PROG=test_fhipath +else +FHI_PROG= +endif + noinst_PROGRAMS = test_copy test_stats test_path test_list \ test_getcwd test_link test_unlink test_symlink \ test_rename test_regions test_stddir test_fcntl_lock test_mknod \ - test_mkdir test_chown $(STATVFS_PROG) + test_mkdir test_chown $(STATVFS_PROG) $(FHI_PROG) CLEANFILES=drv_data.c @@ -103,6 +109,10 @@ test_statvfs_SOURCES=test_statvfs.c $(CM test_statvfs_CFLAGS=$(CFL) test_statvfs_DEPENDENCIES=$(LIBS) +test_fhipath_SOURCES=test_fhipath.c $(CMNSRC) +test_fhipath_CFLAGS=$(CFL) +test_fhipath_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 Index: module.mk =================================================================== RCS file: /cvsroot/libsysio/libsysio/tests/module.mk,v retrieving revision 1.4 retrieving revision 1.5 diff -u -w -b -B -p -r1.4 -r1.5 --- module.mk 28 Jan 2009 15:54:36 -0000 1.4 +++ module.mk 4 Feb 2009 20:07:23 -0000 1.5 @@ -20,4 +20,5 @@ TESTS_EXTRA = \ tests/test_stddir.c \ tests/test_symlink.c \ tests/test_unlink.c \ + tests/test_fhipath.c \ tests/Makefile.am tests/Makefile.in tests/module.mk |