MCPcopy Create free account
hub / github.com/MarlinFirmware/Marlin / openRoot

Method openRoot

Marlin/src/sd/SdBaseFile.cpp:1242–1269  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

1240 * not been initialized or it a FAT12 volume.
1241 */
1242bool 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.

Callers 4

mkdirMethod · 0.80
openMethod · 0.80
openParentMethod · 0.80
mountMethod · 0.80

Calls 4

fatTypeMethod · 0.80
rootDirEntryCountMethod · 0.80
rootDirStartMethod · 0.80
chainSizeMethod · 0.80

Tested by

no test coverage detected