udftools

- Main Page
- Classes
- Files

- File List
- File Members

All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Classes | Macros | Enumerations | Functions | Variables
udffsck.h File Reference
`#include "config.h"`
`#include <ecma_167.h>`
`#include <libudffs.h>`
`#include <stdio.h>`
`#include <errno.h>`
`#include <stdlib.h>`
Include dependency graph for udffsck.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Classes
struct | metadata_t
struct | vds_sequence_t
struct | file_t
struct | filesystemStats
struct | fileInfo
struct | impUseLVID

## Macros
#define | UDFFSCK_VERSION "1.0-beta"
| udffsck version number More...
#define | VDS_STRUCT_AMOUNT 8
| Maximum amount of VDS descriptors. More...
#define | BLOCK_SIZE 2048
| Minimal VRS search block size. More...
#define | E_CHECKSUM 0b00000001
#define | E_CRC 0b00000010
#define | E_POSITION 0b00000100
#define | E_WRONGDESC 0b00001000
#define | E_UUID 0b00010000
#define | E_TIMESTAMP 0b00100000
#define | E_FREESPACE 0b01000000
#define | E_FILES 0b10000000
#define | E_EXTLEN 0b10000000

## Enumerations
enum | avdp_type_e { FIRST_AVDP = 0, SECOND_AVDP, THIRD_AVDP }
enum | vds_type_e { MAIN_VDS = 0, RESERVE_VDS }

## Functions
struct impUseLVID | __attribute__ ((packed))
char * | print_timestamp (timestamp ts)
| Timestamp printing function. More...
uint64_t | count_used_bits (struct filesystemStats *stats)
| Counts used bits (blocks) at stats->actParitionBitmap. More...
int | get_volume_identifier (struct udf_disc *disc, struct filesystemStats *stats, vds_sequence_t *seq)
| Select various volume identifiers and store them at stats structure. More...
int | is_udf (uint8_t *dev, int *sectorsize, int force_sectorsize)
| UDF VRS detection function. More...
int | get_avdp (uint8_t *dev, struct udf_disc *disc, int *sectorsize, size_t devsize, avdp_type_e type, int force_sectorsize, struct filesystemStats *stats)
| Locate AVDP on device and store it. More...
int | write_avdp (uint8_t *dev, struct udf_disc *disc, size_t sectorsize, size_t devsize, avdp_type_e source, avdp_type_e target)
| Writes back specified AVDP from udf_disc structure to device. More...
int | fix_avdp (uint8_t *dev, struct udf_disc *disc, size_t sectorsize, size_t devsize, avdp_type_e target)
| Fix target AVDP's extent length. More...
int | get_vds (uint8_t *dev, struct udf_disc *disc, int sectorsize, avdp_type_e avdp, vds_type_e vds, vds_sequence_t *seq)
| Loads Volume Descriptor Sequence (VDS) and stores it at struct udf_disc. More...
int | verify_vds (struct udf_disc *disc, vds_type_e vds, vds_sequence_t *seq)
| VDS verification structure. More...
int | fix_vds (uint8_t *dev, struct udf_disc *disc, size_t sectorsize, avdp_type_e source, vds_sequence_t *seq)
| Fix VDS sequence. More...
int | get_lvid (uint8_t *dev, struct udf_disc *disc, int sectorsize, struct filesystemStats *stats, vds_sequence_t *seq)
| Loads Logical Volume Integrity Descriptor (LVID) and stores it at struct udf_disc. More...
int | fix_lvid (uint8_t *dev, struct udf_disc *disc, size_t sectorsize, struct filesystemStats *stats, vds_sequence_t *seq)
| Fix LVID values. More...
int | get_pd (uint8_t *dev, struct udf_disc *disc, size_t sectorsize, struct filesystemStats *stats, vds_sequence_t *seq)
| Get PD Partition Header contents. More...
int | fix_pd (uint8_t *dev, struct udf_disc *disc, size_t sectorsize, struct filesystemStats *stats, vds_sequence_t *seq)
| Fix PD Partition Header contents. More...
uint8_t | get_fsd (uint8_t *dev, struct udf_disc *disc, int sectorsize, uint32_t *lbnlsn, struct filesystemStats *stats, vds_sequence_t *seq)
| Loads File Set Descriptor and stores it at struct udf_disc. More...
uint8_t | get_file_structure (const uint8_t *dev, const struct udf_disc *disc, uint32_t lbnlsn, struct filesystemStats *stats, vds_sequence_t *seq)
| File tree entry point. More...

