open a cached directory entry. Assumes vol_ is initialized
| 902 | |
| 903 | // open a cached directory entry. Assumes vol_ is initialized |
| 904 | bool 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. |
no test coverage detected