2013-01-16 16:41:27 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* fs/binfs/fs_binfs.c
|
|
|
|
*
|
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
|
2013-01-16 16:41:27 +01:00
|
|
|
*
|
2021-02-03 14:47:23 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2013-01-16 16:41:27 +01: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.
|
2013-01-16 16:41:27 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/statfs.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
#include <nuttx/fs/fs.h>
|
2013-01-16 18:05:00 +01:00
|
|
|
#include <nuttx/fs/ioctl.h>
|
2019-08-23 17:07:40 +02:00
|
|
|
#include <nuttx/lib/builtin.h>
|
2013-01-16 16:41:27 +01:00
|
|
|
|
2021-08-31 10:00:59 +02:00
|
|
|
#include "inode/inode.h"
|
|
|
|
|
2013-01-16 16:41:27 +01:00
|
|
|
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_FS_BINFS)
|
|
|
|
|
2022-08-05 06:31:25 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Type
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
struct binfs_dir_s
|
|
|
|
{
|
|
|
|
struct fs_dirent_s base; /* VFS directory structure */
|
|
|
|
unsigned int index; /* Index to the next named entry point */
|
|
|
|
};
|
|
|
|
|
2013-01-16 16:41:27 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int binfs_open(FAR struct file *filep, const char *relpath,
|
|
|
|
int oflags, mode_t mode);
|
|
|
|
static int binfs_close(FAR struct file *filep);
|
2020-07-02 16:03:27 +02:00
|
|
|
static ssize_t binfs_read(FAR struct file *filep,
|
|
|
|
char *buffer, size_t buflen);
|
|
|
|
static int binfs_ioctl(FAR struct file *filep,
|
|
|
|
int cmd, unsigned long arg);
|
2013-01-16 16:41:27 +01:00
|
|
|
|
|
|
|
static int binfs_dup(FAR const struct file *oldp, FAR struct file *newp);
|
2020-07-02 16:03:27 +02:00
|
|
|
static int binfs_fstat(FAR const struct file *filep,
|
|
|
|
FAR struct stat *buf);
|
2013-01-16 16:41:27 +01:00
|
|
|
|
2022-08-05 06:31:25 +02:00
|
|
|
static int binfs_opendir(FAR struct inode *mountpt,
|
|
|
|
FAR const char *relpath,
|
|
|
|
FAR struct fs_dirent_s **dir);
|
|
|
|
static int binfs_closedir(FAR struct inode *mountpt,
|
|
|
|
FAR struct fs_dirent_s *dir);
|
2013-01-16 16:41:27 +01:00
|
|
|
static int binfs_readdir(FAR struct inode *mountpt,
|
2022-07-26 08:56:41 +02:00
|
|
|
FAR struct fs_dirent_s *dir,
|
|
|
|
FAR struct dirent *entry);
|
2013-01-16 16:41:27 +01:00
|
|
|
static int binfs_rewinddir(FAR struct inode *mountpt,
|
|
|
|
FAR struct fs_dirent_s *dir);
|
|
|
|
|
|
|
|
static int binfs_bind(FAR struct inode *blkdriver, FAR const void *data,
|
|
|
|
FAR void **handle);
|
2015-03-15 01:14:54 +01:00
|
|
|
static int binfs_unbind(FAR void *handle, FAR struct inode **blkdriver,
|
|
|
|
unsigned int flags);
|
2013-01-16 16:41:27 +01:00
|
|
|
static int binfs_statfs(FAR struct inode *mountpt,
|
|
|
|
FAR struct statfs *buf);
|
|
|
|
|
|
|
|
static int binfs_stat(FAR struct inode *mountpt, FAR const char *relpath,
|
|
|
|
FAR struct stat *buf);
|
|
|
|
|
|
|
|
/****************************************************************************
|
2015-10-03 00:30:35 +02:00
|
|
|
* Public Data
|
2013-01-16 16:41:27 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2015-03-15 14:45:19 +01:00
|
|
|
/* See fs_mount.c -- this structure is explicitly extern'ed there.
|
2013-01-16 16:41:27 +01:00
|
|
|
* We use the old-fashioned kind of initializers so that this will compile
|
|
|
|
* with any compiler.
|
|
|
|
*/
|
|
|
|
|
2023-04-22 16:53:42 +02:00
|
|
|
const struct mountpt_operations g_binfs_operations =
|
2013-01-16 16:41:27 +01:00
|
|
|
{
|
|
|
|
binfs_open, /* open */
|
|
|
|
binfs_close, /* close */
|
|
|
|
binfs_read, /* read */
|
|
|
|
NULL, /* write */
|
|
|
|
NULL, /* seek */
|
|
|
|
binfs_ioctl, /* ioctl */
|
2023-01-02 14:02:51 +01:00
|
|
|
NULL, /* mmap */
|
2023-01-02 18:06:12 +01:00
|
|
|
NULL, /* truncate */
|
2013-01-16 16:41:27 +01:00
|
|
|
|
|
|
|
NULL, /* sync */
|
|
|
|
binfs_dup, /* dup */
|
2017-02-12 20:42:27 +01:00
|
|
|
binfs_fstat, /* fstat */
|
2021-07-09 07:43:26 +02:00
|
|
|
NULL, /* fchstat */
|
2013-01-16 16:41:27 +01:00
|
|
|
|
|
|
|
binfs_opendir, /* opendir */
|
2022-08-05 06:31:25 +02:00
|
|
|
binfs_closedir, /* closedir */
|
2013-01-16 16:41:27 +01:00
|
|
|
binfs_readdir, /* readdir */
|
|
|
|
binfs_rewinddir, /* rewinddir */
|
|
|
|
|
|
|
|
binfs_bind, /* bind */
|
|
|
|
binfs_unbind, /* unbind */
|
|
|
|
binfs_statfs, /* statfs */
|
|
|
|
|
|
|
|
NULL, /* unlink */
|
|
|
|
NULL, /* mkdir */
|
|
|
|
NULL, /* rmdir */
|
|
|
|
NULL, /* rename */
|
2021-07-09 07:43:26 +02:00
|
|
|
binfs_stat, /* stat */
|
|
|
|
NULL /* chstat */
|
2013-01-16 16:41:27 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: binfs_open
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int binfs_open(FAR struct file *filep, FAR const char *relpath,
|
|
|
|
int oflags, mode_t mode)
|
|
|
|
{
|
|
|
|
int index;
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("Open '%s'\n", relpath);
|
2013-01-16 16:41:27 +01:00
|
|
|
|
|
|
|
/* BINFS is read-only. Any attempt to open with any kind of write
|
|
|
|
* access is not permitted.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ((oflags & O_WRONLY) != 0 || (oflags & O_RDONLY) == 0)
|
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: Only O_RDONLY supported\n");
|
2013-01-16 16:41:27 +01:00
|
|
|
return -EACCES;
|
|
|
|
}
|
|
|
|
|
2020-02-12 14:04:00 +01:00
|
|
|
/* Check if the entry exists with this name in the root directory.
|
2013-01-16 16:41:27 +01:00
|
|
|
* so the 'relpath' must be the name of the builtin function.
|
|
|
|
*/
|
|
|
|
|
|
|
|
index = builtin_isavail(relpath);
|
|
|
|
if (index < 0)
|
|
|
|
{
|
2019-03-17 20:42:44 +01:00
|
|
|
ferr("ERROR: Built-in %s does not exist\n", relpath);
|
2013-01-16 16:41:27 +01:00
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Save the index as the open-specific state in filep->f_priv */
|
|
|
|
|
2015-11-21 17:12:21 +01:00
|
|
|
filep->f_priv = (FAR void *)((uintptr_t)index);
|
2013-01-16 16:41:27 +01:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: binfs_close
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int binfs_close(FAR struct file *filep)
|
|
|
|
{
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("Closing\n");
|
2013-01-16 16:41:27 +01:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: binfs_read
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-07-02 16:03:27 +02:00
|
|
|
static ssize_t binfs_read(FAR struct file *filep,
|
|
|
|
char *buffer, size_t buflen)
|
2013-01-16 16:41:27 +01:00
|
|
|
{
|
|
|
|
/* Reading is not supported. Just return end-of-file */
|
|
|
|
|
2020-11-25 12:11:25 +01:00
|
|
|
finfo("Read %zu bytes from offset %jd\n",
|
|
|
|
buflen, (intmax_t)filep->f_pos);
|
2013-01-16 16:41:27 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: binfs_ioctl
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int binfs_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("cmd: %d arg: %08lx\n", cmd, arg);
|
2013-01-16 16:41:27 +01:00
|
|
|
|
|
|
|
/* Only one IOCTL command is supported */
|
|
|
|
|
2021-08-31 10:00:59 +02:00
|
|
|
if (cmd == FIOC_FILEPATH)
|
2013-01-16 16:41:27 +01:00
|
|
|
{
|
2021-08-31 10:00:59 +02:00
|
|
|
/* IN: FAR char *(length >= PATH_MAX)
|
|
|
|
* OUT: The full file path
|
2013-01-16 16:41:27 +01:00
|
|
|
*/
|
|
|
|
|
2021-08-31 10:00:59 +02:00
|
|
|
FAR char *ptr = (FAR char *)((uintptr_t)arg);
|
2013-01-16 16:41:27 +01:00
|
|
|
if (ptr == NULL)
|
|
|
|
{
|
|
|
|
ret = -EINVAL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-03-05 14:13:32 +01:00
|
|
|
ret = inode_getpath(filep->f_inode, ptr, PATH_MAX);
|
2021-08-31 10:00:59 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-03-05 14:13:32 +01:00
|
|
|
strlcat(ptr, builtin_getname((int)((uintptr_t)filep->f_priv)),
|
|
|
|
PATH_MAX);
|
2013-01-16 16:41:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = -ENOTTY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: binfs_dup
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Duplicate open file data in the new file structure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int binfs_dup(FAR const struct file *oldp, FAR struct file *newp)
|
|
|
|
{
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("Dup %p->%p\n", oldp, newp);
|
2013-01-16 16:41:27 +01:00
|
|
|
|
|
|
|
/* Copy the index from the old to the new file structure */
|
|
|
|
|
|
|
|
newp->f_priv = oldp->f_priv;
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2017-02-12 20:42:27 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: binfs_fstat
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Obtain information about an open file associated with the file
|
|
|
|
* descriptor 'fd', and will write it to the area pointed to by 'buf'.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int binfs_fstat(FAR const struct file *filep, FAR struct stat *buf)
|
|
|
|
{
|
2017-02-12 21:47:05 +01:00
|
|
|
DEBUGASSERT(filep != NULL && buf != NULL);
|
|
|
|
|
|
|
|
/* It's a execute-only file system */
|
|
|
|
|
|
|
|
buf->st_mode = S_IFREG | S_IXOTH | S_IXGRP | S_IXUSR;
|
|
|
|
buf->st_size = 0;
|
|
|
|
buf->st_blksize = 0;
|
|
|
|
buf->st_blocks = 0;
|
|
|
|
return OK;
|
2017-02-12 20:42:27 +01:00
|
|
|
}
|
|
|
|
|
2013-01-16 16:41:27 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: binfs_opendir
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Open a directory for read access
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-08-05 06:31:25 +02:00
|
|
|
static int binfs_opendir(FAR struct inode *mountpt, FAR const char *relpath,
|
|
|
|
FAR struct fs_dirent_s **dir)
|
2013-01-16 16:41:27 +01:00
|
|
|
{
|
2022-08-05 06:31:25 +02:00
|
|
|
FAR struct binfs_dir_s *bdir;
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("relpath: \"%s\"\n", relpath ? relpath : "NULL");
|
2013-01-16 16:41:27 +01:00
|
|
|
|
|
|
|
/* The requested directory must be the volume-relative "root" directory */
|
|
|
|
|
|
|
|
if (relpath && relpath[0] != '\0')
|
|
|
|
{
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2022-08-05 06:31:25 +02:00
|
|
|
bdir = kmm_zalloc(sizeof(*bdir));
|
|
|
|
if (bdir == NULL)
|
|
|
|
{
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2013-01-16 16:41:27 +01:00
|
|
|
/* Set the index to the first entry */
|
|
|
|
|
2022-08-05 06:31:25 +02:00
|
|
|
bdir->index = 0;
|
|
|
|
*dir = (FAR struct fs_dirent_s *)bdir;
|
2013-01-16 16:41:27 +01:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2022-08-05 06:31:25 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: binfs_closedir
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Close a directory
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int binfs_closedir(FAR struct inode *mountpt,
|
|
|
|
FAR struct fs_dirent_s *dir)
|
|
|
|
{
|
|
|
|
DEBUGASSERT(dir);
|
|
|
|
kmm_free(dir);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-16 16:41:27 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: binfs_readdir
|
|
|
|
*
|
|
|
|
* Description: Read the next directory entry
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-07-26 08:56:41 +02:00
|
|
|
static int binfs_readdir(FAR struct inode *mountpt,
|
|
|
|
FAR struct fs_dirent_s *dir,
|
|
|
|
FAR struct dirent *entry)
|
2013-01-16 16:41:27 +01:00
|
|
|
{
|
2022-08-05 06:31:25 +02:00
|
|
|
FAR struct binfs_dir_s *bdir;
|
2013-01-17 15:43:55 +01:00
|
|
|
FAR const char *name;
|
2013-01-16 16:41:27 +01:00
|
|
|
unsigned int index;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Have we reached the end of the directory */
|
|
|
|
|
2022-08-05 06:31:25 +02:00
|
|
|
bdir = (FAR struct binfs_dir_s *)dir;
|
|
|
|
index = bdir->index;
|
2013-01-17 15:43:55 +01:00
|
|
|
name = builtin_getname(index);
|
|
|
|
if (name == NULL)
|
2013-01-16 16:41:27 +01:00
|
|
|
{
|
|
|
|
/* We signal the end of the directory by returning the
|
|
|
|
* special error -ENOENT
|
|
|
|
*/
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("Entry %d: End of directory\n", index);
|
2013-01-16 16:41:27 +01:00
|
|
|
ret = -ENOENT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Save the filename and file type */
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("Entry %d: \"%s\"\n", index, name);
|
2022-07-26 08:56:41 +02:00
|
|
|
entry->d_type = DTYPE_FILE;
|
|
|
|
strlcpy(entry->d_name, name, sizeof(entry->d_name));
|
2013-01-16 16:41:27 +01:00
|
|
|
|
|
|
|
/* The application list is terminated by an entry with a NULL name.
|
|
|
|
* Therefore, there is at least one more entry in the list.
|
|
|
|
*/
|
|
|
|
|
|
|
|
index++;
|
|
|
|
|
|
|
|
/* Set up the next directory entry offset. NOTE that we could use the
|
2022-08-05 06:31:25 +02:00
|
|
|
* standard f_pos instead of our own private index.
|
2013-01-16 16:41:27 +01:00
|
|
|
*/
|
|
|
|
|
2022-08-05 06:31:25 +02:00
|
|
|
bdir->index = index;
|
2013-01-16 16:41:27 +01:00
|
|
|
ret = OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: binfs_rewindir
|
|
|
|
*
|
|
|
|
* Description: Reset directory read to the first entry
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int binfs_rewinddir(struct inode *mountpt, struct fs_dirent_s *dir)
|
|
|
|
{
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("Entry\n");
|
2013-01-16 16:41:27 +01:00
|
|
|
|
2022-08-05 06:31:25 +02:00
|
|
|
((FAR struct binfs_dir_s *)dir)->index = 0;
|
2013-01-16 16:41:27 +01:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: binfs_bind
|
|
|
|
*
|
|
|
|
* Description: This implements a portion of the mount operation. This
|
|
|
|
* function allocates and initializes the mountpoint private data and
|
|
|
|
* binds the blockdriver inode to the filesystem private data. The final
|
|
|
|
* binding of the private data (containing the blockdriver) to the
|
|
|
|
* mountpoint is performed by mount().
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int binfs_bind(FAR struct inode *blkdriver, const void *data,
|
|
|
|
void **handle)
|
|
|
|
{
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("Entry\n");
|
2013-01-16 16:41:27 +01:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: binfs_unbind
|
|
|
|
*
|
|
|
|
* Description: This implements the filesystem portion of the umount
|
|
|
|
* operation.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-03-15 00:22:02 +01:00
|
|
|
static int binfs_unbind(FAR void *handle, FAR struct inode **blkdriver,
|
|
|
|
unsigned int flags)
|
2013-01-16 16:41:27 +01:00
|
|
|
{
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("Entry\n");
|
2013-01-16 16:41:27 +01:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: binfs_statfs
|
|
|
|
*
|
|
|
|
* Description: Return filesystem statistics
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int binfs_statfs(struct inode *mountpt, struct statfs *buf)
|
|
|
|
{
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("Entry\n");
|
2013-01-16 16:41:27 +01:00
|
|
|
|
|
|
|
/* Fill in the statfs info */
|
|
|
|
|
|
|
|
memset(buf, 0, sizeof(struct statfs));
|
|
|
|
buf->f_type = BINFS_MAGIC;
|
|
|
|
buf->f_bsize = 0;
|
|
|
|
buf->f_blocks = 0;
|
|
|
|
buf->f_bfree = 0;
|
|
|
|
buf->f_bavail = 0;
|
|
|
|
buf->f_namelen = NAME_MAX;
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: binfs_stat
|
|
|
|
*
|
|
|
|
* Description: Return information about a file or directory
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-07-02 16:03:27 +02:00
|
|
|
static int binfs_stat(struct inode *mountpt,
|
|
|
|
const char *relpath, struct stat *buf)
|
2013-01-16 16:41:27 +01:00
|
|
|
{
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("Entry\n");
|
2013-01-16 16:41:27 +01:00
|
|
|
|
|
|
|
/* The requested directory must be the volume-relative "root" directory */
|
|
|
|
|
|
|
|
if (relpath && relpath[0] != '\0')
|
|
|
|
{
|
|
|
|
/* Check if there is a file with this name. */
|
|
|
|
|
|
|
|
if (builtin_isavail(relpath) < 0)
|
|
|
|
{
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* It's a execute-only file name */
|
|
|
|
|
2015-10-11 19:39:29 +02:00
|
|
|
buf->st_mode = S_IFREG | S_IXOTH | S_IXGRP | S_IXUSR;
|
2013-01-16 16:41:27 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* It's a read/execute-only directory name */
|
|
|
|
|
2015-10-11 19:39:29 +02:00
|
|
|
buf->st_mode = S_IFDIR | S_IROTH | S_IRGRP | S_IRUSR | S_IXOTH |
|
|
|
|
S_IXGRP | S_IXUSR;
|
2013-01-16 16:41:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* File/directory size, access block size */
|
|
|
|
|
|
|
|
buf->st_size = 0;
|
|
|
|
buf->st_blksize = 0;
|
|
|
|
buf->st_blocks = 0;
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#endif /* !CONFIG_DISABLE_MOUNTPOINT && CONFIG_FS_BINFS */
|