SdVolume.h

Sat, 07 Nov 2015 13:23:07 +0100

author
mbayer
date
Sat, 07 Nov 2015 13:23:07 +0100
changeset 0
2c8ba1964db7
permissions
-rw-r--r--

Initial code from reprappro Marlin repository

0
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
1 /* Arduino SdFat Library
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
2 * Copyright (C) 2009 by William Greiman
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
3 *
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
4 * This file is part of the Arduino SdFat Library
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
5 *
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
6 * This Library is free software: you can redistribute it and/or modify
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
8 * the Free Software Foundation, either version 3 of the License, or
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
9 * (at your option) any later version.
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
10 *
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
11 * This Library is distributed in the hope that it will be useful,
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
14 * GNU General Public License for more details.
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
15 *
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
17 * along with the Arduino SdFat Library. If not, see
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
18 * <http://www.gnu.org/licenses/>.
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
19 */
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
20 #include "Marlin.h"
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
21 #ifdef SDSUPPORT
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
22 #ifndef SdVolume_h
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
23 #define SdVolume_h
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
24 /**
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
25 * \file
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
26 * \brief SdVolume class
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
27 */
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
28 #include "SdFatConfig.h"
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
29 #include "Sd2Card.h"
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
30 #include "SdFatStructs.h"
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
31
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
32 //==============================================================================
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
33 // SdVolume class
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
34 /**
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
35 * \brief Cache for an SD data block
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
36 */
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
37 union cache_t {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
38 /** Used to access cached file data blocks. */
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
39 uint8_t data[512];
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
40 /** Used to access cached FAT16 entries. */
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
41 uint16_t fat16[256];
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
42 /** Used to access cached FAT32 entries. */
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
43 uint32_t fat32[128];
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
44 /** Used to access cached directory entries. */
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
45 dir_t dir[16];
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
46 /** Used to access a cached Master Boot Record. */
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
47 mbr_t mbr;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
48 /** Used to access to a cached FAT boot sector. */
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
49 fat_boot_t fbs;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
50 /** Used to access to a cached FAT32 boot sector. */
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
51 fat32_boot_t fbs32;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
52 /** Used to access to a cached FAT32 FSINFO sector. */
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
53 fat32_fsinfo_t fsinfo;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
54 };
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
55 //------------------------------------------------------------------------------
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
56 /**
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
57 * \class SdVolume
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
58 * \brief Access FAT16 and FAT32 volumes on SD and SDHC cards.
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
59 */
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
60 class SdVolume {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
61 public:
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
62 /** Create an instance of SdVolume */
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
63 SdVolume() : fatType_(0) {}
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
64 /** Clear the cache and returns a pointer to the cache. Used by the WaveRP
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
65 * recorder to do raw write to the SD card. Not for normal apps.
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
66 * \return A pointer to the cache buffer or zero if an error occurs.
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
67 */
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
68 cache_t* cacheClear() {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
69 if (!cacheFlush()) return 0;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
70 cacheBlockNumber_ = 0XFFFFFFFF;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
71 return &cacheBuffer_;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
72 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
73 /** Initialize a FAT volume. Try partition one first then try super
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
74 * floppy format.
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
75 *
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
76 * \param[in] dev The Sd2Card where the volume is located.
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
77 *
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
78 * \return The value one, true, is returned for success and
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
79 * the value zero, false, is returned for failure. Reasons for
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
80 * failure include not finding a valid partition, not finding a valid
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
81 * FAT file system or an I/O error.
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
82 */
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
83 bool init(Sd2Card* dev) { return init(dev, 1) ? true : init(dev, 0);}
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
84 bool init(Sd2Card* dev, uint8_t part);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
85
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
86 // inline functions that return volume info
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
87 /** \return The volume's cluster size in blocks. */
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
88 uint8_t blocksPerCluster() const {return blocksPerCluster_;}
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
89 /** \return The number of blocks in one FAT. */
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
90 uint32_t blocksPerFat() const {return blocksPerFat_;}
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
91 /** \return The total number of clusters in the volume. */
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
92 uint32_t clusterCount() const {return clusterCount_;}
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
93 /** \return The shift count required to multiply by blocksPerCluster. */
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
94 uint8_t clusterSizeShift() const {return clusterSizeShift_;}
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
95 /** \return The logical block number for the start of file data. */
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
96 uint32_t dataStartBlock() const {return dataStartBlock_;}
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
97 /** \return The number of FAT structures on the volume. */
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
98 uint8_t fatCount() const {return fatCount_;}
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
99 /** \return The logical block number for the start of the first FAT. */
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
100 uint32_t fatStartBlock() const {return fatStartBlock_;}
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
101 /** \return The FAT type of the volume. Values are 12, 16 or 32. */
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
102 uint8_t fatType() const {return fatType_;}
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
103 int32_t freeClusterCount();
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
104 /** \return The number of entries in the root directory for FAT16 volumes. */
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
105 uint32_t rootDirEntryCount() const {return rootDirEntryCount_;}
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
106 /** \return The logical block number for the start of the root directory
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
107 on FAT16 volumes or the first cluster number on FAT32 volumes. */
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
108 uint32_t rootDirStart() const {return rootDirStart_;}
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
109 /** Sd2Card object for this volume
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
110 * \return pointer to Sd2Card object.
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
111 */
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
112 Sd2Card* sdCard() {return sdCard_;}
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
113 /** Debug access to FAT table
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
114 *
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
115 * \param[in] n cluster number.
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
116 * \param[out] v value of entry
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
117 * \return true for success or false for failure
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
118 */
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
119 bool dbgFat(uint32_t n, uint32_t* v) {return fatGet(n, v);}
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
120 //------------------------------------------------------------------------------
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
121 private:
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
122 // Allow SdBaseFile access to SdVolume private data.
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
123 friend class SdBaseFile;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
124
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
125 // value for dirty argument in cacheRawBlock to indicate read from cache
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
126 static bool const CACHE_FOR_READ = false;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
127 // value for dirty argument in cacheRawBlock to indicate write to cache
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
128 static bool const CACHE_FOR_WRITE = true;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
129
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
130 #if USE_MULTIPLE_CARDS
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
131 cache_t cacheBuffer_; // 512 byte cache for device blocks
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
132 uint32_t cacheBlockNumber_; // Logical number of block in the cache
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
133 Sd2Card* sdCard_; // Sd2Card object for cache
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
134 bool cacheDirty_; // cacheFlush() will write block if true
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
135 uint32_t cacheMirrorBlock_; // block number for mirror FAT
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
136 #else // USE_MULTIPLE_CARDS
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
137 static cache_t cacheBuffer_; // 512 byte cache for device blocks
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
138 static uint32_t cacheBlockNumber_; // Logical number of block in the cache
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
139 static Sd2Card* sdCard_; // Sd2Card object for cache
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
140 static bool cacheDirty_; // cacheFlush() will write block if true
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
141 static uint32_t cacheMirrorBlock_; // block number for mirror FAT
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
142 #endif // USE_MULTIPLE_CARDS
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
143 uint32_t allocSearchStart_; // start cluster for alloc search
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
144 uint8_t blocksPerCluster_; // cluster size in blocks
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
145 uint32_t blocksPerFat_; // FAT size in blocks
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
146 uint32_t clusterCount_; // clusters in one FAT
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
147 uint8_t clusterSizeShift_; // shift to convert cluster count to block count
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
148 uint32_t dataStartBlock_; // first data block number
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
149 uint8_t fatCount_; // number of FATs on volume
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
150 uint32_t fatStartBlock_; // start block for first FAT
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
151 uint8_t fatType_; // volume type (12, 16, OR 32)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
152 uint16_t rootDirEntryCount_; // number of entries in FAT16 root dir
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
153 uint32_t rootDirStart_; // root start block for FAT16, cluster for FAT32
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
154 //----------------------------------------------------------------------------
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
155 bool allocContiguous(uint32_t count, uint32_t* curCluster);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
156 uint8_t blockOfCluster(uint32_t position) const {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
157 return (position >> 9) & (blocksPerCluster_ - 1);}
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
158 uint32_t clusterStartBlock(uint32_t cluster) const {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
159 return dataStartBlock_ + ((cluster - 2) << clusterSizeShift_);}
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
160 uint32_t blockNumber(uint32_t cluster, uint32_t position) const {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
161 return clusterStartBlock(cluster) + blockOfCluster(position);}
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
162 cache_t *cache() {return &cacheBuffer_;}
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
163 uint32_t cacheBlockNumber() {return cacheBlockNumber_;}
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
164 #if USE_MULTIPLE_CARDS
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
165 bool cacheFlush();
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
166 bool cacheRawBlock(uint32_t blockNumber, bool dirty);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
167 #else // USE_MULTIPLE_CARDS
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
168 static bool cacheFlush();
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
169 static bool cacheRawBlock(uint32_t blockNumber, bool dirty);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
170 #endif // USE_MULTIPLE_CARDS
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
171 // used by SdBaseFile write to assign cache to SD location
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
172 void cacheSetBlockNumber(uint32_t blockNumber, bool dirty) {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
173 cacheDirty_ = dirty;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
174 cacheBlockNumber_ = blockNumber;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
175 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
176 void cacheSetDirty() {cacheDirty_ |= CACHE_FOR_WRITE;}
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
177 bool chainSize(uint32_t beginCluster, uint32_t* size);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
178 bool fatGet(uint32_t cluster, uint32_t* value);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
179 bool fatPut(uint32_t cluster, uint32_t value);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
180 bool fatPutEOC(uint32_t cluster) {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
181 return fatPut(cluster, 0x0FFFFFFF);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
182 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
183 bool freeChain(uint32_t cluster);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
184 bool isEOC(uint32_t cluster) const {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
185 if (FAT12_SUPPORT && fatType_ == 12) return cluster >= FAT12EOC_MIN;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
186 if (fatType_ == 16) return cluster >= FAT16EOC_MIN;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
187 return cluster >= FAT32EOC_MIN;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
188 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
189 bool readBlock(uint32_t block, uint8_t* dst) {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
190 return sdCard_->readBlock(block, dst);}
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
191 bool writeBlock(uint32_t block, const uint8_t* dst) {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
192 return sdCard_->writeBlock(block, dst);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
193 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
194 //------------------------------------------------------------------------------
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
195 // Deprecated functions - suppress cpplint warnings with NOLINT comment
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
196 #if ALLOW_DEPRECATED_FUNCTIONS && !defined(DOXYGEN)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
197 public:
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
198 /** \deprecated Use: bool SdVolume::init(Sd2Card* dev);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
199 * \param[in] dev The SD card where the volume is located.
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
200 * \return true for success or false for failure.
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
201 */
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
202 bool init(Sd2Card& dev) {return init(&dev);} // NOLINT
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
203 /** \deprecated Use: bool SdVolume::init(Sd2Card* dev, uint8_t vol);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
204 * \param[in] dev The SD card where the volume is located.
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
205 * \param[in] part The partition to be used.
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
206 * \return true for success or false for failure.
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
207 */
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
208 bool init(Sd2Card& dev, uint8_t part) { // NOLINT
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
209 return init(&dev, part);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
210 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
211 #endif // ALLOW_DEPRECATED_FUNCTIONS
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
212 };
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
213 #endif // SdVolume
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
214 #endif

mercurial