generic/60[78]: ensure the initial DAX file flag state before test
[xfstests-dev.git] / dmapi / src / suite1 / cmd / set_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_set_dmattr().  The
16 command line is:
17
18         set_dmattr [-b buflen] [-s sid] [-u] {pathname|handle} attr value
19
20 where pathname is the name of a file, buflen is the size of the buffer to use
21 in the call, attr is the name of the DMAPI attribute, -u is selected if 
22 setdtime should be updated, and sid is the session ID whose attributes you
23 are interested in.
24
25 ----------------------------------------------------------------------------*/
26
27 #ifndef linux
28 extern  char    *sys_errlist[];
29 #endif
30 extern  int     optind;
31 extern  char    *optarg;
32
33
34 char    *Progname;
35
36 static void
37 usage(void)
38 {
39         fprintf(stderr, "usage:\t%s [-b buflen] [-s sid] [-u] "
40                 "{pathname|handle} attr value\n", Progname);
41         exit(1);
42 }
43
44
45 int
46 main(
47         int     argc, 
48         char    **argv)
49 {
50         dm_sessid_t     sid = DM_NO_SESSION;
51         char            *object;
52         dm_attrname_t   *attrnamep;
53         char            *bufp;
54         size_t          buflen = 0;
55         int             bflag = 0;
56         int             setdtime = 0;
57         void            *hanp;
58         size_t          hlen;
59         char            *name;
60         int             opt;
61
62         Progname = strrchr(argv[0], '/');
63         if (Progname) {
64                 Progname++;
65         } else {
66                 Progname = argv[0];
67         }
68
69         /* Crack and validate the command line options. */
70
71         while ((opt = getopt(argc, argv, "b:s:u")) != EOF) {
72                 switch (opt) {
73                 case 'b':
74                         bflag++;
75                         buflen = atol(optarg);
76                         break;
77                 case 's':
78                         sid = atol(optarg);
79                         break;
80                 case 'u':
81                         setdtime = 1;
82                         break;
83                 case '?':
84                         usage();
85                 }
86         }
87         if (optind + 3 != argc)
88                 usage();
89         object = argv[optind++];
90         attrnamep = (dm_attrname_t *)argv[optind++];
91         bufp = argv[optind];
92         if (!bflag)
93                 buflen = strlen(bufp) + 1;
94
95         if (dm_init_service(&name) == -1)  {
96                 fprintf(stderr, "Can't initialize the DMAPI\n");
97                 exit(1);
98         }
99         if (sid == DM_NO_SESSION)
100                 find_test_session(&sid);
101
102         /* Get the file's handle. */
103
104         if (opaque_to_handle(object, &hanp, &hlen)) {
105                 fprintf(stderr, "can't get handle for %s\n", object);
106                 exit(1);
107         }
108
109         if (dm_set_dmattr(sid, hanp, hlen, DM_NO_TOKEN, attrnamep, setdtime,
110             buflen, bufp)) {
111                 fprintf(stderr, "dm_set_dmattr failed, %s\n",
112                         strerror(errno));
113                 exit(1);
114         }
115
116         dm_handle_free(hanp, hlen);
117         exit(0);
118 }