udftools

- Main Page
- Classes
- Files

- File List
- File Members

All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Macros | Functions
file.c File Reference
`#include "config.h"`
`#include <malloc.h>`
`#include "libudffs.h"`
`#include "file.h"`
`#include "defaults.h"`
Include dependency graph for file.c:

Go to the source code of this file.

## Macros
#define | BITS_PER_LONG 32
#define | leBPL_to_cpup(x) leNUM_to_cpup(BITS_PER_LONG, x)
#define | leNUM_to_cpup(x, y) xleNUM_to_cpup(x,y)
#define | xleNUM_to_cpup(x, y) (le ## x ## _to_cpup(y))
#define | uintBPL uint(BITS_PER_LONG)
#define | uint(x) xuint(x)
#define | xuint(x) uint ## x ## _t

## Functions
tag | query_tag (struct udf_disc *disc, struct udf_extent *ext, struct udf_desc *desc, uint16_t SerialNum)
| create an on-disc format tag for a udf_descriptor of a udf_extent with any space_type. For type:PSPACE the block number will be relative to to the first block of the partition, otherwise it will be relative to the first block of the media More...
tag | udf_query_tag (struct udf_disc *disc, uint16_t Ident, uint16_t SerialNum, uint32_t Location, struct udf_data *data, uint16_t length)
| create an on-disc format tag from udf_descriptor components More...
int | insert_desc (struct udf_disc *disc, struct udf_extent *pspace, struct udf_desc *desc, struct udf_desc *parent, struct udf_data *data)
| append a udf_data item containing a FID in the payload to the udf_data list for a directory tag:FE/EFE udf_descriptor More...
void | insert_data (struct udf_disc *disc, struct udf_extent *pspace, struct udf_desc *desc, struct udf_data *data)
| append a udf_data list to a (hidden) VAT file ??? More...
uint32_t | compute_ident_length (uint32_t length)
| helper function to compute tag:FID udf_descriptor size and padding to a multiple of 4 bytes More...
void | insert_fid (struct udf_disc *disc, struct udf_extent *pspace, struct udf_desc *desc, struct udf_desc *parent, uint8_t *name, uint8_t length, uint8_t filechar)
| create a FID and add it to a directory then increment the file link count More...
struct udf_desc * | udf_create (struct udf_disc *disc, struct udf_extent *pspace, uint8_t *name, uint8_t length, uint32_t offset, struct udf_desc *parent, uint8_t filechar, uint8_t filetype, uint16_t flags)
| create a file tag:FE/EFE udf_descriptor and add the file to a directory More...
struct udf_desc * | udf_mkdir (struct udf_disc *disc, struct udf_extent *pspace, uint8_t *name, uint8_t length, uint32_t offset, struct udf_desc *parent)
| create a directory tag:FE/EFE udf_descriptor and add the directory to a parent directory More...
static unsigned long | ffz (unsigned long word)
| utility function to find the first zero bit in an unsigned long More...
static unsigned long | udf_find_next_one_bit (void *addr, unsigned long size, unsigned long offset)
| find the first one bit in a space bitmap More...
static unsigned long | udf_find_next_zero_bit (void *addr, unsigned long size, unsigned long offset)
| find the first zero bit in a space bitmap More...
int | udf_alloc_bitmap_blocks (struct udf_disc *disc, struct udf_extent *pspace, struct udf_desc *bitmap, uint32_t start, uint32_t blocks)
| allocate an aligned space bitmap on-disc More...
int | udf_alloc_table_blocks (struct udf_disc *disc, struct udf_extent *pspace, struct udf_desc *table, uint32_t start, uint32_t blocks)
| allocate a space table on-disc More...
int | udf_alloc_blocks (struct udf_disc *disc, struct udf_extent *pspace, uint32_t start, uint32_t blocks)
| allocate blocks on-disc More...

## Detailed Description

libudffs file and directory handling functions

Definition in file file.c.

## Macro Definition Documentation

#define BITS_PER_LONG 32

Definition at line 598 of file file.c.

#define leBPL_to_cpup | ( |  | x | ) | leNUM_to_cpup(BITS_PER_LONG, x)

Definition at line 600 of file file.c.

#define leNUM_to_cpup | ( |  | x,
|  |  | y
| ) |  | xleNUM_to_cpup(x,y)

Definition at line 601 of file file.c.

#define uint | ( |  | x | ) | xuint(x)

Definition at line 604 of file file.c.

#define uintBPL uint(BITS_PER_LONG)

Definition at line 603 of file file.c.

