1be3a49eeSEdward Tomasz Napierala /*-
2be3a49eeSEdward Tomasz Napierala * Copyright (c) 2004 Pawel Jakub Dawidek <pjd@FreeBSD.org>
3be3a49eeSEdward Tomasz Napierala * Copyright (c) 2014 The FreeBSD Foundation
4be3a49eeSEdward Tomasz Napierala * All rights reserved.
5be3a49eeSEdward Tomasz Napierala *
6be3a49eeSEdward Tomasz Napierala * This software was developed by Edward Tomasz Napierala under sponsorship
7be3a49eeSEdward Tomasz Napierala * from the FreeBSD Foundation.
8be3a49eeSEdward Tomasz Napierala *
9be3a49eeSEdward Tomasz Napierala * Redistribution and use in source and binary forms, with or without
10be3a49eeSEdward Tomasz Napierala * modification, are permitted provided that the following conditions
11be3a49eeSEdward Tomasz Napierala * are met:
12be3a49eeSEdward Tomasz Napierala * 1. Redistributions of source code must retain the above copyright
13be3a49eeSEdward Tomasz Napierala * notice, this list of conditions and the following disclaimer.
14be3a49eeSEdward Tomasz Napierala * 2. Redistributions in binary form must reproduce the above copyright
15be3a49eeSEdward Tomasz Napierala * notice, this list of conditions and the following disclaimer in the
16be3a49eeSEdward Tomasz Napierala * documentation and/or other materials provided with the distribution.
17be3a49eeSEdward Tomasz Napierala *
18be3a49eeSEdward Tomasz Napierala * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
19be3a49eeSEdward Tomasz Napierala * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20be3a49eeSEdward Tomasz Napierala * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21be3a49eeSEdward Tomasz Napierala * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
22be3a49eeSEdward Tomasz Napierala * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23be3a49eeSEdward Tomasz Napierala * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24be3a49eeSEdward Tomasz Napierala * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25be3a49eeSEdward Tomasz Napierala * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26be3a49eeSEdward Tomasz Napierala * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27be3a49eeSEdward Tomasz Napierala * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28be3a49eeSEdward Tomasz Napierala * SUCH DAMAGE.
29be3a49eeSEdward Tomasz Napierala */
30be3a49eeSEdward Tomasz Napierala
31be3a49eeSEdward Tomasz Napierala #include <sys/cdefs.h>
32be3a49eeSEdward Tomasz Napierala #include <stdio.h>
33be3a49eeSEdward Tomasz Napierala #include <stdlib.h>
34be3a49eeSEdward Tomasz Napierala #include <string.h>
35be3a49eeSEdward Tomasz Napierala
36be3a49eeSEdward Tomasz Napierala #include "fstyp.h"
37be3a49eeSEdward Tomasz Napierala
38be3a49eeSEdward Tomasz Napierala #define ISO9660_MAGIC "\x01" "CD001" "\x01\x00"
39be3a49eeSEdward Tomasz Napierala #define ISO9660_OFFSET 0x8000
40be3a49eeSEdward Tomasz Napierala #define VOLUME_LEN 32
41be3a49eeSEdward Tomasz Napierala
42be3a49eeSEdward Tomasz Napierala int
fstyp_cd9660(FILE * fp,char * label,size_t size)43be3a49eeSEdward Tomasz Napierala fstyp_cd9660(FILE *fp, char *label, size_t size)
44be3a49eeSEdward Tomasz Napierala {
45be3a49eeSEdward Tomasz Napierala char *sector, *volume;
46be3a49eeSEdward Tomasz Napierala
47be3a49eeSEdward Tomasz Napierala sector = read_buf(fp, ISO9660_OFFSET, 512);
48be3a49eeSEdward Tomasz Napierala if (sector == NULL)
49be3a49eeSEdward Tomasz Napierala return (1);
50be3a49eeSEdward Tomasz Napierala if (bcmp(sector, ISO9660_MAGIC, sizeof(ISO9660_MAGIC) - 1) != 0) {
51be3a49eeSEdward Tomasz Napierala free(sector);
52be3a49eeSEdward Tomasz Napierala return (1);
53be3a49eeSEdward Tomasz Napierala }
54be3a49eeSEdward Tomasz Napierala volume = sector + 0x28;
55be3a49eeSEdward Tomasz Napierala bzero(label, size);
56be3a49eeSEdward Tomasz Napierala strlcpy(label, volume, MIN(size, VOLUME_LEN));
57be3a49eeSEdward Tomasz Napierala free(sector);
58*628b7128SEdward Tomasz Napierala rtrim(label, size);
59be3a49eeSEdward Tomasz Napierala return (0);
60be3a49eeSEdward Tomasz Napierala }
61