summaryrefslogtreecommitdiffstats
path: root/src/fat.h
blob: d2c9c90306e9b05326fa59395a936f90f23d8cb2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*

    File: fat.h

    Copyright (C) 1998-2004,2007-2008 Christophe GRENIER <grenier@cgsecurity.org>
  
    This software is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.
  
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
  
    You should have received a copy of the GNU General Public License along
    with this program; if not, write the Free Software Foundation, Inc., 51
    Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

 */

#ifndef _FAT_H
#define _FAT_H
#ifdef __cplusplus
extern "C" {
#endif

#include "fat_common.h"
/*@
  @ requires \valid(disk);
  @ requires valid_disk(disk);
  @ requires \valid_read(partition);
  @ requires valid_partition(partition);
  @ requires separation: \separated(disk, partition);
  @ decreases 0;
  @*/
int comp_FAT(disk_t *disk, const partition_t *partition, const unsigned long int fat_size, const unsigned long int sect_res);

/*@
  @ requires \valid_read(fh1);
  @ requires \valid_read(fh2);
  @*/
int log_fat2_info(const struct fat_boot_sector*fh1, const struct fat_boot_sector*fh2, const upart_type_t upart_type, const unsigned int sector_size);

/*@
  @ requires \valid(disk);
  @ requires valid_disk(disk);
  @ requires \valid_read(partition);
  @ requires valid_partition(partition);
  @ requires separation: \separated(disk, partition);
  @*/
unsigned int get_next_cluster(disk_t *disk, const partition_t *partition, const upart_type_t upart_type, const int offset, const unsigned int cluster);

/*@
  @ requires \valid(disk);
  @ requires valid_disk(disk);
  @ requires \valid_read(partition);
  @ requires valid_partition(partition);
  @ requires separation: \separated(disk, partition);
  @ decreases 0;
  @*/
int set_next_cluster(disk_t *disk, const partition_t *partition, const upart_type_t upart_type, const int offset, const unsigned int cluster, const unsigned int next_cluster);

/*@
  @ requires \valid_read(partition);
  @ terminates \true;
  @ assigns  \nothing;
  @*/
int is_fat(const partition_t *partition);

/*@
  @ requires \valid_read(partition);
  @ terminates \true;
  @ assigns  \nothing;
  @*/
int is_part_fat(const partition_t *partition);

/*@
  @ requires \valid_read(partition);
  @ terminates \true;
  @ assigns  \nothing;
  @*/
int is_part_fat12(const partition_t *partition);

/*@
  @ requires \valid_read(partition);
  @ terminates \true;
  @ assigns  \nothing;
  @*/
int is_part_fat16(const partition_t *partition);

/*@
  @ requires \valid_read(partition);
  @ terminates \true;
  @ assigns  \nothing;
  @*/
int is_part_fat32(const partition_t *partition);

/*@
  @ requires \valid(disk);
  @ requires valid_disk(disk);
  @ requires \valid_read(partition);
  @ requires valid_partition(partition);
  @ requires separation: \separated(disk, partition);
  @ decreases 0;
  @*/
unsigned int fat32_get_prev_cluster(disk_t *disk, const partition_t *partition, const unsigned int fat_offset, const unsigned int cluster, const unsigned int no_of_cluster);

/*@
  @ requires \valid(disk);
  @ requires valid_disk(disk);
  @ requires \valid_read(partition);
  @ requires valid_partition(partition);
  @ requires separation: \separated(disk, partition);
  @ requires \valid(next_free);
  @ requires \valid(free_count);
  @ decreases 0;
  @*/
int fat32_free_info(disk_t *disk, const partition_t *partition, const unsigned int fat_offset, const unsigned int no_of_cluster, unsigned int *next_free, unsigned int *free_count);

/*@
  @ requires \valid_read(boot_fat32 + (0 .. sector_size + 512 -1));
  @ terminates \true;
  @ assigns  \nothing;
  @*/
unsigned long int fat32_get_free_count(const unsigned char *boot_fat32, const unsigned int sector_size);

/*@
  @ requires \valid_read(boot_fat32 + (0 .. sector_size + 512 -1));
  @ terminates \true;
  @ assigns  \nothing;
  @*/
unsigned long int fat32_get_next_free(const unsigned char *boot_fat32, const unsigned int sector_size);

/*@
  @ requires \valid(disk);
  @ requires valid_disk(disk);
  @ requires \valid_read(fat_header);
  @ requires \valid(partition);
  @ requires valid_partition(partition);
  @ requires separation: \separated(disk, partition, fat_header);
  @*/
int recover_FAT(disk_t *disk, const struct fat_boot_sector*fat_header, partition_t *partition, const int verbose, const int dump_ind, const int backup);

/*@
  @ requires \valid(disk);
  @ requires valid_disk(disk);
  @ requires \valid(partition);
  @ requires valid_partition(partition);
  @ requires separation: \separated(disk, partition);
  @ decreases 0;
  @*/
int check_FAT(disk_t *disk, partition_t *partition, const int verbose);

/*@
  @ requires \valid(disk);
  @ requires valid_disk(disk);
  @ requires \valid_read(fat_header);
  @ requires \valid(partition);
  @ requires valid_partition(partition);
  @ requires separation: \separated(disk, partition, fat_header);
  @*/
int test_FAT(disk_t *disk, const struct fat_boot_sector *fat_header, const partition_t *partition, const int verbose, const int dump_ind);

/*@
  @ requires \valid(disk);
  @ requires valid_disk(disk);
  @ requires \valid_read(fat_header);
  @ requires \valid(partition);
  @ requires valid_partition(partition);
  @ requires separation: \separated(disk, partition, fat_header);
  @*/
int recover_OS2MB(const disk_t *disk, const struct fat_boot_sector*fat_header, partition_t *partition, const int verbose, const int dump_ind);

/*@
  @ requires \valid(disk);
  @ requires valid_disk(disk);
  @ requires \valid(partition);
  @ requires valid_partition(partition);
  @ requires separation: \separated(disk, partition);
  @ decreases 0;
  @*/
int check_OS2MB(disk_t *disk, partition_t *partition, const int verbose);

/*@
  @ requires \valid_read(name);
  @ terminates \true;
  @ assigns \nothing;
  @*/
int check_VFAT_volume_name(const char *name, const unsigned int max_size);

#ifdef __cplusplus
} /* closing brace for extern "C" */
#endif
#endif