udftools

- Main Page
- Classes
- Files

- File List
- File Members

All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Macros | Functions | Variables
udffsck.c File Reference
`#include "config.h"`
`#include <math.h>`
`#include <time.h>`
`#include <limits.h>`
`#include "udffsck.h"`
`#include "utils.h"`
`#include "libudffs.h"`
`#include "options.h"`
Include dependency graph for udffsck.c:

Go to the source code of this file.

## Macros
#define | MARK_BLOCK 1
| Mark switch for markUsedBlock() function. More...
#define | UNMARK_BLOCK 0
| Unmark switch for markUsedBlock() function. More...
#define | MAX_DEPTH 100
| Maximal printed filetree depth is MAX_DEPTH/4. Required by function depth2str(). More...
#define | B2(n) n, n+1, n+1, n+2
#define | B4(n) B2(n), B2(n+1), B2(n+1), B2(n+2)
#define | B6(n) B4(n), B4(n+1), B4(n+1), B4(n+2)

## Functions
uint8_t | get_file (const uint8_t *dev, const struct udf_disc *disc, uint32_t lbnlsn, uint32_t lsn, struct filesystemStats *stats, uint32_t depth, uint32_t uuid, struct fileInfo info, vds_sequence_t *seq)
| (E)FE parsing function More...
void | increment_used_space (struct filesystemStats *stats, uint64_t increment, uint32_t position)
| Pair function capturing used space and its position. More...
uint8_t | inspect_fid (const uint8_t *dev, const struct udf_disc *disc, uint32_t lbnlsn, uint32_t lsn, uint8_t *base, uint32_t *pos, struct filesystemStats *stats, uint32_t depth, vds_sequence_t *seq, uint8_t *status)
| FID parsing function. More...
void | print_file_chunks (struct filesystemStats *stats)
int | copy_descriptor (uint8_t *dev, struct udf_disc *disc, size_t sectorsize, uint32_t sourcePosition, uint32_t destinationPosition, size_t size)
| Copy descriptor from one position to another on medium. More...
char * | depth2str (uint32_t depth)
| File tree prefix creator. More...
uint8_t | calculate_checksum (tag descTag)
| Checksum calculation function for tags. More...
int | checksum (tag descTag)
| Wrapper function for checksum. More...
uint16_t | calculate_crc (void *restrict desc, uint16_t size)
| CRC calcultaion wrapper for udf_crc() function from libudffs. More...
int | crc (void *restrict desc, uint16_t size)
| Wrapper function for CRC calculation. More...
int | check_position (tag descTag, uint32_t position)
| Position check function. More...
char * | print_timestamp (timestamp ts)
| Timestamp printing function. More...
time_t | timestamp2epoch (timestamp t)
| UDF timestamp to Unix timestamp conversion function. More...
double | compare_timestamps (timestamp a, timestamp b)
| UDF Timestamp comparison wrapper. More...
void | print_file_info (struct fileInfo info, uint32_t depth)
| File information printing function. More...
int | is_udf (uint8_t *dev, int *sectorsize, int force_sectorsize)
| UDF VRS detection function. More...
uint64_t | count_used_bits (struct filesystemStats *stats)
| Counts used bits (blocks) at stats->actParitionBitmap. 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 | 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 | get_correct (vds_sequence_t *seq, uint16_t tagIdent)
| Selects MAIN_VDS or RESERVE_VDS for required descriptor based on errors. 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 | 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...
uint8_t | markUsedBlock (struct filesystemStats *stats, uint32_t lbn, uint32_t size, uint8_t mark)
| Marks used blocks in actual bitmap. 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 | inspect_aed (const uint8_t *dev, uint32_t lsnBase, uint32_t aedlbn, uint32_t *lengthADArray, uint8_t **ADArray, struct filesystemStats *stats, uint8_t *status)
| Inspect AED and return array of its allocation descriptors. More...
uint8_t | translate_fid (const uint8_t *dev, const struct udf_disc *disc, uint32_t lbnlsn, uint32_t lsn, uint8_t *allocDescs, uint32_t lengthAllocDescs, uint16_t icb_ad, struct filesystemStats *stats, uint32_t depth, vds_sequence_t *seq, uint8_t *status)
| FID allocation descriptor position translation function. More...
void | decrement_used_space (struct filesystemStats *stats, uint64_t increment, uint32_t position)
| Pair function capturing used space and its position. 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...
int | append_error (vds_sequence_t *seq, uint16_t tagIdent, vds_type_e vds, uint8_t error)
| Support function for appending error to seq structure. More...
uint32_t | get_tag_location (vds_sequence_t *seq, uint16_t tagIdent, vds_type_e vds)
| Support function for getting tag location from seq structure. More...
int | verify_vds (struct udf_disc *disc, vds_type_e vds, vds_sequence_t *seq)
| VDS verification structure. 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...
char * | descriptor_name (uint16_t descIdent)
| Get descriptor name string. 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 | 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...
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_lvid (uint8_t *dev, struct udf_disc *disc, size_t sectorsize, struct filesystemStats *stats, vds_sequence_t *seq)
| Fix LVID values. More...

