[Libsysio-commit] HEAD: libsysio/tests test_fhichmod.c test_fhicreate.c test_fhilink.c test_fhilist
Brought to you by:
lward
Update of /cvsroot/libsysio/libsysio/tests In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv3124 Added Files: test_fhichmod.c test_fhicreate.c test_fhilink.c test_fhilist.c test_fhimkdir.c test_fhirename.c test_fhirmdir.c test_fhisymlink.c test_fhitrunc.c test_fhiunlink.c Log Message: New test. --- 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-2009 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-1319 * * 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" #include "fhi_support.h" /* * Link files. * * Usage: test_fhichmod <path> <perms> */ 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 chmodit(const char *path, const char *s); 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); } if (!(argc - optind)) usage(); key = 1; if (_test_fhi_start(&key, argv[optind], &root_handle)) { exit(1); } optind++; n = argc - optind; if (n != 2) usage(); n = chmodit(argv[optind], argv[optind + 1]); /* * Clean up. */ err = SYSIO_INTERFACE_NAME(fhi_unexport)(root_handle.fhi_export); if (err) { perror("FHI unexport"); exit(1); } _test_sysio_shutdown(); return n ? 1 : 0; } static int chmodit(const char *path, const char *s) { long perms; char *cp; char handle_data[128]; struct file_handle_info handle = { NULL, handle_data, sizeof(handle_data) }; int err; struct file_handle_info_sattr setattr; perms = strtol(s, &cp, 0); if (*s == '\0' || *cp != '\0' || perms < 0 || perms > 0xffff) { (void )fprintf(stderr, "Invalid permissions\n"); return -1; } err = _test_fhi_find(&root_handle, path, &handle); if (err) { perror(path); return -1; } FHISATTR_CLEAR(&setattr); FHISATTR_SET_MODE(&setattr, (mode_t )perms); err = SYSIO_INTERFACE_NAME(fhi_setattr)(&handle, &setattr); if (err) { perror("fhi_chmod"); return -1; } return 0; } static void usage() { (void )fprintf(stderr, "Usage: test_fhichmod" " <path> " " <perms>\n"); exit(1); } --- 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-2009 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-1319 * * 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" #include "fhi_support.h" /* * Create files. * * Usage: test_fhicreate [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 createit(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); } if (!(argc - optind)) usage(); key = 1; if (_test_fhi_start(&key, argv[optind], &root_handle)) { exit(1); } optind++; n = argc - optind; /* * Try path(s) listed on command-line. */ while (optind < argc) { const char *path; path = argv[optind++]; (void )createit(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) createit(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 createit(const char *path) { char handle_data[128]; struct file_handle_info handle = { NULL, handle_data, sizeof(handle_data) }; int err; struct file_handle_info_dirop_args where; err = _test_fhi_find(&root_handle, path, &handle); if (err == ENOENT) err = 0; else if (!err) err = -EEXIST; if (err) { perror(path); return -1; } where.fhida_path = path; where.fhida_dir = &root_handle; err = SYSIO_INTERFACE_NAME(fhi_create)(&where, 0644); if (err) { perror(path); return -1; } err = _test_fhi_find(&root_handle, path, &handle); if (err) { perror(path); return -1; } return 0; } static void usage() { (void )fprintf(stderr, "Usage: test_fhicreate" " <export-path> " " [<path>...]\n"); exit(1); } --- 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-2009 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-1319 * * 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" #include "fhi_support.h" /* * Link files. * * Usage: test_fhilink <old-path> <new-path> */ 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 linkit(const char *from, const char *to); 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); } if (!(argc - optind)) usage(); key = 1; if (_test_fhi_start(&key, argv[optind], &root_handle)) { exit(1); } optind++; n = argc - optind; if (n != 2) usage(); n = linkit(argv[optind], argv[optind + 1]); /* * Clean up. */ err = SYSIO_INTERFACE_NAME(fhi_unexport)(root_handle.fhi_export); if (err) { perror("FHI unexport"); exit(1); } _test_sysio_shutdown(); return n ? 1 : 0; } static int linkit(const char *from, const char *to) { char handle_data[128]; struct file_handle_info handle = { NULL, handle_data, sizeof(handle_data) }; int err; struct file_handle_info_dirop_args args[2]; err = _test_fhi_find(&root_handle, to, &handle); if (err == ENOENT) err = 0; else if (!err) err = -EEXIST; if (err) { perror(to); return -1; } args[0].fhida_path = from; args[0].fhida_dir = &root_handle; args[1].fhida_path = to; args[1].fhida_dir = &root_handle; err = SYSIO_INTERFACE_NAME(fhi_link)(&args[0], &args[1]); if (err) { perror("Can't link"); return -1; } err = _test_fhi_find(&root_handle, to, &handle); if (err) { perror(to); return -1; } return 0; } static void usage() { (void )fprintf(stderr, "Usage: test_fhilink" " <old-path> " " <new-path>\n"); exit(1); } --- 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-2009 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-1319 * * le...@sa... */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <errno.h> #include <dirent.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" #include "fhi_support.h" /* * list files in given directories * * Usage: test_fhilist [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 listit(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); } if (!(argc - optind)) usage(); key = 1; if (_test_fhi_start(&key, argv[optind], &root_handle)) { exit(1); } optind++; n = argc - optind; /* * Try path(s) listed on command-line. */ while (optind < argc) { const char *path; path = argv[optind++]; (void )listit(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) listit(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 listit(const char *path) { char handle_data[128]; struct file_handle_info handle = { NULL, handle_data, sizeof(handle_data) }; int err; static char buf[4096]; ssize_t cc; struct dirent64 *dp; off64_t base; err = _test_fhi_find(&root_handle, path, &handle); if (err) { perror(path); return -1; } base = 0; for (;;) { cc = SYSIO_INTERFACE_NAME(fhi_getdirentries64)(&handle, buf, sizeof(buf), &base); if (cc <= 0) break; dp = (struct dirent64 *)buf; while (cc > 0) { (void )printf("\t%s: ino %llu type %u\n", dp->d_name, (unsigned long long )dp->d_ino, (unsigned )dp->d_type); assert(cc >= dp->d_reclen); cc -= dp->d_reclen; dp = (struct dirent64 *)((char *)dp + dp->d_reclen); } } if (cc < 0) { perror(path); return -1; } return 0; } static void usage() { (void )fprintf(stderr, "Usage: test_fhilist" " <export-path> " " [<path>...]\n"); exit(1); } --- 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-2009 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-1319 * * 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" #include "fhi_support.h" /* * Stat files. * * Usage: test_fhimkdir [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 mkdirit(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); } if (!(argc - optind)) usage(); key = 1; if (_test_fhi_start(&key, argv[optind], &root_handle)) { exit(1); } optind++; n = argc - optind; /* * Try path(s) listed on command-line. */ while (optind < argc) { const char *path; path = argv[optind++]; (void )mkdirit(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) mkdirit(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 mkdirit(const char *path) { char handle_data[128]; struct file_handle_info handle = { NULL, handle_data, sizeof(handle_data) }; int err; ssize_t cc; struct file_handle_info_dirop_args where; where.fhida_path = path; where.fhida_dir = &root_handle; err = SYSIO_INTERFACE_NAME(fhi_mkdir)(&where, 0755); if (err) { perror(path); return -1; } cc = _test_fhi_find(&root_handle, path, &handle); if (cc < 0) { perror(path); return -1; } return 0; } static void usage() { (void )fprintf(stderr, "Usage: test_fhimkdir" " <export-path> " " [<path>...]\n"); exit(1); } --- 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-2009 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-1319 * * 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" #include "fhi_support.h" /* * Link files. * * Usage: test_fhirename <old-path> <new-path> */ 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 renameit(const char *from, const char *to); 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); } if (!(argc - optind)) usage(); key = 1; if (_test_fhi_start(&key, argv[optind], &root_handle)) { exit(1); } optind++; n = argc - optind; if (n != 2) usage(); n = renameit(argv[optind], argv[optind + 1]); /* * Clean up. */ err = SYSIO_INTERFACE_NAME(fhi_unexport)(root_handle.fhi_export); if (err) { perror("FHI unexport"); exit(1); } _test_sysio_shutdown(); return n ? 1 : 0; } static int renameit(const char *from, const char *to) { char handle_data[128]; struct file_handle_info handle = { NULL, handle_data, sizeof(handle_data) }; int err; struct file_handle_info_dirop_args args[2]; err = _test_fhi_find(&root_handle, to, &handle); if (err == ENOENT) err = 0; else if (!err) err = -EEXIST; if (err) { perror(to); return -1; } args[0].fhida_path = from; args[0].fhida_dir = &root_handle; args[1].fhida_path = to; args[1].fhida_dir = &root_handle; err = SYSIO_INTERFACE_NAME(fhi_rename)(&args[0], &args[1]); if (err) { perror("Can't rename"); return -1; } err = _test_fhi_find(&root_handle, to, &handle); if (err) { perror(to); return -1; } return 0; } static void usage() { (void )fprintf(stderr, "Usage: test_fhirename" " <old-path> " " <new-path>\n"); exit(1); } --- 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-2009 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-1319 * * 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" #include "fhi_support.h" /* * Stat files. * * Usage: test_fhirmdir [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 rmdirit(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); } if (!(argc - optind)) usage(); key = 1; if (_test_fhi_start(&key, argv[optind], &root_handle)) { exit(1); } optind++; n = argc - optind; /* * Try path(s) listed on command-line. */ while (optind < argc) { const char *path; path = argv[optind++]; (void )rmdirit(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) rmdirit(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 rmdirit(const char *path) { char handle_data[128]; struct file_handle_info handle = { NULL, handle_data, sizeof(handle_data) }; int err; ssize_t cc; struct file_handle_info_dirop_args where; where.fhida_path = path; where.fhida_dir = &root_handle; err = SYSIO_INTERFACE_NAME(fhi_rmdir)(&where); if (err) { perror(path); return -1; } cc = _test_fhi_find(&root_handle, path, &handle); if (cc < 0) { perror(path); return -1; } return 0; } static void usage() { (void )fprintf(stderr, "Usage: test_fhirmdir" " <export-path> " " [<path>...]\n"); exit(1); } --- 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-2009 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-1319 * * 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" #include "fhi_support.h" /* * Link files. * * Usage: test_fhisymlink <old-path> <new-path> */ 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 symlinkit(const char *from, const char *to); 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); } if (!(argc - optind)) usage(); key = 1; if (_test_fhi_start(&key, argv[optind], &root_handle)) { exit(1); } optind++; n = argc - optind; if (n != 2) usage(); n = symlinkit(argv[optind], argv[optind + 1]); /* * Clean up. */ err = SYSIO_INTERFACE_NAME(fhi_unexport)(root_handle.fhi_export); if (err) { perror("FHI unexport"); exit(1); } _test_sysio_shutdown(); return n ? 1 : 0; } static int symlinkit(const char *from, const char *to) { char handle_data[128]; struct file_handle_info handle = { NULL, handle_data, sizeof(handle_data) }; int err; struct file_handle_info_dirop_args arg; err = _test_fhi_find(&root_handle, to, &handle); if (err == ENOENT) err = 0; else if (!err) err = -EEXIST; if (err) { perror(to); return -1; } arg.fhida_path = to; arg.fhida_dir = &root_handle; err = SYSIO_INTERFACE_NAME(fhi_symlink)(from, &arg); if (err) { perror("Can't symlink"); return -1; } err = _test_fhi_find(&root_handle, from, &handle); if (err) { perror(to); return -1; } return 0; } static void usage() { (void )fprintf(stderr, "Usage: test_fhisymlink" " <old-path> " " <new-path>\n"); exit(1); } --- 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-2009 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-1319 * * 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" #include "fhi_support.h" /* * Link files. * * Usage: test_fhitrunc <path> <size> */ 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 truncit(const char *path, const char *s); 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); } if (!(argc - optind)) usage(); key = 1; if (_test_fhi_start(&key, argv[optind], &root_handle)) { exit(1); } optind++; n = argc - optind; if (n != 2) usage(); n = truncit(argv[optind], argv[optind + 1]); /* * Clean up. */ err = SYSIO_INTERFACE_NAME(fhi_unexport)(root_handle.fhi_export); if (err) { perror("FHI unexport"); exit(1); } _test_sysio_shutdown(); return n ? 1 : 0; } static int truncit(const char *path, const char *s) { long long fsiz; char *cp; char handle_data[128]; struct file_handle_info handle = { NULL, handle_data, sizeof(handle_data) }; int err; struct file_handle_info_sattr setattr; fsiz = strtoll(s, &cp, 0); if (*s == '\0' || *cp != '\0' || fsiz < 0 || (fsiz == LLONG_MAX && errno == ERANGE)) { (void )fprintf(stderr, "Invalid size\n"); return -1; } err = _test_fhi_find(&root_handle, path, &handle); if (err) { perror(path); return -1; } FHISATTR_CLEAR(&setattr); FHISATTR_SET_SIZE(&setattr, (off64_t )fsiz); err = SYSIO_INTERFACE_NAME(fhi_setattr)(&handle, &setattr); if (err) { perror("fhi_trunc"); return -1; } return 0; } static void usage() { (void )fprintf(stderr, "Usage: test_fhitrunc" " <path> " " <size>\n"); exit(1); } --- 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-2009 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-1319 * * 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" #include "fhi_support.h" /* * Stat files. * * Usage: test_fhiunlink [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 unlinkit(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); } if (!(argc - optind)) usage(); key = 1; if (_test_fhi_start(&key, argv[optind], &root_handle)) { exit(1); } optind++; n = argc - optind; /* * Try path(s) listed on command-line. */ while (optind < argc) { const char *path; path = argv[optind++]; (void )unlinkit(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) unlinkit(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 unlinkit(const char *path) { char handle_data[128]; struct file_handle_info handle = { NULL, handle_data, sizeof(handle_data) }; int err; ssize_t cc; struct file_handle_info_dirop_args where; where.fhida_path = path; where.fhida_dir = &root_handle; err = SYSIO_INTERFACE_NAME(fhi_unlink)(&where); if (err) { perror(path); return -1; } cc = _test_fhi_find(&root_handle, path, &handle); if (cc < 0) { perror(path); return -1; } return 0; } static void usage() { (void )fprintf(stderr, "Usage: test_fhiunlink" " <export-path> " " [<path>...]\n"); exit(1); } |