cmd/xfsprogs/libdm/dmapi_tests/README 1.1 Renamed to cmd/xfstests/dmapi/README
[xfstests-dev.git] / dmapi / src / suite2 / src / test_fileattr.c
1 /*
2  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
3  * 
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of version 2 of the GNU General Public License as
6  * published by the Free Software Foundation.
7  * 
8  * This program is distributed in the hope that it would be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * 
12  * Further, this software is distributed without any warranty that it is
13  * free of the rightful claim of any third person regarding infringement
14  * or the like.  Any license provided herein, whether implied or
15  * otherwise, applies only to this software file.  Patent licenses, if
16  * any, provided herein do not apply to combinations of this program with
17  * other software, or any other product whatsoever.
18  * 
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write the Free Software Foundation, Inc., 59
21  * Temple Place - Suite 330, Boston MA 02111-1307, USA.
22  * 
23  * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24  * Mountain View, CA  94043, or:
25  * 
26  * http://www.sgi.com 
27  * 
28  * For further information regarding this notice, see: 
29  * 
30  * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31  */
32
33 #include <sys/types.h>
34 #include <sys/stat.h>
35
36 #include <errno.h>
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <strings.h>
40
41 #include <lib/dmport.h>
42 #include <lib/hsm.h>
43 #include <lib/errtest.h>
44
45 #include <unistd.h>
46
47 #ifdef linux
48 #include <string.h>
49 #endif
50
51 /*---------------------------------------------------------------------------
52 Automated test of the DMAPI functions:
53    dm_set_fileattr()
54    dm_get_fileattr()
55    dm_get_bulkattr()
56    dm_get_dirattrs()
57
58 The command line is:
59    test_fileattr [-s sid] [-n num_files] [-v] ls_path pathname
60
61 where:
62    sid
63       is the session ID whose events you you are interested in.
64    num_files
65       is the number of test files to create.
66    ls_path
67       is the path to a copy of ls, which will be copied as a test file.
68    pathname
69       is the filesystem to use for the test.
70 ----------------------------------------------------------------------------*/
71
72 #define SET_MASK  DM_AT_ATIME|DM_AT_MTIME|DM_AT_CTIME|DM_AT_DTIME|\
73                   DM_AT_UID|DM_AT_GID|DM_AT_MODE|DM_AT_SIZE 
74
75 #define GET_MASK DM_AT_EMASK|DM_AT_PMANR|DM_AT_PATTR|\
76                   DM_AT_DTIME|DM_AT_CFLAG|DM_AT_STAT
77
78 extern  int     optind;
79 extern  int     opterr;
80 extern  char    *optarg;
81
82 char    *Progname;
83 int     Vflag=0;
84
85
86 int
87 comp_stat ( dm_stat_t expected,
88             dm_stat_t found,
89             int       i)
90 {
91    int good=0;
92    if (found.dt_mode != expected.dt_mode) {
93      fprintf(stderr, 
94              "ERROR: get #%d, expected mode %ld, but found %ld\n",
95              i, expected.dt_mode, found.dt_mode);
96    }
97    else good++;
98    if (found.dt_uid != expected.dt_uid) {
99      fprintf(stderr, 
100              "ERROR: get #%d, expected uid %ld, but found %ld\n",
101              i, expected.dt_uid, found.dt_uid);
102    }
103    else good++;
104    if (found.dt_gid != expected.dt_gid) {
105      fprintf(stderr, 
106              "ERROR: get #%d, expected gid %ld, but found %ld\n",
107              i, expected.dt_gid, found.dt_gid);
108    }
109    else good++;
110    if (found.dt_atime != expected.dt_atime) {
111      fprintf(stderr, 
112              "ERROR: get #%d, expected atime %ld, but found %ld\n",
113              i, expected.dt_atime, found.dt_atime);
114    }
115    else good++;
116    if (found.dt_mtime != expected.dt_mtime) {
117      fprintf(stderr, 
118              "ERROR: get #%d, expected mtime %ld, but found %ld\n",
119              i, expected.dt_mtime, found.dt_mtime);
120    }
121    else good++;
122    if (found.dt_ctime != expected.dt_ctime) {
123      fprintf(stderr, 
124              "ERROR: get #%d, expected ctime %ld, but found %ld\n",
125              i, expected.dt_ctime, found.dt_ctime);
126    }
127    else good++;
128    
129    /* NOTE: dtime gets set to ctime */
130    
131    if (found.dt_dtime != expected.dt_ctime) {
132      fprintf(stderr, 
133              "ERROR: get #%d, expected dtime %ld, but found %ld\n",
134              i, expected.dt_ctime, found.dt_dtime);
135    }
136    else good++;
137    if (found.dt_size != expected.dt_size) {
138      fprintf(stderr, 
139              "ERROR: get #%d, expected size %ld, but found %ld\n",
140              i, expected.dt_size, found.dt_size);
141    }
142    else good++;
143    if (Vflag){
144      if (good==8) {
145        fprintf(stderr, "report: get #%d had no errors.\n",i);
146      } else {
147        fprintf(stderr, "report: %d tests correct for get #%d.\n", 
148                good, i);
149      }
150    }
151    return(good);
152 }
153
154
155 static void
156 usage(void)
157 {
158         fprintf(stderr, 
159                 "Usage: %s [-v] [-s sid] [-n num_files] ls_path pathname\n",
160                 Progname);
161         exit(1);
162 }
163
164
165 int
166 main(
167         int     argc,
168         char    **argv)
169 {
170         dm_sessid_t     sid = DM_NO_SESSION;
171         dm_token_t      test_token = DM_NO_TOKEN;
172         void            *hanp;
173         size_t          hlen;
174         char            *ls_path;
175         char            *pathname;
176         char            test_file[100];
177         char            command[100];
178         int             fs_num_files;
179         int             num_files=50;
180         dm_stat_t       *stat_arr;
181         dm_stat_t       dmstat;
182         dm_fileattr_t   fileattr;
183         char            *name;
184         int             opt;
185         int             oops=1;
186         int             i=0;
187         dm_attrloc_t    loc;
188         size_t          buflen = 16*sizeof(dm_stat_t);
189         size_t          rlen;
190         void            *bufp;
191         dm_stat_t       *statbuf;
192         int             loops=0;
193         int             all_file_count=0;
194         void            *fs_hanp;
195         size_t          fs_hlen;
196         void            *targhanp;
197         size_t          targhlen;
198         char            check_name[100];
199         char            *chk_name_p;
200         int             chk_num;
201
202         if (Progname = strrchr(argv[0], '/')) {
203                 Progname++;
204         } else {
205                 Progname = argv[0];
206         }
207
208         opterr = 0;
209         while ((opt = getopt(argc, argv, "vn:s:")) != EOF) {
210                 switch (opt) {
211                 case 'v':
212                          Vflag++;
213                          break;
214                 case 'n':
215                          num_files = atoi(optarg);
216                          break;
217                 case 's': 
218                          sid = atol(optarg);
219                          break;
220                 case '?':
221                          usage();
222                 }
223         }
224         if (optind + 2 != argc) {
225                 usage();
226         }
227         ls_path = argv[optind];
228         pathname = argv[optind+1];
229
230         /* Seed the random number generator */
231         srand((unsigned int)time(NULL)); 
232
233         if (dm_init_service(&name) == -1)  {
234                 fprintf(stderr, "Can't inititalize the DMAPI\n");
235                 exit(1);
236         }
237         if (sid == DM_NO_SESSION)
238                 find_test_session(&sid);
239         
240         /* Dynamically allocate stat_arr; */
241         stat_arr = 
242           (dm_stat_t *)malloc(num_files * sizeof(dm_stat_t));
243         
244         printf("Beginning file attribute tests...\n");
245
246         /* Fill in the dm_stat blocks with lots of junk...
247          */
248         for (i=0; i<num_files; i++) {
249           stat_arr[i].dt_atime=(time_t)(rand()+rand()*0x10000);
250           stat_arr[i].dt_mtime=(time_t)(rand()+rand()*0x10000);
251           stat_arr[i].dt_ctime=(time_t)(rand()+rand()*0x10000);
252           stat_arr[i].dt_dtime=(time_t)(rand()+rand()*0x10000);
253           stat_arr[i].dt_uid=(uid_t)(rand()+rand()*0x10000);
254           stat_arr[i].dt_gid=(gid_t)(rand()+rand()*0x10000);
255           stat_arr[i].dt_mode=(mode_t)((rand()%4096)+32768);
256           stat_arr[i].dt_size=(dm_off_t)(rand()+rand()*0x10000);
257         }       
258
259         /*-----------------------------------------------------*\
260         |* File creation and set_fileattr loop                 *|
261         \*-----------------------------------------------------*/
262         if (Vflag) fprintf(stderr, "\nCreating/setting up test files.\n");
263         for (i=0; i < num_files; i++) {
264           sprintf(test_file, "%s/DMAPI_fileattr_test.%d", 
265                   pathname, i);
266           sprintf(command, "cp %s %s \n", ls_path, test_file); 
267           system(command);
268
269           if (dm_path_to_handle(test_file, &hanp, &hlen)) {
270             fprintf(stderr, "ERROR: can't get handle for %s; %s\n",
271                     test_file, ERR_NAME);
272           }
273           else {
274             fileattr.fa_mode  = stat_arr[i].dt_mode;
275             fileattr.fa_uid   = stat_arr[i].dt_uid;
276             fileattr.fa_gid   = stat_arr[i].dt_gid;
277             fileattr.FA_ATIME = stat_arr[i].dt_atime;
278             fileattr.FA_MTIME = stat_arr[i].dt_mtime;
279             fileattr.FA_CTIME = stat_arr[i].dt_ctime;
280             fileattr.FA_DTIME = stat_arr[i].dt_dtime;
281             fileattr.fa_size  = stat_arr[i].dt_size;
282             if (dm_set_fileattr(sid, hanp, hlen, DM_NO_TOKEN,
283                                 SET_MASK, &fileattr)) {
284               fprintf(stderr, "ERROR: set_fileattr failed on pass #%d; %s.\n",
285                       i, ERR_NAME);
286             }
287             else if (Vflag) {
288               fprintf(stderr, "report: set #%d was successful.\n", i);
289             }
290           }
291         }
292         
293         /*-----------------------------------------------------*\
294         |* Get_fileattr loop                                   *|
295         \*-----------------------------------------------------*/
296         if (Vflag) fprintf(stderr, "\nRunning get_fileattr test\n");
297         for (i=0; i < num_files; i++) {
298           sprintf(test_file, "%s/DMAPI_fileattr_test.%d", 
299                   pathname, i);
300           if (dm_path_to_handle(test_file, &hanp, &hlen)) {
301             fprintf(stderr, "ERROR: can't get handle for %s; %s\n",
302                     test_file, ERR_NAME);
303           }
304           if (dm_get_fileattr(sid, hanp, hlen, DM_NO_TOKEN,
305                               GET_MASK, &dmstat)) {
306             fprintf(stderr,
307                     "ERROR: dm_get_fileattr failed on pass #%d, %s\n",
308                     ERR_NAME);
309           }
310           else {
311             comp_stat(stat_arr[i], dmstat, i); 
312           }
313         }
314           
315 #if 0
316         /*-----------------------------------------------------*\
317         |* Get_dirattrs loop                                   *|
318         \*-----------------------------------------------------*/
319         if (Vflag) fprintf(stderr, "\nRunning get_dirattrs test\n");
320         if (dm_path_to_handle(pathname, &hanp, &hlen)) {
321           fprintf(stderr, "ERROR: can't get handle for %s; %s\n",
322                   pathname, ERR_NAME);
323           goto abort_test;
324         }
325         if ((bufp = (void*)malloc(buflen)) == NULL) {
326           fprintf(stderr, "Can't allocate memory for buffer.\n");
327             goto abort_test;
328         }
329         if (dm_init_attrloc(sid, hanp, hlen, DM_NO_TOKEN, &loc)){
330           fprintf(stderr, 
331                   "ERROR: dm_init_attrloc failed with %s.\n",
332                   ERR_NAME);
333           goto abort_test;
334         }
335         i=0; 
336         loops=0;
337         do {
338           /* printf("About to call get_dirattrs;\tloops=%d\n", loops);
339            * fflush(stdout);
340            * sleep(1);
341            */
342           oops=dm_get_dirattrs(sid, hanp, hlen, DM_NO_TOKEN,
343                                GET_MASK, &loc, buflen,
344                                bufp, &rlen);
345           if (rlen==0) break;
346           for (statbuf = bufp; statbuf != NULL; 
347                statbuf = DM_STEP_TO_NEXT(statbuf, dm_stat_t *)) {
348             chk_name_p = DM_GET_VALUE(statbuf, dt_compname, void *);
349             if (strncmp(chk_name_p, "DMAPI_fileattr_test.", 20)==0) {
350               sscanf(chk_name_p, "DMAPI_fileattr_test.%d", &chk_num);
351               if (comp_stat(stat_arr[chk_num], *statbuf, chk_num)==8) i++;
352             }
353           }
354           loops++;
355         } while (oops==1);
356         
357         if (oops==-1) {
358           fprintf(stderr, 
359                   "ERROR: dm_get_dirattrs failed with %s.\n",
360                   ERR_NAME);
361         }
362         if (i!=num_files) {
363           fprintf(stderr,
364                   "ERROR: get_dirattrs found %d matching file%s "
365                   "(expected %d).\n", i, (i==1)?"":"s", num_files);
366         }
367         else if (Vflag) {
368           fprintf(stderr, "report: get_dirattrs successfully "
369                   "found %d files in %d loops.\n", i, loops);
370         }
371 #endif
372
373         /*-----------------------------------------------------*\
374         |* Get_bulkattr loop                                   *|
375         \*-----------------------------------------------------*/
376         if (Vflag) fprintf(stderr, "\nRunning get_bulkattr test\n");
377         if (dm_path_to_handle(pathname, &hanp, &hlen)) {
378           fprintf(stderr, "ERROR: can't get handle for %s; %s\n",
379                   pathname, ERR_NAME);
380           goto abort_test;
381         }
382         if (dm_path_to_fshandle(pathname, &fs_hanp, &fs_hlen)) {
383           fprintf(stderr, "ERROR: can't get filesystem handle for %s; %s\n",
384                   pathname, ERR_NAME);
385           goto abort_test;
386         }
387         
388         buflen = 16*sizeof(dm_stat_t); /* 100000000; */  
389         if ((bufp = (void*)malloc(buflen)) == NULL) {
390           fprintf(stderr, "Can't allocate memory for buffer.\n");
391           goto abort_test;
392         }
393         if (dm_init_attrloc(sid, fs_hanp, fs_hlen,
394                             DM_NO_TOKEN, &loc)){
395           fprintf(stderr, 
396                   "ERROR: dm_init_attrloc failed with %s.\n",
397                   ERR_NAME);
398           goto abort_test;
399         }
400         
401         i=0;
402         loops=0;
403         do {
404           oops=dm_get_bulkattr(sid, fs_hanp, fs_hlen, DM_NO_TOKEN,
405                                GET_MASK, &loc, buflen, bufp, &rlen); 
406           if (rlen==0) break;
407           for( statbuf = bufp; statbuf != NULL;  
408                statbuf = DM_STEP_TO_NEXT(statbuf, dm_stat_t *) ) {
409             targhanp = DM_GET_VALUE(statbuf, dt_handle, void *);
410             targhlen = DM_GET_LEN(statbuf, dt_handle);
411             if (dm_handle_to_path(hanp, hlen, targhanp, targhlen,
412                                   (size_t)100, check_name, &rlen)){
413               fprintf(stderr, 
414                       "Warning: Couldn't get name from handle. (%s)\n",
415                           ERR_NAME);
416             }
417             else {
418               /* Put JUST name (not path) from check_name into chk_name_p */
419               if (chk_name_p = strrchr(check_name, '/')) chk_name_p++;
420               else chk_name_p = check_name;
421               /* Verify that check_name_p holds a testfile name */
422               if (strncmp(chk_name_p, "DMAPI_fileattr_test.",20)==0) {
423                 /* Get the test file's number and compare. */
424                 sscanf(chk_name_p, "DMAPI_fileattr_test.%d", &chk_num);
425                 if (comp_stat(stat_arr[chk_num], *statbuf, chk_num)==8)i++;
426               }
427             }            
428           }
429           loops++;
430         } while (oops==1);
431         
432         if (oops) {
433           fprintf(stderr, 
434                   "ERROR: dm_get_bulkattr failed with %s.\n",
435                   ERR_NAME);
436         }
437         /* printf("All_file_count: %d.  BUFLEN: %d\n",
438          * all_file_count, buflen);
439          */ 
440         if (i!=num_files) {
441           fprintf(stderr,
442                   "ERROR: get_bulkattr found %d matching file%s "
443                   "(expected %d) in %d loops.\n", i, (i==1)?"":"s",
444                   num_files, loops);
445         }
446         else if (Vflag) {
447           fprintf(stderr, "report: get_bulkattr successfully "
448                   "found %d files in %d loops.\n", i, loops);
449         }
450
451           /*------------------------*\
452           |*  ## Errno subtests ##  *|
453           \*------------------------*/
454           printf("\t(errno subtests beginning...)\n");
455           sprintf(test_file, "%s/DMAPI_fileattr_test.ERRNO", 
456                   pathname);
457           sprintf(command, "cp %s %s\n", ls_path, test_file); 
458           system(command);
459
460           if (dm_path_to_handle(test_file, &hanp, &hlen)) {
461             fprintf(stderr, "ERROR: can't get handle for %s; %s\n",
462                     test_file, ERR_NAME);
463             goto abort_test;
464           }
465  
466           /*------------------------------------*\
467           |*  ## dm_set_fileattr() subtests ##  *|
468           \*------------------------------------*/
469           /*---------------------------------------------------------*/
470           EXCLTEST("set", hanp, hlen, test_token, 
471                    dm_set_fileattr(sid, hanp, hlen, test_token,
472                                    SET_MASK, &fileattr))
473           /*---------------------------------------------------------*/
474           { void *test_vp;
475           if ((test_vp = handle_clone(hanp, hlen)) == NULL) {
476             fprintf(stderr, 
477                     "Cannot create a test handle (%s); skipping EBADF test\n",
478                     ERR_NAME);
479           }
480           else {
481             ((char *) test_vp)[hlen/2]++;
482             ERRTEST(EBADF,
483                     "set",
484                     dm_set_fileattr(sid, test_vp, hlen, DM_NO_TOKEN,
485                                     SET_MASK, &fileattr))
486               dm_handle_free(test_vp, hlen);
487           }
488           }
489           /*---------------------------------------------------------*/
490           ERRTEST(EFAULT, 
491                   "set",
492                   dm_set_fileattr(sid, NULL, hlen, DM_NO_TOKEN, 
493                                   SET_MASK, &fileattr))
494           /*---------------------------------------------------------*/
495           /* PROBLEM: 32 ones as a mask does not produce a "bad mask" 
496           /* EINVAL.  If it doesn't, I suspect nothing will.
497           ERRTEST(EINVAL, 
498                   "set (bad mask) [BROKEN]",
499                   dm_set_fileattr(sid, hanp, hlen, DM_NO_TOKEN, 
500                                   0xFFFFFFFF, &fileattr))
501           /*---------------------------------------------------------*/
502           ERRTEST(EINVAL, 
503                   "set (bad token)",
504                   dm_set_fileattr(sid, hanp, hlen, 0, 
505                                   SET_MASK, &fileattr))
506           /*---------------------------------------------------------*/
507           ERRTEST(EINVAL, 
508                   "set (bad session)",
509                   dm_set_fileattr(-100, hanp, hlen, DM_NO_TOKEN, 
510                                   SET_MASK, &fileattr))
511           /*---------------------------------------------------------*/
512
513
514           /*------------------------------------*\
515           |*  ## dm_get_fileattr() subtests ##  *|
516           \*------------------------------------*/
517           /*---------------------------------------------------------*/
518           SHAREDTEST("get", hanp, hlen, test_token,
519                      dm_get_fileattr(sid, hanp, hlen, test_token,
520                                      GET_MASK, &dmstat))
521           /*---------------------------------------------------------*/
522           { void *test_vp;
523           if ((test_vp = handle_clone(hanp, hlen)) == NULL) {
524             fprintf(stderr, 
525                     "Cannot create a test handle (%s); skipping EBADF test\n",
526                     ERR_NAME);
527           }
528           else {
529             ((char *) test_vp)[hlen/2]++;
530             ERRTEST(EBADF,
531                     "get",
532                     dm_get_fileattr(sid, test_vp, hlen, DM_NO_TOKEN,
533                                     GET_MASK, &dmstat))
534               dm_handle_free(test_vp, hlen);
535           }
536           }
537           /*---------------------------------------------------------*/
538           ERRTEST(EFAULT, 
539                   "get",
540                   dm_get_fileattr(sid, NULL, hlen, DM_NO_TOKEN, 
541                                   GET_MASK, &dmstat))
542           ERRTEST(EFAULT, 
543                   "get",
544                   dm_get_fileattr(sid, hanp, hlen, DM_NO_TOKEN, 
545                                   GET_MASK, (dm_stat_t *)(-1000)))
546           /*---------------------------------------------------------*/
547           /* PROBLEM: 32 ones as a mask does not produce a "bad mask" 
548           /* EINVAL.  If it doesn't, I suspect nothing will.
549           ERRTEST(EINVAL, 
550                   "get (bad mask) [BROKEN]",
551                   dm_get_fileattr(sid, hanp, hlen, DM_NO_TOKEN, 
552                                   0xFFFFFFFF, &dmstat))
553           /*---------------------------------------------------------*/
554           ERRTEST(EINVAL, 
555                   "get (bad token)",
556                   dm_get_fileattr(sid, hanp, hlen, 0, 
557                                   GET_MASK, &dmstat))
558           /*---------------------------------------------------------*/
559           ERRTEST(EINVAL, 
560                   "get (bad session)",
561                   dm_get_fileattr(-100, hanp, hlen, DM_NO_TOKEN, 
562                                   GET_MASK, &dmstat))
563           /*---------------------------------------------------------*/
564             
565
566           dm_handle_free(hanp, hlen);
567 #if 0
568           /*------------------------------------*\
569           |*  ## dm_get_dirattrs() subtests ##  *|
570           \*------------------------------------*/
571           if (dm_path_to_handle(pathname, &hanp, &hlen)) {
572             fprintf(stderr, "ERROR: can't get handle for %s; %s\n",
573                     pathname, ERR_NAME);
574           }
575           else if ((bufp = (void*)malloc(buflen)) == NULL) {
576             fprintf(stderr, "Can't allocate memory for buffer.\n");
577           }
578           else {
579             /*---------------------------------------------------------*/
580             if (dm_init_attrloc(sid, hanp, hlen, DM_NO_TOKEN, &loc)){
581               fprintf(stderr, 
582                       "ERROR: dm_init_attrloc failed with %s.\n",
583                       ERR_NAME);
584             } else {
585               SHAREDTEST("get_dir", hanp, hlen, test_token, 
586                          dm_get_dirattrs(sid, hanp, hlen, test_token,
587                                          GET_MASK, &loc, buflen, bufp, &rlen))
588             }
589             /*---------------------------------------------------------*/
590             { void* test_vp;
591               if (dm_init_attrloc(sid, hanp, hlen, DM_NO_TOKEN, &loc)){
592                 fprintf(stderr,  "ERROR: dm_init_attrloc failed with %s.\n",
593                         ERR_NAME);
594               } 
595               else if ((test_vp = handle_clone(hanp, hlen)) == NULL) {
596                 fprintf(stderr, "Cannot create a test handle (%s); "
597                         "skipping EBADF test\n", ERR_NAME);
598               }
599               else {
600                 ((char *) test_vp)[hlen/2]++;
601                 ERRTEST(EBADF,
602                         "get",
603                         dm_get_dirattrs(sid, test_vp, hlen, DM_NO_TOKEN,
604                                         GET_MASK, &loc, buflen, bufp, &rlen))
605                 dm_handle_free(test_vp, hlen);
606               }
607             }
608             /*---------------------------------------------------------*/
609             { void *p = (void *)(((char *)bufp)+1);
610               if (dm_init_attrloc(sid, hanp, hlen, DM_NO_TOKEN, &loc)){
611                 fprintf(stderr, 
612                         "ERROR: dm_init_attrloc failed with %s.\n",
613                         ERR_NAME);
614               } 
615               else {
616                 /* PROBLEM:
617                    This would test alignment.  Right now, no error occurs
618                    when the buffer is "out of sync" with struct size.
619                    It makes it tough to read from the buffer, tho!
620                   ERRTEST(EFAULT,
621                         "get_dir (bad bufp)",
622                         dm_get_dirattrs(sid, hanp, hlen, DM_NO_TOKEN,
623                                         GET_MASK, &loc, buflen, p, &rlen))
624                 */
625                 ERRTEST(EFAULT,
626                         "get_dir (bad locp)",
627                         dm_get_dirattrs(sid, hanp, hlen, DM_NO_TOKEN,
628                                         GET_MASK, (dm_attrloc_t*)(-1000),
629                                         buflen, bufp, &rlen))
630                 ERRTEST(EFAULT,
631                         "get_dir (bad bufp)",
632                         dm_get_dirattrs(sid, hanp, hlen, DM_NO_TOKEN,
633                                         GET_MASK, &loc, buflen, 
634                                         (void*)(-1000), &rlen))
635                 ERRTEST(EFAULT,
636                         "get_dir (bad rlenp)",
637                         dm_get_dirattrs(sid, hanp, hlen, DM_NO_TOKEN,
638                                         GET_MASK, &loc, buflen, bufp,
639                                         (size_t*)(-1000)))
640               }
641             }
642             /*---------------------------------------------------------*/
643             /*---------------------------------------------------------*/
644           }
645 #endif
646             
647          /*------------------------------------*\
648          |*  ## dm_get_bulkattr() subtests ##  *|
649          \*------------------------------------*/
650          if (dm_path_to_fshandle(pathname, &fs_hanp, &fs_hlen)) {
651            fprintf(stderr, "ERROR: can't get handle for %s; %s\n",
652                    pathname, ERR_NAME);
653          }
654          else if ((bufp = (void*)malloc(buflen)) == NULL) {
655            fprintf(stderr, "Can't allocate memory for buffer.\n");
656          }
657          else {
658            /*---------------------------------------------------------*/
659            if (dm_init_attrloc(sid, fs_hanp, fs_hlen, DM_NO_TOKEN, &loc)){
660              fprintf(stderr, 
661                      "ERROR: dm_init_attrloc failed with %s.\n",
662                      ERR_NAME);
663            } 
664            else {
665              SHAREDTEST("get_bulk", fs_hanp, fs_hlen, test_token, 
666                         dm_get_bulkattr(sid, fs_hanp, fs_hlen, test_token,
667                                         GET_MASK, &loc, buflen, bufp, &rlen))
668            }
669            /*---------------------------------------------------------*/
670            if (dm_init_attrloc(sid, fs_hanp, fs_hlen, DM_NO_TOKEN, &loc)){
671              fprintf(stderr, 
672                      "ERROR: dm_init_attrloc failed with %s.\n",
673                      ERR_NAME);
674            }
675            else {
676              void *p = (void *)(((char *)bufp)+1);
677              ERRTEST(EFAULT, "get_bulk (bad bufp)",
678                      dm_get_bulkattr(sid, fs_hanp, fs_hlen, DM_NO_TOKEN,
679                                      GET_MASK, &loc, buflen, 
680                                      (void *)(-1000), &rlen))
681              ERRTEST(EFAULT, "get_bulk (bad locp)",
682                      dm_get_bulkattr(sid, fs_hanp, fs_hlen, DM_NO_TOKEN,
683                                      GET_MASK, (dm_attrloc_t *)(-1000),
684                                      buflen, bufp, &rlen))
685              ERRTEST(EFAULT, "get_bulk (bad rlenp)", 
686                      dm_get_bulkattr(sid, fs_hanp, fs_hlen, DM_NO_TOKEN,
687                                      GET_MASK, &loc, buflen, bufp,
688                                      (u_int*)(-1000)))
689              ERRTEST(EFAULT, "get_bulk (bad bufp)",
690                      dm_get_bulkattr(sid, fs_hanp, fs_hlen, DM_NO_TOKEN,
691                                      GET_MASK, &loc, buflen, p, &rlen))
692            }
693            /*---------------------------------------------------------*/
694          }
695          
696           sprintf(command, "rm %s/DMAPI_fileattr_test.ERRNO\n", pathname); 
697           system(command);
698           printf("\t(errno subtests complete)\n");
699           /*---------------------*\
700           |* End of errno tests  *|
701           \*---------------------*/
702
703 abort_test:
704         /* File deletion loop */
705         if (Vflag) printf("(Deleting test files...)\n"); 
706         for (i=0; i < num_files; i++) {
707           sprintf(test_file, "%s/DMAPI_fileattr_test.%d", 
708                   pathname, i);
709           sprintf(command, "rm %s\n", test_file); 
710           system(command);
711         }
712         printf("File attribute tests complete.\n");
713 }