## Variables
static const unsigned char | BitsSetTable256 [256]
| Support array for bit counting. More...

## Macro Definition Documentation

#define B2 | ( |  | n | ) | n, n+1, n+1, n+2

#define B4 | ( |  | n | ) | B2(n), B2(n+1), B2(n+1), B2(n+2)

#define B6 | ( |  | n | ) | B4(n), B4(n+1), B4(n+1), B4(n+2)

#define MARK_BLOCK 1

Mark switch for markUsedBlock() function.

Definition at line 42 of file udffsck.c.

#define MAX_DEPTH 100

Maximal printed filetree depth is MAX_DEPTH/4. Required by function depth2str().

Definition at line 45 of file udffsck.c.

#define UNMARK_BLOCK 0

Unmark switch for markUsedBlock() function.

Definition at line 43 of file udffsck.c.

## Function Documentation

int append_error | ( | vds_sequence_t * | seq,
|  | uint16_t | tagIdent,
|  | vds_type_e | vds,
|  | uint8_t | error
| ) |  |

Support function for appending error to seq structure.

Parameters

  [in,out] | seq | VDS sequence
  [in] | tagIdent | identifer of descriptor to append
  [in] | vds | VDS to search
  [in] | error | to append

Returns
  0 everything OK
  -1 required descriptor not found

Definition at line 2014 of file udffsck.c.

uint8_t calculate_checksum | ( | tag | descTag | ) |

Checksum calculation function for tags.

This function is tailored for checksum calculation for UDF tags. It skips 5th byte, because there is result stored.

Parameters

  [in] | descTag | target for checksum calculation

Returns
  checksum result

Definition at line 82 of file udffsck.c.

uint16_t calculate_crc | ( | void *restrict | desc,
|  | uint16_t | size
| ) |  |

CRC calcultaion wrapper for udf_crc() function from libudffs.

Parameters

  [in] | desc | descriptor for calculation
  [in] | size | size for calculation

Returns
  CRC result

Definition at line 114 of file udffsck.c.

int check_position | ( | tag | descTag,
|  | uint32_t | position
| ) |  |

Position check function.

Checks declared position from tag against inserted position

Parameters

  [in] | descTag | tag with declared position
  [in] | position | actual position to compare

Returns
  result of position comparsion, 0 if match, 1 if differs

Definition at line 150 of file udffsck.c.

int checksum | ( | tag | descTag | ) |

Wrapper function for checksum.

Parameters

  [in] | descTag | target for checksum calculation

Returns
  result of checksum comparison, 1 if match, 0 if differs

Warning
  This function have oposite results than crc() and check_position()

Definition at line 101 of file udffsck.c.

double compare_timestamps | ( | timestamp | a,
|  | timestamp | b
| ) |  |

UDF Timestamp comparison wrapper.

Timestamps are converted to Unix timestamps and compared with difftime()

Parameters

  [in] | a | first timestamp
  [in] | b | second timestamp

Returns
  result of difftime(). Basically result a-b.

Definition at line 229 of file udffsck.c.

int copy_descriptor | ( | uint8_t * | dev,
|  | struct udf_disc * | disc,
|  | size_t | sectorsize,
|  | uint32_t | sourcePosition,
|  | uint32_t | destinationPosition,
|  | size_t | size
| ) |  |

Copy descriptor from one position to another on medium.

Beside actual copy it also fixes declared position, CRC and checksum.

Parameters

  [in,out] | *dev | memory mapped device
  [in,out] | *disc | UDF disc structure
  [in] | sectorsize |
  [in] | sourcePosition | in blocks
  [in] | destinationPosition | in blocks
  [in] | size | size of descriptor to copy

return 0

Definition at line 2162 of file udffsck.c.

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 crc | ( | void *restrict | desc,
|  | uint16_t | size
| ) |  |

Wrapper function for CRC calculation.

Parameters

  [in] | desc | descriptor for calculation
  [in] | size | size for calculation

Returns
  result of checksum comparsion, 0 if match, 1 if differs

Definition at line 134 of file udffsck.c.

void decrement_used_space | ( | struct filesystemStats * | stats,
|  | uint64_t | increment,
|  | uint32_t | position
| ) |  |

Pair function capturing used space and its position.

This function is pair with increment_used_space()

It only stores information about used:free space ration and positions

