OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [bootloaders/] [orpmon/] [include/] [dosfs.h] - Blame information for rev 756

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 389 tac2
/*
2
        DOSFS Embedded FAT-Compatible Filesystem
3
        (C) 2005 Lewin A.R.W. Edwards (sysadm@zws.com)
4
*/
5
 
6
#ifndef _DOSFS_H
7
#define _DOSFS_H
8
//#include <stdio.h>
9
//#include <sys/types.h>
10
//#include <stdint.h>
11
#include "board.h"
12
#include "typedefs.h"
13
 
14
#include "spr-defs.h"
15
#include "support.h"
16
//#include <stdlib.h>
17
 
18
#include "int.h"
19
#include "uart.h"
20
#include "screen.h"
21
//===================================================================
22
char *strcpy2(char *dest,  char* src);
23
int memcmp2(const void *s1, const void *s2, size_t  n);
24
int strcmp2(const char * s1, const char * s2);
25
 
26
 typedef struct
27
        {
28
           long int quot;
29
           long int rem;
30
        } ldiv_t;
31
 
32
 typedef struct
33
        {
34
          int quot;
35
         int rem;
36
        } div_t;
37
 
38
 
39
#define SECTOR_TO_BLOCK(a) ( (a) << 9)
40
unsigned long int DFS_ReadSector(unsigned char unit, unsigned char *buffer, unsigned long int sector, unsigned long int  count);
41
unsigned long int DFS_WriteSector(unsigned char unit, unsigned char *buffer, unsigned long int sector, unsigned long int  count);
42
 
43
 
44
 ldiv_t ldiv (long int numer, long int denom);
45
div_t div ( int numer,  int denom);
46
 
47
//===================================================================
48
// Configurable items
49
#define MAX_PATH                64              // Maximum path length (increasing this will
50
                                                                // GREATLY increase stack requirements!)
51
#define DIR_SEPARATOR   '/'             // character separating directory components
52
 
53
// End of configurable items
54
//===================================================================
55
 
56
//===================================================================
57
// 32-bit error codes
58
#define DFS_OK                  0                        // no error
59
#define DFS_EOF                 1                       // end of file (not an error)
60
#define DFS_WRITEPROT   2                       // volume is write protected
61
#define DFS_NOTFOUND    3                       // path or file not found
62
#define DFS_PATHLEN             4                       // path too long
63
#define DFS_ALLOCNEW    5                       // must allocate new directory cluster
64
#define DFS_ERRMISC             0xffffffff      // generic error
65
 
66
//===================================================================
67
// File access modes
68
#define DFS_READ                1                       // read-only
69
#define DFS_WRITE               2                       // write-only
70
 
71
//===================================================================
72
// Miscellaneous constants
73
#define SECTOR_SIZE             512             // sector size in bytes
74
 
75
//===================================================================
76
// Internal subformat identifiers
77
#define FAT12                   0
78
#define FAT16                   1
79
#define FAT32                   2
80
 
81
//===================================================================
82
// DOS attribute bits
83
#define ATTR_READ_ONLY  0x01
84
#define ATTR_HIDDEN             0x02
85
#define ATTR_SYSTEM             0x04
86
#define ATTR_VOLUME_ID  0x08
87
#define ATTR_DIRECTORY  0x10
88
#define ATTR_ARCHIVE    0x20
89
#define ATTR_LONG_NAME  (ATTR_READ_ONLY | ATTR_HIDDEN | ATTR_SYSTEM | ATTR_VOLUME_ID)
90
 
91
 
