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

Method openCachedEntry

Marlin/src/sd/SdBaseFile.cpp:904–950  ·  view source on GitHub ↗

open a cached directory entry. Assumes vol_ is initialized

Source from the content-addressed store, hash-verified

902
903// open a cached directory entry. Assumes vol_ is initialized
904bool SdBaseFile::openCachedEntry(const uint8_t dirIndex, const uint8_t oflag) {
905 dir_t *p;
906
907 #if ENABLED(SDCARD_READONLY)
908 if (oflag & (O_WRITE | O_CREAT | O_TRUNC)) goto FAIL;
909 #endif
910
911 // location of entry in cache
912 p = &vol_->cache()->dir[dirIndex];
913
914 // write or truncate is an error for a directory or read-only file
915 if (p->attributes & (DIR_ATT_READ_ONLY | DIR_ATT_DIRECTORY)) {
916 if (oflag & (O_WRITE | O_TRUNC)) goto FAIL;
917 }
918 // remember location of directory entry on SD
919 dirBlock_ = vol_->cacheBlockNumber();
920 dirIndex_ = dirIndex;
921
922 // copy first cluster number for directory fields
923 firstCluster_ = (uint32_t)p->firstClusterHigh << 16;
924 firstCluster_ |= p->firstClusterLow;
925
926 // make sure it is a normal file or subdirectory
927 if (DIR_IS_FILE(p)) {
928 fileSize_ = p->fileSize;
929 type_ = FAT_FILE_TYPE_NORMAL;
930 }
931 else if (DIR_IS_SUBDIR(p)) {
932 if (!vol_->chainSize(firstCluster_, &fileSize_)) goto FAIL;
933 type_ = FAT_FILE_TYPE_SUBDIR;
934 }
935 else
936 goto FAIL;
937
938 // save open flags for read/write
939 flags_ = oflag & F_OFLAG;
940
941 // set to start of file
942 curCluster_ = 0;
943 curPosition_ = 0;
944 if ((oflag & O_TRUNC) && !truncate(0)) return false;
945 return oflag & O_AT_END ? seekEnd(0) : true;
946
947 FAIL:
948 type_ = FAT_FILE_TYPE_CLOSED;
949 return false;
950}
951
952/**
953 * Open the next file or subdirectory in a directory.

Callers 1

openParentMethod · 0.80

Calls 5

DIR_IS_FILEFunction · 0.85
DIR_IS_SUBDIRFunction · 0.85
cacheMethod · 0.80
cacheBlockNumberMethod · 0.80
chainSizeMethod · 0.80

Tested by

no test coverage detected