udftools

- Main Page
- Classes
- Files

- File List
- File Members

All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Classes | Macros | Enumerations | Functions | Variables
libudffs.h File Reference
`#include "ecma_167.h"`
`#include "osta_udf.h"`
`#include "udf_endian.h"`
Include dependency graph for libudffs.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Classes
struct | udf_sizing
struct | udf_disc
struct | udf_extent
struct | udf_desc
struct | udf_data

## Macros
#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_EFE 0x00000010
#define | FLAG_UNICODE8 0x00000020
#define | FLAG_UNICODE16 0x00000040
#define | FLAG_UTF8 0x00000080
#define | FLAG_CHARSET (FLAG_UNICODE8|FLAG_UNICODE16|FLAG_UTF8)
#define | FLAG_STRATEGY4096 0x00000100
#define | FLAG_BLANK_TERMINAL 0x00000200
#define | FLAG_BRIDGE 0x00000400
#define | FLAG_CLOSED 0x00000800
#define | FLAG_VAT 0x00001000

## Enumerations
enum | udf_space_type { RESERVED = 0x0001, VRS = 0x0002, ANCHOR = 0x0004, PVDS = 0x0008, RVDS = 0x0010, LVID = 0x0020, STABLE = 0x0040, SSPACE = 0x0080, PSPACE = 0x0100, USPACE = 0x0200, BAD = 0x0400, UDF_SPACE_TYPE_SIZE = 11 }
enum | udf_alloc_type { VDS_SIZE, LVID_SIZE, STABLE_SIZE, SSPACE_SIZE, PSPACE_SIZE, UDF_ALLOC_TYPE_SIZE }

## Functions
uint16_t | udf_crc (uint8_t *, uint32_t, uint16_t)
struct udf_extent * | next_extent (struct udf_extent *, enum udf_space_type)
| find the next udf_extent of a given space_type on a udf_extent list More...
uint32_t | next_extent_size (struct udf_extent *, enum udf_space_type, uint32_t, uint32_t)
| find the next udf_extent of a given space_type on a udf_extent list that satisfies the necessary size and alignment More...
struct udf_extent * | prev_extent (struct udf_extent *, enum udf_space_type)
| find the previous udf_extent of a given space_type on a udf_extent list More...
uint32_t | prev_extent_size (struct udf_extent *, enum udf_space_type, uint32_t, uint32_t)
| find the previous udf_extent of a given space_type on a udf_extent list that satisfies the necessary size and alignment More...
struct udf_extent * | find_extent (struct udf_disc *, uint32_t)
| find the udf_extent on a udf_disc's udf_extent list which contains a particular block More...
struct udf_extent * | set_extent (struct udf_disc *, enum udf_space_type, uint32_t, uint32_t)
| set the space_type, location and size of a udf_extent on a udf_disc's udf_extent list, splitting the udf_extent if required to have the returned udf_extent only contain the requested blocks More...
struct udf_desc * | next_desc (struct udf_desc *, uint16_t)
| find the next udf_descriptor of a given tag ident on a udf_descriptor list More...
struct udf_desc * | find_desc (struct udf_extent *, uint32_t)
| search the udf_descriptor list of a udf_extent to find the udf_descriptor that describes a particular block More...
struct udf_desc * | set_desc (struct udf_disc *, struct udf_extent *, uint16_t, uint32_t, uint32_t, struct udf_data *)
| allocate a new udf_descriptor having a udf_data item and insert it into the udf_descriptor list of a udf_extent ordered by block number More...
void | append_data (struct udf_desc *, struct udf_data *)
| append a udf_data list to the end of the udf_data list of a udf_descriptor and update the udf_descriptor summed data length More...
struct udf_data * | alloc_data (void *, int)
| allocate a new udf_data item and initialize it with either allocated zeros or the supplied payload More...
size_t | decode_utf8 (dstring *, char *, size_t)
size_t | encode_utf8 (dstring *, char *, char *, size_t)
size_t | decode_string (struct udf_disc *, dstring *, char *, size_t)
size_t | encode_string (struct udf_disc *, dstring *, char *, char *, size_t)

