xfstests: eliminate warnings under dmapi/src/suite1/cmd (1)
[xfstests-dev.git] / dmapi / src / suite1 / cmd / get_fileattr.c
1 /*
2  * Copyright (c) 2000-2002 Silicon Graphics, Inc.
3  * All Rights Reserved.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it would be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * 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 the Free Software Foundation,
16  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17  */
18
19 #include <sys/types.h>
20 #include <sys/stat.h>
21
22 #include <lib/hsm.h>
23
24 #include <string.h>
25 #include <getopt.h>
26
27 extern  int     optind;
28 extern  int     opterr;
29 extern  char    *optarg;
30
31 char    *Progname;
32
33
34 static void
35 usage(void)
36 {
37         fprintf(stderr, "Usage: %s [-a|-A] [-s sid] [-t token] {pathname|handle}\n",
38                 Progname);
39         exit(1);
40 }
41
42
43 int
44 main(
45         int     argc,
46         char    **argv)
47 {
48         dm_sessid_t     sid = DM_NO_SESSION;
49         dm_token_t      token = DM_NO_TOKEN;
50 #if 0
51         char            buffer[500];
52 #endif
53         void            *hanp;
54         size_t          hlen;
55         dm_stat_t       dmstat;
56         char            *pathname_obj;
57         int             a_flag = 0;
58         char            *name;
59         int             opt;
60         int             validate = 0;
61
62         Progname = strrchr(argv[0], '/');
63         if (Progname) {
64                 Progname++;
65         } else {
66                 Progname = argv[0];
67         }
68
69         opterr = 0;
70         while ((opt = getopt(argc, argv, "Aas:t:v")) != EOF) {
71                 switch (opt) {
72                 case 'A':
73                         a_flag = 2;
74                         break;
75                 case 'a':
76                         a_flag = 1;
77                         break;
78                 case 's':
79                         sid = atol(optarg);
80                         break;
81                 case 't':
82                         token = atol(optarg);
83                         break;
84                 case 'v':
85                         validate = 1;
86                         break;
87                 case '?':
88                         usage();
89                 }
90         }
91         if (optind + 1 != argc) {
92                 usage();
93         }
94         pathname_obj = argv[optind];
95
96         if (dm_init_service(&name) == -1)  {
97                 fprintf(stderr, "Can't initialize the DMAPI\n");
98                 exit(1);
99         }
100         if (sid == DM_NO_SESSION)
101                 find_test_session(&sid);
102
103         /* Get the file's handle or convert the external handle. */
104
105         if (opaque_to_handle(pathname_obj, &hanp, &hlen)) {
106                 fprintf(stderr, "can't get handle for %s\n", pathname_obj);
107                 exit(1);
108         }
109
110         if (!a_flag) {
111                 fprintf(stdout, "path/handle            %s\n", pathname_obj);
112
113                 /* Get the file's state, print it, then verify it against
114                    what is in the file's stat block.
115                 */
116
117                 if (dm_get_fileattr(sid, hanp, hlen, token,
118         DM_AT_EMASK|DM_AT_PMANR|DM_AT_PATTR|DM_AT_DTIME|DM_AT_CFLAG|DM_AT_STAT,
119                     &dmstat)) {
120                         fprintf(stderr, "dm_get_fileattr failed, %s\n",
121                                 strerror(errno));
122                         exit(1);
123                 }
124
125                 print_state(&dmstat);
126                 if(validate)
127                         (void)validate_state(&dmstat, pathname_obj, 1);
128 #if 0
129         } else {
130                 if ((rc = filesys_bulkscan_init(pathname, &scanp)) != 0) {
131                         fprintf(stderr, "filesys_bulkscan failed, %s\n",
132                                 fileio_err_image(rc));
133                         exit(1);
134                 }
135                 for (;;) {
136                         rc = filesys_bulkscan_read(scanp, &fhandle, &fullstat);
137                         if (rc != FILEIO_NOERROR)
138                                 break;
139
140                         (void)fhandle_to_buffer(&fhandle, buffer, sizeof(buffer));
141                         if (a_flag == 1) {
142                                 fprintf(stdout, "handle          %s\n", buffer);
143                                 print_state(&fullstat);
144                                 fprintf(stdout, "--------------------------\n");
145                         } else {
146                                 fprintf(stdout, "%s|", buffer);
147                                 print_line(&fullstat);
148                         }
149                 }
150
151                 if (rc != FILEIO_ENDOFSCAN) {
152                         fprintf(stderr, "filesys_bulkscan_read failed, %s\n",
153                                 fileio_err_image(rc));
154                         exit(1);
155                 }
156                 if ((rc = filesys_bulkscan_close(&scanp)) != 0) {
157                         fprintf(stderr, "filesys_bulkscan_close failed, %s\n",
158                                 fileio_err_image(rc));
159                         exit(1);
160                 }
161 #endif
162         }
163         exit(0);
164 }