xref: /onnv-gate/usr/src/cmd/fs.d/hsfs/fstyp/fstyp.c (revision 2212:4d4fd25d9b6e)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*2212Sartem  * Common Development and Distribution License (the "License").
6*2212Sartem  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*2212Sartem  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23452Sjkennedy  * Use is subject to license terms.
240Sstevel@tonic-gate  */
25452Sjkennedy 
26452Sjkennedy #pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate 
28*2212Sartem /*
29*2212Sartem  * libfstyp module for hsfs
30*2212Sartem  */
31*2212Sartem #include <unistd.h>
32*2212Sartem #include <stropts.h>
330Sstevel@tonic-gate #include <fcntl.h>
340Sstevel@tonic-gate #include <stdio.h>
35*2212Sartem #include <strings.h>
360Sstevel@tonic-gate #include <sys/param.h>
370Sstevel@tonic-gate #include <sys/stat.h>
380Sstevel@tonic-gate #include <sys/time.h>
390Sstevel@tonic-gate #include <sys/types.h>
400Sstevel@tonic-gate #include <sys/file.h>
410Sstevel@tonic-gate #include <sys/cdio.h>
420Sstevel@tonic-gate #include <sys/dkio.h>
43*2212Sartem #include <libnvpair.h>
44*2212Sartem #include <libfstyp_module.h>
450Sstevel@tonic-gate #include "hsfs_spec.h"
460Sstevel@tonic-gate #include "iso_spec.h"
470Sstevel@tonic-gate #include "iso_impl.h"
480Sstevel@tonic-gate 
49*2212Sartem typedef struct fstyp_hsfs {
50*2212Sartem 	int		fd;
51*2212Sartem 	nvlist_t	*attr;
52*2212Sartem 	char		hs_buf[ISO_SECTOR_SIZE];
53*2212Sartem 	int		hs_pvd_sec_no;
54*2212Sartem 	char		iso_buf[ISO_SECTOR_SIZE];
55*2212Sartem 	int		iso_pvd_sec_no;
56*2212Sartem 	char		unix_buf[ISO_SECTOR_SIZE];
57*2212Sartem 	int		unix_pvd_sec_no;
58*2212Sartem 	int		cdroff;
59*2212Sartem 	int		cd_type;
60*2212Sartem } fstyp_hsfs_t;
61*2212Sartem 
62*2212Sartem #define	GETCDSECTOR(h, buf, secno, nosec) (getdisk(h, buf, \
63*2212Sartem 	((secno)+(h)->cdroff)*ISO_SECTOR_SIZE, \
640Sstevel@tonic-gate 	(nosec)*ISO_SECTOR_SIZE))
650Sstevel@tonic-gate 
66*2212Sartem #define	NELEM(a)	sizeof (a) / sizeof (*(a))
670Sstevel@tonic-gate 
68*2212Sartem static int	ckvoldesc(fstyp_hsfs_t *h, int *cd_type);
69*2212Sartem static int	findhsvol(fstyp_hsfs_t *h, char *volp);
70*2212Sartem static int	findisovol(fstyp_hsfs_t *h, char *volp);
71*2212Sartem static int	findunixvol(fstyp_hsfs_t *h, char *volp);
72*2212Sartem static char	*get_old_name(char *new);
73*2212Sartem static int	rdev_is_a_cd(int rdevfd);
74*2212Sartem static int	getdisk(fstyp_hsfs_t *h, char *buf, int daddr, int size);
75*2212Sartem static void	copy_string(char *d, char *s, int maxlen);
76*2212Sartem static int	is_hsfs(fstyp_hsfs_t *h);
77*2212Sartem static int	get_attr(fstyp_hsfs_t *h);
78*2212Sartem 
79*2212Sartem int	fstyp_mod_init(int fd, off_t offset, fstyp_mod_handle_t *handle);
80*2212Sartem void	fstyp_mod_fini(fstyp_mod_handle_t handle);
81*2212Sartem int	fstyp_mod_ident(fstyp_mod_handle_t handle);
82*2212Sartem int	fstyp_mod_get_attr(fstyp_mod_handle_t handle, nvlist_t **attrp);
83*2212Sartem int	fstyp_mod_dump(fstyp_mod_handle_t handle, FILE *fout, FILE *ferr);
84*2212Sartem 
850Sstevel@tonic-gate 
86452Sjkennedy int
fstyp_mod_init(int fd,off_t offset,fstyp_mod_handle_t * handle)87*2212Sartem fstyp_mod_init(int fd, off_t offset, fstyp_mod_handle_t *handle)
880Sstevel@tonic-gate {
89*2212Sartem 	fstyp_hsfs_t	*h = (fstyp_hsfs_t *)handle;
90*2212Sartem 
91*2212Sartem 	if (offset != 0) {
92*2212Sartem 		return (FSTYP_ERR_OFFSET);
93*2212Sartem 	}
94*2212Sartem 
95*2212Sartem 	if ((h = calloc(1, sizeof (fstyp_hsfs_t))) == NULL) {
96*2212Sartem 		return (FSTYP_ERR_NOMEM);
97*2212Sartem 	}
98*2212Sartem 	h->fd = fd;
99*2212Sartem 
100*2212Sartem 	*handle = (fstyp_mod_handle_t)h;
101*2212Sartem 	return (0);
102*2212Sartem }
103*2212Sartem 
104*2212Sartem void
fstyp_mod_fini(fstyp_mod_handle_t handle)105*2212Sartem fstyp_mod_fini(fstyp_mod_handle_t handle)
106*2212Sartem {
107*2212Sartem 	fstyp_hsfs_t	*h = (fstyp_hsfs_t *)handle;
1080Sstevel@tonic-gate 
109*2212Sartem 	if (h->attr == NULL) {
110*2212Sartem 		nvlist_free(h->attr);
111*2212Sartem 		h->attr = NULL;
112*2212Sartem 	}
113*2212Sartem 	free(h);
114*2212Sartem }
115*2212Sartem 
116*2212Sartem int
fstyp_mod_ident(fstyp_mod_handle_t handle)117*2212Sartem fstyp_mod_ident(fstyp_mod_handle_t handle)
118*2212Sartem {
119*2212Sartem 	fstyp_hsfs_t *h = (fstyp_hsfs_t *)handle;
120*2212Sartem 
121*2212Sartem 	return (is_hsfs(h));
122*2212Sartem }
123*2212Sartem 
124*2212Sartem int
fstyp_mod_get_attr(fstyp_mod_handle_t handle,nvlist_t ** attrp)125*2212Sartem fstyp_mod_get_attr(fstyp_mod_handle_t handle, nvlist_t **attrp)
126*2212Sartem {
127*2212Sartem 	fstyp_hsfs_t	*h = (fstyp_hsfs_t *)handle;
128*2212Sartem 	int error;
129*2212Sartem 
130*2212Sartem 	if (h->attr == NULL) {
131*2212Sartem 		if (nvlist_alloc(&h->attr, NV_UNIQUE_NAME_TYPE, 0)) {
132*2212Sartem 			return (FSTYP_ERR_NOMEM);
133*2212Sartem 		}
134*2212Sartem 		if ((error = get_attr(h)) != 0) {
135*2212Sartem 			nvlist_free(h->attr);
136*2212Sartem 			h->attr = NULL;
137*2212Sartem 			return (error);
1380Sstevel@tonic-gate 		}
1390Sstevel@tonic-gate 	}
1400Sstevel@tonic-gate 
141*2212Sartem 	*attrp = h->attr;
142*2212Sartem 	return (0);
143*2212Sartem }
144*2212Sartem 
145*2212Sartem /* ARGSUSED */
146*2212Sartem int
fstyp_mod_dump(fstyp_mod_handle_t handle,FILE * fout,FILE * ferr)147*2212Sartem fstyp_mod_dump(fstyp_mod_handle_t handle, FILE *fout, FILE *ferr)
148*2212Sartem {
149*2212Sartem 	int		error;
150*2212Sartem 	nvlist_t	*attr;
151*2212Sartem 	nvpair_t	*elem = NULL;
152*2212Sartem 	char		*str_value;
153*2212Sartem 	uint64_t	uint64_value;
154*2212Sartem 	char		*name;
155*2212Sartem 
156*2212Sartem 	if ((error = fstyp_mod_get_attr(handle, &attr)) != 0) {
157*2212Sartem 		return (error);
1580Sstevel@tonic-gate 	}
159*2212Sartem 	while ((elem = nvlist_next_nvpair(attr, elem)) != NULL) {
160*2212Sartem 		/* format is special */
161*2212Sartem 		if (strcmp(nvpair_name(elem), "format") == 0) {
162*2212Sartem 			(void) nvpair_value_string(elem, &str_value);
163*2212Sartem 			if (strcmp(str_value,
164*2212Sartem 			    "ISO 9660 with UNIX extension") == 0) {
165*2212Sartem 				(void) fprintf(fout,
166*2212Sartem 				    "CD-ROM is in ISO 9660 format with"
167*2212Sartem 				    " UNIX extension\n");
168*2212Sartem 			} else {
169*2212Sartem 				(void) fprintf(fout, "CD-ROM is in %s"
170*2212Sartem 				    " format\n", str_value);
171*2212Sartem 			}
172*2212Sartem 			continue;
173*2212Sartem 		}
174*2212Sartem 		if ((name = get_old_name(nvpair_name(elem))) == NULL) {
175*2212Sartem 			continue;
176*2212Sartem 		}
177*2212Sartem 		if (nvpair_type(elem) == DATA_TYPE_STRING) {
178*2212Sartem 			(void) nvpair_value_string(elem, &str_value);
179*2212Sartem 			(void) fprintf(fout, "%s: %s\n", name, str_value);
180*2212Sartem 		} else if (nvpair_type(elem) == DATA_TYPE_UINT64) {
181*2212Sartem 			(void) nvpair_value_uint64(elem, &uint64_value);
182*2212Sartem 			(void) fprintf(fout, "%s %llu\n",
183*2212Sartem 			    name, (u_longlong_t)uint64_value);
184*2212Sartem 		}
185*2212Sartem 	}
1860Sstevel@tonic-gate 
187452Sjkennedy 	return (0);
1880Sstevel@tonic-gate }
1890Sstevel@tonic-gate 
190*2212Sartem static char *
get_old_name(char * new)191*2212Sartem get_old_name(char *new)
1920Sstevel@tonic-gate {
193*2212Sartem 	static char	*map[] = {
194*2212Sartem 		"system_id",		"System id",
195*2212Sartem 		"volume_id",		"Volume id",
196*2212Sartem 		"volume_set_id",	"Volume set id",
197*2212Sartem 		"publisher_id",		"Publisher id",
198*2212Sartem 		"data_preparer_id",	"Data preparer id",
199*2212Sartem 		"application_id",	"Application id",
200*2212Sartem 		"copyright_file_id",	"Copyright File id",
201*2212Sartem 		"abstract_file_id",	"Abstract File id",
202*2212Sartem 		"bibliographic_file_id", "Bibliographic File id",
203*2212Sartem 		"volume_set_size",	"Volume set size is",
204*2212Sartem 		"volume_set_sequence_number", "Volume set sequence number is",
205*2212Sartem 		"logical_block_size",	"Logical block size is",
206*2212Sartem 		"volume_size",		"Volume size is"
207*2212Sartem 	};
208*2212Sartem 	int	i;
209*2212Sartem 	char	*old = NULL;
210*2212Sartem 
211*2212Sartem 	for (i = 0; i < NELEM(map) / 2; i++) {
212*2212Sartem 		if (strcmp(new, map[i * 2]) == 0) {
213*2212Sartem 			old = map[i * 2 + 1];
214*2212Sartem 			break;
215*2212Sartem 		}
216*2212Sartem 	}
217*2212Sartem 	return (old);
2180Sstevel@tonic-gate }
2190Sstevel@tonic-gate 
2200Sstevel@tonic-gate /*
2210Sstevel@tonic-gate  * findhsvol: check if the disk is in high sierra format
2220Sstevel@tonic-gate  *            return(1) if found, (0) otherwise
2230Sstevel@tonic-gate  *	      if found, volp will point to the descriptor
2240Sstevel@tonic-gate  *
2250Sstevel@tonic-gate  */
226*2212Sartem static int
findhsvol(fstyp_hsfs_t * h,char * volp)227*2212Sartem findhsvol(fstyp_hsfs_t *h, char *volp)
2280Sstevel@tonic-gate {
229*2212Sartem 	int secno;
230*2212Sartem 	int i;
231*2212Sartem 	int err;
2320Sstevel@tonic-gate 
2330Sstevel@tonic-gate 	secno = HS_VOLDESC_SEC;
234*2212Sartem 	if ((err = GETCDSECTOR(h, volp, secno++, 1)) != 0) {
235*2212Sartem 		return (err);
236*2212Sartem 	}
2370Sstevel@tonic-gate 	while (HSV_DESC_TYPE(volp) != VD_EOV) {
2380Sstevel@tonic-gate 		for (i = 0; i < HSV_ID_STRLEN; i++)
2390Sstevel@tonic-gate 			if (HSV_STD_ID(volp)[i] != HSV_ID_STRING[i])
2400Sstevel@tonic-gate 				goto cantfind;
2410Sstevel@tonic-gate 		if (HSV_STD_VER(volp) != HSV_ID_VER)
2420Sstevel@tonic-gate 			goto cantfind;
2430Sstevel@tonic-gate 		switch (HSV_DESC_TYPE(volp)) {
2440Sstevel@tonic-gate 		case VD_SFS:
245*2212Sartem 			h->hs_pvd_sec_no = secno-1;
246*2212Sartem 			return (0);
2470Sstevel@tonic-gate 		case VD_EOV:
2480Sstevel@tonic-gate 			goto cantfind;
2490Sstevel@tonic-gate 		}
250*2212Sartem 		if ((err = GETCDSECTOR(h, volp, secno++, 1)) != 0) {
251*2212Sartem 			return (err);
252*2212Sartem 		}
2530Sstevel@tonic-gate 	}
2540Sstevel@tonic-gate cantfind:
255*2212Sartem 	return (FSTYP_ERR_NO_MATCH);
2560Sstevel@tonic-gate }
2570Sstevel@tonic-gate 
2580Sstevel@tonic-gate /*
2590Sstevel@tonic-gate  * findisovol: check if the disk is in ISO 9660 format
2600Sstevel@tonic-gate  *            return(1) if found, (0) otherwise
2610Sstevel@tonic-gate  *	      if found, volp will point to the descriptor
2620Sstevel@tonic-gate  *
2630Sstevel@tonic-gate  */
264*2212Sartem static int
findisovol(fstyp_hsfs_t * h,char * volp)265*2212Sartem findisovol(fstyp_hsfs_t *h, char *volp)
2660Sstevel@tonic-gate {
267*2212Sartem 	int secno;
268*2212Sartem 	int i;
269*2212Sartem 	int err;
2700Sstevel@tonic-gate 
2710Sstevel@tonic-gate 	secno = ISO_VOLDESC_SEC;
272*2212Sartem 	if ((err = GETCDSECTOR(h, volp, secno++, 1)) != 0) {
273*2212Sartem 		return (err);
274*2212Sartem 	}
2750Sstevel@tonic-gate 	while (ISO_DESC_TYPE(volp) != ISO_VD_EOV) {
2760Sstevel@tonic-gate 		for (i = 0; i < ISO_ID_STRLEN; i++)
2770Sstevel@tonic-gate 			if (ISO_STD_ID(volp)[i] != ISO_ID_STRING[i])
2780Sstevel@tonic-gate 				goto cantfind;
2790Sstevel@tonic-gate 		if (ISO_STD_VER(volp) != ISO_ID_VER)
2800Sstevel@tonic-gate 			goto cantfind;
2810Sstevel@tonic-gate 		switch (ISO_DESC_TYPE(volp)) {
2820Sstevel@tonic-gate 		case ISO_VD_PVD:
283*2212Sartem 			h->iso_pvd_sec_no = secno-1;
284*2212Sartem 			return (0);
2850Sstevel@tonic-gate 		case ISO_VD_EOV:
2860Sstevel@tonic-gate 			goto cantfind;
2870Sstevel@tonic-gate 		}
288*2212Sartem 		if ((err = GETCDSECTOR(h, volp, secno++, 1)) != 0) {
289*2212Sartem 			return (err);
290*2212Sartem 		}
2910Sstevel@tonic-gate 	}
2920Sstevel@tonic-gate cantfind:
293*2212Sartem 	return (FSTYP_ERR_NO_MATCH);
2940Sstevel@tonic-gate }
2950Sstevel@tonic-gate 
2960Sstevel@tonic-gate /*
2970Sstevel@tonic-gate  * findunixvol: check if the disk is in UNIX extension format
2980Sstevel@tonic-gate  *            return(1) if found, (0) otherwise
2990Sstevel@tonic-gate  *	      if found, volp will point to the descriptor
3000Sstevel@tonic-gate  *
3010Sstevel@tonic-gate  */
302*2212Sartem static int
findunixvol(fstyp_hsfs_t * h,char * volp)303*2212Sartem findunixvol(fstyp_hsfs_t *h, char *volp)
3040Sstevel@tonic-gate {
305*2212Sartem 	int secno;
306*2212Sartem 	int i;
307*2212Sartem 	int err;
3080Sstevel@tonic-gate 
3090Sstevel@tonic-gate 	secno = ISO_VOLDESC_SEC;
310*2212Sartem 	if ((err = GETCDSECTOR(h, volp, secno++, 1)) != 0) {
311*2212Sartem 		return (err);
312*2212Sartem 	}
3130Sstevel@tonic-gate 	while (ISO_DESC_TYPE(volp) != ISO_VD_EOV) {
3140Sstevel@tonic-gate 		for (i = 0; i < ISO_ID_STRLEN; i++)
3150Sstevel@tonic-gate 			if (ISO_STD_ID(volp)[i] != ISO_ID_STRING[i])
3160Sstevel@tonic-gate 				goto cantfind;
3170Sstevel@tonic-gate 		if (ISO_STD_VER(volp) != ISO_ID_VER)
3180Sstevel@tonic-gate 			goto cantfind;
3190Sstevel@tonic-gate 		switch (ISO_DESC_TYPE(volp)) {
3200Sstevel@tonic-gate 		case ISO_VD_UNIX:
321*2212Sartem 			h->unix_pvd_sec_no = secno-1;
322*2212Sartem 			return (0);
3230Sstevel@tonic-gate 		case ISO_VD_EOV:
3240Sstevel@tonic-gate 			goto cantfind;
3250Sstevel@tonic-gate 		}
326*2212Sartem 		if ((err = GETCDSECTOR(h, volp, secno++, 1)) != 0) {
327*2212Sartem 			return (err);
328*2212Sartem 		}
3290Sstevel@tonic-gate 	}
3300Sstevel@tonic-gate cantfind:
331*2212Sartem 	return (FSTYP_ERR_NO_MATCH);
3320Sstevel@tonic-gate }
3330Sstevel@tonic-gate 
334*2212Sartem static int
ckvoldesc(fstyp_hsfs_t * h,int * cd_type)335*2212Sartem ckvoldesc(fstyp_hsfs_t *h, int *cd_type)
3360Sstevel@tonic-gate {
337*2212Sartem 	int	err;
3380Sstevel@tonic-gate 
339*2212Sartem 	if ((err = findhsvol(h, h->hs_buf)) == 0) {
340*2212Sartem 		*cd_type = 0;
341*2212Sartem 	} else if ((err = findisovol(h, h->iso_buf)) == 0) {
342*2212Sartem 		if (findunixvol(h, h->unix_buf) == 0) {
343*2212Sartem 			*cd_type = 2;
344*2212Sartem 		} else {
345*2212Sartem 			*cd_type = 1;
346*2212Sartem 		}
347452Sjkennedy 	} else {
348*2212Sartem 		*cd_type = -1;
3490Sstevel@tonic-gate 	}
3500Sstevel@tonic-gate 
351*2212Sartem 	return (err);
3520Sstevel@tonic-gate }
3530Sstevel@tonic-gate 
354*2212Sartem static int
is_hsfs(fstyp_hsfs_t * h)355*2212Sartem is_hsfs(fstyp_hsfs_t *h)
3560Sstevel@tonic-gate {
357*2212Sartem #ifdef CDROMREADOFFSET
3580Sstevel@tonic-gate 	int err;
3590Sstevel@tonic-gate 
360*2212Sartem 	if (rdev_is_a_cd(h->fd)) {
361*2212Sartem 		err = ioctl(h->fd, CDROMREADOFFSET, &h->cdroff);
3620Sstevel@tonic-gate 		if (err == -1)
3630Sstevel@tonic-gate 			/*
3640Sstevel@tonic-gate 			 *  This device doesn't support this ioctl.
3650Sstevel@tonic-gate 			 *  That's OK.
3660Sstevel@tonic-gate 			 */
367*2212Sartem 			h->cdroff = 0;
3680Sstevel@tonic-gate 	}
3690Sstevel@tonic-gate #endif
3700Sstevel@tonic-gate 	/* check volume descriptor */
371*2212Sartem 	return (ckvoldesc(h, &h->cd_type));
3720Sstevel@tonic-gate }
3730Sstevel@tonic-gate 
374*2212Sartem #define	ADD_STRING(h, name, value) \
375*2212Sartem 	if (nvlist_add_string(h->attr, name, value) != 0) { \
376*2212Sartem 		return (FSTYP_ERR_NOMEM); \
377*2212Sartem 	}
378*2212Sartem 
379*2212Sartem #define	ADD_UINT64(h, name, value) \
380*2212Sartem 	if (nvlist_add_uint64(h->attr, name, value) != 0) { \
381*2212Sartem 		return (FSTYP_ERR_NOMEM); \
382*2212Sartem 	}
383*2212Sartem 
384*2212Sartem #define	ADD_BOOL(h, name, value) \
385*2212Sartem 	if (nvlist_add_boolean_value(h->attr, name, value) != 0) { \
386*2212Sartem 		return (FSTYP_ERR_NOMEM); \
387*2212Sartem 	}
388*2212Sartem 
389*2212Sartem static int
get_attr(fstyp_hsfs_t * h)390*2212Sartem get_attr(fstyp_hsfs_t *h)
3910Sstevel@tonic-gate {
3920Sstevel@tonic-gate 	char *sysid;
3930Sstevel@tonic-gate 	char *volid;
3940Sstevel@tonic-gate 	char *volsetid;
3950Sstevel@tonic-gate 	char *pubid;
3960Sstevel@tonic-gate 	char *prepid;
3970Sstevel@tonic-gate 	char *applid;
3980Sstevel@tonic-gate 	char *copyfile;
3990Sstevel@tonic-gate 	char *absfile;
4000Sstevel@tonic-gate 	char *bibfile;
4010Sstevel@tonic-gate 	int volsetsize;
4020Sstevel@tonic-gate 	int volsetseq;
4030Sstevel@tonic-gate 	int blksize;
4040Sstevel@tonic-gate 	int volsize;
405*2212Sartem 	char s[256];
4060Sstevel@tonic-gate 
407*2212Sartem 	switch (h->cd_type) {
4080Sstevel@tonic-gate 	case 0:
409*2212Sartem 		ADD_STRING(h, "format", "High Sierra");
410*2212Sartem 		ADD_STRING(h, "gen_version", "High Sierra");
411*2212Sartem 		sysid = (char *)HSV_sys_id(h->hs_buf);
412*2212Sartem 		volid = (char *)HSV_vol_id(h->hs_buf);
413*2212Sartem 		volsetid = (char *)HSV_vol_set_id(h->hs_buf);
414*2212Sartem 		pubid = (char *)HSV_pub_id(h->hs_buf);
415*2212Sartem 		prepid = (char *)HSV_prep_id(h->hs_buf);
416*2212Sartem 		applid = (char *)HSV_appl_id(h->hs_buf);
417*2212Sartem 		copyfile = (char *)HSV_copyr_id(h->hs_buf);
418*2212Sartem 		absfile = (char *)HSV_abstr_id(h->hs_buf);
419452Sjkennedy 		bibfile = NULL;
420*2212Sartem 		volsetsize = HSV_SET_SIZE(h->hs_buf);
421*2212Sartem 		volsetseq = HSV_SET_SEQ(h->hs_buf);
422*2212Sartem 		blksize = HSV_BLK_SIZE(h->hs_buf);
423*2212Sartem 		volsize = HSV_VOL_SIZE(h->hs_buf);
4240Sstevel@tonic-gate 		break;
4250Sstevel@tonic-gate 	case 1:
426*2212Sartem 		ADD_STRING(h, "format", "ISO 9660");
427*2212Sartem 		ADD_STRING(h, "gen_version", "ISO 9660");
428*2212Sartem 		sysid = (char *)ISO_sys_id(h->iso_buf);
429*2212Sartem 		volid = (char *)ISO_vol_id(h->iso_buf);
430*2212Sartem 		volsetid = (char *)ISO_vol_set_id(h->iso_buf);
431*2212Sartem 		pubid = (char *)ISO_pub_id(h->iso_buf);
432*2212Sartem 		prepid = (char *)ISO_prep_id(h->iso_buf);
433*2212Sartem 		applid = (char *)ISO_appl_id(h->iso_buf);
434*2212Sartem 		copyfile = (char *)ISO_copyr_id(h->iso_buf);
435*2212Sartem 		absfile = (char *)ISO_abstr_id(h->iso_buf);
436*2212Sartem 		bibfile = (char *)ISO_bibli_id(h->iso_buf);
437*2212Sartem 		volsetsize = ISO_SET_SIZE(h->iso_buf);
438*2212Sartem 		volsetseq = ISO_SET_SEQ(h->iso_buf);
439*2212Sartem 		blksize = ISO_BLK_SIZE(h->iso_buf);
440*2212Sartem 		volsize = ISO_VOL_SIZE(h->iso_buf);
4410Sstevel@tonic-gate 		break;
4420Sstevel@tonic-gate 	case 2:
443*2212Sartem 		ADD_STRING(h, "format", "ISO 9660 with UNIX extension");
444*2212Sartem 		ADD_STRING(h, "gen_version", "ISO 9660 with UNIX extension");
445*2212Sartem 		sysid = (char *)ISO_sys_id(h->unix_buf);
446*2212Sartem 		volid = (char *)ISO_vol_id(h->unix_buf);
447*2212Sartem 		volsetid = (char *)ISO_vol_set_id(h->unix_buf);
448*2212Sartem 		pubid = (char *)ISO_pub_id(h->unix_buf);
449*2212Sartem 		prepid = (char *)ISO_prep_id(h->unix_buf);
450*2212Sartem 		applid = (char *)ISO_appl_id(h->unix_buf);
451*2212Sartem 		copyfile = (char *)ISO_copyr_id(h->unix_buf);
452*2212Sartem 		absfile = (char *)ISO_abstr_id(h->unix_buf);
453*2212Sartem 		bibfile = (char *)ISO_bibli_id(h->unix_buf);
454*2212Sartem 		volsetsize = ISO_SET_SIZE(h->unix_buf);
455*2212Sartem 		volsetseq = ISO_SET_SEQ(h->unix_buf);
456*2212Sartem 		blksize = ISO_BLK_SIZE(h->unix_buf);
457*2212Sartem 		volsize = ISO_VOL_SIZE(h->unix_buf);
4580Sstevel@tonic-gate 		break;
4590Sstevel@tonic-gate 	default:
460*2212Sartem 		return (FSTYP_ERR_NO_MATCH);
4610Sstevel@tonic-gate 	}
462*2212Sartem 
463*2212Sartem 	copy_string(s, sysid, 32);
464*2212Sartem 	ADD_STRING(h, "system_id", s);
465*2212Sartem 	copy_string(s, volid, 32);
466*2212Sartem 	ADD_STRING(h, "volume_id", s);
467*2212Sartem 	ADD_STRING(h, "gen_volume_label", s);
468*2212Sartem 	copy_string(s, volsetid, 128);
469*2212Sartem 	ADD_STRING(h, "volume_set_id", s);
470*2212Sartem 	copy_string(s, pubid, 128);
471*2212Sartem 	ADD_STRING(h, "publisher_id", s);
472*2212Sartem 	copy_string(s, prepid, 128);
473*2212Sartem 	ADD_STRING(h, "data_preparer_id", s);
474*2212Sartem 	copy_string(s, applid, 128);
475*2212Sartem 	ADD_STRING(h, "application_id", s);
476*2212Sartem 	copy_string(s, copyfile, 37);
477*2212Sartem 	ADD_STRING(h, "copyright_file_id", s);
478*2212Sartem 	copy_string(s, absfile, 37);
479*2212Sartem 	ADD_STRING(h, "abstract_file_id", s);
480*2212Sartem 	copy_string(s, bibfile, 37);
481*2212Sartem 	ADD_STRING(h, "bibliographic_file_id", s);
482*2212Sartem 	ADD_UINT64(h, "volume_set_size", volsetsize);
483*2212Sartem 	ADD_UINT64(h, "volume_set_sequence_number", volsetseq);
484*2212Sartem 	ADD_UINT64(h, "logical_block_size", blksize);
485*2212Sartem 	ADD_UINT64(h, "volume_size", volsize);
486*2212Sartem 	ADD_BOOL(h, "gen_clean", B_TRUE);
487*2212Sartem 
488*2212Sartem 	return (0);
4890Sstevel@tonic-gate }
4900Sstevel@tonic-gate 
491452Sjkennedy static void
copy_string(char * d,char * s,int maxlen)492*2212Sartem copy_string(char *d, char *s, int maxlen)
4930Sstevel@tonic-gate {
494452Sjkennedy 	int i;
4950Sstevel@tonic-gate 
4960Sstevel@tonic-gate 	/* strip off trailing zeros */
497*2212Sartem 	for (i = maxlen-1; i >= 0; i--) {
498*2212Sartem 		if (s[i] != ' ') {
499*2212Sartem 			break;
500*2212Sartem 		}
501*2212Sartem 	}
5020Sstevel@tonic-gate 
5030Sstevel@tonic-gate 	maxlen = i+1;
504*2212Sartem 	for (i = 0; i < maxlen; i++) {
505*2212Sartem 		*d++ = s[i];
506*2212Sartem 	}
507*2212Sartem 	*d++ = '\0';
5080Sstevel@tonic-gate }
5090Sstevel@tonic-gate 
510452Sjkennedy /* readdisk - read from cdrom image file */
511*2212Sartem static int
getdisk(fstyp_hsfs_t * h,char * buf,int daddr,int size)512*2212Sartem getdisk(fstyp_hsfs_t *h, char *buf, int daddr, int size)
5130Sstevel@tonic-gate {
514*2212Sartem 	if (lseek(h->fd, daddr, L_SET) == -1) {
515*2212Sartem 		return (FSTYP_ERR_IO);
516452Sjkennedy 	}
517*2212Sartem 	if (read(h->fd, buf, size) != size) {
518*2212Sartem 		return (FSTYP_ERR_IO);
519452Sjkennedy 	}
520*2212Sartem 	return (0);
5210Sstevel@tonic-gate }
5220Sstevel@tonic-gate 
5230Sstevel@tonic-gate /*
5240Sstevel@tonic-gate  * rdev_is_a_cd  - return TRUE if the raw device identified by
525452Sjkennedy  *		      a file descriptor is a CDROM device.
5260Sstevel@tonic-gate  *
5270Sstevel@tonic-gate  *		      return FALSE if the device can't be accessed
5280Sstevel@tonic-gate  *		      or is not a CDROM.
5290Sstevel@tonic-gate  */
5300Sstevel@tonic-gate static int
rdev_is_a_cd(int rdevfd)5310Sstevel@tonic-gate rdev_is_a_cd(int rdevfd)
5320Sstevel@tonic-gate {
5330Sstevel@tonic-gate 	struct dk_cinfo dkc;
5340Sstevel@tonic-gate 
535452Sjkennedy 	if (ioctl(rdevfd, DKIOCINFO, &dkc) < 0)
536452Sjkennedy 		return (0);
537452Sjkennedy 	if (dkc.dki_ctype == DKC_CDROM)
538452Sjkennedy 		return (1);
5390Sstevel@tonic-gate 	else
5400Sstevel@tonic-gate 		return (0);
5410Sstevel@tonic-gate }
542