udftools

- Main Page
- Classes
- Files

- File List
- File Members

All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
udffsck.h
Go to the documentation of this file.
1 /*
2 * udffsck.h
3 *
4 * Copyright (c) 2016 Vojtech Vladyka <vojtch.vladyka@gmail.com>
5 * All rights reserved.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 *
21 */
22 #ifndef __UDFFSCK_H__
23 #define __UDFFSCK_H__
24
25 #include "config.h"
26
27 #include <ecma_167.h>
28 #include <libudffs.h>
29
30 #include <stdio.h>
31 #include <errno.h>
32 #include <stdlib.h>
33
34 #define UDFFSCK_VERSION "1.0-beta"
35
36 #define VDS_STRUCT_AMOUNT 8
37 #define BLOCK_SIZE 2048
38
39 typedef enum {
40 FIRST_AVDP = 0,
41 SECOND_AVDP,
42 THIRD_AVDP,
43 } avdp_type_e;
44
45 typedef enum {
46 MAIN_VDS = 0,
47 RESERVE_VDS,
48 } vds_type_e;
49
50 typedef struct {
51 uint16_t tagIdent;
52 uint32_t tagLocation;
53 uint8_t error;
54 } metadata_t;
55
56 typedef struct {
57 metadata_t anchor[3];
58 metadata_t main[VDS_STRUCT_AMOUNT];
59 metadata_t reserve[VDS_STRUCT_AMOUNT];
60 metadata_t lvid;
61 metadata_t pd;
62 } vds_sequence_t;
63
64 typedef struct {
65 uint16_t flags;
66 uint32_t lsn;
67 uint32_t blocks;
68 uint32_t size;
69 } file_t;
70
71 struct filesystemStats {
72 uint16_t blocksize;
73 uint64_t actUUID;
74 uint64_t maxUUID;
75 uint32_t expNumOfFiles;
76 uint32_t countNumOfFiles;
77 uint32_t expNumOfDirs;
78 uint32_t countNumOfDirs;
79 uint16_t minUDFReadRev;
80 uint16_t minUDFWriteRev;
81 uint16_t maxUDFWriteRev;
82 uint16_t AVDPSerialNum;
83 uint64_t usedSpace;
84 uint32_t freeSpaceBlocks;
85 uint32_t partitionSizeBlocks;
86 uint32_t expUsedBlocks;
87 uint32_t expUnusedBlocks;
88 uint32_t partitionNumOfBytes;
89 uint32_t partitionNumOfBits;
90 uint8_t * actPartitionBitmap;
91 uint8_t * expPartitionBitmap;
92 timestamp LVIDtimestamp;
93 dstring * partitionIdent;
94 dstring * volumeSetIdent;
95 };
96
97 struct fileInfo {
98 char * filename;
99 uint8_t fileCharacteristics;
100 uint8_t fileType;
101 uint32_t permissions;
102 uint64_t size;
103 uint16_t FIDSerialNum;
104 timestamp modTime;
105 };
106
107 // Implementation Use for Logical Volume Integrity Descriptor (ECMA 167r3 3/10.10, UDF 2.2.6.4)
108 struct impUseLVID {
109 regid impID;
110 uint32_t numOfFiles;
111 uint32_t numOfDirs;
112 uint16_t minUDFReadRev;
113 uint16_t minUDFWriteRev;
114 uint16_t maxUDFWriteRev;
115 uint8_t impUse[0];
116 } __attribute__ ((packed));
117
118 #define E_CHECKSUM 0b00000001
119 #define E_CRC 0b00000010
120 #define E_POSITION 0b00000100
121 #define E_WRONGDESC 0b00001000
122 #define E_UUID 0b00010000
123 #define E_TIMESTAMP 0b00100000
124 #define E_FREESPACE 0b01000000
125 #define E_FILES 0b10000000
126 #define E_EXTLEN 0b10000000 //AVDP specific
127
128 // Support functions
129 char * print_timestamp(timestamp ts);
130 uint64_t count_used_bits(struct filesystemStats *stats);
131 int get_volume_identifier(struct udf_disc *disc, struct filesystemStats *stats, vds_sequence_t *seq );
132
133 // UDF detection
134 int is_udf(uint8_t *dev, int *sectorsize, int force_sectorsize);
135 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);
136 int write_avdp(uint8_t *dev, struct udf_disc *disc, size_t sectorsize, size_t devsize, avdp_type_e source, avdp_type_e target);
137 int fix_avdp(uint8_t *dev, struct udf_disc *disc, size_t sectorsize, size_t devsize, avdp_type_e target);
138
139 // VDS functions
140 int get_vds(uint8_t *dev, struct udf_disc *disc, int sectorsize, avdp_type_e avdp, vds_type_e vds, vds_sequence_t *seq);
141 int verify_vds(struct udf_disc *disc, vds_type_e vds, vds_sequence_t *seq);
142 int fix_vds(uint8_t *dev, struct udf_disc *disc, size_t sectorsize, avdp_type_e source, vds_sequence_t *seq/*, uint8_t interactive, uint8_t autofix*/);
143
144 // LVID functions
145 int get_lvid(uint8_t *dev, struct udf_disc *disc, int sectorsize, struct filesystemStats *stats, vds_sequence_t *seq);
146 int fix_lvid(uint8_t *dev, struct udf_disc *disc, size_t sectorsize, struct filesystemStats *stats, vds_sequence_t *seq);
147
148 // PD (SBD) functions
149 int get_pd(uint8_t *dev, struct udf_disc *disc, size_t sectorsize, struct filesystemStats *stats, vds_sequence_t *seq);
150 int fix_pd(uint8_t *dev, struct udf_disc *disc, size_t sectorsize, struct filesystemStats *stats, vds_sequence_t *seq);
151
152 // Filetree functions
153 uint8_t get_fsd(uint8_t *dev, struct udf_disc *disc, int sectorsize, uint32_t *lbnlsn, struct filesystemStats * stats, vds_sequence_t *seq);
154 uint8_t get_file_structure(const uint8_t *dev, const struct udf_disc *disc, uint32_t lbnlsn, struct filesystemStats *stats, vds_sequence_t *seq );
155
156 #endif //__UDFFSCK_H__
avdp_type_e
avdp_type_e
Definition: udffsck.h:39
filesystemStats::minUDFWriteRev
uint16_t minUDFWriteRev
Definition: udffsck.h:80
filesystemStats::partitionSizeBlocks
uint32_t partitionSizeBlocks
Definition: udffsck.h:85
print_timestamp
char * print_timestamp(timestamp ts)
Timestamp printing function.
Definition: udffsck.c:170
filesystemStats
Definition: udffsck.h:71
filesystemStats::blocksize
uint16_t blocksize
Definition: udffsck.h:72
impUseLVID::impID
regid impID
Definition: udffsck.h:109
impUseLVID
Definition: udffsck.h:108
vds_sequence_t
Definition: udffsck.h:56
fileInfo::filename
char * filename
Definition: udffsck.h:98
fix_pd
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.
Definition: udffsck.c:2455
main
int main(int argc, char *argv[])
Definition: main.c:237
impUseLVID::numOfDirs
uint32_t numOfDirs
Definition: udffsck.h:111
metadata_t
Definition: udffsck.h:50
metadata_t::tagLocation
uint32_t tagLocation
descriptor declared position
Definition: udffsck.h:52
THIRD_AVDP
Definition: udffsck.h:42
ecma_167.h
filesystemStats::usedSpace
uint64_t usedSpace
Definition: udffsck.h:83
vds_type_e
vds_type_e
Definition: udffsck.h:45
RESERVE_VDS
Definition: udffsck.h:47
impUseLVID::numOfFiles
uint32_t numOfFiles
Definition: udffsck.h:110
fix_avdp
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.
Definition: udffsck.c:2271
impUseLVID::minUDFWriteRev
uint16_t minUDFWriteRev
Definition: udffsck.h:113
dstring
uint8_t dstring
Definition: ecma_167.h:63
__attribute__
struct impUseLVID __attribute__((packed))
filesystemStats::countNumOfDirs
uint32_t countNumOfDirs
Definition: udffsck.h:78
filesystemStats::partitionNumOfBytes
uint32_t partitionNumOfBytes
Definition: udffsck.h:88
filesystemStats::AVDPSerialNum
uint16_t AVDPSerialNum
Definition: udffsck.h:82
filesystemStats::actUUID
uint64_t actUUID
Definition: udffsck.h:73
FIRST_AVDP
Definition: udffsck.h:40
fileInfo::modTime
timestamp modTime
Definition: udffsck.h:104
impUseLVID::impUse
uint8_t impUse[0]
Definition: udffsck.h:115
VDS_STRUCT_AMOUNT
#define VDS_STRUCT_AMOUNT
Maximum amount of VDS descriptors.
Definition: udffsck.h:36
file_t::size
uint32_t size
Definition: udffsck.h:68
MAIN_VDS
Definition: udffsck.h:46
filesystemStats::actPartitionBitmap
uint8_t * actPartitionBitmap
Definition: udffsck.h:90
file_t
Definition: udffsck.h:64
filesystemStats::countNumOfFiles
uint32_t countNumOfFiles
Definition: udffsck.h:76
impUseLVID::minUDFReadRev
uint16_t minUDFReadRev
Definition: udffsck.h:112
get_lvid
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.
Definition: udffsck.c:734
vds_sequence_t::lvid
metadata_t lvid
Definition: udffsck.h:60
filesystemStats::expNumOfDirs
uint32_t expNumOfDirs
Definition: udffsck.h:77
get_volume_identifier
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.
Definition: udffsck.c:818
filesystemStats::LVIDtimestamp
timestamp LVIDtimestamp
Definition: udffsck.h:92
filesystemStats::volumeSetIdent
dstring * volumeSetIdent
Definition: udffsck.h:94
filesystemStats::maxUUID
uint64_t maxUUID
Definition: udffsck.h:74
fileInfo::fileCharacteristics
uint8_t fileCharacteristics
Definition: udffsck.h:99
vds_sequence_t::pd
metadata_t pd
Definition: udffsck.h:61
filesystemStats::expPartitionBitmap
uint8_t * expPartitionBitmap
Definition: udffsck.h:91
metadata_t::error
uint8_t error
errors found on descriptor
Definition: udffsck.h:53
verify_vds
int verify_vds(struct udf_disc *disc, vds_type_e vds, vds_sequence_t *seq)
VDS verification structure.
Definition: udffsck.c:2066
fix_vds
int fix_vds(uint8_t *dev, struct udf_disc *disc, size_t sectorsize, avdp_type_e source, vds_sequence_t *seq)
Fix VDS sequence.
Definition: udffsck.c:2362
filesystemStats::partitionNumOfBits
uint32_t partitionNumOfBits
Definition: udffsck.h:89
get_pd
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.
Definition: udffsck.c:2520
impUseLVID::maxUDFWriteRev
uint16_t maxUDFWriteRev
Definition: udffsck.h:114
get_file_structure
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.
Definition: udffsck.c:1953
filesystemStats::expNumOfFiles
uint32_t expNumOfFiles
Definition: udffsck.h:75
fileInfo::size
uint64_t size
Definition: udffsck.h:102
udf_disc
Definition: libudffs.h:95
fileInfo::FIDSerialNum
uint16_t FIDSerialNum
Definition: udffsck.h:103
get_avdp
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.
Definition: udffsck.c:469
get_vds
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.
Definition: udffsck.c:576
get_fsd
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.
Definition: udffsck.c:923
filesystemStats::freeSpaceBlocks
uint32_t freeSpaceBlocks
Definition: udffsck.h:84
fix_lvid
int fix_lvid(uint8_t *dev, struct udf_disc *disc, size_t sectorsize, struct filesystemStats *stats, vds_sequence_t *seq)
Fix LVID values.
Definition: udffsck.c:2633
filesystemStats::expUnusedBlocks
uint32_t expUnusedBlocks
Definition: udffsck.h:87
libudffs.h
file_t::blocks
uint32_t blocks
Definition: udffsck.h:67
fileInfo::fileType
uint8_t fileType
Definition: udffsck.h:100
SECOND_AVDP
Definition: udffsck.h:41
filesystemStats::maxUDFWriteRev
uint16_t maxUDFWriteRev
Definition: udffsck.h:81
filesystemStats::minUDFReadRev
uint16_t minUDFReadRev
Definition: udffsck.h:79
file_t::flags
uint16_t flags
Definition: udffsck.h:65
fileInfo::permissions
uint32_t permissions
Definition: udffsck.h:101
write_avdp
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.
Definition: udffsck.c:2200
metadata_t::tagIdent
uint16_t tagIdent
descriptor identifier
Definition: udffsck.h:51
count_used_bits
uint64_t count_used_bits(struct filesystemStats *stats)
Counts used bits (blocks) at stats->actParitionBitmap.
Definition: udffsck.c:431
file_t::lsn
uint32_t lsn
Definition: udffsck.h:66
filesystemStats::expUsedBlocks
uint32_t expUsedBlocks
Definition: udffsck.h:86
fileInfo
Definition: udffsck.h:97
filesystemStats::partitionIdent
dstring * partitionIdent
Definition: udffsck.h:93
is_udf
int is_udf(uint8_t *dev, int *sectorsize, int force_sectorsize)
UDF VRS detection function.
Definition: udffsck.c:347