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