提交 104b11c7 编写于 作者: O openharmony_ci 提交者: Gitee

!33 remove redundant code in fs

Merge pull request !33 from 野生毛霉君/master
......@@ -67,28 +67,37 @@
int close_blockdriver(struct Vnode *vnode_ptr)
{
#ifdef VFS_IMPL_LATER
int ret = 0; /* Assume success */
los_part *part = NULL;
los_disk *disk = NULL;
struct block_operations *bop = NULL;
/* Sanity checks */
if (!vnode_ptr || !vnode_ptr->u.i_bops)
if (vnode_ptr == NULL || vnode_ptr->data == NULL)
{
ret = -EINVAL;
goto errout;
}
bop = (struct block_operations*)(((struct drv_data*)vnode_ptr->data)->ops);
if (bop == NULL) {
PRINT_ERR("vnode ops is null, not a valid block driver\n");
ret = -EINVAL;
goto errout;
}
/* Verify that the vnode is a block driver. */
if (!INODE_IS_BLOCK(vnode_ptr))
if (vnode_ptr->type != VNODE_TYPE_BLK)
{
fdbg("vnode is not a block driver\n");
PRINT_ERR("vnode is not a block driver\n");
ret = -ENOTBLK;
goto errout;
}
part = los_part_find(vnode_ptr);
if (part != NULL)
{
......@@ -96,15 +105,15 @@ int close_blockdriver(struct Vnode *vnode_ptr)
if (disk == NULL)
{
ret = -EINVAL;
goto errout_with_vnode;
goto errout;
}
if (pthread_mutex_lock(&disk->disk_mutex) != ENOERR)
{
PRINT_ERR("%s %d, mutex lock fail!\n", __FUNCTION__, __LINE__);
vnode_release(vnode_ptr);
return -1;
return -EAGAIN;
}
if (disk->disk_status == STAT_INUSED)
{
/* Close the block driver. Not that no mutually exclusive access
......@@ -112,36 +121,26 @@ int close_blockdriver(struct Vnode *vnode_ptr)
* if needed.
*/
if (vnode_ptr->u.i_bops->close != NULL)
if (bop->close != NULL)
{
ret = vnode_ptr->u.i_bops->close(vnode_ptr);
ret = bop->close(vnode_ptr);
}
}
if (pthread_mutex_unlock(&disk->disk_mutex) != ENOERR)
{
PRINT_ERR("%s %d, mutex unlock fail!\n", __FUNCTION__, __LINE__);
vnode_release(vnode_ptr);
return -1;
}
}
else
{
if ((vnode_ptr->i_flags & FSNODEFLAG_DELETED) == 0 && vnode_ptr->u.i_bops->close != NULL)
if (bop->close != NULL)
{
ret = vnode_ptr->u.i_bops->close(vnode_ptr);
ret = bop->close(vnode_ptr);
}
}
errout_with_vnode:
/* Then release the reference on the vnode */
vnode_release(vnode_ptr);
errout:
return ret;
#endif
return 0;
}
......@@ -115,62 +115,3 @@ errout:
VnodeDrop();
return ret;
}
#ifdef VFS_IMPL_LATER
int find_blockdriver(FAR const char *pathname, int mountflags,
FAR struct inode **ppinode)
{
FAR struct inode *inode_ptr = NULL;
int ret = 0; /* Assume success */
struct inode_search_s desc;
/* Sanity checks */
#ifdef CONFIG_DEBUG
if (pathname == NULL || ppinode == NULL)
{
ret = -EINVAL;
goto errout;
}
#endif
/* Find the inode registered with this pathname */
SETUP_SEARCH(&desc, pathname, false);
ret = inode_find(&desc);
if (ret < 0)
{
ret = -EACCES;
goto errout;
}
/* Get the search results */
inode_ptr = desc.node;
/* Verify that the inode is a block driver. */
if (!INODE_IS_BLOCK(inode_ptr))
{
fdbg("%s is not a block driver\n", pathname);
ret = -ENOTBLK;
goto errout_with_inode;
}
/* Make sure that the inode supports the requested access */
if (inode_ptr->u.i_bops == NULL || inode_ptr->u.i_bops->read == NULL ||
(inode_ptr->u.i_bops->write == NULL && (mountflags & MS_RDONLY) == 0))
{
fdbg("%s does not support requested access\n", pathname);
ret = -EACCES;
goto errout_with_inode;
}
*ppinode = inode_ptr;
return OK;
errout_with_inode:
inode_release(inode_ptr);
errout:
return ret;
}
#endif
......@@ -36,110 +36,11 @@
/****************************************************************************
* Included Files
****************************************************************************/
#include "vfs_config.h"
#include "sys/statfs.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "assert.h"
#include "errno.h"
#include "fs/fs.h"
#include "fs/vnode.h"
#include "limits.h"
#ifndef CONFIG_DISABLE_MOUNTPOINT
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/* This structure just remembers the final consumer of the mountpoint
* information (and its argument).
*/
struct enum_mountpoint_s
{
foreach_mountpoint_t handler;
void *arg;
};
/****************************************************************************
* Private Functions
****************************************************************************/
#ifdef VFS_IMPL_LATER
static int mountpoint_filter(struct Vnode *node,
char dirpath[PATH_MAX], void *arg)
{
struct enum_mountpoint_s *info = (struct enum_mountpoint_s *)arg;
struct statfs statbuf;
int pathlen;
int namlen;
int ret = OK;
DEBUGASSERT(node && info && info->handler);
/* Check if the vnode is a mountpoint. Mountpoints must support statfs.
* If this one does not for some reason, then it will be ignored.
*
* The root node is a special case: It has no operations (u.i_mops == NULL)
*/
if (INODE_IS_MOUNTPT(node) && node->u.i_mops && node->u.i_mops->statfs)
{
/* Yes... get the full path to the vnode by concatenating the vnode
* name and the path to the directory containing the vnode.
*/
pathlen = strlen(dirpath);
namlen = strlen(node->i_name) + 1;
/* Make sure that this would not exceed the maximum path length */
if (pathlen + namlen >= PATH_MAX)
{
return -ENAMETOOLONG;
}
/* Append the vnode name to the directory path */
ret = snprintf_s(&dirpath[pathlen], PATH_MAX - pathlen, PATH_MAX - pathlen - 1, "/%s", node->i_name);
if (ret < 0)
{
return -ENAMETOOLONG;
}
/* Get the status of the file system */
ret = node->u.i_mops->statfs(node, &statbuf);
if (ret == OK)
{
/* And pass the full path and file system status to the handler */
if (strlen(dirpath) > 1) {
dirpath[strlen(dirpath) - 1] = '\0';
}
ret = info->handler(dirpath, &statbuf, info->arg);
}
/* Truncate the path name back to the correct length */
dirpath[pathlen] = '\0';
}
return ret;
}
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
......
......@@ -78,7 +78,7 @@ static int file_truncate(struct file *filep, off_t length)
vnode = filep->f_vnode;
if (!vnode || !vnode->vop || !vnode->vop->Truncate)
{
err = EBADF;
err = ENOSYS;
goto errout;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册