1 /*
2 * Copyright (c) International Business Machines Corp., 2004
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
12 * the GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 /*
20 * TEST CASE : invis.c
21 *
22 * VARIATIONS : 32
23 *
24 * API'S TESTED : dm_read_invis
25 * dm_write_invis
26 */
27 #include <string.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <errno.h>
31 #include <pthread.h>
32 #include <unistd.h>
33 #include <sys/stat.h>
34 #include <sys/mount.h>
35 #include <fcntl.h>
36 #include "dm_test.h"
37
38 #define TMP_FILELEN 1000
39
40 pthread_t tid;
41 dm_sessid_t sid;
42 char dmMsgBuf[4096];
43 char command[4096];
44 char *mountPt;
45 char *deviceNm;
46 char DummyFile[FILENAME_MAX];
47 char DummySubdir[FILENAME_MAX];
48 char DummyTmp[FILENAME_MAX];
49 char DummyString[DUMMY_STRLEN];
50
51 /* Variables for thread communications */
52 dm_eventtype_t eventReceived;
53 void *hanp1;
54 size_t hlen1;
55 dm_off_t offset;
56 dm_size_t length;
57 int numRegions;
58 dm_region_t maxRegions[1], minRegions[1];
59
60 void *Thread(void *);
61
LogStat(struct stat * statfs)62 void LogStat(struct stat *statfs)
63 {
64
65 DMLOG_PRINT(DMLVL_DEBUG, " st_dev %d\n", statfs->st_dev);
66 DMLOG_PRINT(DMLVL_DEBUG, " st_ino %d\n", statfs->st_ino);
67 DMLOG_PRINT(DMLVL_DEBUG, " st_mode 0x%x\n", statfs->st_mode);
68 DMLOG_PRINT(DMLVL_DEBUG, " st_nlink %d\n", statfs->st_nlink);
69 DMLOG_PRINT(DMLVL_DEBUG, " st_uid %d\n", statfs->st_uid);
70 DMLOG_PRINT(DMLVL_DEBUG, " st_gid %d\n", statfs->st_gid);
71 DMLOG_PRINT(DMLVL_DEBUG, " st_rdev %d\n", statfs->st_rdev);
72 DMLOG_PRINT(DMLVL_DEBUG, " st_size %lld\n", statfs->st_size);
73 DMLOG_PRINT(DMLVL_DEBUG, " st_blksize %d\n", statfs->st_blksize);
74 DMLOG_PRINT(DMLVL_DEBUG, " st_blocks %d\n", statfs->st_blocks);
75 DMLOG_PRINT(DMLVL_DEBUG, " st_atime %d\n", statfs->st_atime);
76 DMLOG_PRINT(DMLVL_DEBUG, " st_mtime %d\n", statfs->st_mtime);
77 DMLOG_PRINT(DMLVL_DEBUG, " st_ctime %d\n", statfs->st_ctime);
78
79 }
80
81 /*
82 * StatCmp is used instead of memcmp because some of the pad fields or unused
83 * fields may not be the same even though the pertinent info may be the same
84 */
StatCmp(struct stat * stat1,struct stat * stat2)85 int StatCmp(struct stat *stat1, struct stat *stat2)
86 {
87
88 if ((stat1->st_dev != stat2->st_dev) ||
89 (stat1->st_ino != stat2->st_ino) ||
90 (stat1->st_mode != stat2->st_mode) ||
91 (stat1->st_nlink != stat2->st_nlink) ||
92 (stat1->st_uid != stat2->st_uid) ||
93 (stat1->st_gid != stat2->st_gid) ||
94 (stat1->st_rdev != stat2->st_rdev) ||
95 (stat1->st_size != stat2->st_size) ||
96 (stat1->st_blksize != stat2->st_blksize) ||
97 (stat1->st_blocks != stat2->st_blocks) ||
98 (stat1->st_atime != stat2->st_atime) ||
99 (stat1->st_mtime != stat2->st_mtime) ||
100 (stat1->st_ctime != stat2->st_ctime)) {
101 return -1;
102 } else {
103 return 0;
104 }
105
106 }
107
main(int argc,char ** argv)108 int main(int argc, char **argv)
109 {
110
111 char *szFuncName;
112 char *varstr;
113 int i;
114 int rc;
115 char *szSessionInfo = "dm_test session info";
116 dm_eventset_t events, maxFileEvents, minFileEvents;
117
118 DMOPT_PARSE(argc, argv);
119 DMLOG_START();
120
121 DMEV_ZERO(events);
122 DMEV_SET(DM_EVENT_MOUNT, events);
123
124 /* CANNOT DO ANYTHING WITHOUT SUCCESSFUL INITIALIZATION!!! */
125 if ((rc = dm_init_service(&varstr)) != 0) {
126 DMLOG_PRINT(DMLVL_ERR,
127 "dm_init_service failed! (rc = %d, errno = %d)\n",
128 rc, errno);
129 DM_EXIT();
130 } else if ((rc = dm_create_session(DM_NO_SESSION, szSessionInfo, &sid))
131 == -1) {
132 DMLOG_PRINT(DMLVL_ERR,
133 "dm_create_session failed! (rc = %d, errno = %d)\n",
134 rc, errno);
135 DM_EXIT();
136 } else
137 if ((rc =
138 dm_set_disp(sid, DM_GLOBAL_HANP, DM_GLOBAL_HLEN, DM_NO_TOKEN,
139 &events, DM_EVENT_MAX)) == -1) {
140 DMLOG_PRINT(DMLVL_ERR,
141 "dm_set_disp failed! (rc = %d, errno = %d)\n", rc,
142 errno);
143 dm_destroy_session(sid);
144 DM_EXIT();
145 } else if ((rc = pthread_create(&tid, NULL, Thread, NULL)) != 0) {
146 DMLOG_PRINT(DMLVL_ERR,
147 "pthread_create failed! (rc = %d, errno = %d)\n",
148 rc, errno);
149 dm_destroy_session(sid);
150 DM_EXIT();
151 } else if ((rc = dmimpl_mount(&mountPt, &deviceNm)) == -1) {
152 DMLOG_PRINT(DMLVL_ERR,
153 "dmimpl_mount failed! (rc = %d, errno = %d)\n", rc,
154 errno);
155 dm_destroy_session(sid);
156 DM_EXIT();
157 } else {
158 int fd;
159
160 sprintf(DummyFile, "%s/%s", mountPt, DUMMY_FILE);
161 sprintf(DummySubdir, "%s/%s", mountPt, DUMMY_SUBDIR);
162 sprintf(DummyTmp, "%s/%s", mountPt, DUMMY_TMP);
163
164 remove(DummyFile);
165 rmdir(DummySubdir);
166
167 memcpy(DummyString, DUMMY_STRING, DUMMY_STRLEN);
168
169 EVENT_DELIVERY_DELAY;
170 fd = open(DummyTmp, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE);
171 if (fd != -1) {
172 for (i = 0; i < TMP_FILELEN / DUMMY_STRLEN; i++) {
173 if (write(fd, DUMMY_STRING, DUMMY_STRLEN) !=
174 DUMMY_STRLEN) {
175 rc = -1;
176 break;
177 }
178 }
179 } else {
180 rc = -1;
181 }
182 if (rc != -1) {
183 rc = fsync(fd);
184 }
185 if (rc != -1) {
186 rc = close(fd);
187 }
188 if (rc == -1) {
189 DMLOG_PRINT(DMLVL_ERR,
190 "creating dummy file failed! (rc = %d, errno = %d)\n",
191 rc, errno);
192 dm_destroy_session(sid);
193 DM_EXIT();
194 }
195 }
196
197 numRegions = 1;
198 maxRegions[0].rg_offset = 0;
199 maxRegions[0].rg_size = 0;
200 maxRegions[0].rg_flags =
201 DM_REGION_READ | DM_REGION_WRITE | DM_REGION_TRUNCATE;
202 minRegions[0].rg_offset = 0;
203 minRegions[0].rg_size = 0;
204 minRegions[0].rg_flags = DM_REGION_NOEVENT;
205
206 DMEV_ZERO(maxFileEvents);
207 DMEV_SET(DM_EVENT_PREUNMOUNT, maxFileEvents);
208 DMEV_SET(DM_EVENT_UNMOUNT, maxFileEvents);
209 DMEV_SET(DM_EVENT_CREATE, maxFileEvents);
210 DMEV_SET(DM_EVENT_CLOSE, maxFileEvents);
211 DMEV_SET(DM_EVENT_POSTCREATE, maxFileEvents);
212 DMEV_SET(DM_EVENT_REMOVE, maxFileEvents);
213 DMEV_SET(DM_EVENT_POSTREMOVE, maxFileEvents);
214 DMEV_SET(DM_EVENT_RENAME, maxFileEvents);
215 DMEV_SET(DM_EVENT_POSTRENAME, maxFileEvents);
216 DMEV_SET(DM_EVENT_LINK, maxFileEvents);
217 DMEV_SET(DM_EVENT_POSTLINK, maxFileEvents);
218 DMEV_SET(DM_EVENT_SYMLINK, maxFileEvents);
219 DMEV_SET(DM_EVENT_POSTSYMLINK, maxFileEvents);
220 DMEV_SET(DM_EVENT_ATTRIBUTE, maxFileEvents);
221
222 DMEV_ZERO(minFileEvents);
223 DMEV_SET(DM_EVENT_PREUNMOUNT, minFileEvents);
224 DMEV_SET(DM_EVENT_UNMOUNT, minFileEvents);
225
226 DMLOG_PRINT(DMLVL_DEBUG, "Starting DMAPI invisible read/write tests\n");
227
228 szFuncName = "dm_read_invis";
229
230 /*
231 * TEST : dm_read_invis - invalid sid
232 * EXPECTED: rc = -1, errno = EINVAL
233 */
234 if (DMVAR_EXEC(READ_INVIS_BASE + 1)) {
235 void *hanp;
236 size_t hlen;
237 dm_off_t inoff = 0;
238 dm_size_t inlen = DUMMY_STRLEN;
239 char buf[DUMMY_STRLEN];
240
241 /* Variation set up */
242 sprintf(command, "cp %s %s", DummyTmp, DummyFile);
243 if ((rc = system(command)) == -1) {
244 /* No clean up */
245 } else if ((rc = dm_path_to_handle(DummyFile, &hanp, &hlen)) ==
246 -1) {
247 remove(DummyFile);
248 }
249 if (rc == -1) {
250 DMLOG_PRINT(DMLVL_DEBUG,
251 "Unable to set up variation! (errno = %d)\n",
252 errno);
253 DMVAR_SKIP();
254 } else {
255 /* Variation */
256 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid sid)\n",
257 szFuncName);
258 rc = dm_read_invis(INVALID_ADDR, hanp, hlen,
259 DM_NO_TOKEN, inoff, inlen, buf);
260 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
261
262 /* Variation clean up */
263 rc = remove(DummyFile);
264 if (rc == -1) {
265 DMLOG_PRINT(DMLVL_DEBUG,
266 "Unable to clean up variation! (errno = %d)\n",
267 errno);
268 }
269 dm_handle_free(hanp, hlen);
270 }
271 }
272
273 /*
274 * TEST : dm_read_invis - invalid hanp
275 * EXPECTED: rc = -1, errno = EFAULT
276 */
277 if (DMVAR_EXEC(READ_INVIS_BASE + 2)) {
278 void *hanp;
279 size_t hlen;
280 dm_off_t inoff = 0;
281 dm_size_t inlen = DUMMY_STRLEN;
282 char buf[DUMMY_STRLEN];
283
284 /* Variation set up */
285 sprintf(command, "cp %s %s", DummyTmp, DummyFile);
286 if ((rc = system(command)) == -1) {
287 /* No clean up */
288 } else if ((rc = dm_path_to_handle(DummyFile, &hanp, &hlen)) ==
289 -1) {
290 remove(DummyFile);
291 }
292 if (rc == -1) {
293 DMLOG_PRINT(DMLVL_DEBUG,
294 "Unable to set up variation! (errno = %d)\n",
295 errno);
296 DMVAR_SKIP();
297 } else {
298 /* Variation */
299 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid hanp)\n",
300 szFuncName);
301 rc = dm_read_invis(sid, (void *)INVALID_ADDR, hlen,
302 DM_NO_TOKEN, inoff, inlen, buf);
303 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT);
304
305 /* Variation clean up */
306 rc = remove(DummyFile);
307 if (rc == -1) {
308 DMLOG_PRINT(DMLVL_DEBUG,
309 "Unable to clean up variation! (errno = %d)\n",
310 errno);
311 }
312 dm_handle_free(hanp, hlen);
313 }
314 }
315
316 /*
317 * TEST : dm_read_invis - invalid hlen
318 * EXPECTED: rc = -1, errno = EBADF
319 */
320 if (DMVAR_EXEC(READ_INVIS_BASE + 3)) {
321 void *hanp;
322 size_t hlen;
323 dm_off_t inoff = 0;
324 dm_size_t inlen = DUMMY_STRLEN;
325 char buf[DUMMY_STRLEN];
326
327 /* Variation set up */
328 sprintf(command, "cp %s %s", DummyTmp, DummyFile);
329 if ((rc = system(command)) == -1) {
330 /* No clean up */
331 } else if ((rc = dm_path_to_handle(DummyFile, &hanp, &hlen)) ==
332 -1) {
333 remove(DummyFile);
334 }
335 if (rc == -1) {
336 DMLOG_PRINT(DMLVL_DEBUG,
337 "Unable to set up variation! (errno = %d)\n",
338 errno);
339 DMVAR_SKIP();
340 } else {
341 /* Variation */
342 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid hlen)\n",
343 szFuncName);
344 rc = dm_read_invis(sid, hanp, INVALID_ADDR, DM_NO_TOKEN,
345 inoff, inlen, buf);
346 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF);
347
348 /* Variation clean up */
349 rc = remove(DummyFile);
350 if (rc == -1) {
351 DMLOG_PRINT(DMLVL_DEBUG,
352 "Unable to clean up variation! (errno = %d)\n",
353 errno);
354 }
355 dm_handle_free(hanp, hlen);
356 }
357 }
358
359 /*
360 * TEST : dm_read_invis - invalid token
361 * EXPECTED: rc = -1, errno = EINVAL
362 */
363 if (DMVAR_EXEC(READ_INVIS_BASE + 4)) {
364 void *hanp;
365 size_t hlen;
366 dm_off_t inoff = 0;
367 dm_size_t inlen = DUMMY_STRLEN;
368 char buf[DUMMY_STRLEN];
369
370 /* Variation set up */
371 sprintf(command, "cp %s %s", DummyTmp, DummyFile);
372 if ((rc = system(command)) == -1) {
373 /* No clean up */
374 } else if ((rc = dm_path_to_handle(DummyFile, &hanp, &hlen)) ==
375 -1) {
376 remove(DummyFile);
377 }
378 if (rc == -1) {
379 DMLOG_PRINT(DMLVL_DEBUG,
380 "Unable to set up variation! (errno = %d)\n",
381 errno);
382 DMVAR_SKIP();
383 } else {
384 /* Variation */
385 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid token)\n",
386 szFuncName);
387 rc = dm_read_invis(sid, hanp, hlen, INVALID_ADDR, inoff,
388 inlen, buf);
389 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
390
391 /* Variation clean up */
392 rc = remove(DummyFile);
393 if (rc == -1) {
394 DMLOG_PRINT(DMLVL_DEBUG,
395 "Unable to clean up variation! (errno = %d)\n",
396 errno);
397 }
398 dm_handle_free(hanp, hlen);
399 }
400 }
401
402 /*
403 * TEST : dm_read_invis - invalid off
404 * EXPECTED: rc = -1, errno = EINVAL
405 *
406 * This variation uncovered XFS BUG #9 (0 returned instead of -1 and
407 * errno EINVAL)
408 */
409 if (DMVAR_EXEC(READ_INVIS_BASE + 5)) {
410 void *hanp;
411 size_t hlen;
412 dm_off_t inoff = TMP_FILELEN + 1;
413 dm_size_t inlen = DUMMY_STRLEN;
414 char buf[DUMMY_STRLEN];
415
416 /* Variation set up */
417 sprintf(command, "cp %s %s", DummyTmp, DummyFile);
418 if ((rc = system(command)) == -1) {
419 /* No clean up */
420 } else if ((rc = dm_path_to_handle(DummyFile, &hanp, &hlen)) ==
421 -1) {
422 remove(DummyFile);
423 }
424 if (rc == -1) {
425 DMLOG_PRINT(DMLVL_DEBUG,
426 "Unable to set up variation! (errno = %d)\n",
427 errno);
428 DMVAR_SKIP();
429 } else {
430 /* Variation */
431 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid off)\n",
432 szFuncName);
433 rc = dm_read_invis(sid, hanp, hlen, DM_NO_TOKEN, inoff,
434 inlen, buf);
435 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
436
437 /* Variation clean up */
438 rc = remove(DummyFile);
439 if (rc == -1) {
440 DMLOG_PRINT(DMLVL_DEBUG,
441 "Unable to clean up variation! (errno = %d)\n",
442 errno);
443 }
444 dm_handle_free(hanp, hlen);
445 }
446 }
447
448 /*
449 * TEST : dm_read_invis - invalid bufp
450 * EXPECTED: rc = -1, errno = EFAULT
451 */
452 if (DMVAR_EXEC(READ_INVIS_BASE + 6)) {
453 void *hanp;
454 size_t hlen;
455 dm_off_t inoff = 0;
456 dm_size_t inlen = DUMMY_STRLEN;
457
458 /* Variation set up */
459 sprintf(command, "cp %s %s", DummyTmp, DummyFile);
460 if ((rc = system(command)) == -1) {
461 /* No clean up */
462 } else if ((rc = dm_path_to_handle(DummyFile, &hanp, &hlen)) ==
463 -1) {
464 remove(DummyFile);
465 }
466 if (rc == -1) {
467 DMLOG_PRINT(DMLVL_DEBUG,
468 "Unable to set up variation! (errno = %d)\n",
469 errno);
470 DMVAR_SKIP();
471 } else {
472 /* Variation */
473 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid bufp)\n",
474 szFuncName);
475 rc = dm_read_invis(sid, hanp, hlen, DM_NO_TOKEN, inoff,
476 inlen, (void *)INVALID_ADDR);
477 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT);
478
479 /* Variation clean up */
480 rc = remove(DummyFile);
481 if (rc == -1) {
482 DMLOG_PRINT(DMLVL_DEBUG,
483 "Unable to clean up variation! (errno = %d)\n",
484 errno);
485 }
486 dm_handle_free(hanp, hlen);
487 }
488 }
489
490 /*
491 * TEST : dm_read_invis - file start
492 * EXPECTED: rc = DUMMY_STRLEN
493 */
494 if (DMVAR_EXEC(READ_INVIS_BASE + 7)) {
495 void *hanp, *fshanp;
496 size_t hlen, fshlen;
497 dm_off_t inoff = 0;
498 dm_size_t inlen = DUMMY_STRLEN;
499 char buf[DUMMY_STRLEN];
500 struct stat statfs1, statfs2;
501 int errnoSaved = 0;
502 dm_boolean_t exactflag;
503 int rc2;
504
505 /* Variation set up */
506 sprintf(command, "cp %s %s", DummyTmp, DummyFile);
507 if ((rc = system(command)) == -1) {
508 /* No clean up */
509 } else if ((rc = dm_path_to_handle(DummyFile, &hanp, &hlen)) ==
510 -1) {
511 remove(DummyFile);
512 } else
513 if ((rc =
514 dm_handle_to_fshandle(hanp, hlen, &fshanp,
515 &fshlen)) == -1) {
516 dm_handle_free(hanp, hlen);
517 remove(DummyFile);
518 } else
519 if (((rc =
520 dm_set_eventlist(sid, fshanp, fshlen, DM_NO_TOKEN,
521 &maxFileEvents, DM_EVENT_MAX)) == -1)
522 ||
523 ((rc =
524 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN,
525 numRegions, maxRegions,
526 &exactflag)) == -1)
527 || ((rc = stat(DummyFile, &statfs1)) == -1)) {
528 dm_handle_free(fshanp, fshlen);
529 dm_handle_free(hanp, hlen);
530 remove(DummyFile);
531 }
532 if (rc == -1) {
533 DMLOG_PRINT(DMLVL_DEBUG,
534 "Unable to set up variation! %d\n", errno);
535 DMVAR_SKIP();
536 } else {
537 /* Variation */
538 TIMESTAMP_DELAY;
539 eventReceived = DM_EVENT_INVALID;
540 DMLOG_PRINT(DMLVL_DEBUG, "%s(file start)\n",
541 szFuncName);
542 rc = dm_read_invis(sid, hanp, hlen, DM_NO_TOKEN, inoff,
543 inlen, buf);
544 errnoSaved = errno;
545 EVENT_DELIVERY_DELAY;
546 rc2 = stat(DummyFile, &statfs2);
547 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, numRegions,
548 minRegions, &exactflag);
549 dm_set_eventlist(sid, fshanp, fshlen, DM_NO_TOKEN,
550 &minFileEvents, DM_EVENT_MAX);
551 if (rc == inlen) {
552 DMLOG_PRINT(DMLVL_DEBUG, "read %d bytes\n", rc);
553 if (memcmp(buf, DUMMY_STRING, DUMMY_STRLEN) ==
554 0) {
555 DMLOG_PRINT(DMLVL_DEBUG,
556 "buffer contents [%.*s]\n",
557 rc, buf);
558 if (eventReceived == DM_EVENT_INVALID) {
559 DMLOG_PRINT(DMLVL_DEBUG,
560 "no event received\n");
561 if ((rc2 == 0)
562 &&
563 (StatCmp(&statfs1, &statfs2)
564 == 0)) {
565 DMLOG_PRINT(DMLVL_DEBUG,
566 "stat info same\n");
567 DMVAR_PASS();
568 } else {
569 DMLOG_PRINT(DMLVL_ERR,
570 "stat info NOT same!\n");
571 DMLOG_PRINT(DMLVL_DEBUG,
572 "stat info before:\n");
573 LogStat(&statfs1);
574 DMLOG_PRINT(DMLVL_DEBUG,
575 "stat info after:\n");
576 LogStat(&statfs2);
577 DMVAR_FAIL();
578 }
579 } else {
580 DMLOG_PRINT(DMLVL_ERR,
581 "event %d received!\n",
582 eventReceived);
583 DMVAR_FAIL();
584 }
585 } else {
586 DMLOG_PRINT(DMLVL_ERR,
587 "buffer contents NOT correct! (%.*s vs %.*s)\n",
588 DUMMY_STRLEN, DUMMY_STRING,
589 rc, buf);
590 DMVAR_FAIL();
591 }
592 } else {
593 DMLOG_PRINT(DMLVL_ERR,
594 "%s failed with unexpected rc = %d (errno = %d)\n",
595 szFuncName, rc, errnoSaved);
596 DMVAR_FAIL();
597 }
598
599 /* Variation clean up */
600 rc = remove(DummyFile);
601 if (rc == -1) {
602 DMLOG_PRINT(DMLVL_DEBUG,
603 "Unable to clean up variation! (errno = %d)\n",
604 errno);
605 }
606 dm_handle_free(fshanp, fshlen);
607 dm_handle_free(hanp, hlen);
608 }
609 }
610
611 /*
612 * TEST : dm_read_invis - file middle
613 * EXPECTED: rc = DUMMY_STRLEN
614 */
615 if (DMVAR_EXEC(READ_INVIS_BASE + 8)) {
616 void *hanp, *fshanp;
617 size_t hlen, fshlen;
618 dm_off_t inoff = (TMP_FILELEN / 2) - ((TMP_FILELEN / 2) % 10);
619 dm_size_t inlen = DUMMY_STRLEN;
620 char buf[DUMMY_STRLEN];
621 struct stat statfs1, statfs2;
622 int errnoSaved = 0;
623 dm_boolean_t exactflag;
624 int rc2;
625
626 /* Variation set up */
627 sprintf(command, "cp %s %s", DummyTmp, DummyFile);
628 if ((rc = system(command)) == -1) {
629 /* No clean up */
630 } else if ((rc = dm_path_to_handle(DummyFile, &hanp, &hlen)) ==
631 -1) {
632 remove(DummyFile);
633 } else
634 if ((rc =
635 dm_handle_to_fshandle(hanp, hlen, &fshanp,
636 &fshlen)) == -1) {
637 dm_handle_free(hanp, hlen);
638 remove(DummyFile);
639 } else
640 if (((rc =
641 dm_set_eventlist(sid, fshanp, fshlen, DM_NO_TOKEN,
642 &maxFileEvents, DM_EVENT_MAX)) == -1)
643 ||
644 ((rc =
645 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN,
646 numRegions, maxRegions,
647 &exactflag)) == -1)
648 || ((rc = stat(DummyFile, &statfs1)) == -1)) {
649 dm_handle_free(fshanp, fshlen);
650 dm_handle_free(hanp, hlen);
651 remove(DummyFile);
652 }
653 if (rc == -1) {
654 DMLOG_PRINT(DMLVL_DEBUG,
655 "Unable to set up variation! %d\n", errno);
656 DMVAR_SKIP();
657 } else {
658 /* Variation */
659 TIMESTAMP_DELAY;
660 eventReceived = DM_EVENT_INVALID;
661 DMLOG_PRINT(DMLVL_DEBUG, "%s(file middle)\n",
662 szFuncName);
663 rc = dm_read_invis(sid, hanp, hlen, DM_NO_TOKEN, inoff,
664 inlen, buf);
665 errnoSaved = errno;
666 EVENT_DELIVERY_DELAY;
667 rc2 = stat(DummyFile, &statfs2);
668 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, numRegions,
669 minRegions, &exactflag);
670 dm_set_eventlist(sid, fshanp, fshlen, DM_NO_TOKEN,
671 &minFileEvents, DM_EVENT_MAX);
672 if (rc == inlen) {
673 DMLOG_PRINT(DMLVL_DEBUG, "read %d bytes\n", rc);
674 if (memcmp(buf, DUMMY_STRING, DUMMY_STRLEN) ==
675 0) {
676 DMLOG_PRINT(DMLVL_DEBUG,
677 "buffer contents [%.*s]\n",
678 rc, buf);
679 if (eventReceived == DM_EVENT_INVALID) {
680 DMLOG_PRINT(DMLVL_DEBUG,
681 "no event received\n");
682 if ((rc2 == 0)
683 &&
684 (StatCmp(&statfs1, &statfs2)
685 == 0)) {
686 DMLOG_PRINT(DMLVL_DEBUG,
687 "stat info same\n");
688 DMVAR_PASS();
689 } else {
690 DMLOG_PRINT(DMLVL_ERR,
691 "stat info NOT same!\n");
692 DMLOG_PRINT(DMLVL_DEBUG,
693 "stat info before:\n");
694 LogStat(&statfs1);
695 DMLOG_PRINT(DMLVL_DEBUG,
696 "stat info after:\n");
697 LogStat(&statfs2);
698 DMVAR_FAIL();
699 }
700 } else {
701 DMLOG_PRINT(DMLVL_ERR,
702 "event %d received!\n",
703 eventReceived);
704 DMVAR_FAIL();
705 }
706 } else {
707 DMLOG_PRINT(DMLVL_ERR,
708 "buffer contents NOT correct! (%.*s vs %.*s)\n",
709 DUMMY_STRLEN, DUMMY_STRING,
710 rc, buf);
711 DMVAR_FAIL();
712 }
713 } else {
714 DMLOG_PRINT(DMLVL_ERR,
715 "%s failed with unexpected rc = %d (errno = %d)\n",
716 szFuncName, rc, errnoSaved);
717 DMVAR_FAIL();
718 }
719
720 /* Variation clean up */
721 rc = remove(DummyFile);
722 if (rc == -1) {
723 DMLOG_PRINT(DMLVL_DEBUG,
724 "Unable to clean up variation! (errno = %d)\n",
725 errno);
726 }
727 dm_handle_free(fshanp, fshlen);
728 dm_handle_free(hanp, hlen);
729 }
730 }
731
732 /*
733 * TEST : dm_read_invis - file end
734 * EXPECTED: rc = DUMMY_STRLEN
735 */
736 if (DMVAR_EXEC(READ_INVIS_BASE + 9)) {
737 void *hanp, *fshanp;
738 size_t hlen, fshlen;
739 dm_off_t inoff = TMP_FILELEN - DUMMY_STRLEN;
740 dm_size_t inlen = DUMMY_STRLEN;
741 char buf[DUMMY_STRLEN];
742 struct stat statfs1, statfs2;
743 int errnoSaved = 0;
744 dm_boolean_t exactflag;
745 int rc2;
746
747 /* Variation set up */
748 sprintf(command, "cp %s %s", DummyTmp, DummyFile);
749 if ((rc = system(command)) == -1) {
750 /* No clean up */
751 } else if ((rc = dm_path_to_handle(DummyFile, &hanp, &hlen)) ==
752 -1) {
753 remove(DummyFile);
754 } else
755 if ((rc =
756 dm_handle_to_fshandle(hanp, hlen, &fshanp,
757 &fshlen)) == -1) {
758 dm_handle_free(hanp, hlen);
759 remove(DummyFile);
760 } else
761 if (((rc =
762 dm_set_eventlist(sid, fshanp, fshlen, DM_NO_TOKEN,
763 &maxFileEvents, DM_EVENT_MAX)) == -1)
764 ||
765 ((rc =
766 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN,
767 numRegions, maxRegions,
768 &exactflag)) == -1)
769 || ((rc = stat(DummyFile, &statfs1)) == -1)) {
770 dm_handle_free(fshanp, fshlen);
771 dm_handle_free(hanp, hlen);
772 remove(DummyFile);
773 }
774 if (rc == -1) {
775 DMLOG_PRINT(DMLVL_DEBUG,
776 "Unable to set up variation! %d\n", errno);
777 DMVAR_SKIP();
778 } else {
779 /* Variation */
780 TIMESTAMP_DELAY;
781 eventReceived = DM_EVENT_INVALID;
782 DMLOG_PRINT(DMLVL_DEBUG, "%s(file end)\n", szFuncName);
783 rc = dm_read_invis(sid, hanp, hlen, DM_NO_TOKEN, inoff,
784 inlen, buf);
785 errnoSaved = errno;
786 EVENT_DELIVERY_DELAY;
787 rc2 = stat(DummyFile, &statfs2);
788 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, numRegions,
789 minRegions, &exactflag);
790 dm_set_eventlist(sid, fshanp, fshlen, DM_NO_TOKEN,
791 &minFileEvents, DM_EVENT_MAX);
792 if (rc == inlen) {
793 DMLOG_PRINT(DMLVL_DEBUG, "read %d bytes\n", rc);
794 if (memcmp(buf, DUMMY_STRING, DUMMY_STRLEN) ==
795 0) {
796 DMLOG_PRINT(DMLVL_DEBUG,
797 "buffer contents [%.*s]\n",
798 rc, buf);
799 if (eventReceived == DM_EVENT_INVALID) {
800 DMLOG_PRINT(DMLVL_DEBUG,
801 "no event received\n");
802 if ((rc2 == 0)
803 &&
804 (StatCmp(&statfs1, &statfs2)
805 == 0)) {
806 DMLOG_PRINT(DMLVL_DEBUG,
807 "stat info same\n");
808 DMVAR_PASS();
809 } else {
810 DMLOG_PRINT(DMLVL_ERR,
811 "stat info NOT same!\n");
812 DMLOG_PRINT(DMLVL_DEBUG,
813 "stat info before:\n");
814 LogStat(&statfs1);
815 DMLOG_PRINT(DMLVL_DEBUG,
816 "stat info after:\n");
817 LogStat(&statfs2);
818 DMVAR_FAIL();
819 }
820 } else {
821 DMLOG_PRINT(DMLVL_ERR,
822 "event %d received!\n",
823 eventReceived);
824 DMVAR_FAIL();
825 }
826 } else {
827 DMLOG_PRINT(DMLVL_ERR,
828 "buffer contents NOT correct! (%.*s vs %.*s)\n",
829 DUMMY_STRLEN, DUMMY_STRING,
830 rc, buf);
831 DMVAR_FAIL();
832 }
833 } else {
834 DMLOG_PRINT(DMLVL_ERR,
835 "%s failed with unexpected rc = %d (errno = %d)\n",
836 szFuncName, rc, errnoSaved);
837 DMVAR_FAIL();
838 }
839
840 /* Variation clean up */
841 rc = remove(DummyFile);
842 if (rc == -1) {
843 DMLOG_PRINT(DMLVL_DEBUG,
844 "Unable to clean up variation! (errno = %d)\n",
845 errno);
846 }
847 dm_handle_free(fshanp, fshlen);
848 dm_handle_free(hanp, hlen);
849 }
850 }
851
852 /*
853 * TEST : dm_read_invis - overlaps file end
854 * EXPECTED: rc = DUMMY_STRLEN/2
855 */
856 if (DMVAR_EXEC(READ_INVIS_BASE + 10)) {
857 void *hanp, *fshanp;
858 size_t hlen, fshlen;
859 dm_off_t inoff = TMP_FILELEN - (DUMMY_STRLEN / 2);
860 dm_size_t inlen = DUMMY_STRLEN;
861 char buf[DUMMY_STRLEN];
862 struct stat statfs1, statfs2;
863 int errnoSaved = 0;
864 dm_boolean_t exactflag;
865 int rc2;
866
867 /* Variation set up */
868 sprintf(command, "cp %s %s", DummyTmp, DummyFile);
869 if ((rc = system(command)) == -1) {
870 /* No clean up */
871 } else if ((rc = dm_path_to_handle(DummyFile, &hanp, &hlen)) ==
872 -1) {
873 remove(DummyFile);
874 } else
875 if ((rc =
876 dm_handle_to_fshandle(hanp, hlen, &fshanp,
877 &fshlen)) == -1) {
878 dm_handle_free(hanp, hlen);
879 remove(DummyFile);
880 } else
881 if (((rc =
882 dm_set_eventlist(sid, fshanp, fshlen, DM_NO_TOKEN,
883 &maxFileEvents, DM_EVENT_MAX)) == -1)
884 ||
885 ((rc =
886 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN,
887 numRegions, maxRegions,
888 &exactflag)) == -1)
889 || ((rc = stat(DummyFile, &statfs1)) == -1)) {
890 dm_handle_free(fshanp, fshlen);
891 dm_handle_free(hanp, hlen);
892 remove(DummyFile);
893 }
894 if (rc == -1) {
895 DMLOG_PRINT(DMLVL_DEBUG,
896 "Unable to set up variation! %d\n", errno);
897 DMVAR_SKIP();
898 } else {
899 /* Variation */
900 TIMESTAMP_DELAY;
901 eventReceived = DM_EVENT_INVALID;
902 DMLOG_PRINT(DMLVL_DEBUG, "%s(overlaps file end)\n",
903 szFuncName);
904 rc = dm_read_invis(sid, hanp, hlen, DM_NO_TOKEN, inoff,
905 inlen, buf);
906 errnoSaved = errno;
907 EVENT_DELIVERY_DELAY;
908 rc2 = stat(DummyFile, &statfs2);
909 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, numRegions,
910 minRegions, &exactflag);
911 dm_set_eventlist(sid, fshanp, fshlen, DM_NO_TOKEN,
912 &minFileEvents, DM_EVENT_MAX);
913 if (rc == DUMMY_STRLEN / 2) {
914 DMLOG_PRINT(DMLVL_DEBUG, "read %d bytes\n", rc);
915 if (memcmp
916 (buf, DummyString + (DUMMY_STRLEN / 2),
917 DUMMY_STRLEN / 2) == 0) {
918 DMLOG_PRINT(DMLVL_DEBUG,
919 "buffer contents [%.*s]\n",
920 rc, buf);
921 if (eventReceived == DM_EVENT_INVALID) {
922 DMLOG_PRINT(DMLVL_DEBUG,
923 "no event received\n");
924 if ((rc2 == 0)
925 &&
926 (StatCmp(&statfs1, &statfs2)
927 == 0)) {
928 DMLOG_PRINT(DMLVL_DEBUG,
929 "stat info same\n");
930 DMVAR_PASS();
931 } else {
932 DMLOG_PRINT(DMLVL_ERR,
933 "stat info NOT same!\n");
934 DMLOG_PRINT(DMLVL_DEBUG,
935 "stat info before:\n");
936 LogStat(&statfs1);
937 DMLOG_PRINT(DMLVL_DEBUG,
938 "stat info after:\n");
939 LogStat(&statfs2);
940 DMVAR_FAIL();
941 }
942 } else {
943 DMLOG_PRINT(DMLVL_ERR,
944 "event %d received!\n",
945 eventReceived);
946 DMVAR_FAIL();
947 }
948 } else {
949 DMLOG_PRINT(DMLVL_ERR,
950 "buffer contents NOT correct! (%.*s vs %.*s)\n",
951 DUMMY_STRLEN, DUMMY_STRING,
952 rc, buf);
953 DMVAR_FAIL();
954 }
955 } else {
956 DMLOG_PRINT(DMLVL_ERR,
957 "%s failed with unexpected rc = %d (errno = %d)\n",
958 szFuncName, rc, errnoSaved);
959 DMVAR_FAIL();
960 }
961
962 /* Variation clean up */
963 rc = remove(DummyFile);
964 if (rc == -1) {
965 DMLOG_PRINT(DMLVL_DEBUG,
966 "Unable to clean up variation! (errno = %d)\n",
967 errno);
968 }
969 dm_handle_free(fshanp, fshlen);
970 dm_handle_free(hanp, hlen);
971 }
972 }
973
974 /*
975 * TEST : dm_read_invis - DM_NO_SESSION sid
976 * EXPECTED: rc = -1, errno = EINVAL
977 */
978 if (DMVAR_EXEC(READ_INVIS_BASE + 11)) {
979 void *hanp;
980 size_t hlen;
981 dm_off_t inoff = 0;
982 dm_size_t inlen = DUMMY_STRLEN;
983 char buf[DUMMY_STRLEN];
984
985 /* Variation set up */
986 sprintf(command, "cp %s %s", DummyTmp, DummyFile);
987 if ((rc = system(command)) == -1) {
988 /* No clean up */
989 } else if ((rc = dm_path_to_handle(DummyFile, &hanp, &hlen)) ==
990 -1) {
991 remove(DummyFile);
992 }
993 if (rc == -1) {
994 DMLOG_PRINT(DMLVL_DEBUG,
995 "Unable to set up variation! (errno = %d)\n",
996 errno);
997 DMVAR_SKIP();
998 } else {
999 /* Variation */
1000 DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_NO_SESSION sid)\n",
1001 szFuncName);
1002 rc = dm_read_invis(DM_NO_SESSION, hanp, hlen,
1003 DM_NO_TOKEN, inoff, inlen, buf);
1004 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
1005
1006 /* Variation clean up */
1007 rc = remove(DummyFile);
1008 if (rc == -1) {
1009 DMLOG_PRINT(DMLVL_DEBUG,
1010 "Unable to clean up variation! (errno = %d)\n",
1011 errno);
1012 }
1013 dm_handle_free(hanp, hlen);
1014 }
1015 }
1016
1017 /*
1018 * TEST : dm_read_invis - directory handle
1019 * EXPECTED: rc = -1, errno = EINVAL
1020 */
1021 if (DMVAR_EXEC(READ_INVIS_BASE + 12)) {
1022 void *hanp;
1023 size_t hlen;
1024 dm_off_t inoff = 0;
1025 dm_size_t inlen = DUMMY_STRLEN;
1026 char buf[DUMMY_STRLEN];
1027
1028 /* Variation set up */
1029 if ((rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE)) == -1) {
1030 /* No clean up */
1031 } else if ((rc = dm_path_to_handle(DummySubdir, &hanp, &hlen))
1032 == -1) {
1033 rmdir(DummySubdir);
1034 }
1035 if (rc == -1) {
1036 DMLOG_PRINT(DMLVL_DEBUG,
1037 "Unable to set up variation! (errno = %d)\n",
1038 errno);
1039 DMVAR_SKIP();
1040 } else {
1041 /* Variation */
1042 DMLOG_PRINT(DMLVL_DEBUG, "%s(directory handle)\n",
1043 szFuncName);
1044 rc = dm_read_invis(sid, hanp, hlen, DM_NO_TOKEN, inoff,
1045 inlen, buf);
1046 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
1047
1048 /* Variation clean up */
1049 rc = rmdir(DummySubdir);
1050 if (rc == -1) {
1051 DMLOG_PRINT(DMLVL_DEBUG,
1052 "Unable to clean up variation! (errno = %d)\n",
1053 errno);
1054 }
1055 dm_handle_free(hanp, hlen);
1056 }
1057 }
1058
1059 /*
1060 * TEST : dm_read_invis - fs handle
1061 * EXPECTED: rc = -1, errno = EINVAL
1062 */
1063 if (DMVAR_EXEC(READ_INVIS_BASE + 13)) {
1064 void *hanp;
1065 size_t hlen;
1066 dm_off_t inoff = 0;
1067 dm_size_t inlen = DUMMY_STRLEN;
1068 char buf[DUMMY_STRLEN];
1069
1070 /* Variation set up */
1071 if ((rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE)) == -1) {
1072 /* No clean up */
1073 } else if ((rc = dm_path_to_fshandle(DummySubdir, &hanp, &hlen))
1074 == -1) {
1075 rmdir(DummySubdir);
1076 }
1077 if (rc == -1) {
1078 DMLOG_PRINT(DMLVL_DEBUG,
1079 "Unable to set up variation! (errno = %d)\n",
1080 errno);
1081 DMVAR_SKIP();
1082 } else {
1083 /* Variation */
1084 DMLOG_PRINT(DMLVL_DEBUG, "%s(fs handle)\n", szFuncName);
1085 rc = dm_read_invis(sid, hanp, hlen, DM_NO_TOKEN, inoff,
1086 inlen, buf);
1087 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
1088
1089 /* Variation clean up */
1090 rc = rmdir(DummySubdir);
1091 if (rc == -1) {
1092 DMLOG_PRINT(DMLVL_DEBUG,
1093 "Unable to clean up variation! (errno = %d)\n",
1094 errno);
1095 }
1096 dm_handle_free(hanp, hlen);
1097 }
1098 }
1099
1100 /*
1101 * TEST : dm_read_invis - global handle
1102 * EXPECTED: rc = -1, errno = EBADF
1103 */
1104 if (DMVAR_EXEC(READ_INVIS_BASE + 14)) {
1105 dm_off_t inoff = 0;
1106 dm_size_t inlen = DUMMY_STRLEN;
1107 char buf[DUMMY_STRLEN];
1108
1109 /* Variation set up */
1110
1111 /* Variation */
1112 DMLOG_PRINT(DMLVL_DEBUG, "%s(global handle)\n", szFuncName);
1113 rc = dm_read_invis(sid, DM_GLOBAL_HANP, DM_GLOBAL_HLEN,
1114 DM_NO_TOKEN, inoff, inlen, buf);
1115 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF);
1116
1117 /* Variation clean up */
1118 }
1119
1120 /*
1121 * TEST : dm_read_invis - invalidated hanp
1122 * EXPECTED: rc = -1, errno = EBADF
1123 */
1124 if (DMVAR_EXEC(READ_INVIS_BASE + 15)) {
1125 void *hanp;
1126 size_t hlen;
1127 dm_off_t inoff = 0;
1128 dm_size_t inlen = DUMMY_STRLEN;
1129 char buf[DUMMY_STRLEN];
1130
1131 /* Variation set up */
1132 sprintf(command, "cp %s %s", DummyTmp, DummyFile);
1133 if ((rc = system(command)) == -1) {
1134 /* No clean up */
1135 } else if ((rc = dm_path_to_handle(DummyFile, &hanp, &hlen)) ==
1136 -1) {
1137 remove(DummyFile);
1138 } else if ((rc = remove(DummyFile)) == -1) {
1139 dm_handle_free(hanp, hlen);
1140 }
1141 if (rc == -1) {
1142 DMLOG_PRINT(DMLVL_DEBUG,
1143 "Unable to set up variation! (errno = %d)\n",
1144 errno);
1145 DMVAR_SKIP();
1146 } else {
1147 /* Variation */
1148 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalidated hanp)\n",
1149 szFuncName);
1150 rc = dm_read_invis(sid, hanp, hlen, DM_NO_TOKEN, inoff,
1151 inlen, buf);
1152 DMLOG_PRINT(DMLVL_DEBUG, "GOT %d, %s\n", rc, buf);
1153 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF);
1154
1155 /* Variation clean up */
1156 dm_handle_free(hanp, hlen);
1157 }
1158 }
1159
1160 szFuncName = "dm_write_invis";
1161
1162 /*
1163 * TEST : dm_write_invis - invalid sid
1164 * EXPECTED: rc = -1, errno = EINVAL
1165 */
1166 if (DMVAR_EXEC(WRITE_INVIS_BASE + 1)) {
1167 void *hanp;
1168 size_t hlen;
1169 dm_off_t outoff = 0;
1170 dm_size_t outlen = DUMMY_STRLEN;
1171 char buf[DUMMY_STRLEN];
1172
1173 /* Variation set up */
1174 sprintf(command, "cp %s %s", DummyTmp, DummyFile);
1175 if ((rc = system(command)) == -1) {
1176 /* No clean up */
1177 } else if ((rc = dm_path_to_handle(DummyFile, &hanp, &hlen)) ==
1178 -1) {
1179 remove(DummyFile);
1180 }
1181 if (rc == -1) {
1182 DMLOG_PRINT(DMLVL_DEBUG,
1183 "Unable to set up variation! (errno = %d)\n",
1184 errno);
1185 DMVAR_SKIP();
1186 } else {
1187 /* Variation */
1188 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid sid)\n",
1189 szFuncName);
1190 rc = dm_write_invis(INVALID_ADDR, hanp, hlen,
1191 DM_NO_TOKEN, 0, outoff, outlen,
1192 buf);
1193 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
1194
1195 /* Variation clean up */
1196 rc = remove(DummyFile);
1197 if (rc == -1) {
1198 DMLOG_PRINT(DMLVL_DEBUG,
1199 "Unable to clean up variation! (errno = %d)\n",
1200 errno);
1201 }
1202 dm_handle_free(hanp, hlen);
1203 }
1204 }
1205
1206 /*
1207 * TEST : dm_write_invis - invalid hanp
1208 * EXPECTED: rc = -1, errno = EFAULT
1209 */
1210 if (DMVAR_EXEC(WRITE_INVIS_BASE + 2)) {
1211 void *hanp;
1212 size_t hlen;
1213 dm_off_t outoff = 0;
1214 dm_size_t outlen = DUMMY_STRLEN;
1215 char buf[DUMMY_STRLEN];
1216
1217 /* Variation set up */
1218 sprintf(command, "cp %s %s", DummyTmp, DummyFile);
1219 if ((rc = system(command)) == -1) {
1220 /* No clean up */
1221 } else if ((rc = dm_path_to_handle(DummyFile, &hanp, &hlen)) ==
1222 -1) {
1223 remove(DummyFile);
1224 }
1225 if (rc == -1) {
1226 DMLOG_PRINT(DMLVL_DEBUG,
1227 "Unable to set up variation! (errno = %d)\n",
1228 errno);
1229 DMVAR_SKIP();
1230 } else {
1231 /* Variation */
1232 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid hanp)\n",
1233 szFuncName);
1234 rc = dm_write_invis(sid, (void *)INVALID_ADDR, hlen,
1235 DM_NO_TOKEN, 0, outoff, outlen,
1236 buf);
1237 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT);
1238
1239 /* Variation clean up */
1240 rc = remove(DummyFile);
1241 if (rc == -1) {
1242 DMLOG_PRINT(DMLVL_DEBUG,
1243 "Unable to clean up variation! (errno = %d)\n",
1244 errno);
1245 }
1246 dm_handle_free(hanp, hlen);
1247 }
1248 }
1249
1250 /*
1251 * TEST : dm_write_invis - invalid hlen
1252 * EXPECTED: rc = -1, errno = EBADF
1253 */
1254 if (DMVAR_EXEC(WRITE_INVIS_BASE + 3)) {
1255 void *hanp;
1256 size_t hlen;
1257 dm_off_t outoff = 0;
1258 dm_size_t outlen = DUMMY_STRLEN;
1259 char buf[DUMMY_STRLEN];
1260
1261 /* Variation set up */
1262 sprintf(command, "cp %s %s", DummyTmp, DummyFile);
1263 if ((rc = system(command)) == -1) {
1264 /* No clean up */
1265 } else if ((rc = dm_path_to_handle(DummyFile, &hanp, &hlen)) ==
1266 -1) {
1267 remove(DummyFile);
1268 }
1269 if (rc == -1) {
1270 DMLOG_PRINT(DMLVL_DEBUG,
1271 "Unable to set up variation! (errno = %d)\n",
1272 errno);
1273 DMVAR_SKIP();
1274 } else {
1275 /* Variation */
1276 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid hlen)\n",
1277 szFuncName);
1278 rc = dm_write_invis(sid, hanp, INVALID_ADDR,
1279 DM_NO_TOKEN, 0, outoff, outlen,
1280 buf);
1281 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF);
1282
1283 /* Variation clean up */
1284 rc = remove(DummyFile);
1285 if (rc == -1) {
1286 DMLOG_PRINT(DMLVL_DEBUG,
1287 "Unable to clean up variation! (errno = %d)\n",
1288 errno);
1289 }
1290 dm_handle_free(hanp, hlen);
1291 }
1292 }
1293
1294 /*
1295 * TEST : dm_write_invis - invalid token
1296 * EXPECTED: rc = -1, errno = EINVAL
1297 */
1298 if (DMVAR_EXEC(WRITE_INVIS_BASE + 4)) {
1299 void *hanp;
1300 size_t hlen;
1301 dm_off_t outoff = 0;
1302 dm_size_t outlen = DUMMY_STRLEN;
1303 char buf[DUMMY_STRLEN];
1304
1305 /* Variation set up */
1306 sprintf(command, "cp %s %s", DummyTmp, DummyFile);
1307 if ((rc = system(command)) == -1) {
1308 /* No clean up */
1309 } else if ((rc = dm_path_to_handle(DummyFile, &hanp, &hlen)) ==
1310 -1) {
1311 remove(DummyFile);
1312 }
1313 if (rc == -1) {
1314 DMLOG_PRINT(DMLVL_DEBUG,
1315 "Unable to set up variation! (errno = %d)\n",
1316 errno);
1317 DMVAR_SKIP();
1318 } else {
1319 /* Variation */
1320 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid token)\n",
1321 szFuncName);
1322 rc = dm_write_invis(sid, hanp, hlen, INVALID_ADDR, 0,
1323 outoff, outlen, buf);
1324 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
1325
1326 /* Variation clean up */
1327 rc = remove(DummyFile);
1328 if (rc == -1) {
1329 DMLOG_PRINT(DMLVL_DEBUG,
1330 "Unable to clean up variation! (errno = %d)\n",
1331 errno);
1332 }
1333 dm_handle_free(hanp, hlen);
1334 }
1335 }
1336
1337 /*
1338 * TEST : dm_write_invis - invalid off+len
1339 * EXPECTED: rc = -1, errno = EFBIG
1340 */
1341 if (DMVAR_EXEC(WRITE_INVIS_BASE + 5)) {
1342 void *hanp;
1343 size_t hlen;
1344 dm_off_t outoff = MAXFILESIZE - 5;
1345 dm_size_t outlen = TMP_FILELEN;
1346 char buf[DUMMY_STRLEN];
1347
1348 /* Variation set up */
1349 sprintf(command, "cp %s %s", DummyTmp, DummyFile);
1350 if ((rc = system(command)) == -1) {
1351 /* No clean up */
1352 } else if ((rc = dm_path_to_handle(DummyFile, &hanp, &hlen)) ==
1353 -1) {
1354 remove(DummyFile);
1355 }
1356 if (rc == -1) {
1357 DMLOG_PRINT(DMLVL_DEBUG,
1358 "Unable to set up variation! (errno = %d)\n",
1359 errno);
1360 DMVAR_SKIP();
1361 } else {
1362 /* Variation */
1363 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid off+len)\n",
1364 szFuncName);
1365 rc = dm_write_invis(sid, hanp, hlen, DM_NO_TOKEN, 0,
1366 outoff, outlen, buf);
1367 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFBIG);
1368
1369 /* Variation clean up */
1370 rc = remove(DummyFile);
1371 if (rc == -1) {
1372 DMLOG_PRINT(DMLVL_DEBUG,
1373 "Unable to clean up variation! (errno = %d)\n",
1374 errno);
1375 }
1376 dm_handle_free(hanp, hlen);
1377 }
1378 }
1379
1380 /*
1381 * TEST : dm_write_invis - invalid bufp
1382 * EXPECTED: rc = -1, errno = EFAULT
1383 */
1384 if (DMVAR_EXEC(WRITE_INVIS_BASE + 6)) {
1385 void *hanp;
1386 size_t hlen;
1387 dm_off_t outoff = 0;
1388 dm_size_t outlen = DUMMY_STRLEN;
1389
1390 /* Variation set up */
1391 sprintf(command, "cp %s %s", DummyTmp, DummyFile);
1392 if ((rc = system(command)) == -1) {
1393 /* No clean up */
1394 } else if ((rc = dm_path_to_handle(DummyFile, &hanp, &hlen)) ==
1395 -1) {
1396 remove(DummyFile);
1397 }
1398 if (rc == -1) {
1399 DMLOG_PRINT(DMLVL_DEBUG,
1400 "Unable to set up variation! (errno = %d)\n",
1401 errno);
1402 DMVAR_SKIP();
1403 } else {
1404 /* Variation */
1405 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid bufp)\n",
1406 szFuncName);
1407 rc = dm_write_invis(sid, hanp, hlen, DM_NO_TOKEN, 0,
1408 outoff, outlen,
1409 (void *)INVALID_ADDR);
1410 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT);
1411
1412 /* Variation clean up */
1413 rc = remove(DummyFile);
1414 if (rc == -1) {
1415 DMLOG_PRINT(DMLVL_DEBUG,
1416 "Unable to clean up variation! (errno = %d)\n",
1417 errno);
1418 }
1419 dm_handle_free(hanp, hlen);
1420 }
1421 }
1422
1423 /*
1424 * TEST : dm_write_invis - file start, async
1425 * EXPECTED: rc = DUMMY_STRLEN
1426 */
1427 if (DMVAR_EXEC(WRITE_INVIS_BASE + 7)) {
1428 int fd;
1429 void *hanp, *fshanp;
1430 size_t hlen, fshlen;
1431 dm_off_t outoff = 0;
1432 dm_size_t outlen = DUMMY_STRLEN;
1433 char buf[DUMMY_STRLEN];
1434 struct stat statfs1, statfs2;
1435 int errnoSaved = 0;
1436 dm_boolean_t exactflag;
1437 int rc2;
1438
1439 /* Variation set up */
1440 sprintf(command, "cp %s %s", DummyTmp, DummyFile);
1441 if ((rc = system(command)) == -1) {
1442 /* No clean up */
1443 } else if ((fd = open(DummyFile, O_RDWR)) == -1) {
1444 remove(DummyFile);
1445 } else if ((rc = dm_path_to_handle(DummyFile, &hanp, &hlen)) ==
1446 -1) {
1447 close(fd);
1448 remove(DummyFile);
1449 } else
1450 if ((rc =
1451 dm_handle_to_fshandle(hanp, hlen, &fshanp,
1452 &fshlen)) == -1) {
1453 dm_handle_free(hanp, hlen);
1454 close(fd);
1455 remove(DummyFile);
1456 } else
1457 if (((rc =
1458 dm_set_eventlist(sid, fshanp, fshlen, DM_NO_TOKEN,
1459 &maxFileEvents, DM_EVENT_MAX)) == -1)
1460 ||
1461 ((rc =
1462 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN,
1463 numRegions, maxRegions,
1464 &exactflag)) == -1)
1465 || ((rc = stat(DummyFile, &statfs1)) == -1)) {
1466 dm_handle_free(fshanp, fshlen);
1467 dm_handle_free(hanp, hlen);
1468 close(fd);
1469 remove(DummyFile);
1470 }
1471 if (fd == -1 || rc == -1) {
1472 DMLOG_PRINT(DMLVL_DEBUG,
1473 "Unable to set up variation! %d\n", errno);
1474 DMVAR_SKIP();
1475 } else {
1476 /* Variation */
1477 TIMESTAMP_DELAY;
1478 eventReceived = DM_EVENT_INVALID;
1479 DMLOG_PRINT(DMLVL_DEBUG, "%s(file start, async)\n",
1480 szFuncName);
1481 rc = dm_write_invis(sid, hanp, hlen, DM_NO_TOKEN, 0,
1482 outoff, outlen, DUMMY_STRING2);
1483 errnoSaved = errno;
1484 EVENT_DELIVERY_DELAY;
1485 rc2 = stat(DummyFile, &statfs2);
1486 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, numRegions,
1487 minRegions, &exactflag);
1488 dm_set_eventlist(sid, fshanp, fshlen, DM_NO_TOKEN,
1489 &minFileEvents, DM_EVENT_MAX);
1490 if (rc == outlen) {
1491 DMLOG_PRINT(DMLVL_DEBUG, "wrote %d bytes\n",
1492 rc);
1493 if ((rc2 == 0)
1494 && (lseek(fd, outoff, SEEK_SET) == outoff)
1495 && (read(fd, buf, DUMMY_STRLEN) == outlen)
1496 && (memcmp(buf, DUMMY_STRING2, DUMMY_STRLEN)
1497 == 0)) {
1498 DMLOG_PRINT(DMLVL_DEBUG,
1499 "buffer contents [%.*s]\n",
1500 rc, buf);
1501 if (eventReceived == DM_EVENT_INVALID) {
1502 DMLOG_PRINT(DMLVL_DEBUG,
1503 "no event received\n");
1504 if (StatCmp(&statfs1, &statfs2)
1505 == 0) {
1506 DMLOG_PRINT(DMLVL_DEBUG,
1507 "stat info same\n");
1508 DMVAR_PASS();
1509 } else {
1510 DMLOG_PRINT(DMLVL_ERR,
1511 "stat info NOT same!\n");
1512 DMLOG_PRINT(DMLVL_DEBUG,
1513 "stat info before:\n");
1514 LogStat(&statfs1);
1515 DMLOG_PRINT(DMLVL_DEBUG,
1516 "stat info after:\n");
1517 LogStat(&statfs2);
1518 DMVAR_FAIL();
1519 }
1520 } else {
1521 DMLOG_PRINT(DMLVL_ERR,
1522 "event %d received!\n",
1523 eventReceived);
1524 DMVAR_FAIL();
1525 }
1526 } else {
1527 DMLOG_PRINT(DMLVL_ERR,
1528 "buffer contents NOT correct! (%.*s vs %.*s)\n",
1529 DUMMY_STRLEN, DUMMY_STRING2,
1530 rc, buf);
1531 DMVAR_FAIL();
1532 }
1533 } else {
1534 DMLOG_PRINT(DMLVL_ERR,
1535 "%s failed with unexpected rc = %d (errno = %d)\n",
1536 szFuncName, rc, errnoSaved);
1537 DMVAR_FAIL();
1538 }
1539
1540 /* Variation clean up */
1541 rc = close(fd);
1542 rc |= remove(DummyFile);
1543 if (rc == -1) {
1544 DMLOG_PRINT(DMLVL_DEBUG,
1545 "Unable to clean up variation! (errno = %d)\n",
1546 errno);
1547 }
1548 dm_handle_free(fshanp, fshlen);
1549 dm_handle_free(hanp, hlen);
1550 }
1551 }
1552
1553 /*
1554 * TEST : dm_write_invis - file middle, async
1555 * EXPECTED: rc = DUMMY_STRLEN
1556 */
1557 if (DMVAR_EXEC(WRITE_INVIS_BASE + 8)) {
1558 int fd;
1559 void *hanp, *fshanp;
1560 size_t hlen, fshlen;
1561 dm_off_t outoff = (TMP_FILELEN / 2) - ((TMP_FILELEN / 2) % 10);
1562 dm_size_t outlen = DUMMY_STRLEN;
1563 char buf[DUMMY_STRLEN];
1564 struct stat statfs1, statfs2;
1565 int errnoSaved = 0;
1566 dm_boolean_t exactflag;
1567 int rc2;
1568
1569 /* Variation set up */
1570 sprintf(command, "cp %s %s", DummyTmp, DummyFile);
1571 if ((rc = system(command)) == -1) {
1572 /* No clean up */
1573 } else if ((fd = open(DummyFile, O_RDWR)) == -1) {
1574 remove(DummyFile);
1575 } else if ((rc = dm_path_to_handle(DummyFile, &hanp, &hlen)) ==
1576 -1) {
1577 close(fd);
1578 remove(DummyFile);
1579 } else
1580 if ((rc =
1581 dm_handle_to_fshandle(hanp, hlen, &fshanp,
1582 &fshlen)) == -1) {
1583 dm_handle_free(hanp, hlen);
1584 close(fd);
1585 remove(DummyFile);
1586 } else
1587 if (((rc =
1588 dm_set_eventlist(sid, fshanp, fshlen, DM_NO_TOKEN,
1589 &maxFileEvents, DM_EVENT_MAX)) == -1)
1590 ||
1591 ((rc =
1592 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN,
1593 numRegions, maxRegions,
1594 &exactflag)) == -1)
1595 || ((rc = stat(DummyFile, &statfs1)) == -1)) {
1596 dm_handle_free(fshanp, fshlen);
1597 dm_handle_free(hanp, hlen);
1598 close(fd);
1599 remove(DummyFile);
1600 }
1601 if (rc == -1) {
1602 DMLOG_PRINT(DMLVL_DEBUG,
1603 "Unable to set up variation! %d\n", errno);
1604 DMVAR_SKIP();
1605 } else {
1606 /* Variation */
1607 TIMESTAMP_DELAY;
1608 eventReceived = DM_EVENT_INVALID;
1609 DMLOG_PRINT(DMLVL_DEBUG, "%s(file middle, async)\n",
1610 szFuncName);
1611 rc = dm_write_invis(sid, hanp, hlen, DM_NO_TOKEN, 0,
1612 outoff, outlen, DUMMY_STRING2);
1613 errnoSaved = errno;
1614 EVENT_DELIVERY_DELAY;
1615 rc2 = stat(DummyFile, &statfs2);
1616 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, numRegions,
1617 minRegions, &exactflag);
1618 dm_set_eventlist(sid, fshanp, fshlen, DM_NO_TOKEN,
1619 &minFileEvents, DM_EVENT_MAX);
1620 if (rc == outlen) {
1621 DMLOG_PRINT(DMLVL_DEBUG, "wrote %d bytes\n",
1622 rc);
1623 if ((rc2 == 0)
1624 && (lseek(fd, outoff, SEEK_SET) == outoff)
1625 && (read(fd, buf, DUMMY_STRLEN) == outlen)
1626 && (memcmp(buf, DUMMY_STRING2, DUMMY_STRLEN)
1627 == 0)) {
1628 DMLOG_PRINT(DMLVL_DEBUG,
1629 "buffer contents [%.*s]\n",
1630 rc, buf);
1631 if (eventReceived == DM_EVENT_INVALID) {
1632 DMLOG_PRINT(DMLVL_DEBUG,
1633 "no event received\n");
1634 if (StatCmp(&statfs1, &statfs2)
1635 == 0) {
1636 DMLOG_PRINT(DMLVL_DEBUG,
1637 "stat info same\n");
1638 DMVAR_PASS();
1639 } else {
1640 DMLOG_PRINT(DMLVL_ERR,
1641 "stat info NOT same!\n");
1642 DMLOG_PRINT(DMLVL_DEBUG,
1643 "stat info before:\n");
1644 LogStat(&statfs1);
1645 DMLOG_PRINT(DMLVL_DEBUG,
1646 "stat info after:\n");
1647 LogStat(&statfs2);
1648 DMVAR_FAIL();
1649 }
1650 } else {
1651 DMLOG_PRINT(DMLVL_ERR,
1652 "event %d received!\n",
1653 eventReceived);
1654 DMVAR_FAIL();
1655 }
1656 } else {
1657 DMLOG_PRINT(DMLVL_ERR,
1658 "buffer contents NOT correct! (%.*s vs %.*s)\n",
1659 DUMMY_STRLEN, DUMMY_STRING2,
1660 rc, buf);
1661 DMVAR_FAIL();
1662 }
1663 } else {
1664 DMLOG_PRINT(DMLVL_ERR,
1665 "%s failed with unexpected rc = %d (errno = %d)\n",
1666 szFuncName, rc, errnoSaved);
1667 DMVAR_FAIL();
1668 }
1669
1670 /* Variation clean up */
1671 rc = close(fd);
1672 rc |= remove(DummyFile);
1673 if (rc == -1) {
1674 DMLOG_PRINT(DMLVL_DEBUG,
1675 "Unable to clean up variation! (errno = %d)\n",
1676 errno);
1677 }
1678 dm_handle_free(fshanp, fshlen);
1679 dm_handle_free(hanp, hlen);
1680 }
1681 }
1682
1683 /*
1684 * TEST : dm_write_invis - file end, async
1685 * EXPECTED: rc = DUMMY_STRLEN
1686 */
1687 if (DMVAR_EXEC(WRITE_INVIS_BASE + 9)) {
1688 int fd;
1689 void *hanp, *fshanp;
1690 size_t hlen, fshlen;
1691 dm_off_t outoff = TMP_FILELEN - DUMMY_STRLEN;
1692 dm_size_t outlen = DUMMY_STRLEN;
1693 char buf[DUMMY_STRLEN];
1694 struct stat statfs1, statfs2;
1695 int errnoSaved = 0;
1696 dm_boolean_t exactflag;
1697 int rc2;
1698
1699 /* Variation set up */
1700 sprintf(command, "cp %s %s", DummyTmp, DummyFile);
1701 if ((rc = system(command)) == -1) {
1702 /* No clean up */
1703 } else if ((fd = open(DummyFile, O_RDWR)) == -1) {
1704 remove(DummyFile);
1705 } else if ((rc = dm_path_to_handle(DummyFile, &hanp, &hlen)) ==
1706 -1) {
1707 close(fd);
1708 remove(DummyFile);
1709 } else
1710 if ((rc =
1711 dm_handle_to_fshandle(hanp, hlen, &fshanp,
1712 &fshlen)) == -1) {
1713 dm_handle_free(hanp, hlen);
1714 close(fd);
1715 remove(DummyFile);
1716 } else
1717 if (((rc =
1718 dm_set_eventlist(sid, fshanp, fshlen, DM_NO_TOKEN,
1719 &maxFileEvents, DM_EVENT_MAX)) == -1)
1720 ||
1721 ((rc =
1722 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN,
1723 numRegions, maxRegions,
1724 &exactflag)) == -1)
1725 || ((rc = stat(DummyFile, &statfs1)) == -1)) {
1726 dm_handle_free(fshanp, fshlen);
1727 dm_handle_free(hanp, hlen);
1728 close(fd);
1729 remove(DummyFile);
1730 }
1731 if (rc == -1) {
1732 DMLOG_PRINT(DMLVL_DEBUG,
1733 "Unable to set up variation! %d\n", errno);
1734 DMVAR_SKIP();
1735 } else {
1736 /* Variation */
1737 TIMESTAMP_DELAY;
1738 eventReceived = DM_EVENT_INVALID;
1739 DMLOG_PRINT(DMLVL_DEBUG, "%s(file end, async)\n",
1740 szFuncName);
1741 rc = dm_write_invis(sid, hanp, hlen, DM_NO_TOKEN, 0,
1742 outoff, outlen, DUMMY_STRING2);
1743 errnoSaved = errno;
1744 EVENT_DELIVERY_DELAY;
1745 rc2 = stat(DummyFile, &statfs2);
1746 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, numRegions,
1747 minRegions, &exactflag);
1748 dm_set_eventlist(sid, fshanp, fshlen, DM_NO_TOKEN,
1749 &minFileEvents, DM_EVENT_MAX);
1750 if (rc == outlen) {
1751 DMLOG_PRINT(DMLVL_DEBUG, "wrote %d bytes\n",
1752 rc);
1753 if ((rc2 == 0)
1754 && (lseek(fd, outoff, SEEK_SET) == outoff)
1755 && (read(fd, buf, DUMMY_STRLEN) == outlen)
1756 && (memcmp(buf, DUMMY_STRING2, DUMMY_STRLEN)
1757 == 0)) {
1758 DMLOG_PRINT(DMLVL_DEBUG,
1759 "buffer contents [%.*s]\n",
1760 rc, buf);
1761 if (eventReceived == DM_EVENT_INVALID) {
1762 DMLOG_PRINT(DMLVL_DEBUG,
1763 "no event received\n");
1764 if (StatCmp(&statfs1, &statfs2)
1765 == 0) {
1766 DMLOG_PRINT(DMLVL_DEBUG,
1767 "stat info same\n");
1768 DMVAR_PASS();
1769 } else {
1770 DMLOG_PRINT(DMLVL_ERR,
1771 "stat info NOT same!\n");
1772 DMLOG_PRINT(DMLVL_DEBUG,
1773 "stat info before:\n");
1774 LogStat(&statfs1);
1775 DMLOG_PRINT(DMLVL_DEBUG,
1776 "stat info after:\n");
1777 LogStat(&statfs2);
1778 DMVAR_FAIL();
1779 }
1780 } else {
1781 DMLOG_PRINT(DMLVL_ERR,
1782 "event %d received!\n",
1783 eventReceived);
1784 DMVAR_FAIL();
1785 }
1786 } else {
1787 DMLOG_PRINT(DMLVL_ERR,
1788 "buffer contents NOT correct! (%.*s vs %.*s)\n",
1789 DUMMY_STRLEN, DUMMY_STRING2,
1790 rc, buf);
1791 DMVAR_FAIL();
1792 }
1793 } else {
1794 DMLOG_PRINT(DMLVL_ERR,
1795 "%s failed with unexpected rc = %d (errno = %d)\n",
1796 szFuncName, rc, errnoSaved);
1797 DMVAR_FAIL();
1798 }
1799
1800 /* Variation clean up */
1801 rc = close(fd);
1802 rc |= remove(DummyFile);
1803 if (rc == -1) {
1804 DMLOG_PRINT(DMLVL_DEBUG,
1805 "Unable to clean up variation! (errno = %d)\n",
1806 errno);
1807 }
1808 dm_handle_free(fshanp, fshlen);
1809 dm_handle_free(hanp, hlen);
1810 }
1811 }
1812
1813 /*
1814 * TEST : dm_write_invis - file start, sync
1815 * EXPECTED: rc = DUMMY_STRLEN
1816 */
1817 if (DMVAR_EXEC(WRITE_INVIS_BASE + 10)) {
1818 int fd;
1819 void *hanp, *fshanp;
1820 size_t hlen, fshlen;
1821 dm_off_t outoff = 0;
1822 dm_size_t outlen = DUMMY_STRLEN;
1823 char buf[DUMMY_STRLEN];
1824 struct stat statfs1, statfs2;
1825 int errnoSaved = 0;
1826 dm_boolean_t exactflag;
1827 int rc2;
1828
1829 /* Variation set up */
1830 sprintf(command, "cp %s %s", DummyTmp, DummyFile);
1831 if ((rc = system(command)) == -1) {
1832 /* No clean up */
1833 } else if ((fd = open(DummyFile, O_RDWR)) == -1) {
1834 remove(DummyFile);
1835 } else if ((rc = dm_path_to_handle(DummyFile, &hanp, &hlen)) ==
1836 -1) {
1837 close(fd);
1838 remove(DummyFile);
1839 } else
1840 if ((rc =
1841 dm_handle_to_fshandle(hanp, hlen, &fshanp,
1842 &fshlen)) == -1) {
1843 dm_handle_free(hanp, hlen);
1844 close(fd);
1845 remove(DummyFile);
1846 } else
1847 if (((rc =
1848 dm_set_eventlist(sid, fshanp, fshlen, DM_NO_TOKEN,
1849 &maxFileEvents, DM_EVENT_MAX)) == -1)
1850 ||
1851 ((rc =
1852 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN,
1853 numRegions, maxRegions,
1854 &exactflag)) == -1)
1855 || ((rc = stat(DummyFile, &statfs1)) == -1)) {
1856 dm_handle_free(fshanp, fshlen);
1857 dm_handle_free(hanp, hlen);
1858 close(fd);
1859 remove(DummyFile);
1860 }
1861 if (fd == -1 || rc == -1) {
1862 DMLOG_PRINT(DMLVL_DEBUG,
1863 "Unable to set up variation! %d\n", errno);
1864 DMVAR_SKIP();
1865 } else {
1866 /* Variation */
1867 TIMESTAMP_DELAY;
1868 eventReceived = DM_EVENT_INVALID;
1869 DMLOG_PRINT(DMLVL_DEBUG, "%s(file start, sync)\n",
1870 szFuncName);
1871 rc = dm_write_invis(sid, hanp, hlen, DM_NO_TOKEN,
1872 DM_WRITE_SYNC, outoff, outlen,
1873 DUMMY_STRING2);
1874 errnoSaved = errno;
1875 EVENT_DELIVERY_DELAY;
1876 rc2 = stat(DummyFile, &statfs2);
1877 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, numRegions,
1878 minRegions, &exactflag);
1879 dm_set_eventlist(sid, fshanp, fshlen, DM_NO_TOKEN,
1880 &minFileEvents, DM_EVENT_MAX);
1881 if (rc == outlen) {
1882 DMLOG_PRINT(DMLVL_DEBUG, "wrote %d bytes\n",
1883 rc);
1884 if ((rc2 == 0)
1885 && (lseek(fd, outoff, SEEK_SET) == outoff)
1886 && (read(fd, buf, DUMMY_STRLEN) == outlen)
1887 && (memcmp(buf, DUMMY_STRING2, DUMMY_STRLEN)
1888 == 0)) {
1889 DMLOG_PRINT(DMLVL_DEBUG,
1890 "buffer contents [%.*s]\n",
1891 rc, buf);
1892 if (eventReceived == DM_EVENT_INVALID) {
1893 DMLOG_PRINT(DMLVL_DEBUG,
1894 "no event received\n");
1895 if (StatCmp(&statfs1, &statfs2)
1896 == 0) {
1897 DMLOG_PRINT(DMLVL_DEBUG,
1898 "stat info same\n");
1899 DMVAR_PASS();
1900 } else {
1901 DMLOG_PRINT(DMLVL_ERR,
1902 "stat info NOT same!\n");
1903 DMLOG_PRINT(DMLVL_DEBUG,
1904 "stat info before:\n");
1905 LogStat(&statfs1);
1906 DMLOG_PRINT(DMLVL_DEBUG,
1907 "stat info after:\n");
1908 LogStat(&statfs2);
1909 DMVAR_FAIL();
1910 }
1911 } else {
1912 DMLOG_PRINT(DMLVL_ERR,
1913 "event %d received!\n",
1914 eventReceived);
1915 DMVAR_FAIL();
1916 }
1917 } else {
1918 DMLOG_PRINT(DMLVL_ERR,
1919 "buffer contents NOT correct! (%.*s vs %.*s)\n",
1920 DUMMY_STRLEN, DUMMY_STRING2,
1921 rc, buf);
1922 DMVAR_FAIL();
1923 }
1924 } else {
1925 DMLOG_PRINT(DMLVL_ERR,
1926 "%s failed with unexpected rc = %d (errno = %d)\n",
1927 szFuncName, rc, errnoSaved);
1928 DMVAR_FAIL();
1929 }
1930
1931 /* Variation clean up */
1932 rc = close(fd);
1933 rc |= remove(DummyFile);
1934 if (rc == -1) {
1935 DMLOG_PRINT(DMLVL_DEBUG,
1936 "Unable to clean up variation! (errno = %d)\n",
1937 errno);
1938 }
1939 dm_handle_free(fshanp, fshlen);
1940 dm_handle_free(hanp, hlen);
1941 }
1942 }
1943
1944 /*
1945 * TEST : dm_write_invis - file middle, sync
1946 * EXPECTED: rc = DUMMY_STRLEN
1947 */
1948 if (DMVAR_EXEC(WRITE_INVIS_BASE + 11)) {
1949 int fd;
1950 void *hanp, *fshanp;
1951 size_t hlen, fshlen;
1952 dm_off_t outoff = (TMP_FILELEN / 2) - ((TMP_FILELEN / 2) % 10);
1953 dm_size_t outlen = DUMMY_STRLEN;
1954 char buf[DUMMY_STRLEN];
1955 struct stat statfs1, statfs2;
1956 int errnoSaved = 0;
1957 dm_boolean_t exactflag;
1958 int rc2;
1959
1960 /* Variation set up */
1961 sprintf(command, "cp %s %s", DummyTmp, DummyFile);
1962 if ((rc = system(command)) == -1) {
1963 /* No clean up */
1964 } else if ((fd = open(DummyFile, O_RDWR)) == -1) {
1965 remove(DummyFile);
1966 } else if ((rc = dm_path_to_handle(DummyFile, &hanp, &hlen)) ==
1967 -1) {
1968 close(fd);
1969 remove(DummyFile);
1970 } else
1971 if ((rc =
1972 dm_handle_to_fshandle(hanp, hlen, &fshanp,
1973 &fshlen)) == -1) {
1974 dm_handle_free(hanp, hlen);
1975 close(fd);
1976 remove(DummyFile);
1977 } else
1978 if (((rc =
1979 dm_set_eventlist(sid, fshanp, fshlen, DM_NO_TOKEN,
1980 &maxFileEvents, DM_EVENT_MAX)) == -1)
1981 ||
1982 ((rc =
1983 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN,
1984 numRegions, maxRegions,
1985 &exactflag)) == -1)
1986 || ((rc = stat(DummyFile, &statfs1)) == -1)) {
1987 dm_handle_free(fshanp, fshlen);
1988 dm_handle_free(hanp, hlen);
1989 close(fd);
1990 remove(DummyFile);
1991 }
1992 if (rc == -1) {
1993 DMLOG_PRINT(DMLVL_DEBUG,
1994 "Unable to set up variation! %d\n", errno);
1995 DMVAR_SKIP();
1996 } else {
1997 /* Variation */
1998 TIMESTAMP_DELAY;
1999 eventReceived = DM_EVENT_INVALID;
2000 DMLOG_PRINT(DMLVL_DEBUG, "%s(file middle, sync)\n",
2001 szFuncName);
2002 rc = dm_write_invis(sid, hanp, hlen, DM_NO_TOKEN,
2003 DM_WRITE_SYNC, outoff, outlen,
2004 DUMMY_STRING2);
2005 errnoSaved = errno;
2006 EVENT_DELIVERY_DELAY;
2007 rc2 = stat(DummyFile, &statfs2);
2008 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, numRegions,
2009 minRegions, &exactflag);
2010 dm_set_eventlist(sid, fshanp, fshlen, DM_NO_TOKEN,
2011 &minFileEvents, DM_EVENT_MAX);
2012 if (rc == outlen) {
2013 DMLOG_PRINT(DMLVL_DEBUG, "wrote %d bytes\n",
2014 rc);
2015 if ((rc2 == 0)
2016 && (lseek(fd, outoff, SEEK_SET) == outoff)
2017 && (read(fd, buf, DUMMY_STRLEN) == outlen)
2018 && (memcmp(buf, DUMMY_STRING2, DUMMY_STRLEN)
2019 == 0)) {
2020 DMLOG_PRINT(DMLVL_DEBUG,
2021 "buffer contents [%.*s]\n",
2022 rc, buf);
2023 if (eventReceived == DM_EVENT_INVALID) {
2024 DMLOG_PRINT(DMLVL_DEBUG,
2025 "no event received\n");
2026 if (StatCmp(&statfs1, &statfs2)
2027 == 0) {
2028 DMLOG_PRINT(DMLVL_DEBUG,
2029 "stat info same\n");
2030 DMVAR_PASS();
2031 } else {
2032 DMLOG_PRINT(DMLVL_ERR,
2033 "stat info NOT same!\n");
2034 DMLOG_PRINT(DMLVL_DEBUG,
2035 "stat info before:\n");
2036 LogStat(&statfs1);
2037 DMLOG_PRINT(DMLVL_DEBUG,
2038 "stat info after:\n");
2039 LogStat(&statfs2);
2040 DMVAR_FAIL();
2041 }
2042 } else {
2043 DMLOG_PRINT(DMLVL_ERR,
2044 "event %d received!\n",
2045 eventReceived);
2046 DMVAR_FAIL();
2047 }
2048 } else {
2049 DMLOG_PRINT(DMLVL_ERR,
2050 "buffer contents NOT correct! (%.*s vs %.*s)\n",
2051 DUMMY_STRLEN, DUMMY_STRING2,
2052 rc, buf);
2053 DMVAR_FAIL();
2054 }
2055 } else {
2056 DMLOG_PRINT(DMLVL_ERR,
2057 "%s failed with unexpected rc = %d (errno = %d)\n",
2058 szFuncName, rc, errnoSaved);
2059 DMVAR_FAIL();
2060 }
2061
2062 /* Variation clean up */
2063 rc = close(fd);
2064 rc |= remove(DummyFile);
2065 if (rc == -1) {
2066 DMLOG_PRINT(DMLVL_DEBUG,
2067 "Unable to clean up variation! (errno = %d)\n",
2068 errno);
2069 }
2070 dm_handle_free(fshanp, fshlen);
2071 dm_handle_free(hanp, hlen);
2072 }
2073 }
2074
2075 /*
2076 * TEST : dm_write_invis - file end, sync
2077 * EXPECTED: rc = DUMMY_STRLEN
2078 */
2079 if (DMVAR_EXEC(WRITE_INVIS_BASE + 12)) {
2080 int fd;
2081 void *hanp, *fshanp;
2082 size_t hlen, fshlen;
2083 dm_off_t outoff = TMP_FILELEN - DUMMY_STRLEN;
2084 dm_size_t outlen = DUMMY_STRLEN;
2085 char buf[DUMMY_STRLEN];
2086 struct stat statfs1, statfs2;
2087 int errnoSaved = 0;
2088 dm_boolean_t exactflag;
2089 int rc2;
2090
2091 /* Variation set up */
2092 sprintf(command, "cp %s %s", DummyTmp, DummyFile);
2093 if ((rc = system(command)) == -1) {
2094 /* No clean up */
2095 } else if ((fd = open(DummyFile, O_RDWR)) == -1) {
2096 remove(DummyFile);
2097 } else if ((rc = dm_path_to_handle(DummyFile, &hanp, &hlen)) ==
2098 -1) {
2099 close(fd);
2100 remove(DummyFile);
2101 } else
2102 if ((rc =
2103 dm_handle_to_fshandle(hanp, hlen, &fshanp,
2104 &fshlen)) == -1) {
2105 dm_handle_free(hanp, hlen);
2106 close(fd);
2107 remove(DummyFile);
2108 } else
2109 if (((rc =
2110 dm_set_eventlist(sid, fshanp, fshlen, DM_NO_TOKEN,
2111 &maxFileEvents, DM_EVENT_MAX)) == -1)
2112 ||
2113 ((rc =
2114 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN,
2115 numRegions, maxRegions,
2116 &exactflag)) == -1)
2117 || ((rc = stat(DummyFile, &statfs1)) == -1)) {
2118 dm_handle_free(fshanp, fshlen);
2119 dm_handle_free(hanp, hlen);
2120 close(fd);
2121 remove(DummyFile);
2122 }
2123 if (rc == -1) {
2124 DMLOG_PRINT(DMLVL_DEBUG,
2125 "Unable to set up variation! %d\n", errno);
2126 DMVAR_SKIP();
2127 } else {
2128 /* Variation */
2129 TIMESTAMP_DELAY;
2130 eventReceived = DM_EVENT_INVALID;
2131 DMLOG_PRINT(DMLVL_DEBUG, "%s(file end, sync)\n",
2132 szFuncName);
2133 rc = dm_write_invis(sid, hanp, hlen, DM_NO_TOKEN,
2134 DM_WRITE_SYNC, outoff, outlen,
2135 DUMMY_STRING2);
2136 errnoSaved = errno;
2137 EVENT_DELIVERY_DELAY;
2138 rc2 = stat(DummyFile, &statfs2);
2139 dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, numRegions,
2140 minRegions, &exactflag);
2141 dm_set_eventlist(sid, fshanp, fshlen, DM_NO_TOKEN,
2142 &minFileEvents, DM_EVENT_MAX);
2143 if (rc == outlen) {
2144 DMLOG_PRINT(DMLVL_DEBUG, "wrote %d bytes\n",
2145 rc);
2146 if ((rc2 == 0)
2147 && (lseek(fd, outoff, SEEK_SET) == outoff)
2148 && (read(fd, buf, DUMMY_STRLEN) == outlen)
2149 && (memcmp(buf, DUMMY_STRING2, DUMMY_STRLEN)
2150 == 0)) {
2151 DMLOG_PRINT(DMLVL_DEBUG,
2152 "buffer contents [%.*s]\n",
2153 rc, buf);
2154 if (eventReceived == DM_EVENT_INVALID) {
2155 DMLOG_PRINT(DMLVL_DEBUG,
2156 "no event received\n");
2157 if (StatCmp(&statfs1, &statfs2)
2158 == 0) {
2159 DMLOG_PRINT(DMLVL_DEBUG,
2160 "stat info same\n");
2161 DMVAR_PASS();
2162 } else {
2163 DMLOG_PRINT(DMLVL_ERR,
2164 "stat info NOT same!\n");
2165 DMLOG_PRINT(DMLVL_DEBUG,
2166 "stat info before:\n");
2167 LogStat(&statfs1);
2168 DMLOG_PRINT(DMLVL_DEBUG,
2169 "stat info after:\n");
2170 LogStat(&statfs2);
2171 DMVAR_FAIL();
2172 }
2173 } else {
2174 DMLOG_PRINT(DMLVL_ERR,
2175 "event %d received!\n",
2176 eventReceived);
2177 DMVAR_FAIL();
2178 }
2179 } else {
2180 DMLOG_PRINT(DMLVL_ERR,
2181 "buffer contents NOT correct! (%.*s vs %.*s)\n",
2182 DUMMY_STRLEN, DUMMY_STRING2,
2183 rc, buf);
2184 DMVAR_FAIL();
2185 }
2186 } else {
2187 DMLOG_PRINT(DMLVL_ERR,
2188 "%s failed with unexpected rc = %d (errno = %d)\n",
2189 szFuncName, rc, errnoSaved);
2190 DMVAR_FAIL();
2191 }
2192
2193 /* Variation clean up */
2194 rc = close(fd);
2195 rc |= remove(DummyFile);
2196 if (rc == -1) {
2197 DMLOG_PRINT(DMLVL_DEBUG,
2198 "Unable to clean up variation! (errno = %d)\n",
2199 errno);
2200 }
2201 dm_handle_free(fshanp, fshlen);
2202 dm_handle_free(hanp, hlen);
2203 }
2204 }
2205
2206 /*
2207 * TEST : dm_write_invis - DM_NO_SESSION sid
2208 * EXPECTED: rc = -1, errno = EINVAL
2209 */
2210 if (DMVAR_EXEC(WRITE_INVIS_BASE + 13)) {
2211 void *hanp;
2212 size_t hlen;
2213 dm_off_t outoff = 0;
2214 dm_size_t outlen = DUMMY_STRLEN;
2215 char buf[DUMMY_STRLEN];
2216
2217 /* Variation set up */
2218 sprintf(command, "cp %s %s", DummyTmp, DummyFile);
2219 if ((rc = system(command)) == -1) {
2220 /* No clean up */
2221 } else if ((rc = dm_path_to_handle(DummyFile, &hanp, &hlen)) ==
2222 -1) {
2223 remove(DummyFile);
2224 }
2225 if (rc == -1) {
2226 DMLOG_PRINT(DMLVL_DEBUG,
2227 "Unable to set up variation! (errno = %d)\n",
2228 errno);
2229 DMVAR_SKIP();
2230 } else {
2231 /* Variation */
2232 DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_NO_SESSION sid)\n",
2233 szFuncName);
2234 rc = dm_write_invis(DM_NO_SESSION, hanp, hlen,
2235 DM_NO_TOKEN, 0, outoff, outlen,
2236 buf);
2237 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
2238
2239 /* Variation clean up */
2240 rc = remove(DummyFile);
2241 if (rc == -1) {
2242 DMLOG_PRINT(DMLVL_DEBUG,
2243 "Unable to clean up variation! (errno = %d)\n",
2244 errno);
2245 }
2246 dm_handle_free(hanp, hlen);
2247 }
2248 }
2249
2250 /*
2251 * TEST : dm_write_invis - directory handle
2252 * EXPECTED: rc = -1, errno = EINVAL
2253 */
2254 if (DMVAR_EXEC(WRITE_INVIS_BASE + 14)) {
2255 void *hanp;
2256 size_t hlen;
2257 dm_off_t outoff = 0;
2258 dm_size_t outlen = DUMMY_STRLEN;
2259 char buf[DUMMY_STRLEN];
2260
2261 /* Variation set up */
2262 if ((rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE)) == -1) {
2263 /* No clean up */
2264 } else if ((rc = dm_path_to_handle(DummySubdir, &hanp, &hlen))
2265 == -1) {
2266 rmdir(DummySubdir);
2267 }
2268 if (rc == -1) {
2269 DMLOG_PRINT(DMLVL_DEBUG,
2270 "Unable to set up variation! (errno = %d)\n",
2271 errno);
2272 DMVAR_SKIP();
2273 } else {
2274 /* Variation */
2275 DMLOG_PRINT(DMLVL_DEBUG, "%s(directory handle)\n",
2276 szFuncName);
2277 rc = dm_write_invis(sid, hanp, hlen, DM_NO_TOKEN, 0,
2278 outoff, outlen, buf);
2279 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
2280
2281 /* Variation clean up */
2282 rc = rmdir(DummySubdir);
2283 if (rc == -1) {
2284 DMLOG_PRINT(DMLVL_DEBUG,
2285 "Unable to clean up variation! (errno = %d)\n",
2286 errno);
2287 }
2288 dm_handle_free(hanp, hlen);
2289 }
2290 }
2291
2292 /*
2293 * TEST : dm_write_invis - fs handle
2294 * EXPECTED: rc = -1, errno = EINVAL
2295 */
2296 if (DMVAR_EXEC(WRITE_INVIS_BASE + 15)) {
2297 void *hanp;
2298 size_t hlen;
2299 dm_off_t outoff = 0;
2300 dm_size_t outlen = DUMMY_STRLEN;
2301 char buf[DUMMY_STRLEN];
2302
2303 /* Variation set up */
2304 if ((rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE)) == -1) {
2305 /* No clean up */
2306 } else if ((rc = dm_path_to_fshandle(DummySubdir, &hanp, &hlen))
2307 == -1) {
2308 rmdir(DummySubdir);
2309 }
2310 if (rc == -1) {
2311 DMLOG_PRINT(DMLVL_DEBUG,
2312 "Unable to set up variation! (errno = %d)\n",
2313 errno);
2314 DMVAR_SKIP();
2315 } else {
2316 /* Variation */
2317 DMLOG_PRINT(DMLVL_DEBUG, "%s(fs handle)\n", szFuncName);
2318 rc = dm_write_invis(sid, hanp, hlen, DM_NO_TOKEN, 0,
2319 outoff, outlen, buf);
2320 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
2321
2322 /* Variation clean up */
2323 rc = rmdir(DummySubdir);
2324 if (rc == -1) {
2325 DMLOG_PRINT(DMLVL_DEBUG,
2326 "Unable to clean up variation! (errno = %d)\n",
2327 errno);
2328 }
2329 dm_handle_free(hanp, hlen);
2330 }
2331 }
2332
2333 /*
2334 * TEST : dm_write_invis - global handle
2335 * EXPECTED: rc = -1, errno = EBADF
2336 */
2337 if (DMVAR_EXEC(WRITE_INVIS_BASE + 16)) {
2338 dm_off_t inoff = 0;
2339 dm_size_t inlen = DUMMY_STRLEN;
2340 char buf[DUMMY_STRLEN];
2341
2342 /* Variation set up */
2343
2344 /* Variation */
2345 DMLOG_PRINT(DMLVL_DEBUG, "%s(global handle)\n", szFuncName);
2346 rc = dm_write_invis(sid, DM_GLOBAL_HANP, DM_GLOBAL_HLEN,
2347 DM_NO_TOKEN, 0, inoff, inlen, buf);
2348 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF);
2349
2350 /* Variation clean up */
2351 }
2352
2353 /*
2354 * TEST : dm_write_invis - invalidated hanp
2355 * EXPECTED: rc = -1, errno = EBADF
2356 */
2357 if (DMVAR_EXEC(WRITE_INVIS_BASE + 17)) {
2358 void *hanp;
2359 size_t hlen;
2360 dm_off_t inoff = 0;
2361 dm_size_t inlen = DUMMY_STRLEN;
2362 char buf[DUMMY_STRLEN];
2363
2364 /* Variation set up */
2365 sprintf(command, "cp %s %s", DummyTmp, DummyFile);
2366 if ((rc = system(command)) == -1) {
2367 /* No clean up */
2368 } else if ((rc = dm_path_to_handle(DummyFile, &hanp, &hlen)) ==
2369 -1) {
2370 remove(DummyFile);
2371 } else if ((rc = remove(DummyFile)) == -1) {
2372 dm_handle_free(hanp, hlen);
2373 }
2374 if (rc == -1) {
2375 DMLOG_PRINT(DMLVL_DEBUG,
2376 "Unable to set up variation! (errno = %d)\n",
2377 errno);
2378 DMVAR_SKIP();
2379 } else {
2380 /* Variation */
2381 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalidated hanp)\n",
2382 szFuncName);
2383 rc = dm_write_invis(sid, hanp, hlen, DM_NO_TOKEN, 0,
2384 inoff, inlen, buf);
2385 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF);
2386
2387 /* Variation clean up */
2388 dm_handle_free(hanp, hlen);
2389 }
2390 }
2391
2392 remove(DummyTmp);
2393
2394 rc = umount(mountPt);
2395 if (rc == -1) {
2396 DMLOG_PRINT(DMLVL_ERR, "umount failed! (rc = %d, errno = %d)\n",
2397 rc, errno);
2398 }
2399
2400 pthread_join(tid, NULL);
2401
2402 rc = dm_destroy_session(sid);
2403 if (rc == -1) {
2404 DMLOG_PRINT(DMLVL_ERR,
2405 "dm_destroy_session failed! (rc = %d, errno = %d)\n",
2406 rc, errno);
2407 }
2408
2409 DMLOG_STOP();
2410
2411 tst_exit();
2412 }
2413
Thread(void * parm)2414 void *Thread(void *parm)
2415 {
2416 int rc;
2417 size_t dmMsgBufLen;
2418 dm_eventmsg_t *dmMsg;
2419 int bMounted = DM_FALSE;
2420 dm_eventtype_t type;
2421 dm_token_t token;
2422 dm_eventset_t events;
2423 dm_response_t response;
2424
2425 do {
2426 /* Loop until message received (wait could be interrupted) */
2427 do {
2428 DMLOG_PRINT(DMLVL_DEBUG, "Waiting for event...\n");
2429 dmMsgBufLen = 0;
2430
2431 rc = dm_get_events(sid, 1, DM_EV_WAIT, sizeof(dmMsgBuf),
2432 dmMsgBuf, &dmMsgBufLen);
2433 DMLOG_PRINT(DMLVL_DEBUG,
2434 "... dm_get_events returned %d (errno %d)\n",
2435 rc, errno);
2436 } while ((rc == -1) && (errno == EINTR) && (dmMsgBufLen == 0));
2437
2438 if (rc) {
2439 DMLOG_PRINT(DMLVL_ERR,
2440 "dm_get_events failed with rc = %d, errno = %d\n",
2441 rc, errno);
2442 dm_destroy_session(sid);
2443 DM_EXIT();
2444 } else {
2445 dmMsg = (dm_eventmsg_t *) dmMsgBuf;
2446 token = dmMsg->ev_token;
2447 type = dmMsg->ev_type;
2448
2449 DMLOG_PRINT(DMLVL_DEBUG, "Received message %d\n", type);
2450 }
2451
2452 if (type == DM_EVENT_MOUNT) {
2453 /* SPECIAL CASE: need to set disposition, events and response */
2454 dm_mount_event_t *me =
2455 DM_GET_VALUE(dmMsg, ev_data, dm_mount_event_t *);
2456 void *lhanp = DM_GET_VALUE(me, me_handle1, void *);
2457 size_t lhlen = DM_GET_LEN(me, me_handle1);
2458
2459 DMLOG_PRINT(DMLVL_DEBUG, "Message is DM_EVENT_MOUNT\n");
2460 DMLOG_PRINT(DMLVL_DEBUG, " Mode: %x\n", me->me_mode);
2461 DMLOG_PRINT(DMLVL_DEBUG, " File system handle: %p\n",
2462 lhanp);
2463 DMLOG_PRINT(DMLVL_DEBUG,
2464 " File system handle length: %d\n", lhlen);
2465 DMLOG_PRINT(DMLVL_DEBUG, " Mountpoint handle: %p\n",
2466 DM_GET_VALUE(me, me_handle2, void *));
2467 DMLOG_PRINT(DMLVL_DEBUG,
2468 " Mountpoint handle length: %d\n",
2469 DM_GET_LEN(me, me_handle2));
2470 DMLOG_PRINT(DMLVL_DEBUG, " Mountpoint path: %s\n",
2471 DM_GET_VALUE(me, me_name1, char *));
2472 DMLOG_PRINT(DMLVL_DEBUG, " Media designator: %s\n",
2473 DM_GET_VALUE(me, me_name2, char *));
2474 DMLOG_PRINT(DMLVL_DEBUG, " Root handle: %p\n",
2475 DM_GET_VALUE(me, me_roothandle, void *));
2476 DMLOG_PRINT(DMLVL_DEBUG, " Root handle length: %d\n",
2477 DM_GET_LEN(me, me_roothandle));
2478
2479 bMounted = dm_handle_is_valid(lhanp, lhlen);
2480
2481 rc = dm_request_right(sid, lhanp, lhlen, token,
2482 DM_RR_WAIT, DM_RIGHT_EXCL);
2483 if (rc == -1) {
2484 DMLOG_PRINT(DMLVL_ERR,
2485 "dm_request_right failed! (rc = %d, errno = %d)\n",
2486 rc, errno);
2487 dm_destroy_session(sid);
2488 DM_EXIT();
2489 }
2490
2491 DMEV_ZERO(events);
2492 DMEV_SET(DM_EVENT_PREUNMOUNT, events);
2493 DMEV_SET(DM_EVENT_UNMOUNT, events);
2494 DMEV_SET(DM_EVENT_CREATE, events);
2495 DMEV_SET(DM_EVENT_CLOSE, events);
2496 DMEV_SET(DM_EVENT_POSTCREATE, events);
2497 DMEV_SET(DM_EVENT_REMOVE, events);
2498 DMEV_SET(DM_EVENT_POSTREMOVE, events);
2499 DMEV_SET(DM_EVENT_RENAME, events);
2500 DMEV_SET(DM_EVENT_POSTRENAME, events);
2501 DMEV_SET(DM_EVENT_LINK, events);
2502 DMEV_SET(DM_EVENT_POSTLINK, events);
2503 DMEV_SET(DM_EVENT_SYMLINK, events);
2504 DMEV_SET(DM_EVENT_POSTSYMLINK, events);
2505 DMEV_SET(DM_EVENT_READ, events);
2506 DMEV_SET(DM_EVENT_WRITE, events);
2507 DMEV_SET(DM_EVENT_TRUNCATE, events);
2508 DMEV_SET(DM_EVENT_ATTRIBUTE, events);
2509 rc = dm_set_disp(sid, lhanp, lhlen, token, &events,
2510 DM_EVENT_MAX);
2511 if (rc == -1) {
2512 DMLOG_PRINT(DMLVL_ERR,
2513 "dm_set_disp failed! (rc = %d, errno = %d)\n",
2514 rc, errno);
2515 dm_destroy_session(sid);
2516 DM_EXIT();
2517 }
2518
2519 DMEV_ZERO(events);
2520 DMEV_SET(DM_EVENT_PREUNMOUNT, events);
2521 DMEV_SET(DM_EVENT_UNMOUNT, events);
2522 rc = dm_set_eventlist(sid, lhanp, lhlen, token, &events,
2523 DM_EVENT_MAX);
2524 if (rc == -1) {
2525 DMLOG_PRINT(DMLVL_ERR,
2526 "dm_set_eventlist failed! (rc = %d, errno = %d)\n",
2527 rc, errno);
2528 dm_destroy_session(sid);
2529 DM_EXIT();
2530 }
2531
2532 rc = dm_release_right(sid, lhanp, lhlen, token);
2533 if (rc == -1) {
2534 DMLOG_PRINT(DMLVL_ERR,
2535 "dm_request_right failed! (rc = %d, errno = %d)\n",
2536 rc, errno);
2537 dm_destroy_session(sid);
2538 DM_EXIT();
2539 }
2540
2541 response = DM_RESP_CONTINUE;
2542 } else if (type == DM_EVENT_PREUNMOUNT) {
2543 /* SPECIAL CASE: need to set response */
2544 dm_namesp_event_t *nse =
2545 DM_GET_VALUE(dmMsg, ev_data, dm_namesp_event_t *);
2546
2547 DMLOG_PRINT(DMLVL_DEBUG,
2548 "Message is DM_EVENT_PREUNMOUNT\n");
2549 DMLOG_PRINT(DMLVL_DEBUG, " Unmount mode: %x\n",
2550 nse->ne_mode);
2551 DMLOG_PRINT(DMLVL_DEBUG, " File system handle: %p\n",
2552 DM_GET_VALUE(nse, ne_handle1, void *));
2553 DMLOG_PRINT(DMLVL_DEBUG,
2554 " File system handle length: %d\n",
2555 DM_GET_LEN(nse, ne_handle1));
2556 DMLOG_PRINT(DMLVL_DEBUG,
2557 " Root directory handle: %p\n",
2558 DM_GET_VALUE(nse, ne_handle2, void *));
2559 DMLOG_PRINT(DMLVL_DEBUG,
2560 " Root directory handle length: %d\n",
2561 DM_GET_LEN(nse, ne_handle2));
2562
2563 response = DM_RESP_CONTINUE;
2564 } else if (type == DM_EVENT_UNMOUNT) {
2565 /* SPECIAL CASE: need to set response and bMounted */
2566 dm_namesp_event_t *nse =
2567 DM_GET_VALUE(dmMsg, ev_data, dm_namesp_event_t *);
2568
2569 DMLOG_PRINT(DMLVL_DEBUG,
2570 "Message is DM_EVENT_UNMOUNT\n");
2571 DMLOG_PRINT(DMLVL_DEBUG, " Unmount mode: %x\n",
2572 nse->ne_mode);
2573 DMLOG_PRINT(DMLVL_DEBUG, " File system handle: %p\n",
2574 DM_GET_VALUE(nse, ne_handle1, void *));
2575 DMLOG_PRINT(DMLVL_DEBUG,
2576 " File system handle length: %d\n",
2577 DM_GET_LEN(nse, ne_handle1));
2578 DMLOG_PRINT(DMLVL_DEBUG, " Return code: %x\n",
2579 nse->ne_retcode);
2580 if (nse->ne_retcode == 0) {
2581 bMounted = DM_FALSE;
2582 }
2583
2584 response = DM_RESP_CONTINUE;
2585 } else {
2586 eventReceived = type;
2587
2588 switch (type) {
2589 case DM_EVENT_READ:
2590 {
2591 dm_data_event_t *de =
2592 DM_GET_VALUE(dmMsg, ev_data,
2593 dm_data_event_t *);
2594 hanp1 =
2595 DM_GET_VALUE(de, de_handle, void *);
2596 hlen1 = DM_GET_LEN(de, de_handle);
2597 offset = de->de_offset;
2598 length = de->de_length;
2599
2600 DMLOG_PRINT(DMLVL_DEBUG,
2601 "Message is DM_EVENT_READ\n");
2602 DMLOG_PRINT(DMLVL_DEBUG,
2603 " Handle: %p\n", hanp1);
2604 DMLOG_PRINT(DMLVL_DEBUG,
2605 " Handle length: %d\n",
2606 hlen1);
2607 DMLOG_PRINT(DMLVL_DEBUG,
2608 " Offset: %d\n", offset);
2609 DMLOG_PRINT(DMLVL_DEBUG,
2610 " Length: %d\n", length);
2611
2612 response = DM_RESP_CONTINUE;
2613 break;
2614 }
2615
2616 case DM_EVENT_WRITE:
2617 {
2618 dm_data_event_t *de =
2619 DM_GET_VALUE(dmMsg, ev_data,
2620 dm_data_event_t *);
2621 hanp1 =
2622 DM_GET_VALUE(de, de_handle, void *);
2623 hlen1 = DM_GET_LEN(de, de_handle);
2624 offset = de->de_offset;
2625 length = de->de_length;
2626
2627 DMLOG_PRINT(DMLVL_DEBUG,
2628 "Message is DM_EVENT_WRITE\n");
2629 DMLOG_PRINT(DMLVL_DEBUG,
2630 " Handle: %p\n", hanp1);
2631 DMLOG_PRINT(DMLVL_DEBUG,
2632 " Handle length: %d\n",
2633 hlen1);
2634 DMLOG_PRINT(DMLVL_DEBUG,
2635 " Offset: %d\n", offset);
2636 DMLOG_PRINT(DMLVL_DEBUG,
2637 " Length: %d\n", length);
2638
2639 response = DM_RESP_CONTINUE;
2640 break;
2641 }
2642
2643 case DM_EVENT_TRUNCATE:
2644 {
2645 dm_data_event_t *de =
2646 DM_GET_VALUE(dmMsg, ev_data,
2647 dm_data_event_t *);
2648 hanp1 =
2649 DM_GET_VALUE(de, de_handle, void *);
2650 hlen1 = DM_GET_LEN(de, de_handle);
2651 offset = de->de_offset;
2652
2653 DMLOG_PRINT(DMLVL_DEBUG,
2654 "Message is DM_EVENT_TRUNCATE\n");
2655 DMLOG_PRINT(DMLVL_DEBUG,
2656 " Handle: %p\n", hanp1);
2657 DMLOG_PRINT(DMLVL_DEBUG,
2658 " Handle length: %d\n",
2659 hlen1);
2660 DMLOG_PRINT(DMLVL_DEBUG,
2661 " Offset: %d\n", offset);
2662
2663 response = DM_RESP_CONTINUE;
2664 break;
2665 }
2666
2667 case DM_EVENT_CREATE:
2668 case DM_EVENT_REMOVE:
2669 case DM_EVENT_RENAME:
2670 case DM_EVENT_LINK:
2671 case DM_EVENT_SYMLINK:
2672 response = DM_RESP_CONTINUE;
2673 break;
2674
2675 case DM_EVENT_POSTCREATE:
2676 case DM_EVENT_POSTREMOVE:
2677 case DM_EVENT_POSTRENAME:
2678 case DM_EVENT_POSTLINK:
2679 case DM_EVENT_POSTSYMLINK:
2680 case DM_EVENT_ATTRIBUTE:
2681 case DM_EVENT_CLOSE:
2682 response = DM_RESP_INVALID;
2683 break;
2684
2685 default:
2686 {
2687 DMLOG_PRINT(DMLVL_ERR,
2688 "Message is unexpected!\n");
2689 response = DM_RESP_ABORT;
2690 break;
2691 }
2692 }
2693 }
2694
2695 if (response != DM_RESP_INVALID) {
2696 DMLOG_PRINT(DMLVL_DEBUG,
2697 "Responding to message %d with %d\n", type,
2698 response);
2699 rc = dm_respond_event(sid, token, response,
2700 response ==
2701 DM_RESP_ABORT ? ABORT_ERRNO : 0,
2702 0, NULL);
2703 }
2704 } while (bMounted);
2705
2706 pthread_exit(0);
2707 }
2708