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>
490c79d02bSRichard Lowe 
500c79d02bSRichard Lowe #include <sys/fs/hsfs_isospec.h>
510c79d02bSRichard Lowe #include <sys/fs/hsfs_spec.h>
527c478bd9Sstevel@tonic-gate 
53c719c59aSjkennedy #define	PUTSECTOR(buf, secno, nosec) (putdisk(buf, (secno)*ISO_SECTOR_SIZE, \
547c478bd9Sstevel@tonic-gate 	(nosec)*ISO_SECTOR_SIZE))
55c719c59aSjkennedy #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
main(int argc,char ** argv)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]);
103c719c59aSjkennedy 	for (c = 1; c < argc; c++) {
1047c478bd9Sstevel@tonic-gate 		string = argv[c];
105c719c59aSjkennedy 		if (match("sysid=")) {
1067c478bd9Sstevel@tonic-gate 			sysid = string;
1077c478bd9Sstevel@tonic-gate 			continue;
1087c478bd9Sstevel@tonic-gate 		}
109c719c59aSjkennedy 		if (match("volid=")) {
1107c478bd9Sstevel@tonic-gate 			volid = string;
1117c478bd9Sstevel@tonic-gate 			continue;
1127c478bd9Sstevel@tonic-gate 		}
113c719c59aSjkennedy 		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 		}
121c719c59aSjkennedy 		if (match("prepid=")) {
1227c478bd9Sstevel@tonic-gate 			prepid = string;
1237c478bd9Sstevel@tonic-gate 			continue;
1247c478bd9Sstevel@tonic-gate 		}
125c719c59aSjkennedy 		if (match("applid=")) {
1267c478bd9Sstevel@tonic-gate 			applid = string;
1277c478bd9Sstevel@tonic-gate 			continue;
1287c478bd9Sstevel@tonic-gate 		}
129c719c59aSjkennedy 		if (match("copyfile=")) {
1307c478bd9Sstevel@tonic-gate 			copyfile = string;
1317c478bd9Sstevel@tonic-gate 			continue;
1327c478bd9Sstevel@tonic-gate 		}
133c719c59aSjkennedy 		if (match("absfile=")) {
1347c478bd9Sstevel@tonic-gate 			absfile = string;
1357c478bd9Sstevel@tonic-gate 			continue;
1367c478bd9Sstevel@tonic-gate 		}
137c719c59aSjkennedy 		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",
147c719c59aSjkennedy 			    callname, string);
148ac34f4ddSToomas Soome 		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], '=') ||
1570c79d02bSRichard Lowe 		    strchr(argv[c], '-')) {
1580c79d02bSRichard Lowe 			usage();
1590c79d02bSRichard 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
usage(void)184c719c59aSjkennedy usage(void)
1857c478bd9Sstevel@tonic-gate {
1867c478bd9Sstevel@tonic-gate 	fprintf(stderr, "usage: %s [-F ufs] [option=value ...] cdimage\n",
1870c79d02bSRichard Lowe 	    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
findhsvol(volp)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  */
231c719c59aSjkennedy int
findisovol(volp)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  */
265c719c59aSjkennedy int
findunixvol(volp)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
ckvoldesc(void)294c719c59aSjkennedy ckvoldesc(void)
2957c478bd9Sstevel@tonic-gate {
296c719c59aSjkennedy 	if (findhsvol(hs_buf))
2977c478bd9Sstevel@tonic-gate 		cd_type = 0;
2987c478bd9Sstevel@tonic-gate 	else if (findisovol(iso_buf)) {
299c719c59aSjkennedy 		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
updatelabel(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 		 */
337*f45bbb21SToomas Soome 		/* FALLTHROUGH */
3387c478bd9Sstevel@tonic-gate 	case 1:
339c719c59aSjkennedy 		copystring(sysid, (char *)ISO_sys_id(iso_buf), 32);
340c719c59aSjkennedy 		copystring(volid, (char *)ISO_vol_id(iso_buf), 32);
341c719c59aSjkennedy 		copystring(volsetid, (char *)ISO_vol_set_id(iso_buf), 128);
342c719c59aSjkennedy 		copystring(pubid, (char *)ISO_pub_id(iso_buf), 128);
343c719c59aSjkennedy 		copystring(prepid, (char *)ISO_prep_id(iso_buf), 128);
344c719c59aSjkennedy 		copystring(applid, (char *)ISO_appl_id(iso_buf), 128);
345c719c59aSjkennedy 		copystring(copyfile, (char *)ISO_copyr_id(iso_buf), 37);
346c719c59aSjkennedy 		copystring(absfile, (char *)ISO_abstr_id(iso_buf), 37);
347c719c59aSjkennedy 		copystring(bibfile, (char *)ISO_bibli_id(iso_buf), 37);
3487c478bd9Sstevel@tonic-gate 		PUTSECTOR(iso_buf, iso_pvd_sec_no, 1);
3497c478bd9Sstevel@tonic-gate 		break;
3507c478bd9Sstevel@tonic-gate 	}
3517c478bd9Sstevel@tonic-gate }
3527c478bd9Sstevel@tonic-gate 
353c719c59aSjkennedy static void
prntlabel(void)354c719c59aSjkennedy prntlabel(void)
3557c478bd9Sstevel@tonic-gate {
3567c478bd9Sstevel@tonic-gate 	int i;
3577c478bd9Sstevel@tonic-gate 	switch (cd_type) {
3587c478bd9Sstevel@tonic-gate 	case 0:
3597c478bd9Sstevel@tonic-gate 		printf("CD-ROM is in High Sierra format\n");
360c719c59aSjkennedy 		sysid = (char *)HSV_sys_id(hs_buf);
361c719c59aSjkennedy 		volid = (char *)HSV_vol_id(hs_buf);
362c719c59aSjkennedy 		volsetid = (char *)HSV_vol_set_id(hs_buf);
363c719c59aSjkennedy 		pubid = (char *)HSV_pub_id(hs_buf);
364c719c59aSjkennedy 		prepid = (char *)HSV_prep_id(hs_buf);
365c719c59aSjkennedy 		applid = (char *)HSV_appl_id(hs_buf);
366c719c59aSjkennedy 		copyfile = (char *)HSV_copyr_id(hs_buf);
367c719c59aSjkennedy 		absfile = (char *)HSV_abstr_id(hs_buf);
368c719c59aSjkennedy 		bibfile = NULL;
369c719c59aSjkennedy 		volsetsize = HSV_SET_SIZE(hs_buf);
370c719c59aSjkennedy 		volsetseq = HSV_SET_SEQ(hs_buf);
371c719c59aSjkennedy 		blksize = HSV_BLK_SIZE(hs_buf);
372c719c59aSjkennedy 		volsize = HSV_VOL_SIZE(hs_buf);
3737c478bd9Sstevel@tonic-gate 		break;
3747c478bd9Sstevel@tonic-gate 	case 1:
3757c478bd9Sstevel@tonic-gate 		printf("CD-ROM is in ISO 9660 format\n");
376c719c59aSjkennedy 		sysid = (char *)ISO_sys_id(iso_buf);
377c719c59aSjkennedy 		volid = (char *)ISO_vol_id(iso_buf);
378c719c59aSjkennedy 		volsetid = (char *)ISO_vol_set_id(iso_buf);
379c719c59aSjkennedy 		pubid = (char *)ISO_pub_id(iso_buf);
380c719c59aSjkennedy 		prepid = (char *)ISO_prep_id(iso_buf);
381c719c59aSjkennedy 		applid = (char *)ISO_appl_id(iso_buf);
382c719c59aSjkennedy 		copyfile = (char *)ISO_copyr_id(iso_buf);
383c719c59aSjkennedy 		absfile = (char *)ISO_abstr_id(iso_buf);
384c719c59aSjkennedy 		bibfile = (char *)ISO_bibli_id(iso_buf);
385c719c59aSjkennedy 		volsetsize = ISO_SET_SIZE(iso_buf);
386c719c59aSjkennedy 		volsetseq = ISO_SET_SEQ(iso_buf);
387c719c59aSjkennedy 		blksize = ISO_BLK_SIZE(iso_buf);
388c719c59aSjkennedy 		volsize = ISO_VOL_SIZE(iso_buf);
3897c478bd9Sstevel@tonic-gate 		break;
3907c478bd9Sstevel@tonic-gate 	case 2:
3917c478bd9Sstevel@tonic-gate 		printf("CD-ROM is in ISO 9660 format with UNIX extension\n");
392c719c59aSjkennedy 		sysid = (char *)ISO_sys_id(unix_buf);
393c719c59aSjkennedy 		volid = (char *)ISO_vol_id(unix_buf);
394c719c59aSjkennedy 		volsetid = (char *)ISO_vol_set_id(unix_buf);
395c719c59aSjkennedy 		pubid = (char *)ISO_pub_id(unix_buf);
396c719c59aSjkennedy 		prepid = (char *)ISO_prep_id(unix_buf);
397c719c59aSjkennedy 		applid = (char *)ISO_appl_id(unix_buf);
398c719c59aSjkennedy 		copyfile = (char *)ISO_copyr_id(unix_buf);
399c719c59aSjkennedy 		absfile = (char *)ISO_abstr_id(unix_buf);
400c719c59aSjkennedy 		bibfile = (char *)ISO_bibli_id(unix_buf);
401c719c59aSjkennedy 		volsetsize = ISO_SET_SIZE(unix_buf);
402c719c59aSjkennedy 		volsetseq = ISO_SET_SEQ(unix_buf);
403c719c59aSjkennedy 		blksize = ISO_BLK_SIZE(unix_buf);
404c719c59aSjkennedy 		volsize = ISO_VOL_SIZE(unix_buf);
4057c478bd9Sstevel@tonic-gate 		break;
4067c478bd9Sstevel@tonic-gate 	default:
4077c478bd9Sstevel@tonic-gate 		return;
4087c478bd9Sstevel@tonic-gate 	}
4097c478bd9Sstevel@tonic-gate 	/* system id */
4107c478bd9Sstevel@tonic-gate 	prntstring("System id", sysid, 32);
4117c478bd9Sstevel@tonic-gate 	/* read volume id */
4127c478bd9Sstevel@tonic-gate 	prntstring("Volume id", volid, 32);
4137c478bd9Sstevel@tonic-gate 	/* read volume set id */
4147c478bd9Sstevel@tonic-gate 	prntstring("Volume set id", volsetid, 128);
4157c478bd9Sstevel@tonic-gate 	/* publisher id */
4167c478bd9Sstevel@tonic-gate 	prntstring("Publisher id", pubid, 128);
4177c478bd9Sstevel@tonic-gate 	/* data preparer id */
4187c478bd9Sstevel@tonic-gate 	prntstring("Data preparer id", prepid, 128);
4197c478bd9Sstevel@tonic-gate 	/* application id */
4207c478bd9Sstevel@tonic-gate 	prntstring("Application id", applid, 128);
4217c478bd9Sstevel@tonic-gate 	/* copyright file identifier */
4227c478bd9Sstevel@tonic-gate 	prntstring("Copyright File id", copyfile, 37);
4237c478bd9Sstevel@tonic-gate 	/* Abstract file identifier */
4247c478bd9Sstevel@tonic-gate 	prntstring("Abstract File id", absfile, 37);
4257c478bd9Sstevel@tonic-gate 	/* Bibliographic file identifier */
4267c478bd9Sstevel@tonic-gate 	prntstring("Bibliographic File id", bibfile, 37);
4277c478bd9Sstevel@tonic-gate 	/* print volume set size */
4287c478bd9Sstevel@tonic-gate 	printf("Volume set size is %d\n", volsetsize);
4297c478bd9Sstevel@tonic-gate 	/* print volume set sequnce number */
4307c478bd9Sstevel@tonic-gate 	printf("Volume set sequence number is %d\n", volsetseq);
4317c478bd9Sstevel@tonic-gate 	/* print logical block size */
4327c478bd9Sstevel@tonic-gate 	printf("Logical block size is %d\n", blksize);
4337c478bd9Sstevel@tonic-gate 	/* print volume size */
4347c478bd9Sstevel@tonic-gate 	printf("Volume size is %d\n", volsize);
4357c478bd9Sstevel@tonic-gate }
4367c478bd9Sstevel@tonic-gate 
437c719c59aSjkennedy static void
copystring(char * from,char * to,int size)438c719c59aSjkennedy copystring(char *from, char *to, int size)
4397c478bd9Sstevel@tonic-gate {
440c719c59aSjkennedy 	int i;
4417c478bd9Sstevel@tonic-gate 
442c719c59aSjkennedy 	if (from == NULL)
443c719c59aSjkennedy 		return;
444c719c59aSjkennedy 	for (i = 0; i < size; i++) {
445c719c59aSjkennedy 		if (*from == '\0')
446c719c59aSjkennedy 			break;
447c719c59aSjkennedy 		else *to++ = *from++;
4487c478bd9Sstevel@tonic-gate 	}
449c719c59aSjkennedy 	for (; i < size; i++) *to++ = ' ';
4507c478bd9Sstevel@tonic-gate }
4517c478bd9Sstevel@tonic-gate 
452c719c59aSjkennedy static void
prntstring(char * heading,char * s,int maxlen)453c719c59aSjkennedy prntstring(char *heading, char *s, int maxlen)
4547c478bd9Sstevel@tonic-gate {
455c719c59aSjkennedy 	int i;
456c719c59aSjkennedy 	if (maxlen < 1)
457c719c59aSjkennedy 		return;
458c719c59aSjkennedy 	if (heading == NULL || s == NULL)
459c719c59aSjkennedy 		return;
4607c478bd9Sstevel@tonic-gate 	/* print heading */
4617c478bd9Sstevel@tonic-gate 	printf("%s: ", heading);
4627c478bd9Sstevel@tonic-gate 
4637c478bd9Sstevel@tonic-gate 	/* strip off trailing zeros */
464c719c59aSjkennedy 	for (i = maxlen-1; i >= 0; i--)
465c719c59aSjkennedy 		if (s[i] != ' ')
466c719c59aSjkennedy 			break;
4677c478bd9Sstevel@tonic-gate 
4687c478bd9Sstevel@tonic-gate 	maxlen = i+1;
469c719c59aSjkennedy 	for (i = 0; i < maxlen; i++)
470c719c59aSjkennedy 		printf("%c", s[i]);
4717c478bd9Sstevel@tonic-gate 	printf("\n");
4727c478bd9Sstevel@tonic-gate }
4737c478bd9Sstevel@tonic-gate 
474c719c59aSjkennedy static int
match(char * s)475c719c59aSjkennedy match(char *s)
4767c478bd9Sstevel@tonic-gate {
477c719c59aSjkennedy 	char *cs;
4787c478bd9Sstevel@tonic-gate 
4797c478bd9Sstevel@tonic-gate 	cs = string;
480c719c59aSjkennedy 	while (*cs++ == *s)
481c719c59aSjkennedy 		if (*s++ == '\0')
4827c478bd9Sstevel@tonic-gate 			goto true;
483c719c59aSjkennedy 	if (*s != '\0')
484c719c59aSjkennedy 		return (0);
4857c478bd9Sstevel@tonic-gate 
4867c478bd9Sstevel@tonic-gate true:
4877c478bd9Sstevel@tonic-gate 	cs--;
4887c478bd9Sstevel@tonic-gate 	string = cs;
489c719c59aSjkennedy 	return (1);
4907c478bd9Sstevel@tonic-gate }
4917c478bd9Sstevel@tonic-gate 
492c719c59aSjkennedy /* readdisk - read from cdrom image file */
493c719c59aSjkennedy static void
getdisk(char * buf,int daddr,int size)494c719c59aSjkennedy getdisk(char *buf, int daddr, int size)
4957c478bd9Sstevel@tonic-gate {
4967c478bd9Sstevel@tonic-gate 
497c719c59aSjkennedy 	if (lseek(cdfd, daddr, L_SET) == -1) {
4987c478bd9Sstevel@tonic-gate 		sprintf(errstrng, "%s: getdisk: lseek()", callname);
499c719c59aSjkennedy 		perror(errstrng);
500c719c59aSjkennedy 		exit(32);
501c719c59aSjkennedy 	}
502c719c59aSjkennedy 	if (read(cdfd, buf, size) != size) {
503c719c59aSjkennedy 		sprintf(errstrng, "%s: getdisk: read()", callname);
504c719c59aSjkennedy 		perror(errstrng);
505c719c59aSjkennedy 		exit(32);
506c719c59aSjkennedy 	}
5077c478bd9Sstevel@tonic-gate }
5087c478bd9Sstevel@tonic-gate 
509c719c59aSjkennedy /* putdisk - write to cdrom image file */
510c719c59aSjkennedy static void
putdisk(char * buf,int daddr,int size)511c719c59aSjkennedy putdisk(char *buf, int daddr, int size)
5127c478bd9Sstevel@tonic-gate {
5137c478bd9Sstevel@tonic-gate 
5147c478bd9Sstevel@tonic-gate 	if (lseek(cdfd, daddr, L_SET) == -1) {
5157c478bd9Sstevel@tonic-gate 		sprintf(errstrng, "%s: putdisk: lseek()", callname);
5167c478bd9Sstevel@tonic-gate 		perror(errstrng);
5177c478bd9Sstevel@tonic-gate 		exit(32);
5187c478bd9Sstevel@tonic-gate 	}
5197c478bd9Sstevel@tonic-gate 	if (write(cdfd, buf, size) != size) {
5207c478bd9Sstevel@tonic-gate 		sprintf(errstrng, "%s: putdisk: write()", callname);
5217c478bd9Sstevel@tonic-gate 		perror(errstrng);
5227c478bd9Sstevel@tonic-gate 		exit(32);
5237c478bd9Sstevel@tonic-gate 	}
5247c478bd9Sstevel@tonic-gate }
525