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

Function dfs_aspace_unmap

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

* @brief Unmap pages from virtual address space * * This function removes mappings of file pages within the specified virtual address range. * It handles cache synchronization and maintains page dirty status when unmapping. * * @param[in] file Pointer to the file structure * @param[in] varea Pointer to the virtual address area to unmap * * @return 0 on success * * @note This functio

Source from the content-addressed store, hash-verified

1887 * cache synchronization and page dirty status maintenance during unmapping.
1888 */
1889int dfs_aspace_unmap(struct dfs_file *file, struct rt_varea *varea)
1890{
1891 struct dfs_vnode *vnode = file->vnode;
1892 struct dfs_aspace *aspace = vnode->aspace;
1893 void *unmap_start = varea->start;
1894 void *unmap_end = (char *)unmap_start + varea->size;
1895
1896 if (aspace)
1897 {
1898 rt_list_t *next;
1899 struct dfs_page *page;
1900
1901 dfs_aspace_lock(aspace);
1902 if (aspace->pages_count > 0)
1903 {
1904 rt_list_for_each(next, &aspace->list_active)
1905 {
1906 if (next != &aspace->list_inactive)
1907 {
1908 page = rt_list_entry(next, struct dfs_page, space_node);
1909 if (page)
1910 {
1911 rt_list_t *node, *tmp;
1912 struct dfs_mmap *map;
1913 rt_varea_t map_varea = RT_NULL;
1914
1915 node = page->mmap_head.next;
1916
1917 while (node != &page->mmap_head)
1918 {
1919 rt_aspace_t map_aspace;
1920 map = rt_list_entry(node, struct dfs_mmap, mmap_node);
1921 tmp = node;
1922 node = node->next;
1923
1924 if (map && varea->aspace == map->aspace
1925 && map->vaddr >= unmap_start && map->vaddr < unmap_end)
1926 {
1927 void *vaddr = map->vaddr;
1928 map_aspace = map->aspace;
1929
1930 if (!map_varea || map_varea->aspace != map_aspace ||
1931 vaddr < map_varea->start ||
1932 vaddr >= map_varea->start + map_varea->size)
1933 {
1934 /* lock the tree so we don't access uncompleted data */
1935 map_varea = rt_aspace_query(map_aspace, vaddr);
1936 }
1937
1938 rt_varea_unmap_page(map_varea, vaddr);
1939
1940 if (!rt_varea_is_private_locked(varea) &&
1941 page->fpos < page->aspace->vnode->size)
1942 {
1943 dfs_page_dirty(page);
1944 }
1945 rt_list_remove(tmp);
1946 rt_free(map);

Callers 2

on_varea_closeFunction · 0.85
on_varea_mergeFunction · 0.85

Calls 8

dfs_aspace_lockFunction · 0.85
rt_aspace_queryFunction · 0.85
rt_varea_unmap_pageFunction · 0.85
dfs_page_dirtyFunction · 0.85
rt_list_removeFunction · 0.85
rt_freeFunction · 0.85
dfs_aspace_unlockFunction · 0.85

Tested by

no test coverage detected