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