1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2001 Silicon Graphics, Inc.
13 #include <sys/types.h>
17 /*---------------------------------------------------------------------------
19 Test program used to test the DMAPI function dm_write_invis(). The
22 write_invis [-c char] [-o offset] [-l length] [-s sid] \
23 [-S storefile] {pathname|handle}
26 'char' is the character to use as a repeated pattern ('X' is the default),
27 'offset' is the offset of the start of the write (0 is the default),
28 'length' is the length of the write in bytes (1 is the default),
29 'sid' is the session ID whose events you you are interested in.
30 'pathname' is the name of the file to be written.
32 DM_WRITE_SYNC is is not supported.
34 ----------------------------------------------------------------------------*/
37 extern char *sys_errlist[];
49 fprintf(stderr, "usage:\t%s [-c char] [-o offset] [-l length] "
50 "[-s sid] [-S storefile] {pathname|handle}\n", Progname);
60 dm_sessid_t sid = DM_NO_SESSION;
65 unsigned long long ulltemp;
73 char *storefile = NULL;
77 Progname = strrchr(argv[0], '/');
84 /* Crack and validate the command line options. */
86 while ((opt = getopt(argc, argv, "c:o:l:s:S:")) != EOF) {
92 sscanf(optarg, "%lld", &lltemp);
93 offset = (dm_off_t) offset;
96 sscanf(optarg, "%llu", &ulltemp);
97 length = (dm_size_t) ulltemp;
109 if (optind + 1 != argc)
111 object = argv[optind];
113 if (dm_init_service(&name) == -1) {
114 fprintf(stderr, "Can't initialize the DMAPI\n");
117 if (sid == DM_NO_SESSION)
118 find_test_session(&sid);
120 /* Get the file's handle. */
122 if (opaque_to_handle(object, &hanp, &hlen)) {
123 fprintf(stderr, "can't get handle for %s\n", object);
128 /* In case it is a realtime file, align the buffer on a
129 sufficiently big boundary.
131 if ((bufp = memalign(4096, length)) == NULL) {
132 fprintf(stderr, "malloc of %llu bytes failed\n",
133 (unsigned long long) length);
136 memset(bufp, ch, length);
143 if ((storefd = open(storefile, O_RDONLY)) == -1) {
144 fprintf(stderr, "unable to open store file for read (%s), errno = %d\n", storefile, errno);
149 sret = read(storefd, bufp, len);
151 fprintf(stderr, "unable to read store file (%s), errno = %d\n", storefile, errno);
154 else if (sret != length) {
155 fprintf(stderr, "read(%s) returned %lld, expected %lld\n",
156 storefile, (long long)sret, (long long)length);
162 rc = dm_write_invis(sid, hanp, hlen, DM_NO_TOKEN, 0, offset, length, bufp);
165 fprintf(stderr, "dm_write_invis failed, %s\n", strerror(errno));
167 } else if (rc != length) {
168 fprintf(stderr, "dm_write_invis expected to write %llu bytes, "
169 "actually wrote %lld\n",
170 (unsigned long long) length, (long long)rc);
173 dm_handle_free(hanp, hlen);