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
50e42dee6Sartem * Common Development and Distribution License (the "License").
60e42dee6Sartem * 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 /*
220e42dee6Sartem * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
230e42dee6Sartem * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate /*
277c478bd9Sstevel@tonic-gate * Label a file system volume.
287c478bd9Sstevel@tonic-gate */
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate
317c478bd9Sstevel@tonic-gate #include <stdio.h>
327c478bd9Sstevel@tonic-gate #include <string.h>
337c478bd9Sstevel@tonic-gate #include <strings.h>
347c478bd9Sstevel@tonic-gate #include <stdlib.h>
357c478bd9Sstevel@tonic-gate #include <unistd.h>
367c478bd9Sstevel@tonic-gate #include <fcntl.h>
377c478bd9Sstevel@tonic-gate #include <locale.h>
387c478bd9Sstevel@tonic-gate #include <errno.h>
397c478bd9Sstevel@tonic-gate #include <sys/fcntl.h>
407c478bd9Sstevel@tonic-gate #include <sys/param.h>
417c478bd9Sstevel@tonic-gate #include <sys/types.h>
427c478bd9Sstevel@tonic-gate #include <sys/mntent.h>
437c478bd9Sstevel@tonic-gate
447c478bd9Sstevel@tonic-gate #include <sys/fs/udf_volume.h>
457c478bd9Sstevel@tonic-gate #include "ud_lib.h"
467c478bd9Sstevel@tonic-gate
477c478bd9Sstevel@tonic-gate static uint8_t buf[MAXBSIZE];
487c478bd9Sstevel@tonic-gate static uint64_t off;
497c478bd9Sstevel@tonic-gate #define BUF_LEN 0x200
507c478bd9Sstevel@tonic-gate static int8_t lvinfo1_buf[BUF_LEN];
517c478bd9Sstevel@tonic-gate static int8_t lvinfo2_buf[BUF_LEN];
527c478bd9Sstevel@tonic-gate static int8_t lvinfo3_buf[BUF_LEN];
537c478bd9Sstevel@tonic-gate static int8_t fsname[BUF_LEN];
547c478bd9Sstevel@tonic-gate static int8_t volname[BUF_LEN];
557c478bd9Sstevel@tonic-gate static int32_t fsname_len;
567c478bd9Sstevel@tonic-gate
577c478bd9Sstevel@tonic-gate #define SET_LVINFO1 0x01
587c478bd9Sstevel@tonic-gate #define SET_LVINFO2 0x02
597c478bd9Sstevel@tonic-gate #define SET_LVINFO3 0x04
607c478bd9Sstevel@tonic-gate #define SET_FSNAME 0x08
617c478bd9Sstevel@tonic-gate #define SET_VOLNAME 0x10
627c478bd9Sstevel@tonic-gate
637c478bd9Sstevel@tonic-gate typedef unsigned short unicode_t;
647c478bd9Sstevel@tonic-gate
657c478bd9Sstevel@tonic-gate #define FSNAME_STR_LEN (8 + 2)
667c478bd9Sstevel@tonic-gate #define VOLNAME_STR_LEN 32
677c478bd9Sstevel@tonic-gate #define INFO_STR_LEN 36
687c478bd9Sstevel@tonic-gate
697c478bd9Sstevel@tonic-gate static void usage();
700e42dee6Sartem static void label(ud_handle_t, uint32_t);
710e42dee6Sartem static void print_info(struct vds *, char *, ud_handle_t);
720e42dee6Sartem static void label_vds(struct vds *, uint32_t, ud_handle_t);
737c478bd9Sstevel@tonic-gate static int32_t convert_string(int8_t *, int8_t *, int32_t, int32_t, int8_t *);
747c478bd9Sstevel@tonic-gate static int32_t ud_convert2unicode(int8_t *, int8_t *, int32_t);
757c478bd9Sstevel@tonic-gate
767c478bd9Sstevel@tonic-gate
777c478bd9Sstevel@tonic-gate int8_t *labelit_subopts[] = {
787c478bd9Sstevel@tonic-gate #define LVINFO1 0x00
797c478bd9Sstevel@tonic-gate "lvinfo1",
807c478bd9Sstevel@tonic-gate #define LVINFO2 0x01
817c478bd9Sstevel@tonic-gate "lvinfo2",
827c478bd9Sstevel@tonic-gate #define LVINFO3 0x02
837c478bd9Sstevel@tonic-gate "lvinfo3",
847c478bd9Sstevel@tonic-gate NULL};
857c478bd9Sstevel@tonic-gate
867c478bd9Sstevel@tonic-gate
877c478bd9Sstevel@tonic-gate int
main(int32_t argc,char * argv[])887c478bd9Sstevel@tonic-gate main(int32_t argc, char *argv[])
897c478bd9Sstevel@tonic-gate {
90*ef150c2bSRichard Lowe int opt = 0;
917c478bd9Sstevel@tonic-gate int32_t flags = 0;
927c478bd9Sstevel@tonic-gate int32_t ret = 0;
937c478bd9Sstevel@tonic-gate int8_t *options = NULL;
947c478bd9Sstevel@tonic-gate int8_t *value = NULL;
957c478bd9Sstevel@tonic-gate uint32_t set_flags = 0;
960e42dee6Sartem ud_handle_t udh;
977c478bd9Sstevel@tonic-gate
987c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, "");
997c478bd9Sstevel@tonic-gate
1007c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)
1017c478bd9Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST"
1027c478bd9Sstevel@tonic-gate #endif
1037c478bd9Sstevel@tonic-gate
1047c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN);
1057c478bd9Sstevel@tonic-gate
1067c478bd9Sstevel@tonic-gate
1077c478bd9Sstevel@tonic-gate while ((opt = getopt(argc, argv, "F:o:")) != EOF) {
1087c478bd9Sstevel@tonic-gate switch (opt) {
1097c478bd9Sstevel@tonic-gate case 'F':
1107c478bd9Sstevel@tonic-gate if (strcmp(optarg, "udfs") != 0) {
1117c478bd9Sstevel@tonic-gate usage();
1127c478bd9Sstevel@tonic-gate }
1137c478bd9Sstevel@tonic-gate break;
1147c478bd9Sstevel@tonic-gate
1157c478bd9Sstevel@tonic-gate case 'o':
1167c478bd9Sstevel@tonic-gate /*
1177c478bd9Sstevel@tonic-gate * UDFS specific options
1187c478bd9Sstevel@tonic-gate */
1197c478bd9Sstevel@tonic-gate options = optarg;
1207c478bd9Sstevel@tonic-gate while (*options != '\0') {
1217c478bd9Sstevel@tonic-gate switch (getsubopt(&options, labelit_subopts,
1227c478bd9Sstevel@tonic-gate &value)) {
1237c478bd9Sstevel@tonic-gate case LVINFO1 :
1247c478bd9Sstevel@tonic-gate set_flags |= SET_LVINFO1;
1257c478bd9Sstevel@tonic-gate (void) convert_string(value,
1267c478bd9Sstevel@tonic-gate lvinfo1_buf, BUF_LEN,
1277c478bd9Sstevel@tonic-gate INFO_STR_LEN,
1287c478bd9Sstevel@tonic-gate gettext("udfs labelit: lvinfo1 should be less than "
1297c478bd9Sstevel@tonic-gate "36 bytes after converting to compressed unicode "
1307c478bd9Sstevel@tonic-gate "dstring\n"));
1317c478bd9Sstevel@tonic-gate break;
1327c478bd9Sstevel@tonic-gate case LVINFO2 :
1337c478bd9Sstevel@tonic-gate set_flags |= SET_LVINFO2;
1347c478bd9Sstevel@tonic-gate (void) convert_string(value,
1357c478bd9Sstevel@tonic-gate lvinfo2_buf, BUF_LEN,
1367c478bd9Sstevel@tonic-gate INFO_STR_LEN,
1377c478bd9Sstevel@tonic-gate gettext("udfs labelit: lvinfo2 should be less than "
1387c478bd9Sstevel@tonic-gate "36 bytes after converting to compressed unicode "
1397c478bd9Sstevel@tonic-gate "dstring\n"));
1407c478bd9Sstevel@tonic-gate break;
1417c478bd9Sstevel@tonic-gate case LVINFO3 :
1427c478bd9Sstevel@tonic-gate set_flags |= SET_LVINFO3;
1437c478bd9Sstevel@tonic-gate (void) convert_string(value,
1447c478bd9Sstevel@tonic-gate lvinfo3_buf, BUF_LEN,
1457c478bd9Sstevel@tonic-gate INFO_STR_LEN,
1467c478bd9Sstevel@tonic-gate gettext("udfs labelit: lvinfo3 should be less than "
1477c478bd9Sstevel@tonic-gate "36 bytes after converting to compressed unicode "
1487c478bd9Sstevel@tonic-gate "dstring\n"));
1497c478bd9Sstevel@tonic-gate break;
1507c478bd9Sstevel@tonic-gate default:
1517c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
1527c478bd9Sstevel@tonic-gate gettext("udfs labelit: Unknown suboption %s\n"), value);
1537c478bd9Sstevel@tonic-gate usage();
1547c478bd9Sstevel@tonic-gate break;
1557c478bd9Sstevel@tonic-gate }
1567c478bd9Sstevel@tonic-gate }
1577c478bd9Sstevel@tonic-gate break;
1587c478bd9Sstevel@tonic-gate
1597c478bd9Sstevel@tonic-gate case '?':
1607c478bd9Sstevel@tonic-gate usage();
1617c478bd9Sstevel@tonic-gate }
1627c478bd9Sstevel@tonic-gate }
1637c478bd9Sstevel@tonic-gate
1647c478bd9Sstevel@tonic-gate if ((argc - optind) == 3) {
1657c478bd9Sstevel@tonic-gate
1667c478bd9Sstevel@tonic-gate /*
1677c478bd9Sstevel@tonic-gate * There are restrictions on the
1687c478bd9Sstevel@tonic-gate * length of the names
1697c478bd9Sstevel@tonic-gate * fsname is 8 characters
1707c478bd9Sstevel@tonic-gate * volume name is 32 characters
1717c478bd9Sstevel@tonic-gate * The extra byte is for compression id
1727c478bd9Sstevel@tonic-gate */
1737c478bd9Sstevel@tonic-gate fsname_len = convert_string(argv[optind + 1],
1747c478bd9Sstevel@tonic-gate fsname, BUF_LEN, FSNAME_STR_LEN,
1757c478bd9Sstevel@tonic-gate gettext("udfs labelit: fsname can not be longer than 8 characters\n"));
1767c478bd9Sstevel@tonic-gate
1777c478bd9Sstevel@tonic-gate (void) convert_string(argv[optind + 2],
1787c478bd9Sstevel@tonic-gate volname, BUF_LEN, VOLNAME_STR_LEN,
1797c478bd9Sstevel@tonic-gate gettext("udfs labelit: volname can not be longer "
1807c478bd9Sstevel@tonic-gate "than 32 bytes after converting to "
1817c478bd9Sstevel@tonic-gate "compressed unicode dstring\n"));
1827c478bd9Sstevel@tonic-gate set_flags |= SET_FSNAME | SET_VOLNAME;
1837c478bd9Sstevel@tonic-gate } else {
1847c478bd9Sstevel@tonic-gate if ((argc - optind) != 1) {
1857c478bd9Sstevel@tonic-gate usage();
1867c478bd9Sstevel@tonic-gate }
1877c478bd9Sstevel@tonic-gate }
1887c478bd9Sstevel@tonic-gate
1890e42dee6Sartem if (ud_init(-1, &udh) != 0) {
1900e42dee6Sartem (void) fprintf(stderr,
1910e42dee6Sartem gettext("udfs labelit: cannot initialize ud_lib\n"));
1920e42dee6Sartem exit(1);
1930e42dee6Sartem }
1940e42dee6Sartem
1957c478bd9Sstevel@tonic-gate /*
1967c478bd9Sstevel@tonic-gate * Open special device
1977c478bd9Sstevel@tonic-gate */
1987c478bd9Sstevel@tonic-gate if (set_flags == 0) {
1997c478bd9Sstevel@tonic-gate flags = O_RDONLY;
2007c478bd9Sstevel@tonic-gate } else {
2017c478bd9Sstevel@tonic-gate flags = O_RDWR;
2027c478bd9Sstevel@tonic-gate }
2030e42dee6Sartem if (ud_open_dev(udh, argv[optind], flags) != 0) {
2047c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
2057c478bd9Sstevel@tonic-gate gettext("udfs labelit: cannot open <%s> errorno <%d>\n"),
2067c478bd9Sstevel@tonic-gate argv[optind], errno);
2077c478bd9Sstevel@tonic-gate exit(1);
2087c478bd9Sstevel@tonic-gate }
2097c478bd9Sstevel@tonic-gate
2100e42dee6Sartem if ((ret = ud_fill_udfs_info(udh)) != 0) {
2117c478bd9Sstevel@tonic-gate goto close_dev;
2127c478bd9Sstevel@tonic-gate }
2137c478bd9Sstevel@tonic-gate
2140e42dee6Sartem if ((udh->udfs.flags & VALID_UDFS) == 0) {
2157c478bd9Sstevel@tonic-gate ret = 1;
2167c478bd9Sstevel@tonic-gate goto close_dev;
2177c478bd9Sstevel@tonic-gate }
2187c478bd9Sstevel@tonic-gate
2190e42dee6Sartem label(udh, set_flags);
2207c478bd9Sstevel@tonic-gate
2217c478bd9Sstevel@tonic-gate close_dev:
2220e42dee6Sartem ud_close_dev(udh);
2230e42dee6Sartem ud_fini(udh);
2247c478bd9Sstevel@tonic-gate
2257c478bd9Sstevel@tonic-gate return (ret);
2267c478bd9Sstevel@tonic-gate }
2277c478bd9Sstevel@tonic-gate
2287c478bd9Sstevel@tonic-gate static void
usage()2297c478bd9Sstevel@tonic-gate usage()
2307c478bd9Sstevel@tonic-gate {
2317c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(
2327c478bd9Sstevel@tonic-gate "udfs usage: labelit [-F udfs] [generic options] "
2337c478bd9Sstevel@tonic-gate "[ -o specific_options ] special [fsname volume]\n"));
2347c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(
2357c478bd9Sstevel@tonic-gate " -o : specific_options : [lvinfo1=string],"
2367c478bd9Sstevel@tonic-gate "[lvinfo2=string],[lvinfo3=string]\n"));
2377c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
2387c478bd9Sstevel@tonic-gate gettext("NOTE that all -o suboptions: must"
2397c478bd9Sstevel@tonic-gate " be separated only by commas.\n"));
2407c478bd9Sstevel@tonic-gate exit(1);
2417c478bd9Sstevel@tonic-gate }
2427c478bd9Sstevel@tonic-gate
2437c478bd9Sstevel@tonic-gate static void
label(ud_handle_t udh,uint32_t set_flags)2440e42dee6Sartem label(ud_handle_t udh, uint32_t set_flags)
2457c478bd9Sstevel@tonic-gate {
2467c478bd9Sstevel@tonic-gate if (set_flags == 0) {
2470e42dee6Sartem if (udh->udfs.flags & VALID_MVDS) {
2480e42dee6Sartem print_info(&udh->udfs.mvds, "mvds", udh);
2497c478bd9Sstevel@tonic-gate }
2500e42dee6Sartem if (udh->udfs.flags & VALID_RVDS) {
2510e42dee6Sartem print_info(&udh->udfs.rvds, "rvds", udh);
2527c478bd9Sstevel@tonic-gate }
2537c478bd9Sstevel@tonic-gate return;
2547c478bd9Sstevel@tonic-gate } else {
2557c478bd9Sstevel@tonic-gate
2560e42dee6Sartem if (udh->udfs.flags & VALID_MVDS) {
2570e42dee6Sartem label_vds(&udh->udfs.mvds, set_flags, udh);
2587c478bd9Sstevel@tonic-gate }
2590e42dee6Sartem if (udh->udfs.flags & VALID_RVDS) {
2600e42dee6Sartem label_vds(&udh->udfs.rvds, set_flags, udh);
2617c478bd9Sstevel@tonic-gate }
2627c478bd9Sstevel@tonic-gate if (((set_flags & (SET_FSNAME | SET_VOLNAME)) ==
2637c478bd9Sstevel@tonic-gate (SET_FSNAME | SET_VOLNAME)) &&
2640e42dee6Sartem (udh->udfs.fsd_len != 0)) {
2657c478bd9Sstevel@tonic-gate struct file_set_desc *fsd;
2667c478bd9Sstevel@tonic-gate
2670e42dee6Sartem off = udh->udfs.fsd_loc * udh->udfs.lbsize;
2680e42dee6Sartem if (ud_read_dev(udh, off, buf,
2690e42dee6Sartem udh->udfs.fsd_len) != 0) {
2707c478bd9Sstevel@tonic-gate return;
2717c478bd9Sstevel@tonic-gate }
2727c478bd9Sstevel@tonic-gate
2737c478bd9Sstevel@tonic-gate /* LINTED */
2747c478bd9Sstevel@tonic-gate fsd = (struct file_set_desc *)buf;
2757c478bd9Sstevel@tonic-gate
2767c478bd9Sstevel@tonic-gate set_dstring(fsd->fsd_lvid,
2777c478bd9Sstevel@tonic-gate volname, sizeof (fsd->fsd_lvid));
2787c478bd9Sstevel@tonic-gate set_dstring(fsd->fsd_fsi,
2797c478bd9Sstevel@tonic-gate volname, sizeof (fsd->fsd_fsi));
2807c478bd9Sstevel@tonic-gate
2810e42dee6Sartem ud_make_tag(udh, &fsd->fsd_tag, UD_FILE_SET_DESC,
2827c478bd9Sstevel@tonic-gate SWAP_32(fsd->fsd_tag.tag_loc),
2837c478bd9Sstevel@tonic-gate SWAP_16(fsd->fsd_tag.tag_crc_len));
2847c478bd9Sstevel@tonic-gate
2850e42dee6Sartem (void) ud_write_dev(udh, off, buf, udh->udfs.fsd_len);
2867c478bd9Sstevel@tonic-gate }
2877c478bd9Sstevel@tonic-gate }
2887c478bd9Sstevel@tonic-gate }
2897c478bd9Sstevel@tonic-gate
2907c478bd9Sstevel@tonic-gate static void
print_info(struct vds * v,char * name,ud_handle_t udh)2910e42dee6Sartem print_info(struct vds *v, char *name, ud_handle_t udh)
2927c478bd9Sstevel@tonic-gate {
2937c478bd9Sstevel@tonic-gate uint8_t outbuf[BUF_LEN];
2947c478bd9Sstevel@tonic-gate
2957c478bd9Sstevel@tonic-gate if (v->pvd_len != 0) {
2960e42dee6Sartem off = v->pvd_loc * udh->udfs.lbsize;
2970e42dee6Sartem if (ud_read_dev(udh, off, buf,
2987c478bd9Sstevel@tonic-gate sizeof (struct pri_vol_desc)) == 0) {
2997c478bd9Sstevel@tonic-gate
3007c478bd9Sstevel@tonic-gate struct pri_vol_desc *pvd;
3017c478bd9Sstevel@tonic-gate
3027c478bd9Sstevel@tonic-gate /* LINTED */
3037c478bd9Sstevel@tonic-gate pvd = (struct pri_vol_desc *)buf;
3047c478bd9Sstevel@tonic-gate
3057c478bd9Sstevel@tonic-gate bzero(outbuf, BUF_LEN);
3067c478bd9Sstevel@tonic-gate (void) ud_convert2local(
3077c478bd9Sstevel@tonic-gate (int8_t *)pvd->pvd_vsi,
3087c478bd9Sstevel@tonic-gate (int8_t *)outbuf, strlen(pvd->pvd_vsi));
3097c478bd9Sstevel@tonic-gate (void) fprintf(stdout,
3107c478bd9Sstevel@tonic-gate gettext("fsname in %s : %s\n"),
3117c478bd9Sstevel@tonic-gate name, outbuf);
3127c478bd9Sstevel@tonic-gate
3137c478bd9Sstevel@tonic-gate bzero(outbuf, BUF_LEN);
3147c478bd9Sstevel@tonic-gate pvd->pvd_vol_id[31] = '\0';
3157c478bd9Sstevel@tonic-gate (void) ud_convert2local(
3167c478bd9Sstevel@tonic-gate (int8_t *)pvd->pvd_vol_id,
3177c478bd9Sstevel@tonic-gate (int8_t *)outbuf,
3187c478bd9Sstevel@tonic-gate strlen(pvd->pvd_vol_id));
3197c478bd9Sstevel@tonic-gate (void) fprintf(stdout,
3207c478bd9Sstevel@tonic-gate gettext("volume label in %s : %s\n"),
3217c478bd9Sstevel@tonic-gate name, outbuf);
3227c478bd9Sstevel@tonic-gate }
3237c478bd9Sstevel@tonic-gate }
3247c478bd9Sstevel@tonic-gate
3257c478bd9Sstevel@tonic-gate if (v->iud_len != 0) {
3260e42dee6Sartem off = v->iud_loc * udh->udfs.lbsize;
3270e42dee6Sartem if (ud_read_dev(udh, off, buf,
3287c478bd9Sstevel@tonic-gate sizeof (struct iuvd_desc)) == 0) {
3297c478bd9Sstevel@tonic-gate
3307c478bd9Sstevel@tonic-gate struct iuvd_desc *iud;
3317c478bd9Sstevel@tonic-gate
3327c478bd9Sstevel@tonic-gate /* LINTED */
3337c478bd9Sstevel@tonic-gate iud = (struct iuvd_desc *)buf;
3347c478bd9Sstevel@tonic-gate bzero(outbuf, BUF_LEN);
3357c478bd9Sstevel@tonic-gate iud->iuvd_ifo1[35] = '\0';
3367c478bd9Sstevel@tonic-gate (void) ud_convert2local(
3377c478bd9Sstevel@tonic-gate (int8_t *)iud->iuvd_ifo1,
3387c478bd9Sstevel@tonic-gate (int8_t *)outbuf,
3397c478bd9Sstevel@tonic-gate strlen(iud->iuvd_ifo1));
3407c478bd9Sstevel@tonic-gate (void) fprintf(stdout,
3417c478bd9Sstevel@tonic-gate gettext("LVInfo1 in %s : %s\n"),
3427c478bd9Sstevel@tonic-gate name, outbuf);
3437c478bd9Sstevel@tonic-gate
3447c478bd9Sstevel@tonic-gate bzero(outbuf, BUF_LEN);
3457c478bd9Sstevel@tonic-gate iud->iuvd_ifo2[35] = '\0';
3467c478bd9Sstevel@tonic-gate (void) ud_convert2local(
3477c478bd9Sstevel@tonic-gate (int8_t *)iud->iuvd_ifo2,
3487c478bd9Sstevel@tonic-gate (int8_t *)outbuf,
3497c478bd9Sstevel@tonic-gate strlen(iud->iuvd_ifo2));
3507c478bd9Sstevel@tonic-gate (void) fprintf(stdout,
3517c478bd9Sstevel@tonic-gate gettext("LVInfo2 in %s : %s\n"),
3527c478bd9Sstevel@tonic-gate name, outbuf);
3537c478bd9Sstevel@tonic-gate
3547c478bd9Sstevel@tonic-gate bzero(outbuf, BUF_LEN);
3557c478bd9Sstevel@tonic-gate iud->iuvd_ifo3[35] = '\0';
3567c478bd9Sstevel@tonic-gate (void) ud_convert2local(
3577c478bd9Sstevel@tonic-gate (int8_t *)iud->iuvd_ifo3,
3587c478bd9Sstevel@tonic-gate (int8_t *)outbuf,
3597c478bd9Sstevel@tonic-gate strlen(iud->iuvd_ifo3));
3607c478bd9Sstevel@tonic-gate (void) fprintf(stdout,
3617c478bd9Sstevel@tonic-gate gettext("LVInfo3 in %s : %s\n"),
3627c478bd9Sstevel@tonic-gate name, outbuf);
3637c478bd9Sstevel@tonic-gate }
3647c478bd9Sstevel@tonic-gate }
3657c478bd9Sstevel@tonic-gate }
3667c478bd9Sstevel@tonic-gate
3677c478bd9Sstevel@tonic-gate /* ARGSUSED */
3687c478bd9Sstevel@tonic-gate static void
label_vds(struct vds * v,uint32_t set_flags,ud_handle_t udh)3690e42dee6Sartem label_vds(struct vds *v, uint32_t set_flags, ud_handle_t udh)
3707c478bd9Sstevel@tonic-gate {
3717c478bd9Sstevel@tonic-gate
3727c478bd9Sstevel@tonic-gate if (((set_flags & (SET_FSNAME | SET_VOLNAME)) ==
3737c478bd9Sstevel@tonic-gate (SET_FSNAME | SET_VOLNAME)) &&
3747c478bd9Sstevel@tonic-gate (v->pvd_len)) {
3757c478bd9Sstevel@tonic-gate
3760e42dee6Sartem off = v->pvd_loc * udh->udfs.lbsize;
3770e42dee6Sartem if (ud_read_dev(udh, off, buf,
3787c478bd9Sstevel@tonic-gate sizeof (struct pri_vol_desc)) == 0) {
3797c478bd9Sstevel@tonic-gate
3807c478bd9Sstevel@tonic-gate struct pri_vol_desc *pvd;
3817c478bd9Sstevel@tonic-gate
3827c478bd9Sstevel@tonic-gate /* LINTED */
3837c478bd9Sstevel@tonic-gate pvd = (struct pri_vol_desc *)buf;
3847c478bd9Sstevel@tonic-gate bzero((int8_t *)&pvd->pvd_vsi[9], 119);
3857c478bd9Sstevel@tonic-gate (void) strncpy((int8_t *)&pvd->pvd_vsi[9],
3867c478bd9Sstevel@tonic-gate &fsname[1], fsname_len - 1);
3877c478bd9Sstevel@tonic-gate
3887c478bd9Sstevel@tonic-gate set_dstring(pvd->pvd_vol_id,
3897c478bd9Sstevel@tonic-gate volname, sizeof (pvd->pvd_vol_id));
3907c478bd9Sstevel@tonic-gate
3910e42dee6Sartem ud_make_tag(udh, &pvd->pvd_tag,
3927c478bd9Sstevel@tonic-gate SWAP_16(pvd->pvd_tag.tag_id),
3937c478bd9Sstevel@tonic-gate SWAP_32(pvd->pvd_tag.tag_loc),
3947c478bd9Sstevel@tonic-gate SWAP_16(pvd->pvd_tag.tag_crc_len));
3957c478bd9Sstevel@tonic-gate
3960e42dee6Sartem (void) ud_write_dev(udh, off, buf,
3977c478bd9Sstevel@tonic-gate sizeof (struct pri_vol_desc));
3987c478bd9Sstevel@tonic-gate }
3997c478bd9Sstevel@tonic-gate }
4007c478bd9Sstevel@tonic-gate
4017c478bd9Sstevel@tonic-gate if (set_flags && v->iud_len) {
4027c478bd9Sstevel@tonic-gate
4030e42dee6Sartem off = v->iud_loc * udh->udfs.lbsize;
4040e42dee6Sartem if (ud_read_dev(udh, off, buf,
4057c478bd9Sstevel@tonic-gate sizeof (struct iuvd_desc)) == 0) {
4067c478bd9Sstevel@tonic-gate
4077c478bd9Sstevel@tonic-gate struct iuvd_desc *iuvd;
4087c478bd9Sstevel@tonic-gate
4097c478bd9Sstevel@tonic-gate /* LINTED */
4107c478bd9Sstevel@tonic-gate iuvd = (struct iuvd_desc *)buf;
4117c478bd9Sstevel@tonic-gate
4127c478bd9Sstevel@tonic-gate if ((set_flags & SET_VOLNAME) == SET_VOLNAME) {
4137c478bd9Sstevel@tonic-gate set_dstring(iuvd->iuvd_lvi,
4147c478bd9Sstevel@tonic-gate volname, sizeof (iuvd->iuvd_lvi));
4157c478bd9Sstevel@tonic-gate }
4167c478bd9Sstevel@tonic-gate if ((set_flags & SET_LVINFO1) == SET_LVINFO1) {
4177c478bd9Sstevel@tonic-gate set_dstring(iuvd->iuvd_ifo1,
4187c478bd9Sstevel@tonic-gate lvinfo1_buf, sizeof (iuvd->iuvd_ifo1));
4197c478bd9Sstevel@tonic-gate }
4207c478bd9Sstevel@tonic-gate if ((set_flags & SET_LVINFO2) == SET_LVINFO2) {
4217c478bd9Sstevel@tonic-gate set_dstring(iuvd->iuvd_ifo2,
4227c478bd9Sstevel@tonic-gate lvinfo2_buf, sizeof (iuvd->iuvd_ifo2));
4237c478bd9Sstevel@tonic-gate }
4247c478bd9Sstevel@tonic-gate if ((set_flags & SET_LVINFO3) == SET_LVINFO3) {
4257c478bd9Sstevel@tonic-gate set_dstring(iuvd->iuvd_ifo3,
4267c478bd9Sstevel@tonic-gate lvinfo3_buf, sizeof (iuvd->iuvd_ifo3));
4277c478bd9Sstevel@tonic-gate }
4287c478bd9Sstevel@tonic-gate
4290e42dee6Sartem ud_make_tag(udh, &iuvd->iuvd_tag,
4307c478bd9Sstevel@tonic-gate SWAP_16(iuvd->iuvd_tag.tag_id),
4317c478bd9Sstevel@tonic-gate SWAP_32(iuvd->iuvd_tag.tag_loc),
4327c478bd9Sstevel@tonic-gate SWAP_16(iuvd->iuvd_tag.tag_crc_len));
4337c478bd9Sstevel@tonic-gate
4340e42dee6Sartem (void) ud_write_dev(udh, off, buf,
4357c478bd9Sstevel@tonic-gate sizeof (struct iuvd_desc));
4367c478bd9Sstevel@tonic-gate }
4377c478bd9Sstevel@tonic-gate }
4387c478bd9Sstevel@tonic-gate
4397c478bd9Sstevel@tonic-gate if (((set_flags & (SET_FSNAME | SET_VOLNAME)) ==
4407c478bd9Sstevel@tonic-gate (SET_FSNAME | SET_VOLNAME)) &&
4417c478bd9Sstevel@tonic-gate (v->lvd_len)) {
4427c478bd9Sstevel@tonic-gate
4430e42dee6Sartem off = v->lvd_loc * udh->udfs.lbsize;
4440e42dee6Sartem if (ud_read_dev(udh, off, buf,
4457c478bd9Sstevel@tonic-gate sizeof (struct log_vol_desc)) == 0) {
4467c478bd9Sstevel@tonic-gate
4477c478bd9Sstevel@tonic-gate struct log_vol_desc *lvd;
4487c478bd9Sstevel@tonic-gate
4497c478bd9Sstevel@tonic-gate /* LINTED */
4507c478bd9Sstevel@tonic-gate lvd = (struct log_vol_desc *)buf;
4517c478bd9Sstevel@tonic-gate set_dstring(lvd->lvd_lvid,
4527c478bd9Sstevel@tonic-gate volname, sizeof (lvd->lvd_lvid));
4537c478bd9Sstevel@tonic-gate
4540e42dee6Sartem ud_make_tag(udh, &lvd->lvd_tag,
4557c478bd9Sstevel@tonic-gate SWAP_16(lvd->lvd_tag.tag_id),
4567c478bd9Sstevel@tonic-gate SWAP_32(lvd->lvd_tag.tag_loc),
4577c478bd9Sstevel@tonic-gate SWAP_16(lvd->lvd_tag.tag_crc_len));
4587c478bd9Sstevel@tonic-gate
4590e42dee6Sartem (void) ud_write_dev(udh, off, buf,
4607c478bd9Sstevel@tonic-gate sizeof (struct log_vol_desc));
4617c478bd9Sstevel@tonic-gate }
4627c478bd9Sstevel@tonic-gate }
4637c478bd9Sstevel@tonic-gate }
4647c478bd9Sstevel@tonic-gate
4657c478bd9Sstevel@tonic-gate
4667c478bd9Sstevel@tonic-gate int32_t
convert_string(int8_t * value,int8_t * out_buf,int32_t out_len,int32_t len,int8_t * error_string)4677c478bd9Sstevel@tonic-gate convert_string(int8_t *value, int8_t *out_buf, int32_t out_len,
4687c478bd9Sstevel@tonic-gate int32_t len, int8_t *error_string)
4697c478bd9Sstevel@tonic-gate {
4707c478bd9Sstevel@tonic-gate int32_t out_length = 0;
4717c478bd9Sstevel@tonic-gate
4727c478bd9Sstevel@tonic-gate out_length = ud_convert2unicode(value, out_buf, out_len);
4737c478bd9Sstevel@tonic-gate if (out_length > len - 1) {
4747c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "%s", error_string);
4757c478bd9Sstevel@tonic-gate exit(1);
4767c478bd9Sstevel@tonic-gate }
4777c478bd9Sstevel@tonic-gate
4787c478bd9Sstevel@tonic-gate return (out_length);
4797c478bd9Sstevel@tonic-gate }
4807c478bd9Sstevel@tonic-gate
4817c478bd9Sstevel@tonic-gate static int32_t
ud_convert2unicode(int8_t * mb,int8_t * comp,int32_t out_len)4827c478bd9Sstevel@tonic-gate ud_convert2unicode(int8_t *mb, int8_t *comp, int32_t out_len)
4837c478bd9Sstevel@tonic-gate {
4847c478bd9Sstevel@tonic-gate wchar_t buf4c[128];
4857c478bd9Sstevel@tonic-gate int32_t len = 0;
4867c478bd9Sstevel@tonic-gate int32_t i = 0;
4877c478bd9Sstevel@tonic-gate int32_t j = 0;
4887c478bd9Sstevel@tonic-gate uint8_t c = 8;
4897c478bd9Sstevel@tonic-gate
4907c478bd9Sstevel@tonic-gate len = mbstowcs(buf4c, mb, 127);
4917c478bd9Sstevel@tonic-gate buf4c[127] = '\0';
4927c478bd9Sstevel@tonic-gate
4937c478bd9Sstevel@tonic-gate for (i = 0; i < len; i++) {
4947c478bd9Sstevel@tonic-gate if (buf4c[i] & 0xFFFFFF00) {
4957c478bd9Sstevel@tonic-gate c = 16;
4967c478bd9Sstevel@tonic-gate break;
4977c478bd9Sstevel@tonic-gate }
4987c478bd9Sstevel@tonic-gate }
4997c478bd9Sstevel@tonic-gate
5007c478bd9Sstevel@tonic-gate comp[0] = c;
5017c478bd9Sstevel@tonic-gate j = 1;
5027c478bd9Sstevel@tonic-gate for (i = 0; i < len && i < out_len; i++) {
5037c478bd9Sstevel@tonic-gate if (c == 16) {
5047c478bd9Sstevel@tonic-gate comp[j] = (buf4c[i] & 0xFF00) >> 8;
5057c478bd9Sstevel@tonic-gate }
5067c478bd9Sstevel@tonic-gate comp[j++] = buf4c[i] & 0xFF;
5077c478bd9Sstevel@tonic-gate }
5087c478bd9Sstevel@tonic-gate
5097c478bd9Sstevel@tonic-gate return (j);
5107c478bd9Sstevel@tonic-gate }
511