annotate packages/fs/fat/current/src/fatfs_supp.c @ 2729:74dbf4c3f2e1 after-copyright-change-20090129

Update all copyright banners to reflect FSF ownership; fix and improve licence text.
author jlarmour
date Thu, 29 Jan 2009 17:47:46 +0000
parents 4f15eaebbf32
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1 //==========================================================================
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2 //
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
3 // fatfs_supp.c
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
4 //
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
5 // FAT file system support functions
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
6 //
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
7 //==========================================================================
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2533
diff changeset
8 // ####ECOSGPLCOPYRIGHTBEGIN####
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2533
diff changeset
9 // -------------------------------------------
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2533
diff changeset
10 // This file is part of eCos, the Embedded Configurable Operating System.
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2533
diff changeset
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
12 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2533
diff changeset
13 // eCos is free software; you can redistribute it and/or modify it under
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2533
diff changeset
14 // the terms of the GNU General Public License as published by the Free
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2533
diff changeset
15 // Software Foundation; either version 2 or (at your option) any later
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2533
diff changeset
16 // version.
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
17 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2533
diff changeset
18 // eCos is distributed in the hope that it will be useful, but WITHOUT
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2533
diff changeset
19 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2533
diff changeset
20 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2533
diff changeset
21 // for more details.
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
22 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2533
diff changeset
23 // You should have received a copy of the GNU General Public License
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2533
diff changeset
24 // along with eCos; if not, write to the Free Software Foundation, Inc.,
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2533
diff changeset
25 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
26 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2533
diff changeset
27 // As a special exception, if other files instantiate templates or use
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2533
diff changeset
28 // macros or inline functions from this file, or you compile this file
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2533
diff changeset
29 // and link it with other works to produce a work based on this file,
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2533
diff changeset
30 // this file does not by itself cause the resulting work to be covered by
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2533
diff changeset
31 // the GNU General Public License. However the source code for this file
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2533
diff changeset
32 // must still be made available in accordance with section (3) of the GNU
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2533
diff changeset
33 // General Public License v2.
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
34 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2533
diff changeset
35 // This exception does not invalidate any other reasons why a work based
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2533
diff changeset
36 // on this file might be covered by the GNU General Public License.
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2533
diff changeset
37 // -------------------------------------------
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2533
diff changeset
38 // ####ECOSGPLCOPYRIGHTEND####
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
39 //==========================================================================
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
40 //#####DESCRIPTIONBEGIN####
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
41 //
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
42 // Author(s): Savin Zlobec <savin@elatec.si>
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
43 // Date: 2003-06-30
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
44 //
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
45 //####DESCRIPTIONEND####
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
46 //
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
47 //==========================================================================
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
48
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
49 #include <pkgconf/fs_fat.h>
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
50 #include <pkgconf/infra.h>
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
51
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
52 #include <cyg/infra/cyg_type.h>
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
53 #include <cyg/infra/cyg_ass.h>
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
54 #include <cyg/infra/cyg_trac.h>
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
55 #include <cyg/infra/diag.h>
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
56 #include <cyg/io/io.h>
1818
5663e2763ba6 * src/fatfs.c:
asl
parents: 1784
diff changeset
57 #include <cyg/fs/fatfs.h>
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
58 #include <blib/blib.h>
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
59
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
60 #include <sys/types.h>
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
61 #include <ctype.h>
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
62
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
63 #include "fatfs.h"
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
64
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
65 //==========================================================================
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
66 // FAT defines & macros
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
67
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
68 // -------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
69 // FAT dir entry attributes macros
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
70
1818
5663e2763ba6 * src/fatfs.c:
asl
parents: 1784
diff changeset
71 #define DENTRY_IS_RDONLY(_dentry_) (S_FATFS_ISRDONLY((_dentry_)->attr))
5663e2763ba6 * src/fatfs.c:
asl
parents: 1784
diff changeset
72 #define DENTRY_IS_HIDDEN(_dentry_) (S_FATFS_ISHIDDEN((_dentry_)->attr))
5663e2763ba6 * src/fatfs.c:
asl
parents: 1784
diff changeset
73 #define DENTRY_IS_SYSTEM(_dentry_) (S_FATFS_ISSYSTEM((_dentry_)->attr))
5663e2763ba6 * src/fatfs.c:
asl
parents: 1784
diff changeset
74 #define DENTRY_IS_VOLUME(_dentry_) (S_FATFS_ISVOLUME((_dentry_)->attr))
5663e2763ba6 * src/fatfs.c:
asl
parents: 1784
diff changeset
75 #define DENTRY_IS_DIR(_dentry_) (S_FATFS_ISDIR((_dentry_)->attr))
5663e2763ba6 * src/fatfs.c:
asl
parents: 1784
diff changeset
76 #define DENTRY_IS_ARCHIVE(_dentry_) (S_FATFS_ISARCHIVE((_dentry_)->attr))
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
77
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
78 #define DENTRY_IS_DELETED(_dentry_) \
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
79 (0xE5 == (cyg_uint8)((_dentry_)->name[0]))
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
80
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
81 #define DENTRY_IS_ZERO(_dentry_) \
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
82 (0x00 == (cyg_uint8)((_dentry_)->name[0]))
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
83
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
84 // -------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
85 // FAT disk data access macros
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
86
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
87 // FIXME: support big endian machines!
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
88
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
89 #define GET_BYTE(_data_, _var_, _off_) \
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
90 (_var_ = *( ((cyg_uint8 *)_data_) + (_off_) ) )
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
91
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
92 #define GET_WORD(_data_, _var_, _off_) \
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
93 (_var_ = *( ((cyg_uint8 *)_data_) + (_off_) ) | \
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
94 *( ((cyg_uint8 *)_data_) + (_off_) + 1 ) << 8)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
95
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
96 #define GET_DWORD(_data_, _var_, _off_) \
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
97 (_var_ = *( ((cyg_uint8 *)_data_) + (_off_)) | \
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
98 *( ((cyg_uint8 *)_data_) + (_off_) + 1 ) << 8 | \
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
99 *( ((cyg_uint8 *)_data_) + (_off_) + 2 ) << 16 | \
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
100 *( ((cyg_uint8 *)_data_) + (_off_) + 3 ) << 24)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
101
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
102 #define GET_BYTES(_data_, _var_, _size_, _off_) \
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
103 memcpy((void *)(_var_), (void*)(((cyg_uint8 *)_data_)+(_off_)),_size_)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
104
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
105 #define SET_BYTE(_data_, _val_, _off_) \
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
106 (*( ((cyg_uint8 *)_data_) + (_off_) ) = _val_)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
107
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
108 #define SET_WORD(_data_, _val_, _off_) \
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
109 do { \
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
110 *( ((cyg_uint8 *)_data_) + (_off_) ) = _val_ & 0xFF; \
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
111 *( ((cyg_uint8 *)_data_) + (_off_) + 1 ) = (_val_ >> 8) & 0xFF; \
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
112 } while (0)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
113
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
114 #define SET_DWORD(_data_, _val_, _off_) \
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
115 do { \
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
116 *( ((cyg_uint8 *)_data_) + (_off_) ) = _val_ & 0xFF; \
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
117 *( ((cyg_uint8 *)_data_) + (_off_) + 1 ) = (_val_ >> 8) & 0xFF; \
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
118 *( ((cyg_uint8 *)_data_) + (_off_) + 2 ) = (_val_ >> 16) & 0xFF; \
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
119 *( ((cyg_uint8 *)_data_) + (_off_) + 3 ) = (_val_ >> 24) & 0xFF; \
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
120 } while (0)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
121
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
122 #define SET_BYTES(_data_, _var_, _size_, _off_) \
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
123 memcpy((void *)(((cyg_uint8 *)_data_)+(_off_)), (void *)(_var_), _size_)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
124
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
125 // -------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
126 // FAT table entries types
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
127
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
128 #define TENTRY_REGULAR 0 // Used when entry points to next file cluster
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
129 #define TENTRY_FREE 1 // Free cluster
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
130 #define TENTRY_LAST 2 // Last cluster of file
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
131 #define TENTRY_RESERVED 3 // Reserved cluster
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
132 #define TENTRY_BAD 4 // Bad cluster
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
133
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
134 // -------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
135 // FAT table structures size
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
136
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
137 #define DENTRY_SIZE 0x20 // Dir entry size
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
138
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
139 // -------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
140 // Time & date defines
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
141
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
142 #define JD_1_JAN_1970 2440588 // 1 Jan 1970 in Julian day number
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
143
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
144 // -------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
145 // Code tracing defines
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
146
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
147 #ifdef FATFS_TRACE_DIR_ENTRY
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
148 # define TDE 1
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
149 #else
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
150 # define TDE 0
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
151 #endif
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
152
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
153 #ifdef FATFS_TRACE_CLUSTER
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
154 # define TCL 1
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
155 #else
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
156 # define TCL 0
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
157 #endif
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
158
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
159 #ifdef FATFS_TRACE_DATA
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
160 # define TDO 1
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
161 #else
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
162 # define TDO 0
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
163 #endif
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
164
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
165 //==========================================================================
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
166 // FAT structures
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
167
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
168 // -------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
169 // FAT table boot record structure
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
170
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
171 typedef struct fat_boot_record_s
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
172 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
173 cyg_uint16 jump; // 00h : Jump code
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
174 // cyg_uint8 jump0; // + NOP
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
175 char oem_name[8+1]; // 03h : OEM name
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
176 cyg_uint16 bytes_per_sec; // 0Bh : cyg_bytes per sector
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
177 cyg_uint8 sec_per_clu; // 0Dh : Sectors per cluster
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
178 cyg_uint16 res_sec_num; // 0Eh : Number of reserved sectors
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
179 cyg_uint8 fat_tbls_num; // 10h : Number of copies of fat
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
180 cyg_uint16 max_root_dents; // 11h : Maximum number of root dir entries
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
181 cyg_uint16 sec_num_32; // 13h : Number of sectors in partition < 32MB
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
182 cyg_uint8 media_desc; // 15h : Media descriptor
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
183 cyg_uint16 sec_per_fat; // 16h : Sectors per FAT
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
184 cyg_uint16 sec_per_track; // 18h : Sectors per track
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
185 cyg_uint16 heads_num; // 1Ah : Number of heads
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
186 cyg_uint32 hsec_num; // 1Ch : Number of hidden sectors
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
187 cyg_uint32 sec_num; // 20h : Number of sectors in partition
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
188 cyg_uint8 exe_marker[2]; // 1FEh: Executable marker (55h AAh)
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
189
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
190 // FAT32 specific fields
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
191
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
192 cyg_uint32 sec_per_fat_32; // 24h : Sectors per FAT
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
193 cyg_uint16 ext_flags; // 28h : Flags
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
194 cyg_uint16 fs_ver; // 2Ah : FS version
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
195 cyg_uint32 root_cluster; // 2Ch : Root dir cluster
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
196 cyg_uint16 fs_info_sec; // 30h : Sector number of FSINFO structure
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
197 cyg_uint16 bk_boot_sec; // 32h : Sector number of backup boot record
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
198 // cyg_uint8 reserved[12]; // 34h : Reserved
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
199
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
200 // Fields with different locations on FAT12/16 and FAT32
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
201
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
202 cyg_uint8 drv_num; // 24h (40h) : Drive number of partition
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
203 // cyg_uint8 reserved1; // 25h (41h) : Reserved 1
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
204 cyg_uint8 ext_sig; // 26h (42h) : Extended signature
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
205 cyg_uint32 ser_num; // 27h (43h) : Serial number of partition
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
206 char vol_name[11+1]; // 2Bh (47h) : Volume name of partition
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
207 char fat_name[8+1]; // 36h (52h) : FAT name
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
208
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
209 } fat_boot_record_t;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
210
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
211 // -------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
212 // FAT dir entry structure
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
213
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
214 typedef struct fat_raw_dir_entry_s
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
215 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
216 char name[8+1]; // 00h : Name
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
217 char ext[3+1]; // 08h : Extension
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
218 cyg_uint8 attr; // 0Bh : Attribute
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
219 cyg_uint8 nt_reserved; // 0Ch : Win NT Reserved field
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
220 cyg_uint8 crt_sec_100; // 0Dh : Creation time ms stamp 0 - 199
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
221 cyg_uint16 crt_time; // 0Eh : Creation time
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
222 cyg_uint16 crt_date; // 10h : Creation date
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
223 cyg_uint16 acc_date; // 12h : Last access date
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
224 cyg_uint16 cluster_HI; // 14h : Starting cluster HI WORD (FAT32)
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
225 cyg_uint16 wrt_time; // 16h : Time
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
226 cyg_uint16 wrt_date; // 18h : Date
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
227 cyg_uint16 cluster; // 1Ah : Starting cluster
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
228 cyg_uint32 size; // 1Ch : Size of the file
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
229 } fat_raw_dir_entry_t;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
230
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
231 // -------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
232 // FAT cluster opts
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
233
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
234 typedef enum cluster_opts_e
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
235 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
236 CO_NONE = 0x00, // NULL option
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
237 CO_EXTEND = 0x01, // Extend cluster chain if one cluster too short
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
238 CO_ERASE_NEW = 0x02, // Erase newly allocated cluster
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
239 CO_MARK_LAST = 0x04 // Mark newly allocated cluster as last
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
240 } cluster_opts_t;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
241
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
242 //==========================================================================
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
243 // Utility functions
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
244
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
245 // -------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
246 // get_val_log2()
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
247 // Gets the log2 of given value or returns 0 if value is not a power of 2.
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
248
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
249 static cyg_uint32
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
250 get_val_log2(cyg_uint32 val)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
251 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
252 cyg_uint32 i, log2;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
253
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
254 i = val;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
255 log2 = 0;
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
256
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
257 while (0 == (i & 1))
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
258 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
259 i >>= 1;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
260 log2++;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
261 }
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
262
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
263 if (i != 1) return 0;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
264 else return log2;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
265 }
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
266
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
267 // -------------------------------------------------------------------------
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
268 // cluster_to_block_pos()
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
269 // Converts cluster position to blib block position.
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
270
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
271 static void
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
272 cluster_to_block_pos(fatfs_disk_t *disk,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
273 cyg_uint32 cluster,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
274 cyg_uint32 cluster_pos,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
275 cyg_uint32 *block,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
276 cyg_uint32 *block_pos)
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
277 {
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
278 cyg_uint32 block_size = cyg_blib_get_block_size(&disk->blib);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
279 cyg_uint32 block_size_log2 = cyg_blib_get_block_size_log2(&disk->blib);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
280
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
281 *block = (cluster - 2) << (disk->cluster_size_log2 - block_size_log2);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
282
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
283 *block_pos = disk->fat_data_pos + cluster_pos;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
284
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
285 if (*block_pos > block_size)
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
286 {
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
287 *block += *block_pos >> block_size_log2;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
288 *block_pos = *block_pos & (block_size - 1);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
289 }
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
290 }
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
291
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
292 // -------------------------------------------------------------------------
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
293 // disk_write()
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
294 // Writes data to disk.
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
295
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
296 static __inline__ int
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
297 disk_write(fatfs_disk_t *disk,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
298 void *buf,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
299 cyg_uint32 *len,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
300 cyg_uint32 pos)
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
301 {
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
302 return cyg_blib_write(&disk->blib, buf, len, 0, pos);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
303 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
304
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
305 // -------------------------------------------------------------------------
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
306 // disk_read()
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
307 // Reads data from disk.
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
308
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
309 static __inline__ int
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
310 disk_read(fatfs_disk_t *disk,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
311 void *buf,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
312 cyg_uint32 *len,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
313 cyg_uint32 pos)
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
314 {
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
315 return cyg_blib_read(&disk->blib, buf, len, 0, pos);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
316 }
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
317
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
318 // -------------------------------------------------------------------------
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
319 // disk_cluster_write()
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
320 // Writes data to disk at specified cluster position.
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
321
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
322 static __inline__ int
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
323 disk_cluster_write(fatfs_disk_t *disk,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
324 void *buf,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
325 cyg_uint32 *len,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
326 cyg_uint32 cluster,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
327 cyg_uint32 cluster_pos)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
328 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
329 cyg_uint32 block, block_pos;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
330
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
331 cluster_to_block_pos(disk, cluster, cluster_pos, &block, &block_pos);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
332
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
333 return cyg_blib_write(&disk->blib, buf, len, block, block_pos);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
334 }
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
335
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
336 // -------------------------------------------------------------------------
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
337 // disk_cluster_read()
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
338 // Reads data from disk at specified cluster position.
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
339
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
340 static __inline__ int
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
341 disk_cluster_read(fatfs_disk_t *disk,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
342 void *buf,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
343 cyg_uint32 *len,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
344 cyg_uint32 cluster,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
345 cyg_uint32 cluster_pos)
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
346 {
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
347 cyg_uint32 block, block_pos;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
348
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
349 cluster_to_block_pos(disk, cluster, cluster_pos, &block, &block_pos);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
350
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
351 return cyg_blib_read(&disk->blib, buf, len, block, block_pos);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
352 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
353
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
354 // -------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
355 // jdays_to_gdate()
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
356 // Converts juilan days into gregorian date.
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
357
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
358 static void
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
359 jdays_to_gdate(cyg_uint32 jd, int *day, int *month, int *year)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
360 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
361 cyg_uint32 l, n, i, j;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
362
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
363 l = jd + 68569;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
364 n = (4 * l) / 146097;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
365 l = l - (146097 * n + 3) / 4;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
366 i = (4000 * (l + 1)) / 1461001;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
367 l = l - (1461 * i) / 4 + 31;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
368 j = (80 * l) / 2447;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
369 *day = l - (2447 * j) / 80;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
370
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
371 l = j / 11;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
372 *month = j + 2 - (12 * l);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
373 *year = 100 * (n - 49) + i + l;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
374 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
375
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
376 // -------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
377 // gdate_to_jdays()
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
378 // Converts gregorian date to juilan days.
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
379
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
380 static void
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
381 gdate_to_jdays(int day, int month, int year, cyg_uint32 *jd)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
382 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
383 *jd = day - 32075 + 1461*(year + 4800 + (month - 14)/12)/4 +
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
384 367*(month - 2 - (month - 14)/12*12)/12 -
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
385 3*((year + 4900 + (month - 14)/12)/100)/4;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
386 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
387
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
388 // -------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
389 // date_unix2dos()
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
390 // Converts unix timestamp to dos time and date.
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
391
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
392 static void
2044
6f4928fc3037 * src/fatfs_supp.c: Correct types to remove compiler warnings.
asl
parents: 1975
diff changeset
393 date_unix2dos(time_t unix_timestamp,
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
394 cyg_uint16 *dos_time,
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
395 cyg_uint16 *dos_date)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
396 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
397 cyg_uint32 jd;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
398 cyg_uint16 dtime, ddate;
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
399 int hour, min, sec;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
400 int day, month, year;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
401
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
402 hour = (unix_timestamp / 3600) % 24;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
403 min = (unix_timestamp / 60) % 60;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
404 sec = unix_timestamp % 60;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
405
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
406 jd = JD_1_JAN_1970 + unix_timestamp / (3600 * 24);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
407 jdays_to_gdate(jd, &day, &month, &year);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
408
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
409 CYG_TRACE7(TDE, "timestamp=%d date=%d:%d:%d %d-%d-%d",
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
410 unix_timestamp, hour, min, sec, year, month, day);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
411
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
412 if (year < 1980)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
413 year = 1980;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
414
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
415 dtime = (hour << 11) | (min << 5) | (sec >> 1);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
416 ddate = ((year - 1980) << 9) | (month << 5) | day;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
417
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
418 CYG_TRACE2(TDE, "dos time=%d date=%d", dtime, ddate);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
419
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
420 if (NULL != dos_time) *dos_time = dtime;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
421 if (NULL != dos_date) *dos_date = ddate;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
422 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
423
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
424 // -------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
425 // date_dos2unix()
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
426 // Converts dos time and date to unix timestamp.
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
427
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
428 static void
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
429 date_dos2unix(cyg_uint16 dos_time,
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
430 cyg_uint16 dos_date,
2044
6f4928fc3037 * src/fatfs_supp.c: Correct types to remove compiler warnings.
asl
parents: 1975
diff changeset
431 time_t *unix_timestamp)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
432 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
433 cyg_uint32 ts;
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
434 int hour, min, sec;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
435 int day, month, year;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
436
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
437 sec = (dos_time & ((1<<5)-1)) * 2;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
438 dos_time >>= 5;
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
439 min = (dos_time & ((1<<6)-1));
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
440 dos_time >>= 6;
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
441 hour = dos_time;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
442
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
443 day = (dos_date & ((1<<5)-1));
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
444 dos_date >>= 5;
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
445 month = (dos_date & ((1<<4)-1));
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
446 dos_date >>= 4;
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
447 year = dos_date + 1980;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
448
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
449 gdate_to_jdays(day, month, year, &ts);
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
450
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
451 ts -= JD_1_JAN_1970;
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
452 ts = (ts * 24 * 3600) + (sec + min * 60 + hour * 3600);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
453
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
454 *unix_timestamp = ts;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
455
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
456 CYG_TRACE2(TDE, "dos time=%d date=%d", dos_time, dos_date);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
457 CYG_TRACE7(TDE, "timestamp=%d date=%d:%d:%d %d-%d-%d",
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
458 ts, hour, min, sec, year, month, day);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
459 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
460
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
461 //==========================================================================
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
462 // FAT boot record functions
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
463
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
464 #if TDE
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
465
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
466 // -------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
467 // print_boot_record()
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
468 // Prints FAT boot record.
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
469
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
470 static void
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
471 print_boot_record(fat_boot_record_t* fbr)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
472 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
473 diag_printf("FAT: FBR jump code: 0x%02X\n", fbr->jump);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
474 diag_printf("FAT: FBR oem name: '%.8s'\n", fbr->oem_name);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
475 diag_printf("FAT: FBR bytes per sec: %u\n", fbr->bytes_per_sec);
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
476 diag_printf("FAT: FBR sec per cluster: %u\n", fbr->sec_per_clu);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
477 diag_printf("FAT: FBR reserved sec: %u\n", fbr->res_sec_num);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
478 diag_printf("FAT: FBR fat tbls num: %u\n", fbr->fat_tbls_num);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
479 diag_printf("FAT: FBR max root dents: %u\n", fbr->max_root_dents);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
480 diag_printf("FAT: FBR sec num (32): %u\n", fbr->sec_num_32);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
481 diag_printf("FAT: FBR media desc: 0x%02X\n", fbr->media_desc);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
482 diag_printf("FAT: FBR sec per fat: %u\n", fbr->sec_per_fat);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
483 diag_printf("FAT: FBR sec per track: %u\n", fbr->sec_per_track);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
484 diag_printf("FAT: FBR heads num: %u\n", fbr->heads_num);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
485 diag_printf("FAT: FBR hidden sec num: %u\n", fbr->hsec_num);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
486 diag_printf("FAT: FBR sec num: %u\n", fbr->sec_num);
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
487
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
488 if (0 == fbr->sec_per_fat)
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
489 {
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
490 diag_printf("FAT: FBR sec per fat32: %u\n", fbr->sec_per_fat_32);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
491 diag_printf("FAT: FBR ext flags: 0x%04X\n", fbr->ext_flags);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
492 diag_printf("FAT: FBR fs ver: %u\n", fbr->fs_ver);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
493 diag_printf("FAT: FBR root cluster: %u\n", fbr->root_cluster);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
494 diag_printf("FAT: FBR fs info sec: %u\n", fbr->fs_info_sec);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
495 }
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
496
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
497 diag_printf("FAT: FBR drv num: %u\n", fbr->drv_num);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
498 diag_printf("FAT: FBR ext sig: 0x%02X\n", fbr->ext_sig);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
499 diag_printf("FAT: FBR ser num: 0x%08X\n", fbr->ser_num);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
500 diag_printf("FAT: FBR vol name: '%.11s'\n", fbr->vol_name);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
501 diag_printf("FAT: FBR fat name: '%.8s'\n", fbr->fat_name);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
502 diag_printf("FAT: FBR exe mark: 0x%02X 0x%02X\n",
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
503 fbr->exe_marker[0], fbr->exe_marker[1]);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
504 }
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
505
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
506 #endif // TDE
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
507
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
508 // -------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
509 // read_boot_record()
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
510 // Reads FAT boot record from disk.
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
511
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
512 static int
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
513 read_boot_record(fatfs_disk_t *disk, fat_boot_record_t *fbr)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
514 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
515 cyg_uint8 data[0x5A];
2044
6f4928fc3037 * src/fatfs_supp.c: Correct types to remove compiler warnings.
asl
parents: 1975
diff changeset
516 cyg_uint32 len;
6f4928fc3037 * src/fatfs_supp.c: Correct types to remove compiler warnings.
asl
parents: 1975
diff changeset
517 int err;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
518
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
519 len = 0x5A;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
520 err = disk_read(disk, (void*)data, &len, 0);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
521 if (err != ENOERR)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
522 return err;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
523
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
524 GET_WORD(data, fbr->jump, 0x00);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
525 GET_BYTES(data, fbr->oem_name, 8, 0x03);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
526 GET_WORD(data, fbr->bytes_per_sec, 0x0B);
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
527 GET_BYTE(data, fbr->sec_per_clu, 0x0D);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
528 GET_WORD(data, fbr->res_sec_num, 0x0E);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
529 GET_BYTE(data, fbr->fat_tbls_num, 0x10);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
530 GET_WORD(data, fbr->max_root_dents, 0x11);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
531 GET_WORD(data, fbr->sec_num_32, 0x13);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
532 GET_BYTE(data, fbr->media_desc, 0x15);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
533 GET_WORD(data, fbr->sec_per_fat, 0x16);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
534 GET_WORD(data, fbr->sec_per_track, 0x18);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
535 GET_WORD(data, fbr->heads_num, 0x1A);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
536 GET_DWORD(data, fbr->hsec_num, 0x1C);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
537 GET_DWORD(data, fbr->sec_num, 0x20);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
538
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
539 // This is a quick check for FAT12/16 or FAT32 boot record.
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
540 // The sec_per_fat field must be 0 on FAT32, since this
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
541 // field plays a crucial role in detection of the FAT type
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
542 // (12,16,32) it is quite safe to make this assumption.
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
543 if (0 == fbr->sec_per_fat)
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
544 {
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
545 GET_DWORD(data, fbr->sec_per_fat_32, 0x24);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
546 GET_WORD(data, fbr->ext_flags, 0x28);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
547 GET_WORD(data, fbr->fs_ver, 0x2A);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
548 GET_DWORD(data, fbr->root_cluster, 0x2C);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
549 GET_WORD(data, fbr->fs_info_sec, 0x30);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
550 GET_WORD(data, fbr->bk_boot_sec, 0x32);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
551 GET_BYTE(data, fbr->drv_num, 0x40);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
552 GET_BYTE(data, fbr->ext_sig, 0x42);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
553 GET_DWORD(data, fbr->ser_num, 0x43);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
554 GET_BYTES(data, fbr->vol_name, 11, 0x47);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
555 GET_BYTES(data, fbr->fat_name, 8, 0x52);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
556 }
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
557 else
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
558 {
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
559 GET_BYTE(data, fbr->drv_num, 0x24);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
560 GET_BYTE(data, fbr->ext_sig, 0x26);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
561 GET_DWORD(data, fbr->ser_num, 0x27);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
562 GET_BYTES(data, fbr->vol_name, 11, 0x2B);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
563 GET_BYTES(data, fbr->fat_name, 8, 0x36);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
564 }
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
565
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
566 // Read the end marker
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
567 len = 0x02;
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
568 err = disk_read(disk, (void*)data, &len, 0x1FE);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
569 if (err != ENOERR)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
570 return err;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
571
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
572 GET_BYTES(data, fbr->exe_marker, 2, 0);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
573
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
574 // Zero terminate strings
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
575 fbr->oem_name[8] = '\0';
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
576 fbr->vol_name[11] = '\0';
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
577 fbr->fat_name[8] = '\0';
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
578
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
579 #if TDE
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
580 print_boot_record(fbr);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
581 #endif
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
582
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
583 return ENOERR;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
584 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
585
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
586 //==========================================================================
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
587 // FAT table entry functions
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
588
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
589 // -------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
590 // read_tentry()
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
591 // Reads FAT table entry from disk.
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
592
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
593 static int
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
594 read_tentry(fatfs_disk_t *disk, cyg_uint32 num, cyg_uint32 *entry)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
595 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
596 cyg_uint8 data[4];
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
597 cyg_uint32 pos, num3;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
598 cyg_uint32 e;
2044
6f4928fc3037 * src/fatfs_supp.c: Correct types to remove compiler warnings.
asl
parents: 1975
diff changeset
599 cyg_uint32 len;
6f4928fc3037 * src/fatfs_supp.c: Correct types to remove compiler warnings.
asl
parents: 1975
diff changeset
600 int err;
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
601
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
602 switch (disk->fat_type)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
603 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
604 case FATFS_FAT12:
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
605 num3 = num * 3;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
606 pos = disk->fat_tbl_pos + (num3 >> 1);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
607 len = 2;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
608
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
609 err = disk_read(disk, (void*)data, &len, pos);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
610 if (err != ENOERR)
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
611 return err;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
612
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
613 GET_WORD(data, e, 0x00);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
614
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
615 if (0 == (num3 & 1)) *entry = e & 0x0FFF;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
616 else *entry = (e >> 4) & 0x0FFF;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
617
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
618 break;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
619
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
620 case FATFS_FAT16:
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
621 pos = disk->fat_tbl_pos + (num << 1);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
622 len = 2;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
623
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
624 err = disk_read(disk, (void*)data, &len, pos);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
625 if (err != ENOERR)
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
626 return err;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
627
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
628 GET_WORD(data, e, 0x00);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
629 *entry = e;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
630
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
631 break;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
632
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
633 case FATFS_FAT32:
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
634 pos = disk->fat_tbl_pos + (num << 2);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
635 len = 4;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
636
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
637 err = disk_read(disk, (void*)data, &len, pos);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
638 if (err != ENOERR)
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
639 return err;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
640
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
641 GET_DWORD(data, e, 0x00);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
642 *entry = e & 0x0FFFFFFF;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
643
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
644 break;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
645
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
646 default:
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
647 CYG_ASSERT(false, "Unknown FAT type");
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
648 }
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
649 return ENOERR;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
650 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
651
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
652 // -------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
653 // write_tentry()
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
654 // Writes FAT table entry to disk (to all copies of FAT).
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
655
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
656 static int
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
657 write_tentry(fatfs_disk_t *disk, cyg_uint32 num, cyg_uint32 *entry)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
658 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
659 cyg_uint8 data[4];
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
660 cyg_uint32 pos=0, num3;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
661 cyg_uint32 e;
2044
6f4928fc3037 * src/fatfs_supp.c: Correct types to remove compiler warnings.
asl
parents: 1975
diff changeset
662 cyg_uint32 len;
6f4928fc3037 * src/fatfs_supp.c: Correct types to remove compiler warnings.
asl
parents: 1975
diff changeset
663 int i;
6f4928fc3037 * src/fatfs_supp.c: Correct types to remove compiler warnings.
asl
parents: 1975
diff changeset
664 int err;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
665
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
666 switch (disk->fat_type)
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
667 {
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
668 case FATFS_FAT12:
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
669 num3 = num * 3;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
670 pos = disk->fat_tbl_pos + (num3 >> 1);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
671 len = 2;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
672
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
673 err = disk_read(disk, (void*)data, &len, pos);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
674 if (err != ENOERR)
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
675 return err;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
676
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
677 GET_WORD(data, e, 0x00);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
678
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
679 if (0 == (num3 & 1)) e = (e & 0xF000) | (*entry & 0x0FFF);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
680 else e = (e & 0x000F) | ((*entry & 0x0FFF) << 4);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
681
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
682 SET_WORD(data, e, 0x00);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
683
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
684 break;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
685
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
686 case FATFS_FAT16:
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
687 pos = disk->fat_tbl_pos + (num << 1);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
688 len = 2;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
689
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
690 e = *entry;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
691 SET_WORD(data, e, 0x00);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
692
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
693 break;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
694
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
695 case FATFS_FAT32:
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
696 pos = disk->fat_tbl_pos + (num << 2);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
697 len = 4;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
698
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
699 err = disk_read(disk, (void*)data, &len, pos);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
700 if (err != ENOERR)
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
701 return err;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
702
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
703 GET_DWORD(data, e, 0x00);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
704
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
705 e = (e & 0xF0000000) | *entry;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
706
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
707 SET_DWORD(data, e, 0x00);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
708
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
709 break;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
710
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
711 default:
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
712 CYG_ASSERT(false, "Unknown FAT type");
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
713 }
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
714
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
715 for (i = 0; i < disk->fat_tbls_num; i++)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
716 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
717 err = disk_write(disk, (void*)data, &len, pos);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
718 if (err != ENOERR)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
719 return err;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
720
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
721 pos += disk->fat_tbl_size;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
722 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
723
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
724 return ENOERR;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
725 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
726
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
727 // -------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
728 // get_tentry_type()
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
729 // Gets the type of FAT table entry.
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
730
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
731 static int
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
732 get_tentry_type(fatfs_disk_t *disk, cyg_uint32 entry)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
733 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
734 int type;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
735
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
736 switch (disk->fat_type)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
737 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
738 case FATFS_FAT12:
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
739 if (entry < 0x0FF0)
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
740 {
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
741 if (0x0000 == entry) type = TENTRY_FREE;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
742 else type = TENTRY_REGULAR;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
743 }
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
744 else if (entry >= 0x0FF8) type = TENTRY_LAST;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
745 else if (0x0FF7 == entry) type = TENTRY_BAD;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
746 else type = TENTRY_RESERVED;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
747
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
748 break;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
749
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
750 case FATFS_FAT16:
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
751 if (entry < 0xFFF0)
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
752 {
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
753 if (0x0000 == entry) type = TENTRY_FREE;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
754 else type = TENTRY_REGULAR;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
755 }
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
756 else if (entry >= 0xFFF8) type = TENTRY_LAST;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
757 else if (0xFFF7 == entry) type = TENTRY_BAD;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
758 else type = TENTRY_RESERVED;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
759
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
760 break;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
761
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
762 case FATFS_FAT32:
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
763
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
764 if (entry < 0x0FFFFFF0)
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
765 {
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
766 if (0x00000000 == entry) type = TENTRY_FREE;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
767 else type = TENTRY_REGULAR;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
768 }
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
769 else if (entry >= 0x0FFFFFF8) type = TENTRY_LAST;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
770 else if (0x0FFFFFF7 == entry) type = TENTRY_BAD;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
771 else type = TENTRY_RESERVED;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
772
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
773 break;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
774
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
775 default:
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
776 CYG_ASSERT(false, "Unknown FAT type");
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
777 type = TENTRY_BAD; // least likely to cause damage
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
778 }
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
779 return type;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
780 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
781
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
782 // -------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
783 // set_tentry_type()
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
784 // Sets the type of FAT table entry.
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
785
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
786 static void
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
787 set_tentry_type(fatfs_disk_t *disk, cyg_uint32 *entry, cyg_uint32 type)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
788 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
789 switch (disk->fat_type)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
790 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
791 case FATFS_FAT12:
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
792 switch (type)
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
793 {
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
794 case TENTRY_FREE: *entry = 0x0000; return;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
795 case TENTRY_LAST: *entry = 0x0FF8; return;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
796 case TENTRY_RESERVED: *entry = 0x0FF0; return;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
797 case TENTRY_BAD: *entry = 0x0FF7; return;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
798 default:
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
799 CYG_ASSERT(false, "Unknown tentry type");
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
800 }
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
801 break;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
802
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
803 case FATFS_FAT16:
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
804 switch (type)
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
805 {
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
806 case TENTRY_FREE: *entry = 0x0000; return;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
807 case TENTRY_LAST: *entry = 0xFFF8; return;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
808 case TENTRY_RESERVED: *entry = 0xFFF0; return;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
809 case TENTRY_BAD: *entry = 0xFFF7; return;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
810 default:
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
811 CYG_ASSERT(false, "Unknown tentry type");
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
812 }
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
813 break;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
814
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
815 case FATFS_FAT32:
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
816 switch (type)
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
817 {
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
818 case TENTRY_FREE: *entry = 0x00000000; return;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
819 case TENTRY_LAST: *entry = 0x0FFFFFF8; return;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
820 case TENTRY_RESERVED: *entry = 0x0FFFFFF0; return;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
821 case TENTRY_BAD: *entry = 0x0FFFFFF7; return;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
822 default:
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
823 CYG_ASSERT(false, "Unknown tentry type");
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
824 }
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
825 break;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
826
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
827 default:
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
828 CYG_ASSERT(false, "Unknown FAT type");
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
829 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
830 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
831
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
832 // -------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
833 // get_tentry_next_cluster()
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
834 // Gets the the next file cluster number from FAT table entry.
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
835
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
836 static __inline__ cyg_uint32
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
837 get_tentry_next_cluster(fatfs_disk_t *disk, cyg_uint32 entry)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
838 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
839 return entry;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
840 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
841
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
842 // -------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
843 // set_tentry_next_cluster()
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
844 // Sets the the next cluster number to FAT table entry.
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
845
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
846 static __inline__ void
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
847 set_tentry_next_cluster(fatfs_disk_t *disk,
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
848 cyg_uint32 *entry,
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
849 cyg_uint32 next_cluster)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
850 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
851 *entry = next_cluster;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
852 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
853
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
854 //==========================================================================
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
855 // FAT cluster functions
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
856
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
857 // -------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
858 // erase_cluster()
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
859 // Erases cluster (fills with 0x00).
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
860
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
861 static int
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
862 erase_cluster(fatfs_disk_t *disk, cyg_uint32 cluster)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
863 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
864 cyg_uint8 data[32];
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
865 cyg_uint32 pos;
2044
6f4928fc3037 * src/fatfs_supp.c: Correct types to remove compiler warnings.
asl
parents: 1975
diff changeset
866 cyg_uint32 len;
6f4928fc3037 * src/fatfs_supp.c: Correct types to remove compiler warnings.
asl
parents: 1975
diff changeset
867 int err, i;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
868
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
869 pos = 0;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
870 len = 32;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
871 memset((void*)data, 0x00, len);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
872
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
873 CYG_TRACE1(TCL, "erasing cluster=%d", cluster);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
874
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
875 for (i = 0; i < (disk->cluster_size >> 5); i++)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
876 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
877 err = disk_cluster_write(disk, (void*)data, &len, cluster, pos);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
878 if (err != ENOERR)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
879 return err;
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
880
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
881 pos += len;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
882 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
883
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
884 return ENOERR;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
885 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
886
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
887 // -------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
888 // mark_cluster()
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
889 // Marks cluster (sets the cluster's FAT table entry to given type).
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
890
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
891 static int
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
892 mark_cluster(fatfs_disk_t *disk, cyg_uint32 cluster, cyg_uint32 type)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
893 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
894 cyg_uint32 tentry;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
895
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
896 set_tentry_type(disk, &tentry, type);
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
897 return write_tentry(disk, cluster, &tentry);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
898 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
899
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
900 // -------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
901 // link_cluster()
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
902 // Links two clusters.
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
903
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
904 static int
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
905 link_cluster(fatfs_disk_t *disk, cyg_uint32 cluster1, cyg_uint32 cluster2)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
906 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
907 cyg_uint32 tentry;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
908
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
909 set_tentry_next_cluster(disk, &tentry, cluster2);
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
910 return write_tentry(disk, cluster1, &tentry);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
911 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
912
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
913 // -------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
914 // find_next_free_cluster()
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
915 // Finds first free cluster starting from given cluster.
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
916 // If none is available free_cluster is set to 0.
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
917 // If CO_MARK_LAST is set in opts the found cluster is marked as LAST.
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
918 // If CO_ERASE_NEW is set in opts the found cluster is erased.
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
919
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
920 static int
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
921 find_next_free_cluster(fatfs_disk_t *disk,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
922 cyg_uint32 start_cluster,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
923 cyg_uint32 *free_cluster,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
924 cluster_opts_t opts)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
925 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
926 cyg_uint32 c, tentry;
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
927 int err;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
928
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
929 if (start_cluster < 2) c = 2;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
930 else c = start_cluster + 1;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
931
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
932 *free_cluster = 0;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
933
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
934 CYG_TRACE1(TCL, "starting at cluster=%d", c);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
935
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
936 // Search from the starting cluster to the end of FAT and
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
937 // from start of FAT to the starting cluster
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
938 while (c != start_cluster)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
939 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
940 // Check for end of FAT
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
941 if (c >= disk->fat_tbl_nents)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
942 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
943 c = 2;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
944 if (c >= start_cluster)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
945 break;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
946 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
947
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
948 err = read_tentry(disk, c, &tentry);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
949 if (err != ENOERR)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
950 return err;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
951
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
952 if (TENTRY_FREE == get_tentry_type(disk, tentry))
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
953 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
954 CYG_TRACE1(TCL, "found free cluster=%d", c);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
955
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
956 *free_cluster = c;
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
957
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
958 if (opts & CO_MARK_LAST)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
959 err = mark_cluster(disk, c, TENTRY_LAST);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
960 if ((err == ENOERR) && (opts & CO_ERASE_NEW))
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
961 err = erase_cluster(disk, c);
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
962
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
963 return err;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
964 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
965 c++;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
966 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
967
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
968 // No free clusters found
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
969
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
970 CYG_TRACE0(TCL, "!!! no free clusters found");
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
971
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
972 return ENOSPC;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
973 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
974
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
975 // -------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
976 // find_and_append_cluster()
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
977 // Finds a free cluster on disk and appends it to the given cluster.
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
978 // New cluster is marked as LAST.
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
979
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
980 static int
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
981 find_and_append_cluster(fatfs_disk_t *disk,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
982 cyg_uint32 cluster,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
983 cyg_uint32 *new_cluster,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
984 cluster_opts_t opts)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
985 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
986 cyg_uint32 free_cluster;
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
987 int err;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
988
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
989 err = find_next_free_cluster(disk, cluster,
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
990 &free_cluster, opts | CO_MARK_LAST);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
991 if (err != ENOERR)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
992 return err;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
993
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
994 err = link_cluster(disk, cluster, free_cluster);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
995 if (err != ENOERR)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
996 return err;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
997
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
998 *new_cluster = free_cluster;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
999
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1000 CYG_TRACE2(TCL, "appending new cluster=%d to cluster=%d",
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1001 free_cluster, cluster);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1002
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1003 return ENOERR;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1004 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1005
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1006 // -------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1007 // find_nth_cluster0()
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1008 // Finds nth cluster in chain (ie nth cluster of file) searching
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1009 // from given position. The result is returned by the same position
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1010 // variable.
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1011
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1012 static int
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1013 find_nth_cluster0(fatfs_disk_t *disk,
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1014 fatfs_data_pos_t *pos,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1015 cyg_uint32 n)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1016 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1017 cyg_uint32 cluster, cluster_snum;
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1018 int err = ENOERR;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1019
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1020 if (pos->cluster_snum == n)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1021 return ENOERR;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1022
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1023 cluster = pos->cluster;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1024 cluster_snum = pos->cluster_snum;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1025
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1026 CYG_TRACE4(TCL, "cluster=%d snum=%d n=%d n_to_search=%d",
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1027 cluster, cluster_snum, n, n-cluster_snum);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1028
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1029 // Adjust the number of clusters that should be
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1030 // walked according to the given position
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1031 n -= cluster_snum;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1032
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1033 // Walk the cluster chain for n clusters or until last cluster
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1034 while (n > 0)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1035 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1036 cyg_uint32 tentry;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1037
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1038 err = read_tentry(disk, cluster, &tentry);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1039 if (err != ENOERR)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1040 return err;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1041
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1042 switch (get_tentry_type(disk, tentry))
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1043 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1044 case TENTRY_REGULAR:
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1045 break;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1046 case TENTRY_LAST:
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1047 CYG_TRACE1(TCL, "chain end at n=%d", n);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1048 err = EEOF; // File has less clusters than given n
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1049 // this err should be caught by the
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1050 // calling function
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1051 goto out;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1052 default:
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1053 // Inconsistant FAT table state !!!
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1054 CYG_TRACE2(TCL, "!!! inconsistant FAT tentry=%x n=%d",
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1055 tentry, n);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1056 err = EIO;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1057 goto out;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1058 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1059 cluster = get_tentry_next_cluster(disk, tentry);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1060 cluster_snum++;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1061 n--;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1062 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1063
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1064 out:
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1065 pos->cluster = cluster;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1066 pos->cluster_snum = cluster_snum;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1067
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1068 CYG_TRACE2(TCL, "nth cluster=%d snum=%d", cluster, cluster_snum);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1069
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1070 return err;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1071 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1072
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1073 // -------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1074 // find_nth_cluster()
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1075 // Finds nth cluster in chain (ie nth cluster of file) searching
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1076 // from given position. The result is returned by the same position
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1077 // variable. If the chain ends one cluster before the given nth cluster
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1078 // and the CO_EXTEND is specified, than the chain is extended by one cluster.
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1079
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1080 static int
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1081 find_nth_cluster(fatfs_disk_t *disk,
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1082 fatfs_data_pos_t *pos,
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1083 cyg_uint32 n,
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1084 cluster_opts_t opts)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1085 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1086 int err;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1087
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1088 // Find nth cluster
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1089 err = find_nth_cluster0(disk, pos, n);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1090
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1091 // EEOF meens that the cluster chain ended early
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1092 if ((err != EEOF) || !(opts & CO_EXTEND))
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1093 return err;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1094
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1095 // Check if one cluster short
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1096 if (pos->cluster_snum == (n - 1))
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1097 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1098 // Extend the chain for one cluster
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1099 cyg_uint32 new_cluster;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1100
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1101 // Append new cluster to the end of chain
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1102 err = find_and_append_cluster(disk, pos->cluster, &new_cluster, opts);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1103 if (err != ENOERR)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1104 return err;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1105
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1106 // Update position
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1107 pos->cluster = new_cluster;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1108 pos->cluster_snum += 1;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1109 pos->cluster_pos = 0;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1110
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1111 CYG_TRACE1(TCL, "appended new cluster=%d", new_cluster);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1112 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1113
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1114 return err;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1115 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1116
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1117 // -------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1118 // get_next_cluster()
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1119 // Gets next cluster in chain (ie next cluster of file).
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1120 // If CO_EXTEND is specified and the current cluster is last in the
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1121 // chain then the chain is extended by one cluster.
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1122
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1123 static int
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1124 get_next_cluster(fatfs_disk_t *disk,
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1125 fatfs_data_pos_t *pos,
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1126 cluster_opts_t opts)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1127 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1128 int err;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1129
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1130 err = find_nth_cluster(disk, pos, pos->cluster_snum + 1, opts);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1131 if (err != ENOERR)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1132 return err;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1133
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1134 // Reset inside cluster position
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1135 pos->cluster_pos = 0;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1136
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1137 return ENOERR;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1138 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1139
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1140 // -------------------------------------------------------------------------
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1141 // get_position_from_off()
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1142 // Gets position from given offset. The search is started from the
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1143 // given position and the result is returned by the same variable.
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1144 // If CO_EXTEND is specified the file is extended if one cluster too short.
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1145
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1146 static int
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1147 get_position_from_off(fatfs_disk_t *disk,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1148 cyg_uint32 first_cluster,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1149 cyg_uint32 offset,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1150 fatfs_data_pos_t *pos,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1151 cluster_opts_t opts)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1152 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1153 fatfs_data_pos_t new_pos;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1154 cyg_uint32 n;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1155 int err;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1156
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1157 // Position inside the cluster
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1158 new_pos.cluster_pos = offset & (disk->cluster_size - 1);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1159
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1160 // Cluster seq number to be searched for
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1161 n = offset >> disk->cluster_size_log2;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1162
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1163 if (n < pos->cluster_snum)
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1164 {
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1165 // Start searching from first cluster
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1166 new_pos.cluster = first_cluster;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1167 new_pos.cluster_snum = 0;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1168 }
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1169 else
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1170 {
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1171 // Start searching from the current position
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1172 new_pos.cluster = pos->cluster;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1173 new_pos.cluster_snum = pos->cluster_snum;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1174 }
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1175
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1176 err = find_nth_cluster(disk, &new_pos, n, opts);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1177
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1178 // Err could be EEOF wich means that the given
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1179 // offset if out of given file (cluster chain)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1180
1975
187dfdcdf712 * src/fatfs_supp.c: lseek returned EEOF when at the end of the
asl
parents: 1869
diff changeset
1181 if (EEOF == err)
187dfdcdf712 * src/fatfs_supp.c: lseek returned EEOF when at the end of the
asl
parents: 1869
diff changeset
1182 new_pos.cluster_pos = disk->cluster_size;
187dfdcdf712 * src/fatfs_supp.c: lseek returned EEOF when at the end of the
asl
parents: 1869
diff changeset
1183
187dfdcdf712 * src/fatfs_supp.c: lseek returned EEOF when at the end of the
asl
parents: 1869
diff changeset
1184 *pos = new_pos;
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1185
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1186 return err;
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1187 }
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1188
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1189 // -------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1190 // free_cluster_chain()
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1191 // Marks all clusters FREE from given cluster to the last cluster in chain.
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1192
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1193 static int
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1194 free_cluster_chain(fatfs_disk_t *disk, cyg_uint32 start_cluster)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1195 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1196 cyg_uint32 c, next_c, tentry;
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1197 bool last;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1198 int err;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1199
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1200 CYG_TRACE1(TCL, "start cluster=%d", start_cluster);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1201
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1202 c = next_c = start_cluster;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1203 last = false;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1204 while (!last)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1205 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1206 err = read_tentry(disk, c, &tentry);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1207 if (err != ENOERR)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1208 return err;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1209
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1210 switch (get_tentry_type(disk, tentry))
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1211 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1212 case TENTRY_LAST:
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1213 // Last cluster in chain
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1214 last = true;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1215 break;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1216 case TENTRY_REGULAR:
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1217 // Get next cluster in chain
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1218 next_c = get_tentry_next_cluster(disk, tentry);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1219 break;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1220 default:
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1221 CYG_TRACE2(TCL, "!!! inconsistant FAT tentry=%x c=%d",
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1222 tentry, c);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1223 return EIO;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1224 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1225
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1226 // Set the current tentry to FREE
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1227 set_tentry_type(disk, &tentry, TENTRY_FREE);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1228 err = write_tentry(disk, c, &tentry);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1229 if (err != ENOERR)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1230 return err;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1231
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1232 // Next cluster in chain
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1233 c = next_c;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1234 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1235
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1236 CYG_TRACE1(TCL, "last cluster=%d", c);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1237
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1238 return ENOERR;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1239 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1240
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1241 //==========================================================================
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1242 // FAT dir entry functions
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1243
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1244 // -------------------------------------------------------------------------
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1245 // print_raw_dentry()
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1246 // Prints FAT directory entry.
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1247
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1248 #if TDE
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1249 static void
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1250 print_raw_dentry(fat_raw_dir_entry_t* dentry)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1251 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1252 if (DENTRY_IS_DELETED(dentry))
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1253 diag_printf("FAT: FDE name: '?%.7s'\n", &dentry->name[1]);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1254 else
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1255 diag_printf("FAT: FDE name: '%.8s'\n", dentry->name);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1256 diag_printf("FAT: FDE ext: '%.3s'\n", dentry->ext);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1257 diag_printf("FAT: FDE attr: %c%c%c%c%c%c\n",
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1258 (DENTRY_IS_RDONLY(dentry) ? 'R' : '-'),
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1259 (DENTRY_IS_HIDDEN(dentry) ? 'H' : '-'),
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1260 (DENTRY_IS_SYSTEM(dentry) ? 'S' : '-'),
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1261 (DENTRY_IS_VOLUME(dentry) ? 'V' : '-'),
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1262 (DENTRY_IS_DIR(dentry) ? 'D' : '-'),
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1263 (DENTRY_IS_ARCHIVE(dentry) ? 'A' : '-'));
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1264 diag_printf("FAT: FDE crt time: %u\n", dentry->crt_time);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1265 diag_printf("FAT: FDE crt date: %u\n", dentry->crt_date);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1266 diag_printf("FAT: FDE acc date: %u\n", dentry->acc_date);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1267 diag_printf("FAT: FDE wrt time: %u\n", dentry->wrt_time);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1268 diag_printf("FAT: FDE wrt date: %u\n", dentry->wrt_date);
2364
028e0fe198b5 * src/fatfs_supp.c: Fixed FAT32 cluster handling in
asl
parents: 2044
diff changeset
1269 diag_printf("FAT: FDE cluster: %u\n", (dentry->cluster_HI << 16) | dentry->cluster);
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1270 diag_printf("FAT: FDE size: %u\n", dentry->size);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1271 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1272 #endif // TDE
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1273
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1274 // -------------------------------------------------------------------------
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1275 // read_raw_dentry()
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1276 // Reads dir entry from disk.
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1277
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1278 static int
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1279 read_raw_dentry(fatfs_disk_t *disk,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1280 fatfs_data_pos_t *pos,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1281 fat_raw_dir_entry_t *dentry)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1282 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1283 cyg_uint8 data[DENTRY_SIZE];
2044
6f4928fc3037 * src/fatfs_supp.c: Correct types to remove compiler warnings.
asl
parents: 1975
diff changeset
1284 cyg_uint32 len;
6f4928fc3037 * src/fatfs_supp.c: Correct types to remove compiler warnings.
asl
parents: 1975
diff changeset
1285 int err;
6f4928fc3037 * src/fatfs_supp.c: Correct types to remove compiler warnings.
asl
parents: 1975
diff changeset
1286
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1287 CYG_TRACE3(TDE, "cluster=%d snum=%d pos=%d",
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1288 pos->cluster, pos->cluster_snum, pos->cluster_pos);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1289
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1290 len = DENTRY_SIZE;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1291
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1292 // Check if we are reading the FAT12/16 root directory
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1293 if (0 == pos->cluster)
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1294 err = disk_read(disk, (void*)data, &len,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1295 disk->fat_root_dir_pos + pos->cluster_pos);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1296 else
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1297 err = disk_cluster_read(disk, (void*)data, &len,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1298 pos->cluster, pos->cluster_pos);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1299 if (err != ENOERR)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1300 return err;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1301
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1302 GET_BYTES(data, dentry->name, 8, 0x00);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1303 GET_BYTES(data, dentry->ext, 3, 0x08);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1304 GET_BYTE(data, dentry->attr, 0x0B);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1305 GET_BYTE(data, dentry->nt_reserved, 0x0C);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1306 GET_BYTE(data, dentry->crt_sec_100, 0x0D);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1307 GET_WORD(data, dentry->crt_time, 0x0E);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1308 GET_WORD(data, dentry->crt_date, 0x10);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1309 GET_WORD(data, dentry->acc_date, 0x12);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1310 GET_WORD(data, dentry->cluster_HI, 0x14);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1311 GET_WORD(data, dentry->wrt_time, 0x16);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1312 GET_WORD(data, dentry->wrt_date, 0x18);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1313 GET_WORD(data, dentry->cluster, 0x1A);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1314 GET_DWORD(data, dentry->size, 0x1C);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1315
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1316 // Zero terminate strings
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1317 dentry->name[8] = '\0';
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1318 dentry->ext[3] = '\0';
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1319
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1320 #if TDE
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1321 print_raw_dentry(dentry);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1322 #endif
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1323
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1324 return ENOERR;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1325 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1326
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1327 // -------------------------------------------------------------------------
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1328 // write_raw_dentry()
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1329 // Writes raw dir entry to disk.
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1330
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1331 static int
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1332 write_raw_dentry(fatfs_disk_t *disk,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1333 fatfs_data_pos_t *pos,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1334 fat_raw_dir_entry_t *dentry)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1335 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1336 cyg_uint8 data[DENTRY_SIZE];
2044
6f4928fc3037 * src/fatfs_supp.c: Correct types to remove compiler warnings.
asl
parents: 1975
diff changeset
1337 cyg_uint32 len;
6f4928fc3037 * src/fatfs_supp.c: Correct types to remove compiler warnings.
asl
parents: 1975
diff changeset
1338 int err;
6f4928fc3037 * src/fatfs_supp.c: Correct types to remove compiler warnings.
asl
parents: 1975
diff changeset
1339
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1340 CYG_TRACE3(TDE, "cluster=%d snum=%d pos=%d",
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1341 pos->cluster, pos->cluster_snum, pos->cluster_pos);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1342
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1343 SET_BYTES(data, dentry->name, 8, 0x00);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1344 SET_BYTES(data, dentry->ext, 3, 0x08);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1345 SET_BYTE(data, dentry->attr, 0x0B);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1346 SET_BYTE(data, dentry->nt_reserved, 0x0C);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1347 SET_BYTE(data, dentry->crt_sec_100, 0x0D);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1348 SET_WORD(data, dentry->crt_time, 0x0E);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1349 SET_WORD(data, dentry->crt_date, 0x10);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1350 SET_WORD(data, dentry->acc_date, 0x12);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1351 SET_WORD(data, dentry->cluster_HI, 0x14);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1352 SET_WORD(data, dentry->wrt_time, 0x16);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1353 SET_WORD(data, dentry->wrt_date, 0x18);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1354 SET_WORD(data, dentry->cluster, 0x1A);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1355 SET_DWORD(data, dentry->size, 0x1C);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1356
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1357 len = DENTRY_SIZE;
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1358
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1359 // Check if we are writting to the FAT12/16 root directory
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1360 if (0 == pos->cluster)
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1361 err = disk_write(disk, (void*)data, &len,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1362 disk->fat_root_dir_pos + pos->cluster_pos);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1363 else
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1364 err = disk_cluster_write(disk, (void*)data, &len,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1365 pos->cluster, pos->cluster_pos);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1366 if (err != ENOERR)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1367 return err;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1368
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1369 #if TDE
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1370 print_raw_dentry(dentry);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1371 #endif
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1372
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1373 return ENOERR;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1374 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1375
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1376 // -------------------------------------------------------------------------
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1377 // raw_dentry_set_deleted()
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1378 // Sets the dentry filename first char to 0xE5 (ie deleted).
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1379
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1380 static __inline__ void
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1381 raw_dentry_set_deleted(fatfs_disk_t *disk, fat_raw_dir_entry_t *dentry)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1382 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1383 dentry->name[0] = 0xE5;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1384 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1385
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1386 // -------------------------------------------------------------------------
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1387 // get_raw_dentry_filename()
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1388 // Gets the filename from given dir entry.
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1389
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1390 static void
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1391 get_raw_dentry_filename(fat_raw_dir_entry_t *dentry, char *name)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1392 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1393 int i = 0;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1394 char *cptr = dentry->name;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1395 char *cname = name;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1396
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1397 while (*cptr != ' ' && i < 8)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1398 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1399 *cname++ = *cptr++; i++;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1400 }
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1401 cptr = dentry->ext;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1402
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1403 if (*cptr != ' ')
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1404 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1405 *cname++ = '.'; i = 0;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1406 while (*cptr != ' ' && i < 3)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1407 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1408 *cname++ = *cptr++; i++;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1409 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1410 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1411 *cname = '\0';
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1412
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1413 CYG_TRACE3(TDE, "dos name='%s' dos ext='%s' filename='%s'",
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1414 dentry->name, dentry->ext, name);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1415 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1416
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1417 // -------------------------------------------------------------------------
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1418 // set_raw_dentry_filename()
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1419 // Sets the filename of given dir entry.
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1420
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1421 static void
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1422 set_raw_dentry_filename(fat_raw_dir_entry_t *dentry,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1423 const char *name,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1424 int namelen)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1425 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1426 int i, nidx;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1427 const char *cname;
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1428 char *cptr;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1429
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1430 // Special case check
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1431 if ('.' == name[0])
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1432 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1433 if ('\0' == name[1])
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1434 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1435 strcpy(dentry->name, ". ");
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1436 strcpy(dentry->ext, " ");
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1437 return;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1438 }
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1439 else if ('.' == name[1] && '\0' == name[2])
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1440 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1441 strcpy(dentry->name, ".. ");
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1442 strcpy(dentry->ext, " ");
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1443 return;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1444 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1445 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1446
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1447 if (0 == namelen)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1448 namelen = 9999;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1449
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1450 nidx = 0;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1451 cname = name;
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1452 cptr = dentry->name;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1453 for (i = 0; i < 8; i++)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1454 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1455 if (*cname != '.' && *cname != '\0' && nidx++ < namelen)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1456 *cptr++ = toupper(*cname++);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1457 else
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1458 *cptr++ = ' ';
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1459 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1460 *cptr = '\0';
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1461
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1462 while (*cname != '.' && *cname != '\0' && nidx++ < namelen)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1463 cname++;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1464
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1465 if ('.' == *cname && nidx++ < namelen)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1466 cname++;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1467
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1468 cptr = dentry->ext;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1469 for (i = 0; i < 3; i++)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1470 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1471 if (*cname != '.' && *cname != '\0' && nidx++ < namelen)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1472 *cptr++ = toupper(*cname++);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1473 else
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1474 *cptr++ = ' ';
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1475 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1476 *cptr = '\0';
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1477
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1478 CYG_TRACE4(TDE, "filename='%s' namelen=%d dos name='%s' dos ext='%s'",
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1479 name, namelen, dentry->name, dentry->ext);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1480 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1481
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1482 // -------------------------------------------------------------------------
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1483 // read_next_raw_dentry()
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1484 // Gets next dir entry searching from given position to the end.
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1485 // If EEOF is returned there are no more entries in given dir.
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1486
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1487 static int
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1488 read_next_raw_dentry(fatfs_disk_t *disk,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1489 fatfs_data_pos_t *pos,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1490 fat_raw_dir_entry_t *dentry)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1491 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1492 int err = ENOERR;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1493
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1494 // If we are reading the root dir on FAT32 we have
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1495 // to correct the position to the root dir cluster
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1496 if (FATFS_FAT32 == disk->fat_type && 0 == pos->cluster)
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1497 pos->cluster = disk->fat_root_dir_cluster;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1498
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1499 while (true)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1500 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1501 // FAT12/16 root dir check
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1502 if (0 == pos->cluster)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1503 {
1869
17d9a15eab14 * src/fatfs_supp.c:
asl
parents: 1818
diff changeset
1504 if (pos->cluster_pos >= disk->fat_root_dir_size)
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1505 err = EEOF;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1506 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1507 else
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1508 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1509 // Change cluster if needed
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1510 if (pos->cluster_pos >= disk->cluster_size)
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1511 err = get_next_cluster(disk, pos, CO_NONE);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1512 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1513
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1514 if (err != ENOERR)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1515 break;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1516
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1517 err = read_raw_dentry(disk, pos, dentry);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1518 if (err != ENOERR)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1519 return err;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1520
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1521 if (DENTRY_IS_ZERO(dentry))
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1522 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1523 // If we get a ZERO dir entry, we assume that
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1524 // there are no more entries in current dir
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1525 CYG_TRACE0(TDE, "end of dir");
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1526 err = EEOF;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1527 break;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1528 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1529 else if (!DENTRY_IS_DELETED(dentry))
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1530 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1531 // Dir entry found
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1532 CYG_TRACE3(TDE, "found new dentry at cluster=%d snum=%d pos=%d",
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1533 pos->cluster, pos->cluster_snum, pos->cluster_pos);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1534 break;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1535 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1536
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1537 pos->cluster_pos += DENTRY_SIZE;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1538 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1539
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1540 // EEOF could be returned if there are no more entries in this
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1541 // dir - this should be cought by the calling function
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1542
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1543 return err;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1544 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1545
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1546 // -------------------------------------------------------------------------
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1547 // get_free_raw_dentry()
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1548 // Gets free dir entry slot searching from given position extending the
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1549 // directory if needed. If an deleated entry is found it is reused.
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1550
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1551 static int
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1552 get_free_raw_dentry(fatfs_disk_t *disk,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1553 fatfs_data_pos_t *pos)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1554 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1555 fat_raw_dir_entry_t raw_dentry;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1556 fatfs_data_pos_t cpos;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1557 int err = ENOERR;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1558
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1559 cpos = *pos;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1560
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1561 // If we are reading the root dir on FAT32 we have
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1562 // to correct the position to the root dir cluster
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1563 if (FATFS_FAT32 == disk->fat_type && 0 == cpos.cluster)
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1564 cpos.cluster = disk->fat_root_dir_cluster;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1565
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1566 CYG_TRACE3(TDE, "cluster=%d snum=%d pos=%d",
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1567 pos->cluster, pos->cluster_snum, pos->cluster_pos);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1568
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1569 while (true)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1570 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1571 // FAT12/16 root dir check
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1572 if (0 == cpos.cluster)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1573 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1574 if (cpos.cluster_pos >= disk->fat_root_dir_size)
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1575 err = ENOSPC;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1576 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1577 else
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1578 {
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1579 // Change cluster if needed
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1580 if (cpos.cluster_pos >= disk->cluster_size)
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1581 err = get_next_cluster(disk, &cpos, CO_EXTEND | CO_ERASE_NEW);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1582 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1583
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1584 if (err != ENOERR)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1585 return err;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1586
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1587 err = read_raw_dentry(disk, &cpos, &raw_dentry);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1588 if (err != ENOERR)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1589 return err;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1590
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1591 if (DENTRY_IS_DELETED(&raw_dentry))
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1592 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1593 CYG_TRACE3(TDE, "deleted dentry at cluster=%d snum=%d pos=%d",
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1594 cpos.cluster, cpos.cluster_snum, cpos.cluster_pos);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1595
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1596 *pos = cpos;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1597 return ENOERR;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1598 }
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1599 else if (DENTRY_IS_ZERO(&raw_dentry))
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1600 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1601 CYG_TRACE3(TDE, "zero dentry at cluster=%d snum=%d pos=%d",
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1602 cpos.cluster, cpos.cluster_snum, cpos.cluster_pos);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1603
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1604 *pos = cpos;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1605 return ENOERR;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1606 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1607
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1608 cpos.cluster_pos += DENTRY_SIZE;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1609 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1610 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1611
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1612 // -------------------------------------------------------------------------
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1613 // raw_to_dentry()
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1614 // Converts raw FAT dir entry to dir entry.
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1615
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1616 static void
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1617 raw_to_dentry(fat_raw_dir_entry_t *raw_dentry,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1618 fatfs_data_pos_t *raw_dentry_pos,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1619 fatfs_dir_entry_t *dentry)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1620 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1621 get_raw_dentry_filename(raw_dentry, dentry->filename);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1622
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1623 if (DENTRY_IS_DIR(raw_dentry))
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1624 dentry->mode = __stat_mode_DIR;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1625 else
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1626 dentry->mode = __stat_mode_REG;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1627
1818
5663e2763ba6 * src/fatfs.c:
asl
parents: 1784
diff changeset
1628 #ifdef CYGCFG_FS_FAT_USE_ATTRIBUTES
5663e2763ba6 * src/fatfs.c:
asl
parents: 1784
diff changeset
1629 dentry->attrib = raw_dentry->attr;
5663e2763ba6 * src/fatfs.c:
asl
parents: 1784
diff changeset
1630 #endif // CYGCFG_FS_FAT_USE_ATTRIBUTES
5663e2763ba6 * src/fatfs.c:
asl
parents: 1784
diff changeset
1631
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1632 date_dos2unix(raw_dentry->crt_time, raw_dentry->crt_date, &dentry->ctime);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1633 date_dos2unix(0, raw_dentry->acc_date, &dentry->atime);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1634 date_dos2unix(raw_dentry->wrt_time, raw_dentry->wrt_date, &dentry->mtime);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1635
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1636 dentry->size = raw_dentry->size;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1637 dentry->priv_data = raw_dentry->nt_reserved;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1638 dentry->cluster = raw_dentry->cluster | (raw_dentry->cluster_HI << 16);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1639 dentry->disk_pos = *raw_dentry_pos;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1640 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1641
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1642 // -------------------------------------------------------------------------
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1643 // dentry_to_raw()
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1644 // Converts dir entry to raw FAT dir entry.
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1645
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1646 static void
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1647 dentry_to_raw(fatfs_dir_entry_t *dentry, fat_raw_dir_entry_t *raw_dentry)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1648 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1649 set_raw_dentry_filename(raw_dentry, dentry->filename, 0);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1650
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1651 if (__stat_mode_DIR == dentry->mode)
1818
5663e2763ba6 * src/fatfs.c:
asl
parents: 1784
diff changeset
1652 raw_dentry->attr = S_FATFS_DIR;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1653 else
1818
5663e2763ba6 * src/fatfs.c:
asl
parents: 1784
diff changeset
1654 raw_dentry->attr = S_FATFS_ARCHIVE;
5663e2763ba6 * src/fatfs.c:
asl
parents: 1784
diff changeset
1655 #ifdef CYGCFG_FS_FAT_USE_ATTRIBUTES
5663e2763ba6 * src/fatfs.c:
asl
parents: 1784
diff changeset
1656 raw_dentry->attr = dentry->attrib;
5663e2763ba6 * src/fatfs.c:
asl
parents: 1784
diff changeset
1657 #endif // CYGCFG_FS_FAT_USE_ATTRIBUTES
5663e2763ba6 * src/fatfs.c:
asl
parents: 1784
diff changeset
1658
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1659
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1660 date_unix2dos(dentry->ctime, &raw_dentry->crt_time, &raw_dentry->crt_date);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1661 date_unix2dos(dentry->atime, NULL, &raw_dentry->acc_date);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1662 date_unix2dos(dentry->mtime, &raw_dentry->wrt_time, &raw_dentry->wrt_date);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1663
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1664 raw_dentry->crt_sec_100 = 0; //FIXME
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1665 raw_dentry->size = dentry->size;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1666 raw_dentry->nt_reserved = dentry->priv_data;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1667 raw_dentry->cluster = dentry->cluster & 0xFFFF;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1668 raw_dentry->cluster_HI = dentry->cluster >> 16;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1669 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1670
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1671 //==========================================================================
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1672 // FAT data functions
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1673
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1674 // -------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1675 // read_data()
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1676 // Reads data from given position.
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1677
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1678 static int
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1679 read_data(fatfs_disk_t *disk,
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1680 void *data,
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1681 cyg_uint32 *len,
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1682 fatfs_data_pos_t *pos)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1683 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1684 cyg_uint8 *buf = (cyg_uint8 *) data;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1685 cyg_uint32 size = *len;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1686 int err = ENOERR;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1687
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1688 CYG_TRACE4(TDO, "len=%d cluster=%d snum=%d pos=%d",
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1689 *len, pos->cluster, pos->cluster_snum,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1690 pos->cluster_pos);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1691
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1692 while (size > 0)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1693 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1694 cyg_uint32 csize;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1695
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1696 // Check if we are still inside current cluster
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1697 if (pos->cluster_pos >= disk->cluster_size)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1698 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1699 // Get next cluster of file
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1700 err = get_next_cluster(disk, pos, CO_NONE);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1701 if (err != ENOERR)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1702 goto out;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1703 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1704
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1705 // Adjust the data chunk size to be read to the cluster boundary
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1706 if (size > (disk->cluster_size - pos->cluster_pos))
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1707 csize = disk->cluster_size - pos->cluster_pos;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1708 else
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1709 csize = size;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1710
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1711 CYG_TRACE4(TDO, "-- len=%d cluster=%d snum=%d pos=%d",
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1712 csize, pos->cluster, pos->cluster_snum,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1713 pos->cluster_pos);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1714
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1715 err = disk_cluster_read(disk, (void*)buf, &csize,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1716 pos->cluster, pos->cluster_pos);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1717 if (err != ENOERR)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1718 goto out;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1719
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1720 // Adjust running variables
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1721
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1722 buf += csize;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1723 pos->cluster_pos += csize;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1724 size -= csize;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1725 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1726
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1727 out:
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1728 *len -= size;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1729
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1730 CYG_TRACE1(TDO, "total len=%d", *len);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1731
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1732 return err;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1733 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1734
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1735 // -------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1736 // write_data()
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1737 // Writes data to given position.
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1738
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1739 static int
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1740 write_data(fatfs_disk_t *disk,
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1741 void *data,
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1742 cyg_uint32 *len,
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1743 fatfs_data_pos_t *pos)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1744 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1745 cyg_uint8 *buf = (cyg_uint8 *) data;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1746 cyg_uint32 size = *len;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1747 int err = ENOERR;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1748
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1749 CYG_TRACE4(TDO, "len=%d cluster=%d snum=%d pos=%d",
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1750 *len, pos->cluster, pos->cluster_snum,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1751 pos->cluster_pos);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1752
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1753 while (size > 0)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1754 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1755 cyg_uint32 csize;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1756
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1757 // Check if we are still inside current cluster
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1758 if (pos->cluster_pos >= disk->cluster_size)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1759 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1760 // Get next cluster of file, if at the last
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1761 // cluster try to extend the cluster chain
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1762 err = get_next_cluster(disk, pos, CO_EXTEND);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1763 if (err != ENOERR)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1764 goto out;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1765 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1766
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1767 // Adjust the data chunk size to be read to the cluster boundary
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1768 if (size > (disk->cluster_size - pos->cluster_pos))
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1769 csize = disk->cluster_size - pos->cluster_pos;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1770 else
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1771 csize = size;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1772
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1773 CYG_TRACE4(TDO, "-- len=%d cluster=%d snum=%d pos=%d",
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1774 csize, pos->cluster, pos->cluster_snum,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1775 pos->cluster_pos);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1776
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1777 err = disk_cluster_write(disk, (void*)buf, &csize,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1778 pos->cluster, pos->cluster_pos);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1779 if (err != ENOERR)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1780 goto out;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1781
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1782 // Adjust running variables
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1783
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1784 buf += csize;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1785 pos->cluster_pos += csize;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1786 size -= csize;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1787 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1788
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1789 out:
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1790 *len -= size;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1791
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1792 CYG_TRACE1(TDO, "total len=%d", *len);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1793
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1794 return err;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1795 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1796
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1797 //==========================================================================
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1798 // Misc functions
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1799
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1800 // -------------------------------------------------------------------------
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1801 // init_dir_entry()
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1802 // Initializes attributes of a new dir entry.
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1803
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1804 static void
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1805 init_dir_entry(fatfs_dir_entry_t *dentry,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1806 const char *name,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1807 int namelen,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1808 mode_t mode,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1809 cyg_uint32 parent_cluster,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1810 cyg_uint32 first_cluster,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1811 fatfs_data_pos_t *pos)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1812 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1813 if (0 == namelen)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1814 namelen = 12;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1815
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1816 strncpy(dentry->filename, name, namelen);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1817 dentry->filename[namelen] = '\0';
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1818
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1819 dentry->mode = mode;
1818
5663e2763ba6 * src/fatfs.c:
asl
parents: 1784
diff changeset
1820
5663e2763ba6 * src/fatfs.c:
asl
parents: 1784
diff changeset
1821 #ifdef CYGCFG_FS_FAT_USE_ATTRIBUTES
5663e2763ba6 * src/fatfs.c:
asl
parents: 1784
diff changeset
1822 if (S_ISDIR(dentry->mode))
5663e2763ba6 * src/fatfs.c:
asl
parents: 1784
diff changeset
1823 dentry->attrib = S_FATFS_DIR;
5663e2763ba6 * src/fatfs.c:
asl
parents: 1784
diff changeset
1824 else
5663e2763ba6 * src/fatfs.c:
asl
parents: 1784
diff changeset
1825 dentry->attrib = S_FATFS_ARCHIVE;
5663e2763ba6 * src/fatfs.c:
asl
parents: 1784
diff changeset
1826 #endif // CYGCFG_FS_FAT_USE_ATTRIBUTES
5663e2763ba6 * src/fatfs.c:
asl
parents: 1784
diff changeset
1827
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1828 dentry->ctime =
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1829 dentry->atime =
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1830 dentry->mtime = cyg_timestamp();
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1831
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1832 dentry->priv_data = 0;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1833 dentry->size = 0;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1834 dentry->cluster = first_cluster;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1835 dentry->parent_cluster = parent_cluster;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1836 dentry->disk_pos = *pos;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1837 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1838
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1839 // -------------------------------------------------------------------------
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1840 // is_root_dir_entry()
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1841 // Check if the given dir entry is the root dir entry.
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1842
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1843 static __inline__ bool
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1844 is_root_dir_entry(fatfs_dir_entry_t *dentry)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1845 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1846 return ('\0' == dentry->filename[0] && 0 == dentry->cluster);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1847 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1848
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1849 //==========================================================================
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1850 //==========================================================================
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1851 // Exported functions
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1852
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1853 // -------------------------------------------------------------------------
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1854 // fatfs_init()
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1855 // Gets disk info.
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1856
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1857 int
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1858 fatfs_init(fatfs_disk_t *disk)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1859 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1860 cyg_uint32 sec_num, sec_per_fat, root_dir_sec_num;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1861 cyg_uint32 data_sec_num, data_clu_num;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1862 fat_boot_record_t boot_rec;
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1863 int err;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1864
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1865 CYG_CHECK_DATA_PTRC(disk);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1866
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1867 err = read_boot_record(disk, &boot_rec);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1868 if (err != ENOERR)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1869 return err;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1870
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1871 // Check some known boot record values
2533
4f15eaebbf32 * cdl/fatfs.cdl: Add configury for the disk device names to be
asl
parents: 2483
diff changeset
1872 if (!(0x29 == boot_rec.ext_sig ||
4f15eaebbf32 * cdl/fatfs.cdl: Add configury for the disk device names to be
asl
parents: 2483
diff changeset
1873 0x28 == boot_rec.ext_sig) ||
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1874 0x55 != boot_rec.exe_marker[0] ||
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1875 0xAA != boot_rec.exe_marker[1])
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1876 return EINVAL;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1877
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1878 // Sector and cluster sizes
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1879 disk->sector_size = boot_rec.bytes_per_sec;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1880 disk->sector_size_log2 = get_val_log2(disk->sector_size);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1881 disk->cluster_size = boot_rec.bytes_per_sec * boot_rec.sec_per_clu;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1882 disk->cluster_size_log2 = get_val_log2(disk->cluster_size);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1883
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1884 // Sector and cluster size should always be a power of 2
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1885 if (0 == disk->sector_size_log2 || 0 == disk->cluster_size_log2)
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1886 return EINVAL;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1887
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1888 // Determine number of sectors
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1889 if (boot_rec.sec_num_32 != 0)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1890 sec_num = boot_rec.sec_num_32;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1891 else
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1892 sec_num = boot_rec.sec_num;
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1893
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1894 // Determine number of sectors per fat
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1895 if (boot_rec.sec_per_fat != 0)
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1896 sec_per_fat = boot_rec.sec_per_fat;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1897 else
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1898 sec_per_fat = boot_rec.sec_per_fat_32;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1899
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1900 // Number of sectors used by root directory
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1901 root_dir_sec_num = ((boot_rec.max_root_dents * DENTRY_SIZE) +
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1902 (boot_rec.bytes_per_sec - 1)) / boot_rec.bytes_per_sec;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1903
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1904 // Number of data sectors
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1905 data_sec_num = sec_num - (boot_rec.res_sec_num +
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1906 (boot_rec.fat_tbls_num * sec_per_fat) + root_dir_sec_num);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1907
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1908 // Number of data clusters
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1909 data_clu_num = data_sec_num / boot_rec.sec_per_clu;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1910
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1911 // FAT table size and position
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1912 disk->fat_tbl_pos = boot_rec.bytes_per_sec * boot_rec.res_sec_num;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1913 disk->fat_tbl_size = boot_rec.bytes_per_sec * sec_per_fat;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1914 disk->fat_tbl_nents = data_clu_num + 2;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1915 disk->fat_tbls_num = boot_rec.fat_tbls_num;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1916
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1917 // Determine the type of FAT based on number of data clusters
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1918 if (data_clu_num < 4085)
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1919 disk->fat_type = FATFS_FAT12;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1920 else if (data_clu_num < 65525)
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1921 disk->fat_type = FATFS_FAT16;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1922 else
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1923 disk->fat_type = FATFS_FAT32;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1924
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1925 // Determine root dir and data positions
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1926 if (FATFS_FAT32 != disk->fat_type)
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1927 {
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1928 disk->fat_root_dir_pos = disk->fat_tbl_pos +
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1929 disk->fat_tbls_num * disk->fat_tbl_size;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1930 disk->fat_root_dir_size = boot_rec.max_root_dents * DENTRY_SIZE;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1931 disk->fat_root_dir_nents = boot_rec.max_root_dents;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1932 disk->fat_root_dir_cluster = 0;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1933 disk->fat_data_pos = disk->fat_root_dir_pos +
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1934 disk->fat_root_dir_size;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1935 }
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1936 else
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1937 {
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1938 disk->fat_root_dir_pos = 0;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1939 disk->fat_root_dir_size = 0;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1940 disk->fat_root_dir_nents = 0;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1941 disk->fat_root_dir_cluster = boot_rec.root_cluster;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1942 disk->fat_data_pos = disk->fat_tbl_pos +
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1943 disk->fat_tbls_num * disk->fat_tbl_size;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1944 }
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1945
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1946 return ENOERR;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1947 }
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1948
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1949 // -------------------------------------------------------------------------
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1950 // fatfs_get_root_dir_entry()
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1951 // Gets root dir entry.
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1952
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1953 void
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1954 fatfs_get_root_dir_entry(fatfs_disk_t *disk, fatfs_dir_entry_t *dentry)
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1955 {
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1956 CYG_CHECK_DATA_PTRC(disk);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1957 CYG_CHECK_DATA_PTRC(dentry);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1958
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1959 dentry->mode = __stat_mode_DIR;
1818
5663e2763ba6 * src/fatfs.c:
asl
parents: 1784
diff changeset
1960 #ifdef CYGCFG_FS_FAT_USE_ATTRIBUTES
5663e2763ba6 * src/fatfs.c:
asl
parents: 1784
diff changeset
1961 dentry->attrib = S_FATFS_DIR;
5663e2763ba6 * src/fatfs.c:
asl
parents: 1784
diff changeset
1962 #endif // CYGCFG_FS_FAT_USE_ATTRIBUTES
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1963 dentry->size = disk->fat_root_dir_size;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1964 dentry->ctime = 0;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1965 dentry->atime = 0;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1966 dentry->mtime = 0;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1967 dentry->filename[0] = '\0';
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1968 dentry->cluster = 0;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1969 dentry->parent_cluster = 0;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1970
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1971 dentry->disk_pos.cluster = 0;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1972 dentry->disk_pos.cluster_snum = 0;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1973 dentry->disk_pos.cluster_pos = 0;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1974 }
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1975
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1976 // -------------------------------------------------------------------------
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1977 // fatfs_get_disk_usage()
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1978 // Gets disk space.
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1979
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1980 int
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1981 fatfs_get_disk_usage(fatfs_disk_t *disk,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1982 cyg_uint32 *total_clusters,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1983 cyg_uint32 *free_clusters)
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1984 {
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1985 cyg_uint32 c, nfree, tentry;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1986 int err;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1987
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1988 nfree = 0;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1989 for (c = 2; c < disk->fat_tbl_nents; c++)
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1990 {
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1991 err = read_tentry(disk, c, &tentry);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1992 if (err != ENOERR)
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1993 return err;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1994
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1995 if (TENTRY_FREE == get_tentry_type(disk, tentry))
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1996 nfree++;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1997 }
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1998
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
1999 *total_clusters = disk->fat_tbl_nents - 2;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2000 *free_clusters = nfree;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2001
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2002 return ENOERR;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2003 }
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2004
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2005
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2006 // -------------------------------------------------------------------------
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2007 // fatfs_read_dir_entry()
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2008 // Reads dir entry at given position.
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2009 // If there is no dir entry at given position the next closest is returned
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2010 // and the position is updated. If EEOF error is returned, then there are
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2011 // no more dir entries in given dir.
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2012
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2013 int
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2014 fatfs_read_dir_entry(fatfs_disk_t *disk,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2015 fatfs_dir_entry_t *dir,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2016 fatfs_data_pos_t *pos,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2017 fatfs_dir_entry_t *dentry)
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2018 {
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2019 fat_raw_dir_entry_t raw_dentry;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2020 int err;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2021
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2022 CYG_CHECK_DATA_PTRC(disk);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2023 CYG_CHECK_DATA_PTRC(dir);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2024 CYG_CHECK_DATA_PTRC(pos);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2025 CYG_CHECK_DATA_PTRC(dentry);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2026
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2027 err = read_next_raw_dentry(disk, pos, &raw_dentry);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2028 if (err != ENOERR)
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2029 return err;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2030
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2031 raw_to_dentry(&raw_dentry, pos, dentry);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2032 dentry->parent_cluster = dir->cluster;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2033
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2034 // Increment position for next call
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2035 pos->cluster_pos += DENTRY_SIZE;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2036
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2037 return ENOERR;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2038 }
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2039
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2040 // -------------------------------------------------------------------------
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2041 // fatfs_initpos()
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2042 // Initializes position to the start of the given file.
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2043
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2044 int
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2045 fatfs_initpos(fatfs_disk_t *disk,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2046 fatfs_dir_entry_t *file,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2047 fatfs_data_pos_t *pos)
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2048 {
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2049 CYG_CHECK_DATA_PTRC(disk);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2050 CYG_CHECK_DATA_PTRC(file);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2051 CYG_CHECK_DATA_PTRC(pos);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2052
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2053 pos->cluster = file->cluster;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2054 pos->cluster_snum = 0;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2055 pos->cluster_pos = 0;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2056
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2057 return ENOERR;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2058 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2059
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2060 // -------------------------------------------------------------------------
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2061 // fatfs_setpos()
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2062 // Sets the file position from offset.
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2063
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2064 int
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2065 fatfs_setpos(fatfs_disk_t *disk,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2066 fatfs_dir_entry_t *file,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2067 fatfs_data_pos_t *pos,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2068 cyg_uint32 offset)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2069 {
1975
187dfdcdf712 * src/fatfs_supp.c: lseek returned EEOF when at the end of the
asl
parents: 1869
diff changeset
2070 int err;
187dfdcdf712 * src/fatfs_supp.c: lseek returned EEOF when at the end of the
asl
parents: 1869
diff changeset
2071
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2072 CYG_CHECK_DATA_PTRC(disk);
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2073 CYG_CHECK_DATA_PTRC(file);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2074 CYG_CHECK_DATA_PTRC(pos);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2075
1975
187dfdcdf712 * src/fatfs_supp.c: lseek returned EEOF when at the end of the
asl
parents: 1869
diff changeset
2076 err = get_position_from_off(disk, file->cluster, offset, pos, CO_NONE);
187dfdcdf712 * src/fatfs_supp.c: lseek returned EEOF when at the end of the
asl
parents: 1869
diff changeset
2077
187dfdcdf712 * src/fatfs_supp.c: lseek returned EEOF when at the end of the
asl
parents: 1869
diff changeset
2078 if (EEOF == err && offset == file->size)
187dfdcdf712 * src/fatfs_supp.c: lseek returned EEOF when at the end of the
asl
parents: 1869
diff changeset
2079 return ENOERR;
187dfdcdf712 * src/fatfs_supp.c: lseek returned EEOF when at the end of the
asl
parents: 1869
diff changeset
2080 else
187dfdcdf712 * src/fatfs_supp.c: lseek returned EEOF when at the end of the
asl
parents: 1869
diff changeset
2081 return err;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2082 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2083
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2084 // -------------------------------------------------------------------------
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2085 // fatfs_getpos()
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2086 // Gets the file offset from position.
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2087
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2088 cyg_uint32
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2089 fatfs_getpos(fatfs_disk_t *disk,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2090 fatfs_dir_entry_t *file,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2091 fatfs_data_pos_t *pos)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2092 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2093 CYG_CHECK_DATA_PTRC(disk);
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2094 CYG_CHECK_DATA_PTRC(file);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2095 CYG_CHECK_DATA_PTRC(pos);
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2096
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2097 return (pos->cluster_snum << disk->cluster_size_log2) + pos->cluster_pos;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2098 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2099
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2100 // -------------------------------------------------------------------------
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2101 // fatfs_write_dir_entry()
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2102 // Writes dir entry to disk.
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2103
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2104 int
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2105 fatfs_write_dir_entry(fatfs_disk_t *disk, fatfs_dir_entry_t *dentry)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2106 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2107 fat_raw_dir_entry_t raw_dentry;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2108 int err;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2109
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2110 CYG_CHECK_DATA_PTRC(disk);
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2111 CYG_CHECK_DATA_PTRC(dentry);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2112
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2113 dentry_to_raw(dentry, &raw_dentry);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2114 err = write_raw_dentry(disk, &dentry->disk_pos, &raw_dentry);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2115 return err;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2116 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2117
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2118 // -------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2119 // fatfs_delete_file()
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2120 // Marks dir entry as deleted and frees its cluster chain.
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2121
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2122 int
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2123 fatfs_delete_file(fatfs_disk_t *disk, fatfs_dir_entry_t *file)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2124 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2125 fat_raw_dir_entry_t raw_dentry;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2126 int err;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2127
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2128 CYG_CHECK_DATA_PTRC(disk);
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2129 CYG_CHECK_DATA_PTRC(file);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2130
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2131 if (is_root_dir_entry(file))
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2132 return EINVAL;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2133
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2134 CYG_TRACE1(TDE, "filename='%s'", file->filename);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2135
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2136 dentry_to_raw(file, &raw_dentry);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2137
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2138 // Check if we are about to delete a directory
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2139 if (DENTRY_IS_DIR(&raw_dentry))
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2140 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2141 fat_raw_dir_entry_t raw_cdentry;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2142 fatfs_data_pos_t pos;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2143 int i = 0;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2144
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2145 fatfs_initpos(disk, file, &pos);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2146
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2147 CYG_TRACE0(TDE, "got directory");
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2148
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2149 // Count number of entries in this dir
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2150
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2151 while (true)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2152 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2153 err = read_next_raw_dentry(disk, &pos, &raw_cdentry);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2154
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2155 if (EEOF == err)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2156 break;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2157 else if (err != ENOERR)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2158 return err;
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2159
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2160 pos.cluster_pos += DENTRY_SIZE;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2161 i++;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2162 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2163 CYG_TRACE1(TDE, "child count=%d", i);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2164
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2165 // Check if the dir is empty (except '.' and '..')
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2166 if (i > 2)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2167 return EPERM;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2168 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2169
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2170 // Free file clusters
2364
028e0fe198b5 * src/fatfs_supp.c: Fixed FAT32 cluster handling in
asl
parents: 2044
diff changeset
2171 free_cluster_chain(disk, raw_dentry.cluster | (raw_dentry.cluster_HI << 16));
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2172 raw_dentry_set_deleted(disk, &raw_dentry);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2173 err = write_raw_dentry(disk, &file->disk_pos, &raw_dentry);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2174 return err;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2175 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2176
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2177 // -------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2178 // fatfs_create_file()
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2179 // Creates a new file.
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2180
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2181 int
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2182 fatfs_create_file(fatfs_disk_t *disk,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2183 fatfs_dir_entry_t *dir,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2184 const char *name,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2185 int namelen,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2186 fatfs_dir_entry_t *dentry)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2187 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2188 fatfs_data_pos_t pos;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2189 int err;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2190
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2191 CYG_CHECK_DATA_PTRC(disk);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2192 CYG_CHECK_DATA_PTRC(dir);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2193 CYG_CHECK_DATA_PTRC(name);
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2194 CYG_CHECK_DATA_PTRC(dentry);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2195
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2196 CYG_TRACE2(TDE, "filename='%s' parent='%s'", name, dir->filename);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2197
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2198 fatfs_initpos(disk, dir, &pos);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2199
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2200 // Get free dir entry in parent dir
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2201 err = get_free_raw_dentry(disk, &pos);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2202 if (err != ENOERR)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2203 return err;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2204
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2205 // Create new file dir entry
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2206
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2207 init_dir_entry(dentry,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2208 name,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2209 namelen,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2210 __stat_mode_REG,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2211 dir->cluster,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2212 0,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2213 &pos);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2214
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2215 err = fatfs_write_dir_entry(disk, dentry);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2216 if (err != ENOERR)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2217 return err;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2218
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2219 return ENOERR;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2220 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2221
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2222 // -------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2223 // fatfs_create_dir()
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2224 // Creates a new directory.
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2225
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2226 int
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2227 fatfs_create_dir(fatfs_disk_t *disk,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2228 fatfs_dir_entry_t *dir,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2229 const char *name,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2230 int namelen,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2231 fatfs_dir_entry_t *dentry)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2232 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2233 fatfs_dir_entry_t cdentry;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2234 fatfs_data_pos_t pos;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2235 cyg_uint32 free_cluster;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2236 int err;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2237
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2238 CYG_CHECK_DATA_PTRC(disk);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2239 CYG_CHECK_DATA_PTRC(dir);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2240 CYG_CHECK_DATA_PTRC(name);
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2241 CYG_CHECK_DATA_PTRC(dentry);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2242
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2243 CYG_TRACE2(TDE, "filename='%s' parent='%s'", name, dir->filename);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2244
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2245 // Get free cluster
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2246 err = find_next_free_cluster(disk,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2247 0,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2248 &free_cluster,
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2249 CO_MARK_LAST | CO_ERASE_NEW);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2250 if (err != ENOERR)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2251 return err;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2252
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2253 fatfs_initpos(disk, dir, &pos);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2254
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2255 // Get free dir entry in parent dir
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2256 err = get_free_raw_dentry(disk, &pos);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2257 if (err != ENOERR)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2258 return err;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2259
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2260 // Create new dir entry
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2261
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2262 init_dir_entry(dentry,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2263 name,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2264 namelen,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2265 __stat_mode_DIR,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2266 dir->cluster,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2267 free_cluster,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2268 &pos);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2269
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2270 err = fatfs_write_dir_entry(disk, dentry);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2271 if (err != ENOERR)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2272 return err;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2273
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2274 // Create '.' and '..' dir entries
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2275
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2276 fatfs_initpos(disk, dentry, &pos);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2277
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2278 CYG_TRACE0(TDE, "Creating '.' entry");
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2279
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2280 init_dir_entry(&cdentry,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2281 ".",
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2282 0,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2283 __stat_mode_DIR,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2284 dentry->cluster,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2285 dentry->cluster,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2286 &pos);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2287
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2288 err = fatfs_write_dir_entry(disk, &cdentry);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2289 if (err != ENOERR)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2290 return err;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2291
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2292 pos.cluster_pos += DENTRY_SIZE;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2293
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2294 CYG_TRACE0(TDE, "Creating '..' entry");
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2295
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2296 init_dir_entry(&cdentry,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2297 "..",
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2298 0,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2299 __stat_mode_DIR,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2300 dentry->cluster,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2301 dir->cluster,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2302 &pos);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2303
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2304 err = fatfs_write_dir_entry(disk, &cdentry);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2305 if (err != ENOERR)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2306 return err;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2307
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2308 return ENOERR;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2309 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2310
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2311 // -------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2312 // fatfs_trunc_file()
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2313 // Truncates a file to zero length.
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2314
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2315 int
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2316 fatfs_trunc_file(fatfs_disk_t *disk, fatfs_dir_entry_t *file)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2317 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2318 int err;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2319
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2320 CYG_CHECK_DATA_PTRC(disk);
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2321 CYG_CHECK_DATA_PTRC(file);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2322
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2323 CYG_TRACE1(TDE, "file='%s'", file->filename);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2324
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2325 if (S_ISDIR(file->mode))
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2326 return EINVAL;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2327
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2328 if (0 == file->size)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2329 return ENOERR;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2330
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2331 err = free_cluster_chain(disk, file->cluster);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2332 if (err != ENOERR)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2333 return err;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2334
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2335 // Update file attributes
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2336
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2337 file->cluster = 0;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2338 file->size = 0;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2339 file->mtime =
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2340 file->atime = cyg_timestamp();
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2341
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2342 return fatfs_write_dir_entry(disk, file);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2343 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2344
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2345 // -------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2346 // fatfs_rename_file()
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2347 // Renames a file.
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2348
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2349 int
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2350 fatfs_rename_file(fatfs_disk_t *disk,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2351 fatfs_dir_entry_t *dir1,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2352 fatfs_dir_entry_t *target,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2353 fatfs_dir_entry_t *dir2,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2354 const char *name,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2355 int namelen)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2356 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2357 fat_raw_dir_entry_t raw_dentry;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2358 fatfs_data_pos_t new_pos;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2359 int err;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2360
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2361 CYG_CHECK_DATA_PTRC(disk);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2362 CYG_CHECK_DATA_PTRC(dir1);
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2363 CYG_CHECK_DATA_PTRC(target);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2364 CYG_CHECK_DATA_PTRC(dir2);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2365 CYG_CHECK_DATA_PTRC(name);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2366
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2367 if (is_root_dir_entry(target))
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2368 return EINVAL;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2369
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2370 strncpy(target->filename, name, namelen);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2371 target->filename[namelen] = '\0';
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2372
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2373 // Moving around in same dir
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2374
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2375 if (dir1 == dir2)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2376 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2377 CYG_TRACE0(TDE, "same dir");
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2378 return fatfs_write_dir_entry(disk, target);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2379 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2380
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2381 CYG_TRACE0(TDE, "different dirs");
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2382
2483
3071a60a92da * src/fatfs.c: Fix handling of '.' and '..' nodes in dirsearch.
asl
parents: 2364
diff changeset
2383 // Moving around in different dirs
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2384
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2385 fatfs_initpos(disk, dir2, &new_pos);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2386
2483
3071a60a92da * src/fatfs.c: Fix handling of '.' and '..' nodes in dirsearch.
asl
parents: 2364
diff changeset
2387 CYG_TRACE0(TDE, "writing to new dir");
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2388
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2389 // Get free dir entry in target dir
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2390
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2391 err = get_free_raw_dentry(disk, &new_pos);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2392 if (err != ENOERR)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2393 return err;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2394
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2395 // Write file dentry to new location
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2396
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2397 dentry_to_raw(target, &raw_dentry);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2398 err = write_raw_dentry(disk, &new_pos, &raw_dentry);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2399 if (err != ENOERR)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2400 return err;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2401
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2402 CYG_TRACE0(TDE, "deleting from old dir");
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2403
2483
3071a60a92da * src/fatfs.c: Fix handling of '.' and '..' nodes in dirsearch.
asl
parents: 2364
diff changeset
2404 // Delete dentry at old location
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2405
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2406 raw_dentry_set_deleted(disk, &raw_dentry);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2407 raw_dentry.size = 0;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2408 raw_dentry.cluster = 0;
2364
028e0fe198b5 * src/fatfs_supp.c: Fixed FAT32 cluster handling in
asl
parents: 2044
diff changeset
2409 raw_dentry.cluster_HI = 0;
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2410 err = write_raw_dentry(disk, &target->disk_pos, &raw_dentry);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2411 if (err != ENOERR)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2412 return err;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2413
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2414 // Set file new position and parent cluster
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2415
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2416 target->disk_pos = new_pos;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2417 target->parent_cluster = dir2->cluster;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2418
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2419 // If we moved a directory, we also have to correct the '..' entry
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2420
1818
5663e2763ba6 * src/fatfs.c:
asl
parents: 1784
diff changeset
2421 if ( S_ISDIR(target->mode) )
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2422 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2423 fat_raw_dir_entry_t raw_cdentry;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2424 fatfs_data_pos_t pos;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2425
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2426 fatfs_initpos(disk, target, &pos);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2427
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2428 CYG_TRACE0(TDE, "moving directory - correcting '..' entry");
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2429
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2430 while (true)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2431 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2432 err = read_next_raw_dentry(disk, &pos, &raw_cdentry);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2433
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2434 if (EEOF == err)
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2435 return EINVAL; // This dir doesn't have the '..' entry,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2436 // that means something is very wrong
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2437 else if (err != ENOERR)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2438 return err;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2439
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2440 if (0 == strncmp("..", raw_cdentry.name, 2))
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2441 {
2364
028e0fe198b5 * src/fatfs_supp.c: Fixed FAT32 cluster handling in
asl
parents: 2044
diff changeset
2442 raw_cdentry.cluster = dir2->cluster & 0xFFFF;
028e0fe198b5 * src/fatfs_supp.c: Fixed FAT32 cluster handling in
asl
parents: 2044
diff changeset
2443 raw_cdentry.cluster_HI = dir2->cluster >> 16;
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2444 err = write_raw_dentry(disk, &pos, &raw_cdentry);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2445 if (err != ENOERR)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2446 return err;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2447 break;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2448 }
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2449
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2450 pos.cluster_pos += DENTRY_SIZE;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2451 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2452 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2453
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2454 return ENOERR;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2455 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2456
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2457 // -------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2458 // fatfs_read_data()
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2459 // Reads data from disk.
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2460
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2461 int
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2462 fatfs_read_data(fatfs_disk_t *disk,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2463 fatfs_dir_entry_t *file,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2464 fatfs_data_pos_t *pos,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2465 void *data,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2466 cyg_uint32 *len)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2467 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2468 CYG_CHECK_DATA_PTRC(disk);
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2469 CYG_CHECK_DATA_PTRC(file);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2470 CYG_CHECK_DATA_PTRC(data);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2471 CYG_CHECK_DATA_PTRC(len);
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2472 CYG_CHECK_DATA_PTRC(pos);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2473
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2474 return read_data(disk, data, len, pos);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2475 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2477 // -------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2478 // fatfs_write_data()
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2479 // Writes data to disk.
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2480
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2481 int
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2482 fatfs_write_data(fatfs_disk_t *disk,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2483 fatfs_dir_entry_t *file,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2484 fatfs_data_pos_t *pos,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2485 void *data,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2486 cyg_uint32 *len)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2487 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2488 int err;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2489
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2490 CYG_CHECK_DATA_PTRC(disk);
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2491 CYG_CHECK_DATA_PTRC(file);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2492 CYG_CHECK_DATA_PTRC(data);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2493 CYG_CHECK_DATA_PTRC(len);
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2494 CYG_CHECK_DATA_PTRC(pos);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2495
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2496 // Check if this file has a zero size and no first cluster
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2497
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2498 if (0 == file->size && 0 == file->cluster)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2499 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2500 cyg_uint32 free_cluster;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2501
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2502 CYG_TRACE0(TDO, "new cluster for zero file");
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2503
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2504 err = find_next_free_cluster(disk, 0, &free_cluster, CO_MARK_LAST);
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2505
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2506 if (err != ENOERR)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2507 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2508 *len = 0;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2509 return err;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2510 }
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2511
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2512 file->cluster = free_cluster;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2513 fatfs_initpos(disk, file, pos);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2514 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2515
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
2516 return write_data(disk, data, len, pos);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2517 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2518
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2519 // -------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2520 // Support routines
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2521 // These enable the definition of local versions of certain routines
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2522 // if the given packages are not present.
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2523
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2524 #ifndef CYGPKG_LIBC_I18N
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2525
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2526 __externC int
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2527 toupper( int c )
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2528 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2529 return (('a' <= c) && (c <= 'z')) ? c - 'a' + 'A' : c ;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2530 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2531
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2532 #endif
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2533
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2534 #ifndef CYGFUN_LIBC_STRING_BSD_FUNCS
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2535
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2536 __externC int
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2537 strcasecmp( const char *s1, const char *s2 )
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2538 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2539 int ret;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2540 CYG_REPORT_FUNCNAMETYPE( "strcasecmp", "returning %d" );
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2541 CYG_REPORT_FUNCARG2( "s1=%08x, s2=%08x", s1, s2 );
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2542
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2543 CYG_CHECK_DATA_PTR( s1, "s1 is not a valid pointer!" );
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2544 CYG_CHECK_DATA_PTR( s2, "s2 is not a valid pointer!" );
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2545
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2546 while (*s1 != '\0' && toupper(*s1) == toupper(*s2))
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2547 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2548 s1++;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2549 s2++;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2550 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2551
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2552 ret = toupper(*(unsigned char *) s1) - toupper(*(unsigned char *) s2);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2553 CYG_REPORT_RETVAL( ret );
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2554 return ret;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2555 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2556
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2557 __externC int
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2558 strncasecmp( const char *s1, const char *s2, size_t n )
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2559 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2560 int ret;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2561 CYG_REPORT_FUNCNAMETYPE( "strncasecmp", "returning %d" );
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2562 CYG_REPORT_FUNCARG3( "s1=%08x, s2=%08x, n=%d", s1, s2, n );
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2563
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2564 if (n == 0)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2565 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2566 CYG_REPORT_RETVAL(0);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2567 return 0;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2568 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2569
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2570 CYG_CHECK_DATA_PTR( s1, "s1 is not a valid pointer!" );
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2571 CYG_CHECK_DATA_PTR( s2, "s2 is not a valid pointer!" );
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2572
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2573 while (n-- != 0 && toupper(*s1) == toupper(*s2))
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2574 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2575 if (n == 0 || *s1 == '\0' || *s2 == '\0')
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2576 break;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2577 s1++;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2578 s2++;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2579 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2580
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2581 ret = toupper(*(unsigned char *) s1) - toupper(*(unsigned char *) s2);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2582 CYG_REPORT_RETVAL( ret );
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2583 return ret;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2584 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2585
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2586 #endif
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2587
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2588 // -------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2589 // EOF fatfs_supp.c