#define xleNUM_to_cpup | ( |  | x,
|  |  | y
| ) |  | (le ## x ## _to_cpup(y))

Definition at line 602 of file file.c.

#define xuint | ( |  | x | ) | uint ## x ## _t

Definition at line 605 of file file.c.

## Function Documentation

uint32_t compute_ident_length | ( | uint32_t | length | ) |

helper function to compute tag:FID udf_descriptor size and padding to a multiple of 4 bytes

Parameters

  length | the length of the file name in bytes

Returns
  the length of the required memory allocation

Definition at line 368 of file file.c.

static unsigned long ffz | ( | unsigned long | word | ) |
| inline static

utility function to find the first zero bit in an unsigned long

Parameters

  word | the unsigned long to search

Returns
  the 0 based bit position from the lsb or BITS_PER_LONG

Definition at line 612 of file file.c.

void insert_data | ( | struct udf_disc * | disc,
|  | struct udf_extent * | pspace,
|  | struct udf_desc * | desc,
|  | struct udf_data * | data
| ) |  |

append a udf_data list to a (hidden) VAT file ???

Parameters

  disc | the udf_disc
  pspace | the type:PSPACE udf_extent for on-disc allocations
  desc | the file tag:FE/EFE udf_descriptor of a VAT file
  data | the udf_data list head

Returns
  void

Definition at line 333 of file file.c.

int insert_desc | ( | struct udf_disc * | disc,
|  | struct udf_extent * | pspace,
|  | struct udf_desc * | desc,
|  | struct udf_desc * | parent,
|  | struct udf_data * | data
| ) |  |

append a udf_data item containing a FID in the payload to the udf_data list for a directory tag:FE/EFE udf_descriptor

Parameters

  disc | the udf_disc
  pspace | the type:PSPACE udf_extent for on-disc allocations
  desc | the file tag:FE/EFE udf_descriptor (for offset)
  parent | the directory tag:FE/EFE udf_descriptor
  data | the udf_data item containing the FID

Returns
  the block number of the on-disc tag:FID udf_desciptor

Definition at line 174 of file file.c.

void insert_fid | ( | struct udf_disc * | disc,
|  | struct udf_extent * | pspace,
|  | struct udf_desc * | desc,
|  | struct udf_desc * | parent,
|  | uint8_t * | name,
|  | uint8_t | length,
|  | uint8_t | filechar
| ) |  |

create a FID and add it to a directory then increment the file link count

Parameters

  disc | the udf_disc
  pspace | the type:PSPACE udf_extent for on-disc allocations
  desc | the file tag:FE/EFE udf_descriptor
  parent | the directory tag:FE/EFE udf_descriptor
  name | the file name - the first byte is the OSTA unicode compression type
  length | the length of the file name in bytes
  filechar | the file characteristics

Returns
  void

Definition at line 385 of file file.c.

tag query_tag | ( | struct udf_disc * | disc,
|  | struct udf_extent * | ext,
|  | struct udf_desc * | desc,
|  | uint16_t | SerialNum
| ) |  |

create an on-disc format tag for a udf_descriptor of a udf_extent with any space_type. For type:PSPACE the block number will be relative to to the first block of the partition, otherwise it will be relative to the first block of the media

For a more detailed discussion of partition and extends see the comments at the top of extent.c in this directory.

An information control block (ICB) is an on-disc structure used to store information about files such as allocation descriptors. The structure of the ICB hierarchy can be quite complex for write-once media which use various strategies of linked lists to preserve multiple historial file versions. Strategy type 4 is normally used on rewritable media where an ICB containing 'direct entries' can be updated as needed.

Every file has a file entry/extended file entry (tag:FE/EFE) udf_descriptor which is in the root of the ICB hierarchy for the file. For normal files the FE/EFE can be thought of as the 'inode' for the file as it contains the location of the on-disc extents of the file. Small amounts of data can be recorded directly in the allocation descriptor area of the FE/EFE ICB if it is deemed useful. This 'INICB' feature is used for directories with strategy type 4.

A file identifier descriptor (tag:FID) udf_descriptor is a 40+ byte structure recorded in a directory file to describe the parent directory and any files or subdirectories. The unnamed parent entry is always recorded first and the parent of the root directory is the root directory, generally referred to as '<root>'. All other files/directories must have a non-zero length name. Along with the name and attributes of the file a FID contains the location of the file FE/EFE 'inode' ICB. While not required, this may be recorded adjacent to the file data on-disc for convenience.

The notation tag:FE/EFE means a udf_descriptor with an ident of either TAG_IDENT_FE or TAG_IDENT_EFE with the on-disc format FE/EFE structure stored in the first udf_data item on the udf_data list of that udf_descriptor. The 16-byte on-disc format tag will be at the beginning of that structure. Additional information such as the FID structure for directory entries will be stored in subsequent entries on the list.

Parameters

  disc | the udf_disc
  ext | the udf_extent containing the udf_descriptor
  desc | the udf_descriptor
  SerialNum | the serial number to assign

Returns
  the tag

Definition at line 83 of file file.c.

int udf_alloc_bitmap_blocks | ( | struct udf_disc * | disc,
|  | struct udf_extent * | pspace,
|  | struct udf_desc * | bitmap,
|  | uint32_t | start,
|  | uint32_t | blocks
| ) |  |

allocate an aligned space bitmap on-disc

Parameters

  disc | the udf disc
  pspace | the type:PSPACE udf_extent for on-disc allocations
  bitmap | the space bitmap tag:USB/FSB udf_descriptor
  start | the starting block number to search for on-disc allocations
  blocks | the number of blocks in the space bitmap

Returns
  the starting block number of the on-disc aligned space bitmap

Definition at line 725 of file file.c.

int udf_alloc_blocks | ( | struct udf_disc * | disc,
|  | struct udf_extent * | pspace,
|  | uint32_t | start,
|  | uint32_t | blocks
| ) |  |

allocate blocks on-disc

Parameters

  disc | the udf_disc
  start | the starting block offset for the allocation search
  blocks | the number of blocks to allocate

Returns
  the starting block number of the on-disc allocation

Definition at line 814 of file file.c.

int udf_alloc_table_blocks | ( | struct udf_disc * | disc,
|  | struct udf_extent * | pspace,
|  | struct udf_desc * | table,
|  | uint32_t | start,
|  | uint32_t | blocks
| ) |  |

allocate a space table on-disc

Parameters

  disc | the udf_disc
  pspace | the type:PSPACE udf_extent for on-disc allocations
  table | the space table tag:USE/FSE udf_descriptor
  start | the starting block offset for the allocation search
  blocks | the number of blocks in the space table

Returns
  the starting block number of the on-disc space table

Definition at line 755 of file file.c.

struct udf_desc* udf_create | ( | struct udf_disc * | disc,
|  | struct udf_extent * | pspace,
|  | uint8_t * | name,
|  | uint8_t | length,
|  | uint32_t | offset,
|  | struct udf_desc * | parent,
|  | uint8_t | filechar,
|  | uint8_t | filetype,
|  | uint16_t | flags
| ) |  |

create a file tag:FE/EFE udf_descriptor and add the file to a directory

Parameters

  disc | the udf_disc
  pspace | the type:PSPACE udf_extent for on-disc allocations
  name | the file name - the first byte is the OSTA unicode compression type
  length | the length of the file name in bytes
  offset | the starting block number to search for on-disc allocations
  parent | the directory tag:FE/EFE udf_descriptor
  filechar | file characteristics
  filetype | the file type
  flags | the file flags

Returns
  the in-memory address of file tag:FE/EFE udf_descriptor

Definition at line 466 of file file.c.

static unsigned long udf_find_next_one_bit | ( | void * | addr,
|  | unsigned long | size,
|  | unsigned long | offset
| ) |  |
| inline static

find the first one bit in a space bitmap

Parameters

  addr | the in-memory address of the space bitmap
  size | the size of the space bitmap in bits
  offset | the starting bit position for the search

Returns
  the 0 based bit position or size

Definition at line 633 of file file.c.

static unsigned long udf_find_next_zero_bit | ( | void * | addr,
|  | unsigned long | size,
|  | unsigned long | offset
| ) |  |
| inline static

find the first zero bit in a space bitmap

Parameters

  addr | the in-memory address of the space bitmap
  size | the size of the space bitmap in bits
  offset | the starting bit position for the search

Returns
  the 0 based bit position or size

Definition at line 677 of file file.c.

struct udf_desc* udf_mkdir | ( | struct udf_disc * | disc,
|  | struct udf_extent * | pspace,
|  | uint8_t * | name,
|  | uint8_t | length,
|  | uint32_t | offset,
|  | struct udf_desc * | parent
| ) |  |

create a directory tag:FE/EFE udf_descriptor and add the directory to a parent directory

Parameters

  disc | the udf_disc
  pspace | the type:PSPACE udf_extent for on-disc allocations
  name | the file name - the first byte is the OSTA unicode compression type
  length | the length of the file name in bytes
  offset | the starting block number to search for on-disc allocations
  parent | the parent directory tag:FE/EFE udf_descriptor

Returns
  the in-memory address of the directory tag:FE/EFE udf_descriptor

Definition at line 587 of file file.c.

tag udf_query_tag | ( | struct udf_disc * | disc,
|  | uint16_t | Ident,
|  | uint16_t | SerialNum,
|  | uint32_t | Location,
|  | struct udf_data * | data,
|  | uint16_t | length
| ) |  |

create an on-disc format tag from udf_descriptor components

Parameters

  disc | the udf_disc
  Ident | the tag:Ident to assign
  SerialNum | the serial number to assign
  Location | the block number of the on-disc tag:Ident udf_descriptor
  data | the udf_data list head
  length | the summed data length

Returns
  the tag

Definition at line 129 of file file.c.