## Variables
regid | impID
uint32_t | numOfFiles
uint32_t | numOfDirs
uint16_t | minUDFReadRev
uint16_t | minUDFWriteRev
uint16_t | maxUDFWriteRev
uint8_t | impUse [0]

## Macro Definition Documentation

#define BLOCK_SIZE 2048

Minimal VRS search block size.

Definition at line 37 of file udffsck.h.

#define E_CHECKSUM 0b00000001

Definition at line 118 of file udffsck.h.

#define E_CRC 0b00000010

Definition at line 119 of file udffsck.h.

#define E_EXTLEN 0b10000000

Definition at line 126 of file udffsck.h.

#define E_FILES 0b10000000

Definition at line 125 of file udffsck.h.

#define E_FREESPACE 0b01000000

Definition at line 124 of file udffsck.h.

#define E_POSITION 0b00000100

Definition at line 120 of file udffsck.h.

#define E_TIMESTAMP 0b00100000

Definition at line 123 of file udffsck.h.

#define E_UUID 0b00010000

Definition at line 122 of file udffsck.h.

#define E_WRONGDESC 0b00001000

Definition at line 121 of file udffsck.h.

#define UDFFSCK_VERSION "1.0-beta"

udffsck version number

Definition at line 34 of file udffsck.h.

#define VDS_STRUCT_AMOUNT 8

Maximum amount of VDS descriptors.

Definition at line 36 of file udffsck.h.

## Enumeration Type Documentation

enum avdp_type_e

Enumerator
FIRST_AVDP |
SECOND_AVDP |
THIRD_AVDP |

Definition at line 39 of file udffsck.h.

enum vds_type_e

Enumerator
MAIN_VDS |
RESERVE_VDS |

Definition at line 45 of file udffsck.h.

## Function Documentation

struct impUseLVID __attribute__ | ( | (packed) |  | ) |

uint64_t count_used_bits | ( | struct filesystemStats * | stats | ) |

Counts used bits (blocks) at stats->actParitionBitmap.

Support function for getting free space from actual bitmap.

Parameters

  [in] | *stats | file system stats structure with filled bitmap

Returns
  used blocks amount

Definition at line 431 of file udffsck.c.

int fix_avdp | ( | uint8_t * | dev,
|  | struct udf_disc * | disc,
|  | size_t | sectorsize,
|  | size_t | devsize,
|  | avdp_type_e | target
| ) |  |

Fix target AVDP's extent length.

Parameters

  [in,out] | *dev | memory mapped device
  [in,out] | *disc | UDF disc structure
  [in] | sectorsize |
  [in] | devsize | size of device in bytes
  [in] | target | target AVDP

Returns
  0 everything OK
  -2 checksum failed
  -4 CRC failed

Definition at line 2271 of file udffsck.c.

int fix_lvid | ( | uint8_t * | dev,
|  | struct udf_disc * | disc,
|  | size_t | sectorsize,
|  | struct filesystemStats * | stats,
|  | vds_sequence_t * | seq
| ) |  |

Fix LVID values.

This function fixes only values of LVID. It is not able to fix structurally broken LVID (wrong CRC/checksum).

Fixes opened intergrity type, timestamps, amounts of files/directories, free space tables.

Parameters

  [in,out] | *dev | memory mapped device
  [in,out] | *disc | UDF disc
  [in] | sectorsize |
  [in] | *stats | filesystem status
  [in] | *seq | VDS sequence

Returns
  0 – All Ok
  4 – No correct LVD found

Definition at line 2633 of file udffsck.c.

int fix_pd | ( | uint8_t * | dev,
|  | struct udf_disc * | disc,
|  | size_t | sectorsize,
|  | struct filesystemStats * | stats,
|  | vds_sequence_t * | seq
| ) |  |

Fix PD Partition Header contents.

At this moment it fixes only SBD, because no other descriptors were found.

Parameters

  [in,out] | *dev | memory mapped medium
  [in] | *disc | UDF disc
  [in] | sectorsize |
  [in,out] | *stats | file system status
  [in] | *seq | VDS sequence

Returns
  0 – All OK
  1 – PD SBD recovery failed
  4 – No correct PD found
  -1 – no SBD found even if declared

Definition at line 2455 of file udffsck.c.