## Variables
enum udf_space_type | __attribute__

## Detailed Description

libudffs defines and structure definitions

Definition in file libudffs.h.

## Macro Definition Documentation

#define FLAG_BLANK_TERMINAL 0x00000200

Definition at line 51 of file libudffs.h.

#define FLAG_BRIDGE 0x00000400

Definition at line 53 of file libudffs.h.

#define FLAG_CHARSET (FLAG_UNICODE8|FLAG_UNICODE16|FLAG_UTF8)

Definition at line 48 of file libudffs.h.

#define FLAG_CLOSED 0x00000800

Definition at line 54 of file libudffs.h.

#define FLAG_EFE 0x00000010

Definition at line 43 of file libudffs.h.

#define FLAG_FREED_BITMAP 0x00000001

Definition at line 35 of file libudffs.h.

#define FLAG_FREED_TABLE 0x00000002

Definition at line 36 of file libudffs.h.

#define FLAG_SPACE (FLAG_SPACE_BITMAP|FLAG_SPACE_TABLE)

Definition at line 41 of file libudffs.h.

#define FLAG_SPACE_BITMAP (FLAG_FREED_BITMAP|FLAG_UNALLOC_BITMAP)

Definition at line 39 of file libudffs.h.

#define FLAG_SPACE_TABLE (FLAG_FREED_TABLE|FLAG_UNALLOC_TABLE)

Definition at line 40 of file libudffs.h.

#define FLAG_STRATEGY4096 0x00000100

Definition at line 50 of file libudffs.h.

#define FLAG_UNALLOC_BITMAP 0x00000004

Definition at line 37 of file libudffs.h.

#define FLAG_UNALLOC_TABLE 0x00000008

Definition at line 38 of file libudffs.h.

#define FLAG_UNICODE16 0x00000040

Definition at line 46 of file libudffs.h.

#define FLAG_UNICODE8 0x00000020

Definition at line 45 of file libudffs.h.

#define FLAG_UTF8 0x00000080

Definition at line 47 of file libudffs.h.

#define FLAG_VAT 0x00001000

Definition at line 55 of file libudffs.h.

## Enumeration Type Documentation

enum udf_alloc_type

Enumerator
VDS_SIZE |
LVID_SIZE |
STABLE_SIZE |
SSPACE_SIZE |
PSPACE_SIZE |
UDF_ALLOC_TYPE_SIZE |

Definition at line 85 of file libudffs.h.

enum udf_space_type

Enumerator
RESERVED |
VRS |
ANCHOR |
PVDS |
RVDS |
LVID |
STABLE |
SSPACE |
PSPACE |
USPACE |
BAD |
UDF_SPACE_TYPE_SIZE |

Definition at line 61 of file libudffs.h.

## Function Documentation

struct udf_data* alloc_data | ( | void * | buffer,
|  | int | length
| ) |  |

allocate a new udf_data item and initialize it with either allocated zeros or the supplied payload

Parameters

  buffer | the supplied payload, if NULL allocate memory for the payload
  length | the length of the udf_data item payload in bytes

Returns
  the in-memory address of the new udf_data item

Definition at line 462 of file extent.c.

void append_data | ( | struct udf_desc * | desc,
|  | struct udf_data * | data
| ) |  |

append a udf_data list to the end of the udf_data list of a udf_descriptor and update the udf_descriptor summed data length

Parameters

  desc | the udf_descriptor containing the target udf_data list head
  data | the source udf_data list head

Returns
  void

Definition at line 442 of file extent.c.

size_t decode_string | ( | struct udf_disc * | ,
|  | dstring * | ,
|  | char * | ,
|  | size_t |
| ) |  |

Definition at line 178 of file unicode.c.

size_t decode_utf8 | ( | dstring * | ,
|  | char * | ,
|  | size_t |
| ) |  |

Definition at line 32 of file unicode.c.

