iso9660.c revision 1.1 1 1.1 drochner /* $NetBSD: iso9660.c,v 1.1 2004/07/04 14:11:44 drochner Exp $ */
2 1.1 drochner
3 1.1 drochner #include <sys/types.h>
4 1.1 drochner #include <stdlib.h>
5 1.1 drochner #include <unistd.h>
6 1.1 drochner #include <string.h>
7 1.1 drochner #include <stdio.h>
8 1.1 drochner #include <err.h>
9 1.1 drochner #include <isofs/cd9660/iso.h>
10 1.1 drochner
11 1.1 drochner #include "mscdlabel.h"
12 1.1 drochner
13 1.1 drochner #define BLKSIZ ISO_DEFAULT_BLOCK_SIZE
14 1.1 drochner
15 1.1 drochner static void
16 1.1 drochner printinfo(struct iso_primary_descriptor *vd)
17 1.1 drochner {
18 1.1 drochner char label[32 + 1], date[] = "yyyy/mm/dd hh:mm", *d;
19 1.1 drochner
20 1.1 drochner strlcpy(label, vd->volume_id, sizeof(label));
21 1.1 drochner d = vd->creation_date;
22 1.1 drochner memcpy(date, d, 4); /* year */
23 1.1 drochner memcpy(date + 5, d + 4, 2); /* month */
24 1.1 drochner memcpy(date + 8, d + 6, 2); /* day */
25 1.1 drochner memcpy(date + 11, d + 8, 2); /* hour */
26 1.1 drochner memcpy(date + 14, d + 10, 2); /* min */
27 1.1 drochner printf("ISO filesystem, label \"%s\", creation time: %s\n",
28 1.1 drochner label, date);
29 1.1 drochner }
30 1.1 drochner
31 1.1 drochner int
32 1.1 drochner check_primary_vd(int fd, int start, int len)
33 1.1 drochner {
34 1.1 drochner int i, res, isiso;
35 1.1 drochner struct iso_primary_descriptor *vd;
36 1.1 drochner
37 1.1 drochner isiso = 0;
38 1.1 drochner vd = malloc(BLKSIZ);
39 1.1 drochner
40 1.1 drochner for (i = 16; (i < 100) && (i < len); i++) {
41 1.1 drochner res = pread(fd, vd, BLKSIZ, (start + i) * BLKSIZ);
42 1.1 drochner if (res < 0) {
43 1.1 drochner warn("read CD sector %d", start + i);
44 1.1 drochner break;
45 1.1 drochner }
46 1.1 drochner
47 1.1 drochner if (memcmp(vd->id, ISO_STANDARD_ID, sizeof(vd->id)))
48 1.1 drochner continue;
49 1.1 drochner if (isonum_711(vd->type) == ISO_VD_PRIMARY) {
50 1.1 drochner printinfo(vd);
51 1.1 drochner isiso = 1;
52 1.1 drochner break;
53 1.1 drochner } else if (isonum_711(vd->type) == ISO_VD_END)
54 1.1 drochner break;
55 1.1 drochner }
56 1.1 drochner
57 1.1 drochner free(vd);
58 1.1 drochner return (isiso);
59 1.1 drochner }
60