diff --git a/fs/driver/fs_closeblockdriver.c b/fs/driver/fs_closeblockdriver.c index f159a73a42bf67423cfa9379840785bf0c8e59ed..cd3eab9596379bcc459692dcdd6e3fd7b455ffd3 100644 --- a/fs/driver/fs_closeblockdriver.c +++ b/fs/driver/fs_closeblockdriver.c @@ -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; } diff --git a/fs/driver/fs_findblockdriver.c b/fs/driver/fs_findblockdriver.c index 9e92e456f95c1dd2c60a3c20b2ef82a5f06d4be7..775fe69b99f28c0759520a6e156cb28b62a89c59 100644 --- a/fs/driver/fs_findblockdriver.c +++ b/fs/driver/fs_findblockdriver.c @@ -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 diff --git a/fs/mount/fs_foreachmountpoint.c b/fs/mount/fs_foreachmountpoint.c index 7fe4f3e2fc6fde214e69656b4b9c88dad266dc78..6080d9f1394401d22cb81c11933015f8842c4bfd 100644 --- a/fs/mount/fs_foreachmountpoint.c +++ b/fs/mount/fs_foreachmountpoint.c @@ -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 ****************************************************************************/ diff --git a/fs/vfs/fs_truncate.c b/fs/vfs/fs_truncate.c index 0621ba30d609e56af222121ee0ad203a8122ac25..57fc4c1c2b5c452855a08d9aca0135ebc1e0ad8d 100644 --- a/fs/vfs/fs_truncate.c +++ b/fs/vfs/fs_truncate.c @@ -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; }