2007-05-28 01:09:23 +02:00
|
|
|
/****************************************************************************
|
2014-09-28 19:46:11 +02:00
|
|
|
* fs/vfs/fs_statfs.c
|
2007-05-28 01:09:23 +02:00
|
|
|
*
|
2017-02-04 18:46:54 +01:00
|
|
|
* Copyright (C) 2007-2009, 2012, 2017 Gregory Nutt. All rights reserved.
|
2012-01-04 21:49:47 +01:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
2007-05-28 01:09:23 +02:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
2008-09-12 16:46:44 +02:00
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
2007-05-28 01:09:23 +02:00
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
2009-12-15 01:18:32 +01:00
|
|
|
|
2007-05-28 01:09:23 +02:00
|
|
|
#include <sys/statfs.h>
|
|
|
|
#include <string.h>
|
2007-05-29 02:31:17 +02:00
|
|
|
#include <limits.h>
|
2007-05-28 01:09:23 +02:00
|
|
|
#include <sched.h>
|
|
|
|
#include <errno.h>
|
2009-12-15 01:18:32 +01:00
|
|
|
|
2014-09-29 15:14:38 +02:00
|
|
|
#include "inode/inode.h"
|
2007-05-28 01:09:23 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-08-05 19:44:11 +02:00
|
|
|
* Name: statpseudo
|
2007-05-28 01:09:23 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2017-02-14 13:30:35 +01:00
|
|
|
static int statpseudofs(FAR struct inode *inode, FAR struct statfs *buf)
|
2007-05-28 01:09:23 +02:00
|
|
|
{
|
2012-01-04 21:49:47 +01:00
|
|
|
memset(buf, 0, sizeof(struct statfs));
|
|
|
|
buf->f_type = PROC_SUPER_MAGIC;
|
|
|
|
buf->f_namelen = NAME_MAX;
|
|
|
|
return OK;
|
2007-05-28 01:09:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2008-11-10 15:40:03 +01:00
|
|
|
* Public Functions
|
2007-05-28 01:09:23 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-02-17 15:35:59 +01:00
|
|
|
* Name: statfs
|
2007-05-28 01:09:23 +02:00
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
|
|
|
* Zero on success; -1 on failure with errno set:
|
2007-05-28 01:09:23 +02:00
|
|
|
*
|
|
|
|
* EACCES Search permission is denied for one of the directories in the
|
|
|
|
* path prefix of path.
|
|
|
|
* EFAULT Bad address.
|
|
|
|
* ENOENT A component of the path path does not exist, or the path is an
|
|
|
|
* empty string.
|
|
|
|
* ENOMEM Out of memory
|
|
|
|
* ENOTDIR A component of the path is not a directory.
|
|
|
|
* ENOSYS The file system does not support this call.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2008-11-10 15:40:03 +01:00
|
|
|
int statfs(FAR const char *path, FAR struct statfs *buf)
|
2007-05-28 01:09:23 +02:00
|
|
|
{
|
2017-02-05 16:51:42 +01:00
|
|
|
struct inode_search_s desc;
|
2007-05-28 01:09:23 +02:00
|
|
|
FAR struct inode *inode;
|
2017-02-05 16:51:42 +01:00
|
|
|
int ret = OK;
|
2007-05-28 01:09:23 +02:00
|
|
|
|
|
|
|
/* Sanity checks */
|
|
|
|
|
2017-02-14 13:30:35 +01:00
|
|
|
if (path == NULL || buf == NULL)
|
2007-05-28 01:09:23 +02:00
|
|
|
{
|
|
|
|
ret = EFAULT;
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
2017-02-14 13:30:35 +01:00
|
|
|
if (*path == '\0')
|
2007-05-28 01:09:23 +02:00
|
|
|
{
|
|
|
|
ret = ENOENT;
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
2017-02-14 13:30:35 +01:00
|
|
|
/* Check for the fake root directory (which has no inode) */
|
|
|
|
|
|
|
|
if (strcmp(path, "/") == 0)
|
|
|
|
{
|
|
|
|
return statpseudofs(NULL, buf);
|
|
|
|
}
|
|
|
|
|
2007-05-28 01:09:23 +02:00
|
|
|
/* Get an inode for this file */
|
|
|
|
|
2017-02-05 21:25:45 +01:00
|
|
|
SETUP_SEARCH(&desc, path, false);
|
2017-02-05 16:51:42 +01:00
|
|
|
|
|
|
|
ret = inode_find(&desc);
|
|
|
|
if (ret < 0)
|
2007-05-28 01:09:23 +02:00
|
|
|
{
|
|
|
|
/* This name does not refer to a psudeo-inode and there is no
|
|
|
|
* mountpoint that includes in this path.
|
|
|
|
*/
|
|
|
|
|
2017-02-05 16:51:42 +01:00
|
|
|
ret = -ret;
|
2017-02-05 21:25:45 +01:00
|
|
|
goto errout_with_search;
|
2007-05-28 01:09:23 +02:00
|
|
|
}
|
|
|
|
|
2017-02-05 16:51:42 +01:00
|
|
|
/* Get the search results */
|
|
|
|
|
|
|
|
inode = desc.node;
|
|
|
|
DEBUGASSERT(inode != NULL);
|
|
|
|
|
2012-01-04 21:49:47 +01:00
|
|
|
/* The way we handle the statfs depends on the type of inode that we
|
2007-05-28 01:09:23 +02:00
|
|
|
* are dealing with.
|
|
|
|
*/
|
|
|
|
|
2007-06-09 21:11:00 +02:00
|
|
|
#ifndef CONFIG_DISABLE_MOUNTPOINT
|
2007-05-28 01:09:23 +02:00
|
|
|
if (INODE_IS_MOUNTPT(inode))
|
|
|
|
{
|
|
|
|
/* The node is a file system mointpoint. Verify that the mountpoint
|
2012-01-04 21:49:47 +01:00
|
|
|
* supports the statfs() method
|
2007-05-28 01:09:23 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (inode->u.i_mops && inode->u.i_mops->statfs)
|
|
|
|
{
|
2012-01-04 21:49:47 +01:00
|
|
|
/* Perform the statfs() operation */
|
2007-05-28 01:09:23 +02:00
|
|
|
|
2007-05-29 02:31:17 +02:00
|
|
|
ret = inode->u.i_mops->statfs(inode, buf);
|
2007-05-28 01:09:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
2012-08-05 19:44:11 +02:00
|
|
|
/* The node is part of the root pseudo file system */
|
2007-05-28 01:09:23 +02:00
|
|
|
|
2012-08-05 19:44:11 +02:00
|
|
|
ret = statpseudofs(inode, buf);
|
2007-05-28 01:09:23 +02:00
|
|
|
}
|
|
|
|
|
2012-01-04 21:49:47 +01:00
|
|
|
/* Check if the statfs operation was successful */
|
2007-05-28 01:09:23 +02:00
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
ret = -ret;
|
|
|
|
goto errout_with_inode;
|
|
|
|
}
|
|
|
|
|
2012-01-04 21:49:47 +01:00
|
|
|
/* Successfully statfs'ed the file */
|
2007-05-28 01:09:23 +02:00
|
|
|
|
|
|
|
inode_release(inode);
|
2017-02-05 21:25:45 +01:00
|
|
|
RELEASE_SEARCH(&desc);
|
2007-05-28 01:09:23 +02:00
|
|
|
return OK;
|
|
|
|
|
2019-10-27 18:48:14 +01:00
|
|
|
/* Failure conditions always set the errno appropriately */
|
2007-05-28 01:09:23 +02:00
|
|
|
|
2012-01-04 21:49:47 +01:00
|
|
|
errout_with_inode:
|
2007-05-28 01:09:23 +02:00
|
|
|
inode_release(inode);
|
2017-02-05 21:25:45 +01:00
|
|
|
|
|
|
|
errout_with_search:
|
|
|
|
RELEASE_SEARCH(&desc);
|
|
|
|
|
2012-01-04 21:49:47 +01:00
|
|
|
errout:
|
|
|
|
set_errno(ret);
|
2007-05-28 01:09:23 +02:00
|
|
|
return ERROR;
|
|
|
|
}
|