int fix_vds | ( | uint8_t * | dev,
|  | struct udf_disc * | disc,
|  | size_t | sectorsize,
|  | avdp_type_e | source,
|  | vds_sequence_t * | seq
| ) |  |

Fix VDS sequence.

This function go thru VDS and if find error, check second VDS. If secondary is ok, copy it, if not, report unrecoverable error.

Parameters

  [in,out] | *dev | memory mapped medium
  [in,out] | *disc | UDF disc structure
  [in] | sectorsize |
  [in] | source | AVDP pointing to VDS
  [in,out] | *seq | VDS sequence

Returns
  sum of 0, 1 and 4 according fixing and found errors

Definition at line 2362 of file udffsck.c.

int get_avdp | ( | uint8_t * | dev,
|  | struct udf_disc * | disc,
|  | int * | sectorsize,
|  | size_t | devsize,
|  | avdp_type_e | type,
|  | int | force_sectorsize,
|  | struct filesystemStats * | stats
| ) |  |

Locate AVDP on device and store it.

This function searches AVDP at its positions. If it finds it, store it to udf_disc structure to required position by type parameter.

It also determine sector size, since AVDP have fixed position.

Parameters

  [in] | *dev | pointer to device array
  [out] | *disc | AVDP is stored in udf_disc structure
  [in,out] | *sectorsize | device logical sector size
  [in] | devsize | size of whole device in LSN
  [in] | type | selector of AVDP - first or second
  [in] | *stats | statistics of file system

Returns
  0 everything is ok
  sum of E_CRC, E_CHECKSUM, E_WRONGDESC, E_POSITION, E_EXTLEN

Definition at line 469 of file udffsck.c.

uint8_t get_file_structure | ( | const uint8_t * | dev,
|  | const struct udf_disc * | disc,
|  | uint32_t | lbnlsn,
|  | struct filesystemStats * | stats,
|  | vds_sequence_t * | seq
| ) |  |

File tree entry point.

This function is entry for file tree parsing. It actually parses two trees, Stream file tree based on Stream Directory ICB and normal File tree based on Root Directory ICB.

Parameters

  [in,out] | *dev | memory mapped device
  [in] | *disc | udf disc structure
  [in] | lbnlsn | LBN offset from LSN [in,out] *stats file system status
  [in] | *seq | VDS sequence

Returns
  sum of returns from stream and normal get_file()

Definition at line 1953 of file udffsck.c.

uint8_t get_fsd | ( | uint8_t * | dev,
|  | struct udf_disc * | disc,
|  | int | sectorsize,
|  | uint32_t * | lbnlsn,
|  | struct filesystemStats * | stats,
|  | vds_sequence_t * | seq
| ) |  |

Loads File Set Descriptor and stores it at struct udf_disc.

Parameters

  [in] | *dev | pointer to device array
  [out] | *disc | FSD is stored in udf_disc structure
  [in] | sectorsize | device logical sector size
  [out] | lbnlsn | LBN starting offset
  [in] | *stats | file system status
  [in] | *seq | VDS sequence

Returns
  0 everything ok
  4 no correct PD or LVD found

Definition at line 923 of file udffsck.c.

int get_lvid | ( | uint8_t * | dev,
|  | struct udf_disc * | disc,
|  | int | sectorsize,
|  | struct filesystemStats * | stats,
|  | vds_sequence_t * | seq
| ) |  |

Loads Logical Volume Integrity Descriptor (LVID) and stores it at struct udf_disc.

Loads LVID descriptor to disc stucture. Beside that, it stores selected params in stats structure for easier access.

Parameters

  [in] | *dev | pointer to device array
  [out] | *disc | LVID is stored in udf_disc structure
  [in] | sectorsize | device logical sector size
  [out] | *stats | file system status
  [in] | *seq | descriptor sequence

Returns
  0 everything ok
  4 structure is already set or no correct LVID found

Definition at line 734 of file udffsck.c.

int get_pd | ( | uint8_t * | dev,
|  | struct udf_disc * | disc,
|  | size_t | sectorsize,
|  | struct filesystemStats * | stats,
|  | vds_sequence_t * | seq
| ) |  |

Get PD Partition Header contents.

At this moment handles only SBD, because none other was found.

Parameters

  [in] | *dev | memory mapped device
  [in] | *disc | UDF disc
  [in] | sectorsize |
  [out] | *stats | filesystem status
  [in] | *seq | VDS sequence

