xfs: test fallocate ops when rt extent size is and isn't a power of 2
[xfstests-dev.git] / dmapi / src / common / cmd / set_return_on_destroy.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2000-2002 Silicon Graphics, Inc.
4  * All Rights Reserved.
5  */
6
7 #include <lib/hsm.h>
8
9 #include <string.h>
10 #include <getopt.h>
11
12 /*---------------------------------------------------------------------------
13
14 Test program used to test the DMAPI function dm_set_return_on_destroy().  The
15 command line is:
16
17         set_return_on_destroy [-F] [-s sid] [-t token] {pathname|fshandle} [attr]
18
19 where pathname is the name of a file which resides in the filesystem of
20 interest.  attr is the name of the DMAPI attribute; if none is specified,
21 then set-return-on-destroy will be disabled for the filesystem.
22 sid is the session ID whose attribute you are interested in setting.
23
24 Use -F if you want the program to find the fshandle based on the pathname.
25
26 ----------------------------------------------------------------------------*/
27
28 #ifndef linux
29 extern  char    *sys_errlist[];
30 #endif
31 extern  int     optind;
32 extern  char    *optarg;
33
34
35 char    *Progname;
36
37 static void
38 usage(void)
39 {
40         fprintf(stderr, "usage:\t%s [-F] [-s sid] [-t token] {pathname|fshandle} [attr]\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         dm_token_t      token = DM_NO_TOKEN;
52         char            *pathname;
53         dm_attrname_t   *attrnamep = NULL;
54         dm_boolean_t    enable = DM_FALSE;
55         void            *hanp;
56         size_t          hlen;
57         char            *name;
58         int             opt;
59         int             Fflag = 0;
60
61         Progname = strrchr(argv[0], '/');
62         if (Progname) {
63                 Progname++;
64         } else {
65                 Progname = argv[0];
66         }
67
68         /* Crack and validate the command line options. */
69
70         while ((opt = getopt(argc, argv, "Fs:t:")) != EOF) {
71                 switch (opt) {
72                 case 's':
73                         sid = atol(optarg);
74                         break;
75                 case 't':
76                         token = atol(optarg);
77                         break;
78                 case 'F':
79                         Fflag++;
80                         break;
81                 case '?':
82                         usage();
83                 }
84         }
85         if (optind == argc || optind + 2 < argc)
86                 usage();
87         pathname = argv[optind++];
88         if (optind < argc) {
89                 enable = DM_TRUE;
90                 attrnamep = (dm_attrname_t *)argv[optind++];
91         }
92
93         if (dm_init_service(&name) == -1)  {
94                 fprintf(stderr, "Can't initialize the DMAPI\n");
95                 exit(1);
96         }
97         if (sid == DM_NO_SESSION)
98                 find_test_session(&sid);
99
100         if (opaque_to_handle(pathname, &hanp, &hlen)) {
101                 fprintf(stderr, "can't get handle for %s\n", pathname);
102                 exit(1);
103         }
104
105         /* Get the file's handle. */
106
107         if (Fflag) {
108                 void *fshanp;
109                 size_t fshlen;
110
111                 if (dm_handle_to_fshandle(hanp, hlen, &fshanp, &fshlen)) {
112                         fprintf(stderr, "can't get filesystem handle for file %s, %s\n",
113                                 pathname, strerror(errno));
114                         exit(1);
115                 }
116                 dm_handle_free(hanp, hlen);
117                 hanp = fshanp;
118                 hlen = fshlen;
119         }
120
121         if (dm_set_return_on_destroy(sid, hanp, hlen, token,
122             attrnamep, enable)) {
123                 fprintf(stderr, "dm_set_return_on_destroy failed, %s\n",
124                         strerror(errno));
125                 exit(1);
126         }
127
128         dm_handle_free(hanp, hlen);
129         exit(0);
130 }