1 1.2 drochner /* $NetBSD: iso9660.c,v 1.2 2005/09/14 09:41:24 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.2 drochner /* strip trailing blanks */ 22 1.2 drochner d = label + strlen(label); 23 1.2 drochner while (d > label && *(d - 1) == ' ') 24 1.2 drochner d--; 25 1.2 drochner *d = '\0'; 26 1.2 drochner 27 1.1 drochner d = vd->creation_date; 28 1.1 drochner memcpy(date, d, 4); /* year */ 29 1.1 drochner memcpy(date + 5, d + 4, 2); /* month */ 30 1.1 drochner memcpy(date + 8, d + 6, 2); /* day */ 31 1.1 drochner memcpy(date + 11, d + 8, 2); /* hour */ 32 1.1 drochner memcpy(date + 14, d + 10, 2); /* min */ 33 1.1 drochner printf("ISO filesystem, label \"%s\", creation time: %s\n", 34 1.1 drochner label, date); 35 1.1 drochner } 36 1.1 drochner 37 1.1 drochner int 38 1.1 drochner check_primary_vd(int fd, int start, int len) 39 1.1 drochner { 40 1.1 drochner int i, res, isiso; 41 1.1 drochner struct iso_primary_descriptor *vd; 42 1.1 drochner 43 1.1 drochner isiso = 0; 44 1.1 drochner vd = malloc(BLKSIZ); 45 1.1 drochner 46 1.1 drochner for (i = 16; (i < 100) && (i < len); i++) { 47 1.1 drochner res = pread(fd, vd, BLKSIZ, (start + i) * BLKSIZ); 48 1.1 drochner if (res < 0) { 49 1.1 drochner warn("read CD sector %d", start + i); 50 1.1 drochner break; 51 1.1 drochner } 52 1.1 drochner 53 1.1 drochner if (memcmp(vd->id, ISO_STANDARD_ID, sizeof(vd->id))) 54 1.1 drochner continue; 55 1.1 drochner if (isonum_711(vd->type) == ISO_VD_PRIMARY) { 56 1.1 drochner printinfo(vd); 57 1.1 drochner isiso = 1; 58 1.1 drochner break; 59 1.1 drochner } else if (isonum_711(vd->type) == ISO_VD_END) 60 1.1 drochner break; 61 1.1 drochner } 62 1.1 drochner 63 1.1 drochner free(vd); 64 1.1 drochner return (isiso); 65 1.1 drochner } 66