static int rtems_jffs2_rmnod( const rtems_filesystem_location_info_t *parentloc, const rtems_filesystem_location_info_t *loc ) { struct _inode *dir_i = rtems_jffs2_get_inode_by_location(parentloc); struct _inode *entry_i = rtems_jffs2_get_inode_by_location(loc); char *name; size_t namelen; int eno = rtems_jffs2_cache_fd_name(entry_i, &name, &namelen); if (eno == 0) { switch (dir_i->i_mode & S_IFMT) { case S_IFDIR: eno = -jffs2_rmdir(dir_i, entry_i, name, namelen); break; case S_IFREG: eno = -jffs2_unlink(dir_i, entry_i, name, namelen); break; default: eno = EINVAL; break; } } return rtems_jffs2_eno_to_rv_and_errno(eno); }
static int dfs_jffs2_unlink(struct dfs_filesystem* fs, const char* path) { int result; struct jffs2_stat s; cyg_mtab_entry * mte; result = _find_fs(&mte, fs->dev_id); if (result) return -DFS_STATUS_ENOENT; /* deal path */ if (path[0] == '/') path++; /* judge file type, dir is to be delete by rmdir, others by unlink */ rt_mutex_take(&jffs2_lock, RT_WAITING_FOREVER); result = jffs2_porting_stat(mte, mte->root, path, (void *)&s); if (result) { rt_mutex_release(&jffs2_lock); return jffs2_result_to_dfs(result); } switch(s.st_mode & JFFS2_S_IFMT) { case JFFS2_S_IFREG: result = jffs2_file_unlink(mte, mte->root, path); break; case JFFS2_S_IFDIR: result = jffs2_rmdir(mte, mte->root, path); break; default: /* unknown file type */ rt_mutex_release(&jffs2_lock); return -1; } rt_mutex_release(&jffs2_lock); if (result) return jffs2_result_to_dfs(result); return 0; }