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