Add storefile option to DMAPI invis I/O tests

add storefile option
This commit is contained in:
Dean Roehrich
2003-09-30 20:20:59 +00:00
parent 4f9557442f
commit 170d452e56
2 changed files with 99 additions and 19 deletions
+55 -12
View File
@@ -37,13 +37,17 @@
#include <string.h>
#include <malloc.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
/*---------------------------------------------------------------------------
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++;
}
for (i = 0; i < rc; i++) {
if (isprint(bufp[i])) {
fprintf(stdout, "%c", bufp[i]);
} else {
fprintf(stdout, "\\%03d", bufp[i]);
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);
}
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);
}
+44 -7
View File
@@ -35,13 +35,17 @@
#include <string.h>
#include <malloc.h>
#include <getopt.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
/*---------------------------------------------------------------------------
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);
}