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
|
|
|
*
|
2021-02-03 14:47:23 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2007-05-28 01:09:23 +02:00
|
|
|
*
|
2021-02-03 14:47:23 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2007-05-28 01:09:23 +02:00
|
|
|
*
|
2021-02-03 14:47:23 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2007-05-28 01:09:23 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* 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>
|
2021-05-18 08:59:14 +02:00
|
|
|
#include <assert.h>
|
2007-05-28 01:09:23 +02:00
|
|
|
#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
|
|
|
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
|
|
|
{
|
2021-12-17 01:20:26 +01:00
|
|
|
ret = -EFAULT;
|
2007-05-28 01:09:23 +02:00
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
2017-02-14 13:30:35 +01:00
|
|
|
if (*path == '\0')
|
2007-05-28 01:09:23 +02:00
|
|
|
{
|
2021-12-17 01:20:26 +01:00
|
|
|
ret = -ENOENT;
|
2007-05-28 01:09:23 +02:00
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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 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.
|
|
|
|
*/
|
|
|
|
|
2023-06-06 05:59:14 +02:00
|
|
|
memset(buf, 0, sizeof(struct statfs));
|
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)
|
|
|
|
{
|
|
|
|
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:
|
2021-12-17 01:20:26 +01:00
|
|
|
set_errno(-ret);
|
2007-05-28 01:09:23 +02:00
|
|
|
return ERROR;
|
|
|
|
}
|