41#ifdef LOSCFG_KERNEL_VM
46定义见于 ..\third_party\NuttX\include\nuttx\fs\fs.h
103 PRINT_ERR(
"Create mutex for file map of page cache failed, (ret=%u)\n", ret);
112 struct file *filp = NULL;
114 while (i < CONFIG_NFILE_DESCRIPTORS) {
115 filp = &tg_filelist.fl_files[i];
125 char *map_name = NULL;
127 int name_len = strlen(fullpath);
130 map_name = fmap->rename ? fmap->rename: fmap->
owner;
131 if ((name_len == fmap->name_len) && !strcmp(map_name, fullpath)) {
154 if (filep == NULL || fullpath == NULL) {
163 mapping->
host = filep;
167 path_len = strlen(fullpath);
171 PRINT_WARN(
"%s %d, Mem alloc failed.\n", __FUNCTION__, __LINE__);
177 fmap->name_len = path_len;
178 (
void)strcpy_s(fmap->
owner, path_len + 1, fullpath);
183 if (retval != LOS_OK) {
184 PRINT_ERR(
"%s %d, Create mutex for mapping.mux_lock failed, status: %d\n", __FUNCTION__, __LINE__, retval);
250 struct filelist *f_list = NULL;
253 f_list = &tg_filelist;
256 PRINTK(
"sem_wait error, ret=%d\n", ret);
281 if (src_path == NULL || dst_path == NULL) {
285 path_len = strlen(dst_path);
296 fmap = LOS_DL_LIST_ENTRY(mapping,
struct file_map, mapping);
300 PRINT_ERR(
"%s-%d: Mem alloc failed, path length(%d)\n", __FUNCTION__, __LINE__, path_len);
303 ret = strncpy_s(tmp, path_len, dst_path, strlen(dst_path));
309 tmp[path_len] =
'\0';
318 struct filelist *f_list = NULL;
319 struct file *filp = NULL;
322 f_list = &tg_filelist;
325 PRINTK(
"sem_wait error, ret=%d\n", ret);
330 for (
int i = 3; i < CONFIG_NFILE_DESCRIPTORS; i++) {
334 filp = &tg_filelist.fl_files[i];
335 if (filp->
f_path == NULL || strcmp(filp->
f_path, old_path)) {
338 int len = strlen(new_path) + 1;
340 if (tmp_path == NULL) {
341 PRINT_ERR(
"%s-%d: Mem alloc failed, path length(%d)\n", __FUNCTION__, __LINE__, len);
345 ret = strncpy_s(tmp_path, strlen(new_path) + 1, new_path, len);
348 PRINT_ERR(
"%s-%d: strcpy failed.\n", __FUNCTION__, __LINE__);
363#ifdef LOSCFG_DEBUG_VERSION
STATIC INLINE VOID LOS_AtomicInc(Atomic *v)
Atomic addSelf.
STATIC INLINE INT32 LOS_AtomicRead(const Atomic *v)
Atomic read. | 读取32bit原子数据
STATIC INLINE VOID LOS_AtomicSet(Atomic *v, INT32 setVal)
Atomic setting.
STATIC INLINE VOID LOS_AtomicDec(Atomic *v)
Atomic auto-decrement. | 对32bit原子数据做减1
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListInit(LOS_DL_LIST *list)
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListTailInsert(LOS_DL_LIST *list, LOS_DL_LIST *node)
Insert a node to the tail of a doubly linked list.
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListDelete(LOS_DL_LIST *node)
VOID * LOS_MemAlloc(VOID *pool, UINT32 size)
从指定内存池中申请size长度的内存,注意这可不是从内核堆空间中申请内存
UINT32 LOS_MemFree(VOID *pool, VOID *ptr)
释放从指定动态内存中申请的内存
UINT8 * m_aucSysMem0
异常交互动态内存池地址的起始地址,当不支持异常交互特性时,m_aucSysMem0等于m_aucSysMem1。
LITE_OS_SEC_TEXT UINT32 LOS_MuxInit(LosMux *mutex, const LosMuxAttr *attr)
初始化互斥锁
LITE_OS_SEC_TEXT UINT32 LOS_MuxUnlock(LosMux *mutex)
释放锁
LITE_OS_SEC_TEXT UINT32 LOS_MuxDestroy(LosMux *mutex)
销毁互斥锁
LITE_OS_SEC_TEXT UINT32 LOS_MuxLock(LosMux *mutex, UINT32 timeout)
拿互斥锁,
原子操作 http://weharmonyos.com/openharmony/zh-cn/device-dev/kernel/kernel-small-basic-atomic....
双向链表由内联函数实现 http://weharmonyos.com/openharmony/zh-cn/device-dev/kernel/kernel-small-apx-dll....
VOID LOS_SpinInit(SPIN_LOCK_S *lock)
VOID OsFileCacheFlush(struct page_mapping *mapping)
文件缓存冲洗,把所有fpage冲洗一边,把脏页洗到dirtyList中,配合OsFileCacheRemove理解
VOID OsFileCacheRemove(struct page_mapping *mapping)
void * zalloc(size_t size)
void free(void *ptr)
释放ptr所指向的内存空间
int sem_post(sem_t *sem)
增加信号量计数
int sem_wait(sem_t *sem)
获取信号量
struct page_mapping mapping
每个文件都有唯一的page_mapping标识其在内存的身份
LOS_DL_LIST head
链表节点,用于挂到g_file_mapping上
struct page_mapping * f_mapping
FAR struct inode * f_inode
unsigned long flags
@note_why 全量代码中也没查到源码中对其操作
ARG_NUM_3 ARG_NUM_1 ARG_NUM_2 ARG_NUM_2 ARG_NUM_3 ARG_NUM_1 ARG_NUM_4 ARG_NUM_2 ARG_NUM_2 ARG_NUM_5 ARG_NUM_2 void
定义见于 third_party NuttX include nuttx fs fs h typedef volatile INT32 Atomic
void add_mapping(struct file *filep, const char *fullpath)
增加一个文件映射,这个函数被do_open()函数调用,每打开一次文件就会调用一次 注意不同的进程打开同一个文件,拿到的file是不一样的。 https://blog....
void dec_mapping_nolock(struct page_mapping *mapping)
无锁方式引用递减,删除或关闭文件时 由 files_close_internal调用
static struct page_mapping * find_mapping_nolock(const char *fullpath)
以无锁的方式通过文件名查找文件映射并返回
struct file_map * GetFileMappingList(void)
int update_file_path(const char *old_path, const char *new_path)
更新文件路径
void rename_mapping(const char *src_path, const char *dst_path)
重命名映射
static void clear_file_mapping(const struct page_mapping *mapping)
清除文件映射
int remove_mapping_nolock(struct page_mapping *mapping)
删除一个文件映射,需要有个三个地方删除才算断开了文件和内存的联系. 以无锁的方式删除映射
int remove_mapping(const char *fullpath)
已有锁的方式删除文件映射
static struct file_map g_file_mapping
用于挂载所有文件的file_map