size_t encode_string | ( | struct udf_disc * | ,
|  | dstring * | ,
|  | char * | ,
|  | char * | ,
|  | size_t |
| ) |  |

Definition at line 191 of file unicode.c.

size_t encode_utf8 | ( | dstring * | ,
|  | char * | ,
|  | char * | ,
|  | size_t |
| ) |  |

Definition at line 68 of file unicode.c.

struct udf_desc* find_desc | ( | struct udf_extent * | ext,
|  | uint32_t | offset
| ) |  |

search the udf_descriptor list of a udf_extent to find the udf_descriptor that describes a particular block

Parameters

  ext | the udf_extent containing the udf_descriptor list head
  offset | the block to search for

Returns
  the in-memory address of the udf_descriptor or NULL

Definition at line 366 of file extent.c.

struct udf_extent* find_extent | ( | struct udf_disc * | disc,
|  | uint32_t | start
| ) |  |

find the udf_extent on a udf_disc's udf_extent list which contains a particular block

Parameters

  disc | the udf_disc containing the udf_extent list head
  start | the block to search for

Returns
  the in-memory address of the udf_extent or NULL

Definition at line 207 of file extent.c.

struct udf_desc* next_desc | ( | struct udf_desc * | start_desc,
|  | uint16_t | ident
| ) |  |

find the next udf_descriptor of a given tag ident on a udf_descriptor list

Parameters

  start_desc | the starting udf_descriptor for the search
  ident | the tag ident of udf_descriptor to search for

Returns
  the in-memory address of the udf_descriptor or NULL

Definition at line 351 of file extent.c.

struct udf_extent* next_extent | ( | struct udf_extent * | start_ext,
|  | enum udf_space_type | type
| ) |  |

find the next udf_extent of a given space_type on a udf_extent list

This code was very sparsely commented and essentially undocumented as written. Comments and doxygen documentation were generated by code inspection more than a decade after the fact. If you find errors please feel free to correct them.

For a more detailed discussion about descriptors the comments at the top of file.c in this directory.

Volume space is the set of all blocks on a particular physical disc volume. Blocks in volume space are described using an 32-bit short_ad. A volume-set is multiple related physical volumes, usually with a robotic media changer. Blocks anywhere in a volume set are described by an 48-bit long_ad which contains a volume identifier as well as a location in the volume space of the identifed volume. Block numbers in volume space start at zero and are relative to the first block of the media.

Partition space is the set of all blocks contained in a logical partition. Block numbers in partition space start at zero and are relative to the first block of the partition, NOT the first block of of the media

An 'extent' is a contiguous set of data and a descriptor is a structure containing descriptive information, but these names are used in two very different ways when creating a UDF filesystem on a disc volume/volume-set.

An ECMA-167 extent is a region in the volume space of a single physical disc volume described by type extent_ad having a 32-bit starting block and a 32-bit length <2^30 BYTES which is normally a multiple of blocksize. The two high order bits define the allocated/written status of the extent. These extents are used in on-disc descriptors at the physical volume level for structures such as the primary volume descriptor and anchor points that operate above the filesystem level.

The on-disc descriptors are little-endian and require the use of various le*_to_cpu() and cpu_to_le*() functions when reading and writing them. Descriptors like the primary volume descriptor which are shared with other standards such as ECMA-119/ISO-9660 begin with a one byte type identifier. Other descriptors which are specific to ECMA-167 and UDF begin with a 16-byte tag which starts with a two byte tag identifer and contains additional information such as a CRC field which is pertinent to udf_extents.

A udf_extent is an in-memory structure used to organize UDF filesystem level structures such as directories and files and is described using a struct udf_extent having a 32-bit starting block and a 32-bit length IN BLOCKS as well as a space type such as unallocated or partition space and various linked lists in cpu byte order. A udf_disc starts with a single extent of unallocated space which becomes a list as that extent is split and the new smaller extents are used for various things. A udf_extent has a udf_descriptor list which is kept sorted by the location within the extent of the described blocks. A udf_descriptor can have a number of different tag identifiers such as file-entry/extended-file-entry descriptor or allocation descriptor. A udf_descriptor has a udf_data list. A udf_data item carries a payload of arbitrary data dependent on the descriptor type. The udf_descriptor can be thought of as the in-memory version of the descriptor tag since it contains the tag ident. The on-disc format structure corresponding to that tag is stored in the first udf_data item on the udf_data list of that descriptor. The 16-byte on-disc format tag will be at the beginning of that structure.