Returns
  0 – All OK
  4 –No correct PD found
  -1 – SBD not found even if declared
  -128 – UST, FST or FSB found

Definition at line 2520 of file udffsck.c.

int get_vds | ( | uint8_t * | dev,
|  | struct udf_disc * | disc,
|  | int | sectorsize,
|  | avdp_type_e | avdp,
|  | vds_type_e | vds,
|  | vds_sequence_t * | seq
| ) |  |

Loads Volume Descriptor Sequence (VDS) and stores it at struct udf_disc.

Parameters

  [in] | *dev | pointer to device array
  [out] | *disc | VDS is stored in udf_disc structure
  [in] | sectorsize | device logical sector size
  [in] | vds | MAIN_VDS or RESERVE_VDS selector
  [out] | *seq | structure capturing actual order of descriptors in VDS for recovery

Returns
  0 everything ok -3 found unknown tag -4 descriptor is already set

Definition at line 576 of file udffsck.c.

int get_volume_identifier | ( | struct udf_disc * | disc,
|  | struct filesystemStats * | stats,
|  | vds_sequence_t * | seq
| ) |  |

Select various volume identifiers and store them at stats structure.

At this moment it selects PVD->volSetIdent and FSD->logicalVolIdent

Parameters

  [in] | *disc | disc structure
  [out] | *stats | file system status structure
  [in] | *seq | VDS sequence

Returns
  0 – everything OK
  4 – no correct PVD found.

Definition at line 818 of file udffsck.c.

int is_udf | ( | uint8_t * | dev,
|  | int * | sectorsize,
|  | int | force_sectorsize
| ) |  |

UDF VRS detection function.

This function is trying to find VRS at sector 16. It also do first attempt to guess sectorsize.

Parameters

  [in] | *dev | memory mapped device array
  [in,out] | *sectorsize | found sectorsize candidate
  [in] | force_sectorsize | if -B param is used, this flag should be set and sectorsize should be used automatically.

Returns
  0 – UDF succesfully detected, sectorsize candidate found
  -1 – found BOOT2 or CDW02. Unsupported for now
  1 – UDF not detected

Definition at line 347 of file udffsck.c.

char* print_timestamp | ( | timestamp | ts | ) |

Timestamp printing function.

This function prints timestamp to static char array in human readable form

Used format is YYYY-MM-DD hh:mm:ss.cshmms+hh:mm
cs – centiseconds
hm – hundreds of microseconds
ms – microseconds

Parameters

  [in] | ts | UDF timestamp

Returns
  pointer to char static char array

Warning
  char array is NOT NULL terminated

Definition at line 170 of file udffsck.c.

int verify_vds | ( | struct udf_disc * | disc,
|  | vds_type_e | vds,
|  | vds_sequence_t * | seq
| ) |  |

VDS verification structure.

This function go thru all VDS descriptors and checks them for checksum, CRC and position. Result are stored using append_error() function.

Parameters

  [in] | *disc | UDF disc structure
  [in] | vds | VDS to search
  [in,out] | *seq | VDS sequence for error storing

Returns
  0

Definition at line 2066 of file udffsck.c.

int write_avdp | ( | uint8_t * | dev,
|  | struct udf_disc * | disc,
|  | size_t | sectorsize,
|  | size_t | devsize,
|  | avdp_type_e | source,
|  | avdp_type_e | target
| ) |  |

Writes back specified AVDP from udf_disc structure to device.

Parameters

  [in,out] | *dev | memory mapped device
  [in,out] | *disc | UDF disc structure
  [in] | sectorsize |
  [in] | devsize | size of device in bytes
  [in] | source | source AVDP
  [in] | target | target AVDP

Returns
  0 everything OK
  -2 after write checksum failed
  -4 after write CRC failed

Definition at line 2200 of file udffsck.c.

## Variable Documentation

regid impID

Definition at line 2634 of file udffsck.h.

uint8_t impUse[0]

Definition at line 2640 of file udffsck.h.

uint16_t maxUDFWriteRev

Definition at line 2639 of file udffsck.h.

uint16_t minUDFReadRev

Definition at line 2637 of file udffsck.h.

uint16_t minUDFWriteRev

Definition at line 2638 of file udffsck.h.

uint32_t numOfDirs

Definition at line 2636 of file udffsck.h.

uint32_t numOfFiles

Definition at line 2635 of file udffsck.h.