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