|
|
|
|
1097
|
fail:
|
1097
|
fail:
|
1098
|
return -1;
|
1098
|
return -1;
|
1099
|
}
|
1099
|
}
|
1100
|
-//------------------------------------------------------------------------------
|
|
|
1101
|
-/** Read the next directory entry from a directory file.
|
|
|
|
|
1100
|
+
|
|
|
1101
|
+/**
|
|
|
1102
|
+ * Read the next entry in a directory.
|
1102
|
*
|
1103
|
*
|
1103
|
* \param[out] dir The dir_t struct that will receive the data.
|
1104
|
* \param[out] dir The dir_t struct that will receive the data.
|
1104
|
*
|
1105
|
*
|
|
|
|
|
1130
|
// Fill the long filename if we have a long filename entry.
|
1131
|
// Fill the long filename if we have a long filename entry.
|
1131
|
// Long filename entries are stored before the short filename.
|
1132
|
// Long filename entries are stored before the short filename.
|
1132
|
if (longFilename != NULL && DIR_IS_LONG_NAME(dir)) {
|
1133
|
if (longFilename != NULL && DIR_IS_LONG_NAME(dir)) {
|
1133
|
- vfat_t *VFAT = (vfat_t*)dir;
|
|
|
1134
|
- // Sanity-check the VFAT entry. The first cluster is always set to zero. And the sequence number should be higher than 0
|
|
|
1135
|
- if (VFAT->firstClusterLow == 0 && (VFAT->sequenceNumber & 0x1F) > 0 && (VFAT->sequenceNumber & 0x1F) <= MAX_VFAT_ENTRIES) {
|
|
|
1136
|
- // TODO: Store the filename checksum to verify if a none-long filename aware system modified the file table.
|
|
|
1137
|
- n = ((VFAT->sequenceNumber & 0x1F) - 1) * FILENAME_LENGTH;
|
|
|
|
|
1134
|
+ vfat_t *VFAT = (vfat_t*)dir;
|
|
|
1135
|
+ // Sanity-check the VFAT entry. The first cluster is always set to zero. And the sequence number should be higher than 0
|
|
|
1136
|
+ if (VFAT->firstClusterLow == 0 && (VFAT->sequenceNumber & 0x1F) > 0 && (VFAT->sequenceNumber & 0x1F) <= MAX_VFAT_ENTRIES) {
|
|
|
1137
|
+ // TODO: Store the filename checksum to verify if a none-long filename aware system modified the file table.
|
|
|
1138
|
+ n = ((VFAT->sequenceNumber & 0x1F) - 1) * FILENAME_LENGTH;
|
1138
|
for (uint8_t i=0; i<FILENAME_LENGTH; i++)
|
1139
|
for (uint8_t i=0; i<FILENAME_LENGTH; i++)
|
1139
|
longFilename[n+i] = (i < 5) ? VFAT->name1[i] : (i < 11) ? VFAT->name2[i-5] : VFAT->name3[i-11];
|
1140
|
longFilename[n+i] = (i < 5) ? VFAT->name1[i] : (i < 11) ? VFAT->name2[i-5] : VFAT->name3[i-11];
|
1140
|
// If this VFAT entry is the last one, add a NUL terminator at the end of the string
|
1141
|
// If this VFAT entry is the last one, add a NUL terminator at the end of the string
|
1141
|
if (VFAT->sequenceNumber & 0x40) longFilename[n+FILENAME_LENGTH] = '\0';
|
1142
|
if (VFAT->sequenceNumber & 0x40) longFilename[n+FILENAME_LENGTH] = '\0';
|
1142
|
- }
|
|
|
|
|
1143
|
+ }
|
1143
|
}
|
1144
|
}
|
1144
|
// Return if normal file or subdirectory
|
1145
|
// Return if normal file or subdirectory
|
1145
|
if (DIR_IS_FILE_OR_SUBDIR(dir)) return n;
|
1146
|
if (DIR_IS_FILE_OR_SUBDIR(dir)) return n;
|