_scratch_mkfs_geom(): Filter out 'k' suffix from fs block size
[xfstests-dev.git] / dmapi / src / suite1 / cmd / remove_dmattr.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2000-2001 Silicon Graphics, Inc.
4  * All Rights Reserved.
5  */
6
7 #include <lib/hsm.h>
8
9 #include <getopt.h>
10 #include <string.h>
11
12
13 /*---------------------------------------------------------------------------
14
15 Test program used to test the DMAPI function dm_remove_dmattr().  The
16 command line is:
17
18         remove_dmattr [-s sid] [-u] pathname attr
19
20 where pathname is the name of a file, attr is the name of the DMAPI attribute,
21 and sid is the session ID whose attributes you are interested in.
22
23 ----------------------------------------------------------------------------*/
24
25 #ifndef linux
26 extern  char    *sys_errlist[];
27 #endif
28 extern  int     optind;
29 extern  char    *optarg;
30
31
32 char    *Progname;
33
34 static void
35 usage(void)
36 {
37         fprintf(stderr, "usage:\t%s [-s sid] [-u] pathname attr\n", Progname);
38         exit(1);
39 }
40
41
42 int
43 main(
44         int     argc, 
45         char    **argv)
46 {
47         dm_sessid_t     sid = DM_NO_SESSION;
48         char            *pathname;
49         dm_attrname_t   *attrnamep;
50         int             setdtime = 0;
51         void            *hanp;
52         size_t          hlen;
53         char            *name;
54         int             opt;
55
56         Progname = strrchr(argv[0], '/');
57         if (Progname) {
58                 Progname++;
59         } else {
60                 Progname = argv[0];
61         }
62
63         /* Crack and validate the command line options. */
64
65         while ((opt = getopt(argc, argv, "s:u")) != EOF) {
66                 switch (opt) {
67                 case 's':
68                         sid = atol(optarg);
69                         break;
70                 case 'u':
71                         setdtime = 1;
72                         break;
73                 case '?':
74                         usage();
75                 }
76         }
77         if (optind + 2 != argc)
78                 usage();
79         pathname = argv[optind++];
80         attrnamep = (dm_attrname_t *)argv[optind++];
81
82         if (dm_init_service(&name) == -1)  {
83                 fprintf(stderr, "Can't initialize the DMAPI\n");
84                 exit(1);
85         }
86         if (sid == DM_NO_SESSION)
87                 find_test_session(&sid);
88
89         /* Get the file's handle. */
90
91         if (dm_path_to_handle(pathname, &hanp, &hlen)) {
92                 fprintf(stderr, "can't get handle for file %s\n", pathname);
93                 exit(1);
94         }
95
96         if (dm_remove_dmattr(sid, hanp, hlen, DM_NO_TOKEN, setdtime,
97            attrnamep)) {
98                 fprintf(stderr, "dm_remove_dmattr failed, %s\n",
99                         strerror(errno));
100                 exit(1);
101         }
102
103         dm_handle_free(hanp, hlen);
104         exit(0);
105 }