xref: /illumos-gate/usr/src/cmd/fs.d/udfs/labelit/labelit.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
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) 1999-2000 by Sun Microsystems, Inc.
24*7c478bd9Sstevel@tonic-gate  * All rights reserved.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate /*
30*7c478bd9Sstevel@tonic-gate  * Label a file system volume.
31*7c478bd9Sstevel@tonic-gate  */
32*7c478bd9Sstevel@tonic-gate 
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate #include <stdio.h>
35*7c478bd9Sstevel@tonic-gate #include <string.h>
36*7c478bd9Sstevel@tonic-gate #include <strings.h>
37*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
38*7c478bd9Sstevel@tonic-gate #include <unistd.h>
39*7c478bd9Sstevel@tonic-gate #include <fcntl.h>
40*7c478bd9Sstevel@tonic-gate #include <locale.h>
41*7c478bd9Sstevel@tonic-gate #include <errno.h>
42*7c478bd9Sstevel@tonic-gate #include <sys/fcntl.h>
43*7c478bd9Sstevel@tonic-gate #include <sys/param.h>
44*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
45*7c478bd9Sstevel@tonic-gate #include <sys/mntent.h>
46*7c478bd9Sstevel@tonic-gate 
47*7c478bd9Sstevel@tonic-gate #include <sys/fs/udf_volume.h>
48*7c478bd9Sstevel@tonic-gate #include "ud_lib.h"
49*7c478bd9Sstevel@tonic-gate 
50*7c478bd9Sstevel@tonic-gate static uint8_t buf[MAXBSIZE];
51*7c478bd9Sstevel@tonic-gate static uint64_t off;
52*7c478bd9Sstevel@tonic-gate #define	BUF_LEN	0x200
53*7c478bd9Sstevel@tonic-gate static int8_t	lvinfo1_buf[BUF_LEN];
54*7c478bd9Sstevel@tonic-gate static int8_t	lvinfo2_buf[BUF_LEN];
55*7c478bd9Sstevel@tonic-gate static int8_t	lvinfo3_buf[BUF_LEN];
56*7c478bd9Sstevel@tonic-gate static int8_t	fsname[BUF_LEN];
57*7c478bd9Sstevel@tonic-gate static int8_t	volname[BUF_LEN];
58*7c478bd9Sstevel@tonic-gate static int32_t fsname_len;
59*7c478bd9Sstevel@tonic-gate 
60*7c478bd9Sstevel@tonic-gate #define	SET_LVINFO1	0x01
61*7c478bd9Sstevel@tonic-gate #define	SET_LVINFO2	0x02
62*7c478bd9Sstevel@tonic-gate #define	SET_LVINFO3	0x04
63*7c478bd9Sstevel@tonic-gate #define	SET_FSNAME	0x08
64*7c478bd9Sstevel@tonic-gate #define	SET_VOLNAME	0x10
65*7c478bd9Sstevel@tonic-gate 
66*7c478bd9Sstevel@tonic-gate typedef unsigned short unicode_t;
67*7c478bd9Sstevel@tonic-gate 
68*7c478bd9Sstevel@tonic-gate #define	FSNAME_STR_LEN	(8 + 2)
69*7c478bd9Sstevel@tonic-gate #define	VOLNAME_STR_LEN	32
70*7c478bd9Sstevel@tonic-gate #define	INFO_STR_LEN	36
71*7c478bd9Sstevel@tonic-gate 
72*7c478bd9Sstevel@tonic-gate static void usage();
73*7c478bd9Sstevel@tonic-gate static void label(int32_t, uint32_t);
74*7c478bd9Sstevel@tonic-gate static void print_info(struct vds *, char *, int32_t);
75*7c478bd9Sstevel@tonic-gate static void label_vds(struct vds *, uint32_t, int32_t);
76*7c478bd9Sstevel@tonic-gate static int32_t convert_string(int8_t *, int8_t *, int32_t, int32_t, int8_t *);
77*7c478bd9Sstevel@tonic-gate static int32_t ud_convert2unicode(int8_t *, int8_t *, int32_t);
78*7c478bd9Sstevel@tonic-gate 
79*7c478bd9Sstevel@tonic-gate 
80*7c478bd9Sstevel@tonic-gate int8_t *labelit_subopts[] = {
81*7c478bd9Sstevel@tonic-gate #define	LVINFO1	0x00
82*7c478bd9Sstevel@tonic-gate 	"lvinfo1",
83*7c478bd9Sstevel@tonic-gate #define	LVINFO2	0x01
84*7c478bd9Sstevel@tonic-gate 	"lvinfo2",
85*7c478bd9Sstevel@tonic-gate #define	LVINFO3	0x02
86*7c478bd9Sstevel@tonic-gate 	"lvinfo3",
87*7c478bd9Sstevel@tonic-gate 	NULL};
88*7c478bd9Sstevel@tonic-gate 
89*7c478bd9Sstevel@tonic-gate 
90*7c478bd9Sstevel@tonic-gate int
91*7c478bd9Sstevel@tonic-gate main(int32_t argc, char *argv[])
92*7c478bd9Sstevel@tonic-gate {
93*7c478bd9Sstevel@tonic-gate 	int32_t		opt = 0;
94*7c478bd9Sstevel@tonic-gate 	int32_t		fd = 0;
95*7c478bd9Sstevel@tonic-gate 	int32_t		flags = 0;
96*7c478bd9Sstevel@tonic-gate 	int32_t		ret = 0;
97*7c478bd9Sstevel@tonic-gate 	int8_t		*options = NULL;
98*7c478bd9Sstevel@tonic-gate 	int8_t		*value = NULL;
99*7c478bd9Sstevel@tonic-gate 	uint32_t	set_flags = 0;
100*7c478bd9Sstevel@tonic-gate 
101*7c478bd9Sstevel@tonic-gate 	(void) setlocale(LC_ALL, "");
102*7c478bd9Sstevel@tonic-gate 
103*7c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)
104*7c478bd9Sstevel@tonic-gate #define	TEXT_DOMAIN	"SYS_TEST"
105*7c478bd9Sstevel@tonic-gate #endif
106*7c478bd9Sstevel@tonic-gate 
107*7c478bd9Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
108*7c478bd9Sstevel@tonic-gate 
109*7c478bd9Sstevel@tonic-gate 
110*7c478bd9Sstevel@tonic-gate 	while ((opt = getopt(argc, argv, "F:o:")) != EOF) {
111*7c478bd9Sstevel@tonic-gate 		switch (opt) {
112*7c478bd9Sstevel@tonic-gate 		case 'F':
113*7c478bd9Sstevel@tonic-gate 			if (strcmp(optarg, "udfs") != 0) {
114*7c478bd9Sstevel@tonic-gate 				usage();
115*7c478bd9Sstevel@tonic-gate 			}
116*7c478bd9Sstevel@tonic-gate 			break;
117*7c478bd9Sstevel@tonic-gate 
118*7c478bd9Sstevel@tonic-gate 		case 'o':
119*7c478bd9Sstevel@tonic-gate 			/*
120*7c478bd9Sstevel@tonic-gate 			 * UDFS specific options
121*7c478bd9Sstevel@tonic-gate 			 */
122*7c478bd9Sstevel@tonic-gate 			options = optarg;
123*7c478bd9Sstevel@tonic-gate 			while (*options != '\0') {
124*7c478bd9Sstevel@tonic-gate 				switch (getsubopt(&options, labelit_subopts,
125*7c478bd9Sstevel@tonic-gate 						&value)) {
126*7c478bd9Sstevel@tonic-gate 				case LVINFO1 :
127*7c478bd9Sstevel@tonic-gate 					set_flags |= SET_LVINFO1;
128*7c478bd9Sstevel@tonic-gate 					(void) convert_string(value,
129*7c478bd9Sstevel@tonic-gate 						lvinfo1_buf, BUF_LEN,
130*7c478bd9Sstevel@tonic-gate 						INFO_STR_LEN,
131*7c478bd9Sstevel@tonic-gate 			gettext("udfs labelit: lvinfo1 should be less than "
132*7c478bd9Sstevel@tonic-gate 			"36 bytes after converting to compressed unicode "
133*7c478bd9Sstevel@tonic-gate 			"dstring\n"));
134*7c478bd9Sstevel@tonic-gate 					break;
135*7c478bd9Sstevel@tonic-gate 				case LVINFO2 :
136*7c478bd9Sstevel@tonic-gate 					set_flags |= SET_LVINFO2;
137*7c478bd9Sstevel@tonic-gate 					(void) convert_string(value,
138*7c478bd9Sstevel@tonic-gate 						lvinfo2_buf, BUF_LEN,
139*7c478bd9Sstevel@tonic-gate 						INFO_STR_LEN,
140*7c478bd9Sstevel@tonic-gate 			gettext("udfs labelit: lvinfo2 should be less than "
141*7c478bd9Sstevel@tonic-gate 			"36 bytes after converting to compressed unicode "
142*7c478bd9Sstevel@tonic-gate 			"dstring\n"));
143*7c478bd9Sstevel@tonic-gate 					break;
144*7c478bd9Sstevel@tonic-gate 				case LVINFO3 :
145*7c478bd9Sstevel@tonic-gate 					set_flags |= SET_LVINFO3;
146*7c478bd9Sstevel@tonic-gate 					(void) convert_string(value,
147*7c478bd9Sstevel@tonic-gate 						lvinfo3_buf, BUF_LEN,
148*7c478bd9Sstevel@tonic-gate 						INFO_STR_LEN,
149*7c478bd9Sstevel@tonic-gate 			gettext("udfs labelit: lvinfo3 should be less than "
150*7c478bd9Sstevel@tonic-gate 			"36 bytes after converting to compressed unicode "
151*7c478bd9Sstevel@tonic-gate 			"dstring\n"));
152*7c478bd9Sstevel@tonic-gate 					break;
153*7c478bd9Sstevel@tonic-gate 				default:
154*7c478bd9Sstevel@tonic-gate 					(void) fprintf(stderr,
155*7c478bd9Sstevel@tonic-gate 			gettext("udfs labelit: Unknown suboption %s\n"), value);
156*7c478bd9Sstevel@tonic-gate 					usage();
157*7c478bd9Sstevel@tonic-gate 					break;
158*7c478bd9Sstevel@tonic-gate 				}
159*7c478bd9Sstevel@tonic-gate 			}
160*7c478bd9Sstevel@tonic-gate 			break;
161*7c478bd9Sstevel@tonic-gate 
162*7c478bd9Sstevel@tonic-gate 		case '?':
163*7c478bd9Sstevel@tonic-gate 			usage();
164*7c478bd9Sstevel@tonic-gate 		}
165*7c478bd9Sstevel@tonic-gate 	}
166*7c478bd9Sstevel@tonic-gate 
167*7c478bd9Sstevel@tonic-gate 	if ((argc - optind) == 3) {
168*7c478bd9Sstevel@tonic-gate 
169*7c478bd9Sstevel@tonic-gate 		/*
170*7c478bd9Sstevel@tonic-gate 		 * There are restrictions on the
171*7c478bd9Sstevel@tonic-gate 		 * length of the names
172*7c478bd9Sstevel@tonic-gate 		 * fsname is 8 characters
173*7c478bd9Sstevel@tonic-gate 		 * volume name is 32 characters
174*7c478bd9Sstevel@tonic-gate 		 * The extra byte is for compression id
175*7c478bd9Sstevel@tonic-gate 		 */
176*7c478bd9Sstevel@tonic-gate 		fsname_len = convert_string(argv[optind + 1],
177*7c478bd9Sstevel@tonic-gate 				fsname, BUF_LEN, FSNAME_STR_LEN,
178*7c478bd9Sstevel@tonic-gate 	gettext("udfs labelit: fsname can not be longer than 8 characters\n"));
179*7c478bd9Sstevel@tonic-gate 
180*7c478bd9Sstevel@tonic-gate 		(void) convert_string(argv[optind + 2],
181*7c478bd9Sstevel@tonic-gate 				volname, BUF_LEN, VOLNAME_STR_LEN,
182*7c478bd9Sstevel@tonic-gate 		gettext("udfs labelit: volname can not be longer "
183*7c478bd9Sstevel@tonic-gate 			"than 32 bytes after converting to "
184*7c478bd9Sstevel@tonic-gate 			"compressed unicode dstring\n"));
185*7c478bd9Sstevel@tonic-gate 		set_flags |= SET_FSNAME | SET_VOLNAME;
186*7c478bd9Sstevel@tonic-gate 	} else {
187*7c478bd9Sstevel@tonic-gate 		if ((argc - optind) != 1) {
188*7c478bd9Sstevel@tonic-gate 			usage();
189*7c478bd9Sstevel@tonic-gate 		}
190*7c478bd9Sstevel@tonic-gate 	}
191*7c478bd9Sstevel@tonic-gate 
192*7c478bd9Sstevel@tonic-gate 	/*
193*7c478bd9Sstevel@tonic-gate 	 * Open special device
194*7c478bd9Sstevel@tonic-gate 	 */
195*7c478bd9Sstevel@tonic-gate 	if (set_flags == 0) {
196*7c478bd9Sstevel@tonic-gate 		flags = O_RDONLY;
197*7c478bd9Sstevel@tonic-gate 	} else {
198*7c478bd9Sstevel@tonic-gate 		flags = O_RDWR;
199*7c478bd9Sstevel@tonic-gate 	}
200*7c478bd9Sstevel@tonic-gate 	if ((fd = ud_open_dev(argv[optind], flags)) < 0) {
201*7c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr,
202*7c478bd9Sstevel@tonic-gate 		gettext("udfs labelit: cannot open <%s> errorno <%d>\n"),
203*7c478bd9Sstevel@tonic-gate 					argv[optind], errno);
204*7c478bd9Sstevel@tonic-gate 		exit(1);
205*7c478bd9Sstevel@tonic-gate 	}
206*7c478bd9Sstevel@tonic-gate 
207*7c478bd9Sstevel@tonic-gate 	if ((ret = ud_fill_udfs_info(fd)) != 0) {
208*7c478bd9Sstevel@tonic-gate 		goto close_dev;
209*7c478bd9Sstevel@tonic-gate 	}
210*7c478bd9Sstevel@tonic-gate 
211*7c478bd9Sstevel@tonic-gate 	if ((udfs.flags & VALID_UDFS) == 0) {
212*7c478bd9Sstevel@tonic-gate 		ret = 1;
213*7c478bd9Sstevel@tonic-gate 		goto close_dev;
214*7c478bd9Sstevel@tonic-gate 	}
215*7c478bd9Sstevel@tonic-gate 
216*7c478bd9Sstevel@tonic-gate 	label(fd, set_flags);
217*7c478bd9Sstevel@tonic-gate 
218*7c478bd9Sstevel@tonic-gate close_dev:
219*7c478bd9Sstevel@tonic-gate 	ud_close_dev(fd);
220*7c478bd9Sstevel@tonic-gate 
221*7c478bd9Sstevel@tonic-gate 	return (ret);
222*7c478bd9Sstevel@tonic-gate }
223*7c478bd9Sstevel@tonic-gate 
224*7c478bd9Sstevel@tonic-gate static void
225*7c478bd9Sstevel@tonic-gate usage()
226*7c478bd9Sstevel@tonic-gate {
227*7c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, gettext(
228*7c478bd9Sstevel@tonic-gate 		"udfs usage: labelit [-F udfs] [generic options] "
229*7c478bd9Sstevel@tonic-gate 		"[ -o specific_options ] special [fsname volume]\n"));
230*7c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, gettext(
231*7c478bd9Sstevel@tonic-gate 		" -o : specific_options : [lvinfo1=string],"
232*7c478bd9Sstevel@tonic-gate 		"[lvinfo2=string],[lvinfo3=string]\n"));
233*7c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr,
234*7c478bd9Sstevel@tonic-gate 		gettext("NOTE that all -o suboptions: must"
235*7c478bd9Sstevel@tonic-gate 		" be separated only by commas.\n"));
236*7c478bd9Sstevel@tonic-gate 	exit(1);
237*7c478bd9Sstevel@tonic-gate }
238*7c478bd9Sstevel@tonic-gate 
239*7c478bd9Sstevel@tonic-gate static void
240*7c478bd9Sstevel@tonic-gate label(int32_t fd, uint32_t set_flags)
241*7c478bd9Sstevel@tonic-gate {
242*7c478bd9Sstevel@tonic-gate 	if (set_flags == 0) {
243*7c478bd9Sstevel@tonic-gate 		if (udfs.flags & VALID_MVDS) {
244*7c478bd9Sstevel@tonic-gate 			print_info(&udfs.mvds, "mvds", fd);
245*7c478bd9Sstevel@tonic-gate 		}
246*7c478bd9Sstevel@tonic-gate 		if (udfs.flags & VALID_RVDS) {
247*7c478bd9Sstevel@tonic-gate 			print_info(&udfs.rvds, "rvds", fd);
248*7c478bd9Sstevel@tonic-gate 		}
249*7c478bd9Sstevel@tonic-gate 		return;
250*7c478bd9Sstevel@tonic-gate 	} else {
251*7c478bd9Sstevel@tonic-gate 
252*7c478bd9Sstevel@tonic-gate 		if (udfs.flags & VALID_MVDS) {
253*7c478bd9Sstevel@tonic-gate 			label_vds(&udfs.mvds, set_flags, fd);
254*7c478bd9Sstevel@tonic-gate 		}
255*7c478bd9Sstevel@tonic-gate 		if (udfs.flags & VALID_RVDS) {
256*7c478bd9Sstevel@tonic-gate 			label_vds(&udfs.rvds, set_flags, fd);
257*7c478bd9Sstevel@tonic-gate 		}
258*7c478bd9Sstevel@tonic-gate 		if (((set_flags & (SET_FSNAME | SET_VOLNAME)) ==
259*7c478bd9Sstevel@tonic-gate 			(SET_FSNAME | SET_VOLNAME)) &&
260*7c478bd9Sstevel@tonic-gate 			(udfs.fsd_len != 0)) {
261*7c478bd9Sstevel@tonic-gate 			struct file_set_desc *fsd;
262*7c478bd9Sstevel@tonic-gate 
263*7c478bd9Sstevel@tonic-gate 			off = udfs.fsd_loc * udfs.lbsize;
264*7c478bd9Sstevel@tonic-gate 			if (ud_read_dev(fd, off, buf, udfs.fsd_len) != 0) {
265*7c478bd9Sstevel@tonic-gate 				return;
266*7c478bd9Sstevel@tonic-gate 			}
267*7c478bd9Sstevel@tonic-gate 
268*7c478bd9Sstevel@tonic-gate 			/* LINTED */
269*7c478bd9Sstevel@tonic-gate 			fsd = (struct file_set_desc *)buf;
270*7c478bd9Sstevel@tonic-gate 
271*7c478bd9Sstevel@tonic-gate 			set_dstring(fsd->fsd_lvid,
272*7c478bd9Sstevel@tonic-gate 				volname, sizeof (fsd->fsd_lvid));
273*7c478bd9Sstevel@tonic-gate 			set_dstring(fsd->fsd_fsi,
274*7c478bd9Sstevel@tonic-gate 				volname, sizeof (fsd->fsd_fsi));
275*7c478bd9Sstevel@tonic-gate 
276*7c478bd9Sstevel@tonic-gate 			ud_make_tag(&fsd->fsd_tag, UD_FILE_SET_DESC,
277*7c478bd9Sstevel@tonic-gate 				SWAP_32(fsd->fsd_tag.tag_loc),
278*7c478bd9Sstevel@tonic-gate 				SWAP_16(fsd->fsd_tag.tag_crc_len));
279*7c478bd9Sstevel@tonic-gate 
280*7c478bd9Sstevel@tonic-gate 			(void) ud_write_dev(fd, off, buf, udfs.fsd_len);
281*7c478bd9Sstevel@tonic-gate 		}
282*7c478bd9Sstevel@tonic-gate 	}
283*7c478bd9Sstevel@tonic-gate }
284*7c478bd9Sstevel@tonic-gate 
285*7c478bd9Sstevel@tonic-gate static void
286*7c478bd9Sstevel@tonic-gate print_info(struct vds *v, char *name, int32_t fd)
287*7c478bd9Sstevel@tonic-gate {
288*7c478bd9Sstevel@tonic-gate 	uint8_t		outbuf[BUF_LEN];
289*7c478bd9Sstevel@tonic-gate 
290*7c478bd9Sstevel@tonic-gate 	if (v->pvd_len != 0) {
291*7c478bd9Sstevel@tonic-gate 		off = v->pvd_loc * udfs.lbsize;
292*7c478bd9Sstevel@tonic-gate 		if (ud_read_dev(fd, off, buf,
293*7c478bd9Sstevel@tonic-gate 			sizeof (struct pri_vol_desc)) == 0) {
294*7c478bd9Sstevel@tonic-gate 
295*7c478bd9Sstevel@tonic-gate 			struct pri_vol_desc *pvd;
296*7c478bd9Sstevel@tonic-gate 
297*7c478bd9Sstevel@tonic-gate 			/* LINTED */
298*7c478bd9Sstevel@tonic-gate 			pvd = (struct pri_vol_desc *)buf;
299*7c478bd9Sstevel@tonic-gate 
300*7c478bd9Sstevel@tonic-gate 			bzero(outbuf, BUF_LEN);
301*7c478bd9Sstevel@tonic-gate 			(void) ud_convert2local(
302*7c478bd9Sstevel@tonic-gate 					(int8_t *)pvd->pvd_vsi,
303*7c478bd9Sstevel@tonic-gate 					(int8_t *)outbuf, strlen(pvd->pvd_vsi));
304*7c478bd9Sstevel@tonic-gate 			(void) fprintf(stdout,
305*7c478bd9Sstevel@tonic-gate 				gettext("fsname in  %s : %s\n"),
306*7c478bd9Sstevel@tonic-gate 					name, outbuf);
307*7c478bd9Sstevel@tonic-gate 
308*7c478bd9Sstevel@tonic-gate 			bzero(outbuf, BUF_LEN);
309*7c478bd9Sstevel@tonic-gate 			pvd->pvd_vol_id[31] = '\0';
310*7c478bd9Sstevel@tonic-gate 			(void) ud_convert2local(
311*7c478bd9Sstevel@tonic-gate 					(int8_t *)pvd->pvd_vol_id,
312*7c478bd9Sstevel@tonic-gate 					(int8_t *)outbuf,
313*7c478bd9Sstevel@tonic-gate 					strlen(pvd->pvd_vol_id));
314*7c478bd9Sstevel@tonic-gate 			(void) fprintf(stdout,
315*7c478bd9Sstevel@tonic-gate 				gettext("volume label in %s : %s\n"),
316*7c478bd9Sstevel@tonic-gate 					name, outbuf);
317*7c478bd9Sstevel@tonic-gate 		}
318*7c478bd9Sstevel@tonic-gate 	}
319*7c478bd9Sstevel@tonic-gate 
320*7c478bd9Sstevel@tonic-gate 	if (v->iud_len != 0) {
321*7c478bd9Sstevel@tonic-gate 		off = v->iud_loc * udfs.lbsize;
322*7c478bd9Sstevel@tonic-gate 		if (ud_read_dev(fd, off, buf,
323*7c478bd9Sstevel@tonic-gate 			sizeof (struct iuvd_desc)) == 0) {
324*7c478bd9Sstevel@tonic-gate 
325*7c478bd9Sstevel@tonic-gate 			struct iuvd_desc *iud;
326*7c478bd9Sstevel@tonic-gate 
327*7c478bd9Sstevel@tonic-gate 			/* LINTED */
328*7c478bd9Sstevel@tonic-gate 			iud = (struct iuvd_desc *)buf;
329*7c478bd9Sstevel@tonic-gate 			bzero(outbuf, BUF_LEN);
330*7c478bd9Sstevel@tonic-gate 			iud->iuvd_ifo1[35] = '\0';
331*7c478bd9Sstevel@tonic-gate 			(void) ud_convert2local(
332*7c478bd9Sstevel@tonic-gate 					(int8_t *)iud->iuvd_ifo1,
333*7c478bd9Sstevel@tonic-gate 					(int8_t *)outbuf,
334*7c478bd9Sstevel@tonic-gate 					strlen(iud->iuvd_ifo1));
335*7c478bd9Sstevel@tonic-gate 			(void) fprintf(stdout,
336*7c478bd9Sstevel@tonic-gate 				gettext("LVInfo1 in  %s : %s\n"),
337*7c478bd9Sstevel@tonic-gate 					name, outbuf);
338*7c478bd9Sstevel@tonic-gate 
339*7c478bd9Sstevel@tonic-gate 			bzero(outbuf, BUF_LEN);
340*7c478bd9Sstevel@tonic-gate 			iud->iuvd_ifo2[35] = '\0';
341*7c478bd9Sstevel@tonic-gate 			(void) ud_convert2local(
342*7c478bd9Sstevel@tonic-gate 					(int8_t *)iud->iuvd_ifo2,
343*7c478bd9Sstevel@tonic-gate 					(int8_t *)outbuf,
344*7c478bd9Sstevel@tonic-gate 					strlen(iud->iuvd_ifo2));
345*7c478bd9Sstevel@tonic-gate 			(void) fprintf(stdout,
346*7c478bd9Sstevel@tonic-gate 				gettext("LVInfo2 in  %s : %s\n"),
347*7c478bd9Sstevel@tonic-gate 					name, outbuf);
348*7c478bd9Sstevel@tonic-gate 
349*7c478bd9Sstevel@tonic-gate 			bzero(outbuf, BUF_LEN);
350*7c478bd9Sstevel@tonic-gate 			iud->iuvd_ifo3[35] = '\0';
351*7c478bd9Sstevel@tonic-gate 			(void) ud_convert2local(
352*7c478bd9Sstevel@tonic-gate 					(int8_t *)iud->iuvd_ifo3,
353*7c478bd9Sstevel@tonic-gate 					(int8_t *)outbuf,
354*7c478bd9Sstevel@tonic-gate 					strlen(iud->iuvd_ifo3));
355*7c478bd9Sstevel@tonic-gate 			(void) fprintf(stdout,
356*7c478bd9Sstevel@tonic-gate 				gettext("LVInfo3 in  %s : %s\n"),
357*7c478bd9Sstevel@tonic-gate 					name, outbuf);
358*7c478bd9Sstevel@tonic-gate 		}
359*7c478bd9Sstevel@tonic-gate 	}
360*7c478bd9Sstevel@tonic-gate }
361*7c478bd9Sstevel@tonic-gate 
362*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
363*7c478bd9Sstevel@tonic-gate static void
364*7c478bd9Sstevel@tonic-gate label_vds(struct vds *v, uint32_t set_flags, int32_t fd)
365*7c478bd9Sstevel@tonic-gate {
366*7c478bd9Sstevel@tonic-gate 
367*7c478bd9Sstevel@tonic-gate 	if (((set_flags & (SET_FSNAME | SET_VOLNAME)) ==
368*7c478bd9Sstevel@tonic-gate 		(SET_FSNAME | SET_VOLNAME)) &&
369*7c478bd9Sstevel@tonic-gate 		(v->pvd_len)) {
370*7c478bd9Sstevel@tonic-gate 
371*7c478bd9Sstevel@tonic-gate 		off = v->pvd_loc * udfs.lbsize;
372*7c478bd9Sstevel@tonic-gate 		if (ud_read_dev(fd, off, buf,
373*7c478bd9Sstevel@tonic-gate 			sizeof (struct pri_vol_desc)) == 0) {
374*7c478bd9Sstevel@tonic-gate 
375*7c478bd9Sstevel@tonic-gate 			struct pri_vol_desc *pvd;
376*7c478bd9Sstevel@tonic-gate 
377*7c478bd9Sstevel@tonic-gate 			/* LINTED */
378*7c478bd9Sstevel@tonic-gate 			pvd = (struct pri_vol_desc *)buf;
379*7c478bd9Sstevel@tonic-gate 			bzero((int8_t *)&pvd->pvd_vsi[9], 119);
380*7c478bd9Sstevel@tonic-gate 			(void) strncpy((int8_t *)&pvd->pvd_vsi[9],
381*7c478bd9Sstevel@tonic-gate 					&fsname[1], fsname_len - 1);
382*7c478bd9Sstevel@tonic-gate 
383*7c478bd9Sstevel@tonic-gate 			set_dstring(pvd->pvd_vol_id,
384*7c478bd9Sstevel@tonic-gate 				volname, sizeof (pvd->pvd_vol_id));
385*7c478bd9Sstevel@tonic-gate 
386*7c478bd9Sstevel@tonic-gate 			ud_make_tag(&pvd->pvd_tag,
387*7c478bd9Sstevel@tonic-gate 				SWAP_16(pvd->pvd_tag.tag_id),
388*7c478bd9Sstevel@tonic-gate 				SWAP_32(pvd->pvd_tag.tag_loc),
389*7c478bd9Sstevel@tonic-gate 				SWAP_16(pvd->pvd_tag.tag_crc_len));
390*7c478bd9Sstevel@tonic-gate 
391*7c478bd9Sstevel@tonic-gate 			(void) ud_write_dev(fd, off, buf,
392*7c478bd9Sstevel@tonic-gate 				sizeof (struct pri_vol_desc));
393*7c478bd9Sstevel@tonic-gate 		}
394*7c478bd9Sstevel@tonic-gate 	}
395*7c478bd9Sstevel@tonic-gate 
396*7c478bd9Sstevel@tonic-gate 	if (set_flags && v->iud_len) {
397*7c478bd9Sstevel@tonic-gate 
398*7c478bd9Sstevel@tonic-gate 		off = v->iud_loc * udfs.lbsize;
399*7c478bd9Sstevel@tonic-gate 		if (ud_read_dev(fd, off, buf,
400*7c478bd9Sstevel@tonic-gate 			sizeof (struct iuvd_desc)) == 0) {
401*7c478bd9Sstevel@tonic-gate 
402*7c478bd9Sstevel@tonic-gate 			struct iuvd_desc *iuvd;
403*7c478bd9Sstevel@tonic-gate 
404*7c478bd9Sstevel@tonic-gate 			/* LINTED */
405*7c478bd9Sstevel@tonic-gate 			iuvd = (struct iuvd_desc *)buf;
406*7c478bd9Sstevel@tonic-gate 
407*7c478bd9Sstevel@tonic-gate 			if ((set_flags & SET_VOLNAME) == SET_VOLNAME) {
408*7c478bd9Sstevel@tonic-gate 				set_dstring(iuvd->iuvd_lvi,
409*7c478bd9Sstevel@tonic-gate 					volname, sizeof (iuvd->iuvd_lvi));
410*7c478bd9Sstevel@tonic-gate 			}
411*7c478bd9Sstevel@tonic-gate 			if ((set_flags & SET_LVINFO1) == SET_LVINFO1) {
412*7c478bd9Sstevel@tonic-gate 				set_dstring(iuvd->iuvd_ifo1,
413*7c478bd9Sstevel@tonic-gate 					lvinfo1_buf, sizeof (iuvd->iuvd_ifo1));
414*7c478bd9Sstevel@tonic-gate 			}
415*7c478bd9Sstevel@tonic-gate 			if ((set_flags & SET_LVINFO2) == SET_LVINFO2) {
416*7c478bd9Sstevel@tonic-gate 				set_dstring(iuvd->iuvd_ifo2,
417*7c478bd9Sstevel@tonic-gate 					lvinfo2_buf, sizeof (iuvd->iuvd_ifo2));
418*7c478bd9Sstevel@tonic-gate 			}
419*7c478bd9Sstevel@tonic-gate 			if ((set_flags & SET_LVINFO3) == SET_LVINFO3) {
420*7c478bd9Sstevel@tonic-gate 				set_dstring(iuvd->iuvd_ifo3,
421*7c478bd9Sstevel@tonic-gate 					lvinfo3_buf, sizeof (iuvd->iuvd_ifo3));
422*7c478bd9Sstevel@tonic-gate 			}
423*7c478bd9Sstevel@tonic-gate 
424*7c478bd9Sstevel@tonic-gate 			ud_make_tag(&iuvd->iuvd_tag,
425*7c478bd9Sstevel@tonic-gate 				SWAP_16(iuvd->iuvd_tag.tag_id),
426*7c478bd9Sstevel@tonic-gate 				SWAP_32(iuvd->iuvd_tag.tag_loc),
427*7c478bd9Sstevel@tonic-gate 				SWAP_16(iuvd->iuvd_tag.tag_crc_len));
428*7c478bd9Sstevel@tonic-gate 
429*7c478bd9Sstevel@tonic-gate 			(void) ud_write_dev(fd, off, buf,
430*7c478bd9Sstevel@tonic-gate 				sizeof (struct iuvd_desc));
431*7c478bd9Sstevel@tonic-gate 		}
432*7c478bd9Sstevel@tonic-gate 	}
433*7c478bd9Sstevel@tonic-gate 
434*7c478bd9Sstevel@tonic-gate 	if (((set_flags & (SET_FSNAME | SET_VOLNAME)) ==
435*7c478bd9Sstevel@tonic-gate 		(SET_FSNAME | SET_VOLNAME)) &&
436*7c478bd9Sstevel@tonic-gate 		(v->lvd_len)) {
437*7c478bd9Sstevel@tonic-gate 
438*7c478bd9Sstevel@tonic-gate 		off = v->lvd_loc * udfs.lbsize;
439*7c478bd9Sstevel@tonic-gate 		if (ud_read_dev(fd, off, buf,
440*7c478bd9Sstevel@tonic-gate 			sizeof (struct log_vol_desc)) == 0) {
441*7c478bd9Sstevel@tonic-gate 
442*7c478bd9Sstevel@tonic-gate 			struct log_vol_desc *lvd;
443*7c478bd9Sstevel@tonic-gate 
444*7c478bd9Sstevel@tonic-gate 			/* LINTED */
445*7c478bd9Sstevel@tonic-gate 			lvd = (struct log_vol_desc *)buf;
446*7c478bd9Sstevel@tonic-gate 			set_dstring(lvd->lvd_lvid,
447*7c478bd9Sstevel@tonic-gate 				volname, sizeof (lvd->lvd_lvid));
448*7c478bd9Sstevel@tonic-gate 
449*7c478bd9Sstevel@tonic-gate 			ud_make_tag(&lvd->lvd_tag,
450*7c478bd9Sstevel@tonic-gate 				SWAP_16(lvd->lvd_tag.tag_id),
451*7c478bd9Sstevel@tonic-gate 				SWAP_32(lvd->lvd_tag.tag_loc),
452*7c478bd9Sstevel@tonic-gate 				SWAP_16(lvd->lvd_tag.tag_crc_len));
453*7c478bd9Sstevel@tonic-gate 
454*7c478bd9Sstevel@tonic-gate 			(void) ud_write_dev(fd, off, buf,
455*7c478bd9Sstevel@tonic-gate 				sizeof (struct log_vol_desc));
456*7c478bd9Sstevel@tonic-gate 		}
457*7c478bd9Sstevel@tonic-gate 	}
458*7c478bd9Sstevel@tonic-gate }
459*7c478bd9Sstevel@tonic-gate 
460*7c478bd9Sstevel@tonic-gate 
461*7c478bd9Sstevel@tonic-gate int32_t
462*7c478bd9Sstevel@tonic-gate convert_string(int8_t *value, int8_t *out_buf, int32_t out_len,
463*7c478bd9Sstevel@tonic-gate 	int32_t len, int8_t *error_string)
464*7c478bd9Sstevel@tonic-gate {
465*7c478bd9Sstevel@tonic-gate 	int32_t		out_length = 0;
466*7c478bd9Sstevel@tonic-gate 
467*7c478bd9Sstevel@tonic-gate 	out_length = ud_convert2unicode(value, out_buf, out_len);
468*7c478bd9Sstevel@tonic-gate 	if (out_length > len - 1) {
469*7c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, "%s", error_string);
470*7c478bd9Sstevel@tonic-gate 		exit(1);
471*7c478bd9Sstevel@tonic-gate 	}
472*7c478bd9Sstevel@tonic-gate 
473*7c478bd9Sstevel@tonic-gate 	return (out_length);
474*7c478bd9Sstevel@tonic-gate }
475*7c478bd9Sstevel@tonic-gate 
476*7c478bd9Sstevel@tonic-gate static int32_t
477*7c478bd9Sstevel@tonic-gate ud_convert2unicode(int8_t *mb, int8_t *comp, int32_t out_len)
478*7c478bd9Sstevel@tonic-gate {
479*7c478bd9Sstevel@tonic-gate 	wchar_t		buf4c[128];
480*7c478bd9Sstevel@tonic-gate 	int32_t		len = 0;
481*7c478bd9Sstevel@tonic-gate 	int32_t		i = 0;
482*7c478bd9Sstevel@tonic-gate 	int32_t		j = 0;
483*7c478bd9Sstevel@tonic-gate 	uint8_t		c = 8;
484*7c478bd9Sstevel@tonic-gate 
485*7c478bd9Sstevel@tonic-gate 	len = mbstowcs(buf4c, mb, 127);
486*7c478bd9Sstevel@tonic-gate 	buf4c[127] = '\0';
487*7c478bd9Sstevel@tonic-gate 
488*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < len; i++) {
489*7c478bd9Sstevel@tonic-gate 		if (buf4c[i] & 0xFFFFFF00) {
490*7c478bd9Sstevel@tonic-gate 			c = 16;
491*7c478bd9Sstevel@tonic-gate 			break;
492*7c478bd9Sstevel@tonic-gate 		}
493*7c478bd9Sstevel@tonic-gate 	}
494*7c478bd9Sstevel@tonic-gate 
495*7c478bd9Sstevel@tonic-gate 	comp[0] = c;
496*7c478bd9Sstevel@tonic-gate 	j = 1;
497*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < len && i < out_len; i++) {
498*7c478bd9Sstevel@tonic-gate 		if (c == 16) {
499*7c478bd9Sstevel@tonic-gate 			comp[j] = (buf4c[i] & 0xFF00) >> 8;
500*7c478bd9Sstevel@tonic-gate 		}
501*7c478bd9Sstevel@tonic-gate 		comp[j++] = buf4c[i] & 0xFF;
502*7c478bd9Sstevel@tonic-gate 	}
503*7c478bd9Sstevel@tonic-gate 
504*7c478bd9Sstevel@tonic-gate 	return (j);
505*7c478bd9Sstevel@tonic-gate }
506