annotate packages/fs/fat/current/src/fatfs_supp.c @ 2533:4f15eaebbf32

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