diff options
author | Pali Rohár <pali.rohar@gmail.com> | 2018-01-16 23:47:19 +0100 |
---|---|---|
committer | Pali Rohár <pali.rohar@gmail.com> | 2018-01-16 23:47:19 +0100 |
commit | 05fce0a970fe98a114b56719b046d783c7c28062 (patch) | |
tree | e218684ae5e81477e5672ee7828096c291a1c724 /include |
Import udftools_2.0.orig.tar.gz
[dgit import orig udftools_2.0.orig.tar.gz]
Diffstat (limited to 'include')
-rw-r--r-- | include/bswap.h | 278 | ||||
-rw-r--r-- | include/config.in | 93 | ||||
-rw-r--r-- | include/ecma_167.h | 841 | ||||
-rw-r--r-- | include/libudffs.h | 235 | ||||
-rw-r--r-- | include/osta_udf.h | 278 | ||||
-rw-r--r-- | include/udf_endian.h | 104 |
6 files changed, 1829 insertions, 0 deletions
diff --git a/include/bswap.h b/include/bswap.h new file mode 100644 index 0000000..00627fa --- /dev/null +++ b/include/bswap.h @@ -0,0 +1,278 @@ +/* + * bswap.h + * + * Copyright (c) 2001-2002 Ben Fennema <bfennema@falcon.csc.calpoly.edu> + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#ifndef __BSWAP_H +#define __BSWAP_H + +#include "config.h" + +#include <inttypes.h> +#include <sys/types.h> + +#ifdef HAVE_SYS_ISA_DEFS_H +#define __LITTLE_ENDIAN 1234 +#define __BIG_ENDIAN 4321 +#define __PDP_ENDIAN 3412 + +#ifdef _LITTLE_ENDIAN +#define __BYTE_ORDER __LITTLE_ENDIAN +#endif + +#ifdef _BIG_ENDIAN +#define __BYTE_ORDER __BIG_ENDIAN +#endif +#endif + +#define constant_swab16(x) \ + ((uint16_t)((((uint16_t)(x) & 0x00FFU) << 8) | \ + (((uint16_t)(x) & 0xFF00U) >> 8))) + +#define constant_swab32(x) \ + ((uint32_t)((((uint32_t)(x) & 0x000000FFU) << 24) | \ + (((uint32_t)(x) & 0x0000FF00U) << 8) | \ + (((uint32_t)(x) & 0x00FF0000U) >> 8) | \ + (((uint32_t)(x) & 0xFF000000U) >> 24))) + +#define constant_swab64(x) \ + ((uint64_t)((((uint64_t)(x) & 0x00000000000000FFULL) << 56) | \ + (((uint64_t)(x) & 0x000000000000FF00ULL) << 40) | \ + (((uint64_t)(x) & 0x0000000000FF0000ULL) << 24) | \ + (((uint64_t)(x) & 0x00000000FF000000ULL) << 8) | \ + (((uint64_t)(x) & 0x000000FF00000000ULL) >> 8) | \ + (((uint64_t)(x) & 0x0000FF0000000000ULL) >> 24) | \ + (((uint64_t)(x) & 0x00FF000000000000ULL) >> 40) | \ + (((uint64_t)(x) & 0xFF00000000000000ULL) >> 56))) + +static inline uint16_t swab16(uint16_t x) +{ + return ((uint16_t)((((uint16_t)(x) & 0x00FFU) << 8) | \ + (((uint16_t)(x) & 0xFF00U) >> 8))); +} + +static inline uint32_t swab32(uint32_t x) +{ + return ((uint32_t)((((uint32_t)(x) & 0x000000FFU) << 24) | \ + (((uint32_t)(x) & 0x0000FF00U) << 8) | \ + (((uint32_t)(x) & 0x00FF0000U) >> 8) | \ + (((uint32_t)(x) & 0xFF000000U) >> 24))); +} + +static inline uint64_t swab64(uint64_t x) +{ + return ((uint64_t)((((uint64_t)(x) & 0x00000000000000FFULL) << 56) | \ + (((uint64_t)(x) & 0x000000000000FF00ULL) << 40) | \ + (((uint64_t)(x) & 0x0000000000FF0000ULL) << 24) | \ + (((uint64_t)(x) & 0x00000000FF000000ULL) << 8) | \ + (((uint64_t)(x) & 0x000000FF00000000ULL) >> 8) | \ + (((uint64_t)(x) & 0x0000FF0000000000ULL) >> 24) | \ + (((uint64_t)(x) & 0x00FF000000000000ULL) >> 40) | \ + (((uint64_t)(x) & 0xFF00000000000000ULL) >> 56))); +} + +#define constant_swab16p(x) \ + ((uint16_t)(((*(uint16_t *)(x) & 0x00FFU) << 8) | \ + ((*(uint16_t *)(x) & 0xFF00U) >> 8))) + +#define constant_swab32p(x) \ + ((uint32_t)(((*(uint32_t *)(x) & 0x000000FFU) << 24) | \ + ((*(uint32_t *)(x) & 0x0000FF00U) << 8) | \ + ((*(uint32_t *)(x) & 0x00FF0000U) >> 8) | \ + ((*(uint32_t *)(x) & 0xFF000000U) >> 24))) + +#define constant_swab64p(x) \ + ((uint64_t)(((*(uint64_t *)(x) & 0x00000000000000FFULL) << 56) | \ + ((*(uint64_t *)(x) & 0x000000000000FF00ULL) << 40) | \ + ((*(uint64_t *)(x) & 0x0000000000FF0000ULL) << 24) | \ + ((*(uint64_t *)(x) & 0x00000000FF000000ULL) << 8) | \ + ((*(uint64_t *)(x) & 0x000000FF00000000ULL) >> 8) | \ + ((*(uint64_t *)(x) & 0x0000FF0000000000ULL) >> 24) | \ + ((*(uint64_t *)(x) & 0x00FF000000000000ULL) >> 40) | \ + ((*(uint64_t *)(x) & 0xFF00000000000000ULL) >> 56))) + + +static inline uint16_t swab16p(uint16_t *x) +{ + return ((uint16_t)(((*(uint16_t *)(x) & 0x00FFU) << 8) | \ + ((*(uint16_t *)(x) & 0xFF00U) >> 8))); +} + +static inline uint32_t swab32p(uint32_t *x) +{ + return ((uint32_t)(((*(uint32_t *)(x) & 0x000000FFU) << 24) | \ + ((*(uint32_t *)(x) & 0x0000FF00U) << 8) | \ + ((*(uint32_t *)(x) & 0x00FF0000U) >> 8) | \ + ((*(uint32_t *)(x) & 0xFF000000U) >> 24))); +} + +static inline uint64_t swab64p(uint64_t *x) +{ + return ((uint64_t)(((*(uint64_t *)(x) & 0x00000000000000FFULL) << 56) | \ + ((*(uint64_t *)(x) & 0x000000000000FF00ULL) << 40) | \ + ((*(uint64_t *)(x) & 0x0000000000FF0000ULL) << 24) | \ + ((*(uint64_t *)(x) & 0x00000000FF000000ULL) << 8) | \ + ((*(uint64_t *)(x) & 0x000000FF00000000ULL) >> 8) | \ + ((*(uint64_t *)(x) & 0x0000FF0000000000ULL) >> 24) | \ + ((*(uint64_t *)(x) & 0x00FF000000000000ULL) >> 40) | \ + ((*(uint64_t *)(x) & 0xFF00000000000000ULL) >> 56))); +} + +#if __BYTE_ORDER == 0 + +#error "__BYTE_ORDER must be defined" + +#elif __BYTE_ORDER == __BIG_ENDIAN + +#define le16_to_cpu(x) (__builtin_constant_p(x) ? \ + constant_swab16(x) : \ + swab16(x)) + +#define le32_to_cpu(x) (__builtin_constant_p(x) ? \ + constant_swab32(x) : \ + swab32(x)) + +#define le64_to_cpu(x) (__builtin_constant_p(x) ? \ + constant_swab64(x) : \ + swab64(x)) + + +#define constant_le16_to_cpu(x) constant_swab16((x)) +#define constant_le32_to_cpu(x) constant_swab32((x)) +#define constant_le64_to_cpu(x) constant_swab64((x)) + +#define le16_to_cpup(x) (__builtin_constant_p(x) ? \ + constant_swab16p(x) : \ + swab16p(x)) + +#define le32_to_cpup(x) (__builtin_constant_p(x) ? \ + constant_swab32p(x) : \ + swab32p(x)) + +#define le64_to_cpup(x) (__builtin_constant_p(x) ? \ + constant_swab64p(x) : \ + swab64p(x)) + +#define constant_le16_to_cpup(x) constant_swab16p((x)) +#define constant_le32_to_cpup(x) constant_swab32p((x)) +#define constant_le64_to_cpup(x) constant_swab64p((x)) + +#define be16_to_cpu(x) ((uint16_t)(x)) +#define be32_to_cpu(x) ((uint32_t)(x)) +#define be64_to_cpu(x) ((uint64_t)(x)) + +#define constant_be16_to_cpu(x) ((uint16_t)(x)) +#define constant_be32_to_cpu(x) ((uint32_t)(x)) +#define constant_be64_to_cpu(x) ((uint64_t)(x)) + +#define be16_to_cpup(x) (*(uint16_t *)(x)) +#define be32_to_cpup(x) (*(uint32_t *)(x)) +#define be64_to_cpup(x) (*(uint64_t *)(x)) + +#define constant_be16_to_cpup(x) (*(uint16_t *)(x)) +#define constant_be32_to_cpup(x) (*(uint32_t *)(x)) +#define constant_be64_to_cpup(x) (*(uint64_t *)(x)) + +#else /* __BYTE_ORDER == __LITTLE_ENDIAN */ + +#define le16_to_cpu(x) ((uint16_t)(x)) +#define le32_to_cpu(x) ((uint32_t)(x)) +#define le64_to_cpu(x) ((uint64_t)(x)) + +#define constant_le16_to_cpu(x) ((uint16_t)(x)) +#define constant_le32_to_cpu(x) ((uint32_t)(x)) +#define constant_le64_to_cpu(x) ((uint64_t)(x)) + +#define le16_to_cpup(x) (*(uint16_t *)(x)) +#define le32_to_cpup(x) (*(uint32_t *)(x)) +#define le64_to_cpup(x) (*(uint64_t *)(x)) + +#define constant_le16_to_cpup(x) (*(uint16_t *)(x)) +#define constant_le32_to_cpup(x) (*(uint32_t *)(x)) +#define constant_le64_to_cpup(x) (*(uint64_t *)(x)) + +#define be16_to_cpu(x) (__builtin_constant_p(x) ? \ + constant_swab16(x) : \ + swab16(x)) + +#define be32_to_cpu(x) (__builtin_constant_p(x) ? \ + constant_swab32(x) : \ + swab32(x)) + +#define be64_to_cpu(x) (__builtin_constant_p(x) ? \ + constant_swab64(x) : \ + swab64(x)) + + +#define constant_be16_to_cpu(x) constant_swab16((x)) +#define constant_be32_to_cpu(x) constant_swab32((x)) +#define constant_be64_to_cpu(x) constant_swab64((x)) + +#define be16_to_cpup(x) (__builtin_constant_p(x) ? \ + constant_swab16p(x) : \ + swab16p(x)) + +#define be32_to_cpup(x) (__builtin_constant_p(x) ? \ + constant_swab32p(x) : \ + swab32p(x)) + +#define be64_to_cpup(x) (__builtin_constant_p(x) ? \ + constant_swab64p(x) : \ + swab64p(x)) + +#define constant_be16_to_cpup(x) constant_swab16p((x)) +#define constant_be32_to_cpup(x) constant_swab32p((x)) +#define constant_be64_to_cpup(x) constant_swab64p((x)) + +#endif /* __BYTE_ORDER == 0 */ + +#define cpu_to_le16(x) le16_to_cpu((x)) +#define cpu_to_le32(x) le32_to_cpu((x)) +#define cpu_to_le64(x) le64_to_cpu((x)) + +#define constant_cpu_to_le16(x) constant_le16_to_cpu((x)) +#define constant_cpu_to_le32(x) constant_le32_to_cpu((x)) +#define constant_cpu_to_le64(x) constant_le64_to_cpu((x)) + +#define cpu_to_le16p(x) le16_to_cpup((x)) +#define cpu_to_le32p(x) le32_to_cpup((x)) +#define cpu_to_le64p(x) le64_to_cpup((x)) + +#define constant_cpu_to_le16p(x) constant_le16_to_cpup((x)) +#define constant_cpu_to_le32p(x) constant_le32_to_cpup((x)) +#define constant_cpu_to_le64p(x) constant_le64_to_cpup((x)) + +#define cpu_to_be16(x) be16_to_cpu((x)) +#define cpu_to_be32(x) be32_to_cpu((x)) +#define cpu_to_be64(x) be64_to_cpu((x)) + +#define constant_cpu_to_be16(x) constant_be16_to_cpu((x)) +#define constant_cpu_to_be32(x) constant_be32_to_cpu((x)) +#define constant_cpu_to_be64(x) constant_be64_to_cpu((x)) + +#define cpu_to_be16p(x) be16_to_cpup((x)) +#define cpu_to_be32p(x) be32_to_cpup((x)) +#define cpu_to_be64p(x) be64_to_cpup((x)) + +#define constant_cpu_to_be16p(x) constant_be16_to_cpup((x)) +#define constant_cpu_to_be32p(x) constant_be32_to_cpup((x)) +#define constant_cpu_to_be64p(x) constant_be64_to_cpup((x)) + +#endif /* __BSWAP_H */ diff --git a/include/config.in b/include/config.in new file mode 100644 index 0000000..c92956c --- /dev/null +++ b/include/config.in @@ -0,0 +1,93 @@ +/* include/config.in. Generated from configure.ac by autoheader. */ + +/* Define to 1 if you have the <dlfcn.h> header file. */ +#undef HAVE_DLFCN_H + +/* Define to 1 if you have the <fcntl.h> header file. */ +#undef HAVE_FCNTL_H + +/* Define to 1 if you have the <getopt.h> header file. */ +#undef HAVE_GETOPT_H + +/* Define to 1 if you have the <inttypes.h> header file. */ +#undef HAVE_INTTYPES_H + +/* Define to 1 if you have the <memory.h> header file. */ +#undef HAVE_MEMORY_H + +/* Define to 1 if you have the <stdint.h> header file. */ +#undef HAVE_STDINT_H + +/* Define to 1 if you have the <stdlib.h> header file. */ +#undef HAVE_STDLIB_H + +/* Define to 1 if you have the <strings.h> header file. */ +#undef HAVE_STRINGS_H + +/* Define to 1 if you have the <string.h> header file. */ +#undef HAVE_STRING_H + +/* Define to 1 if you have the <sys/stat.h> header file. */ +#undef HAVE_SYS_STAT_H + +/* Define to 1 if you have the <sys/time.h> header file. */ +#undef HAVE_SYS_TIME_H + +/* Define to 1 if you have the <sys/types.h> header file. */ +#undef HAVE_SYS_TYPES_H + +/* Define to 1 if you have the <unistd.h> header file. */ +#undef HAVE_UNISTD_H + +/* Define to the sub-directory where libtool stores uninstalled libraries. */ +#undef LT_OBJDIR + +/* Name of package */ +#undef PACKAGE + +/* Define to the address where bug reports for this package should be sent. */ +#undef PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +#undef PACKAGE_NAME + +/* Define to the full name and version of this package. */ +#undef PACKAGE_STRING + +/* Define to the one symbol short name of this package. */ +#undef PACKAGE_TARNAME + +/* Define to the home page for this package. */ +#undef PACKAGE_URL + +/* Define to the version of this package. */ +#undef PACKAGE_VERSION + +/* Define to 1 if you have the ANSI C header files. */ +#undef STDC_HEADERS + +/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */ +#undef TIME_WITH_SYS_TIME + +/* Define to 1 if your <sys/time.h> declares `struct tm'. */ +#undef TM_IN_SYS_TIME + +/* Version number of package */ +#undef VERSION + +/* Enable large inode numbers on Mac OS X 10.5. */ +#ifndef _DARWIN_USE_64_BIT_INODE +# define _DARWIN_USE_64_BIT_INODE 1 +#endif + +/* Number of bits in a file offset, on hosts where this is settable. */ +#undef _FILE_OFFSET_BITS + +/* Define for large files, on AIX-style hosts. */ +#undef _LARGE_FILES + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +#undef inline +#endif diff --git a/include/ecma_167.h b/include/ecma_167.h new file mode 100644 index 0000000..9ef146c --- /dev/null +++ b/include/ecma_167.h @@ -0,0 +1,841 @@ +/* + * ecma_167.h + * + * This file is based on ECMA-167 3rd edition (June 1997) + * http://www.ecma.ch + * + * Copyright (c) 2001-2002 Ben Fennema <bfennema@falcon.csc.calpoly.edu> + * Copyright (c) 2017 Pali Rohár <pali.rohar@gmail.com> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU Public License ("GPL"). + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/** + * @file + * ECMA-167r3 defines and structure definitions + */ + +#include <inttypes.h> + +#ifndef _ECMA_167_H +#define _ECMA_167_H 1 + +/* Character sets and coding - d-characters (ECMA 167r3 1/7.2) */ +typedef uint8_t dchars; + +/* Character set specification (ECMA 167r3 1/7.2.1) */ +typedef struct +{ + uint8_t charSetType; + uint8_t charSetInfo[63]; +} __attribute__ ((packed)) charspec; + +/* Character Set Type (ECMA 167r3 1/7.2.1.1) */ +#define CHARSPEC_TYPE_CS0 0x00 /* (1/7.2.2) */ +#define CHARSPEC_TYPE_CS1 0x01 /* (1/7.2.3) */ +#define CHARSPEC_TYPE_CS2 0x02 /* (1/7.2.4) */ +#define CHARSPEC_TYPE_CS3 0x03 /* (1/7.2.5) */ +#define CHARSPEC_TYPE_CS4 0x04 /* (1/7.2.6) */ +#define CHARSPEC_TYPE_CS5 0x05 /* (1/7.2.7) */ +#define CHARSPEC_TYPE_CS6 0x06 /* (1/7.2.8) */ +#define CHARSPEC_TYPE_CS7 0x07 /* (1/7.2.9) */ +#define CHARSPEC_TYPE_CS8 0x08 /* (1/7.2.10) */ + +/* Fixed-length character fields - d-string (EMCA 167r3 1/7.2.12) */ +typedef uint8_t dstring; + +/* Timestamp (ECMA 167r3 1/7.3) */ +typedef struct +{ + uint16_t typeAndTimezone; + int16_t year; + uint8_t month; + uint8_t day; + uint8_t hour; + uint8_t minute; + uint8_t second; + uint8_t centiseconds; + uint8_t hundredsOfMicroseconds; + uint8_t microseconds; +} __attribute__ ((packed)) timestamp; + +/* Type and Time Zone (ECMA 167r3 1/7.3.1) */ +#define TIMESTAMP_TYPE_MASK 0xF000 +#define TIMESTAMP_TYPE_CUT 0x0000 +#define TIMESTAMP_TYPE_LOCAL 0x1000 +#define TIMESTAMP_TYPE_AGREEMENT 0x2000 +#define TIMESTAMP_TIMEZONE_MASK 0x0FFF + +/* Entity identifier (ECMA 167r3 1/7.4) */ +typedef struct +{ + uint8_t flags; + uint8_t ident[23]; + uint8_t identSuffix[8]; +} __attribute__ ((packed)) regid; + +/* Flags (ECMA 167r3 1/7.4.1) */ +#define ENTITYID_FLAGS_DIRTY 0x00 +#define ENTITYID_FLAGS_PROTECTED 0x01 + +/* Volume Structure Descriptor (ECMA 167r3 2/9.1) */ +#define VSD_STD_ID_LEN 5 +struct volStructDesc +{ + uint8_t structType; + uint8_t stdIdent[VSD_STD_ID_LEN]; + uint8_t structVersion; + uint8_t structData[2041]; +} __attribute__ ((packed)); + +/* Standard Identifier (EMCA 167r2 2/9.1.2) */ +#define VSD_STD_ID_NSR02 "NSR02" /* (3/9.1) */ + +/* Standard Identifier (ECMA 167r3 2/9.1.2) */ +#define VSD_STD_ID_BEA01 "BEA01" /* (2/9.2) */ +#define VSD_STD_ID_BOOT2 "BOOT2" /* (2/9.4) */ +#define VSD_STD_ID_CD001 "CD001" /* (ECMA-119) */ +#define VSD_STD_ID_CDW02 "CDW02" /* (ECMA-168) */ +#define VSD_STD_ID_NSR03 "NSR03" /* (3/9.1) */ +#define VSD_STD_ID_TEA01 "TEA01" /* (2/9.3) */ + +/* Beginning Extended Area Descriptor (ECMA 167r3 2/9.2) */ +struct beginningExtendedAreaDesc +{ + uint8_t structType; + uint8_t stdIdent[VSD_STD_ID_LEN]; + uint8_t structVersion; + uint8_t structData[2041]; +} __attribute__ ((packed)); + +/* Terminating Extended Area Descriptor (ECMA 167r3 2/9.3) */ +struct terminatingExtendedAreaDesc +{ + uint8_t structType; + uint8_t stdIdent[VSD_STD_ID_LEN]; + uint8_t structVersion; + uint8_t structData[2041]; +} __attribute__ ((packed)); + +/* Boot Descriptor (ECMA 167r3 2/9.4) */ +struct bootDesc +{ + uint8_t structType; + uint8_t stdIdent[VSD_STD_ID_LEN]; + uint8_t structVersion; + uint8_t reserved1; + regid archType; + regid bootIdent; + uint32_t bootExtLocation; + uint32_t bootExtLength; + uint64_t loadAddress; + uint64_t startAddress; + timestamp descCreationDateAndTime; + uint16_t flags; + uint8_t reserved2[32]; + uint8_t bootUse[1906]; +} __attribute__ ((packed)); + +/* Flags (ECMA 167r3 2/9.4.12) */ +#define BOOT_FLAGS_ERASE 0x01 + +/* Extent Descriptor (ECMA 167r3 3/7.1) */ +typedef struct +{ + uint32_t extLength; + uint32_t extLocation; +} __attribute__ ((packed)) extent_ad; + +/* Descriptor Tag (ECMA 167r3 3/7.2) */ +typedef struct +{ + uint16_t tagIdent; + uint16_t descVersion; + uint8_t tagChecksum; + uint8_t reserved; + uint16_t tagSerialNum; + uint16_t descCRC; + uint16_t descCRCLength; + uint32_t tagLocation; +} __attribute__ ((packed)) tag; + +/* Tag Identifier (ECMA 167r3 3/7.2.1) */ +#define TAG_IDENT_PVD 0x0001 +#define TAG_IDENT_AVDP 0x0002 +#define TAG_IDENT_VDP 0x0003 +#define TAG_IDENT_IUVD 0x0004 +#define TAG_IDENT_PD 0x0005 +#define TAG_IDENT_LVD 0x0006 +#define TAG_IDENT_USD 0x0007 +#define TAG_IDENT_TD 0x0008 +#define TAG_IDENT_LVID 0x0009 + +/* NSR Descriptor (ECMA 167r3 3/9.1) */ +struct NSRDesc +{ + uint8_t structType; + uint8_t stdIdent[VSD_STD_ID_LEN]; + uint8_t structVersion; + uint8_t reserved; + uint8_t structData[2040]; +} __attribute__ ((packed)); + +/* Generic Descriptor */ +struct genericDesc +{ + tag descTag; + uint32_t volDescSeqNum; + uint8_t reserved[492]; +} __attribute__ ((packed)); + +/* Primary Volume Descriptor (ECMA 167r3 3/10.1) */ +struct primaryVolDesc +{ + tag descTag; + uint32_t volDescSeqNum; + uint32_t primaryVolDescNum; + dstring volIdent[32]; + uint16_t volSeqNum; + uint16_t maxVolSeqNum; + uint16_t interchangeLvl; + uint16_t maxInterchangeLvl; + uint32_t charSetList; + uint32_t maxCharSetList; + dstring volSetIdent[128]; + charspec descCharSet; + charspec explanatoryCharSet; + extent_ad volAbstract; + extent_ad volCopyright; + regid appIdent; + timestamp recordingDateAndTime; + regid impIdent; + uint8_t impUse[64]; + uint32_t predecessorVolDescSeqLocation; + uint16_t flags; + uint8_t reserved[22]; +} __attribute__ ((packed)); + +/* Flags (ECMA 167r3 3/10.1.21) */ +#define PVD_FLAGS_VSID_COMMON 0x0001 + +/* Anchor Volume Descriptor Pointer (ECMA 167r3 3/10.2) */ +struct anchorVolDescPtr +{ + tag descTag; + extent_ad mainVolDescSeqExt; + extent_ad reserveVolDescSeqExt; + uint8_t reserved[480]; +} __attribute__ ((packed)); + +/* Volume Descriptor Pointer (ECMA 167r3 3/10.3) */ +struct volDescPtr +{ + tag descTag; + uint32_t volDescSeqNum; + extent_ad nextVolDescSeqExt; + uint8_t reserved[484]; +} __attribute__ ((packed)); + +/* Implementation Use Volume Descriptor (ECMA 167r3 3/10.4) */ +struct impUseVolDesc +{ + tag descTag; + uint32_t volDescSeqNum; + regid impIdent; + uint8_t impUse[460]; +} __attribute__ ((packed)); + +/* Partition Descriptor (ECMA 167r3 3/10.5) */ +struct partitionDesc +{ + tag descTag; + uint32_t volDescSeqNum; + uint16_t partitionFlags; + uint16_t partitionNumber; + regid partitionContents; + uint8_t partitionContentsUse[128]; + uint32_t accessType; + uint32_t partitionStartingLocation; + uint32_t partitionLength; + regid impIdent; + uint8_t impUse[128]; + uint8_t reserved[156]; +} __attribute__ ((packed)); + +/* Partition Flags (ECMA 167r3 3/10.5.3) */ +#define PD_PARTITION_FLAGS_ALLOC 0x0001 + +/* Partition Contents (ECMA 167r2 3/10.5.3) */ +#define PD_PARTITION_CONTENTS_NSR02 "+NSR02" + +/* Partition Contents (ECMA 167r3 3/10.5.5) */ +#define PD_PARTITION_CONTENTS_FDC01 "+FDC01" +#define PD_PARTITION_CONTENTS_CD001 "+CD001" +#define PD_PARTITION_CONTENTS_CDW02 "+CDW02" +#define PD_PARTITION_CONTENTS_NSR03 "+NSR03" + +/* Access Type (ECMA 167r3 3/10.5.7) */ +#define PD_ACCESS_TYPE_NONE 0x00000000 +#define PD_ACCESS_TYPE_READ_ONLY 0x00000001 +#define PD_ACCESS_TYPE_WRITE_ONCE 0x00000002 +#define PD_ACCESS_TYPE_REWRITABLE 0x00000003 +#define PD_ACCESS_TYPE_OVERWRITABLE 0x00000004 + +/* Logical Volume Descriptor (ECMA 167r3 3/10.6) */ +struct logicalVolDesc +{ + tag descTag; + uint32_t volDescSeqNum; + charspec descCharSet; + dstring logicalVolIdent[128]; + uint32_t logicalBlockSize; + regid domainIdent; + uint8_t logicalVolContentsUse[16]; + uint32_t mapTableLength; + uint32_t numPartitionMaps; + regid impIdent; + uint8_t impUse[128]; + extent_ad integritySeqExt; + uint8_t partitionMaps[0]; +} __attribute__ ((packed)); + +/* Generic Partition Map (ECMA 167r3 3/10.7.1) */ +struct genericPartitionMap +{ + uint8_t partitionMapType; + uint8_t partitionMapLength; + uint8_t partitionMapping[0]; +} __attribute__ ((packed)); + +/* Partition Map Type (ECMA 167r3 3/10.7.1.1) */ +#define GP_PARTITION_MAP_TYPE_UNDEF 0x00 +#define GP_PARTITION_MAP_TYPE_1 0x01 +#define GP_PARTITION_MAP_TYPE_2 0x02 + +/* Type 1 Partition Map (ECMA 167r3 3/10.7.2) */ +struct genericPartitionMap1 +{ + uint8_t partitionMapType; + uint8_t partitionMapLength; + uint16_t volSeqNum; + uint16_t partitionNum; +} __attribute__ ((packed)); + +/* Type 2 Partition Map (ECMA 167r3 3/10.7.3) */ +struct genericPartitionMap2 +{ + uint8_t partitionMapType; + uint8_t partitionMapLength; + uint8_t partitionIdent[62]; +} __attribute__ ((packed)); + +/* Unallocated Space Descriptor (ECMA 167r3 3/10.8) */ +struct unallocSpaceDesc +{ + tag descTag; + uint32_t volDescSeqNum; + uint32_t numAllocDescs; + extent_ad allocDescs[0]; +} __attribute__ ((packed)); + +/* Terminating Descriptor (ECMA 167r3 3/10.9) */ +struct terminatingDesc +{ + tag descTag; + uint8_t reserved[496]; +} __attribute__ ((packed)); + +/* Logical Volume Integrity Descriptor (ECMA 167r3 3/10.10) */ +struct logicalVolIntegrityDesc +{ + tag descTag; + timestamp recordingDateAndTime; + uint32_t integrityType; + extent_ad nextIntegrityExt; + uint8_t logicalVolContentsUse[32]; + uint32_t numOfPartitions; + uint32_t lengthOfImpUse; + uint32_t freeSpaceTable[0]; + uint32_t sizeTable[0]; + uint8_t impUse[0]; +} __attribute__ ((packed)); + +/* Integrity Type (ECMA 167r3 3/10.10.3) */ +#define LVID_INTEGRITY_TYPE_OPEN 0x00000000 +#define LVID_INTEGRITY_TYPE_CLOSE 0x00000001 + +/* Recorded Address (ECMA 167r3 4/7.1) */ +typedef struct +{ + uint32_t logicalBlockNum; + uint16_t partitionReferenceNum; +} __attribute__ ((packed)) lb_addr; + +/* Short Allocation Descriptor (ECMA 167r3 4/14.14.1) */ +typedef struct +{ + uint32_t extLength; + uint32_t extPosition; +} __attribute__ ((packed)) short_ad; + +/* Long Allocation Descriptor (ECMA 167r3 4/14.14.2) */ +typedef struct +{ + uint32_t extLength; + lb_addr extLocation; + uint8_t impUse[6]; +} __attribute__ ((packed)) long_ad; + +/* Extended Allocation Descriptor (ECMA 167r3 4/14.14.3) */ +typedef struct +{ + uint32_t extLength; + uint32_t recordedLength; + uint32_t informationLength; + lb_addr extLocation; +} __attribute__ ((packed)) ext_ad; + +/* Descriptor Tag (ECMA 167r3 4/7.2 - See 3/7.2) */ + +/* Tag Identifier (ECMA 167r3 4/7.2.1) */ +#define TAG_IDENT_FSD 0x0100 +#define TAG_IDENT_FID 0x0101 +#define TAG_IDENT_AED 0x0102 +#define TAG_IDENT_IE 0x0103 +#define TAG_IDENT_TE 0x0104 +#define TAG_IDENT_FE 0x0105 +#define TAG_IDENT_EAHD 0x0106 +#define TAG_IDENT_USE 0x0107 +#define TAG_IDENT_SBD 0x0108 +#define TAG_IDENT_PIE 0x0109 +#define TAG_IDENT_EFE 0x010A + +/* File Set Descriptor (ECMA 167r3 4/14.1) */ +struct fileSetDesc +{ + tag descTag; + timestamp recordingDateAndTime; + uint16_t interchangeLvl; + uint16_t maxInterchangeLvl; + uint32_t charSetList; + uint32_t maxCharSetList; + uint32_t fileSetNum; + uint32_t fileSetDescNum; + charspec logicalVolIdentCharSet; + dstring logicalVolIdent[128]; + charspec fileSetCharSet; + dstring fileSetIdent[32]; + dstring copyrightFileIdent[32]; + dstring abstractFileIdent[32]; + long_ad rootDirectoryICB; + regid domainIdent; + long_ad nextExt; + long_ad streamDirectoryICB; + uint8_t reserved[32]; +} __attribute__ ((packed)); + +/* Partition Header Descriptor (ECMA 167r3 4/14.3) */ +struct partitionHeaderDesc +{ + short_ad unallocSpaceTable; + short_ad unallocSpaceBitmap; + short_ad partitionIntegrityTable; + short_ad freedSpaceTable; + short_ad freedSpaceBitmap; + uint8_t reserved[88]; +} __attribute__ ((packed)); + +/* File Identifier Descriptor (ECMA 167r3 4/14.4) */ +struct fileIdentDesc +{ + tag descTag; + uint16_t fileVersionNum; + uint8_t fileCharacteristics; + uint8_t lengthFileIdent; + long_ad icb; + uint16_t lengthOfImpUse; + uint8_t impUse[0]; + dchars fileIdent[0]; + uint8_t padding[0]; +} __attribute__ ((packed)); + +/* File Characteristics (ECMA 167r3 4/14.4.3) */ +#define FID_FILE_CHAR_HIDDEN 0x01 +#define FID_FILE_CHAR_DIRECTORY 0x02 +#define FID_FILE_CHAR_DELETED 0x04 +#define FID_FILE_CHAR_PARENT 0x08 +#define FID_FILE_CHAR_METADATA 0x10 + +/* Allocation Ext Descriptor (ECMA 167r3 4/14.5) */ +struct allocExtDesc +{ + tag descTag; + uint32_t previousAllocExtLocation; + uint32_t lengthAllocDescs; +} __attribute__ ((packed)); + +/* ICB Tag (ECMA 167r3 4/14.6) */ +typedef struct +{ + uint32_t priorRecordedNumDirectEntries; + uint16_t strategyType; + uint16_t strategyParameter; + uint16_t numEntries; + uint8_t reserved; + uint8_t fileType; + lb_addr parentICBLocation; + uint16_t flags; +} __attribute__ ((packed)) icbtag; + +/* Strategy Type (ECMA 167r3 4/14.6.2) */ +#define ICBTAG_STRATEGY_TYPE_UNDEF 0x0000 +#define ICBTAG_STRATEGY_TYPE_1 0x0001 +#define ICBTAG_STRATEGY_TYPE_2 0x0002 +#define ICBTAG_STRATEGY_TYPE_3 0x0003 +#define ICBTAG_STRATEGY_TYPE_4 0x0004 + +/* File Type (ECMA 167r3 4/14.6.6) */ +#define ICBTAG_FILE_TYPE_UNDEF 0x00 +#define ICBTAG_FILE_TYPE_USE 0x01 +#define ICBTAG_FILE_TYPE_PIE 0x02 +#define ICBTAG_FILE_TYPE_IE 0x03 +#define ICBTAG_FILE_TYPE_DIRECTORY 0x04 +#define ICBTAG_FILE_TYPE_REGULAR 0x05 +#define ICBTAG_FILE_TYPE_BLOCK 0x06 +#define ICBTAG_FILE_TYPE_CHAR 0x07 +#define ICBTAG_FILE_TYPE_EA 0x08 +#define ICBTAG_FILE_TYPE_FIFO 0x09 +#define ICBTAG_FILE_TYPE_SOCKET 0x0A +#define ICBTAG_FILE_TYPE_TE 0x0B +#define ICBTAG_FILE_TYPE_SYMLINK 0x0C +#define ICBTAG_FILE_TYPE_STREAMDIR 0x0D + +/* Flags (ECMA 167r3 4/14.6.8) */ +#define ICBTAG_FLAG_AD_MASK 0x0007 +#define ICBTAG_FLAG_AD_SHORT 0x0000 +#define ICBTAG_FLAG_AD_LONG 0x0001 +#define ICBTAG_FLAG_AD_EXTENDED 0x0002 +#define ICBTAG_FLAG_AD_IN_ICB 0x0003 +#define ICBTAG_FLAG_SORTED 0x0008 +#define ICBTAG_FLAG_NONRELOCATABLE 0x0010 +#define ICBTAG_FLAG_ARCHIVE 0x0020 +#define ICBTAG_FLAG_SETUID 0x0040 +#define ICBTAG_FLAG_SETGID 0x0080 +#define ICBTAG_FLAG_STICKY 0x0100 +#define ICBTAG_FLAG_CONTIGUOUS 0x0200 +#define ICBTAG_FLAG_SYSTEM 0x0400 +#define ICBTAG_FLAG_TRANSFORMED 0x0800 +#define ICBTAG_FLAG_MULTIVERSIONS 0x1000 +#define ICBTAG_FLAG_STREAM 0x2000 + +/* Indirect Entry (ECMA 167r3 4/14.7) */ +struct indirectEntry +{ + tag descTag; + icbtag icbTag; + long_ad indirectICB; +} __attribute__ ((packed)); + +/* Terminal Entry (ECMA 167r3 4/14.8) */ +struct terminalEntry +{ + tag descTag; + icbtag icbTag; +} __attribute__ ((packed)); + +/* File Entry (ECMA 167r3 4/14.9) */ +struct fileEntry +{ + tag descTag; + icbtag icbTag; + uint32_t uid; + uint32_t gid; + uint32_t permissions; + uint16_t fileLinkCount; + uint8_t recordFormat; + uint8_t recordDisplayAttr; + uint32_t recordLength; + uint64_t informationLength; + uint64_t logicalBlocksRecorded; + timestamp accessTime; + timestamp modificationTime; + timestamp attrTime; + uint32_t checkpoint; + long_ad extendedAttrICB; + regid impIdent; + uint64_t uniqueID; + uint32_t lengthExtendedAttr; + uint32_t lengthAllocDescs; + uint8_t extendedAttr[0]; + uint8_t allocDescs[0]; +} __attribute__ ((packed)); + +/* Permissions (ECMA 167r3 4/14.9.5) */ +#define FE_PERM_O_EXEC 0x00000001U +#define FE_PERM_O_WRITE 0x00000002U +#define FE_PERM_O_READ 0x00000004U +#define FE_PERM_O_CHATTR 0x00000008U +#define FE_PERM_O_DELETE 0x00000010U +#define FE_PERM_G_EXEC 0x00000020U +#define FE_PERM_G_WRITE 0x00000040U +#define FE_PERM_G_READ 0x00000080U +#define FE_PERM_G_CHATTR 0x00000100U +#define FE_PERM_G_DELETE 0x00000200U +#define FE_PERM_U_EXEC 0x00000400U +#define FE_PERM_U_WRITE 0x00000800U +#define FE_PERM_U_READ 0x00001000U +#define FE_PERM_U_CHATTR 0x00002000U +#define FE_PERM_U_DELETE 0x00004000U + +/* Record Format (ECMA 167r3 4/14.9.7) */ +#define FE_RECORD_FMT_UNDEF 0x00 +#define FE_RECORD_FMT_FIXED_PAD 0x01 +#define FE_RECORD_FMT_FIXED 0x02 +#define FE_RECORD_FMT_VARIABLE8 0x03 +#define FE_RECORD_FMT_VARIABLE16 0x04 +#define FE_RECORD_FMT_VARIABLE16_MSB 0x05 +#define FE_RECORD_FMT_VARIABLE32 0x06 +#define FE_RECORD_FMT_PRINT 0x07 +#define FE_RECORD_FMT_LF 0x08 +#define FE_RECORD_FMT_CR 0x09 +#define FE_RECORD_FMT_CRLF 0x0A +#define FE_RECORD_FMT_LFCR 0x0B + +/* Record Display Attributes (ECMA 167r3 4/14.9.8) */ +#define FE_RECORD_DISPLAY_ATTR_UNDEF 0x00 +#define FE_RECORD_DISPLAY_ATTR_1 0x01 +#define FE_RECORD_DISPLAY_ATTR_2 0x02 +#define FE_RECORD_DISPLAY_ATTR_3 0x03 + +/* Extended Attribute Header Descriptor (ECMA 167r3 4/14.10.1) */ +struct extendedAttrHeaderDesc +{ + tag descTag; + uint32_t impAttrLocation; + uint32_t appAttrLocation; +} __attribute__ ((packed)); + +/* Generic Format (ECMA 167r3 4/14.10.2) */ +struct genericFormat +{ + uint32_t attrType; + uint8_t attrSubtype; + uint8_t reserved[3]; + uint32_t attrLength; + uint8_t attrData[0]; +} __attribute__ ((packed)); + +/* Character Set Information (ECMA 167r3 4/14.10.3) */ +struct charSetInfo +{ + uint32_t attrType; + uint8_t attrSubtype; + uint8_t reserved[3]; + uint32_t attrLength; + uint32_t escapeSeqLength; + uint8_t charSetType; + uint8_t escapeSeq[0]; +} __attribute__ ((packed)); + +/* Alternate Permissions (ECMA 167r3 4/14.10.4) */ +struct altPerms +{ + uint32_t attrType; + uint8_t attrSubtype; + uint8_t reserved[3]; + uint32_t attrLength; + uint16_t ownerIdent; + uint16_t groupIdent; + uint16_t permission; +} __attribute__ ((packed)); + +/* File Times Extended Attribute (ECMA 167r3 4/14.10.5) */ +struct fileTimesExtAttr +{ + uint32_t attrType; + uint8_t attrSubtype; + uint8_t reserved[3]; + uint32_t attrLength; + uint32_t dataLength; + uint32_t fileTimeExistence; + uint8_t fileTimes; +} __attribute__ ((packed)); + +/* FileTimeExistence (ECMA 167r3 4/14.10.5.6) */ +#define FTE_CREATION 0x00000001 +#define FTE_DELETION 0x00000004 +#define FTE_EFFECTIVE 0x00000008 +#define FTE_BACKUP 0x00000002 + +/* Information Times Extended Attribute (ECMA 167r3 4/14.10.6) */ +struct infoTimesExtAttr +{ + uint32_t attrType; + uint8_t attrSubtype; + uint8_t reserved[3]; + uint32_t attrLength; + uint32_t dataLength; + uint32_t infoTimeExistence; + uint8_t infoTimes[0]; +} __attribute__ ((packed)); + +/* Device Specification (ECMA 167r3 4/14.10.7) */ +struct deviceSpec +{ + uint32_t attrType; + uint8_t attrSubtype; + uint8_t reserved[3]; + uint32_t attrLength; + uint32_t impUseLength; + uint32_t majorDeviceIdent; + uint32_t minorDeviceIdent; + uint8_t impUse[0]; +} __attribute__ ((packed)); + +/* Implementation Use Extended Attr (ECMA 167r3 4/14.10.8) */ +struct impUseExtAttr +{ + uint32_t attrType; + uint8_t attrSubtype; + uint8_t reserved[3]; + uint32_t attrLength; + uint32_t impUseLength; + regid impIdent; + uint8_t impUse[0]; +} __attribute__ ((packed)); + +/* Application Use Extended Attribute (ECMA 167r3 4/14.10.9) */ +struct appUseExtAttr +{ + uint32_t attrType; + uint8_t attrSubtype; + uint8_t reserved[3]; + uint32_t attrLength; + uint32_t appUseLength; + regid appIdent; + uint8_t appUse[0]; +} __attribute__ ((packed)); + +#define EXTATTR_CHAR_SET 1 +#define EXTATTR_ALT_PERMS 3 +#define EXTATTR_FILE_TIMES 5 +#define EXTATTR_INFO_TIMES 6 +#define EXTATTR_DEV_SPEC 12 +#define EXTATTR_IMP_USE 2048 +#define EXTATTR_APP_USE 65536 + + +/* Unallocated Space Entry (ECMA 167r3 4/14.11) */ +struct unallocSpaceEntry +{ + tag descTag; + icbtag icbTag; + uint32_t lengthAllocDescs; + uint8_t allocDescs[0]; +} __attribute__ ((packed)); + +/* Space Bitmap Descriptor (ECMA 167r3 4/14.12) */ +struct spaceBitmapDesc +{ + tag descTag; + uint32_t numOfBits; + uint32_t numOfBytes; + uint8_t bitmap[0]; +} __attribute__ ((packed)); + +/* Partition Integrity Entry (ECMA 167r3 4/14.13) */ +struct partitionIntegrityEntry +{ + tag descTag; + icbtag icbTag; + timestamp recordingDateAndTime; + uint8_t integrityType; + uint8_t reserved[175]; + regid impIdent; + uint8_t impUse[256]; +} __attribute__ ((packed)); + +/* Short Allocation Descriptor (ECMA 167r3 4/14.14.1) */ + +/* Extent Length (ECMA 167r3 4/14.14.1.1) */ +#define EXT_LENGTH_MASK 0x3FFFFFFF +#define EXT_RECORDED_ALLOCATED 0x00000000 +#define EXT_NOT_RECORDED_ALLOCATED 0x40000000 +#define EXT_NOT_RECORDED_NOT_ALLOCATED 0x80000000 +#define EXT_NEXT_EXTENT_ALLOCDECS 0xC0000000 + +/* Long Allocation Descriptor (ECMA 167r3 4/14.14.2) */ + +/* Extended Allocation Descriptor (ECMA 167r3 4/14.14.3) */ + +/* Logical Volume Header Descriptor (ECMA 167r3 4/14.15) */ +struct logicalVolHeaderDesc +{ + uint64_t uniqueID; + uint8_t reserved[24]; +} __attribute__ ((packed)); + +/* Path Component (ECMA 167r3 4/14.16.1) */ +struct pathComponent +{ + uint8_t componentType; + uint8_t lengthComponentIdent; + uint16_t componentFileVersionNum; + dchars componentIdent[0]; +} __attribute__ ((packed)); + +/* File Entry (ECMA 167r3 4/14.17) */ +struct extendedFileEntry +{ + tag descTag; + icbtag icbTag; + uint32_t uid; + uint32_t gid; + uint32_t permissions; + uint16_t fileLinkCount; + uint8_t recordFormat; + uint8_t recordDisplayAttr; + uint32_t recordLength; + uint64_t informationLength; + uint64_t objectSize; + uint64_t logicalBlocksRecorded; + timestamp accessTime; + timestamp modificationTime; + timestamp createTime; + timestamp attrTime; + uint32_t checkpoint; + uint32_t reserved; + long_ad extendedAttrICB; + long_ad streamDirectoryICB; + regid impIdent; + uint64_t uniqueID; + uint32_t lengthExtendedAttr; + uint32_t lengthAllocDescs; + uint8_t extendedAttr[0]; + uint8_t allocDescs[0]; +} __attribute__ ((packed)); + +#endif /* _ECMA_167_H */ diff --git a/include/libudffs.h b/include/libudffs.h new file mode 100644 index 0000000..3f1abe3 --- /dev/null +++ b/include/libudffs.h @@ -0,0 +1,235 @@ +/* + * libudffs.h + * + * Copyright (c) 2001-2002 Ben Fennema <bfennema@falcon.csc.calpoly.edu> + * Copyright (c) 2014-2017 Pali Rohár <pali.rohar@gmail.com> + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +/** + * @file + * libudffs defines and structure definitions + */ + +#ifndef __LIBUDFFS_H +#define __LIBUDFFS_H + +#include "ecma_167.h" +#include "osta_udf.h" +#include "udf_endian.h" + +#define FLAG_FREED_BITMAP 0x00000001 +#define FLAG_FREED_TABLE 0x00000002 +#define FLAG_UNALLOC_BITMAP 0x00000004 +#define FLAG_UNALLOC_TABLE 0x00000008 +#define FLAG_SPACE_BITMAP (FLAG_FREED_BITMAP|FLAG_UNALLOC_BITMAP) +#define FLAG_SPACE_TABLE (FLAG_FREED_TABLE|FLAG_UNALLOC_TABLE) +#define FLAG_SPACE (FLAG_SPACE_BITMAP|FLAG_SPACE_TABLE) + +#define FLAG_LOCALE 0x00000010 +#define FLAG_UNICODE8 0x00000020 +#define FLAG_UNICODE16 0x00000040 +#define FLAG_UTF8 0x00000080 +#define FLAG_CHARSET (FLAG_LOCALE|FLAG_UNICODE8|FLAG_UNICODE16|FLAG_UTF8) + +#define FLAG_STRATEGY4096 0x00000100 +#define FLAG_BLANK_TERMINAL 0x00000200 + +#define FLAG_MIN_300_BLOCKS 0x00000400 +#define FLAG_CLOSED 0x00000800 +#define FLAG_VAT 0x00001000 + +#define FLAG_EFE 0x00002000 + +#define FLAG_NO_WRITE 0x00004000 + +#define FLAG_BOOTAREA_PRESERVE 0x00010000 +#define FLAG_BOOTAREA_ERASE 0x00020000 +#define FLAG_BOOTAREA_MBR 0x00040000 +#define FLAG_BOOTAREA_MASK (FLAG_BOOTAREA_PRESERVE|FLAG_BOOTAREA_ERASE|FLAG_BOOTAREA_MBR) + +struct udf_extent; +struct udf_desc; +struct udf_data; + +enum udf_space_type +{ + RESERVED = 0x0001, /* Reserved Space */ + VRS = 0x0002, /* Volume Recognition Sequence */ + ANCHOR = 0x0004, /* Anchor */ + MVDS = 0x0008, /* Main Volume Descriptor Sequence */ + RVDS = 0x0010, /* Reserve Volume Descriptor Sequence */ + LVID = 0x0020, /* Logical Volume Integrity Descriptor */ + STABLE = 0x0040, /* Sparing Table */ + SSPACE = 0x0080, /* Sparing Space */ + PSPACE = 0x0100, /* Partition Space */ + USPACE = 0x0200, /* Unallocated Space */ + BAD = 0x0400, /* Bad Blocks */ + MBR = 0x0800, /* MBR Boot Area */ + UDF_SPACE_TYPE_SIZE = 12, +}; + +struct udf_sizing +{ + uint32_t align; + uint32_t numSize; + uint32_t denomSize; + uint32_t minSize; +}; + +enum udf_alloc_type +{ + VDS_SIZE, + LVID_SIZE, + STABLE_SIZE, + SSPACE_SIZE, + PSPACE_SIZE, + UDF_ALLOC_TYPE_SIZE, +}; + +struct udf_disc +{ + uint16_t udf_rev; + uint16_t udf_write_rev; + uint32_t blocksize; + uint32_t blocks; + uint32_t flags; + unsigned int blkssz; + uint64_t blksize; + uint32_t num_files; + uint32_t num_dirs; + uint32_t free_space_blocks; + uint32_t total_space_blocks; + + uint32_t uid; + uint32_t gid; + uint16_t mode; + + struct udf_sizing sizing[UDF_ALLOC_TYPE_SIZE]; + + int (*write)(struct udf_disc *, struct udf_extent *); + void *write_data; + + struct volStructDesc *udf_vrs[3]; + struct anchorVolDescPtr *udf_anchor[3]; + struct primaryVolDesc *udf_pvd[2]; + struct logicalVolDesc *udf_lvd[2]; + struct partitionDesc *udf_pd[2]; + struct unallocSpaceDesc *udf_usd[2]; + struct impUseVolDesc *udf_iuvd[2]; + struct terminatingDesc *udf_td[2]; + struct logicalVolIntegrityDesc *udf_lvid; + + struct sparingTable *udf_stable[4]; + + uint32_t vat_block; + uint32_t *vat; + uint64_t vat_entries; + + struct fileSetDesc *udf_fsd; + + struct udf_extent *head; + struct udf_extent *tail; +}; + +struct udf_extent +{ + enum udf_space_type space_type; + uint32_t start; + uint32_t blocks; + + struct udf_desc *head; + struct udf_desc *tail; + + struct udf_extent *next; + struct udf_extent *prev; +}; + +struct udf_desc +{ + uint16_t ident; + uint32_t offset; + uint64_t length; + struct udf_data *data; + + struct udf_desc *next; + struct udf_desc *prev; +}; + +struct udf_data +{ + uint64_t length; + void *buffer; + struct udf_data *next; + struct udf_data *prev; +}; + +#define MBR_PARTITION_NOT_BOOTABLE 0x00 +#define MBR_PARTITION_TYPE_IFS 0x07 /* Installable File System (IFS), see: https://serverfault.com/a/829172 */ + +struct mbr_partition +{ + uint8_t boot_indicator; + uint8_t starting_chs[3]; + uint8_t partition_type; + uint8_t ending_chs[3]; + uint32_t starting_lba; + uint32_t size_in_lba; +} __attribute__ ((packed)); + +#define MBR_BOOT_SIGNATURE 0xAA55 + +struct mbr +{ + unsigned char boot_code[440]; + uint32_t disk_signature; + uint16_t unknown; + struct mbr_partition partitions[4]; + uint16_t boot_signature; +} __attribute__ ((packed)); + +/* crc.c */ +extern uint16_t udf_crc(uint8_t *, uint32_t, uint16_t); + +/* extent.c */ +struct udf_extent *next_extent(struct udf_extent *, enum udf_space_type); +uint32_t next_extent_size(struct udf_disc *, struct udf_extent *, enum udf_space_type, uint32_t, uint32_t); +uint32_t find_next_extent_size(struct udf_disc *, uint32_t, enum udf_space_type, uint32_t, uint32_t); +struct udf_extent *prev_extent(struct udf_extent *, enum udf_space_type); +uint32_t prev_extent_size(struct udf_extent *, enum udf_space_type, uint32_t, uint32_t); +struct udf_extent *find_extent(struct udf_disc *, uint32_t); +struct udf_extent *set_extent(struct udf_disc *, enum udf_space_type, uint32_t,uint32_t); +struct udf_desc *next_desc(struct udf_desc *, uint16_t); +struct udf_desc *find_desc(struct udf_extent *, uint32_t); +struct udf_desc *set_desc(struct udf_extent *, uint16_t, uint32_t, uint32_t, struct udf_data *); +void append_data(struct udf_desc *, struct udf_data *); +struct udf_data *alloc_data(void *, int); + +/* unicode.c */ +extern size_t decode_utf8(const dchars *, char *, size_t, size_t); +extern size_t encode_utf8(dchars *, const char *, size_t); +extern size_t decode_locale(const dchars *, char *, size_t, size_t); +extern size_t encode_locale(dchars *, const char *, size_t); +extern size_t decode_string(struct udf_disc *, const dstring *, char *, size_t, size_t); +extern size_t encode_string(struct udf_disc *, dstring *, const char *, size_t); + +/* misc.c */ +extern const char *appname; +size_t gen_uuid_from_vol_set_ident(char[17], const dstring *, size_t); + +#endif /* __LIBUDFFS_H */ diff --git a/include/osta_udf.h b/include/osta_udf.h new file mode 100644 index 0000000..413c816 --- /dev/null +++ b/include/osta_udf.h @@ -0,0 +1,278 @@ +/* + * osta_udf.h + * + * This file is based on OSTA UDF(tm) 2.01 (March 15, 2000) + * http://www.osta.org + * + * Copyright (c) 2001-2002 Ben Fennema <bfennema@falcon.csc.calpoly.edu> + * Copyright (c) 2017 Pali Rohár <pali.rohar@gmail.com> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU Public License ("GPL"). + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/** + * @file + * OSTA-UDF defines and structure definitions + */ + +#include "ecma_167.h" + +#ifndef _OSTA_UDF_H +#define _OSTA_UDF_H 1 + +/* OSTA CS0 Charspec (UDF 2.01 2.1.2) */ +#define UDF_CHAR_SET_TYPE 0 +#define UDF_CHAR_SET_INFO "OSTA Compressed Unicode" + +/* Entity Identifier (UDF 2.01 2.1.5) */ +/* Identifiers (UDF 2.01 2.1.5.2) */ +#define UDF_ID_DEVELOPER "*Linux UDFFS" +#define UDF_ID_COMPLIANT "*OSTA UDF Compliant" +#define UDF_ID_LV_INFO "*UDF LV Info" +#define UDF_ID_FREE_EA "*UDF FreeEASpace" +#define UDF_ID_FREE_APP_EA "*UDF FreeAppEASpace" +#define UDF_ID_DVD_CGMS "*UDF DVD CGMS Info" +#define UDF_ID_OS2_EA "*UDF OS/2 EA" +#define UDF_ID_OS2_EA_LENGTH "*UDF OS/2 EALength" +#define UDF_ID_MAC_VOLUME "*UDF Mac VolumeInfo" +#define UDF_ID_MAC_FINDER "*UDF Mac FinderInfo" +#define UDF_ID_MAC_UNIQUE "*UDF Mac UniqueIDTable" +#define UDF_ID_MAC_RESOURCE "*UDF Mac ResourceFork" +#define UDF_ID_VIRTUAL "*UDF Virtual Partition" +#define UDF_ID_SPARABLE "*UDF Sparable Partition" +#define UDF_ID_ALLOC "*UDF Virtual Alloc Tbl" +#define UDF_ID_SPARING "*UDF Sparing Table" +#define UDF_ID_METADATA "*UDF Metadata Partition" + +/* Identifier Suffix (UDF 2.01 2.1.5.3) */ +#define IS_DF_HARD_WRITE_PROTECT 0x01 +#define IS_DF_SOFT_WRITE_PROTECT 0x02 + +struct UDFIdentSuffix +{ + uint16_t UDFRevision; + uint8_t OSClass; + uint8_t OSIdentifier; + uint8_t reserved[4]; +} __attribute__ ((packed)); + +struct impIdentSuffix +{ + uint8_t OSClass; + uint8_t OSIdentifier; + uint8_t reserved[6]; +} __attribute__ ((packed)); + +struct appIdentSuffix +{ + uint8_t impUse[8]; +} __attribute__ ((packed)); + +/* Logical Volume Integrity Descriptor (UDF 2.01 2.2.6) */ +/* Implementation Use (UDF 2.01 2.2.6.4) */ +struct logicalVolIntegrityDescImpUse +{ + regid impIdent; + uint32_t numFiles; + uint32_t numDirs; + uint16_t minUDFReadRev; + uint16_t minUDFWriteRev; + uint16_t maxUDFWriteRev; + uint8_t impUse[0]; +} __attribute__ ((packed)); + +/* Implementation Use Volume Descriptor (UDF 2.01 2.2.7) */ +/* Implementation Use (UDF 2.01 2.2.7.2) */ +struct impUseVolDescImpUse +{ + charspec LVICharset; + dstring logicalVolIdent[128]; + dstring LVInfo1[36]; + dstring LVInfo2[36]; + dstring LVInfo3[36]; + regid impIdent; + uint8_t impUse[128]; +} __attribute__ ((packed)); + +struct udfPartitionMap2 +{ + uint8_t partitionMapType; + uint8_t partitionMapLength; + uint8_t reserved1[2]; + regid partIdent; + uint16_t volSeqNum; + uint16_t partitionNum; +} __attribute__ ((packed)); + +/* Virtual Partition Map (UDF 2.01 2.2.8) */ +struct virtualPartitionMap +{ + uint8_t partitionMapType; + uint8_t partitionMapLength; + uint8_t reserved1[2]; + regid partIdent; + uint16_t volSeqNum; + uint16_t partitionNum; + uint8_t reserved2[24]; +} __attribute__ ((packed)); + +/* Sparable Partition Map (UDF 2.01 2.2.9) */ +struct sparablePartitionMap +{ + uint8_t partitionMapType; + uint8_t partitionMapLength; + uint8_t reserved1[2]; + regid partIdent; + uint16_t volSeqNum; + uint16_t partitionNum; + uint16_t packetLength; + uint8_t numSparingTables; + uint8_t reserved2[1]; + uint32_t sizeSparingTable; + uint32_t locSparingTable[4]; +} __attribute__ ((packed)); + +/* Virtual Allocation Table (UDF 1.5 2.2.10) */ +struct virtualAllocationTable15 +{ + uint32_t vatEntry[0]; + regid vatIdent; + uint32_t previousVATICBLoc; +} __attribute__ ((packed)); + +#define ICBTAG_FILE_TYPE_VAT15 0x00U + +/* Virtual Allocation Table (UDF 2.01 2.2.10) */ +struct virtualAllocationTable20 +{ + uint16_t lengthHeader; + uint16_t lengthImpUse; + dstring logicalVolIdent[128]; + uint32_t previousVATICBLoc; + uint32_t numFiles; + uint32_t numDirs; + uint16_t minUDFReadRev; + uint16_t minUDFWriteRev; + uint16_t maxUDFWriteRev; + uint16_t reserved; + uint8_t impUse[0]; + uint32_t vatEntry[0]; +} __attribute__ ((packed)); + +#define ICBTAG_FILE_TYPE_VAT20 0xF8U + +/* Sparing Table (UDF 2.01 2.2.11) */ +struct sparingEntry +{ + uint32_t origLocation; + uint32_t mappedLocation; +} __attribute__ ((packed)); + +struct sparingTable +{ + tag descTag; + regid sparingIdent; + uint16_t reallocationTableLen; + uint16_t reserved; + uint32_t sequenceNum; + struct sparingEntry + mapEntry[0]; +} __attribute__ ((packed)); + +/* struct long_ad ICB - ADImpUse (UDF 2.01 2.2.4.3) */ +struct allocDescImpUse +{ + uint16_t flags; + uint8_t impUse[4]; +} __attribute__ ((packed)); + +#define AD_IU_EXT_ERASED 0x0001 + +/* Real-Time Files (UDF 2.01 6.11) */ +#define ICBTAG_FILE_TYPE_REALTIME 0xF9U + +/* Implementation Use Extended Attribute (UDF 2.01 3.3.4.5) */ +/* FreeEASpace (UDF 2.01 3.3.4.5.1.1) */ +struct freeEaSpace +{ + uint16_t headerChecksum; + uint8_t freeEASpace[0]; +} __attribute__ ((packed)); + +/* DVD Copyright Management Information (UDF 2.01 3.3.4.5.1.2) */ +struct DVDCopyrightImpUse +{ + uint16_t headerChecksum; + uint8_t CGMSInfo; + uint8_t dataType; + uint8_t protectionSystemInfo[4]; +} __attribute__ ((packed)); + +/* Application Use Extended Attribute (UDF 2.01 3.3.4.6) */ +/* FreeAppEASpace (UDF 2.01 3.3.4.6.1) */ +struct freeAppEASpace +{ + uint16_t headerChecksum; + uint8_t freeEASpace[0]; +} __attribute__ ((packed)); + +/* UDF Defined System Stream (UDF 2.01 3.3.7) */ +#define UDF_ID_UNIQUE_ID "*UDF Unique ID Mapping Data" +#define UDF_ID_NON_ALLOC "*UDF Non-Allocatable Space" +#define UDF_ID_POWER_CAL "*UDF Power Cal Table" +#define UDF_ID_BACKUP "*UDF Backup" + +/* Operating System Identifiers (UDF 2.01 6.3) */ +#define UDF_OS_CLASS_UNDEF 0x00U +#define UDF_OS_CLASS_DOS 0x01U +#define UDF_OS_CLASS_OS2 0x02U +#define UDF_OS_CLASS_MAC 0x03U +#define UDF_OS_CLASS_UNIX 0x04U +#define UDF_OS_CLASS_WIN9X 0x05U +#define UDF_OS_CLASS_WINNT 0x06U +#define UDF_OS_CLASS_OS400 0x07U +#define UDF_OS_CLASS_BEOS 0x08U +#define UDF_OS_CLASS_WINCE 0x09U + +#define UDF_OS_ID_UNDEF 0x00U +#define UDF_OS_ID_DOS 0x00U +#define UDF_OS_ID_OS2 0x00U +#define UDF_OS_ID_MAC 0x00U +#define UDF_OS_ID_UNIX 0x00U +#define UDF_OS_ID_AIX 0x01U +#define UDF_OS_ID_SOLARIS 0x02U +#define UDF_OS_ID_HPUX 0x03U +#define UDF_OS_ID_IRIX 0x04U +#define UDF_OS_ID_LINUX 0x05U +#define UDF_OS_ID_MKLINUX 0x06U +#define UDF_OS_ID_FREEBSD 0x07U +#define UDF_OS_ID_WIN9X 0x00U +#define UDF_OS_ID_WINNT 0x00U +#define UDF_OS_ID_OS400 0x00U +#define UDF_OS_ID_BEOS 0x00U +#define UDF_OS_ID_WINCE 0x00U + +#endif /* _OSTA_UDF_H */ diff --git a/include/udf_endian.h b/include/udf_endian.h new file mode 100644 index 0000000..daa0e3d --- /dev/null +++ b/include/udf_endian.h @@ -0,0 +1,104 @@ +/* + * udf_endian.h + * + * Copyright (c) 2001-2002 Ben Fennema <bfennema@falcon.csc.calpoly.edu> + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#ifndef __UDF_ENDIAN_H +#define __UDF_ENDIAN_H + +#include <string.h> + +#include "bswap.h" + +static inline lb_addr lelb_to_cpu(lb_addr in) +{ + lb_addr out; + out.logicalBlockNum = le32_to_cpu(in.logicalBlockNum); + out.partitionReferenceNum = le16_to_cpu(in.partitionReferenceNum); + return out; +} + +static inline lb_addr cpu_to_lelb(lb_addr in) +{ + lb_addr out; + out.logicalBlockNum = cpu_to_le32(in.logicalBlockNum); + out.partitionReferenceNum = cpu_to_le16(in.partitionReferenceNum); + return out; +} + +static inline timestamp lets_to_cpu(timestamp in) +{ + timestamp out; + memcpy(&out, &in, sizeof(timestamp)); + out.typeAndTimezone = le16_to_cpu(in.typeAndTimezone); + out.year = le16_to_cpu(in.year); + return out; +} + +static inline short_ad lesa_to_cpu(short_ad in) +{ + short_ad out; + out.extLength = le32_to_cpu(in.extLength); + out.extPosition = le32_to_cpu(in.extPosition); + return out; +} + +static inline short_ad cpu_to_lesa(short_ad in) +{ + short_ad out; + out.extLength = cpu_to_le32(in.extLength); + out.extPosition = cpu_to_le32(in.extPosition); + return out; +} + +static inline long_ad lela_to_cpu(long_ad in) +{ + long_ad out; + out.extLength = le32_to_cpu(in.extLength); + out.extLocation = lelb_to_cpu(in.extLocation); + return out; +} + +static inline long_ad cpu_to_lela(long_ad in) +{ + long_ad out; + out.extLength = cpu_to_le32(in.extLength); + out.extLocation = cpu_to_lelb(in.extLocation); + return out; +} + +static inline extent_ad leea_to_cpu(extent_ad in) +{ + extent_ad out; + out.extLength = le32_to_cpu(in.extLength); + out.extLocation = le32_to_cpu(in.extLocation); + return out; +} + +static inline timestamp cpu_to_lets(timestamp in) +{ + timestamp out; + memcpy(&out, &in, sizeof(timestamp)); + out.typeAndTimezone = cpu_to_le16(in.typeAndTimezone); + out.year = cpu_to_le16(in.year); + return out; +} + +#endif /* __UDF_ENDIAN_H */ |