Subversion Repositories freemyipod

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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