92
/*
93
        Directory entry structure
94
        note: if name[0] == 0xe5, this is a free dir entry
95
              if name[0] == 0x00, this is a free entry and all subsequent entries are free
96
                  if name[0] == 0x05, the first character of the name is 0xe5 [a kanji nicety]
97
 
98
        Date format: bit 0-4  = day of month (1-31)
99
                     bit 5-8  = month, 1=Jan..12=Dec
100
                                 bit 9-15 =     count of years since 1980 (0-127)
101
        Time format: bit 0-4  = 2-second count, (0-29)
102
                     bit 5-10 = minutes (0-59)
103
                                 bit 11-15= hours (0-23)
104
*/
105
typedef struct _tagDIRENT {
106
        unsigned char name[11];                 // filename
107
        unsigned char attr;                             // attributes (see ATTR_* constant definitions)
108
        unsigned char reserved;                 // reserved, must be 0
109
        unsigned char crttimetenth;             // create time, 10ths of a second (0-199 are valid)
110
        unsigned char crttime_l;                        // creation time low byte
111
        unsigned char crttime_h;                        // creation time high byte
112
        unsigned char crtdate_l;                        // creation date low byte
113
        unsigned char crtdate_h;                        // creation date high byte
114
        unsigned char lstaccdate_l;             // last access date low byte
115
        unsigned char lstaccdate_h;             // last access date high byte
116
        unsigned char startclus_h_l;            // high word of first cluster, low byte (FAT32)
117
        unsigned char startclus_h_h;            // high word of first cluster, high byte (FAT32)
118
        unsigned char wrttime_l;                        // last write time low byte
119
        unsigned char wrttime_h;                        // last write time high byte
120
        unsigned char wrtdate_l;                        // last write date low byte
121
        unsigned char wrtdate_h;                        // last write date high byte
122
        unsigned char startclus_l_l;            // low word of first cluster, low byte
123
        unsigned char startclus_l_h;            // low word of first cluster, high byte
124
        unsigned char filesize_0;                       // file size, low byte
125
        unsigned char filesize_1;                       //
126
        unsigned char filesize_2;                       //
127
        unsigned char filesize_3;                       // file size, high byte
128
} DIRENT, *PDIRENT;
129
 
130
/*
131
        Partition table entry structure
132
*/
133
typedef struct _tagPTINFO {
134
        unsigned char           active;                 // 0x80 if partition active
135
        unsigned char           start_h;                // starting head
136
        unsigned char           start_cs_l;             // starting cylinder and sector (low byte)
137
        unsigned char           start_cs_h;             // starting cylinder and sector (high byte)
138
        unsigned char           type;                   // type ID byte
139
        unsigned char           end_h;                  // ending head
140
        unsigned char           end_cs_l;               // ending cylinder and sector (low byte)
141
        unsigned char           end_cs_h;               // ending cylinder and sector (high byte)
142
        unsigned char           start_0;                // starting sector# (low byte)
143
        unsigned char           start_1;                //
144
        unsigned char           start_2;                //
145
        unsigned char           start_3;                // starting sector# (high byte)
146
        unsigned char           size_0;                 // size of partition (low byte)
147
        unsigned char           size_1;                 //
148
        unsigned char           size_2;                 //
149
        unsigned char           size_3;                 // size of partition (high byte)
150
} PTINFO, *PPTINFO;
151
 
152
/*
153
        Master Boot Record structure
154
*/
155
typedef struct _tagMBR {
156
        unsigned char bootcode[0x1be];  // boot sector
157
        PTINFO ptable[4] __attribute__((__packed__));
158
;                       // four partition table structures
159
        unsigned char sig_55;                           // 0x55 signature byte
160
        unsigned char sig_aa;                           // 0xaa signature byte
161
} MBR, *PMBR;
162
 
