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