| 211 |
theseven |
1 |
/***************************************************************************
|
|
|
2 |
* __________ __ ___.
|
|
|
3 |
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
4 |
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
5 |
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
6 |
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
7 |
* \/ \/ \/ \/ \/
|
|
|
8 |
* $Id$
|
|
|
9 |
*
|
|
|
10 |
* Copyright (C) 2002 by Linus Nielsen Feltzing
|
|
|
11 |
*
|
|
|
12 |
* This program is free software; you can redistribute it and/or
|
|
|
13 |
* modify it under the terms of the GNU General Public License
|
|
|
14 |
* as published by the Free Software Foundation; either version 2
|
|
|
15 |
* of the License, or (at your option) any later version.
|
|
|
16 |
*
|
|
|
17 |
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
18 |
* KIND, either express or implied.
|
|
|
19 |
*
|
|
|
20 |
****************************************************************************/
|
|
|
21 |
|
|
|
22 |
#ifndef FAT_H
|
|
|
23 |
#define FAT_H
|
|
|
24 |
|
| 489 |
theseven |
25 |
#ifndef IN_APPLICATION_CODE
|
|
|
26 |
|
| 211 |
theseven |
27 |
#include "global.h"
|
|
|
28 |
#include "util.h"
|
|
|
29 |
#include "mv.h" /* for volume definitions */
|
|
|
30 |
|
|
|
31 |
#ifndef SECTOR_SIZE
|
|
|
32 |
#define SECTOR_SIZE 512
|
|
|
33 |
#endif
|
|
|
34 |
|
|
|
35 |
/* Number of bytes reserved for a file name (including the trailing \0).
|
|
|
36 |
Since names are stored in the entry as UTF-8, we won't be able to
|
|
|
37 |
store all names allowed by FAT. In FAT, a name can have max 255
|
|
|
38 |
characters (not bytes!). Since the UTF-8 encoding of a char may take
|
|
|
39 |
up to 4 bytes, there will be names that we won't be able to store
|
|
|
40 |
completely. For such names, the short DOS name is used. */
|
|
|
41 |
#define FAT_FILENAME_BYTES 256
|
|
|
42 |
|
|
|
43 |
struct fat_direntry
|
|
|
44 |
{
|
|
|
45 |
unsigned char name[FAT_FILENAME_BYTES]; /* UTF-8 encoded name plus \0 */
|
|
|
46 |
unsigned short attr; /* Attributes */
|
|
|
47 |
unsigned char crttimetenth; /* Millisecond creation
|
|
|
48 |
time stamp (0-199) */
|
|
|
49 |
unsigned short crttime; /* Creation time */
|
|
|
50 |
unsigned short crtdate; /* Creation date */
|
|
|
51 |
unsigned short lstaccdate; /* Last access date */
|
|
|
52 |
unsigned short wrttime; /* Last write time */
|
|
|
53 |
unsigned short wrtdate; /* Last write date */
|
|
|
54 |
unsigned long filesize; /* File size in bytes */
|
|
|
55 |
long firstcluster; /* fstclusterhi<<16 + fstcluslo */
|
|
|
56 |
};
|
|
|
57 |
|
|
|
58 |
#define FAT_ATTR_READ_ONLY 0x01
|
|
|
59 |
#define FAT_ATTR_HIDDEN 0x02
|
|
|
60 |
#define FAT_ATTR_SYSTEM 0x04
|
|
|
61 |
#define FAT_ATTR_VOLUME_ID 0x08
|
|
|
62 |
#define FAT_ATTR_DIRECTORY 0x10
|
|
|
63 |
#define FAT_ATTR_ARCHIVE 0x20
|
|
|
64 |
#define FAT_ATTR_VOLUME 0x40 /* this is a volume, not a real directory */
|
|
|
65 |
|
|
|
66 |
struct fat_file
|
|
|
67 |
{
|
|
|
68 |
long firstcluster; /* first cluster in file */
|
|
|
69 |
long lastcluster; /* cluster of last access */
|
|
|
70 |
long lastsector; /* sector of last access */
|
|
|
71 |
long clusternum; /* current clusternum */
|
|
|
72 |
long sectornum; /* sector number in this cluster */
|
|
|
73 |
unsigned int direntry; /* short dir entry index from start of dir */
|
|
|
74 |
unsigned int direntries; /* number of dir entries used by this file */
|
|
|
75 |
long dircluster; /* first cluster of dir */
|
|
|
76 |
bool eof;
|
|
|
77 |
#ifdef HAVE_MULTIVOLUME
|
|
|
78 |
int volume; /* file resides on which volume */
|
|
|
79 |
#endif
|
|
|
80 |
};
|
|
|
81 |
|
|
|
82 |
struct fat_dir
|
|
|
83 |
{
|
|
|
84 |
unsigned int entry;
|
|
|
85 |
unsigned int entrycount;
|
|
|
86 |
long sector;
|
|
|
87 |
struct fat_file file;
|
|
|
88 |
unsigned char sectorcache[SECTOR_SIZE] CACHEALIGN_ATTR;
|
|
|
89 |
/* There are 2-bytes per characters. We don't want to bother too much, as LFN entries are
|
|
|
90 |
* at much 255 characters longs, that's at most 20 LFN entries. Each entry hold at most
|
|
|
91 |
* 13 characters, that a total of 260 characters. So we keep a buffer of that size.
|
|
|
92 |
* Keep coherent with fat.c code. */
|
|
|
93 |
unsigned char longname[260 * 2];
|
|
|
94 |
} CACHEALIGN_ATTR;
|
|
|
95 |
|
|
|
96 |
#ifdef HAVE_HOTSWAP
|
|
|
97 |
extern void fat_lock(void);
|
|
|
98 |
extern void fat_unlock(void);
|
|
|
99 |
#endif
|
|
|
100 |
|
|
|
101 |
extern void fat_init(void);
|
|
|
102 |
extern int fat_mount(IF_MV2(int volume,) IF_MD2(int drive,) long startsector);
|
|
|
103 |
extern int fat_unmount(int volume, bool flush);
|
|
|
104 |
extern void fat_size(IF_MV2(int volume,) /* public for info */
|
|
|
105 |
unsigned long* size,
|
|
|
106 |
unsigned long* free);
|
|
|
107 |
extern void fat_recalc_free(IF_MV_NONVOID(int volume)); /* public for debug info screen */
|
|
|
108 |
extern int fat_create_dir(const char* name,
|
|
|
109 |
struct fat_dir* dir);
|
|
|
110 |
extern int fat_open(IF_MV2(int volume,)
|
|
|
111 |
long cluster,
|
|
|
112 |
struct fat_file* ent,
|
|
|
113 |
const struct fat_dir* dir);
|
|
|
114 |
extern int fat_create_file(const char* name,
|
|
|
115 |
struct fat_file* ent,
|
|
|
116 |
struct fat_dir* dir);
|
|
|
117 |
extern long fat_readwrite(struct fat_file *ent, long sectorcount,
|
|
|
118 |
void* buf, bool write );
|
|
|
119 |
extern int fat_closewrite(struct fat_file *ent, long size, int attr);
|
|
|
120 |
extern int fat_seek(struct fat_file *ent, unsigned long sector );
|
|
|
121 |
extern int fat_remove(struct fat_file *ent);
|
|
|
122 |
extern int fat_truncate(const struct fat_file *ent);
|
|
|
123 |
extern int fat_rename(struct fat_file* file,
|
|
|
124 |
struct fat_dir* dir,
|
|
|
125 |
const unsigned char* newname,
|
|
|
126 |
long size, int attr);
|
|
|
127 |
|
|
|
128 |
extern int fat_opendir(IF_MV2(int volume,)
|
|
|
129 |
struct fat_dir *ent, unsigned long startcluster,
|
|
|
130 |
const struct fat_dir *parent_dir);
|
|
|
131 |
extern int fat_getnext(struct fat_dir *ent, struct fat_direntry *entry);
|
|
|
132 |
extern unsigned int fat_get_cluster_size(IF_MV_NONVOID(int volume)); /* public for debug info screen */
|
|
|
133 |
extern bool fat_ismounted(int volume);
|
|
|
134 |
extern void* fat_get_sector_buffer(void);
|
|
|
135 |
extern void fat_release_sector_buffer(void);
|
| 489 |
theseven |
136 |
|
|
|
137 |
#endif
|
|
|
138 |
|
| 479 |
theseven |
139 |
extern void fat_enable_flushing(bool state);
|
| 211 |
theseven |
140 |
|
|
|
141 |
#endif
|