1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate * with the License.
8*7c478bd9Sstevel@tonic-gate *
9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate *
14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate * Copyright (c) 2000-2001 by Sun Microsystems, Inc.
24*7c478bd9Sstevel@tonic-gate * All rights reserved.
25*7c478bd9Sstevel@tonic-gate */
26*7c478bd9Sstevel@tonic-gate
27*7c478bd9Sstevel@tonic-gate /*
28*7c478bd9Sstevel@tonic-gate * Routines to support fssnap subcommand of switchout. See switchout.c for
29*7c478bd9Sstevel@tonic-gate * the real fssnap command.
30*7c478bd9Sstevel@tonic-gate */
31*7c478bd9Sstevel@tonic-gate
32*7c478bd9Sstevel@tonic-gate #include <stdio.h>
33*7c478bd9Sstevel@tonic-gate #include <kstat.h>
34*7c478bd9Sstevel@tonic-gate #include <libintl.h>
35*7c478bd9Sstevel@tonic-gate #include <sys/fssnap_if.h>
36*7c478bd9Sstevel@tonic-gate #include <string.h>
37*7c478bd9Sstevel@tonic-gate #include <errno.h>
38*7c478bd9Sstevel@tonic-gate
39*7c478bd9Sstevel@tonic-gate static void fssnap_display_info(ulong_t, int *, int);
40*7c478bd9Sstevel@tonic-gate
41*7c478bd9Sstevel@tonic-gate #define MAX_INFO_DESCRIPTORS (10)
42*7c478bd9Sstevel@tonic-gate
43*7c478bd9Sstevel@tonic-gate static char *infosubopts[] = {
44*7c478bd9Sstevel@tonic-gate #define INFO_SNAPSHOT (0)
45*7c478bd9Sstevel@tonic-gate "snapnumber",
46*7c478bd9Sstevel@tonic-gate #define INFO_BLKDEV (1)
47*7c478bd9Sstevel@tonic-gate "blockdevname",
48*7c478bd9Sstevel@tonic-gate #define INFO_CHARDEV (2)
49*7c478bd9Sstevel@tonic-gate "rawdevname",
50*7c478bd9Sstevel@tonic-gate #define INFO_MNTPT (3)
51*7c478bd9Sstevel@tonic-gate "mountpoint",
52*7c478bd9Sstevel@tonic-gate #define INFO_STATE (4)
53*7c478bd9Sstevel@tonic-gate "state",
54*7c478bd9Sstevel@tonic-gate #define INFO_BACKPATH (5)
55*7c478bd9Sstevel@tonic-gate "backing-store",
56*7c478bd9Sstevel@tonic-gate #define INFO_BACKSIZE (6)
57*7c478bd9Sstevel@tonic-gate "backing-store-len",
58*7c478bd9Sstevel@tonic-gate #define INFO_MAXSIZE (7)
59*7c478bd9Sstevel@tonic-gate "maxsize",
60*7c478bd9Sstevel@tonic-gate #define INFO_CREATETIME (8)
61*7c478bd9Sstevel@tonic-gate "createtime",
62*7c478bd9Sstevel@tonic-gate #define INFO_CHUNKSIZE (9)
63*7c478bd9Sstevel@tonic-gate "chunksize",
64*7c478bd9Sstevel@tonic-gate NULL
65*7c478bd9Sstevel@tonic-gate };
66*7c478bd9Sstevel@tonic-gate
67*7c478bd9Sstevel@tonic-gate #define BLOCK_PATH "/dev/" SNAP_BLOCK_NAME "/"
68*7c478bd9Sstevel@tonic-gate #define CHAR_PATH "/dev/" SNAP_CHAR_NAME "/"
69*7c478bd9Sstevel@tonic-gate
70*7c478bd9Sstevel@tonic-gate /* labels are truncated to this many characters when displayed */
71*7c478bd9Sstevel@tonic-gate #define MAX_LABEL_LEN (30)
72*7c478bd9Sstevel@tonic-gate
73*7c478bd9Sstevel@tonic-gate /*
74*7c478bd9Sstevel@tonic-gate * fssnap_show_status() - display file system snapshot status
75*7c478bd9Sstevel@tonic-gate *
76*7c478bd9Sstevel@tonic-gate * displays snapshot information. If mountpoint is set, information is
77*7c478bd9Sstevel@tonic-gate * only displayed for the snapshot (if one exists) on that file system.
78*7c478bd9Sstevel@tonic-gate * If mountpoint is NULL, information is displayed for all snapshots.
79*7c478bd9Sstevel@tonic-gate *
80*7c478bd9Sstevel@tonic-gate * If opts is defined, it is parsed as a list of suboptions (via
81*7c478bd9Sstevel@tonic-gate * getsubopt()) corresponding to the options list defined above. These
82*7c478bd9Sstevel@tonic-gate * options determine what data should be displayed and in what order. An
83*7c478bd9Sstevel@tonic-gate * option may appear more than once.
84*7c478bd9Sstevel@tonic-gate *
85*7c478bd9Sstevel@tonic-gate * The labels parameter is a boolean that determines whether labels
86*7c478bd9Sstevel@tonic-gate * (internationalized) are displayed before each data element. If it is
87*7c478bd9Sstevel@tonic-gate * 0, labels are not displayed, otherwise they are. The labels parameter
88*7c478bd9Sstevel@tonic-gate * is ignored if brief is nonzero.
89*7c478bd9Sstevel@tonic-gate *
90*7c478bd9Sstevel@tonic-gate * The brief parameter is also a boolean and specifies a mode where only
91*7c478bd9Sstevel@tonic-gate * the snapshot number and mount point are displayed, regardless of the
92*7c478bd9Sstevel@tonic-gate * value of labels. This could be used for listing all active snapshots.
93*7c478bd9Sstevel@tonic-gate *
94*7c478bd9Sstevel@tonic-gate * Based on these parameters, an order list is created that tells
95*7c478bd9Sstevel@tonic-gate * fssnap_display_info() what info to display and in what order.
96*7c478bd9Sstevel@tonic-gate *
97*7c478bd9Sstevel@tonic-gate * Note that when labels are not specified, the assumption is that the
98*7c478bd9Sstevel@tonic-gate * output is made for script readable consumption. For this reason, text
99*7c478bd9Sstevel@tonic-gate * is not I18N'd and numbers are left as bytes instead of converted to KB.
100*7c478bd9Sstevel@tonic-gate */
101*7c478bd9Sstevel@tonic-gate void
fssnap_show_status(char * mountpoint,char * opts,int labels,int brief)102*7c478bd9Sstevel@tonic-gate fssnap_show_status(char *mountpoint, char *opts, int labels, int brief)
103*7c478bd9Sstevel@tonic-gate {
104*7c478bd9Sstevel@tonic-gate int *order, orderlen = MAX_INFO_DESCRIPTORS+1;
105*7c478bd9Sstevel@tonic-gate kstat_ctl_t *kslib;
106*7c478bd9Sstevel@tonic-gate kstat_t *mnt;
107*7c478bd9Sstevel@tonic-gate kstat_t *kshigh;
108*7c478bd9Sstevel@tonic-gate kstat_named_t *highp;
109*7c478bd9Sstevel@tonic-gate char *suboptions, *v, *n;
110*7c478bd9Sstevel@tonic-gate int i = 0;
111*7c478bd9Sstevel@tonic-gate int num, usenum = 0;
112*7c478bd9Sstevel@tonic-gate
113*7c478bd9Sstevel@tonic-gate kslib = kstat_open();
114*7c478bd9Sstevel@tonic-gate kshigh = kstat_lookup(kslib, SNAP_NAME, 0, FSSNAP_KSTAT_HIGHWATER);
115*7c478bd9Sstevel@tonic-gate
116*7c478bd9Sstevel@tonic-gate /*
117*7c478bd9Sstevel@tonic-gate * First check and see if they gave us a mount point or a device
118*7c478bd9Sstevel@tonic-gate * name (ie /dev/fssnap/X or /dev/rfssnap/X).
119*7c478bd9Sstevel@tonic-gate */
120*7c478bd9Sstevel@tonic-gate if (mountpoint) {
121*7c478bd9Sstevel@tonic-gate if (strncmp(BLOCK_PATH, mountpoint, strlen(BLOCK_PATH)) == 0 ||
122*7c478bd9Sstevel@tonic-gate strncmp(CHAR_PATH, mountpoint, strlen(CHAR_PATH)) == 0) {
123*7c478bd9Sstevel@tonic-gate n = strrchr(mountpoint, '/');
124*7c478bd9Sstevel@tonic-gate n++;
125*7c478bd9Sstevel@tonic-gate if (isdigit(*n)) {
126*7c478bd9Sstevel@tonic-gate errno = 0;
127*7c478bd9Sstevel@tonic-gate num = (int)strtol(n, NULL, 10);
128*7c478bd9Sstevel@tonic-gate if (errno == 0) {
129*7c478bd9Sstevel@tonic-gate usenum++;
130*7c478bd9Sstevel@tonic-gate }
131*7c478bd9Sstevel@tonic-gate }
132*7c478bd9Sstevel@tonic-gate }
133*7c478bd9Sstevel@tonic-gate }
134*7c478bd9Sstevel@tonic-gate
135*7c478bd9Sstevel@tonic-gate if (opts) {
136*7c478bd9Sstevel@tonic-gate i = 0;
137*7c478bd9Sstevel@tonic-gate order = (int *)malloc(orderlen * sizeof (int));
138*7c478bd9Sstevel@tonic-gate if (order == NULL) {
139*7c478bd9Sstevel@tonic-gate fprintf(stderr,
140*7c478bd9Sstevel@tonic-gate gettext("cannot allocate order list.\n"));
141*7c478bd9Sstevel@tonic-gate return;
142*7c478bd9Sstevel@tonic-gate }
143*7c478bd9Sstevel@tonic-gate suboptions = opts;
144*7c478bd9Sstevel@tonic-gate while (*suboptions != '\0') {
145*7c478bd9Sstevel@tonic-gate /*
146*7c478bd9Sstevel@tonic-gate * -1 means invalid option, MAX_INFO_DESCRIPTORS is
147*7c478bd9Sstevel@tonic-gate * the end.
148*7c478bd9Sstevel@tonic-gate */
149*7c478bd9Sstevel@tonic-gate order[i++] = getsubopt(&suboptions, infosubopts, &v);
150*7c478bd9Sstevel@tonic-gate if (i >= orderlen) {
151*7c478bd9Sstevel@tonic-gate order = (int *)realloc(order,
152*7c478bd9Sstevel@tonic-gate sizeof (int) * (orderlen *= 2));
153*7c478bd9Sstevel@tonic-gate if (order == NULL) {
154*7c478bd9Sstevel@tonic-gate fprintf(stderr,
155*7c478bd9Sstevel@tonic-gate gettext("cannot reallocate order "
156*7c478bd9Sstevel@tonic-gate "list.\n"));
157*7c478bd9Sstevel@tonic-gate return;
158*7c478bd9Sstevel@tonic-gate }
159*7c478bd9Sstevel@tonic-gate }
160*7c478bd9Sstevel@tonic-gate
161*7c478bd9Sstevel@tonic-gate }
162*7c478bd9Sstevel@tonic-gate order[i] = MAX_INFO_DESCRIPTORS;
163*7c478bd9Sstevel@tonic-gate } else {
164*7c478bd9Sstevel@tonic-gate order = (int *)malloc(orderlen * sizeof (int));
165*7c478bd9Sstevel@tonic-gate if (order == NULL) {
166*7c478bd9Sstevel@tonic-gate fprintf(stderr,
167*7c478bd9Sstevel@tonic-gate gettext("cannot allocate order list.\n"));
168*7c478bd9Sstevel@tonic-gate return;
169*7c478bd9Sstevel@tonic-gate }
170*7c478bd9Sstevel@tonic-gate for (i = 0; i <= MAX_INFO_DESCRIPTORS; i++)
171*7c478bd9Sstevel@tonic-gate order[i] = i;
172*7c478bd9Sstevel@tonic-gate }
173*7c478bd9Sstevel@tonic-gate
174*7c478bd9Sstevel@tonic-gate /* check if fssnap module is loaded */
175*7c478bd9Sstevel@tonic-gate if (kshigh == NULL) {
176*7c478bd9Sstevel@tonic-gate kstat_close(kslib);
177*7c478bd9Sstevel@tonic-gate return;
178*7c478bd9Sstevel@tonic-gate }
179*7c478bd9Sstevel@tonic-gate
180*7c478bd9Sstevel@tonic-gate (void) kstat_read(kslib, kshigh, NULL);
181*7c478bd9Sstevel@tonic-gate highp = kstat_data_lookup(kshigh, FSSNAP_KSTAT_HIGHWATER);
182*7c478bd9Sstevel@tonic-gate
183*7c478bd9Sstevel@tonic-gate /* Loop up to the maximum number of snapshots */
184*7c478bd9Sstevel@tonic-gate for (i = 0; i <= highp->value.ui32; i++) {
185*7c478bd9Sstevel@tonic-gate mnt = kstat_lookup(kslib, SNAP_NAME, i, FSSNAP_KSTAT_MNTPT);
186*7c478bd9Sstevel@tonic-gate
187*7c478bd9Sstevel@tonic-gate /* if this snapshot is not allocated, skip to the next */
188*7c478bd9Sstevel@tonic-gate if (mnt == NULL)
189*7c478bd9Sstevel@tonic-gate continue;
190*7c478bd9Sstevel@tonic-gate if (kstat_read(kslib, mnt, NULL) == -1)
191*7c478bd9Sstevel@tonic-gate continue;
192*7c478bd9Sstevel@tonic-gate if (mountpoint != NULL) {
193*7c478bd9Sstevel@tonic-gate if ((usenum && i != num) ||
194*7c478bd9Sstevel@tonic-gate (!usenum && strcmp(mountpoint, mnt->ks_data) != 0))
195*7c478bd9Sstevel@tonic-gate continue;
196*7c478bd9Sstevel@tonic-gate }
197*7c478bd9Sstevel@tonic-gate
198*7c478bd9Sstevel@tonic-gate if (brief)
199*7c478bd9Sstevel@tonic-gate printf("%4d\t%s\n", i, (char *)mnt->ks_data);
200*7c478bd9Sstevel@tonic-gate else
201*7c478bd9Sstevel@tonic-gate fssnap_display_info(i, order, labels);
202*7c478bd9Sstevel@tonic-gate }
203*7c478bd9Sstevel@tonic-gate }
204*7c478bd9Sstevel@tonic-gate
205*7c478bd9Sstevel@tonic-gate static void
fssnap_display_info(ulong_t snapnum,int * order,int labels)206*7c478bd9Sstevel@tonic-gate fssnap_display_info(ulong_t snapnum, int *order, int labels)
207*7c478bd9Sstevel@tonic-gate {
208*7c478bd9Sstevel@tonic-gate kstat_ctl_t *kslib;
209*7c478bd9Sstevel@tonic-gate kstat_t *back, *num;
210*7c478bd9Sstevel@tonic-gate kstat_named_t *numvalp;
211*7c478bd9Sstevel@tonic-gate kstat_t *mnt;
212*7c478bd9Sstevel@tonic-gate u_longlong_t inuse, size = 0;
213*7c478bd9Sstevel@tonic-gate char buf[BUFSIZ], *first;
214*7c478bd9Sstevel@tonic-gate int i;
215*7c478bd9Sstevel@tonic-gate
216*7c478bd9Sstevel@tonic-gate /* load num kstat */
217*7c478bd9Sstevel@tonic-gate kslib = kstat_open();
218*7c478bd9Sstevel@tonic-gate num = kstat_lookup(kslib, SNAP_NAME, snapnum, FSSNAP_KSTAT_NUM);
219*7c478bd9Sstevel@tonic-gate if (num == NULL)
220*7c478bd9Sstevel@tonic-gate return;
221*7c478bd9Sstevel@tonic-gate
222*7c478bd9Sstevel@tonic-gate if (kstat_read(kslib, num, NULL) == -1)
223*7c478bd9Sstevel@tonic-gate return;
224*7c478bd9Sstevel@tonic-gate
225*7c478bd9Sstevel@tonic-gate for (i = 0; order[i] != MAX_INFO_DESCRIPTORS; i++) {
226*7c478bd9Sstevel@tonic-gate switch (order[i]) {
227*7c478bd9Sstevel@tonic-gate case INFO_SNAPSHOT:
228*7c478bd9Sstevel@tonic-gate if (labels)
229*7c478bd9Sstevel@tonic-gate printf("%-*s: %lu\n", MAX_LABEL_LEN,
230*7c478bd9Sstevel@tonic-gate gettext("Snapshot number"), snapnum);
231*7c478bd9Sstevel@tonic-gate else
232*7c478bd9Sstevel@tonic-gate printf("%lu\n", snapnum);
233*7c478bd9Sstevel@tonic-gate break;
234*7c478bd9Sstevel@tonic-gate case INFO_BLKDEV:
235*7c478bd9Sstevel@tonic-gate if (labels)
236*7c478bd9Sstevel@tonic-gate printf("%-*s: /dev/%s/%lu\n", MAX_LABEL_LEN,
237*7c478bd9Sstevel@tonic-gate gettext("Block Device"), SNAP_BLOCK_NAME,
238*7c478bd9Sstevel@tonic-gate snapnum);
239*7c478bd9Sstevel@tonic-gate else
240*7c478bd9Sstevel@tonic-gate printf("/dev/%s/%lu\n", SNAP_BLOCK_NAME,
241*7c478bd9Sstevel@tonic-gate snapnum);
242*7c478bd9Sstevel@tonic-gate break;
243*7c478bd9Sstevel@tonic-gate case INFO_CHARDEV:
244*7c478bd9Sstevel@tonic-gate if (labels)
245*7c478bd9Sstevel@tonic-gate printf("%-*s: /dev/%s/%lu\n", MAX_LABEL_LEN,
246*7c478bd9Sstevel@tonic-gate gettext("Raw Device"), SNAP_CHAR_NAME,
247*7c478bd9Sstevel@tonic-gate snapnum);
248*7c478bd9Sstevel@tonic-gate else
249*7c478bd9Sstevel@tonic-gate printf("/dev/%s/%lu\n", SNAP_CHAR_NAME,
250*7c478bd9Sstevel@tonic-gate snapnum);
251*7c478bd9Sstevel@tonic-gate break;
252*7c478bd9Sstevel@tonic-gate
253*7c478bd9Sstevel@tonic-gate case INFO_MNTPT:
254*7c478bd9Sstevel@tonic-gate mnt = kstat_lookup(kslib, SNAP_NAME, snapnum,
255*7c478bd9Sstevel@tonic-gate FSSNAP_KSTAT_MNTPT);
256*7c478bd9Sstevel@tonic-gate if (mnt == NULL) {
257*7c478bd9Sstevel@tonic-gate fprintf(stderr,
258*7c478bd9Sstevel@tonic-gate gettext("cannot read mount point kstat\n"));
259*7c478bd9Sstevel@tonic-gate continue;
260*7c478bd9Sstevel@tonic-gate }
261*7c478bd9Sstevel@tonic-gate if (kstat_read(kslib, mnt, NULL) == -1) {
262*7c478bd9Sstevel@tonic-gate continue;
263*7c478bd9Sstevel@tonic-gate }
264*7c478bd9Sstevel@tonic-gate if (labels)
265*7c478bd9Sstevel@tonic-gate printf("%-*s: %s\n", MAX_LABEL_LEN,
266*7c478bd9Sstevel@tonic-gate gettext("Mount point"),
267*7c478bd9Sstevel@tonic-gate (char *)mnt->ks_data);
268*7c478bd9Sstevel@tonic-gate else
269*7c478bd9Sstevel@tonic-gate printf("%s\n", (char *)mnt->ks_data);
270*7c478bd9Sstevel@tonic-gate break;
271*7c478bd9Sstevel@tonic-gate case INFO_STATE:
272*7c478bd9Sstevel@tonic-gate /* state */
273*7c478bd9Sstevel@tonic-gate numvalp = kstat_data_lookup(num,
274*7c478bd9Sstevel@tonic-gate FSSNAP_KSTAT_NUM_STATE);
275*7c478bd9Sstevel@tonic-gate if (numvalp == NULL) {
276*7c478bd9Sstevel@tonic-gate fprintf(stderr,
277*7c478bd9Sstevel@tonic-gate gettext("cannot read state kstat\n"));
278*7c478bd9Sstevel@tonic-gate continue;
279*7c478bd9Sstevel@tonic-gate }
280*7c478bd9Sstevel@tonic-gate
281*7c478bd9Sstevel@tonic-gate if (labels) {
282*7c478bd9Sstevel@tonic-gate printf("%-*s: ", MAX_LABEL_LEN,
283*7c478bd9Sstevel@tonic-gate gettext("Device state"));
284*7c478bd9Sstevel@tonic-gate switch (numvalp->value.i32) {
285*7c478bd9Sstevel@tonic-gate case 0: printf(gettext("creating\n"));
286*7c478bd9Sstevel@tonic-gate break;
287*7c478bd9Sstevel@tonic-gate case 1: printf(gettext("idle\n"));
288*7c478bd9Sstevel@tonic-gate break;
289*7c478bd9Sstevel@tonic-gate case 2: printf(gettext("active\n"));
290*7c478bd9Sstevel@tonic-gate break;
291*7c478bd9Sstevel@tonic-gate case 3: printf(gettext("disabled\n"));
292*7c478bd9Sstevel@tonic-gate break;
293*7c478bd9Sstevel@tonic-gate default: printf(gettext("unknown\n"));
294*7c478bd9Sstevel@tonic-gate break;
295*7c478bd9Sstevel@tonic-gate }
296*7c478bd9Sstevel@tonic-gate } else {
297*7c478bd9Sstevel@tonic-gate switch (numvalp->value.i32) {
298*7c478bd9Sstevel@tonic-gate case 0: printf("creating\n");
299*7c478bd9Sstevel@tonic-gate break;
300*7c478bd9Sstevel@tonic-gate case 1: printf("idle\n");
301*7c478bd9Sstevel@tonic-gate break;
302*7c478bd9Sstevel@tonic-gate case 2: printf("active\n");
303*7c478bd9Sstevel@tonic-gate break;
304*7c478bd9Sstevel@tonic-gate case 3: printf("disabled\n");
305*7c478bd9Sstevel@tonic-gate break;
306*7c478bd9Sstevel@tonic-gate default: printf("unknown\n");
307*7c478bd9Sstevel@tonic-gate break;
308*7c478bd9Sstevel@tonic-gate }
309*7c478bd9Sstevel@tonic-gate }
310*7c478bd9Sstevel@tonic-gate break;
311*7c478bd9Sstevel@tonic-gate
312*7c478bd9Sstevel@tonic-gate case INFO_BACKPATH:
313*7c478bd9Sstevel@tonic-gate /* backing file kstat */
314*7c478bd9Sstevel@tonic-gate back = kstat_lookup(kslib, SNAP_NAME, snapnum,
315*7c478bd9Sstevel@tonic-gate FSSNAP_KSTAT_BFNAME);
316*7c478bd9Sstevel@tonic-gate if (back == NULL ||
317*7c478bd9Sstevel@tonic-gate (kstat_read(kslib, back, NULL) == -1) ||
318*7c478bd9Sstevel@tonic-gate (back->ks_data == NULL)) {
319*7c478bd9Sstevel@tonic-gate fprintf(stderr,
320*7c478bd9Sstevel@tonic-gate gettext("cannot read backing file name "
321*7c478bd9Sstevel@tonic-gate "kstat from kernel\n"));
322*7c478bd9Sstevel@tonic-gate continue;
323*7c478bd9Sstevel@tonic-gate }
324*7c478bd9Sstevel@tonic-gate if (labels)
325*7c478bd9Sstevel@tonic-gate printf("%-*s: %s\n", MAX_LABEL_LEN,
326*7c478bd9Sstevel@tonic-gate gettext("Backing store path"),
327*7c478bd9Sstevel@tonic-gate (char *)back->ks_data);
328*7c478bd9Sstevel@tonic-gate else
329*7c478bd9Sstevel@tonic-gate printf("%s\n", (char *)back->ks_data);
330*7c478bd9Sstevel@tonic-gate break;
331*7c478bd9Sstevel@tonic-gate
332*7c478bd9Sstevel@tonic-gate case INFO_BACKSIZE:
333*7c478bd9Sstevel@tonic-gate numvalp = kstat_data_lookup(num,
334*7c478bd9Sstevel@tonic-gate FSSNAP_KSTAT_NUM_BFSIZE);
335*7c478bd9Sstevel@tonic-gate if (numvalp == NULL) {
336*7c478bd9Sstevel@tonic-gate fprintf(stderr,
337*7c478bd9Sstevel@tonic-gate gettext("cannot read backing file size "
338*7c478bd9Sstevel@tonic-gate "kstat from kernel\n"));
339*7c478bd9Sstevel@tonic-gate continue;
340*7c478bd9Sstevel@tonic-gate }
341*7c478bd9Sstevel@tonic-gate
342*7c478bd9Sstevel@tonic-gate size = numvalp->value.ui64;
343*7c478bd9Sstevel@tonic-gate
344*7c478bd9Sstevel@tonic-gate if (labels)
345*7c478bd9Sstevel@tonic-gate printf("%-*s: %llu KB\n", MAX_LABEL_LEN,
346*7c478bd9Sstevel@tonic-gate gettext("Backing store size"),
347*7c478bd9Sstevel@tonic-gate size / 1024LL);
348*7c478bd9Sstevel@tonic-gate else
349*7c478bd9Sstevel@tonic-gate printf("%llu\n", size);
350*7c478bd9Sstevel@tonic-gate break;
351*7c478bd9Sstevel@tonic-gate
352*7c478bd9Sstevel@tonic-gate case INFO_MAXSIZE:
353*7c478bd9Sstevel@tonic-gate numvalp = kstat_data_lookup(num,
354*7c478bd9Sstevel@tonic-gate FSSNAP_KSTAT_NUM_MAXSIZE);
355*7c478bd9Sstevel@tonic-gate if (numvalp == NULL) {
356*7c478bd9Sstevel@tonic-gate fprintf(stderr,
357*7c478bd9Sstevel@tonic-gate gettext("cannot read backing file maxsize "
358*7c478bd9Sstevel@tonic-gate "kstat from kernel\n"));
359*7c478bd9Sstevel@tonic-gate continue;
360*7c478bd9Sstevel@tonic-gate }
361*7c478bd9Sstevel@tonic-gate if (labels) {
362*7c478bd9Sstevel@tonic-gate printf("%-*s: ", MAX_LABEL_LEN,
363*7c478bd9Sstevel@tonic-gate gettext("Maximum backing store size"));
364*7c478bd9Sstevel@tonic-gate
365*7c478bd9Sstevel@tonic-gate if (numvalp->value.ui64 == 0LL)
366*7c478bd9Sstevel@tonic-gate printf(gettext("Unlimited\n"));
367*7c478bd9Sstevel@tonic-gate else
368*7c478bd9Sstevel@tonic-gate printf("%llu KB\n",
369*7c478bd9Sstevel@tonic-gate numvalp->value.ui64 / 1024LL);
370*7c478bd9Sstevel@tonic-gate } else {
371*7c478bd9Sstevel@tonic-gate printf("%llu\n", numvalp->value.ui64);
372*7c478bd9Sstevel@tonic-gate }
373*7c478bd9Sstevel@tonic-gate break;
374*7c478bd9Sstevel@tonic-gate
375*7c478bd9Sstevel@tonic-gate case INFO_CREATETIME:
376*7c478bd9Sstevel@tonic-gate {
377*7c478bd9Sstevel@tonic-gate /* snapshot creation time */
378*7c478bd9Sstevel@tonic-gate char buf[256];
379*7c478bd9Sstevel@tonic-gate struct tm *tm;
380*7c478bd9Sstevel@tonic-gate char *p;
381*7c478bd9Sstevel@tonic-gate
382*7c478bd9Sstevel@tonic-gate numvalp = kstat_data_lookup(num,
383*7c478bd9Sstevel@tonic-gate FSSNAP_KSTAT_NUM_CREATETIME);
384*7c478bd9Sstevel@tonic-gate if (numvalp == NULL) {
385*7c478bd9Sstevel@tonic-gate fprintf(stderr,
386*7c478bd9Sstevel@tonic-gate gettext("cannot read snapshot create time "
387*7c478bd9Sstevel@tonic-gate "kstat from kernel\n"));
388*7c478bd9Sstevel@tonic-gate continue;
389*7c478bd9Sstevel@tonic-gate }
390*7c478bd9Sstevel@tonic-gate
391*7c478bd9Sstevel@tonic-gate if (labels) {
392*7c478bd9Sstevel@tonic-gate printf("%-*s: ", MAX_LABEL_LEN,
393*7c478bd9Sstevel@tonic-gate gettext("Snapshot create time"));
394*7c478bd9Sstevel@tonic-gate
395*7c478bd9Sstevel@tonic-gate /* get the localized time */
396*7c478bd9Sstevel@tonic-gate tm = localtime(&numvalp->value.l);
397*7c478bd9Sstevel@tonic-gate if (strftime(buf, sizeof (buf),
398*7c478bd9Sstevel@tonic-gate "%c\n", tm) == 0)
399*7c478bd9Sstevel@tonic-gate /* Wouldn't fit in buf, fall back */
400*7c478bd9Sstevel@tonic-gate p = ctime(&numvalp->value.l);
401*7c478bd9Sstevel@tonic-gate else
402*7c478bd9Sstevel@tonic-gate p = buf;
403*7c478bd9Sstevel@tonic-gate } else {
404*7c478bd9Sstevel@tonic-gate /*
405*7c478bd9Sstevel@tonic-gate * for script-readable options we want
406*7c478bd9Sstevel@tonic-gate * the locale-independent time only.
407*7c478bd9Sstevel@tonic-gate */
408*7c478bd9Sstevel@tonic-gate p = ctime(&numvalp->value.l);
409*7c478bd9Sstevel@tonic-gate }
410*7c478bd9Sstevel@tonic-gate /* p should already have a \n appended */
411*7c478bd9Sstevel@tonic-gate printf("%s", p);
412*7c478bd9Sstevel@tonic-gate break;
413*7c478bd9Sstevel@tonic-gate }
414*7c478bd9Sstevel@tonic-gate
415*7c478bd9Sstevel@tonic-gate case INFO_CHUNKSIZE:
416*7c478bd9Sstevel@tonic-gate numvalp = kstat_data_lookup(num,
417*7c478bd9Sstevel@tonic-gate FSSNAP_KSTAT_NUM_CHUNKSIZE);
418*7c478bd9Sstevel@tonic-gate if (numvalp == NULL) {
419*7c478bd9Sstevel@tonic-gate fprintf(stderr,
420*7c478bd9Sstevel@tonic-gate gettext("cannot read chunksize kstat\n"));
421*7c478bd9Sstevel@tonic-gate continue;
422*7c478bd9Sstevel@tonic-gate }
423*7c478bd9Sstevel@tonic-gate if (labels)
424*7c478bd9Sstevel@tonic-gate printf("%-*s: %lu KB\n", MAX_LABEL_LEN,
425*7c478bd9Sstevel@tonic-gate gettext("Copy-on-write granularity"),
426*7c478bd9Sstevel@tonic-gate numvalp->value.ui32 / 1024L);
427*7c478bd9Sstevel@tonic-gate else
428*7c478bd9Sstevel@tonic-gate printf("%lu\n", numvalp->value.ui32);
429*7c478bd9Sstevel@tonic-gate break;
430*7c478bd9Sstevel@tonic-gate
431*7c478bd9Sstevel@tonic-gate case -1:
432*7c478bd9Sstevel@tonic-gate /*
433*7c478bd9Sstevel@tonic-gate * Print a place holder for unknown options so that
434*7c478bd9Sstevel@tonic-gate * the user can determine which option was not
435*7c478bd9Sstevel@tonic-gate * understood and the number outputted is the same
436*7c478bd9Sstevel@tonic-gate * number they requested.
437*7c478bd9Sstevel@tonic-gate */
438*7c478bd9Sstevel@tonic-gate printf("?\n");
439*7c478bd9Sstevel@tonic-gate break;
440*7c478bd9Sstevel@tonic-gate
441*7c478bd9Sstevel@tonic-gate default:
442*7c478bd9Sstevel@tonic-gate printf(gettext("No such data type %d.\n"), order[i]);
443*7c478bd9Sstevel@tonic-gate break;
444*7c478bd9Sstevel@tonic-gate }
445*7c478bd9Sstevel@tonic-gate }
446*7c478bd9Sstevel@tonic-gate }
447