1275680Strasz/*-
2275680Strasz * Copyright (c) 2004 Pawel Jakub Dawidek <pjd@FreeBSD.org>
3275680Strasz * Copyright (c) 2014 The FreeBSD Foundation
4275680Strasz * All rights reserved.
5275680Strasz *
6275680Strasz * This software was developed by Edward Tomasz Napierala under sponsorship
7275680Strasz * from the FreeBSD Foundation.
8275680Strasz *
9275680Strasz * Redistribution and use in source and binary forms, with or without
10275680Strasz * modification, are permitted provided that the following conditions
11275680Strasz * are met:
12275680Strasz * 1. Redistributions of source code must retain the above copyright
13275680Strasz *    notice, this list of conditions and the following disclaimer.
14275680Strasz * 2. Redistributions in binary form must reproduce the above copyright
15275680Strasz *    notice, this list of conditions and the following disclaimer in the
16275680Strasz *    documentation and/or other materials provided with the distribution.
17275680Strasz *
18275680Strasz * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
19275680Strasz * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20275680Strasz * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21275680Strasz * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
22275680Strasz * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23275680Strasz * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24275680Strasz * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25275680Strasz * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26275680Strasz * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27275680Strasz * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28275680Strasz * SUCH DAMAGE.
29275680Strasz */
30275680Strasz
31275680Strasz#include <sys/cdefs.h>
32275680Strasz__FBSDID("$FreeBSD$");
33275680Strasz
34275680Strasz#include <stdio.h>
35275680Strasz#include <stdlib.h>
36275680Strasz#include <string.h>
37275680Strasz
38275680Strasz#include "fstyp.h"
39275680Strasz
40275680Strasz#define	ISO9660_MAGIC	"\x01" "CD001" "\x01\x00"
41275680Strasz#define	ISO9660_OFFSET	0x8000
42275680Strasz#define	VOLUME_LEN	32
43275680Strasz
44275680Straszint
45275680Straszfstyp_cd9660(FILE *fp, char *label, size_t size)
46275680Strasz{
47275680Strasz	char *sector, *volume;
48275680Strasz
49275680Strasz	sector = read_buf(fp, ISO9660_OFFSET, 512);
50275680Strasz	if (sector == NULL)
51275680Strasz		return (1);
52275680Strasz	if (bcmp(sector, ISO9660_MAGIC, sizeof(ISO9660_MAGIC) - 1) != 0) {
53275680Strasz		free(sector);
54275680Strasz		return (1);
55275680Strasz	}
56275680Strasz	volume = sector + 0x28;
57275680Strasz	bzero(label, size);
58275680Strasz	strlcpy(label, volume, MIN(size, VOLUME_LEN));
59275680Strasz	free(sector);
60286193Strasz	rtrim(label, size);
61275680Strasz	return (0);
62275680Strasz}
63