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
24typedef enum fatAccessMode_t {
25	FAT_ACCESS_READ,
26	FAT_ACCESS_WRITE
27} fatAccessMode_t;
28
29typedef struct Fs_t {
30	Class_t *Class;
31	int refs;
32	Stream_t *Next;
33	Stream_t *Buffer;
34
35	int serialized;
36	unsigned long serial_number;
37	unsigned int cluster_size;
38	unsigned int sector_size;
39	int fat_error;
40
41	unsigned int (*fat_decode)(struct Fs_t *This, unsigned int num);
42	void (*fat_encode)(struct Fs_t *This, unsigned int num,
43			   unsigned int code);
44
45	Stream_t *Direct;
46	int fat_dirty;
47	unsigned int fat_start;
48	unsigned int fat_len;
49
50	unsigned int num_fat;
51	unsigned int end_fat;
52	unsigned int last_fat;
53	int fat_bits; /* must be signed, because we use negative values
54		       * for special purposes */
55	struct FatMap_t *FatMap;
56
57	unsigned int dir_start;
58	unsigned int dir_len;
59	unsigned int clus_start;
60
61	unsigned int num_clus;
62	char drive; /* for error messages */
63
64	/* fat 32 */
65	unsigned int primaryFat;
66	unsigned int writeAllFats;
67	unsigned int rootCluster;
68	unsigned int infoSectorLoc;
69	unsigned int last; /* last sector allocated, or MAX32 if unknown */
70	unsigned int freeSpace; /* free space, or MAX32 if unknown */
71	int preallocatedClusters;
72
73	int lastFatSectorNr;
74	unsigned char *lastFatSectorData;
75	fatAccessMode_t lastFatAccessMode;
76	int sectorMask;
77	int sectorShift;
78
79	doscp_t *cp;
80} Fs_t;
81
82int fs_free(Stream_t *Stream);
83
84void set_fat12(Fs_t *Fs);
85void set_fat16(Fs_t *Fs);
86void set_fat32(Fs_t *Fs);
87unsigned int get_next_free_cluster(Fs_t *Fs, unsigned int last);
88unsigned int fatDecode(Fs_t *This, unsigned int pos);
89void fatAppend(Fs_t *This, unsigned int pos, unsigned int newpos);
90void fatDeallocate(Fs_t *This, unsigned int pos);
91void fatAllocate(Fs_t *This, unsigned int pos, unsigned int value);
92void fatEncode(Fs_t *This, unsigned int pos, unsigned int value);
93
94int fat_read(Fs_t *This, struct bootsector *boot, int fat_bits,
95			 size_t tot_sectors, int nodups);
96void fat_write(Fs_t *This);
97int zero_fat(Fs_t *Fs, int media_descriptor);
98extern Class_t FsClass;
99int fsPreallocateClusters(Fs_t *Fs, long);
100Fs_t *getFs(Stream_t *Stream);
101
102
103#endif
104