From: Dean Roehrich Date: Tue, 30 Sep 2003 20:20:59 +0000 (+0000) Subject: Add storefile option to DMAPI invis I/O tests X-Git-Tag: v1.1.0~907 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=170d452e56aa59326dc7c1eff62b602f3a97a7d9;p=users%2Fhch%2Fxfstests-dev.git Add storefile option to DMAPI invis I/O tests add storefile option --- diff --git a/dmapi/src/common/cmd/read_invis.c b/dmapi/src/common/cmd/read_invis.c index 0f3ba70df..0a622b064 100644 --- a/dmapi/src/common/cmd/read_invis.c +++ b/dmapi/src/common/cmd/read_invis.c @@ -37,13 +37,17 @@ #include #include #include +#include +#include +#include /*--------------------------------------------------------------------------- Test program used to test the DMAPI function dm_read_invis(). The command line is: - read_invis [-o offset] [-l length] [-s sid] [-c char] {pathname|handle} + read_invis [-o offset] [-l length] [-s sid] [-c char] \ + [-S storefile] {pathname|handle} where: 'offset' is the offset of the start of the write (0 is the default), @@ -69,7 +73,8 @@ static void usage(void) { fprintf(stderr, "usage:\t%s [-o offset] [-l length] " - "[-s sid] [-c char] {pathname|handle}\n", Progname); + "[-s sid] [-c char] " + "[-S storefile] {pathname|handle}\n", Progname); exit(1); } @@ -90,6 +95,9 @@ main( char *name; int opt; int i; + char *storefile = NULL; + int storefd; + int exit_status = 0; if (Progname = strrchr(argv[0], '/')) { Progname++; @@ -99,7 +107,7 @@ main( /* Crack and validate the command line options. */ - while ((opt = getopt(argc, argv, "o:l:s:c:")) != EOF) { + while ((opt = getopt(argc, argv, "o:l:s:c:S:")) != EOF) { switch (opt) { case 'o': sscanf(optarg, "%lld", &offset); @@ -117,6 +125,9 @@ main( * the params. */ break; + case 'S': + storefile = optarg; + break; case '?': usage(); } @@ -150,23 +161,55 @@ main( memset(bufp, '\0', length); } + if (storefile) { + off_t lret; + + if ((storefd = open(storefile, O_WRONLY|O_CREAT, 0777)) == -1) { + fprintf(stderr, "unable to open store file for write (%s), errno = %d\n", storefile, errno); + exit(1); + } + lret = lseek(storefd, offset, SEEK_SET); + if (lret < 0) { + fprintf(stderr, "unable to lseek(%s) to offset %lld, errno = %d\n", + storefile, (long long)lret, errno); + exit(1); + } + } + rc = dm_read_invis(sid, hanp, hlen, DM_NO_TOKEN, offset, length, bufp); if (rc < 0) { fprintf(stderr, "dm_read_invis failed, %s\n", strerror(errno)); - exit(1); + exit_status++; } else if (rc != length) { - fprintf(stderr, "expected to read %lld bytes, actually " + fprintf(stderr, "dm_read_invis expected to read %lld bytes, actually " "read %lld\n", length, rc); - exit(1); + exit_status++; + } + + if (storefile) { + ssize_t sret; + sret = write(storefd, bufp, rc); + if (sret < 0) { + fprintf(stderr, "unable to write to store file (%s), errno = %d\n", storefile, errno); + exit_status++; + } + else if (sret != rc) { + fprintf(stderr, "write(%s) returned %lld, expected %lld\n", + storefile, (long long)sret, (long long)rc); + exit_status++; + } + close(storefd); } - for (i = 0; i < rc; i++) { - if (isprint(bufp[i])) { - fprintf(stdout, "%c", bufp[i]); - } else { - fprintf(stdout, "\\%03d", bufp[i]); + else { + for (i = 0; i < rc; i++) { + if (isprint(bufp[i])) { + fprintf(stdout, "%c", bufp[i]); + } else { + fprintf(stdout, "\\%03d", bufp[i]); + } } } dm_handle_free(hanp, hlen); - exit(0); + exit(exit_status); } diff --git a/dmapi/src/common/cmd/write_invis.c b/dmapi/src/common/cmd/write_invis.c index bba87016f..d543c8d70 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|handle} + 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|handle}\n", Progname); + "[-s sid] [-S storefile] {pathname|handle}\n", Progname); exit(1); } @@ -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,7 +105,7 @@ 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; @@ -112,6 +119,9 @@ main( case 's': sid = atol(optarg); break; + case 'S': + storefile = optarg; + break; case '?': usage(); } @@ -145,16 +155,43 @@ main( memset(bufp, ch, length); } + if (storefile) { + ssize_t sret; + off_t lret; + + if ((storefd = open(storefile, O_RDONLY)) == -1) { + fprintf(stderr, "unable to open store file for read (%s), errno = %d\n", storefile, errno); + exit(1); + } + lret = lseek(storefd, offset, SEEK_SET); + if (lret < 0) { + fprintf(stderr, "unable to lseek(%s) to offset %lld, errno = %d\n", + storefile, (long long)lret, errno); + exit(1); + } + sret = read(storefd, bufp, length); + 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); }