• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef MTOOLS_FSP_H
2 #define MTOOLS_FSP_H
3 
4 /*  Copyright 1996-1999,2001-2003,2008,2009 Alain Knaff.
5  *  This file is part of mtools.
6  *
7  *  Mtools 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 3 of the License, or
10  *  (at your option) any later version.
11  *
12  *  Mtools 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 Mtools.  If not, see <http://www.gnu.org/licenses/>.
19  */
20 #include "stream.h"
21 #include "msdos.h"
22 #include "fs.h"
23 
24 typedef enum fatAccessMode_t {
25 	FAT_ACCESS_READ,
26 	FAT_ACCESS_WRITE
27 } fatAccessMode_t;
28 
29 typedef struct Fs_t {
30 	struct Stream_t head;
31 
32 	int serialized;
33 	unsigned long serial_number;
34 	uint8_t cluster_size;
35 	uint16_t sector_size;
36 
37 	int fat_error;
38 
39 	unsigned int (*fat_decode)(struct Fs_t *This, unsigned int num);
40 	void (*fat_encode)(struct Fs_t *This, unsigned int num,
41 			   unsigned int code);
42 
43 	int fat_dirty;
44 	uint16_t fat_start;
45 	uint32_t fat_len;
46 
47 	uint8_t num_fat;
48 	uint32_t end_fat;
49 	uint32_t last_fat;
50 	unsigned int fat_bits; /* When it ends up here, all negative
51 				  special values have been
52 				  eliminated */
53 
54 	struct FatMap_t *FatMap;
55 
56 	uint32_t dir_start;
57 	uint16_t dir_len;
58 	uint32_t clus_start;
59 
60 	uint32_t num_clus;
61 	char drive; /* for error messages */
62 
63 	/* fat 32 */
64 	uint32_t primaryFat;
65 	uint32_t writeAllFats;
66 	uint32_t rootCluster;
67 	uint32_t infoSectorLoc;
68 	uint16_t backupBoot;
69 	uint32_t last; /* last sector allocated, or MAX32 if unknown */
70 	uint32_t freeSpace; /* free space, or MAX32 if unknown */
71 	unsigned int preallocatedClusters;
72 
73 	uint32_t lastFatSectorNr;
74 	unsigned char *lastFatSectorData;
75 	fatAccessMode_t lastFatAccessMode;
76 	unsigned int sectorMask;
77 	unsigned int sectorShift;
78 
79 	doscp_t *cp;
80 } Fs_t;
81 
82 #ifndef abs
83 #define abs(x) ((unsigned int)((x)>0?(x):-(x)))
84 #endif
85 
86 mt_off_t sectorsToBytes(Fs_t *This, uint32_t off);
87 int fs_free(Stream_t *Stream);
88 
89 void set_fat(Fs_t *This);
90 unsigned int get_next_free_cluster(Fs_t *Fs, unsigned int last);
91 unsigned int fatDecode(Fs_t *This, unsigned int pos);
92 void fatAppend(Fs_t *This, unsigned int pos, unsigned int newpos);
93 void fatDeallocate(Fs_t *This, unsigned int pos);
94 void fatAllocate(Fs_t *This, unsigned int pos, unsigned int value);
95 void fatEncode(Fs_t *This, unsigned int pos, unsigned int value);
96 
97 int fat_read(Fs_t *This, union bootsector *boot, int nodups);
98 void fat_write(Fs_t *This);
99 int zero_fat(Fs_t *Fs, uint8_t media_descriptor);
100 extern Class_t FsClass;
101 int fsPreallocateClusters(Fs_t *Fs, uint32_t);
102 void fsReleasePreallocateClusters(Fs_t *Fs, uint32_t);
103 Fs_t *getFs(Stream_t *Stream);
104 
105 int calc_fs_parameters(struct device *dev, bool fat32, uint32_t tot_sectors,
106 		       struct Fs_t *Fs, uint8_t *descr);
107 
108 /* Fs_t *makeFsForFormat(void); */
109 void initFsForFormat(Fs_t *Fs);
110 void setFsSectorSize(Fs_t *Fs, struct device *dev, uint16_t msize);
111 
112 uint32_t parseFsParams(	Fs_t *This,
113 			union bootsector *boot,
114 			int media,
115 			unsigned int cylinder_size);
116 uint32_t calc_clus_start(Fs_t *Fs);
117 int calc_num_clus(Fs_t *Fs, uint32_t tot_sectors);
118 
119 #endif
120