#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),
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);
}
char *name;
int opt;
int i;
+ char *storefile = NULL;
+ int storefd;
+ int exit_status = 0;
if (Progname = strrchr(argv[0], '/')) {
Progname++;
/* 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);
* the params.
*/
break;
+ case 'S':
+ storefile = optarg;
+ break;
case '?':
usage();
}
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);
}
#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),
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);
}
dm_ssize_t rc;
char *name;
int opt;
+ char *storefile = NULL;
+ int storefd;
+ int exit_status = 0;
if (Progname = strrchr(argv[0], '/')) {
Progname++;
/* 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;
case 's':
sid = atol(optarg);
break;
+ case 'S':
+ storefile = optarg;
+ break;
case '?':
usage();
}
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);
}