common/rc: factor out _scratch_xfs_[get|set]_sb_field
[xfstests-dev.git] / dmapi / src / suite1 / cmd / remove_dmattr.c
1 /*
2  * Copyright (c) 2000-2001 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 <lib/hsm.h>
20
21 #include <getopt.h>
22 #include <string.h>
23
24
25 /*---------------------------------------------------------------------------
26
27 Test program used to test the DMAPI function dm_remove_dmattr().  The
28 command line is:
29
30         remove_dmattr [-s sid] [-u] pathname attr
31
32 where pathname is the name of a file, attr is the name of the DMAPI attribute,
33 and sid is the session ID whose attributes you are interested in.
34
35 ----------------------------------------------------------------------------*/
36
37 #ifndef linux
38 extern  char    *sys_errlist[];
39 #endif
40 extern  int     optind;
41 extern  char    *optarg;
42
43
44 char    *Progname;
45
46 static void
47 usage(void)
48 {
49         fprintf(stderr, "usage:\t%s [-s sid] [-u] pathname attr\n", Progname);
50         exit(1);
51 }
52
53
54 int
55 main(
56         int     argc, 
57         char    **argv)
58 {
59         dm_sessid_t     sid = DM_NO_SESSION;
60         char            *pathname;
61         dm_attrname_t   *attrnamep;
62         int             setdtime = 0;
63         void            *hanp;
64         size_t          hlen;
65         char            *name;
66         int             opt;
67
68         Progname = strrchr(argv[0], '/');
69         if (Progname) {
70                 Progname++;
71         } else {
72                 Progname = argv[0];
73         }
74
75         /* Crack and validate the command line options. */
76
77         while ((opt = getopt(argc, argv, "s:u")) != EOF) {
78                 switch (opt) {
79                 case 's':
80                         sid = atol(optarg);
81                         break;
82                 case 'u':
83                         setdtime = 1;
84                         break;
85                 case '?':
86                         usage();
87                 }
88         }
89         if (optind + 2 != argc)
90                 usage();
91         pathname = argv[optind++];
92         attrnamep = (dm_attrname_t *)argv[optind++];
93
94         if (dm_init_service(&name) == -1)  {
95                 fprintf(stderr, "Can't initialize the DMAPI\n");
96                 exit(1);
97         }
98         if (sid == DM_NO_SESSION)
99                 find_test_session(&sid);
100
101         /* Get the file's handle. */
102
103         if (dm_path_to_handle(pathname, &hanp, &hlen)) {
104                 fprintf(stderr, "can't get handle for file %s\n", pathname);
105                 exit(1);
106         }
107
108         if (dm_remove_dmattr(sid, hanp, hlen, DM_NO_TOKEN, setdtime,
109            attrnamep)) {
110                 fprintf(stderr, "dm_remove_dmattr failed, %s\n",
111                         strerror(errno));
112                 exit(1);
113         }
114
115         dm_handle_free(hanp, hlen);
116         exit(0);
117 }