xref: /titanic_51/usr/src/cmd/fs.d/hsfs/labelit/labelit.c (revision 0c79d02b29618f74322989ec8ceafaa5486ac1db)
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
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
23c719c59aSjkennedy  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24c719c59aSjkennedy  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
26c719c59aSjkennedy 
277c478bd9Sstevel@tonic-gate /*
287c478bd9Sstevel@tonic-gate  * labelit [option=value ...] cdimage
297c478bd9Sstevel@tonic-gate  * where options are:
30c719c59aSjkennedy  *      sysid		system identifier               (a characters, 32 max)
31c719c59aSjkennedy  *      volid:          volume identifier               (d-characters, 32 max)
32c719c59aSjkennedy  *      volsetid:       volume set identifier           (d-characters, 128 max)
33c719c59aSjkennedy  *      pubid:          publisher identifier            (d-characters, 128 max)
34c719c59aSjkennedy  *      prepid:         data preparer identifier        (d-charcter, 128 max)
35c719c59aSjkennedy  *      applid:         application identifier          (d-charcter, 128 max)
36c719c59aSjkennedy  *      copyfile:       copyright file identifier       (d-characters, 128 max)
37c719c59aSjkennedy  *      absfile:        abstract file identifier        (d-characters, 37 max)
38c719c59aSjkennedy  *      bibfile:        bibliographic file identifier   (d-charcters, 37 max)
397c478bd9Sstevel@tonic-gate  */
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #include <fcntl.h>
427c478bd9Sstevel@tonic-gate #include <stdio.h>
437c478bd9Sstevel@tonic-gate #include <sys/param.h>
447c478bd9Sstevel@tonic-gate #include <sys/stat.h>
457c478bd9Sstevel@tonic-gate #include <sys/time.h>
467c478bd9Sstevel@tonic-gate #include <sys/types.h>
477c478bd9Sstevel@tonic-gate #include <sys/file.h>
487c478bd9Sstevel@tonic-gate #include <dirent.h>
49*0c79d02bSRichard Lowe 
50*0c79d02bSRichard Lowe #include <sys/fs/hsfs_isospec.h>
51*0c79d02bSRichard Lowe #include <sys/fs/hsfs_spec.h>
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate #define	PUTSECTOR(buf, secno, nosec) (putdisk(buf, (secno)*ISO_SECTOR_SIZE, \
547c478bd9Sstevel@tonic-gate 	(nosec)*ISO_SECTOR_SIZE))
557c478bd9Sstevel@tonic-gate #define	GETSECTOR(buf, secno, nosec) (getdisk(buf, (secno)*ISO_SECTOR_SIZE, \
567c478bd9Sstevel@tonic-gate 	(nosec)*ISO_SECTOR_SIZE))
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate char *string;
597c478bd9Sstevel@tonic-gate #define	MAXERRSTRNG	80
607c478bd9Sstevel@tonic-gate char	errstrng[MAXERRSTRNG];
617c478bd9Sstevel@tonic-gate char	callname[160];
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate int  cdfd;
647c478bd9Sstevel@tonic-gate int cd_type;
657c478bd9Sstevel@tonic-gate char hs_buf[ISO_SECTOR_SIZE];
667c478bd9Sstevel@tonic-gate int  hs_pvd_sec_no;
677c478bd9Sstevel@tonic-gate char iso_buf[ISO_SECTOR_SIZE];
687c478bd9Sstevel@tonic-gate int  iso_pvd_sec_no;
697c478bd9Sstevel@tonic-gate char unix_buf[ISO_SECTOR_SIZE];
707c478bd9Sstevel@tonic-gate int  unix_pvd_sec_no;
717c478bd9Sstevel@tonic-gate char *vdp;
727c478bd9Sstevel@tonic-gate char *sysid;
737c478bd9Sstevel@tonic-gate char *volid;
747c478bd9Sstevel@tonic-gate char *volsetid;
757c478bd9Sstevel@tonic-gate char *pubid;
767c478bd9Sstevel@tonic-gate char *prepid;
777c478bd9Sstevel@tonic-gate char *applid;
787c478bd9Sstevel@tonic-gate char *copyfile;
797c478bd9Sstevel@tonic-gate char *absfile;
807c478bd9Sstevel@tonic-gate char *bibfile;
817c478bd9Sstevel@tonic-gate int volsetsize;
827c478bd9Sstevel@tonic-gate int volsetseq;
837c478bd9Sstevel@tonic-gate int blksize;
847c478bd9Sstevel@tonic-gate int volsize;
857c478bd9Sstevel@tonic-gate 
86c719c59aSjkennedy static int match(char *s);
87c719c59aSjkennedy static void usage(void);
88c719c59aSjkennedy static void putdisk(char *buf, int daddr, int size);
89c719c59aSjkennedy static void getdisk(char *buf, int daddr, int size);
90c719c59aSjkennedy static void prntstring(char *heading, char *s, int maxlen);
91c719c59aSjkennedy static void copystring(char *from, char *to, int size);
92c719c59aSjkennedy static void prntlabel(void);
93c719c59aSjkennedy static void updatelabel(void);
94c719c59aSjkennedy static void ckvoldesc(void);
95c719c59aSjkennedy 
96c719c59aSjkennedy int
97c719c59aSjkennedy main(int argc, char **argv)
987c478bd9Sstevel@tonic-gate {
99c719c59aSjkennedy 	int c;
1007c478bd9Sstevel@tonic-gate 	int openopt;
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate 	strcpy(callname, argv[0]);
1037c478bd9Sstevel@tonic-gate 	for (c = 1; c < argc; c++) {
1047c478bd9Sstevel@tonic-gate 		string = argv[c];
1057c478bd9Sstevel@tonic-gate 		if (match("sysid=")) {
1067c478bd9Sstevel@tonic-gate 			sysid = string;
1077c478bd9Sstevel@tonic-gate 			continue;
1087c478bd9Sstevel@tonic-gate 		}
1097c478bd9Sstevel@tonic-gate 		if (match("volid=")) {
1107c478bd9Sstevel@tonic-gate 			volid = string;
1117c478bd9Sstevel@tonic-gate 			continue;
1127c478bd9Sstevel@tonic-gate 		}
1137c478bd9Sstevel@tonic-gate 		if (match("volsetid=")) {
1147c478bd9Sstevel@tonic-gate 			volsetid = string;
1157c478bd9Sstevel@tonic-gate 			continue;
1167c478bd9Sstevel@tonic-gate 		}
1177c478bd9Sstevel@tonic-gate 		if (match("pubid=")) {
1187c478bd9Sstevel@tonic-gate 			pubid = string;
1197c478bd9Sstevel@tonic-gate 			continue;
1207c478bd9Sstevel@tonic-gate 		}
1217c478bd9Sstevel@tonic-gate 		if (match("prepid=")) {
1227c478bd9Sstevel@tonic-gate 			prepid = string;
1237c478bd9Sstevel@tonic-gate 			continue;
1247c478bd9Sstevel@tonic-gate 		}
1257c478bd9Sstevel@tonic-gate 		if (match("applid=")) {
1267c478bd9Sstevel@tonic-gate 			applid = string;
1277c478bd9Sstevel@tonic-gate 			continue;
1287c478bd9Sstevel@tonic-gate 		}
1297c478bd9Sstevel@tonic-gate 		if (match("copyfile=")) {
1307c478bd9Sstevel@tonic-gate 			copyfile = string;
1317c478bd9Sstevel@tonic-gate 			continue;
1327c478bd9Sstevel@tonic-gate 		}
1337c478bd9Sstevel@tonic-gate 		if (match("absfile=")) {
1347c478bd9Sstevel@tonic-gate 			absfile = string;
1357c478bd9Sstevel@tonic-gate 			continue;
1367c478bd9Sstevel@tonic-gate 		}
1377c478bd9Sstevel@tonic-gate 		if (match("bibfile=")) {
1387c478bd9Sstevel@tonic-gate 			bibfile = string;
1397c478bd9Sstevel@tonic-gate 			continue;
1407c478bd9Sstevel@tonic-gate 		}
1417c478bd9Sstevel@tonic-gate 		break;
1427c478bd9Sstevel@tonic-gate 	}
1437c478bd9Sstevel@tonic-gate 	/* the last argument must be the cdrom iamge file */
1447c478bd9Sstevel@tonic-gate 	if (argc != c+1) {
1457c478bd9Sstevel@tonic-gate 		if (argc > 1)
1467c478bd9Sstevel@tonic-gate 			fprintf(stderr, "%s: Illegal option %s in input\n",
1477c478bd9Sstevel@tonic-gate 			    callname, string);
1487c478bd9Sstevel@tonic-gate 			usage();
1497c478bd9Sstevel@tonic-gate 	}
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate 	/* open image file in read write only if necessary */
1527c478bd9Sstevel@tonic-gate 	if (argc == 2) openopt = O_RDONLY;
1537c478bd9Sstevel@tonic-gate 	else openopt = O_RDWR;
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate 	if ((cdfd = open(argv[c], openopt)) < 0) {
1567c478bd9Sstevel@tonic-gate 		if (strchr(argv[c], '=') ||
157*0c79d02bSRichard Lowe 		    strchr(argv[c], '-')) {
158*0c79d02bSRichard Lowe 			usage();
159*0c79d02bSRichard Lowe 		}
1607c478bd9Sstevel@tonic-gate 		sprintf(errstrng, "%s: main: open(): ", callname);
1617c478bd9Sstevel@tonic-gate 		perror(errstrng);
1627c478bd9Sstevel@tonic-gate 		exit(32);
1637c478bd9Sstevel@tonic-gate 	}
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate 	/* check volume descriptor */
1667c478bd9Sstevel@tonic-gate 	(void) ckvoldesc();
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate 	if (cd_type < 0) {
1697c478bd9Sstevel@tonic-gate 		fprintf(stderr, "%s: unknown cdrom format label\n", callname);
1707c478bd9Sstevel@tonic-gate 		exit(32);
1717c478bd9Sstevel@tonic-gate 	}
1727c478bd9Sstevel@tonic-gate 
1737c478bd9Sstevel@tonic-gate 	/* update label, if needed */
1747c478bd9Sstevel@tonic-gate 	if (argc != 2) updatelabel();
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate 	/* print the (updated) image label */
1777c478bd9Sstevel@tonic-gate 	prntlabel();
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate 	close(cdfd);
180c719c59aSjkennedy 	return (0);
1817c478bd9Sstevel@tonic-gate }
1827c478bd9Sstevel@tonic-gate 
183c719c59aSjkennedy static void
184c719c59aSjkennedy usage(void)
1857c478bd9Sstevel@tonic-gate {
1867c478bd9Sstevel@tonic-gate 	fprintf(stderr, "usage: %s [-F ufs] [option=value ...] cdimage\n",
1877c478bd9Sstevel@tonic-gate 	    callname);
1887c478bd9Sstevel@tonic-gate 	exit(32);
1897c478bd9Sstevel@tonic-gate }
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate /*
1927c478bd9Sstevel@tonic-gate  * findhsvol: check if the disk is in high sierra format
1937c478bd9Sstevel@tonic-gate  *            return(1) if found, (0) otherwise
1947c478bd9Sstevel@tonic-gate  *	      if found, volp will point to the descriptor
1957c478bd9Sstevel@tonic-gate  *
1967c478bd9Sstevel@tonic-gate  */
1977c478bd9Sstevel@tonic-gate int
1987c478bd9Sstevel@tonic-gate findhsvol(volp)
1997c478bd9Sstevel@tonic-gate char *volp;
2007c478bd9Sstevel@tonic-gate {
2017c478bd9Sstevel@tonic-gate int secno;
2027c478bd9Sstevel@tonic-gate int i;
2037c478bd9Sstevel@tonic-gate 
2047c478bd9Sstevel@tonic-gate 	secno = HS_VOLDESC_SEC;
2057c478bd9Sstevel@tonic-gate 	GETSECTOR(volp, secno++, 1);
2067c478bd9Sstevel@tonic-gate 	while (HSV_DESC_TYPE(volp) != VD_EOV) {
2077c478bd9Sstevel@tonic-gate 		for (i = 0; i < HSV_ID_STRLEN; i++)
2087c478bd9Sstevel@tonic-gate 			if (HSV_STD_ID(volp)[i] != HSV_ID_STRING[i])
2097c478bd9Sstevel@tonic-gate 				goto cantfind;
2107c478bd9Sstevel@tonic-gate 		if (HSV_STD_VER(volp) != HSV_ID_VER)
2117c478bd9Sstevel@tonic-gate 			goto cantfind;
2127c478bd9Sstevel@tonic-gate 		switch (HSV_DESC_TYPE(volp)) {
2137c478bd9Sstevel@tonic-gate 		case VD_SFS:
2147c478bd9Sstevel@tonic-gate 			hs_pvd_sec_no = secno-1;
2157c478bd9Sstevel@tonic-gate 			return (1);
2167c478bd9Sstevel@tonic-gate 		case VD_EOV:
2177c478bd9Sstevel@tonic-gate 			goto cantfind;
2187c478bd9Sstevel@tonic-gate 		}
2197c478bd9Sstevel@tonic-gate 		GETSECTOR(volp, secno++, 1);
2207c478bd9Sstevel@tonic-gate 	}
2217c478bd9Sstevel@tonic-gate cantfind:
2227c478bd9Sstevel@tonic-gate 	return (0);
2237c478bd9Sstevel@tonic-gate }
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate /*
2267c478bd9Sstevel@tonic-gate  * findisovol: check if the disk is in ISO 9660 format
2277c478bd9Sstevel@tonic-gate  *            return(1) if found, (0) otherwise
2287c478bd9Sstevel@tonic-gate  *	      if found, volp will point to the descriptor
2297c478bd9Sstevel@tonic-gate  *
2307c478bd9Sstevel@tonic-gate  */
2317c478bd9Sstevel@tonic-gate int
2327c478bd9Sstevel@tonic-gate findisovol(volp)
2337c478bd9Sstevel@tonic-gate char *volp;
2347c478bd9Sstevel@tonic-gate {
2357c478bd9Sstevel@tonic-gate int secno;
2367c478bd9Sstevel@tonic-gate int i;
2377c478bd9Sstevel@tonic-gate 
2387c478bd9Sstevel@tonic-gate 	secno = ISO_VOLDESC_SEC;
2397c478bd9Sstevel@tonic-gate 	GETSECTOR(volp, secno++, 1);
2407c478bd9Sstevel@tonic-gate 	while (ISO_DESC_TYPE(volp) != ISO_VD_EOV) {
2417c478bd9Sstevel@tonic-gate 		for (i = 0; i < ISO_ID_STRLEN; i++)
2427c478bd9Sstevel@tonic-gate 			if (ISO_STD_ID(volp)[i] != ISO_ID_STRING[i])
2437c478bd9Sstevel@tonic-gate 				goto cantfind;
2447c478bd9Sstevel@tonic-gate 		if (ISO_STD_VER(volp) != ISO_ID_VER)
2457c478bd9Sstevel@tonic-gate 			goto cantfind;
2467c478bd9Sstevel@tonic-gate 		switch (ISO_DESC_TYPE(volp)) {
2477c478bd9Sstevel@tonic-gate 		case ISO_VD_PVD:
2487c478bd9Sstevel@tonic-gate 			iso_pvd_sec_no = secno-1;
2497c478bd9Sstevel@tonic-gate 			return (1);
2507c478bd9Sstevel@tonic-gate 		case ISO_VD_EOV:
2517c478bd9Sstevel@tonic-gate 			goto cantfind;
2527c478bd9Sstevel@tonic-gate 		}
2537c478bd9Sstevel@tonic-gate 		GETSECTOR(volp, secno++, 1);
2547c478bd9Sstevel@tonic-gate 	}
2557c478bd9Sstevel@tonic-gate cantfind:
2567c478bd9Sstevel@tonic-gate 	return (0);
2577c478bd9Sstevel@tonic-gate }
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate /*
2607c478bd9Sstevel@tonic-gate  * findunixvol: check if the disk is in UNIX extension format
2617c478bd9Sstevel@tonic-gate  *            return(1) if found, (0) otherwise
2627c478bd9Sstevel@tonic-gate  *	      if found, volp will point to the descriptor
2637c478bd9Sstevel@tonic-gate  *
2647c478bd9Sstevel@tonic-gate  */
2657c478bd9Sstevel@tonic-gate int
2667c478bd9Sstevel@tonic-gate findunixvol(volp)
2677c478bd9Sstevel@tonic-gate char *volp;
2687c478bd9Sstevel@tonic-gate {
2697c478bd9Sstevel@tonic-gate int secno;
2707c478bd9Sstevel@tonic-gate int i;
2717c478bd9Sstevel@tonic-gate 
2727c478bd9Sstevel@tonic-gate 	secno = ISO_VOLDESC_SEC;
2737c478bd9Sstevel@tonic-gate 	GETSECTOR(volp, secno++, 1);
2747c478bd9Sstevel@tonic-gate 	while (ISO_DESC_TYPE(volp) != ISO_VD_EOV) {
2757c478bd9Sstevel@tonic-gate 		for (i = 0; i < ISO_ID_STRLEN; i++)
2767c478bd9Sstevel@tonic-gate 			if (ISO_STD_ID(volp)[i] != ISO_ID_STRING[i])
2777c478bd9Sstevel@tonic-gate 				goto cantfind;
2787c478bd9Sstevel@tonic-gate 		if (ISO_STD_VER(volp) != ISO_ID_VER)
2797c478bd9Sstevel@tonic-gate 			goto cantfind;
2807c478bd9Sstevel@tonic-gate 		switch (ISO_DESC_TYPE(volp)) {
2817c478bd9Sstevel@tonic-gate 		case ISO_VD_UNIX:
2827c478bd9Sstevel@tonic-gate 			unix_pvd_sec_no = secno-1;
2837c478bd9Sstevel@tonic-gate 			return (1);
2847c478bd9Sstevel@tonic-gate 		case ISO_VD_EOV:
2857c478bd9Sstevel@tonic-gate 			goto cantfind;
2867c478bd9Sstevel@tonic-gate 		}
2877c478bd9Sstevel@tonic-gate 		GETSECTOR(volp, secno++, 1);
2887c478bd9Sstevel@tonic-gate 	}
2897c478bd9Sstevel@tonic-gate cantfind:
2907c478bd9Sstevel@tonic-gate 	return (0);
2917c478bd9Sstevel@tonic-gate }
2927c478bd9Sstevel@tonic-gate 
293c719c59aSjkennedy static void
294c719c59aSjkennedy ckvoldesc(void)
2957c478bd9Sstevel@tonic-gate {
2967c478bd9Sstevel@tonic-gate 	if (findhsvol(hs_buf))
2977c478bd9Sstevel@tonic-gate 		cd_type = 0;
2987c478bd9Sstevel@tonic-gate 	else if (findisovol(iso_buf)) {
2997c478bd9Sstevel@tonic-gate 		if (findunixvol(unix_buf))
3007c478bd9Sstevel@tonic-gate 			cd_type = 2;
3017c478bd9Sstevel@tonic-gate 		else cd_type = 1;
302c719c59aSjkennedy 	} else {
303c719c59aSjkennedy 		cd_type = -1;
3047c478bd9Sstevel@tonic-gate 	}
3057c478bd9Sstevel@tonic-gate }
3067c478bd9Sstevel@tonic-gate 
307c719c59aSjkennedy static void
308c719c59aSjkennedy updatelabel(void)
3097c478bd9Sstevel@tonic-gate {
3107c478bd9Sstevel@tonic-gate 	switch (cd_type) {
3117c478bd9Sstevel@tonic-gate 	case 0:
312c719c59aSjkennedy 		copystring(sysid, (char *)HSV_sys_id(hs_buf), 32);
313c719c59aSjkennedy 		copystring(volid, (char *)HSV_vol_id(hs_buf), 32);
314c719c59aSjkennedy 		copystring(volsetid, (char *)HSV_vol_set_id(hs_buf), 128);
315c719c59aSjkennedy 		copystring(pubid, (char *)HSV_pub_id(hs_buf), 128);
316c719c59aSjkennedy 		copystring(prepid, (char *)HSV_prep_id(hs_buf), 128);
317c719c59aSjkennedy 		copystring(applid, (char *)HSV_appl_id(hs_buf), 128);
318c719c59aSjkennedy 		copystring(copyfile, (char *)HSV_copyr_id(hs_buf), 37);
319c719c59aSjkennedy 		copystring(absfile, (char *)HSV_abstr_id(hs_buf), 37);
3207c478bd9Sstevel@tonic-gate 		PUTSECTOR(hs_buf, hs_pvd_sec_no, 1);
3217c478bd9Sstevel@tonic-gate 		break;
3227c478bd9Sstevel@tonic-gate 	case 2:
323c719c59aSjkennedy 		copystring(sysid, (char *)ISO_sys_id(unix_buf), 32);
324c719c59aSjkennedy 		copystring(volid, (char *)ISO_vol_id(unix_buf), 32);
325c719c59aSjkennedy 		copystring(volsetid, (char *)ISO_vol_set_id(unix_buf), 128);
326c719c59aSjkennedy 		copystring(pubid, (char *)ISO_pub_id(unix_buf), 128);
327c719c59aSjkennedy 		copystring(prepid, (char *)ISO_prep_id(unix_buf), 128);
328c719c59aSjkennedy 		copystring(applid, (char *)ISO_appl_id(unix_buf), 128);
329c719c59aSjkennedy 		copystring(copyfile, (char *)ISO_copyr_id(unix_buf), 37);
330c719c59aSjkennedy 		copystring(absfile, (char *)ISO_abstr_id(unix_buf), 37);
331c719c59aSjkennedy 		copystring(bibfile, (char *)ISO_bibli_id(unix_buf), 37);
3327c478bd9Sstevel@tonic-gate 		PUTSECTOR(unix_buf, unix_pvd_sec_no, 1);
333c719c59aSjkennedy 		/*
334c719c59aSjkennedy 		 * after update unix volume descriptor,
335c719c59aSjkennedy 		 * fall thru to update the iso primary vol descriptor
336c719c59aSjkennedy 		 */
3377c478bd9Sstevel@tonic-gate 	case 1:
338c719c59aSjkennedy 		copystring(sysid, (char *)ISO_sys_id(iso_buf), 32);
339c719c59aSjkennedy 		copystring(volid, (char *)ISO_vol_id(iso_buf), 32);
340c719c59aSjkennedy 		copystring(volsetid, (char *)ISO_vol_set_id(iso_buf), 128);
341c719c59aSjkennedy 		copystring(pubid, (char *)ISO_pub_id(iso_buf), 128);
342c719c59aSjkennedy 		copystring(prepid, (char *)ISO_prep_id(iso_buf), 128);
343c719c59aSjkennedy 		copystring(applid, (char *)ISO_appl_id(iso_buf), 128);
344c719c59aSjkennedy 		copystring(copyfile, (char *)ISO_copyr_id(iso_buf), 37);
345c719c59aSjkennedy 		copystring(absfile, (char *)ISO_abstr_id(iso_buf), 37);
346c719c59aSjkennedy 		copystring(bibfile, (char *)ISO_bibli_id(iso_buf), 37);
3477c478bd9Sstevel@tonic-gate 		PUTSECTOR(iso_buf, iso_pvd_sec_no, 1);
3487c478bd9Sstevel@tonic-gate 		break;
3497c478bd9Sstevel@tonic-gate 	}
3507c478bd9Sstevel@tonic-gate }
3517c478bd9Sstevel@tonic-gate 
352c719c59aSjkennedy static void
353c719c59aSjkennedy prntlabel(void)
3547c478bd9Sstevel@tonic-gate {
3557c478bd9Sstevel@tonic-gate 	int i;
3567c478bd9Sstevel@tonic-gate 	switch (cd_type) {
3577c478bd9Sstevel@tonic-gate 	case 0:
3587c478bd9Sstevel@tonic-gate 		printf("CD-ROM is in High Sierra format\n");
3597c478bd9Sstevel@tonic-gate 		sysid = (char *)HSV_sys_id(hs_buf);
3607c478bd9Sstevel@tonic-gate 		volid = (char *)HSV_vol_id(hs_buf);
3617c478bd9Sstevel@tonic-gate 		volsetid = (char *)HSV_vol_set_id(hs_buf);
3627c478bd9Sstevel@tonic-gate 		pubid = (char *)HSV_pub_id(hs_buf);
3637c478bd9Sstevel@tonic-gate 		prepid = (char *)HSV_prep_id(hs_buf);
3647c478bd9Sstevel@tonic-gate 		applid = (char *)HSV_appl_id(hs_buf);
3657c478bd9Sstevel@tonic-gate 		copyfile = (char *)HSV_copyr_id(hs_buf);
3667c478bd9Sstevel@tonic-gate 		absfile = (char *)HSV_abstr_id(hs_buf);
3677c478bd9Sstevel@tonic-gate 		bibfile = NULL;
3687c478bd9Sstevel@tonic-gate 		volsetsize = HSV_SET_SIZE(hs_buf);
3697c478bd9Sstevel@tonic-gate 		volsetseq = HSV_SET_SEQ(hs_buf);
3707c478bd9Sstevel@tonic-gate 		blksize = HSV_BLK_SIZE(hs_buf);
3717c478bd9Sstevel@tonic-gate 		volsize = HSV_VOL_SIZE(hs_buf);
3727c478bd9Sstevel@tonic-gate 		break;
3737c478bd9Sstevel@tonic-gate 	case 1:
3747c478bd9Sstevel@tonic-gate 		printf("CD-ROM is in ISO 9660 format\n");
3757c478bd9Sstevel@tonic-gate 		sysid = (char *)ISO_sys_id(iso_buf);
3767c478bd9Sstevel@tonic-gate 		volid = (char *)ISO_vol_id(iso_buf);
3777c478bd9Sstevel@tonic-gate 		volsetid = (char *)ISO_vol_set_id(iso_buf);
3787c478bd9Sstevel@tonic-gate 		pubid = (char *)ISO_pub_id(iso_buf);
3797c478bd9Sstevel@tonic-gate 		prepid = (char *)ISO_prep_id(iso_buf);
3807c478bd9Sstevel@tonic-gate 		applid = (char *)ISO_appl_id(iso_buf);
3817c478bd9Sstevel@tonic-gate 		copyfile = (char *)ISO_copyr_id(iso_buf);
3827c478bd9Sstevel@tonic-gate 		absfile = (char *)ISO_abstr_id(iso_buf);
3837c478bd9Sstevel@tonic-gate 		bibfile = (char *)ISO_bibli_id(iso_buf);
3847c478bd9Sstevel@tonic-gate 		volsetsize = ISO_SET_SIZE(iso_buf);
3857c478bd9Sstevel@tonic-gate 		volsetseq = ISO_SET_SEQ(iso_buf);
3867c478bd9Sstevel@tonic-gate 		blksize = ISO_BLK_SIZE(iso_buf);
3877c478bd9Sstevel@tonic-gate 		volsize = ISO_VOL_SIZE(iso_buf);
3887c478bd9Sstevel@tonic-gate 		break;
3897c478bd9Sstevel@tonic-gate 	case 2:
3907c478bd9Sstevel@tonic-gate 		printf("CD-ROM is in ISO 9660 format with UNIX extension\n");
3917c478bd9Sstevel@tonic-gate 		sysid = (char *)ISO_sys_id(unix_buf);
3927c478bd9Sstevel@tonic-gate 		volid = (char *)ISO_vol_id(unix_buf);
3937c478bd9Sstevel@tonic-gate 		volsetid = (char *)ISO_vol_set_id(unix_buf);
3947c478bd9Sstevel@tonic-gate 		pubid = (char *)ISO_pub_id(unix_buf);
3957c478bd9Sstevel@tonic-gate 		prepid = (char *)ISO_prep_id(unix_buf);
3967c478bd9Sstevel@tonic-gate 		applid = (char *)ISO_appl_id(unix_buf);
3977c478bd9Sstevel@tonic-gate 		copyfile = (char *)ISO_copyr_id(unix_buf);
3987c478bd9Sstevel@tonic-gate 		absfile = (char *)ISO_abstr_id(unix_buf);
3997c478bd9Sstevel@tonic-gate 		bibfile = (char *)ISO_bibli_id(unix_buf);
4007c478bd9Sstevel@tonic-gate 		volsetsize = ISO_SET_SIZE(unix_buf);
4017c478bd9Sstevel@tonic-gate 		volsetseq = ISO_SET_SEQ(unix_buf);
4027c478bd9Sstevel@tonic-gate 		blksize = ISO_BLK_SIZE(unix_buf);
4037c478bd9Sstevel@tonic-gate 		volsize = ISO_VOL_SIZE(unix_buf);
4047c478bd9Sstevel@tonic-gate 		break;
4057c478bd9Sstevel@tonic-gate 	default:
4067c478bd9Sstevel@tonic-gate 		return;
4077c478bd9Sstevel@tonic-gate 	}
4087c478bd9Sstevel@tonic-gate 	/* system id */
4097c478bd9Sstevel@tonic-gate 	prntstring("System id", sysid, 32);
4107c478bd9Sstevel@tonic-gate 	/* read volume id */
4117c478bd9Sstevel@tonic-gate 	prntstring("Volume id", volid, 32);
4127c478bd9Sstevel@tonic-gate 	/* read volume set id */
4137c478bd9Sstevel@tonic-gate 	prntstring("Volume set id", volsetid, 128);
4147c478bd9Sstevel@tonic-gate 	/* publisher id */
4157c478bd9Sstevel@tonic-gate 	prntstring("Publisher id", pubid, 128);
4167c478bd9Sstevel@tonic-gate 	/* data preparer id */
4177c478bd9Sstevel@tonic-gate 	prntstring("Data preparer id", prepid, 128);
4187c478bd9Sstevel@tonic-gate 	/* application id */
4197c478bd9Sstevel@tonic-gate 	prntstring("Application id", applid, 128);
4207c478bd9Sstevel@tonic-gate 	/* copyright file identifier */
4217c478bd9Sstevel@tonic-gate 	prntstring("Copyright File id", copyfile, 37);
4227c478bd9Sstevel@tonic-gate 	/* Abstract file identifier */
4237c478bd9Sstevel@tonic-gate 	prntstring("Abstract File id", absfile, 37);
4247c478bd9Sstevel@tonic-gate 	/* Bibliographic file identifier */
4257c478bd9Sstevel@tonic-gate 	prntstring("Bibliographic File id", bibfile, 37);
4267c478bd9Sstevel@tonic-gate 	/* print volume set size */
4277c478bd9Sstevel@tonic-gate 	printf("Volume set size is %d\n", volsetsize);
4287c478bd9Sstevel@tonic-gate 	/* print volume set sequnce number */
4297c478bd9Sstevel@tonic-gate 	printf("Volume set sequence number is %d\n", volsetseq);
4307c478bd9Sstevel@tonic-gate 	/* print logical block size */
4317c478bd9Sstevel@tonic-gate 	printf("Logical block size is %d\n", blksize);
4327c478bd9Sstevel@tonic-gate 	/* print volume size */
4337c478bd9Sstevel@tonic-gate 	printf("Volume size is %d\n", volsize);
4347c478bd9Sstevel@tonic-gate }
4357c478bd9Sstevel@tonic-gate 
436c719c59aSjkennedy static void
437c719c59aSjkennedy copystring(char *from, char *to, int size)
4387c478bd9Sstevel@tonic-gate {
4397c478bd9Sstevel@tonic-gate 	int i;
4407c478bd9Sstevel@tonic-gate 
441c719c59aSjkennedy 	if (from == NULL)
442c719c59aSjkennedy 		return;
4437c478bd9Sstevel@tonic-gate 	for (i = 0; i < size; i++) {
444c719c59aSjkennedy 		if (*from == '\0')
445c719c59aSjkennedy 			break;
4467c478bd9Sstevel@tonic-gate 		else *to++ = *from++;
4477c478bd9Sstevel@tonic-gate 	}
4487c478bd9Sstevel@tonic-gate 	for (; i < size; i++) *to++ = ' ';
4497c478bd9Sstevel@tonic-gate }
4507c478bd9Sstevel@tonic-gate 
451c719c59aSjkennedy static void
452c719c59aSjkennedy prntstring(char *heading, char *s, int maxlen)
4537c478bd9Sstevel@tonic-gate {
4547c478bd9Sstevel@tonic-gate 	int i;
455c719c59aSjkennedy 	if (maxlen < 1)
456c719c59aSjkennedy 		return;
457c719c59aSjkennedy 	if (heading == NULL || s == NULL)
458c719c59aSjkennedy 		return;
4597c478bd9Sstevel@tonic-gate 	/* print heading */
4607c478bd9Sstevel@tonic-gate 	printf("%s: ", heading);
4617c478bd9Sstevel@tonic-gate 
4627c478bd9Sstevel@tonic-gate 	/* strip off trailing zeros */
4637c478bd9Sstevel@tonic-gate 	for (i = maxlen-1; i >= 0; i--)
464c719c59aSjkennedy 		if (s[i] != ' ')
465c719c59aSjkennedy 			break;
4667c478bd9Sstevel@tonic-gate 
4677c478bd9Sstevel@tonic-gate 	maxlen = i+1;
468c719c59aSjkennedy 	for (i = 0; i < maxlen; i++)
469c719c59aSjkennedy 		printf("%c", s[i]);
4707c478bd9Sstevel@tonic-gate 	printf("\n");
4717c478bd9Sstevel@tonic-gate }
4727c478bd9Sstevel@tonic-gate 
473c719c59aSjkennedy static int
474c719c59aSjkennedy match(char *s)
4757c478bd9Sstevel@tonic-gate {
476c719c59aSjkennedy 	char *cs;
4777c478bd9Sstevel@tonic-gate 
4787c478bd9Sstevel@tonic-gate 	cs = string;
4797c478bd9Sstevel@tonic-gate 	while (*cs++ == *s)
4807c478bd9Sstevel@tonic-gate 		if (*s++ == '\0')
4817c478bd9Sstevel@tonic-gate 			goto true;
4827c478bd9Sstevel@tonic-gate 	if (*s != '\0')
4837c478bd9Sstevel@tonic-gate 		return (0);
4847c478bd9Sstevel@tonic-gate 
4857c478bd9Sstevel@tonic-gate true:
4867c478bd9Sstevel@tonic-gate 	cs--;
4877c478bd9Sstevel@tonic-gate 	string = cs;
4887c478bd9Sstevel@tonic-gate 	return (1);
4897c478bd9Sstevel@tonic-gate }
4907c478bd9Sstevel@tonic-gate 
4917c478bd9Sstevel@tonic-gate /* readdisk - read from cdrom image file */
492c719c59aSjkennedy static void
493c719c59aSjkennedy getdisk(char *buf, int daddr, int size)
4947c478bd9Sstevel@tonic-gate {
4957c478bd9Sstevel@tonic-gate 
4967c478bd9Sstevel@tonic-gate 	if (lseek(cdfd, daddr, L_SET) == -1) {
4977c478bd9Sstevel@tonic-gate 		sprintf(errstrng, "%s: getdisk: lseek()", callname);
4987c478bd9Sstevel@tonic-gate 		perror(errstrng);
4997c478bd9Sstevel@tonic-gate 		exit(32);
5007c478bd9Sstevel@tonic-gate 	}
5017c478bd9Sstevel@tonic-gate 	if (read(cdfd, buf, size) != size) {
5027c478bd9Sstevel@tonic-gate 		sprintf(errstrng, "%s: getdisk: read()", callname);
5037c478bd9Sstevel@tonic-gate 		perror(errstrng);
5047c478bd9Sstevel@tonic-gate 		exit(32);
5057c478bd9Sstevel@tonic-gate 	}
5067c478bd9Sstevel@tonic-gate }
5077c478bd9Sstevel@tonic-gate 
5087c478bd9Sstevel@tonic-gate /* putdisk - write to cdrom image file */
509c719c59aSjkennedy static void
510c719c59aSjkennedy putdisk(char *buf, int daddr, int size)
5117c478bd9Sstevel@tonic-gate {
5127c478bd9Sstevel@tonic-gate 
5137c478bd9Sstevel@tonic-gate 	if (lseek(cdfd, daddr, L_SET) == -1) {
5147c478bd9Sstevel@tonic-gate 		sprintf(errstrng, "%s: putdisk: lseek()", callname);
5157c478bd9Sstevel@tonic-gate 		perror(errstrng);
5167c478bd9Sstevel@tonic-gate 		exit(32);
5177c478bd9Sstevel@tonic-gate 	}
5187c478bd9Sstevel@tonic-gate 	if (write(cdfd, buf, size) != size) {
5197c478bd9Sstevel@tonic-gate 		sprintf(errstrng, "%s: putdisk: write()", callname);
5207c478bd9Sstevel@tonic-gate 		perror(errstrng);
5217c478bd9Sstevel@tonic-gate 		exit(32);
5227c478bd9Sstevel@tonic-gate 	}
5237c478bd9Sstevel@tonic-gate }
524