MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / findEntryOffset

Function findEntryOffset

modules/io/storage/flash/storage-flash.c:136–204  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

134}
135
136static uint8_t findEntryOffset(const char *domain, const char *key, uint32_t *entryOffset, uint32_t *valueOffset, uint32_t *entrySize, uint8_t *buffer)
137{
138 uint32_t offset, endOffset;
139
140 if (!findStorageBlock(&offset)) {
141 if (domain && key)
142 return 0;
143 }
144
145 endOffset = offset + kFlashSectorSize;
146 offset += sizeof(uint32_t);
147 while (offset < endOffset) {
148 uint8_t *b = buffer;
149 uint8_t match;
150 uint32_t valueSize;
151 uint32_t use = endOffset - offset;
152 if (use > kBufferSize)
153 use = kBufferSize;
154
155 modSPIRead(offset, use, buffer);
156 while (use) {
157 if (0xff == *b) {
158 if (!domain && !key) {
159 *entryOffset = offset;
160 return 1;
161 }
162 return 0;
163 }
164
165 if (*b)
166 break;
167
168 b += 1;
169 use -= 1;
170 offset += 1;
171 }
172 if (0 == use) continue;
173
174 *entryOffset = offset;
175 modSPIRead(offset, kBufferSize, buffer);
176 match = domain && (0 == c_strcmp((char *)buffer, domain));
177 offset += c_strlen((char *)buffer) + 1;
178
179 modSPIRead(offset, kBufferSize, buffer);
180 if (match)
181 match = 0 == c_strcmp((char *)buffer, key);
182 offset += c_strlen((char *)buffer) + 1;
183 *valueOffset = offset;
184
185 modSPIRead(offset, kBufferSize, buffer);
186 valueSize = getEntryValueSize(buffer);
187 if (match && (*buffer >= kStorageFormatOffset))
188 match = 1;
189 else if (match)
190 match = 0;
191 offset += valueSize;
192 offset = (offset + 3) & ~3;
193 *entrySize = offset - *entryOffset;

Callers 3

eraseEntryFunction · 0.85
writeEntryFunction · 0.85
xs_directorystorage_readFunction · 0.85

Calls 3

findStorageBlockFunction · 0.85
getEntryValueSizeFunction · 0.85
modSPIReadFunction · 0.50

Tested by

no test coverage detected