163
/*
164
        BIOS Parameter Block structure (FAT12/16)
165
*/
166
typedef struct _tagBPB {
167
        unsigned char bytepersec_l;             // bytes per sector low byte (0x00)
168
        unsigned char bytepersec_h;             // bytes per sector high byte (0x02)
169
        unsigned char   secperclus;                     // sectors per cluster (1,2,4,8,16,32,64,128 are valid)
170
        unsigned char reserved_l;                       // reserved sectors low byte
171
        unsigned char reserved_h;                       // reserved sectors high byte
172
        unsigned char numfats;                  // number of FAT copies (2)
173
        unsigned char rootentries_l;            // number of root dir entries low byte (0x00 normally)
174
        unsigned char rootentries_h;            // number of root dir entries high byte (0x02 normally)
175
        unsigned char sectors_s_l;              // small num sectors low byte
176
        unsigned char sectors_s_h;              // small num sectors high byte
177
        unsigned char mediatype;                        // media descriptor byte
178
        unsigned char secperfat_l;              // sectors per FAT low byte
179
        unsigned char secperfat_h;              // sectors per FAT high byte
180
        unsigned char secpertrk_l;              // sectors per track low byte
181
        unsigned char secpertrk_h;              // sectors per track high byte
182
        unsigned char heads_l;                  // heads low byte
183
        unsigned char heads_h;                  // heads high byte
184
        unsigned char hidden_0;                 // hidden sectors low byte
185
        unsigned char hidden_1;                 // (note - this is the number of MEDIA sectors before
186
        unsigned char hidden_2;                 // first sector of VOLUME - we rely on the MBR instead)
187
        unsigned char hidden_3;                 // hidden sectors high byte
188
        unsigned char sectors_l_0;              // large num sectors low byte
189
        unsigned char sectors_l_1;              //
190
        unsigned char sectors_l_2;              //
191
        unsigned char sectors_l_3;              // large num sectors high byte
192
} BPB, *PBPB;
193
 
194
 
195
 
196
 
197
/*
198
        Extended BIOS Parameter Block structure (FAT12/16)
199
*/
200
typedef struct _tagEBPB {
201
        unsigned char unit;                             // int 13h drive#
202
        unsigned char head;                             // archaic, used by Windows NT-class OSes for flags
203
        unsigned char signature;                        // 0x28 or 0x29
204
        unsigned char serial_0;                 // serial#
205
        unsigned char serial_1;                 // serial#
206
        unsigned char serial_2;                 // serial#
207
        unsigned char serial_3;                 // serial#
208
        unsigned char label[11];                        // volume label
209
        unsigned char system[8];                        // filesystem ID
210
} EBPB, *PEBPB;
211
 
212
/*
213
        Extended BIOS Parameter Block structure (FAT32)
214
*/
215
typedef struct _tagEBPB32 {
216
        unsigned char fatsize_0;                        // big FAT size in sectors low byte
217
        unsigned char fatsize_1;                        //
218
        unsigned char fatsize_2;                        //
219
        unsigned char fatsize_3;                        // big FAT size in sectors high byte
220
        unsigned char extflags_l;                       // extended flags low byte
221
        unsigned char extflags_h;                       // extended flags high byte
222
        unsigned char fsver_l;                  // filesystem version (0x00) low byte
223
        unsigned char fsver_h;                  // filesystem version (0x00) high byte
224
        unsigned char root_0;                           // cluster of root dir, low byte
225
        unsigned char root_1;                           //
226
        unsigned char root_2;                           //
227
        unsigned char root_3;                           // cluster of root dir, high byte
228
        unsigned char fsinfo_l;                 // sector pointer to FSINFO within reserved area, low byte (2)
229
        unsigned char fsinfo_h;                 // sector pointer to FSINFO within reserved area, high byte (0)
230
        unsigned char bkboot_l;                 // sector pointer to backup boot sector within reserved area, low byte (6)
231
        unsigned char bkboot_h;                 // sector pointer to backup boot sector within reserved area, high byte (0)
232
        unsigned char reserved[12];             // reserved, should be 0
233
 
234
        unsigned char unit;                             // int 13h drive#
235
        unsigned char head;                             // archaic, used by Windows NT-class OSes for flags
236
        unsigned char signature;                        // 0x28 or 0x29
237
        unsigned char serial_0;                 // serial#
238
        unsigned char serial_1;                 // serial#
239
        unsigned char serial_2;                 // serial#
240
        unsigned char serial_3;                 // serial#
241
        unsigned char label[11];                        // volume label
242
        unsigned char system[8];                        // filesystem ID
243
} EBPB32, *PEBPB32;
244
 
