19313Ssos/*- 29313Ssos * Copyright (c) 2004 Pawel Jakub Dawidek <pjd@FreeBSD.org> 39313Ssos * Copyright (c) 2014 The FreeBSD Foundation 49313Ssos * All rights reserved. 59313Ssos * 69313Ssos * This software was developed by Edward Tomasz Napierala under sponsorship 79313Ssos * from the FreeBSD Foundation. 89313Ssos * 99313Ssos * Redistribution and use in source and binary forms, with or without 109313Ssos * modification, are permitted provided that the following conditions 119313Ssos * are met: 129313Ssos * 1. Redistributions of source code must retain the above copyright 139313Ssos * notice, this list of conditions and the following disclaimer. 149313Ssos * 2. Redistributions in binary form must reproduce the above copyright 159313Ssos * notice, this list of conditions and the following disclaimer in the 169313Ssos * documentation and/or other materials provided with the distribution. 179313Ssos * 189313Ssos * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 199313Ssos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 209313Ssos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 219313Ssos * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 229313Ssos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 239313Ssos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 249313Ssos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 259313Ssos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 269313Ssos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 279313Ssos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2850477Speter * SUCH DAMAGE. 299313Ssos */ 309313Ssos 319313Ssos#include <sys/cdefs.h> 329313Ssos__FBSDID("$FreeBSD: releng/11.0/usr.sbin/fstyp/cd9660.c 284582 2015-06-18 21:55:55Z trasz $"); 3312458Sbde 349313Ssos#include <stdio.h> 359313Ssos#include <stdlib.h> 369313Ssos#include <string.h> 379313Ssos 3814331Speter#include "fstyp.h" 3914331Speter 409313Ssos#define ISO9660_MAGIC "\x01" "CD001" "\x01\x00" 419313Ssos#define ISO9660_OFFSET 0x8000 4214331Speter#define VOLUME_LEN 32 4314331Speter 449313Ssosint 459313Ssosfstyp_cd9660(FILE *fp, char *label, size_t size) 4640203Sjdp{ 4714331Speter char *sector, *volume; 4814331Speter 4914331Speter sector = read_buf(fp, ISO9660_OFFSET, 512); 5014331Speter if (sector == NULL) 5114331Speter return (1); 529313Ssos if (bcmp(sector, ISO9660_MAGIC, sizeof(ISO9660_MAGIC) - 1) != 0) { 539313Ssos free(sector); 549313Ssos return (1); 559313Ssos } 5614331Speter volume = sector + 0x28; 5714331Speter bzero(label, size); 589313Ssos strlcpy(label, volume, MIN(size, VOLUME_LEN)); 599313Ssos free(sector); 6040203Sjdp rtrim(label, size); 6114331Speter return (0); 6214331Speter} 6314331Speter