* Open a volume's root directory. * * \param[in] vol The FAT volume containing the root directory to be opened. * * \return true for success, false for failure. * Reasons for failure include the file is already open, the FAT volume has * not been initialized or it a FAT12 volume. */
| 1240 | * not been initialized or it a FAT12 volume. |
| 1241 | */ |
| 1242 | bool SdBaseFile::openRoot(SdVolume *vol) { |
| 1243 | // error if file is already open |
| 1244 | if (isOpen()) return false; |
| 1245 | |
| 1246 | if (vol->fatType() == 16 || (FAT12_SUPPORT && vol->fatType() == 12)) { |
| 1247 | type_ = FAT_FILE_TYPE_ROOT_FIXED; |
| 1248 | firstCluster_ = 0; |
| 1249 | fileSize_ = 32 * vol->rootDirEntryCount(); |
| 1250 | } |
| 1251 | else if (vol->fatType() == 32) { |
| 1252 | type_ = FAT_FILE_TYPE_ROOT32; |
| 1253 | firstCluster_ = vol->rootDirStart(); |
| 1254 | if (!vol->chainSize(firstCluster_, &fileSize_)) return false; |
| 1255 | } |
| 1256 | else // volume is not initialized, invalid, or FAT12 without support |
| 1257 | return false; |
| 1258 | |
| 1259 | vol_ = vol; |
| 1260 | // read only |
| 1261 | flags_ = O_READ; |
| 1262 | |
| 1263 | // set to start of file |
| 1264 | curCluster_ = curPosition_ = 0; |
| 1265 | |
| 1266 | // root has no directory entry |
| 1267 | dirBlock_ = dirIndex_ = 0; |
| 1268 | return true; |
| 1269 | } |
| 1270 | |
| 1271 | /** |
| 1272 | * Return the next available byte without consuming it. |
no test coverage detected