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

Function dfs_aspace_read

components/dfs/dfs_v2/src/dfs_pcache.c:1558–1617  ·  view source on GitHub ↗

* @brief Read data from file through address space page cache * * This function reads data from a file using its address space page cache. It handles * the lookup of pages containing the requested data, copies the data to the provided * buffer, and manages page references. * * @param[in] file Pointer to the file structure containing vnode and aspace * @param[in] buf Buffer to store the r

Source from the content-addressed store, hash-verified

1556 * @return Number of bytes successfully read, or negative error code
1557 */
1558int dfs_aspace_read(struct dfs_file *file, void *buf, size_t count, off_t *pos)
1559{
1560 int ret = -EINVAL;
1561
1562 if (file && file->vnode && file->vnode->aspace)
1563 {
1564 if (!(file->vnode->aspace->ops->read))
1565 return ret;
1566 struct dfs_vnode *vnode = file->vnode;
1567 struct dfs_aspace *aspace = vnode->aspace;
1568
1569 struct dfs_page *page;
1570 char *ptr = (char *)buf;
1571
1572 ret = 0;
1573
1574 while (count)
1575 {
1576 page = dfs_page_lookup(file, *pos);
1577 if (page)
1578 {
1579 off_t len;
1580
1581 dfs_aspace_lock(aspace);
1582 if (aspace->vnode->size < page->fpos + ARCH_PAGE_SIZE)
1583 {
1584 len = aspace->vnode->size - *pos;
1585 }
1586 else
1587 {
1588 len = page->fpos + ARCH_PAGE_SIZE - *pos;
1589 }
1590
1591 len = count > len ? len : count;
1592 if (len > 0)
1593 {
1594 rt_memcpy(ptr, page->page + *pos - page->fpos, len);
1595 ptr += len;
1596 *pos += len;
1597 count -= len;
1598 ret += len;
1599 }
1600 else
1601 {
1602 dfs_page_release(page);
1603 dfs_aspace_unlock(aspace);
1604 break;
1605 }
1606 dfs_page_release(page);
1607 dfs_aspace_unlock(aspace);
1608 }
1609 else
1610 {
1611 break;
1612 }
1613 }
1614 }
1615

Callers 3

dfs_file_preadFunction · 0.85
dfs_file_readFunction · 0.85
dfs_aspace_mmap_readFunction · 0.85

Calls 5

dfs_page_lookupFunction · 0.85
dfs_aspace_lockFunction · 0.85
rt_memcpyFunction · 0.85
dfs_page_releaseFunction · 0.85
dfs_aspace_unlockFunction · 0.85

Tested by

no test coverage detected