245
/*
246
        Logical Boot Record structure (volume boot sector)
247
*/
248
typedef struct _tagLBR {
249
        unsigned char jump[3];                  // JMP instruction
250
        unsigned char oemid[8];                 // OEM ID, space-padded
251
        BPB bpb  __attribute__((__packed__));                                   // BIOS Parameter Block
252
        union {
253
                EBPB ebpb  __attribute__((__packed__));                         // FAT12/16 Extended BIOS Parameter Block
254
                EBPB32 ebpb32  __attribute__((__packed__));                     // FAT32 Extended BIOS Parameter Block
255
        } ebpb;
256
        unsigned char code[420];                        // boot sector code
257
        unsigned char sig_55;                           // 0x55 signature byte
258
        unsigned char sig_aa;                           // 0xaa signature byte
259
} LBR, *PLBR;
260
 
261
/*
262
        Volume information structure (Internal to DOSFS)
263
*/
264
typedef struct _tagVOLINFO {
265
        unsigned char unit;                             // unit on which this volume resides
266
        unsigned char filesystem;                       // formatted filesystem
267
 
268
// These two fields aren't very useful, so support for them has been commented out to
269
// save memory. (Note that the "system" tag is not actually used by DOS to determine
270
// filesystem type - that decision is made entirely on the basis of how many clusters
271
// the drive contains. DOSFS works the same way).
272
// See tag: OEMID in dosfs.c
273
//      unsigned char oemid[9];                 // OEM ID ASCIIZ
274
//      unsigned char system[9];                        // system ID ASCIIZ
275
        unsigned char label[12];                        // volume label ASCIIZ
276
        unsigned long int  startsector;         // starting sector of filesystem
277
        unsigned char secperclus;                       // sectors per cluster
278
        unsigned short int reservedsecs;                // reserved sectors
279
        unsigned long int numsecs;                      // number of sectors in volume
280
        unsigned long int secperfat;                    // sectors per FAT
281
        unsigned short int rootentries;         // number of root dir entries
282
 
283
        unsigned long int numclusters;          // number of clusters on drive
284
 
285
        // The fields below are PHYSICAL SECTOR NUMBERS.
286
        unsigned long int fat1;                         // starting sector# of FAT copy 1
287
        unsigned long int rootdir;                      // starting sector# of root directory (FAT12/FAT16) or cluster (FAT32)
288
        unsigned long int dataarea;                     // starting sector# of data area (cluster #2)
289
} VOLINFO, *PVOLINFO;
290
 
291
/*
292
        Flags in DIRINFO.flags
293
*/
294
#define DFS_DI_BLANKENT         0x01    // Searching for blank entry
295
 
296
/*
297
        Directory search structure (Internal to DOSFS)
298
*/
299
typedef struct _tagDIRINFO {
300
        unsigned long int currentcluster;       // current cluster in dir
301
        unsigned char currentsector;            // current sector in cluster
302
        unsigned char currententry;             // current dir entry in sector
303
        unsigned char *scratch;                 // ptr to user-supplied scratch buffer (one sector)
304
        unsigned char flags;                            // internal DOSFS flags
305
} DIRINFO, *PDIRINFO;
306
 
307
/*
308
        File handle structure (Internal to DOSFS)
309
*/
310
typedef struct _tagFILEINFO {
311
        PVOLINFO volinfo  __attribute__((__packed__));                  // VOLINFO used to open this file
312
        unsigned long int dirsector;                    // physical sector containing dir entry of this file
313
        unsigned char diroffset;                        // # of this entry within the dir sector
314
        unsigned char mode;                             // mode in which this file was opened
315
        unsigned long int firstcluster;         // first cluster of file
316
        unsigned long int filelen;                      // byte length of file
317
 
318
        unsigned long int cluster;                      // current cluster
319
        unsigned long int pointer;                      // current (BYTE) pointer
320
} FILEINFO, *PFILEINFO;
321
 
322
/*
323
        Get starting sector# of specified partition on drive #unit
324
        NOTE: This code ASSUMES an MBR on the disk.
325
        scratchsector should point to a SECTOR_SIZE scratch area
326
        Returns 0xffffffff for any error.
327
        If pactive is non-NULL, this function also returns the partition active flag.
328
        If pptype is non-NULL, this function also returns the partition type.
329
        If psize is non-NULL, this function also returns the partition size.
330
*/
331
unsigned long int init_fat(VOLINFO *vis);
332
 
