1197139Shrs/*-
2197139Shrs * Copyright (c) 2004 Pawel Jakub Dawidek <pjd@FreeBSD.org>
3197139Shrs * Copyright (c) 2014 The FreeBSD Foundation
4197139Shrs * All rights reserved.
5197139Shrs *
6198190Sdougb * This software was developed by Edward Tomasz Napierala under sponsorship
7197139Shrs * from the FreeBSD Foundation.
8197139Shrs *
9197139Shrs * Redistribution and use in source and binary forms, with or without
10197139Shrs * modification, are permitted provided that the following conditions
11197139Shrs * are met:
12197139Shrs * 1. Redistributions of source code must retain the above copyright
13197139Shrs *    notice, this list of conditions and the following disclaimer.
14197139Shrs * 2. Redistributions in binary form must reproduce the above copyright
15197139Shrs *    notice, this list of conditions and the following disclaimer in the
16197139Shrs *    documentation and/or other materials provided with the distribution.
17197139Shrs *
18197139Shrs * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
19197139Shrs * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20197139Shrs * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21197139Shrs * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
22197139Shrs * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23197139Shrs * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24220153Semaste * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25197139Shrs * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26197139Shrs * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27197139Shrs * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28197139Shrs * SUCH DAMAGE.
29197139Shrs */
30197139Shrs
31197139Shrs#include <sys/cdefs.h>
32197139Shrs#include <stdio.h>
33197139Shrs#include <stdlib.h>
34197139Shrs#include <string.h>
35197139Shrs
36197139Shrs#include "fstyp.h"
37197139Shrs
38197139Shrs#define	ISO9660_MAGIC	"\x01" "CD001" "\x01\x00"
39197139Shrs#define	ISO9660_OFFSET	0x8000
40197139Shrs#define	VOLUME_LEN	32
41197139Shrs
42197947Sdougbint
43197139Shrsfstyp_cd9660(FILE *fp, char *label, size_t size)
44197139Shrs{
45197139Shrs	char *sector, *volume;
46197139Shrs
47197139Shrs	sector = read_buf(fp, ISO9660_OFFSET, 512);
48197139Shrs	if (sector == NULL)
49197139Shrs		return (1);
50197139Shrs	if (bcmp(sector, ISO9660_MAGIC, sizeof(ISO9660_MAGIC) - 1) != 0) {
51220153Semaste		free(sector);
52197139Shrs		return (1);
53197139Shrs	}
54197139Shrs	volume = sector + 0x28;
55197139Shrs	bzero(label, size);
56197139Shrs	strlcpy(label, volume, MIN(size, VOLUME_LEN));
57197139Shrs	free(sector);
58197139Shrs	rtrim(label, size);
59197139Shrs	return (0);
60197139Shrs}
61197139Shrs