4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
28 * labelit [option=value ...] cdimage
30 * sysid system identifier (a characters, 32 max)
31 * volid: volume identifier (d-characters, 32 max)
32 * volsetid: volume set identifier (d-characters, 128 max)
33 * pubid: publisher identifier (d-characters, 128 max)
34 * prepid: data preparer identifier (d-charcter, 128 max)
35 * applid: application identifier (d-charcter, 128 max)
36 * copyfile: copyright file identifier (d-characters, 128 max)
37 * absfile: abstract file identifier (d-characters, 37 max)
38 * bibfile: bibliographic file identifier (d-charcters, 37 max)
43 #include <sys/param.h>
46 #include <sys/types.h>
50 #include <sys/fs/hsfs_isospec.h>
51 #include <sys/fs/hsfs_spec.h>
53 #define PUTSECTOR(buf, secno, nosec) (putdisk(buf, (secno)*ISO_SECTOR_SIZE, \
54 (nosec)*ISO_SECTOR_SIZE))
55 #define GETSECTOR(buf, secno, nosec) (getdisk(buf, (secno)*ISO_SECTOR_SIZE, \
56 (nosec)*ISO_SECTOR_SIZE))
59 #define MAXERRSTRNG 80
60 char errstrng
[MAXERRSTRNG
];
65 char hs_buf
[ISO_SECTOR_SIZE
];
67 char iso_buf
[ISO_SECTOR_SIZE
];
69 char unix_buf
[ISO_SECTOR_SIZE
];
86 static int match(char *s
);
87 static void usage(void);
88 static void putdisk(char *buf
, int daddr
, int size
);
89 static void getdisk(char *buf
, int daddr
, int size
);
90 static void prntstring(char *heading
, char *s
, int maxlen
);
91 static void copystring(char *from
, char *to
, int size
);
92 static void prntlabel(void);
93 static void updatelabel(void);
94 static void ckvoldesc(void);
97 main(int argc
, char **argv
)
102 strcpy(callname
, argv
[0]);
103 for (c
= 1; c
< argc
; c
++) {
105 if (match("sysid=")) {
109 if (match("volid=")) {
113 if (match("volsetid=")) {
117 if (match("pubid=")) {
121 if (match("prepid=")) {
125 if (match("applid=")) {
129 if (match("copyfile=")) {
133 if (match("absfile=")) {
137 if (match("bibfile=")) {
143 /* the last argument must be the cdrom iamge file */
146 fprintf(stderr
, "%s: Illegal option %s in input\n",
151 /* open image file in read write only if necessary */
152 if (argc
== 2) openopt
= O_RDONLY
;
153 else openopt
= O_RDWR
;
155 if ((cdfd
= open(argv
[c
], openopt
)) < 0) {
156 if (strchr(argv
[c
], '=') ||
157 strchr(argv
[c
], '-')) {
160 sprintf(errstrng
, "%s: main: open(): ", callname
);
165 /* check volume descriptor */
169 fprintf(stderr
, "%s: unknown cdrom format label\n", callname
);
173 /* update label, if needed */
174 if (argc
!= 2) updatelabel();
176 /* print the (updated) image label */
186 fprintf(stderr
, "usage: %s [-F ufs] [option=value ...] cdimage\n",
192 * findhsvol: check if the disk is in high sierra format
193 * return(1) if found, (0) otherwise
194 * if found, volp will point to the descriptor
204 secno
= HS_VOLDESC_SEC
;
205 GETSECTOR(volp
, secno
++, 1);
206 while (HSV_DESC_TYPE(volp
) != VD_EOV
) {
207 for (i
= 0; i
< HSV_ID_STRLEN
; i
++)
208 if (HSV_STD_ID(volp
)[i
] != HSV_ID_STRING
[i
])
210 if (HSV_STD_VER(volp
) != HSV_ID_VER
)
212 switch (HSV_DESC_TYPE(volp
)) {
214 hs_pvd_sec_no
= secno
-1;
219 GETSECTOR(volp
, secno
++, 1);
226 * findisovol: check if the disk is in ISO 9660 format
227 * return(1) if found, (0) otherwise
228 * if found, volp will point to the descriptor
238 secno
= ISO_VOLDESC_SEC
;
239 GETSECTOR(volp
, secno
++, 1);
240 while (ISO_DESC_TYPE(volp
) != ISO_VD_EOV
) {
241 for (i
= 0; i
< ISO_ID_STRLEN
; i
++)
242 if (ISO_STD_ID(volp
)[i
] != ISO_ID_STRING
[i
])
244 if (ISO_STD_VER(volp
) != ISO_ID_VER
)
246 switch (ISO_DESC_TYPE(volp
)) {
248 iso_pvd_sec_no
= secno
-1;
253 GETSECTOR(volp
, secno
++, 1);
260 * findunixvol: check if the disk is in UNIX extension format
261 * return(1) if found, (0) otherwise
262 * if found, volp will point to the descriptor
272 secno
= ISO_VOLDESC_SEC
;
273 GETSECTOR(volp
, secno
++, 1);
274 while (ISO_DESC_TYPE(volp
) != ISO_VD_EOV
) {
275 for (i
= 0; i
< ISO_ID_STRLEN
; i
++)
276 if (ISO_STD_ID(volp
)[i
] != ISO_ID_STRING
[i
])
278 if (ISO_STD_VER(volp
) != ISO_ID_VER
)
280 switch (ISO_DESC_TYPE(volp
)) {
282 unix_pvd_sec_no
= secno
-1;
287 GETSECTOR(volp
, secno
++, 1);
296 if (findhsvol(hs_buf
))
298 else if (findisovol(iso_buf
)) {
299 if (findunixvol(unix_buf
))
312 copystring(sysid
, (char *)HSV_sys_id(hs_buf
), 32);
313 copystring(volid
, (char *)HSV_vol_id(hs_buf
), 32);
314 copystring(volsetid
, (char *)HSV_vol_set_id(hs_buf
), 128);
315 copystring(pubid
, (char *)HSV_pub_id(hs_buf
), 128);
316 copystring(prepid
, (char *)HSV_prep_id(hs_buf
), 128);
317 copystring(applid
, (char *)HSV_appl_id(hs_buf
), 128);
318 copystring(copyfile
, (char *)HSV_copyr_id(hs_buf
), 37);
319 copystring(absfile
, (char *)HSV_abstr_id(hs_buf
), 37);
320 PUTSECTOR(hs_buf
, hs_pvd_sec_no
, 1);
323 copystring(sysid
, (char *)ISO_sys_id(unix_buf
), 32);
324 copystring(volid
, (char *)ISO_vol_id(unix_buf
), 32);
325 copystring(volsetid
, (char *)ISO_vol_set_id(unix_buf
), 128);
326 copystring(pubid
, (char *)ISO_pub_id(unix_buf
), 128);
327 copystring(prepid
, (char *)ISO_prep_id(unix_buf
), 128);
328 copystring(applid
, (char *)ISO_appl_id(unix_buf
), 128);
329 copystring(copyfile
, (char *)ISO_copyr_id(unix_buf
), 37);
330 copystring(absfile
, (char *)ISO_abstr_id(unix_buf
), 37);
331 copystring(bibfile
, (char *)ISO_bibli_id(unix_buf
), 37);
332 PUTSECTOR(unix_buf
, unix_pvd_sec_no
, 1);
334 * after update unix volume descriptor,
335 * fall thru to update the iso primary vol descriptor
338 copystring(sysid
, (char *)ISO_sys_id(iso_buf
), 32);
339 copystring(volid
, (char *)ISO_vol_id(iso_buf
), 32);
340 copystring(volsetid
, (char *)ISO_vol_set_id(iso_buf
), 128);
341 copystring(pubid
, (char *)ISO_pub_id(iso_buf
), 128);
342 copystring(prepid
, (char *)ISO_prep_id(iso_buf
), 128);
343 copystring(applid
, (char *)ISO_appl_id(iso_buf
), 128);
344 copystring(copyfile
, (char *)ISO_copyr_id(iso_buf
), 37);
345 copystring(absfile
, (char *)ISO_abstr_id(iso_buf
), 37);
346 copystring(bibfile
, (char *)ISO_bibli_id(iso_buf
), 37);
347 PUTSECTOR(iso_buf
, iso_pvd_sec_no
, 1);
358 printf("CD-ROM is in High Sierra format\n");
359 sysid
= (char *)HSV_sys_id(hs_buf
);
360 volid
= (char *)HSV_vol_id(hs_buf
);
361 volsetid
= (char *)HSV_vol_set_id(hs_buf
);
362 pubid
= (char *)HSV_pub_id(hs_buf
);
363 prepid
= (char *)HSV_prep_id(hs_buf
);
364 applid
= (char *)HSV_appl_id(hs_buf
);
365 copyfile
= (char *)HSV_copyr_id(hs_buf
);
366 absfile
= (char *)HSV_abstr_id(hs_buf
);
368 volsetsize
= HSV_SET_SIZE(hs_buf
);
369 volsetseq
= HSV_SET_SEQ(hs_buf
);
370 blksize
= HSV_BLK_SIZE(hs_buf
);
371 volsize
= HSV_VOL_SIZE(hs_buf
);
374 printf("CD-ROM is in ISO 9660 format\n");
375 sysid
= (char *)ISO_sys_id(iso_buf
);
376 volid
= (char *)ISO_vol_id(iso_buf
);
377 volsetid
= (char *)ISO_vol_set_id(iso_buf
);
378 pubid
= (char *)ISO_pub_id(iso_buf
);
379 prepid
= (char *)ISO_prep_id(iso_buf
);
380 applid
= (char *)ISO_appl_id(iso_buf
);
381 copyfile
= (char *)ISO_copyr_id(iso_buf
);
382 absfile
= (char *)ISO_abstr_id(iso_buf
);
383 bibfile
= (char *)ISO_bibli_id(iso_buf
);
384 volsetsize
= ISO_SET_SIZE(iso_buf
);
385 volsetseq
= ISO_SET_SEQ(iso_buf
);
386 blksize
= ISO_BLK_SIZE(iso_buf
);
387 volsize
= ISO_VOL_SIZE(iso_buf
);
390 printf("CD-ROM is in ISO 9660 format with UNIX extension\n");
391 sysid
= (char *)ISO_sys_id(unix_buf
);
392 volid
= (char *)ISO_vol_id(unix_buf
);
393 volsetid
= (char *)ISO_vol_set_id(unix_buf
);
394 pubid
= (char *)ISO_pub_id(unix_buf
);
395 prepid
= (char *)ISO_prep_id(unix_buf
);
396 applid
= (char *)ISO_appl_id(unix_buf
);
397 copyfile
= (char *)ISO_copyr_id(unix_buf
);
398 absfile
= (char *)ISO_abstr_id(unix_buf
);
399 bibfile
= (char *)ISO_bibli_id(unix_buf
);
400 volsetsize
= ISO_SET_SIZE(unix_buf
);
401 volsetseq
= ISO_SET_SEQ(unix_buf
);
402 blksize
= ISO_BLK_SIZE(unix_buf
);
403 volsize
= ISO_VOL_SIZE(unix_buf
);
409 prntstring("System id", sysid
, 32);
411 prntstring("Volume id", volid
, 32);
412 /* read volume set id */
413 prntstring("Volume set id", volsetid
, 128);
415 prntstring("Publisher id", pubid
, 128);
416 /* data preparer id */
417 prntstring("Data preparer id", prepid
, 128);
419 prntstring("Application id", applid
, 128);
420 /* copyright file identifier */
421 prntstring("Copyright File id", copyfile
, 37);
422 /* Abstract file identifier */
423 prntstring("Abstract File id", absfile
, 37);
424 /* Bibliographic file identifier */
425 prntstring("Bibliographic File id", bibfile
, 37);
426 /* print volume set size */
427 printf("Volume set size is %d\n", volsetsize
);
428 /* print volume set sequnce number */
429 printf("Volume set sequence number is %d\n", volsetseq
);
430 /* print logical block size */
431 printf("Logical block size is %d\n", blksize
);
432 /* print volume size */
433 printf("Volume size is %d\n", volsize
);
437 copystring(char *from
, char *to
, int size
)
443 for (i
= 0; i
< size
; i
++) {
446 else *to
++ = *from
++;
448 for (; i
< size
; i
++) *to
++ = ' ';
452 prntstring(char *heading
, char *s
, int maxlen
)
457 if (heading
== NULL
|| s
== NULL
)
460 printf("%s: ", heading
);
462 /* strip off trailing zeros */
463 for (i
= maxlen
-1; i
>= 0; i
--)
468 for (i
= 0; i
< maxlen
; i
++)
491 /* readdisk - read from cdrom image file */
493 getdisk(char *buf
, int daddr
, int size
)
496 if (lseek(cdfd
, daddr
, L_SET
) == -1) {
497 sprintf(errstrng
, "%s: getdisk: lseek()", callname
);
501 if (read(cdfd
, buf
, size
) != size
) {
502 sprintf(errstrng
, "%s: getdisk: read()", callname
);
508 /* putdisk - write to cdrom image file */
510 putdisk(char *buf
, int daddr
, int size
)
513 if (lseek(cdfd
, daddr
, L_SET
) == -1) {
514 sprintf(errstrng
, "%s: putdisk: lseek()", callname
);
518 if (write(cdfd
, buf
, size
) != size
) {
519 sprintf(errstrng
, "%s: putdisk: write()", callname
);