00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00033 #ifndef FAT_FAT_H_
00034 #define FAT_FAT_H_
00035
00036 #include "fat_fat.h"
00037 #include <fibril_synch.h>
00038 #include <libfs.h>
00039 #include <atomic.h>
00040 #include <sys/types.h>
00041 #include <bool.h>
00042 #include "../../vfs/vfs.h"
00043
00044 #ifndef dprintf
00045 #define dprintf(...) printf(__VA_ARGS__)
00046 #endif
00047
00048 #define min(a, b) ((a) < (b) ? (a) : (b))
00049
00050
00051
00052
00053 #define BPS(bs) uint16_t_le2host((bs)->bps)
00054 #define SPC(bs) (bs)->spc
00055 #define RSCNT(bs) uint16_t_le2host((bs)->rscnt)
00056 #define FATCNT(bs) (bs)->fatcnt
00057 #define SF(bs) uint16_t_le2host((bs)->sec_per_fat)
00058 #define RDE(bs) uint16_t_le2host((bs)->root_ent_max)
00059 #define TS(bs) (uint16_t_le2host((bs)->totsec16) != 0 ? \
00060 uint16_t_le2host((bs)->totsec16) : \
00061 uint32_t_le2host(bs->totsec32))
00062
00063 #define BS_BLOCK 0
00064 #define BS_SIZE 512
00065
00066 typedef struct fat_bs {
00067 uint8_t ji[3];
00068 uint8_t oem_name[8];
00069
00070 uint16_t bps;
00071 uint8_t spc;
00072 uint16_t rscnt;
00073 uint8_t fatcnt;
00074 uint16_t root_ent_max;
00076 uint16_t totsec16;
00077 uint8_t mdesc;
00078 uint16_t sec_per_fat;
00079 uint16_t sec_per_track;
00080 uint16_t headcnt;
00081 uint32_t hidden_sec;
00082 uint32_t totsec32;
00084 union {
00085 struct {
00086
00088 uint8_t pdn;
00089 uint8_t reserved;
00091 uint8_t ebs;
00093 uint32_t id;
00095 uint8_t label[11];
00097 uint8_t type[8];
00099 uint8_t boot_code[448];
00101 uint16_t signature;
00102 } __attribute__ ((packed));
00103 struct {
00104
00106 uint32_t sectors_per_fat;
00108 uint16_t flags;
00110 uint16_t version;
00112 uint32_t root_cluster;
00114 uint16_t fsinfo_sec;
00116 uint16_t bscopy_sec;
00117 uint8_t reserved1[12];
00119 uint8_t pdn;
00120 uint8_t reserved2;
00122 uint8_t ebs;
00124 uint32_t id;
00126 uint8_t label[11];
00128 uint8_t type[8];
00130 uint8_t boot_code[420];
00132 uint16_t signature;
00133 } fat32 __attribute__ ((packed));
00134 };
00135 } __attribute__ ((packed)) fat_bs_t;
00136
00137 typedef enum {
00138 FAT_INVALID,
00139 FAT_DIRECTORY,
00140 FAT_FILE
00141 } fat_node_type_t;
00142
00143 struct fat_node;
00144
00170 typedef struct {
00172 link_t uph_link;
00174 link_t uih_link;
00175
00176 fibril_mutex_t lock;
00177 devmap_handle_t devmap_handle;
00178 fs_index_t index;
00185 fat_cluster_t pfc;
00187 unsigned pdi;
00189 struct fat_node *nodep;
00190 } fat_idx_t;
00191
00193 typedef struct fat_node {
00195 fs_node_t *bp;
00196
00197 fibril_mutex_t lock;
00198 fat_node_type_t type;
00199 fat_idx_t *idx;
00205 fat_cluster_t firstc;
00207 link_t ffn_link;
00208 aoff64_t size;
00209 unsigned lnkcnt;
00210 unsigned refcnt;
00211 bool dirty;
00212
00213
00214
00215
00216
00217
00218 bool lastc_cached_valid;
00219 fat_cluster_t lastc_cached_value;
00220
00221 bool currc_cached_valid;
00222 aoff64_t currc_cached_bn;
00223 fat_cluster_t currc_cached_value;
00224 } fat_node_t;
00225
00226 extern fs_reg_t fat_reg;
00227
00228 extern void fat_mounted(ipc_callid_t, ipc_call_t *);
00229 extern void fat_mount(ipc_callid_t, ipc_call_t *);
00230 extern void fat_unmounted(ipc_callid_t, ipc_call_t *);
00231 extern void fat_unmount(ipc_callid_t, ipc_call_t *);
00232 extern void fat_lookup(ipc_callid_t, ipc_call_t *);
00233 extern void fat_read(ipc_callid_t, ipc_call_t *);
00234 extern void fat_write(ipc_callid_t, ipc_call_t *);
00235 extern void fat_truncate(ipc_callid_t, ipc_call_t *);
00236 extern void fat_stat(ipc_callid_t, ipc_call_t *);
00237 extern void fat_close(ipc_callid_t, ipc_call_t *);
00238 extern void fat_destroy(ipc_callid_t, ipc_call_t *);
00239 extern void fat_open_node(ipc_callid_t, ipc_call_t *);
00240 extern void fat_stat(ipc_callid_t, ipc_call_t *);
00241 extern void fat_sync(ipc_callid_t, ipc_call_t *);
00242
00243 extern int fat_idx_get_new(fat_idx_t **, devmap_handle_t);
00244 extern fat_idx_t *fat_idx_get_by_pos(devmap_handle_t, fat_cluster_t, unsigned);
00245 extern fat_idx_t *fat_idx_get_by_index(devmap_handle_t, fs_index_t);
00246 extern void fat_idx_destroy(fat_idx_t *);
00247 extern void fat_idx_hashin(fat_idx_t *);
00248 extern void fat_idx_hashout(fat_idx_t *);
00249
00250 extern int fat_idx_init(void);
00251 extern void fat_idx_fini(void);
00252 extern int fat_idx_init_by_devmap_handle(devmap_handle_t);
00253 extern void fat_idx_fini_by_devmap_handle(devmap_handle_t);
00254
00255 #endif
00256