Do some crackdown on kernel object reinitialization after they could be in use and...
[Rockbox.git] / firmware / export / fat.h
blob3cf2923b783034c0a7157a4f7c820100800bec67
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 by Linus Nielsen Feltzing
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #ifndef FAT_H
21 #define FAT_H
23 #include <stdbool.h>
24 #include "ata.h" /* for volume definitions */
25 #include "config.h"
27 #define SECTOR_SIZE 512
29 /* Number of bytes reserved for a file name (including the trailing \0).
30 Since names are stored in the entry as UTF-8, we won't be able to
31 store all names allowed by FAT. In FAT, a name can have max 255
32 characters (not bytes!). Since the UTF-8 encoding of a char may take
33 up to 4 bytes, there will be names that we won't be able to store
34 completely. For such names, the short DOS name is used. */
35 #define FAT_FILENAME_BYTES 256
37 struct fat_direntry
39 unsigned char name[FAT_FILENAME_BYTES]; /* UTF-8 encoded name plus \0 */
40 unsigned short attr; /* Attributes */
41 unsigned char crttimetenth; /* Millisecond creation
42 time stamp (0-199) */
43 unsigned short crttime; /* Creation time */
44 unsigned short crtdate; /* Creation date */
45 unsigned short lstaccdate; /* Last access date */
46 unsigned short wrttime; /* Last write time */
47 unsigned short wrtdate; /* Last write date */
48 unsigned long filesize; /* File size in bytes */
49 long firstcluster; /* fstclusterhi<<16 + fstcluslo */
52 #define FAT_ATTR_READ_ONLY 0x01
53 #define FAT_ATTR_HIDDEN 0x02
54 #define FAT_ATTR_SYSTEM 0x04
55 #define FAT_ATTR_VOLUME_ID 0x08
56 #define FAT_ATTR_DIRECTORY 0x10
57 #define FAT_ATTR_ARCHIVE 0x20
58 #define FAT_ATTR_VOLUME 0x40 /* this is a volume, not a real directory */
60 struct fat_file
62 long firstcluster; /* first cluster in file */
63 long lastcluster; /* cluster of last access */
64 long lastsector; /* sector of last access */
65 long clusternum; /* current clusternum */
66 long sectornum; /* sector number in this cluster */
67 unsigned int direntry; /* short dir entry index from start of dir */
68 unsigned int direntries; /* number of dir entries used by this file */
69 long dircluster; /* first cluster of dir */
70 bool eof;
71 #ifdef HAVE_MULTIVOLUME
72 int volume; /* file resides on which volume */
73 #endif
76 struct fat_dir
78 unsigned int entry;
79 unsigned int entrycount;
80 long sector;
81 struct fat_file file;
82 unsigned char sectorcache[3][SECTOR_SIZE];
85 #ifdef HAVE_HOTSWAP
86 extern void fat_lock(void);
87 extern void fat_unlock(void);
88 #endif
90 extern void fat_init(void);
91 extern int fat_mount(IF_MV2(int volume,) IF_MV2(int drive,) long startsector);
92 extern int fat_unmount(int volume, bool flush);
93 extern void fat_size(IF_MV2(int volume,) /* public for info */
94 unsigned long* size,
95 unsigned long* free);
96 extern void fat_recalc_free(IF_MV_NONVOID(int volume)); /* public for debug info screen */
97 extern int fat_create_dir(const char* name,
98 struct fat_dir* newdir,
99 struct fat_dir* dir);
100 extern int fat_open(IF_MV2(int volume,)
101 long cluster,
102 struct fat_file* ent,
103 const struct fat_dir* dir);
104 extern int fat_create_file(const char* name,
105 struct fat_file* ent,
106 struct fat_dir* dir);
107 extern long fat_readwrite(struct fat_file *ent, long sectorcount,
108 void* buf, bool write );
109 extern int fat_closewrite(struct fat_file *ent, long size, int attr);
110 extern int fat_seek(struct fat_file *ent, unsigned long sector );
111 extern int fat_remove(struct fat_file *ent);
112 extern int fat_truncate(const struct fat_file *ent);
113 extern int fat_rename(struct fat_file* file,
114 struct fat_dir* dir,
115 const unsigned char* newname,
116 long size, int attr);
118 extern int fat_opendir(IF_MV2(int volume,)
119 struct fat_dir *ent, unsigned long currdir,
120 const struct fat_dir *parent_dir);
121 extern int fat_getnext(struct fat_dir *ent, struct fat_direntry *entry);
122 extern unsigned int fat_get_cluster_size(IF_MV_NONVOID(int volume)); /* public for debug info screen */
123 extern bool fat_ismounted(int volume);
125 #endif