Once the UDF volume structure has been constructed in memory, writing it to disc is just a matter of iterating through the extents and their descriptors and data in order and writing them sequentially onto the media while also converting to the on-disc little-endian format as needed.

Parameters

  start_ext | the starting udf_extent for the search
  type | the space_type of the udf_extent to search for

Returns
  the in-memory address of udf_extent or NULL

Definition at line 112 of file extent.c.

uint32_t next_extent_size | ( | struct udf_extent * | start_ext,
|  | enum udf_space_type | type,
|  | uint32_t | blocks,
|  | uint32_t | offset
| ) |  |

find the next udf_extent of a given space_type on a udf_extent list that satisfies the necessary size and alignment

Parameters

  start_ext | the starting udf_extent for the search
  type | the space_type of the udf_extent to search for
  blocks | the minimum size of the udf_extent in blocks
  offset | the required alignment for the start block

Returns
  the start block of the aligned udf_extent or zero

Definition at line 129 of file extent.c.

struct udf_extent* prev_extent | ( | struct udf_extent * | start_ext,
|  | enum udf_space_type | type
| ) |  |

find the previous udf_extent of a given space_type on a udf_extent list

Parameters

  start_ext | the starting udf_extent for the search
  type | the space_type of the udf_extent to search for

Returns
  the in-memory address of the udf_extent or NULL

Definition at line 159 of file extent.c.

uint32_t prev_extent_size | ( | struct udf_extent * | start_ext,
|  | enum udf_space_type | type,
|  | uint32_t | blocks,
|  | uint32_t | offset
| ) |  |

find the previous udf_extent of a given space_type on a udf_extent list that satisfies the necessary size and alignment

Parameters

  start_ext | the starting udf_extent for the search
  type | the space_type of the udf_extent to search for
  blocks | the minimum size of the udf_extent in blocks
  offset | the required alignment for the start block

Returns
  the start block of the aligned udf_extent or zero

Definition at line 176 of file extent.c.

struct udf_desc* set_desc | ( | struct udf_disc * | disc,
|  | struct udf_extent * | ext,
|  | uint16_t | ident,
|  | uint32_t | offset,
|  | uint32_t | length,
|  | struct udf_data * | data
| ) |  |

allocate a new udf_descriptor having a udf_data item and insert it into the udf_descriptor list of a udf_extent ordered by block number

Parameters

  disc | the udf_disc - unused ext the udf_extent containing the udf_descriptor list head
  ident | the tag ident of the new udf_descriptor
  offset | the first block the new descriptor describes
  length | the length of the udf_data item payload in bytes
  data | the udf_data item, if NULL allocate memory for the udf_data item

Returns
  the in-memory address of the new udf_descriptor

Definition at line 393 of file extent.c.

struct udf_extent* set_extent | ( | struct udf_disc * | disc,
|  | enum udf_space_type | type,
|  | uint32_t | start,
|  | uint32_t | blocks
| ) |  |

set the space_type, location and size of a udf_extent on a udf_disc's udf_extent list, splitting the udf_extent if required to have the returned udf_extent only contain the requested blocks

Parameters

  disc | the udf_disc containing the blocks
  type | the space_type of the udf_extent
  start | the start block of the udf_extent
  blocks | the size of the udf_extent in blocks

Returns
  the in-memory address of the udf_extent

Definition at line 230 of file extent.c.

uint16_t udf_crc | ( | uint8_t * | ,
|  | uint32_t | ,
|  | uint16_t |
| ) |  |

Definition at line 88 of file crc.c.

## Variable Documentation

enum udf_space_type __attribute__