X-Git-Url: http://git.apps.os.sepia.ceph.com/?p=xfstests-dev.git;a=blobdiff_plain;f=dmapi%2Fsrc%2Fcommon%2Fcmd%2Fwrite_invis.c;h=a28bdeee6e1e80e4fda8a87ccf16f7ce3b9a14d6;hp=23d12ed5526d8de8b47ff1db2f6740309f65bd8c;hb=a3d6ec627d55cc33f232430967fa779d86710695;hpb=3ef12e382456faea5ff49d4261685d377f4fcab7 diff --git a/dmapi/src/common/cmd/write_invis.c b/dmapi/src/common/cmd/write_invis.c index 23d12ed5..a28bdeee 100644 --- a/dmapi/src/common/cmd/write_invis.c +++ b/dmapi/src/common/cmd/write_invis.c @@ -35,13 +35,17 @@ #include #include #include +#include +#include +#include /*--------------------------------------------------------------------------- Test program used to test the DMAPI function dm_write_invis(). The command line is: - write_invis [-c char] [-o offset] [-l length] [-s sid] pathname + write_invis [-c char] [-o offset] [-l length] [-s sid] \ + [-S storefile] {pathname|handle} where: 'char' is the character to use as a repeated pattern ('X' is the default), @@ -68,7 +72,7 @@ static void usage(void) { fprintf(stderr, "usage:\t%s [-c char] [-o offset] [-l length] " - "[-s sid] pathname\n", Progname); + "[-s sid] [-S storefile] {pathname|handle}\n", Progname); exit(1); } @@ -79,7 +83,7 @@ main( char **argv) { dm_sessid_t sid = DM_NO_SESSION; - char *pathname = NULL; + char *object = NULL; dm_off_t offset = 0; dm_size_t length = 1; u_char ch = 'X'; @@ -89,6 +93,9 @@ main( dm_ssize_t rc; char *name; int opt; + char *storefile = NULL; + int storefd; + int exit_status = 0; if (Progname = strrchr(argv[0], '/')) { Progname++; @@ -98,27 +105,30 @@ main( /* Crack and validate the command line options. */ - while ((opt = getopt(argc, argv, "c:o:l:s:")) != EOF) { + while ((opt = getopt(argc, argv, "c:o:l:s:S:")) != EOF) { switch (opt) { case 'c': ch = *optarg; break; case 'o': - offset = atol(optarg); + sscanf(optarg, "%lld", &offset); break; case 'l': - length = atol(optarg); + sscanf(optarg, "%llu", &length); break; case 's': sid = atol(optarg); break; + case 'S': + storefile = optarg; + break; case '?': usage(); } } if (optind + 1 != argc) usage(); - pathname = argv[optind]; + object = argv[optind]; if (dm_init_service(&name) == -1) { fprintf(stderr, "Can't initialize the DMAPI\n"); @@ -129,8 +139,8 @@ main( /* Get the file's handle. */ - if (dm_path_to_handle(pathname, &hanp, &hlen)) { - fprintf(stderr, "can't get handle for file %s\n", pathname); + if (opaque_to_handle(object, &hanp, &hlen)) { + fprintf(stderr, "can't get handle for %s\n", object); exit(1); } @@ -145,16 +155,39 @@ main( memset(bufp, ch, length); } + if (storefile) { + ssize_t sret; + size_t len; + + if ((storefd = open(storefile, O_RDONLY)) == -1) { + fprintf(stderr, "unable to open store file for read (%s), errno = %d\n", storefile, errno); + exit(1); + } + + len = length; + sret = read(storefd, bufp, len); + if (sret < 0) { + fprintf(stderr, "unable to read store file (%s), errno = %d\n", storefile, errno); + exit(1); + } + else if (sret != length) { + fprintf(stderr, "read(%s) returned %lld, expected %lld\n", + storefile, (long long)sret, (long long)length); + exit(1); + } + close(storefd); + } + rc = dm_write_invis(sid, hanp, hlen, DM_NO_TOKEN, 0, offset, length, bufp); if (rc < 0) { fprintf(stderr, "dm_write_invis failed, %s\n", strerror(errno)); - exit(1); + exit_status++; } else if (rc != length) { - fprintf(stderr, "expected to write %lld bytes, actually " + fprintf(stderr, "dm_write_invis expected to write %lld bytes, actually " "wrote %lld\n", length, rc); - exit(1); + exit_status++; } dm_handle_free(hanp, hlen); - exit(0); + exit(exit_status); }