MCPcopy Create free account
hub / github.com/PaulStoffregen/SerialFlash / open

Method open

SerialFlashDirectory.cpp:128–176  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

126#endif
127
128SerialFlashFile SerialFlashChip::open(const char *filename)
129{
130 uint32_t maxfiles, straddr;
131 uint16_t hash, hashtable[8];
132 uint32_t i, n, index=0;
133 uint32_t buf[3];
134 SerialFlashFile file;
135
136 maxfiles = check_signature();
137 //Serial.printf("sig: %08X\n", maxfiles);
138 if (!maxfiles) return file;
139 maxfiles &= 0xFFFF;
140 hash = filename_hash(filename);
141 //Serial.printf("hash %04X for \"%s\"\n", hash, filename);
142 while (index < maxfiles) {
143 n = 8;
144 if (n > maxfiles - index) n = maxfiles - index;
145 SerialFlash.read(8 + index * 2, hashtable, n * 2);
146 //Serial.printf(" read %u: ", 8 + index * 2);
147 //pbuf(hashtable, n * 2);
148 for (i=0; i < n; i++) {
149 if (hashtable[i] == hash) {
150 //Serial.printf(" hash match at index %u\n", index+i);
151 buf[2] = 0;
152 SerialFlash.read(8 + maxfiles * 2 + (index+i) * 10, buf, 10);
153
154 //Serial.printf(" maxf=%d, index=%d, i=%d\n", maxfiles, index, i);
155 //Serial.printf(" read %u: ", 8 + maxfiles * 2 + (index+i) * 10);
156 //pbuf(buf, 10);
157 straddr = 8 + maxfiles * 12 + buf[2] * 4;
158 //Serial.printf(" straddr = %u\n", straddr);
159 if (filename_compare(filename, straddr)) {
160 //Serial.printf(" match!\n");
161 //Serial.printf(" addr = %u\n", buf[0]);
162 //Serial.printf(" len = %u\n", buf[1]);
163 file.address = buf[0];
164 file.length = buf[1];
165 file.offset = 0;
166 file.dirindex = index + i;
167 return file;
168 }
169 } else if (hashtable[i] == 0xFFFF) {
170 return file;
171 }
172 }
173 index += n;
174 }
175 return file;
176}
177
178bool SerialFlashChip::exists(const char *filename)
179{

Callers

nothing calls this directly

Calls 4

check_signatureFunction · 0.85
filename_hashFunction · 0.85
filename_compareFunction · 0.85
readMethod · 0.45

Tested by

no test coverage detected