MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / dfs_seq_read

Function dfs_seq_read

components/dfs/dfs_v2/src/dfs_seq_file.c:175–318  ·  view source on GitHub ↗

* @brief Read data from sequence file * * @param[in] file Pointer to the file structure * @param[out] buf Buffer to store the read data * @param[in] size Size of the buffer in bytes * @param[in,out] pos Current file position (updated after read) * * @return ssize_t Number of bytes read on success, negative error code on failure: * -EFAULT if buffer error occurs * -ENOMEM i

Source from the content-addressed store, hash-verified

173 * 7. Copy data to user buffer and update positions
174 */
175ssize_t dfs_seq_read(struct dfs_file *file, void *buf, size_t size, off_t *pos)
176{
177 struct dfs_seq_file *seq = file->data;
178 size_t copied = 0;
179 size_t n;
180 void *p;
181 int err = 0;
182
183 if (!size)
184 return 0;
185
186 rt_mutex_take(&seq->lock, RT_WAITING_FOREVER);
187
188 /*
189 * if request is to read from zero offset, reset iterator to first
190 * record as it might have been already advanced by previous requests
191 */
192 if (*pos == 0)
193 {
194 seq->index = 0;
195 seq->count = 0;
196 }
197
198 /* Don't assume ki_pos is where we left it */
199 if (*pos != seq->read_pos)
200 {
201 while ((err = dfs_seq_traverse(seq, *pos)) == -EAGAIN)
202 ;
203 if (err)
204 {
205 /* With prejudice... */
206 seq->read_pos = 0;
207 seq->index = 0;
208 seq->count = 0;
209 goto Done;
210 }
211 else
212 {
213 seq->read_pos = *pos;
214 }
215 }
216
217 /* grab buffer if we didn't have one */
218 if (!seq->buf)
219 {
220 seq->buf = dfs_seq_alloc(seq->size = PAGE_SIZE);
221 if (!seq->buf)
222 goto Enomem;
223 }
224 /* something left in the buffer - copy it out first */
225 if (seq->count)
226 {
227 n = seq->count > size ? size : seq->count;
228 rt_memcpy((char *)buf + copied, seq->buf + seq->from, n);
229 size -= n;
230 seq->count -= n;
231 seq->from += n;
232 copied += n;

Callers

nothing calls this directly

Calls 8

rt_mutex_takeFunction · 0.85
dfs_seq_traverseFunction · 0.85
dfs_seq_allocFunction · 0.85
rt_memcpyFunction · 0.85
dfs_seq_is_fullFunction · 0.85
rt_freeFunction · 0.85
rt_mutex_releaseFunction · 0.85
startMethod · 0.80

Tested by

no test coverage detected