Parameters

  [in,out] | *stats | file system status contatins fields used for free space counting and bitmaps for position marking
  [in] | increment | size of space to mark
  [in] | its | position

Definition at line 1523 of file udffsck.c.

char* depth2str | ( | uint32_t | depth | ) |

File tree prefix creator.

This fuction takes depth and based on that prints lines and splits

Parameters

  [in] | depth | required depth to print

Returns
  NULL terminated static char array with printed depth

Definition at line 55 of file udffsck.c.

char* descriptor_name | ( | uint16_t | descIdent | ) |

Get descriptor name string.

Parameters

  [in] | descIdent | descriptor identifier

Returns
  constant char array

Definition at line 2326 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.

int get_correct | ( | vds_sequence_t * | seq,
|  | uint16_t | tagIdent
| ) |  |

Selects MAIN_VDS or RESERVE_VDS for required descriptor based on errors.

If some function needs some descriptor from VDS, it requires check if descriptor is structurally correct. This is already checked and stored in seq->main[vds].error and seq->reserve[vds].error. This function search thru this sequence based on tagIdent and looks at errors when found.

Parameters

  [in] | *seq | descriptor sequence
  [in] | tagIdent | identifier to find

Returns
  MAIN_VDS or RESERVE_VDS if correct descriptor found
  -1 if no correct descriptor found or both are broken.

Definition at line 709 of file udffsck.c.

uint8_t get_file | ( | const uint8_t * | dev,
|  | const struct udf_disc * | disc,
|  | uint32_t | lbnlsn,
|  | uint32_t | lsn,
|  | struct filesystemStats * | stats,
|  | uint32_t | depth,
|  | uint32_t | uuid,
|  | struct fileInfo | info,
|  | vds_sequence_t * | seq
| ) |  |

(E)FE parsing function

This function parses thru file tree, made of FE. It is complement to inspect_fid() function, which parses FIDs.

It fixes Unifinished writes, File modifiacation timestamps (or records them for LVID fix, depending on error) and Unique ID.

When it finds directory, it calls inspect_fid() to process its contents.

Parameters

  [in,out] | *dev | memory mapped device
  [in] | *disc | udf_disc structure
  [in] | lbnlsn | LBN offset against LSN
  [in] | lsn | actual LSN
  [in,out] | *stats | file system status
  [in] | depth | depth of FE for printing
  [in] | uuid | Unique ID from parent FID
  [in] | info | file information structure for easier handling for print
  [in] | *seq | VDS sequence

Returns
  4 – No correct LVD found
  4 – Checksum failed
  4 – CRC failed
  32 – removed unfinished file
  sum of status returned from inspect_fid(), translate_fid() or own actions (4 for unfixed error, 1 for fixed error, 0 for no error)

Definition at line 1557 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.

uint32_t get_tag_location | ( | vds_sequence_t * | seq,
|  | uint16_t | tagIdent,
|  | vds_type_e | vds
| ) |  |

Support function for getting tag location from seq structure.

Parameters

  [in,out] | *seq | VDS sequence
  [in] | tagIdent | identifier of descriptor to find
  [in] | vds | VDS to search

Returns
  requested location if found or UINT32_MAX if not

Definition at line 2040 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.

void increment_used_space | ( | struct filesystemStats * | stats,
|  | uint64_t | increment,
|  | uint32_t | position
| ) |  |

Pair function capturing used space and its position.

This function is pair with decrement_used_space()

It only stores information about used:free space ration and positions

Parameters

  [in,out] | *stats | file system status contatins fields used for free space counting and bitmaps for position marking
  [in] | increment | size of space to mark
  [in] | its | position

Definition at line 1503 of file udffsck.c.

uint8_t inspect_aed | ( | const uint8_t * | dev,
|  | uint32_t | lsnBase,
|  | uint32_t | aedlbn,
|  | uint32_t * | lengthADArray,
|  | uint8_t ** | ADArray,
|  | struct filesystemStats * | stats,
|  | uint8_t * | status
| ) |  |

Inspect AED and return array of its allocation descriptors.

This function returns pointer to array of allocation descriptors. This pointer points to memory mapped device!

Parameters

  [in] | *dev | memory mapped device
  [in] | lsnBase | LBN offset to LSN
  [in] | aedlbn | LBN of AED
  [out] | *lengthADArray | size of allocation descriptor array ADArray
  [out] | **ADAarray | allocation descriptors array itself
  [in] | *stats | file system status
  [out] | status | error status

Returns
  0 – AED found and ADArray is set
  4 – AED not found
  4 – checksum failed
  4 – CRC failed

Definition at line 991 of file udffsck.c.

