17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*0e42dee6Sartem * Common Development and Distribution License (the "License").
6*0e42dee6Sartem * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
22*0e42dee6Sartem * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23*0e42dee6Sartem * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
277c478bd9Sstevel@tonic-gate
287c478bd9Sstevel@tonic-gate /*
297c478bd9Sstevel@tonic-gate * Label a file system volume.
307c478bd9Sstevel@tonic-gate */
317c478bd9Sstevel@tonic-gate
327c478bd9Sstevel@tonic-gate
337c478bd9Sstevel@tonic-gate #include <stdio.h>
347c478bd9Sstevel@tonic-gate #include <string.h>
357c478bd9Sstevel@tonic-gate #include <strings.h>
367c478bd9Sstevel@tonic-gate #include <stdlib.h>
377c478bd9Sstevel@tonic-gate #include <unistd.h>
387c478bd9Sstevel@tonic-gate #include <fcntl.h>
397c478bd9Sstevel@tonic-gate #include <locale.h>
407c478bd9Sstevel@tonic-gate #include <errno.h>
417c478bd9Sstevel@tonic-gate #include <sys/fcntl.h>
427c478bd9Sstevel@tonic-gate #include <sys/param.h>
437c478bd9Sstevel@tonic-gate #include <sys/types.h>
447c478bd9Sstevel@tonic-gate #include <sys/mntent.h>
457c478bd9Sstevel@tonic-gate
467c478bd9Sstevel@tonic-gate #include <sys/fs/udf_volume.h>
477c478bd9Sstevel@tonic-gate #include "ud_lib.h"
487c478bd9Sstevel@tonic-gate
497c478bd9Sstevel@tonic-gate static uint8_t buf[MAXBSIZE];
507c478bd9Sstevel@tonic-gate static uint64_t off;
517c478bd9Sstevel@tonic-gate #define BUF_LEN 0x200
527c478bd9Sstevel@tonic-gate static int8_t lvinfo1_buf[BUF_LEN];
537c478bd9Sstevel@tonic-gate static int8_t lvinfo2_buf[BUF_LEN];
547c478bd9Sstevel@tonic-gate static int8_t lvinfo3_buf[BUF_LEN];
557c478bd9Sstevel@tonic-gate static int8_t fsname[BUF_LEN];
567c478bd9Sstevel@tonic-gate static int8_t volname[BUF_LEN];
577c478bd9Sstevel@tonic-gate static int32_t fsname_len;
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate #define SET_LVINFO1 0x01
607c478bd9Sstevel@tonic-gate #define SET_LVINFO2 0x02
617c478bd9Sstevel@tonic-gate #define SET_LVINFO3 0x04
627c478bd9Sstevel@tonic-gate #define SET_FSNAME 0x08
637c478bd9Sstevel@tonic-gate #define SET_VOLNAME 0x10
647c478bd9Sstevel@tonic-gate
657c478bd9Sstevel@tonic-gate typedef unsigned short unicode_t;
667c478bd9Sstevel@tonic-gate
677c478bd9Sstevel@tonic-gate #define FSNAME_STR_LEN (8 + 2)
687c478bd9Sstevel@tonic-gate #define VOLNAME_STR_LEN 32
697c478bd9Sstevel@tonic-gate #define INFO_STR_LEN 36
707c478bd9Sstevel@tonic-gate
717c478bd9Sstevel@tonic-gate static void usage();
72*0e42dee6Sartem static void label(ud_handle_t, uint32_t);
73*0e42dee6Sartem static void print_info(struct vds *, char *, ud_handle_t);
74*0e42dee6Sartem static void label_vds(struct vds *, uint32_t, ud_handle_t);
757c478bd9Sstevel@tonic-gate static int32_t convert_string(int8_t *, int8_t *, int32_t, int32_t, int8_t *);
767c478bd9Sstevel@tonic-gate static int32_t ud_convert2unicode(int8_t *, int8_t *, int32_t);
777c478bd9Sstevel@tonic-gate
787c478bd9Sstevel@tonic-gate
797c478bd9Sstevel@tonic-gate int8_t *labelit_subopts[] = {
807c478bd9Sstevel@tonic-gate #define LVINFO1 0x00
817c478bd9Sstevel@tonic-gate "lvinfo1",
827c478bd9Sstevel@tonic-gate #define LVINFO2 0x01
837c478bd9Sstevel@tonic-gate "lvinfo2",
847c478bd9Sstevel@tonic-gate #define LVINFO3 0x02
857c478bd9Sstevel@tonic-gate "lvinfo3",
867c478bd9Sstevel@tonic-gate NULL};
877c478bd9Sstevel@tonic-gate
887c478bd9Sstevel@tonic-gate
897c478bd9Sstevel@tonic-gate int
main(int32_t argc,char * argv[])907c478bd9Sstevel@tonic-gate main(int32_t argc, char *argv[])
917c478bd9Sstevel@tonic-gate {
927c478bd9Sstevel@tonic-gate int32_t opt = 0;
937c478bd9Sstevel@tonic-gate int32_t flags = 0;
947c478bd9Sstevel@tonic-gate int32_t ret = 0;
957c478bd9Sstevel@tonic-gate int8_t *options = NULL;
967c478bd9Sstevel@tonic-gate int8_t *value = NULL;
977c478bd9Sstevel@tonic-gate uint32_t set_flags = 0;
98*0e42dee6Sartem ud_handle_t udh;
997c478bd9Sstevel@tonic-gate
1007c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, "");
1017c478bd9Sstevel@tonic-gate
1027c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)
1037c478bd9Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST"
1047c478bd9Sstevel@tonic-gate #endif
1057c478bd9Sstevel@tonic-gate
1067c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN);
1077c478bd9Sstevel@tonic-gate
1087c478bd9Sstevel@tonic-gate
1097c478bd9Sstevel@tonic-gate while ((opt = getopt(argc, argv, "F:o:")) != EOF) {
1107c478bd9Sstevel@tonic-gate switch (opt) {
1117c478bd9Sstevel@tonic-gate case 'F':
1127c478bd9Sstevel@tonic-gate if (strcmp(optarg, "udfs") != 0) {
1137c478bd9Sstevel@tonic-gate usage();
1147c478bd9Sstevel@tonic-gate }
1157c478bd9Sstevel@tonic-gate break;
1167c478bd9Sstevel@tonic-gate
1177c478bd9Sstevel@tonic-gate case 'o':
1187c478bd9Sstevel@tonic-gate /*
1197c478bd9Sstevel@tonic-gate * UDFS specific options
1207c478bd9Sstevel@tonic-gate */
1217c478bd9Sstevel@tonic-gate options = optarg;
1227c478bd9Sstevel@tonic-gate while (*options != '\0') {
1237c478bd9Sstevel@tonic-gate switch (getsubopt(&options, labelit_subopts,
1247c478bd9Sstevel@tonic-gate &value)) {
1257c478bd9Sstevel@tonic-gate case LVINFO1 :
1267c478bd9Sstevel@tonic-gate set_flags |= SET_LVINFO1;
1277c478bd9Sstevel@tonic-gate (void) convert_string(value,
1287c478bd9Sstevel@tonic-gate lvinfo1_buf, BUF_LEN,
1297c478bd9Sstevel@tonic-gate INFO_STR_LEN,
1307c478bd9Sstevel@tonic-gate gettext("udfs labelit: lvinfo1 should be less than "
1317c478bd9Sstevel@tonic-gate "36 bytes after converting to compressed unicode "
1327c478bd9Sstevel@tonic-gate "dstring\n"));
1337c478bd9Sstevel@tonic-gate break;
1347c478bd9Sstevel@tonic-gate case LVINFO2 :
1357c478bd9Sstevel@tonic-gate set_flags |= SET_LVINFO2;
1367c478bd9Sstevel@tonic-gate (void) convert_string(value,
1377c478bd9Sstevel@tonic-gate lvinfo2_buf, BUF_LEN,
1387c478bd9Sstevel@tonic-gate INFO_STR_LEN,
1397c478bd9Sstevel@tonic-gate gettext("udfs labelit: lvinfo2 should be less than "
1407c478bd9Sstevel@tonic-gate "36 bytes after converting to compressed unicode "
1417c478bd9Sstevel@tonic-gate "dstring\n"));
1427c478bd9Sstevel@tonic-gate break;
1437c478bd9Sstevel@tonic-gate case LVINFO3 :
1447c478bd9Sstevel@tonic-gate set_flags |= SET_LVINFO3;
1457c478bd9Sstevel@tonic-gate (void) convert_string(value,
1467c478bd9Sstevel@tonic-gate lvinfo3_buf, BUF_LEN,
1477c478bd9Sstevel@tonic-gate INFO_STR_LEN,
1487c478bd9Sstevel@tonic-gate gettext("udfs labelit: lvinfo3 should be less than "
1497c478bd9Sstevel@tonic-gate "36 bytes after converting to compressed unicode "
1507c478bd9Sstevel@tonic-gate "dstring\n"));
1517c478bd9Sstevel@tonic-gate break;
1527c478bd9Sstevel@tonic-gate default:
1537c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
1547c478bd9Sstevel@tonic-gate gettext("udfs labelit: Unknown suboption %s\n"), value);
1557c478bd9Sstevel@tonic-gate usage();
1567c478bd9Sstevel@tonic-gate break;
1577c478bd9Sstevel@tonic-gate }
1587c478bd9Sstevel@tonic-gate }
1597c478bd9Sstevel@tonic-gate break;
1607c478bd9Sstevel@tonic-gate
1617c478bd9Sstevel@tonic-gate case '?':
1627c478bd9Sstevel@tonic-gate usage();
1637c478bd9Sstevel@tonic-gate }
1647c478bd9Sstevel@tonic-gate }
1657c478bd9Sstevel@tonic-gate
1667c478bd9Sstevel@tonic-gate if ((argc - optind) == 3) {
1677c478bd9Sstevel@tonic-gate
1687c478bd9Sstevel@tonic-gate /*
1697c478bd9Sstevel@tonic-gate * There are restrictions on the
1707c478bd9Sstevel@tonic-gate * length of the names
1717c478bd9Sstevel@tonic-gate * fsname is 8 characters
1727c478bd9Sstevel@tonic-gate * volume name is 32 characters
1737c478bd9Sstevel@tonic-gate * The extra byte is for compression id
1747c478bd9Sstevel@tonic-gate */
1757c478bd9Sstevel@tonic-gate fsname_len = convert_string(argv[optind + 1],
1767c478bd9Sstevel@tonic-gate fsname, BUF_LEN, FSNAME_STR_LEN,
1777c478bd9Sstevel@tonic-gate gettext("udfs labelit: fsname can not be longer than 8 characters\n"));
1787c478bd9Sstevel@tonic-gate
1797c478bd9Sstevel@tonic-gate (void) convert_string(argv[optind + 2],
1807c478bd9Sstevel@tonic-gate volname, BUF_LEN, VOLNAME_STR_LEN,
1817c478bd9Sstevel@tonic-gate gettext("udfs labelit: volname can not be longer "
1827c478bd9Sstevel@tonic-gate "than 32 bytes after converting to "
1837c478bd9Sstevel@tonic-gate "compressed unicode dstring\n"));
1847c478bd9Sstevel@tonic-gate set_flags |= SET_FSNAME | SET_VOLNAME;
1857c478bd9Sstevel@tonic-gate } else {
1867c478bd9Sstevel@tonic-gate if ((argc - optind) != 1) {
1877c478bd9Sstevel@tonic-gate usage();
1887c478bd9Sstevel@tonic-gate }
1897c478bd9Sstevel@tonic-gate }
1907c478bd9Sstevel@tonic-gate
191*0e42dee6Sartem if (ud_init(-1, &udh) != 0) {
192*0e42dee6Sartem (void) fprintf(stderr,
193*0e42dee6Sartem gettext("udfs labelit: cannot initialize ud_lib\n"));
194*0e42dee6Sartem exit(1);
195*0e42dee6Sartem }
196*0e42dee6Sartem
1977c478bd9Sstevel@tonic-gate /*
1987c478bd9Sstevel@tonic-gate * Open special device
1997c478bd9Sstevel@tonic-gate */
2007c478bd9Sstevel@tonic-gate if (set_flags == 0) {
2017c478bd9Sstevel@tonic-gate flags = O_RDONLY;
2027c478bd9Sstevel@tonic-gate } else {
2037c478bd9Sstevel@tonic-gate flags = O_RDWR;
2047c478bd9Sstevel@tonic-gate }
205*0e42dee6Sartem if (ud_open_dev(udh, argv[optind], flags) != 0) {
2067c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
2077c478bd9Sstevel@tonic-gate gettext("udfs labelit: cannot open <%s> errorno <%d>\n"),
2087c478bd9Sstevel@tonic-gate argv[optind], errno);
2097c478bd9Sstevel@tonic-gate exit(1);
2107c478bd9Sstevel@tonic-gate }
2117c478bd9Sstevel@tonic-gate
212*0e42dee6Sartem if ((ret = ud_fill_udfs_info(udh)) != 0) {
2137c478bd9Sstevel@tonic-gate goto close_dev;
2147c478bd9Sstevel@tonic-gate }
2157c478bd9Sstevel@tonic-gate
216*0e42dee6Sartem if ((udh->udfs.flags & VALID_UDFS) == 0) {
2177c478bd9Sstevel@tonic-gate ret = 1;
2187c478bd9Sstevel@tonic-gate goto close_dev;
2197c478bd9Sstevel@tonic-gate }
2207c478bd9Sstevel@tonic-gate
221*0e42dee6Sartem label(udh, set_flags);
2227c478bd9Sstevel@tonic-gate
2237c478bd9Sstevel@tonic-gate close_dev:
224*0e42dee6Sartem ud_close_dev(udh);
225*0e42dee6Sartem ud_fini(udh);
2267c478bd9Sstevel@tonic-gate
2277c478bd9Sstevel@tonic-gate return (ret);
2287c478bd9Sstevel@tonic-gate }
2297c478bd9Sstevel@tonic-gate
2307c478bd9Sstevel@tonic-gate static void
usage()2317c478bd9Sstevel@tonic-gate usage()
2327c478bd9Sstevel@tonic-gate {
2337c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(
2347c478bd9Sstevel@tonic-gate "udfs usage: labelit [-F udfs] [generic options] "
2357c478bd9Sstevel@tonic-gate "[ -o specific_options ] special [fsname volume]\n"));
2367c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(
2377c478bd9Sstevel@tonic-gate " -o : specific_options : [lvinfo1=string],"
2387c478bd9Sstevel@tonic-gate "[lvinfo2=string],[lvinfo3=string]\n"));
2397c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
2407c478bd9Sstevel@tonic-gate gettext("NOTE that all -o suboptions: must"
2417c478bd9Sstevel@tonic-gate " be separated only by commas.\n"));
2427c478bd9Sstevel@tonic-gate exit(1);
2437c478bd9Sstevel@tonic-gate }
2447c478bd9Sstevel@tonic-gate
2457c478bd9Sstevel@tonic-gate static void
label(ud_handle_t udh,uint32_t set_flags)246*0e42dee6Sartem label(ud_handle_t udh, uint32_t set_flags)
2477c478bd9Sstevel@tonic-gate {
2487c478bd9Sstevel@tonic-gate if (set_flags == 0) {
249*0e42dee6Sartem if (udh->udfs.flags & VALID_MVDS) {
250*0e42dee6Sartem print_info(&udh->udfs.mvds, "mvds", udh);
2517c478bd9Sstevel@tonic-gate }
252*0e42dee6Sartem if (udh->udfs.flags & VALID_RVDS) {
253*0e42dee6Sartem print_info(&udh->udfs.rvds, "rvds", udh);
2547c478bd9Sstevel@tonic-gate }
2557c478bd9Sstevel@tonic-gate return;
2567c478bd9Sstevel@tonic-gate } else {
2577c478bd9Sstevel@tonic-gate
258*0e42dee6Sartem if (udh->udfs.flags & VALID_MVDS) {
259*0e42dee6Sartem label_vds(&udh->udfs.mvds, set_flags, udh);
2607c478bd9Sstevel@tonic-gate }
261*0e42dee6Sartem if (udh->udfs.flags & VALID_RVDS) {
262*0e42dee6Sartem label_vds(&udh->udfs.rvds, set_flags, udh);
2637c478bd9Sstevel@tonic-gate }
2647c478bd9Sstevel@tonic-gate if (((set_flags & (SET_FSNAME | SET_VOLNAME)) ==
2657c478bd9Sstevel@tonic-gate (SET_FSNAME | SET_VOLNAME)) &&
266*0e42dee6Sartem (udh->udfs.fsd_len != 0)) {
2677c478bd9Sstevel@tonic-gate struct file_set_desc *fsd;
2687c478bd9Sstevel@tonic-gate
269*0e42dee6Sartem off = udh->udfs.fsd_loc * udh->udfs.lbsize;
270*0e42dee6Sartem if (ud_read_dev(udh, off, buf,
271*0e42dee6Sartem udh->udfs.fsd_len) != 0) {
2727c478bd9Sstevel@tonic-gate return;
2737c478bd9Sstevel@tonic-gate }
2747c478bd9Sstevel@tonic-gate
2757c478bd9Sstevel@tonic-gate /* LINTED */
2767c478bd9Sstevel@tonic-gate fsd = (struct file_set_desc *)buf;
2777c478bd9Sstevel@tonic-gate
2787c478bd9Sstevel@tonic-gate set_dstring(fsd->fsd_lvid,
2797c478bd9Sstevel@tonic-gate volname, sizeof (fsd->fsd_lvid));
2807c478bd9Sstevel@tonic-gate set_dstring(fsd->fsd_fsi,
2817c478bd9Sstevel@tonic-gate volname, sizeof (fsd->fsd_fsi));
2827c478bd9Sstevel@tonic-gate
283*0e42dee6Sartem ud_make_tag(udh, &fsd->fsd_tag, UD_FILE_SET_DESC,
2847c478bd9Sstevel@tonic-gate SWAP_32(fsd->fsd_tag.tag_loc),
2857c478bd9Sstevel@tonic-gate SWAP_16(fsd->fsd_tag.tag_crc_len));
2867c478bd9Sstevel@tonic-gate
287*0e42dee6Sartem (void) ud_write_dev(udh, off, buf, udh->udfs.fsd_len);
2887c478bd9Sstevel@tonic-gate }
2897c478bd9Sstevel@tonic-gate }
2907c478bd9Sstevel@tonic-gate }
2917c478bd9Sstevel@tonic-gate
2927c478bd9Sstevel@tonic-gate static void
print_info(struct vds * v,char * name,ud_handle_t udh)293*0e42dee6Sartem print_info(struct vds *v, char *name, ud_handle_t udh)
2947c478bd9Sstevel@tonic-gate {
2957c478bd9Sstevel@tonic-gate uint8_t outbuf[BUF_LEN];
2967c478bd9Sstevel@tonic-gate
2977c478bd9Sstevel@tonic-gate if (v->pvd_len != 0) {
298*0e42dee6Sartem off = v->pvd_loc * udh->udfs.lbsize;
299*0e42dee6Sartem if (ud_read_dev(udh, off, buf,
3007c478bd9Sstevel@tonic-gate sizeof (struct pri_vol_desc)) == 0) {
3017c478bd9Sstevel@tonic-gate
3027c478bd9Sstevel@tonic-gate struct pri_vol_desc *pvd;
3037c478bd9Sstevel@tonic-gate
3047c478bd9Sstevel@tonic-gate /* LINTED */
3057c478bd9Sstevel@tonic-gate pvd = (struct pri_vol_desc *)buf;
3067c478bd9Sstevel@tonic-gate
3077c478bd9Sstevel@tonic-gate bzero(outbuf, BUF_LEN);
3087c478bd9Sstevel@tonic-gate (void) ud_convert2local(
3097c478bd9Sstevel@tonic-gate (int8_t *)pvd->pvd_vsi,
3107c478bd9Sstevel@tonic-gate (int8_t *)outbuf, strlen(pvd->pvd_vsi));
3117c478bd9Sstevel@tonic-gate (void) fprintf(stdout,
3127c478bd9Sstevel@tonic-gate gettext("fsname in %s : %s\n"),
3137c478bd9Sstevel@tonic-gate name, outbuf);
3147c478bd9Sstevel@tonic-gate
3157c478bd9Sstevel@tonic-gate bzero(outbuf, BUF_LEN);
3167c478bd9Sstevel@tonic-gate pvd->pvd_vol_id[31] = '\0';
3177c478bd9Sstevel@tonic-gate (void) ud_convert2local(
3187c478bd9Sstevel@tonic-gate (int8_t *)pvd->pvd_vol_id,
3197c478bd9Sstevel@tonic-gate (int8_t *)outbuf,
3207c478bd9Sstevel@tonic-gate strlen(pvd->pvd_vol_id));
3217c478bd9Sstevel@tonic-gate (void) fprintf(stdout,
3227c478bd9Sstevel@tonic-gate gettext("volume label in %s : %s\n"),
3237c478bd9Sstevel@tonic-gate name, outbuf);
3247c478bd9Sstevel@tonic-gate }
3257c478bd9Sstevel@tonic-gate }
3267c478bd9Sstevel@tonic-gate
3277c478bd9Sstevel@tonic-gate if (v->iud_len != 0) {
328*0e42dee6Sartem off = v->iud_loc * udh->udfs.lbsize;
329*0e42dee6Sartem if (ud_read_dev(udh, off, buf,
3307c478bd9Sstevel@tonic-gate sizeof (struct iuvd_desc)) == 0) {
3317c478bd9Sstevel@tonic-gate
3327c478bd9Sstevel@tonic-gate struct iuvd_desc *iud;
3337c478bd9Sstevel@tonic-gate
3347c478bd9Sstevel@tonic-gate /* LINTED */
3357c478bd9Sstevel@tonic-gate iud = (struct iuvd_desc *)buf;
3367c478bd9Sstevel@tonic-gate bzero(outbuf, BUF_LEN);
3377c478bd9Sstevel@tonic-gate iud->iuvd_ifo1[35] = '\0';
3387c478bd9Sstevel@tonic-gate (void) ud_convert2local(
3397c478bd9Sstevel@tonic-gate (int8_t *)iud->iuvd_ifo1,
3407c478bd9Sstevel@tonic-gate (int8_t *)outbuf,
3417c478bd9Sstevel@tonic-gate strlen(iud->iuvd_ifo1));
3427c478bd9Sstevel@tonic-gate (void) fprintf(stdout,
3437c478bd9Sstevel@tonic-gate gettext("LVInfo1 in %s : %s\n"),
3447c478bd9Sstevel@tonic-gate name, outbuf);
3457c478bd9Sstevel@tonic-gate
3467c478bd9Sstevel@tonic-gate bzero(outbuf, BUF_LEN);
3477c478bd9Sstevel@tonic-gate iud->iuvd_ifo2[35] = '\0';
3487c478bd9Sstevel@tonic-gate (void) ud_convert2local(
3497c478bd9Sstevel@tonic-gate (int8_t *)iud->iuvd_ifo2,
3507c478bd9Sstevel@tonic-gate (int8_t *)outbuf,
3517c478bd9Sstevel@tonic-gate strlen(iud->iuvd_ifo2));
3527c478bd9Sstevel@tonic-gate (void) fprintf(stdout,
3537c478bd9Sstevel@tonic-gate gettext("LVInfo2 in %s : %s\n"),
3547c478bd9Sstevel@tonic-gate name, outbuf);
3557c478bd9Sstevel@tonic-gate
3567c478bd9Sstevel@tonic-gate bzero(outbuf, BUF_LEN);
3577c478bd9Sstevel@tonic-gate iud->iuvd_ifo3[35] = '\0';
3587c478bd9Sstevel@tonic-gate (void) ud_convert2local(
3597c478bd9Sstevel@tonic-gate (int8_t *)iud->iuvd_ifo3,
3607c478bd9Sstevel@tonic-gate (int8_t *)outbuf,
3617c478bd9Sstevel@tonic-gate strlen(iud->iuvd_ifo3));
3627c478bd9Sstevel@tonic-gate (void) fprintf(stdout,
3637c478bd9Sstevel@tonic-gate gettext("LVInfo3 in %s : %s\n"),
3647c478bd9Sstevel@tonic-gate name, outbuf);
3657c478bd9Sstevel@tonic-gate }
3667c478bd9Sstevel@tonic-gate }
3677c478bd9Sstevel@tonic-gate }
3687c478bd9Sstevel@tonic-gate
3697c478bd9Sstevel@tonic-gate /* ARGSUSED */
3707c478bd9Sstevel@tonic-gate static void
label_vds(struct vds * v,uint32_t set_flags,ud_handle_t udh)371*0e42dee6Sartem label_vds(struct vds *v, uint32_t set_flags, ud_handle_t udh)
3727c478bd9Sstevel@tonic-gate {
3737c478bd9Sstevel@tonic-gate
3747c478bd9Sstevel@tonic-gate if (((set_flags & (SET_FSNAME | SET_VOLNAME)) ==
3757c478bd9Sstevel@tonic-gate (SET_FSNAME | SET_VOLNAME)) &&
3767c478bd9Sstevel@tonic-gate (v->pvd_len)) {
3777c478bd9Sstevel@tonic-gate
378*0e42dee6Sartem off = v->pvd_loc * udh->udfs.lbsize;
379*0e42dee6Sartem if (ud_read_dev(udh, off, buf,
3807c478bd9Sstevel@tonic-gate sizeof (struct pri_vol_desc)) == 0) {
3817c478bd9Sstevel@tonic-gate
3827c478bd9Sstevel@tonic-gate struct pri_vol_desc *pvd;
3837c478bd9Sstevel@tonic-gate
3847c478bd9Sstevel@tonic-gate /* LINTED */
3857c478bd9Sstevel@tonic-gate pvd = (struct pri_vol_desc *)buf;
3867c478bd9Sstevel@tonic-gate bzero((int8_t *)&pvd->pvd_vsi[9], 119);
3877c478bd9Sstevel@tonic-gate (void) strncpy((int8_t *)&pvd->pvd_vsi[9],
3887c478bd9Sstevel@tonic-gate &fsname[1], fsname_len - 1);
3897c478bd9Sstevel@tonic-gate
3907c478bd9Sstevel@tonic-gate set_dstring(pvd->pvd_vol_id,
3917c478bd9Sstevel@tonic-gate volname, sizeof (pvd->pvd_vol_id));
3927c478bd9Sstevel@tonic-gate
393*0e42dee6Sartem ud_make_tag(udh, &pvd->pvd_tag,
3947c478bd9Sstevel@tonic-gate SWAP_16(pvd->pvd_tag.tag_id),
3957c478bd9Sstevel@tonic-gate SWAP_32(pvd->pvd_tag.tag_loc),
3967c478bd9Sstevel@tonic-gate SWAP_16(pvd->pvd_tag.tag_crc_len));
3977c478bd9Sstevel@tonic-gate
398*0e42dee6Sartem (void) ud_write_dev(udh, off, buf,
3997c478bd9Sstevel@tonic-gate sizeof (struct pri_vol_desc));
4007c478bd9Sstevel@tonic-gate }
4017c478bd9Sstevel@tonic-gate }
4027c478bd9Sstevel@tonic-gate
4037c478bd9Sstevel@tonic-gate if (set_flags && v->iud_len) {
4047c478bd9Sstevel@tonic-gate
405*0e42dee6Sartem off = v->iud_loc * udh->udfs.lbsize;
406*0e42dee6Sartem if (ud_read_dev(udh, off, buf,
4077c478bd9Sstevel@tonic-gate sizeof (struct iuvd_desc)) == 0) {
4087c478bd9Sstevel@tonic-gate
4097c478bd9Sstevel@tonic-gate struct iuvd_desc *iuvd;
4107c478bd9Sstevel@tonic-gate
4117c478bd9Sstevel@tonic-gate /* LINTED */
4127c478bd9Sstevel@tonic-gate iuvd = (struct iuvd_desc *)buf;
4137c478bd9Sstevel@tonic-gate
4147c478bd9Sstevel@tonic-gate if ((set_flags & SET_VOLNAME) == SET_VOLNAME) {
4157c478bd9Sstevel@tonic-gate set_dstring(iuvd->iuvd_lvi,
4167c478bd9Sstevel@tonic-gate volname, sizeof (iuvd->iuvd_lvi));
4177c478bd9Sstevel@tonic-gate }
4187c478bd9Sstevel@tonic-gate if ((set_flags & SET_LVINFO1) == SET_LVINFO1) {
4197c478bd9Sstevel@tonic-gate set_dstring(iuvd->iuvd_ifo1,
4207c478bd9Sstevel@tonic-gate lvinfo1_buf, sizeof (iuvd->iuvd_ifo1));
4217c478bd9Sstevel@tonic-gate }
4227c478bd9Sstevel@tonic-gate if ((set_flags & SET_LVINFO2) == SET_LVINFO2) {
4237c478bd9Sstevel@tonic-gate set_dstring(iuvd->iuvd_ifo2,
4247c478bd9Sstevel@tonic-gate lvinfo2_buf, sizeof (iuvd->iuvd_ifo2));
4257c478bd9Sstevel@tonic-gate }
4267c478bd9Sstevel@tonic-gate if ((set_flags & SET_LVINFO3) == SET_LVINFO3) {
4277c478bd9Sstevel@tonic-gate set_dstring(iuvd->iuvd_ifo3,
4287c478bd9Sstevel@tonic-gate lvinfo3_buf, sizeof (iuvd->iuvd_ifo3));
4297c478bd9Sstevel@tonic-gate }
4307c478bd9Sstevel@tonic-gate
431*0e42dee6Sartem ud_make_tag(udh, &iuvd->iuvd_tag,
4327c478bd9Sstevel@tonic-gate SWAP_16(iuvd->iuvd_tag.tag_id),
4337c478bd9Sstevel@tonic-gate SWAP_32(iuvd->iuvd_tag.tag_loc),
4347c478bd9Sstevel@tonic-gate SWAP_16(iuvd->iuvd_tag.tag_crc_len));
4357c478bd9Sstevel@tonic-gate
436*0e42dee6Sartem (void) ud_write_dev(udh, off, buf,
4377c478bd9Sstevel@tonic-gate sizeof (struct iuvd_desc));
4387c478bd9Sstevel@tonic-gate }
4397c478bd9Sstevel@tonic-gate }
4407c478bd9Sstevel@tonic-gate
4417c478bd9Sstevel@tonic-gate if (((set_flags & (SET_FSNAME | SET_VOLNAME)) ==
4427c478bd9Sstevel@tonic-gate (SET_FSNAME | SET_VOLNAME)) &&
4437c478bd9Sstevel@tonic-gate (v->lvd_len)) {
4447c478bd9Sstevel@tonic-gate
445*0e42dee6Sartem off = v->lvd_loc * udh->udfs.lbsize;
446*0e42dee6Sartem if (ud_read_dev(udh, off, buf,
4477c478bd9Sstevel@tonic-gate sizeof (struct log_vol_desc)) == 0) {
4487c478bd9Sstevel@tonic-gate
4497c478bd9Sstevel@tonic-gate struct log_vol_desc *lvd;
4507c478bd9Sstevel@tonic-gate
4517c478bd9Sstevel@tonic-gate /* LINTED */
4527c478bd9Sstevel@tonic-gate lvd = (struct log_vol_desc *)buf;
4537c478bd9Sstevel@tonic-gate set_dstring(lvd->lvd_lvid,
4547c478bd9Sstevel@tonic-gate volname, sizeof (lvd->lvd_lvid));
4557c478bd9Sstevel@tonic-gate
456*0e42dee6Sartem ud_make_tag(udh, &lvd->lvd_tag,
4577c478bd9Sstevel@tonic-gate SWAP_16(lvd->lvd_tag.tag_id),
4587c478bd9Sstevel@tonic-gate SWAP_32(lvd->lvd_tag.tag_loc),
4597c478bd9Sstevel@tonic-gate SWAP_16(lvd->lvd_tag.tag_crc_len));
4607c478bd9Sstevel@tonic-gate
461*0e42dee6Sartem (void) ud_write_dev(udh, off, buf,
4627c478bd9Sstevel@tonic-gate sizeof (struct log_vol_desc));
4637c478bd9Sstevel@tonic-gate }
4647c478bd9Sstevel@tonic-gate }
4657c478bd9Sstevel@tonic-gate }
4667c478bd9Sstevel@tonic-gate
4677c478bd9Sstevel@tonic-gate
4687c478bd9Sstevel@tonic-gate int32_t
convert_string(int8_t * value,int8_t * out_buf,int32_t out_len,int32_t len,int8_t * error_string)4697c478bd9Sstevel@tonic-gate convert_string(int8_t *value, int8_t *out_buf, int32_t out_len,
4707c478bd9Sstevel@tonic-gate int32_t len, int8_t *error_string)
4717c478bd9Sstevel@tonic-gate {
4727c478bd9Sstevel@tonic-gate int32_t out_length = 0;
4737c478bd9Sstevel@tonic-gate
4747c478bd9Sstevel@tonic-gate out_length = ud_convert2unicode(value, out_buf, out_len);
4757c478bd9Sstevel@tonic-gate if (out_length > len - 1) {
4767c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "%s", error_string);
4777c478bd9Sstevel@tonic-gate exit(1);
4787c478bd9Sstevel@tonic-gate }
4797c478bd9Sstevel@tonic-gate
4807c478bd9Sstevel@tonic-gate return (out_length);
4817c478bd9Sstevel@tonic-gate }
4827c478bd9Sstevel@tonic-gate
4837c478bd9Sstevel@tonic-gate static int32_t
ud_convert2unicode(int8_t * mb,int8_t * comp,int32_t out_len)4847c478bd9Sstevel@tonic-gate ud_convert2unicode(int8_t *mb, int8_t *comp, int32_t out_len)
4857c478bd9Sstevel@tonic-gate {
4867c478bd9Sstevel@tonic-gate wchar_t buf4c[128];
4877c478bd9Sstevel@tonic-gate int32_t len = 0;
4887c478bd9Sstevel@tonic-gate int32_t i = 0;
4897c478bd9Sstevel@tonic-gate int32_t j = 0;
4907c478bd9Sstevel@tonic-gate uint8_t c = 8;
4917c478bd9Sstevel@tonic-gate
4927c478bd9Sstevel@tonic-gate len = mbstowcs(buf4c, mb, 127);
4937c478bd9Sstevel@tonic-gate buf4c[127] = '\0';
4947c478bd9Sstevel@tonic-gate
4957c478bd9Sstevel@tonic-gate for (i = 0; i < len; i++) {
4967c478bd9Sstevel@tonic-gate if (buf4c[i] & 0xFFFFFF00) {
4977c478bd9Sstevel@tonic-gate c = 16;
4987c478bd9Sstevel@tonic-gate break;
4997c478bd9Sstevel@tonic-gate }
5007c478bd9Sstevel@tonic-gate }
5017c478bd9Sstevel@tonic-gate
5027c478bd9Sstevel@tonic-gate comp[0] = c;
5037c478bd9Sstevel@tonic-gate j = 1;
5047c478bd9Sstevel@tonic-gate for (i = 0; i < len && i < out_len; i++) {
5057c478bd9Sstevel@tonic-gate if (c == 16) {
5067c478bd9Sstevel@tonic-gate comp[j] = (buf4c[i] & 0xFF00) >> 8;
5077c478bd9Sstevel@tonic-gate }
5087c478bd9Sstevel@tonic-gate comp[j++] = buf4c[i] & 0xFF;
5097c478bd9Sstevel@tonic-gate }
5107c478bd9Sstevel@tonic-gate
5117c478bd9Sstevel@tonic-gate return (j);
5127c478bd9Sstevel@tonic-gate }
513