2 * Simple util to print out DMAPI info about a file
4 * This code was written by Peter Lawthers, and placed in the public
5 * domain for use by DMAPI implementors and app writers.
8 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
9 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
10 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
11 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
12 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
13 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
14 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
15 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
16 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
17 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
21 #include <sys/types.h>
22 #include <sys/param.h>
32 #define MAX_RGNS 8 /* Arbitrary for this release */
36 extern int optind, optopt, opterr;
40 int mr_info(dm_sessid_t, void *, size_t);
41 int alloc_info(dm_sessid_t, void *, size_t);
42 int event_info(dm_sessid_t, void *, size_t);
43 int handle_info(dm_sessid_t, void *, size_t);
45 extern int setup_dmapi(dm_sessid_t *);
46 extern void errno_msg(char *, ...);
47 extern void print_handle(void *, size_t);
54 fprintf(stderr, "Usage: %s <options> filename \n ", prog);
55 fprintf(stderr, "\t-m managed region info\n");
56 fprintf(stderr, "\t-a allocation info\n");
57 fprintf(stderr, "\t-e event info\n");
58 fprintf(stderr, "\t-h handle\n");
69 int mr_flag, alloc_flag, handle_flag, event_flag;
77 mr_flag = alloc_flag = handle_flag = event_flag = 0;
79 while ((c = getopt(argc, argv, "maeh")) != EOF) {
103 filename = argv[optind];
104 if (filename == NULL) {
111 * Set up our link to the DMAPI, and get a handle for
112 * the file we want to query
114 error = setup_dmapi(&sid);
118 if (dm_path_to_handle(filename, &hanp, &hlen) == -1) {
119 printf("Can't get handle for path %s", filename);
124 printf("File %s:\n", filename);
126 error = mr_info(sid, hanp, hlen);
133 error = alloc_info(sid, hanp, hlen);
140 error = event_info(sid, hanp, hlen);
147 error = handle_info(sid, hanp, hlen);
155 if (dm_destroy_session(sid)) {
156 errno_msg("Can't shut down session");
164 * Get the complete list of all managed regions for a file. For now,
165 * we know that most implementations only support a small number of
166 * regions, so we don't handle the E2BIG error here.
176 dm_region_t rgn[MAX_RGNS];
178 memset((char *)&rgn, 0, (sizeof(dm_region_t) * MAX_RGNS));
179 if (dm_get_region(sid, hanp, hlen, DM_NO_TOKEN, MAX_RGNS, rgn, &ret)) {
180 errno_msg("Can't get list of managed regions");
184 for (i=0; i<ret; i++) {
185 printf("\tRegion %d:\n", i);
186 printf("\t\toffset %lld, ", rgn[i].rg_offset);
187 printf("size %lld, ", rgn[i].rg_size);
188 printf("flags 0x%x", rgn[i].rg_flags);
190 if (rgn[i].rg_flags & DM_REGION_NOEVENT)
192 if (rgn[i].rg_flags & DM_REGION_READ)
194 if (rgn[i].rg_flags & DM_REGION_WRITE)
196 if (rgn[i].rg_flags & DM_REGION_TRUNCATE)
204 * Get the complete list of events for a file.
213 dm_eventset_t eventlist;
215 DMEV_ZERO(eventlist);
216 if (dm_get_eventlist(sid, hanp, hlen, DM_NO_TOKEN, DM_EVENT_MAX,
218 errno_msg("Can't get list of events");
221 printf("\n\tEvent list: \n\t\t");
222 if (DMEV_ISSET(DM_EVENT_MOUNT, eventlist))
224 if (DMEV_ISSET(DM_EVENT_PREUNMOUNT, eventlist))
225 printf("preunmount ");
226 if (DMEV_ISSET(DM_EVENT_UNMOUNT, eventlist))
228 if (DMEV_ISSET(DM_EVENT_DEBUT, eventlist))
230 if (DMEV_ISSET(DM_EVENT_CREATE, eventlist))
232 if (DMEV_ISSET(DM_EVENT_POSTCREATE, eventlist))
233 printf("postcreate ");
234 if (DMEV_ISSET(DM_EVENT_REMOVE, eventlist))
236 if (DMEV_ISSET(DM_EVENT_POSTREMOVE, eventlist))
237 printf("postmount ");
238 if (DMEV_ISSET(DM_EVENT_RENAME, eventlist))
240 if (DMEV_ISSET(DM_EVENT_POSTRENAME, eventlist))
241 printf("postrename ");
242 if (DMEV_ISSET(DM_EVENT_LINK, eventlist))
244 if (DMEV_ISSET(DM_EVENT_POSTLINK, eventlist))
246 if (DMEV_ISSET(DM_EVENT_SYMLINK, eventlist))
248 if (DMEV_ISSET(DM_EVENT_POSTSYMLINK, eventlist))
249 printf("postsymlink ");
250 if (DMEV_ISSET(DM_EVENT_READ, eventlist))
252 if (DMEV_ISSET(DM_EVENT_WRITE, eventlist))
254 if (DMEV_ISSET(DM_EVENT_TRUNCATE, eventlist))
256 if (DMEV_ISSET(DM_EVENT_ATTRIBUTE, eventlist))
257 printf("attribute ");
258 if (DMEV_ISSET(DM_EVENT_DESTROY, eventlist))
260 if (DMEV_ISSET(DM_EVENT_NOSPACE, eventlist))
262 if (DMEV_ISSET(DM_EVENT_USER, eventlist))
270 * Print out the handle for a file
278 printf("\n\tHandle (handle length, value) \n\t\t");
279 print_handle(hanp, hlen);
284 * Get the allocation info for a file. We pick some small number
285 * of extents to get the residency info on at one time
295 u_int nextents, nret;
296 dm_extent_t ext[NUM_EXTENTS];
299 nextents = NUM_EXTENTS;
301 printf("\n\tAllocation info \n");
303 more = dm_get_allocinfo(sid, hanp, hlen, DM_NO_TOKEN, &offset,
304 nextents, ext, &nret);
306 errno_msg("Can't get alloc info for file");
309 for (i=0; i<nret; i++) {
310 printf("\t\tExtent %d ", i);
311 if (ext[i].ex_type == DM_EXTENT_RES)
312 printf("(resident): ");
313 if (ext[i].ex_type == DM_EXTENT_HOLE)
315 printf("offset %lld, ", ext[i].ex_offset);
316 printf("len %lld\n", ext[i].ex_length);