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>
53 #include <sys/fs/hsfs_isospec.h>
54 #include <sys/fs/hsfs_spec.h>
56 #define PUTSECTOR(buf, secno, nosec) (putdisk(buf, (secno)*ISO_SECTOR_SIZE, \
57 (nosec)*ISO_SECTOR_SIZE))
58 #define GETSECTOR(buf, secno, nosec) (getdisk(buf, (secno)*ISO_SECTOR_SIZE, \
59 (nosec)*ISO_SECTOR_SIZE))
62 #define MAXERRSTRNG 80
63 char errstrng
[MAXERRSTRNG
];
68 char hs_buf
[ISO_SECTOR_SIZE
];
70 char iso_buf
[ISO_SECTOR_SIZE
];
72 char unix_buf
[ISO_SECTOR_SIZE
];
89 static int match(char *s
);
90 static void usage(void);
91 static void putdisk(char *buf
, int daddr
, int size
);
92 static void getdisk(char *buf
, int daddr
, int size
);
93 static void prntstring(char *heading
, char *s
, int maxlen
);
94 static void copystring(char *from
, char *to
, int size
);
95 static void prntlabel(void);
96 static void updatelabel(void);
97 static void ckvoldesc(void);
100 main(int argc
, char **argv
)
105 strcpy(callname
, argv
[0]);
106 for (c
= 1; c
< argc
; c
++) {
108 if (match("sysid=")) {
112 if (match("volid=")) {
116 if (match("volsetid=")) {
120 if (match("pubid=")) {
124 if (match("prepid=")) {
128 if (match("applid=")) {
132 if (match("copyfile=")) {
136 if (match("absfile=")) {
140 if (match("bibfile=")) {
146 /* the last argument must be the cdrom iamge file */
149 fprintf(stderr
, "%s: Illegal option %s in input\n",
154 /* open image file in read write only if necessary */
155 if (argc
== 2) openopt
= O_RDONLY
;
156 else openopt
= O_RDWR
;
158 if ((cdfd
= open(argv
[c
], openopt
)) < 0) {
159 if (strchr(argv
[c
], '=') ||
160 strchr(argv
[c
], '-')) {
163 sprintf(errstrng
, "%s: main: open(): ", callname
);
168 /* check volume descriptor */
172 fprintf(stderr
, "%s: unknown cdrom format label\n", callname
);
176 /* update label, if needed */
177 if (argc
!= 2) updatelabel();
179 /* print the (updated) image label */
189 fprintf(stderr
, "usage: %s [-F ufs] [option=value ...] cdimage\n",
195 * findhsvol: check if the disk is in high sierra format
196 * return(1) if found, (0) otherwise
197 * if found, volp will point to the descriptor
207 secno
= HS_VOLDESC_SEC
;
208 GETSECTOR(volp
, secno
++, 1);
209 while (HSV_DESC_TYPE(volp
) != VD_EOV
) {
210 for (i
= 0; i
< HSV_ID_STRLEN
; i
++)
211 if (HSV_STD_ID(volp
)[i
] != HSV_ID_STRING
[i
])
213 if (HSV_STD_VER(volp
) != HSV_ID_VER
)
215 switch (HSV_DESC_TYPE(volp
)) {
217 hs_pvd_sec_no
= secno
-1;
222 GETSECTOR(volp
, secno
++, 1);
229 * findisovol: check if the disk is in ISO 9660 format
230 * return(1) if found, (0) otherwise
231 * if found, volp will point to the descriptor
241 secno
= ISO_VOLDESC_SEC
;
242 GETSECTOR(volp
, secno
++, 1);
243 while (ISO_DESC_TYPE(volp
) != ISO_VD_EOV
) {
244 for (i
= 0; i
< ISO_ID_STRLEN
; i
++)
245 if (ISO_STD_ID(volp
)[i
] != ISO_ID_STRING
[i
])
247 if (ISO_STD_VER(volp
) != ISO_ID_VER
)
249 switch (ISO_DESC_TYPE(volp
)) {
251 iso_pvd_sec_no
= secno
-1;
256 GETSECTOR(volp
, secno
++, 1);
263 * findunixvol: check if the disk is in UNIX extension format
264 * return(1) if found, (0) otherwise
265 * if found, volp will point to the descriptor
275 secno
= ISO_VOLDESC_SEC
;
276 GETSECTOR(volp
, secno
++, 1);
277 while (ISO_DESC_TYPE(volp
) != ISO_VD_EOV
) {
278 for (i
= 0; i
< ISO_ID_STRLEN
; i
++)
279 if (ISO_STD_ID(volp
)[i
] != ISO_ID_STRING
[i
])
281 if (ISO_STD_VER(volp
) != ISO_ID_VER
)
283 switch (ISO_DESC_TYPE(volp
)) {
285 unix_pvd_sec_no
= secno
-1;
290 GETSECTOR(volp
, secno
++, 1);
299 if (findhsvol(hs_buf
))
301 else if (findisovol(iso_buf
)) {
302 if (findunixvol(unix_buf
))
315 copystring(sysid
, (char *)HSV_sys_id(hs_buf
), 32);
316 copystring(volid
, (char *)HSV_vol_id(hs_buf
), 32);
317 copystring(volsetid
, (char *)HSV_vol_set_id(hs_buf
), 128);
318 copystring(pubid
, (char *)HSV_pub_id(hs_buf
), 128);
319 copystring(prepid
, (char *)HSV_prep_id(hs_buf
), 128);
320 copystring(applid
, (char *)HSV_appl_id(hs_buf
), 128);
321 copystring(copyfile
, (char *)HSV_copyr_id(hs_buf
), 37);
322 copystring(absfile
, (char *)HSV_abstr_id(hs_buf
), 37);
323 PUTSECTOR(hs_buf
, hs_pvd_sec_no
, 1);
326 copystring(sysid
, (char *)ISO_sys_id(unix_buf
), 32);
327 copystring(volid
, (char *)ISO_vol_id(unix_buf
), 32);
328 copystring(volsetid
, (char *)ISO_vol_set_id(unix_buf
), 128);
329 copystring(pubid
, (char *)ISO_pub_id(unix_buf
), 128);
330 copystring(prepid
, (char *)ISO_prep_id(unix_buf
), 128);
331 copystring(applid
, (char *)ISO_appl_id(unix_buf
), 128);
332 copystring(copyfile
, (char *)ISO_copyr_id(unix_buf
), 37);
333 copystring(absfile
, (char *)ISO_abstr_id(unix_buf
), 37);
334 copystring(bibfile
, (char *)ISO_bibli_id(unix_buf
), 37);
335 PUTSECTOR(unix_buf
, unix_pvd_sec_no
, 1);
337 * after update unix volume descriptor,
338 * fall thru to update the iso primary vol descriptor
342 copystring(sysid
, (char *)ISO_sys_id(iso_buf
), 32);
343 copystring(volid
, (char *)ISO_vol_id(iso_buf
), 32);
344 copystring(volsetid
, (char *)ISO_vol_set_id(iso_buf
), 128);
345 copystring(pubid
, (char *)ISO_pub_id(iso_buf
), 128);
346 copystring(prepid
, (char *)ISO_prep_id(iso_buf
), 128);
347 copystring(applid
, (char *)ISO_appl_id(iso_buf
), 128);
348 copystring(copyfile
, (char *)ISO_copyr_id(iso_buf
), 37);
349 copystring(absfile
, (char *)ISO_abstr_id(iso_buf
), 37);
350 copystring(bibfile
, (char *)ISO_bibli_id(iso_buf
), 37);
351 PUTSECTOR(iso_buf
, iso_pvd_sec_no
, 1);
362 printf("CD-ROM is in High Sierra format\n");
363 sysid
= (char *)HSV_sys_id(hs_buf
);
364 volid
= (char *)HSV_vol_id(hs_buf
);
365 volsetid
= (char *)HSV_vol_set_id(hs_buf
);
366 pubid
= (char *)HSV_pub_id(hs_buf
);
367 prepid
= (char *)HSV_prep_id(hs_buf
);
368 applid
= (char *)HSV_appl_id(hs_buf
);
369 copyfile
= (char *)HSV_copyr_id(hs_buf
);
370 absfile
= (char *)HSV_abstr_id(hs_buf
);
372 volsetsize
= HSV_SET_SIZE(hs_buf
);
373 volsetseq
= HSV_SET_SEQ(hs_buf
);
374 blksize
= HSV_BLK_SIZE(hs_buf
);
375 volsize
= HSV_VOL_SIZE(hs_buf
);
378 printf("CD-ROM is in ISO 9660 format\n");
379 sysid
= (char *)ISO_sys_id(iso_buf
);
380 volid
= (char *)ISO_vol_id(iso_buf
);
381 volsetid
= (char *)ISO_vol_set_id(iso_buf
);
382 pubid
= (char *)ISO_pub_id(iso_buf
);
383 prepid
= (char *)ISO_prep_id(iso_buf
);
384 applid
= (char *)ISO_appl_id(iso_buf
);
385 copyfile
= (char *)ISO_copyr_id(iso_buf
);
386 absfile
= (char *)ISO_abstr_id(iso_buf
);
387 bibfile
= (char *)ISO_bibli_id(iso_buf
);
388 volsetsize
= ISO_SET_SIZE(iso_buf
);
389 volsetseq
= ISO_SET_SEQ(iso_buf
);
390 blksize
= ISO_BLK_SIZE(iso_buf
);
391 volsize
= ISO_VOL_SIZE(iso_buf
);
394 printf("CD-ROM is in ISO 9660 format with UNIX extension\n");
395 sysid
= (char *)ISO_sys_id(unix_buf
);
396 volid
= (char *)ISO_vol_id(unix_buf
);
397 volsetid
= (char *)ISO_vol_set_id(unix_buf
);
398 pubid
= (char *)ISO_pub_id(unix_buf
);
399 prepid
= (char *)ISO_prep_id(unix_buf
);
400 applid
= (char *)ISO_appl_id(unix_buf
);
401 copyfile
= (char *)ISO_copyr_id(unix_buf
);
402 absfile
= (char *)ISO_abstr_id(unix_buf
);
403 bibfile
= (char *)ISO_bibli_id(unix_buf
);
404 volsetsize
= ISO_SET_SIZE(unix_buf
);
405 volsetseq
= ISO_SET_SEQ(unix_buf
);
406 blksize
= ISO_BLK_SIZE(unix_buf
);
407 volsize
= ISO_VOL_SIZE(unix_buf
);
413 prntstring("System id", sysid
, 32);
415 prntstring("Volume id", volid
, 32);
416 /* read volume set id */
417 prntstring("Volume set id", volsetid
, 128);
419 prntstring("Publisher id", pubid
, 128);
420 /* data preparer id */
421 prntstring("Data preparer id", prepid
, 128);
423 prntstring("Application id", applid
, 128);
424 /* copyright file identifier */
425 prntstring("Copyright File id", copyfile
, 37);
426 /* Abstract file identifier */
427 prntstring("Abstract File id", absfile
, 37);
428 /* Bibliographic file identifier */
429 prntstring("Bibliographic File id", bibfile
, 37);
430 /* print volume set size */
431 printf("Volume set size is %d\n", volsetsize
);
432 /* print volume set sequnce number */
433 printf("Volume set sequence number is %d\n", volsetseq
);
434 /* print logical block size */
435 printf("Logical block size is %d\n", blksize
);
436 /* print volume size */
437 printf("Volume size is %d\n", volsize
);
441 copystring(char *from
, char *to
, int size
)
447 for (i
= 0; i
< size
; i
++) {
450 else *to
++ = *from
++;
452 for (; i
< size
; i
++) *to
++ = ' ';
456 prntstring(char *heading
, char *s
, int maxlen
)
461 if (heading
== NULL
|| s
== NULL
)
464 printf("%s: ", heading
);
466 /* strip off trailing zeros */
467 for (i
= maxlen
-1; i
>= 0; i
--)
472 for (i
= 0; i
< maxlen
; i
++)
495 /* readdisk - read from cdrom image file */
497 getdisk(char *buf
, int daddr
, int size
)
500 if (lseek(cdfd
, daddr
, L_SET
) == -1) {
501 sprintf(errstrng
, "%s: getdisk: lseek()", callname
);
505 if (read(cdfd
, buf
, size
) != size
) {
506 sprintf(errstrng
, "%s: getdisk: read()", callname
);
512 /* putdisk - write to cdrom image file */
514 putdisk(char *buf
, int daddr
, int size
)
517 if (lseek(cdfd
, daddr
, L_SET
) == -1) {
518 sprintf(errstrng
, "%s: putdisk: lseek()", callname
);
522 if (write(cdfd
, buf
, size
) != size
) {
523 sprintf(errstrng
, "%s: putdisk: write()", callname
);