uint8_t inspect_fid | ( | const uint8_t * | dev,
|  | const struct udf_disc * | disc,
|  | uint32_t | lbnlsn,
|  | uint32_t | lsn,
|  | uint8_t * | base,
|  | uint32_t * | pos,
|  | struct filesystemStats * | stats,
|  | uint32_t | depth,
|  | vds_sequence_t * | seq,
|  | uint8_t * | status
| ) |  |

FID parsing function.

This function pareses via FIDs. It continues to its FE using get_file() function. Checks and fixes Unique ID, Serial Numbers or unfinished writings.

This fucntion is complement to get_file() and translate_fid().

Parameters

  [in,out] | *dev | memory mapped device
  [in] | *disc | udf_disc structure
  [in] | lbnlsn | LBN offset against LSN
  [in] | lsn | actual LSN
  [in] | *base | base pointer for for FID area
  [in,out] | *pos | actial position in FID area
  [in] | *stats | file system status
  [in] | depth | depth of FE for printing
  [in] | *seq | VDS sequence
  [out] | *status | run status

Returns
  0 – everything OK
  1 – Unknown descriptor found
  252 – FID checksum failed
  251 – FID CRC failed

Definition at line 1315 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.

uint8_t markUsedBlock | ( | struct filesystemStats * | stats,
|  | uint32_t | lbn,
|  | uint32_t | size,
|  | uint8_t | mark
| ) |  |

Marks used blocks in actual bitmap.

This function mark or unmark specified areas of block bitmap at stats->actPartitionBitmap If medium is consistent, this bitmap should be same as declared (stats->expPartitionBitmap)

Parameters

  [in,out] | *stats | file system status structure
  [in] | lbn | starting logical block of area
  [in] | size | length of marked area
  [in] | MARK_BLOCK | or UNMARK_BLOCK switch

Returns
  0 everything is OK or size is 0 (nothing to mark)
  -1 marking failed (actParititonBitmap is uninitialized)

Definition at line 843 of file udffsck.c.

void print_file_chunks | ( | struct filesystemStats * | stats | ) |

void print_file_info | ( | struct fileInfo | info,
|  | uint32_t | depth
| ) |  |

File information printing function.

This function wraps file charactersitics, file type, permissions, modification time, size and record name and prints it in human readable form.

Format is this: HdDPM:darwxd:arwxd:arwx <FILETYPE> <TIMESTAMP> <SIZE> "<NAME>"

- H – Hidden
- d – Directory
- D – Deleted
- P – Parent
- M – Metadata
- d – right to delete
- r – right to read
- w – right to write
- x – right to execute
- a – right to change attributes
- . – bit not set

Parameters

  [in] | info | file information to print
  [in] | depth | parameter for prefix, required by depth2str().

Definition at line 256 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.

time_t timestamp2epoch | ( | timestamp | t | ) |

UDF timestamp to Unix timestamp conversion function.

This function fills Unix timestamp structure with its values, add time offset from UDF timestamp to it and create timestamp.

Warning
  Because Unix timestamp have second as minimal unit of time, there is precission loss since UDF operates up to microseconds

Parameters

  [in] | t | UDF timestamp

Returns
  time_t Unix timestamp structure

Definition at line 196 of file udffsck.c.

uint8_t translate_fid | ( | const uint8_t * | dev,
|  | const struct udf_disc * | disc,
|  | uint32_t | lbnlsn,
|  | uint32_t | lsn,
|  | uint8_t * | allocDescs,
|  | uint32_t | lengthAllocDescs,
|  | uint16_t | icb_ad,
|  | struct filesystemStats * | stats,
|  | uint32_t | depth,
|  | vds_sequence_t * | seq,
|  | uint8_t * | status
| ) |  |

FID allocation descriptor position translation function.

FID's allocation descriptors are stored at Allocation Descriptors area of FE. Problem is, this area is not necessarily in one piece and can be splitted, even in middle of descriptor. This function creates virtual linear area for futher processing.

This function internally calls inspect_fid().

Parameters

  [in] | *dev | memory mapped device
  [in] | *disc | udf_disc structure
  [in] | lbnlsn | LBN offset against LSN
  [in] | lsn | actual LSN
  [in] | *allocDescs | pointer to allocation descriptors area
  [in] | lengthAllocDescs | length of allocation descriptors area
  [in] | icb_ad | type od AD
  [in] | *stats | file system status
  [in] | depth | depth of FE for printing
  [in] | *seq | VDS sequence
  [out] | *status | run status

Returns
  0 – everything OK
  1 – Unsupported AD
  2 – FID array allocation failed
  255 – inspect_aed() failed

Definition at line 1074 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

const unsigned char BitsSetTable256[256]
| static

Initial value:
=
{
#define B2(n)
#define B4(n)
#define B6(n)
B6(0), B6(1), B6(1), B6(2)
}
B6
#define B6(n)

Support array for bit counting.

Definition at line 2431 of file udffsck.c.