333
unsigned long int DFS_GetPtnStart(unsigned char unit, unsigned char *scratchsector, unsigned char pnum, unsigned char *pactive, unsigned char *pptype, unsigned long int *psize);
334
 
335
/*
336
        Retrieve volume info from BPB and store it in a VOLINFO structure
337
        You must provide the unit and starting sector of the filesystem, and
338
        a pointer to a sector buffer for scratch
339
        Attempts to read BPB and glean information about the FS from that.
340
        Returns 0 OK, nonzero for any error.
341
*/
342
unsigned long int DFS_GetVolInfo(unsigned char unit, unsigned char *scratchsector, unsigned long int startsector, PVOLINFO volinfo);
343
 
344
/*
345
        Open a directory for enumeration by DFS_GetNextDirEnt
346
        You must supply a populated VOLINFO (see DFS_GetVolInfo)
347
        The empty string or a string containing only the directory separator are
348
        considered to be the root directory.
349
        Returns 0 OK, nonzero for any error.
350
*/
351
unsigned long int DFS_OpenDir(PVOLINFO volinfo, unsigned char *dirname, PDIRINFO dirinfo);
352
 
353
/*
354
        Get next entry in opened directory structure. Copies fields into the dirent
355
        structure, updates dirinfo. Note that it is the _caller's_ responsibility to
356
        handle the '.' and '..' entries.
357
        A deleted file will be returned as a NULL entry (first char of filename=0)
358
        by this code. Filenames beginning with 0x05 will be translated to 0xE5
359
        automatically. Long file name entries will be returned as NULL.
360
        returns DFS_EOF if there are no more entries, DFS_OK if this entry is valid,
361
        or DFS_ERRMISC for a media error
362
*/
363
unsigned long int DFS_GetNext(PVOLINFO volinfo, PDIRINFO dirinfo, PDIRENT dirent);
364
 
365
/*
366
        Open a file for reading or writing. You supply populated VOLINFO, a path to the file,
367
        mode (DFS_READ or DFS_WRITE) and an empty fileinfo structure. You also need to
368
        provide a pointer to a sector-sized scratch buffer.
369
        Returns various DFS_* error states. If the result is DFS_OK, fileinfo can be used
370
        to access the file from this point on.
371
*/
372
unsigned long int DFS_OpenFile(PVOLINFO volinfo, unsigned char *path, unsigned char mode, unsigned char *scratch, PFILEINFO fileinfo);
373
 
374
/*
375
        Read an open file
376
        You must supply a prepopulated FILEINFO as provided by DFS_OpenFile, and a
377
        pointer to a SECTOR_SIZE scratch buffer.
378
        Note that returning DFS_EOF is not an error condition. This function updates the
379
        successcount field with the number of bytes actually read.
380
*/
381
unsigned long int DFS_ReadFile(PFILEINFO fileinfo, unsigned char *scratch, unsigned char *buffer, unsigned long int *successcount, unsigned long int len);
382
 
383
/*
384
        Write an open file
385
        You must supply a prepopulated FILEINFO as provided by DFS_OpenFile, and a
386
        pointer to a SECTOR_SIZE scratch buffer.
387
        This function updates the successcount field with the number of bytes actually written.
388
*/
389
unsigned long int DFS_WriteFile(PFILEINFO fileinfo, unsigned char *scratch, unsigned char *buffer, unsigned long int *successcount, unsigned long int len);
390
 
391
/*
392
        Seek file pointer to a given position
393
        This function does not return status - refer to the fileinfo->pointer value
394
        to see where the pointer wound up.
395
        Requires a SECTOR_SIZE scratch buffer
396
*/
397
void DFS_Seek(PFILEINFO fileinfo, unsigned long int offset, unsigned char *scratch);
398
 
399
/*
400
        Delete a file
401
        scratch must point to a sector-sized buffer
402
*/
403
unsigned long int DFS_UnlinkFile(PVOLINFO volinfo, unsigned char *path, unsigned char *scratch);
404
 
405
// If we are building a host-emulation version, include host support
406
#ifdef HOSTVER
407
#include "hostemu.h"
408
#endif
409
 
410
#endif // _DOSFS_H

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.