2012-03-22 01:51:01 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* fs/nfs/nfs_vfsops.c
|
|
|
|
*
|
2020-03-30 17:00:51 +02:00
|
|
|
* Copyright (C) 2012-2013, 2015, 2017-2018 Gregory Nutt. All rights
|
|
|
|
* reserved.
|
2012-03-22 01:51:01 +01:00
|
|
|
* Copyright (C) 2012 Jose Pablo Rojas Vargas. All rights reserved.
|
|
|
|
* Author: Jose Pablo Rojas Vargas <jrojas@nx-engineering.com>
|
2012-06-11 01:17:10 +02:00
|
|
|
* Gregory Nutt <gnutt@nuttx.org>
|
2012-03-22 01:51:01 +01:00
|
|
|
*
|
|
|
|
* Leveraged from OpenBSD:
|
|
|
|
*
|
|
|
|
* Copyright (c) 1989, 1993, 1995
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Rick Macklem at The University of Guelph.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-04-17 01:01:21 +02:00
|
|
|
#include <nuttx/config.h>
|
2012-04-28 01:29:24 +02:00
|
|
|
|
2017-02-13 17:07:43 +01:00
|
|
|
#include <sys/types.h>
|
2012-03-22 01:51:01 +01:00
|
|
|
#include <sys/socket.h>
|
2012-04-17 01:01:21 +02:00
|
|
|
#include <sys/statfs.h>
|
|
|
|
#include <sys/stat.h>
|
2012-04-14 02:27:44 +02:00
|
|
|
|
2020-11-25 12:09:09 +01:00
|
|
|
#include <inttypes.h>
|
2012-04-17 01:01:21 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <fcntl.h>
|
2012-06-11 01:17:10 +02:00
|
|
|
#include <time.h>
|
2012-04-14 02:27:44 +02:00
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <debug.h>
|
2012-06-11 01:17:10 +02:00
|
|
|
|
2012-04-19 01:31:47 +02:00
|
|
|
#include <nuttx/kmalloc.h>
|
2012-03-28 02:10:43 +02:00
|
|
|
#include <nuttx/fs/fs.h>
|
2012-04-23 21:55:32 +02:00
|
|
|
#include <nuttx/fs/nfs.h>
|
2014-06-24 16:53:28 +02:00
|
|
|
#include <nuttx/net/netconfig.h>
|
2012-03-22 01:51:01 +01:00
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <netinet/in.h>
|
2014-07-05 03:13:08 +02:00
|
|
|
#include <arpa/inet.h>
|
2012-03-22 01:51:01 +01:00
|
|
|
|
2024-09-09 14:28:16 +02:00
|
|
|
#include "fs_heap.h"
|
|
|
|
|
2012-04-23 22:33:25 +02:00
|
|
|
#include "nfs.h"
|
2012-04-19 01:31:47 +02:00
|
|
|
#include "rpc.h"
|
2012-04-17 01:01:21 +02:00
|
|
|
#include "nfs_proto.h"
|
2012-03-28 02:10:43 +02:00
|
|
|
#include "nfs_node.h"
|
|
|
|
#include "nfs_mount.h"
|
|
|
|
#include "xdr_subs.h"
|
2012-03-22 01:51:01 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-08-05 06:31:25 +02:00
|
|
|
#define DIRENT_NFS_MAXHANDLE 64 /* Maximum length of an NFSv3 file handle */
|
|
|
|
#define DIRENT_NFS_VERFLEN 8 /* Length of the copy verifier */
|
|
|
|
|
2012-06-10 20:16:01 +02:00
|
|
|
/* include/nuttx/fs/dirent.h has its own version of these lengths. They must
|
|
|
|
* match the NFS versions.
|
|
|
|
*/
|
|
|
|
|
2012-06-11 20:55:58 +02:00
|
|
|
#if NFSX_V3FHMAX != DIRENT_NFS_MAXHANDLE
|
2012-06-10 20:16:01 +02:00
|
|
|
# error "Length of file handle in fs_dirent_s is incorrect"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if NFSX_V3COOKIEVERF != DIRENT_NFS_VERFLEN
|
|
|
|
# error "Length of cookie verify in fs_dirent_s is incorrect"
|
|
|
|
#endif
|
|
|
|
|
2022-08-05 06:31:25 +02:00
|
|
|
/****************************************************************************
|
2023-12-03 15:48:00 +01:00
|
|
|
* Private Types
|
2022-08-05 06:31:25 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
struct nfs_dir_s
|
|
|
|
{
|
|
|
|
struct fs_dirent_s nfs_base; /* VFS diretory structure */
|
|
|
|
uint8_t nfs_fhsize; /* Length of the file handle */
|
|
|
|
uint8_t nfs_fhandle[DIRENT_NFS_MAXHANDLE]; /* File handle (max size allocated) */
|
|
|
|
uint8_t nfs_verifier[DIRENT_NFS_VERFLEN]; /* Cookie verifier */
|
|
|
|
uint32_t nfs_cookie[2]; /* Cookie */
|
|
|
|
};
|
|
|
|
|
2017-02-13 17:07:43 +01:00
|
|
|
/****************************************************************************
|
2020-03-01 21:53:45 +01:00
|
|
|
* Private Data
|
2017-02-13 17:07:43 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
static uint32_t nfs_true;
|
|
|
|
static uint32_t nfs_false;
|
|
|
|
static uint32_t nfs_xdrneg1;
|
2012-06-28 00:03:32 +02:00
|
|
|
|
2012-04-17 01:01:21 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-01-04 17:54:54 +01:00
|
|
|
static int nfs_filecreate(FAR struct nfsmount *nmp,
|
|
|
|
FAR struct nfsnode *np, FAR const char *relpath,
|
|
|
|
mode_t mode);
|
2021-08-10 09:35:43 +02:00
|
|
|
static int nfs_filechstat(FAR struct nfsmount *nmp,
|
|
|
|
FAR struct nfsnode *np,
|
|
|
|
FAR const struct stat *buf, int flags);
|
2018-01-04 17:54:54 +01:00
|
|
|
static int nfs_fileopen(FAR struct nfsmount *nmp,
|
|
|
|
FAR struct nfsnode *np, FAR const char *relpath,
|
|
|
|
int oflags, mode_t mode);
|
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
static int nfs_open(FAR struct file *filep, FAR const char *relpath,
|
2012-06-07 18:53:46 +02:00
|
|
|
int oflags, mode_t mode);
|
2012-06-14 02:47:42 +02:00
|
|
|
static int nfs_close(FAR struct file *filep);
|
2020-03-07 18:43:40 +01:00
|
|
|
static ssize_t nfs_read(FAR struct file *filep, FAR char *buffer,
|
|
|
|
size_t buflen);
|
2020-03-01 21:53:45 +01:00
|
|
|
static ssize_t nfs_write(FAR struct file *filep, FAR const char *buffer,
|
2012-06-07 18:53:46 +02:00
|
|
|
size_t buflen);
|
2023-07-25 10:15:56 +02:00
|
|
|
static off_t nfs_seek(FAR struct file *filep, off_t offset, int whence);
|
|
|
|
static int nfs_sync(FAR struct file *filep);
|
2013-01-14 20:22:32 +01:00
|
|
|
static int nfs_dup(FAR const struct file *oldp, FAR struct file *newp);
|
2020-03-01 21:53:45 +01:00
|
|
|
static int nfs_fsinfo(FAR struct nfsmount *nmp);
|
2017-02-12 20:42:27 +01:00
|
|
|
static int nfs_fstat(FAR const struct file *filep, FAR struct stat *buf);
|
2021-08-10 09:35:43 +02:00
|
|
|
static int nfs_fchstat(FAR const struct file *filep,
|
|
|
|
FAR const struct stat *buf, int flags);
|
2018-01-04 17:54:54 +01:00
|
|
|
static int nfs_truncate(FAR struct file *filep, off_t length);
|
2020-03-30 17:00:51 +02:00
|
|
|
static int nfs_opendir(FAR struct inode *mountpt,
|
2022-08-05 06:31:25 +02:00
|
|
|
FAR const char *relpath, FAR struct fs_dirent_s **dir);
|
|
|
|
static int nfs_closedir(FAR struct inode *mountpt,
|
|
|
|
FAR struct fs_dirent_s *dir);
|
2020-03-07 18:43:40 +01:00
|
|
|
static int nfs_readdir(FAR struct inode *mountpt,
|
2022-07-26 08:56:41 +02:00
|
|
|
FAR struct fs_dirent_s *dir,
|
|
|
|
FAR struct dirent *entry);
|
2012-06-14 23:54:50 +02:00
|
|
|
static int nfs_rewinddir(FAR struct inode *mountpt,
|
|
|
|
FAR struct fs_dirent_s *dir);
|
|
|
|
static void nfs_decode_args(FAR struct nfs_mount_parameters *nprmt,
|
|
|
|
FAR struct nfs_args *argp);
|
2020-03-01 21:53:45 +01:00
|
|
|
static int nfs_bind(FAR struct inode *blkdriver, FAR const void *data,
|
|
|
|
FAR void **handle);
|
2015-06-26 15:06:53 +02:00
|
|
|
static int nfs_unbind(FAR void *handle, FAR struct inode **blkdriver,
|
2015-03-15 00:22:02 +01:00
|
|
|
unsigned int flags);
|
2017-02-13 17:07:43 +01:00
|
|
|
static int nfs_statfs(FAR struct inode *mountpt,
|
|
|
|
FAR struct statfs *buf);
|
|
|
|
static int nfs_remove(FAR struct inode *mountpt,
|
|
|
|
FAR const char *relpath);
|
|
|
|
static int nfs_mkdir(FAR struct inode *mountpt,
|
|
|
|
FAR const char *relpath, mode_t mode);
|
|
|
|
static int nfs_rmdir(FAR struct inode *mountpt,
|
|
|
|
FAR const char *relpath);
|
|
|
|
static int nfs_rename(FAR struct inode *mountpt,
|
|
|
|
FAR const char *oldrelpath, FAR const char *newrelpath);
|
2020-03-01 21:53:45 +01:00
|
|
|
static mode_t nfs_stat_mode(unsigned int mode, unsigned int type);
|
|
|
|
static int nfs_stat(FAR struct inode *mountpt, FAR const char *relpath,
|
2017-02-13 17:07:43 +01:00
|
|
|
FAR struct stat *buf);
|
2021-08-10 09:35:43 +02:00
|
|
|
static int nfs_chstat(FAR struct inode *mountpt, FAR const char *relpath,
|
|
|
|
FAR const struct stat *buf, int flags);
|
2012-04-17 01:01:21 +02:00
|
|
|
|
2012-03-22 01:51:01 +01:00
|
|
|
/****************************************************************************
|
2012-03-27 02:23:40 +02:00
|
|
|
* Public Data
|
2012-03-22 01:51:01 +01:00
|
|
|
****************************************************************************/
|
2018-08-26 21:11:24 +02:00
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
#ifdef CONFIG_NFS_STATISTICS
|
|
|
|
struct nfsstats nfsstats;
|
|
|
|
#endif
|
|
|
|
|
2012-03-27 02:23:40 +02:00
|
|
|
/* nfs vfs operations. */
|
|
|
|
|
2023-04-22 16:53:42 +02:00
|
|
|
const struct mountpt_operations g_nfs_operations =
|
2012-04-17 01:01:21 +02:00
|
|
|
{
|
2012-03-27 02:23:40 +02:00
|
|
|
nfs_open, /* open */
|
2012-06-14 02:47:42 +02:00
|
|
|
nfs_close, /* close */
|
2012-03-27 02:23:40 +02:00
|
|
|
nfs_read, /* read */
|
|
|
|
nfs_write, /* write */
|
2023-07-25 10:15:56 +02:00
|
|
|
nfs_seek, /* seek */
|
2012-04-10 01:35:45 +02:00
|
|
|
NULL, /* ioctl */
|
2023-01-02 14:02:51 +01:00
|
|
|
NULL, /* mmap */
|
2023-01-02 18:06:12 +01:00
|
|
|
nfs_truncate, /* truncate */
|
2023-11-25 13:11:03 +01:00
|
|
|
NULL, /* poll */
|
2013-01-14 16:42:03 +01:00
|
|
|
|
2023-07-25 10:15:56 +02:00
|
|
|
nfs_sync, /* sync */
|
2013-01-14 20:22:32 +01:00
|
|
|
nfs_dup, /* dup */
|
2017-02-12 20:42:27 +01:00
|
|
|
nfs_fstat, /* fstat */
|
2021-08-10 09:35:43 +02:00
|
|
|
nfs_fchstat, /* fchstat */
|
2012-03-27 02:23:40 +02:00
|
|
|
|
2012-05-29 01:40:20 +02:00
|
|
|
nfs_opendir, /* opendir */
|
2022-08-05 06:31:25 +02:00
|
|
|
nfs_closedir, /* closedir */
|
2012-03-27 02:23:40 +02:00
|
|
|
nfs_readdir, /* readdir */
|
2012-06-14 23:54:50 +02:00
|
|
|
nfs_rewinddir, /* rewinddir */
|
2012-03-27 02:23:40 +02:00
|
|
|
|
2012-04-21 01:15:41 +02:00
|
|
|
nfs_bind, /* bind */
|
|
|
|
nfs_unbind, /* unbind */
|
2012-03-27 02:23:40 +02:00
|
|
|
nfs_statfs, /* statfs */
|
|
|
|
|
|
|
|
nfs_remove, /* unlink */
|
|
|
|
nfs_mkdir, /* mkdir */
|
|
|
|
nfs_rmdir, /* rmdir */
|
|
|
|
nfs_rename, /* rename */
|
2021-07-09 07:43:26 +02:00
|
|
|
nfs_stat, /* stat */
|
2021-08-10 09:35:43 +02:00
|
|
|
nfs_chstat /* chstat */
|
2012-03-27 02:23:40 +02:00
|
|
|
};
|
2012-03-22 01:51:01 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
2020-03-01 21:53:45 +01:00
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-06-09 21:29:49 +02:00
|
|
|
/****************************************************************************
|
2012-06-11 19:14:46 +02:00
|
|
|
* Name: nfs_filecreate
|
2012-06-09 17:55:10 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Create a file. This is part of the file open logic that is executed if
|
|
|
|
* the user asks to create a file.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
2020-03-01 21:53:45 +01:00
|
|
|
* 0 on success; a negative errno value on failure.
|
2012-06-09 17:55:10 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-01-04 17:54:54 +01:00
|
|
|
static int nfs_filecreate(FAR struct nfsmount *nmp, FAR struct nfsnode *np,
|
2012-06-11 19:14:46 +02:00
|
|
|
FAR const char *relpath, mode_t mode)
|
2012-06-09 17:55:10 +02:00
|
|
|
{
|
2022-09-06 08:18:45 +02:00
|
|
|
struct file_handle fhandle;
|
|
|
|
struct nfs_fattr fattr;
|
|
|
|
char filename[NAME_MAX + 1];
|
|
|
|
FAR uint32_t *ptr;
|
|
|
|
uint32_t tmp;
|
|
|
|
int namelen;
|
|
|
|
int reqlen;
|
|
|
|
int ret;
|
2012-06-11 19:14:46 +02:00
|
|
|
|
2012-06-11 20:55:58 +02:00
|
|
|
/* Find the NFS node of the directory containing the file to be created */
|
2012-06-11 19:14:46 +02:00
|
|
|
|
2020-03-30 17:00:51 +02:00
|
|
|
ret = nfs_finddir(nmp, relpath, &fhandle, &fattr, filename);
|
|
|
|
if (ret != OK)
|
2012-06-11 19:14:46 +02:00
|
|
|
{
|
2020-03-30 17:00:51 +02:00
|
|
|
ferr("ERROR: nfs_finddir returned: %d\n", ret);
|
|
|
|
return ret;
|
2012-06-11 19:14:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Create the CREATE RPC call arguments */
|
|
|
|
|
2012-06-14 17:45:38 +02:00
|
|
|
ptr = (FAR uint32_t *)&nmp->nm_msgbuffer.create.create;
|
2012-06-11 19:14:46 +02:00
|
|
|
reqlen = 0;
|
|
|
|
|
|
|
|
/* Copy the variable length, directory file handle */
|
|
|
|
|
|
|
|
*ptr++ = txdr_unsigned(fhandle.length);
|
|
|
|
reqlen += sizeof(uint32_t);
|
|
|
|
|
|
|
|
memcpy(ptr, &fhandle.handle, fhandle.length);
|
2020-03-01 21:53:45 +01:00
|
|
|
reqlen += uint32_alignup(fhandle.length);
|
2012-06-11 19:14:46 +02:00
|
|
|
ptr += uint32_increment(fhandle.length);
|
|
|
|
|
|
|
|
/* Copy the variable-length file name */
|
|
|
|
|
|
|
|
namelen = strlen(filename);
|
|
|
|
|
|
|
|
*ptr++ = txdr_unsigned(namelen);
|
|
|
|
reqlen += sizeof(uint32_t);
|
|
|
|
|
|
|
|
memcpy(ptr, filename, namelen);
|
2012-06-11 23:16:35 +02:00
|
|
|
ptr += uint32_increment(namelen);
|
2012-06-11 19:14:46 +02:00
|
|
|
reqlen += uint32_alignup(namelen);
|
|
|
|
|
|
|
|
/* Set the creation mode */
|
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
*ptr++ = HTONL(NFSV3CREATE_GUARDED);
|
2012-06-11 19:14:46 +02:00
|
|
|
reqlen += sizeof(uint32_t);
|
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
/* Set the mode. NOTE: Here we depend on the fact that the NuttX and NFS
|
|
|
|
* bit settings are the same (at least for the bits of interest).
|
2012-06-11 19:14:46 +02:00
|
|
|
*/
|
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
*ptr++ = nfs_true; /* True: mode value follows */
|
|
|
|
reqlen += sizeof(uint32_t);
|
2012-06-11 19:14:46 +02:00
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
tmp = mode & (NFSMODE_IXOTH | NFSMODE_IWOTH | NFSMODE_IROTH |
|
|
|
|
NFSMODE_IXGRP | NFSMODE_IWGRP | NFSMODE_IRGRP |
|
|
|
|
NFSMODE_IXUSR | NFSMODE_IWUSR | NFSMODE_IRUSR |
|
|
|
|
NFSMODE_SAVETEXT | NFSMODE_ISGID | NFSMODE_ISUID);
|
|
|
|
*ptr++ = txdr_unsigned(tmp);
|
|
|
|
reqlen += sizeof(uint32_t);
|
2012-06-11 19:14:46 +02:00
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
/* Set the user ID to zero */
|
2012-06-11 19:14:46 +02:00
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
*ptr++ = nfs_true; /* True: Uid value follows */
|
|
|
|
*ptr++ = 0; /* UID = 0 (nobody) */
|
|
|
|
reqlen += 2*sizeof(uint32_t);
|
2012-06-14 02:47:42 +02:00
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
/* Set the group ID to one */
|
2012-06-11 19:14:46 +02:00
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
*ptr++ = nfs_true; /* True: Gid value follows */
|
2020-03-02 13:07:09 +01:00
|
|
|
*ptr++ = 0; /* GID = 0 (nogroup) */
|
2020-03-01 21:53:45 +01:00
|
|
|
reqlen += 2*sizeof(uint32_t);
|
2012-06-14 02:47:42 +02:00
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
/* Set the size to zero */
|
2012-06-11 19:14:46 +02:00
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
*ptr++ = nfs_true; /* True: Size value follows */
|
|
|
|
*ptr++ = 0; /* Size = 0 */
|
|
|
|
*ptr++ = 0;
|
|
|
|
reqlen += 3*sizeof(uint32_t);
|
2012-06-11 19:14:46 +02:00
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
/* Don't change times */
|
2012-06-11 19:14:46 +02:00
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
*ptr++ = HTONL(NFSV3SATTRTIME_DONTCHANGE); /* Don't change atime */
|
|
|
|
*ptr++ = HTONL(NFSV3SATTRTIME_DONTCHANGE); /* Don't change mtime */
|
|
|
|
reqlen += 2*sizeof(uint32_t);
|
2012-06-11 19:14:46 +02:00
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
/* Send the NFS request. */
|
2012-06-09 17:55:10 +02:00
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
nfs_statistics(NFSPROC_CREATE);
|
2020-03-30 17:00:51 +02:00
|
|
|
ret = nfs_request(nmp, NFSPROC_CREATE,
|
2022-09-06 08:18:45 +02:00
|
|
|
&nmp->nm_msgbuffer.create, reqlen,
|
|
|
|
nmp->nm_iobuffer, nmp->nm_buflen);
|
2012-06-09 17:55:10 +02:00
|
|
|
|
2012-06-11 19:14:46 +02:00
|
|
|
/* Check for success */
|
2012-06-11 20:55:58 +02:00
|
|
|
|
2020-03-30 17:00:51 +02:00
|
|
|
if (ret == OK)
|
2012-06-09 17:55:10 +02:00
|
|
|
{
|
2012-06-11 20:55:58 +02:00
|
|
|
/* Parse the returned data */
|
|
|
|
|
2019-10-27 18:48:14 +01:00
|
|
|
ptr = (FAR uint32_t *)&((FAR struct rpc_reply_create *)
|
|
|
|
nmp->nm_iobuffer)->create;
|
2012-06-11 20:55:58 +02:00
|
|
|
|
|
|
|
/* Save the file handle in the file data structure */
|
|
|
|
|
|
|
|
tmp = *ptr++; /* handle_follows */
|
|
|
|
if (!tmp)
|
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: no file handle follows\n");
|
2020-03-01 21:53:45 +01:00
|
|
|
return -EINVAL;
|
2012-06-11 20:55:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
tmp = *ptr++;
|
|
|
|
tmp = fxdr_unsigned(uint32_t, tmp);
|
|
|
|
DEBUGASSERT(tmp <= NFSX_V3FHMAX);
|
|
|
|
|
|
|
|
np->n_fhsize = (uint8_t)tmp;
|
|
|
|
memcpy(&np->n_fhandle, ptr, tmp);
|
|
|
|
ptr += uint32_increment(tmp);
|
2012-06-14 02:47:42 +02:00
|
|
|
|
2012-06-11 20:55:58 +02:00
|
|
|
/* Save the attributes in the file data structure */
|
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
tmp = *ptr; /* attributes_follows */
|
2012-06-11 20:55:58 +02:00
|
|
|
if (!tmp)
|
|
|
|
{
|
2016-06-12 01:31:11 +02:00
|
|
|
fwarn("WARNING: no file attributes\n");
|
2012-06-11 20:55:58 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-06-12 18:11:31 +02:00
|
|
|
/* Initialize the file attributes */
|
2012-06-11 20:55:58 +02:00
|
|
|
|
2012-06-12 18:11:31 +02:00
|
|
|
nfs_attrupdate(np, (FAR struct nfs_fattr *)ptr);
|
2012-06-11 20:55:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Any following dir_wcc data is ignored for now */
|
2012-06-09 17:55:10 +02:00
|
|
|
}
|
|
|
|
|
2020-03-30 17:00:51 +02:00
|
|
|
return ret;
|
2012-06-09 17:55:10 +02:00
|
|
|
}
|
|
|
|
|
2012-06-14 20:04:39 +02:00
|
|
|
/****************************************************************************
|
2021-08-10 09:35:43 +02:00
|
|
|
* Name: nfs_filechstat
|
2012-06-14 20:04:39 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2021-08-10 09:35:43 +02:00
|
|
|
* Change the status of an open file. This is part of the file open logic.
|
2012-06-14 20:04:39 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
2020-03-01 21:53:45 +01:00
|
|
|
* 0 on success; a negative errno value on failure.
|
2012-06-14 20:04:39 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-08-10 09:35:43 +02:00
|
|
|
static int nfs_filechstat(FAR struct nfsmount *nmp, FAR struct nfsnode *np,
|
|
|
|
FAR const struct stat *buf, int flags)
|
2012-06-14 20:04:39 +02:00
|
|
|
{
|
|
|
|
FAR uint32_t *ptr;
|
|
|
|
int reqlen;
|
2020-03-30 17:00:51 +02:00
|
|
|
int ret;
|
2012-06-14 20:04:39 +02:00
|
|
|
|
2021-08-10 09:35:43 +02:00
|
|
|
finfo("Changing file status\n");
|
2012-06-14 20:04:39 +02:00
|
|
|
|
|
|
|
/* Create the SETATTR RPC call arguments */
|
|
|
|
|
|
|
|
ptr = (FAR uint32_t *)&nmp->nm_msgbuffer.setattr.setattr;
|
|
|
|
reqlen = 0;
|
|
|
|
|
|
|
|
/* Copy the variable length, directory file handle */
|
|
|
|
|
|
|
|
*ptr++ = txdr_unsigned(np->n_fhsize);
|
|
|
|
reqlen += sizeof(uint32_t);
|
|
|
|
|
|
|
|
memcpy(ptr, &np->n_fhandle, np->n_fhsize);
|
2020-03-01 21:53:45 +01:00
|
|
|
reqlen += uint32_alignup(np->n_fhsize);
|
2012-06-14 20:04:39 +02:00
|
|
|
ptr += uint32_increment(np->n_fhsize);
|
|
|
|
|
2013-01-14 20:22:32 +01:00
|
|
|
/* Copy the variable-length attributes */
|
2012-06-14 20:04:39 +02:00
|
|
|
|
2021-08-10 09:35:43 +02:00
|
|
|
if (flags & CH_STAT_MODE)
|
|
|
|
{
|
|
|
|
*ptr++ = nfs_true;
|
|
|
|
*ptr++ = txdr_unsigned(buf->st_mode);
|
|
|
|
reqlen += 2 * sizeof(uint32_t);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*ptr++ = nfs_false;
|
|
|
|
reqlen += sizeof(uint32_t);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & CH_STAT_UID)
|
|
|
|
{
|
|
|
|
*ptr++ = nfs_true;
|
|
|
|
*ptr++ = txdr_unsigned(buf->st_uid);
|
|
|
|
reqlen += 2 * sizeof(uint32_t);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*ptr++ = nfs_false;
|
|
|
|
reqlen += sizeof(uint32_t);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & CH_STAT_GID)
|
|
|
|
{
|
|
|
|
*ptr++ = nfs_true;
|
|
|
|
*ptr++ = txdr_unsigned(buf->st_gid);
|
|
|
|
reqlen += 2 * sizeof(uint32_t);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*ptr++ = nfs_false;
|
|
|
|
reqlen += sizeof(uint32_t);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & CH_STAT_SIZE)
|
|
|
|
{
|
|
|
|
*ptr++ = nfs_true;
|
|
|
|
txdr_hyper(buf->st_size, ptr);
|
|
|
|
ptr += 2;
|
|
|
|
reqlen += 3 * sizeof(uint32_t);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*ptr++ = nfs_false;
|
|
|
|
reqlen += sizeof(uint32_t);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & CH_STAT_ATIME)
|
|
|
|
{
|
|
|
|
*ptr++ = nfs_true;
|
|
|
|
txdr_nfsv3time(&buf->st_atim, ptr);
|
|
|
|
ptr += 2;
|
|
|
|
reqlen += 3 * sizeof(uint32_t);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*ptr++ = nfs_false;
|
|
|
|
reqlen += sizeof(uint32_t);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & CH_STAT_MTIME)
|
|
|
|
{
|
|
|
|
*ptr++ = nfs_true;
|
|
|
|
txdr_nfsv3time(&buf->st_mtim, ptr);
|
|
|
|
ptr += 2;
|
|
|
|
reqlen += 3 * sizeof(uint32_t);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*ptr++ = nfs_false;
|
|
|
|
reqlen += sizeof(uint32_t);
|
|
|
|
}
|
|
|
|
|
|
|
|
*ptr++ = nfs_false; /* No guard value */
|
|
|
|
reqlen += sizeof(uint32_t);
|
2012-06-14 20:04:39 +02:00
|
|
|
|
|
|
|
/* Perform the SETATTR RPC */
|
|
|
|
|
|
|
|
nfs_statistics(NFSPROC_SETATTR);
|
2020-03-30 17:00:51 +02:00
|
|
|
ret = nfs_request(nmp, NFSPROC_SETATTR,
|
2022-09-06 08:18:45 +02:00
|
|
|
&nmp->nm_msgbuffer.setattr, reqlen,
|
|
|
|
nmp->nm_iobuffer, nmp->nm_buflen);
|
2020-03-30 17:00:51 +02:00
|
|
|
if (ret != OK)
|
2012-06-14 20:04:39 +02:00
|
|
|
{
|
2020-03-30 17:00:51 +02:00
|
|
|
ferr("ERROR: nfs_request failed: %d\n", ret);
|
|
|
|
return ret;
|
2012-06-14 20:04:39 +02:00
|
|
|
}
|
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
/* Get a pointer to the SETATTR reply data */
|
|
|
|
|
|
|
|
ptr = (FAR uint32_t *)&((FAR struct rpc_reply_setattr *)
|
|
|
|
nmp->nm_iobuffer)->setattr;
|
|
|
|
|
|
|
|
/* Parse file_wcc. First, check if WCC attributes follow. */
|
|
|
|
|
|
|
|
if (*ptr++ != 0)
|
|
|
|
{
|
|
|
|
/* Yes.. WCC attributes follow. But we just skip over them. */
|
|
|
|
|
|
|
|
ptr += uint32_increment(sizeof(struct wcc_attr));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if normal file attributes follow */
|
|
|
|
|
|
|
|
if (*ptr++ != 0)
|
|
|
|
{
|
|
|
|
/* Yes.. Update the cached file status in the file structure. */
|
|
|
|
|
|
|
|
nfs_attrupdate(np, (FAR struct nfs_fattr *)ptr);
|
|
|
|
}
|
2012-06-14 20:04:39 +02:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2012-06-11 19:14:46 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: nfs_fileopen
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Open a file. This is part of the file open logic that attempts to open
|
|
|
|
* an existing file.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
2020-03-01 21:53:45 +01:00
|
|
|
* 0 on success; a negative errno value on failure.
|
2012-06-11 19:14:46 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-01-04 17:54:54 +01:00
|
|
|
static int nfs_fileopen(FAR struct nfsmount *nmp, FAR struct nfsnode *np,
|
2012-06-11 19:14:46 +02:00
|
|
|
FAR const char *relpath, int oflags, mode_t mode)
|
|
|
|
{
|
|
|
|
struct file_handle fhandle;
|
2012-06-12 18:11:31 +02:00
|
|
|
struct nfs_fattr fattr;
|
2012-06-11 19:14:46 +02:00
|
|
|
uint32_t tmp;
|
2020-03-30 17:00:51 +02:00
|
|
|
int ret = 0;
|
2012-06-11 19:14:46 +02:00
|
|
|
|
|
|
|
/* Find the NFS node associate with the path */
|
|
|
|
|
2020-03-30 17:00:51 +02:00
|
|
|
ret = nfs_findnode(nmp, relpath, &fhandle, &fattr, NULL);
|
|
|
|
if (ret != OK)
|
2012-06-11 19:14:46 +02:00
|
|
|
{
|
2020-03-30 17:00:51 +02:00
|
|
|
ferr("ERROR: nfs_findnode returned: %d\n", ret);
|
|
|
|
return ret;
|
2012-06-11 19:14:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if the object is a directory */
|
|
|
|
|
2012-06-12 18:11:31 +02:00
|
|
|
tmp = fxdr_unsigned(uint32_t, fattr.fa_type);
|
2012-06-11 19:14:46 +02:00
|
|
|
if (tmp == NFDIR)
|
|
|
|
{
|
|
|
|
/* Exit with EISDIR if we attempt to open a directory */
|
|
|
|
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: Path is a directory\n");
|
2020-03-01 21:53:45 +01:00
|
|
|
return -EISDIR;
|
2012-06-11 19:14:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if the caller has sufficient privileges to open the file */
|
|
|
|
|
|
|
|
if ((oflags & O_WRONLY) != 0)
|
|
|
|
{
|
2020-02-22 19:31:14 +01:00
|
|
|
/* Check if anyone has privileges to write to the file -- owner,
|
2012-06-11 19:14:46 +02:00
|
|
|
* group, or other (we are probably "other" and may still not be
|
|
|
|
* able to write).
|
|
|
|
*/
|
|
|
|
|
2012-06-12 18:11:31 +02:00
|
|
|
tmp = fxdr_unsigned(uint32_t, fattr.fa_mode);
|
2015-10-11 19:39:29 +02:00
|
|
|
if ((tmp & (NFSMODE_IWOTH | NFSMODE_IWGRP | NFSMODE_IWUSR)) == 0)
|
2012-06-11 19:14:46 +02:00
|
|
|
{
|
2020-11-25 12:09:09 +01:00
|
|
|
ferr("ERROR: File is read-only: %08" PRIx32 "\n", tmp);
|
2020-03-01 21:53:45 +01:00
|
|
|
return -EACCES;
|
2012-06-11 19:14:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-30 17:00:51 +02:00
|
|
|
/* It would be an ret if we are asked to create the file exclusively */
|
2012-06-11 19:14:46 +02:00
|
|
|
|
2015-10-11 19:39:29 +02:00
|
|
|
if ((oflags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
|
2012-06-11 19:14:46 +02:00
|
|
|
{
|
|
|
|
/* Already exists -- can't create it exclusively */
|
|
|
|
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: File exists\n");
|
2020-03-01 21:53:45 +01:00
|
|
|
return -EEXIST;
|
2012-06-11 19:14:46 +02:00
|
|
|
}
|
|
|
|
|
2019-03-01 22:00:00 +01:00
|
|
|
/* Initialize the file private data.
|
|
|
|
*
|
|
|
|
* Copy the file handle.
|
|
|
|
*/
|
2012-06-14 20:04:39 +02:00
|
|
|
|
|
|
|
np->n_fhsize = (uint8_t)fhandle.length;
|
|
|
|
memcpy(&np->n_fhandle, &fhandle.handle, fhandle.length);
|
|
|
|
|
|
|
|
/* Save the file attributes */
|
|
|
|
|
|
|
|
nfs_attrupdate(np, &fattr);
|
|
|
|
|
2012-06-11 19:14:46 +02:00
|
|
|
/* If O_TRUNC is specified and the file is opened for writing,
|
|
|
|
* then truncate the file. This operation requires that the file is
|
|
|
|
* writable, but we have already checked that. O_TRUNC without write
|
|
|
|
* access is ignored.
|
|
|
|
*/
|
|
|
|
|
2015-10-11 19:39:29 +02:00
|
|
|
if ((oflags & (O_TRUNC | O_WRONLY)) == (O_TRUNC | O_WRONLY))
|
2012-06-11 19:14:46 +02:00
|
|
|
{
|
2021-08-10 09:35:43 +02:00
|
|
|
struct stat buf;
|
|
|
|
|
2012-06-11 19:14:46 +02:00
|
|
|
/* Truncate the file to zero length. I think we can do this with
|
|
|
|
* the SETATTR call by setting the length to zero.
|
|
|
|
*/
|
|
|
|
|
2021-08-10 09:35:43 +02:00
|
|
|
buf.st_size = 0;
|
|
|
|
return nfs_filechstat(nmp, np, &buf, CH_STAT_SIZE);
|
2012-06-11 19:14:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-04-17 01:01:21 +02:00
|
|
|
* Name: nfs_open
|
|
|
|
*
|
2012-06-07 18:53:46 +02:00
|
|
|
* Description:
|
|
|
|
* If oflags == O_CREAT it creates a file, if not it check to see if the
|
|
|
|
* type is ok and that deletion is not in progress.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* 0 on success; a negated errno value on failure.
|
|
|
|
*
|
2012-04-17 01:01:21 +02:00
|
|
|
****************************************************************************/
|
2012-03-27 02:23:40 +02:00
|
|
|
|
2012-05-31 01:21:37 +02:00
|
|
|
static int nfs_open(FAR struct file *filep, FAR const char *relpath,
|
|
|
|
int oflags, mode_t mode)
|
2012-03-27 02:23:40 +02:00
|
|
|
{
|
2020-03-01 21:53:45 +01:00
|
|
|
FAR struct nfsmount *nmp;
|
|
|
|
FAR struct nfsnode *np;
|
2020-03-30 17:00:51 +02:00
|
|
|
int ret;
|
2012-03-27 02:23:40 +02:00
|
|
|
|
2012-04-10 01:35:45 +02:00
|
|
|
/* Get the mountpoint inode reference from the file structure and the
|
|
|
|
* mountpoint private data from the inode structure
|
|
|
|
*/
|
|
|
|
|
2023-08-29 06:16:49 +02:00
|
|
|
nmp = filep->f_inode->i_private;
|
2012-04-10 01:35:45 +02:00
|
|
|
DEBUGASSERT(nmp != NULL);
|
2012-03-27 02:23:40 +02:00
|
|
|
|
2012-06-09 17:55:10 +02:00
|
|
|
/* Pre-allocate the file private data to describe the opened file. */
|
|
|
|
|
2024-09-09 14:28:16 +02:00
|
|
|
np = fs_heap_zalloc(sizeof(struct nfsnode));
|
2012-06-09 17:55:10 +02:00
|
|
|
if (!np)
|
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: Failed to allocate private data\n");
|
2012-06-09 17:55:10 +02:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxmutex_lock(&nmp->nm_lock);
|
2020-03-30 17:00:51 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2024-09-09 14:28:16 +02:00
|
|
|
fs_heap_free(np);
|
2020-03-30 17:00:51 +02:00
|
|
|
return ret;
|
|
|
|
}
|
2012-03-27 02:23:40 +02:00
|
|
|
|
2012-06-11 19:14:46 +02:00
|
|
|
/* Try to open an existing file at that path */
|
2012-03-27 02:23:40 +02:00
|
|
|
|
2020-03-30 17:00:51 +02:00
|
|
|
ret = nfs_fileopen(nmp, np, relpath, oflags, mode);
|
|
|
|
if (ret != OK)
|
2012-06-09 17:55:10 +02:00
|
|
|
{
|
2020-03-30 17:00:51 +02:00
|
|
|
/* An ret occurred while trying to open the existing file. Check if
|
2012-06-11 19:14:46 +02:00
|
|
|
* the open failed because the file does not exist. That is not
|
2020-03-30 17:00:51 +02:00
|
|
|
* necessarily an ret; that may only mean that we have to create the
|
2012-06-11 19:14:46 +02:00
|
|
|
* file.
|
|
|
|
*/
|
2012-04-14 02:27:44 +02:00
|
|
|
|
2020-03-30 17:00:51 +02:00
|
|
|
if (ret != -ENOENT)
|
2012-04-10 01:35:45 +02:00
|
|
|
{
|
2020-03-30 17:00:51 +02:00
|
|
|
ferr("ERROR: nfs_fileopen failed: %d\n", ret);
|
2022-09-06 08:18:45 +02:00
|
|
|
goto errout_with_lock;
|
2012-06-09 17:55:10 +02:00
|
|
|
}
|
2012-06-02 01:12:17 +02:00
|
|
|
|
2020-03-07 18:43:40 +01:00
|
|
|
/* The file does not exist. Check if we were asked to create the file.
|
|
|
|
* If the O_CREAT bit is set in the oflags then we should create the
|
|
|
|
* file if it does not exist.
|
2012-06-11 19:14:46 +02:00
|
|
|
*/
|
2012-06-02 01:12:17 +02:00
|
|
|
|
2012-06-11 19:14:46 +02:00
|
|
|
if ((oflags & O_CREAT) == 0)
|
2012-06-09 17:55:10 +02:00
|
|
|
{
|
2012-06-11 19:14:46 +02:00
|
|
|
/* Return ENOENT if the file does not exist and we were not asked
|
|
|
|
* to create it.
|
2012-06-11 01:17:10 +02:00
|
|
|
*/
|
|
|
|
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: File does not exist\n");
|
2022-09-06 08:18:45 +02:00
|
|
|
goto errout_with_lock;
|
2012-06-09 17:55:10 +02:00
|
|
|
}
|
2012-06-14 02:47:42 +02:00
|
|
|
|
2012-06-11 19:14:46 +02:00
|
|
|
/* Create the file */
|
2012-04-10 01:35:45 +02:00
|
|
|
|
2020-03-30 17:00:51 +02:00
|
|
|
ret = nfs_filecreate(nmp, np, relpath, mode);
|
|
|
|
if (ret != OK)
|
2012-04-10 01:35:45 +02:00
|
|
|
{
|
2020-03-30 17:00:51 +02:00
|
|
|
ferr("ERROR: nfs_filecreate failed: %d\n", ret);
|
2022-09-06 08:18:45 +02:00
|
|
|
goto errout_with_lock;
|
2012-03-27 02:23:40 +02:00
|
|
|
}
|
|
|
|
}
|
2012-04-10 01:35:45 +02:00
|
|
|
|
2012-06-09 17:55:10 +02:00
|
|
|
/* Initialize the file private data (only need to initialize
|
|
|
|
* non-zero elements)
|
|
|
|
*/
|
|
|
|
|
2013-01-14 20:22:32 +01:00
|
|
|
np->n_crefs = 1;
|
|
|
|
|
2012-06-09 17:55:10 +02:00
|
|
|
/* Attach the private data to the struct file instance */
|
|
|
|
|
|
|
|
filep->f_priv = np;
|
|
|
|
|
2012-06-14 02:47:42 +02:00
|
|
|
/* Then insert the new instance at the head of the list in the mountpoint
|
2020-03-07 18:43:40 +01:00
|
|
|
* structure. It needs to be there (1) to handle error conditions that
|
|
|
|
* effect all files, and (2) to inform the umount logic that we are busy.
|
|
|
|
* We cannot unmount the file system if this list is not empty!
|
2012-06-09 17:55:10 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
np->n_next = nmp->nm_head;
|
2012-06-14 02:47:42 +02:00
|
|
|
nmp->nm_head = np;
|
2012-06-09 17:55:10 +02:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&nmp->nm_lock);
|
2012-06-09 17:55:10 +02:00
|
|
|
return OK;
|
2012-04-10 01:35:45 +02:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
errout_with_lock:
|
2012-06-14 02:47:42 +02:00
|
|
|
if (np)
|
|
|
|
{
|
2024-09-09 14:28:16 +02:00
|
|
|
fs_heap_free(np);
|
2012-06-14 02:47:42 +02:00
|
|
|
}
|
2013-01-14 20:22:32 +01:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&nmp->nm_lock);
|
2020-03-30 17:00:51 +02:00
|
|
|
return ret;
|
2012-03-27 02:23:40 +02:00
|
|
|
}
|
|
|
|
|
2012-04-10 01:35:45 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: nfs_close
|
2012-06-07 18:53:46 +02:00
|
|
|
*
|
2012-06-14 02:47:42 +02:00
|
|
|
* Description:
|
|
|
|
* Close a file.
|
|
|
|
*
|
2012-06-07 18:53:46 +02:00
|
|
|
* Returned Value:
|
|
|
|
* 0 on success; a negated errno value on failure.
|
|
|
|
*
|
2012-04-10 01:35:45 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2012-06-14 02:47:42 +02:00
|
|
|
static int nfs_close(FAR struct file *filep)
|
2012-03-27 02:23:40 +02:00
|
|
|
{
|
2012-06-14 02:47:42 +02:00
|
|
|
FAR struct nfsmount *nmp;
|
|
|
|
FAR struct nfsnode *np;
|
|
|
|
FAR struct nfsnode *prev;
|
|
|
|
FAR struct nfsnode *curr;
|
2013-01-16 15:14:14 +01:00
|
|
|
int ret;
|
2012-04-10 01:35:45 +02:00
|
|
|
|
2012-03-27 02:23:40 +02:00
|
|
|
/* Sanity checks */
|
|
|
|
|
2023-08-28 11:17:05 +02:00
|
|
|
DEBUGASSERT(filep->f_priv != NULL);
|
2012-04-10 01:35:45 +02:00
|
|
|
|
2012-06-14 03:37:10 +02:00
|
|
|
/* Recover our private data from the struct file instance */
|
|
|
|
|
2023-08-29 06:16:49 +02:00
|
|
|
nmp = filep->f_inode->i_private;
|
2022-09-06 08:18:45 +02:00
|
|
|
np = (FAR struct nfsnode *)filep->f_priv;
|
2012-04-10 01:35:45 +02:00
|
|
|
|
2012-03-27 02:23:40 +02:00
|
|
|
DEBUGASSERT(nmp != NULL);
|
|
|
|
|
2012-06-14 02:47:42 +02:00
|
|
|
/* Get exclusive access to the mount structure. */
|
2012-04-10 01:35:45 +02:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxmutex_lock(&nmp->nm_lock);
|
2020-03-30 17:00:51 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2012-06-14 02:47:42 +02:00
|
|
|
|
2013-01-14 20:22:32 +01:00
|
|
|
/* Decrement the reference count. If the reference count would not
|
|
|
|
* decrement to zero, then that is all we have to do.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (np->n_crefs > 1)
|
|
|
|
{
|
|
|
|
np->n_crefs--;
|
2013-01-16 15:14:14 +01:00
|
|
|
ret = OK;
|
2013-01-14 20:22:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* There are no more references to the file structure. Now we need to
|
|
|
|
* free up all resources associated with the open file.
|
|
|
|
*
|
|
|
|
* First, find our file structure in the list of file structures
|
2020-02-23 09:50:23 +01:00
|
|
|
* contained in the mount structure.
|
2012-06-14 02:47:42 +02:00
|
|
|
*/
|
|
|
|
|
2013-01-16 15:14:14 +01:00
|
|
|
else
|
|
|
|
{
|
2020-07-02 16:03:27 +02:00
|
|
|
/* Assume file structure won't be found. This should never happen. */
|
2012-06-14 02:47:42 +02:00
|
|
|
|
2013-01-16 15:14:14 +01:00
|
|
|
ret = -EINVAL;
|
|
|
|
|
|
|
|
for (prev = NULL, curr = nmp->nm_head;
|
|
|
|
curr;
|
|
|
|
prev = curr, curr = curr->n_next)
|
|
|
|
{
|
|
|
|
/* Check if this node is ours */
|
2012-06-14 02:47:42 +02:00
|
|
|
|
2013-01-16 15:14:14 +01:00
|
|
|
if (np == curr)
|
|
|
|
{
|
|
|
|
/* Yes.. remove it from the list of file structures */
|
2012-06-14 02:47:42 +02:00
|
|
|
|
2013-01-16 15:14:14 +01:00
|
|
|
if (prev)
|
|
|
|
{
|
|
|
|
/* Remove from mid-list */
|
2012-06-14 02:47:42 +02:00
|
|
|
|
2013-01-16 15:14:14 +01:00
|
|
|
prev->n_next = np->n_next;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Remove from the head of the list */
|
2012-06-14 02:47:42 +02:00
|
|
|
|
2013-01-16 15:14:14 +01:00
|
|
|
nmp->nm_head = np->n_next;
|
|
|
|
}
|
2012-06-14 02:47:42 +02:00
|
|
|
|
2013-01-16 15:14:14 +01:00
|
|
|
/* Then deallocate the file structure and return success */
|
|
|
|
|
2024-09-09 14:28:16 +02:00
|
|
|
fs_heap_free(np);
|
2013-01-16 15:14:14 +01:00
|
|
|
ret = OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-06-14 02:47:42 +02:00
|
|
|
|
2013-01-16 15:14:14 +01:00
|
|
|
filep->f_priv = NULL;
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&nmp->nm_lock);
|
2013-01-16 15:14:14 +01:00
|
|
|
return ret;
|
2012-03-27 02:23:40 +02:00
|
|
|
}
|
|
|
|
|
2012-04-10 01:35:45 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: nfs_read
|
2012-06-07 18:53:46 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* The (non-negative) number of bytes read on success; a negated errno
|
|
|
|
* value on failure.
|
|
|
|
*
|
2012-04-10 01:35:45 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2020-03-07 18:43:40 +01:00
|
|
|
static ssize_t nfs_read(FAR struct file *filep, FAR char *buffer,
|
|
|
|
size_t buflen)
|
2012-03-27 02:23:40 +02:00
|
|
|
{
|
2012-06-11 01:17:10 +02:00
|
|
|
FAR struct nfsmount *nmp;
|
|
|
|
FAR struct nfsnode *np;
|
|
|
|
ssize_t readsize;
|
|
|
|
ssize_t tmp;
|
|
|
|
ssize_t bytesread;
|
|
|
|
size_t reqlen;
|
|
|
|
FAR uint32_t *ptr;
|
2020-03-30 17:00:51 +02:00
|
|
|
int ret = 0;
|
2012-04-12 02:42:01 +02:00
|
|
|
|
2020-11-25 12:09:09 +01:00
|
|
|
finfo("Read %zu bytes from offset %jd\n",
|
|
|
|
buflen, (intmax_t)filep->f_pos);
|
2012-04-12 02:42:01 +02:00
|
|
|
|
|
|
|
/* Sanity checks */
|
|
|
|
|
2023-08-28 11:17:05 +02:00
|
|
|
DEBUGASSERT(filep->f_priv != NULL);
|
2012-04-12 02:42:01 +02:00
|
|
|
|
|
|
|
/* Recover our private data from the struct file instance */
|
|
|
|
|
2023-08-29 06:16:49 +02:00
|
|
|
nmp = filep->f_inode->i_private;
|
2015-10-11 19:39:29 +02:00
|
|
|
np = (FAR struct nfsnode *)filep->f_priv;
|
2012-04-12 02:42:01 +02:00
|
|
|
|
|
|
|
DEBUGASSERT(nmp != NULL);
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxmutex_lock(&nmp->nm_lock);
|
2020-03-30 17:00:51 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return (ssize_t)ret;
|
|
|
|
}
|
2012-04-12 02:42:01 +02:00
|
|
|
|
2012-06-11 01:17:10 +02:00
|
|
|
/* Get the number of bytes left in the file and truncate read count so that
|
|
|
|
* it does not exceed the number of bytes left in the file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
tmp = np->n_size - filep->f_pos;
|
|
|
|
if (buflen > tmp)
|
2012-04-10 01:35:45 +02:00
|
|
|
{
|
2012-06-11 01:17:10 +02:00
|
|
|
buflen = tmp;
|
2022-03-18 16:47:00 +01:00
|
|
|
finfo("Read size truncated to %zu\n", buflen);
|
2012-04-12 02:42:01 +02:00
|
|
|
}
|
|
|
|
|
2012-06-11 01:17:10 +02:00
|
|
|
/* Now loop until we fill the user buffer (or hit the end of the file) */
|
|
|
|
|
|
|
|
for (bytesread = 0; bytesread < buflen; )
|
2012-04-12 02:42:01 +02:00
|
|
|
{
|
2020-07-02 16:03:27 +02:00
|
|
|
/* Make sure that the attempted read size does not exceed the RPC
|
|
|
|
* maximum
|
|
|
|
*/
|
2012-06-14 02:47:42 +02:00
|
|
|
|
2017-12-28 13:31:49 +01:00
|
|
|
readsize = buflen - bytesread;
|
2012-06-11 01:17:10 +02:00
|
|
|
if (readsize > nmp->nm_rsize)
|
|
|
|
{
|
|
|
|
readsize = nmp->nm_rsize;
|
|
|
|
}
|
2012-04-12 02:42:01 +02:00
|
|
|
|
2020-07-02 16:03:27 +02:00
|
|
|
/* Make sure that the attempted read size does not exceed the IO buffer
|
|
|
|
* size
|
|
|
|
*/
|
2012-04-12 02:42:01 +02:00
|
|
|
|
2012-06-11 01:17:10 +02:00
|
|
|
tmp = SIZEOF_rpc_reply_read(readsize);
|
2012-06-14 02:47:42 +02:00
|
|
|
if (tmp > nmp->nm_buflen)
|
2012-06-11 01:17:10 +02:00
|
|
|
{
|
2012-06-14 02:47:42 +02:00
|
|
|
readsize -= (tmp - nmp->nm_buflen);
|
2012-06-11 01:17:10 +02:00
|
|
|
}
|
2012-04-12 02:42:01 +02:00
|
|
|
|
2012-06-11 01:17:10 +02:00
|
|
|
/* Initialize the request */
|
2012-04-12 02:42:01 +02:00
|
|
|
|
2015-10-11 19:39:29 +02:00
|
|
|
ptr = (FAR uint32_t *)&nmp->nm_msgbuffer.read.read;
|
2012-06-11 01:17:10 +02:00
|
|
|
reqlen = 0;
|
2012-04-12 02:42:01 +02:00
|
|
|
|
2012-06-12 18:11:31 +02:00
|
|
|
/* Copy the variable length, file handle */
|
2012-04-28 01:29:24 +02:00
|
|
|
|
2012-06-11 01:17:10 +02:00
|
|
|
*ptr++ = txdr_unsigned((uint32_t)np->n_fhsize);
|
|
|
|
reqlen += sizeof(uint32_t);
|
2012-04-14 02:27:44 +02:00
|
|
|
|
2012-06-11 01:17:10 +02:00
|
|
|
memcpy(ptr, &np->n_fhandle, np->n_fhsize);
|
2020-03-01 21:53:45 +01:00
|
|
|
reqlen += uint32_alignup(np->n_fhsize);
|
|
|
|
ptr += uint32_increment(np->n_fhsize);
|
2012-04-12 02:42:01 +02:00
|
|
|
|
2012-06-11 01:17:10 +02:00
|
|
|
/* Copy the file offset */
|
2012-04-12 02:42:01 +02:00
|
|
|
|
2012-06-11 01:17:10 +02:00
|
|
|
txdr_hyper((uint64_t)filep->f_pos, ptr);
|
|
|
|
ptr += 2;
|
|
|
|
reqlen += 2*sizeof(uint32_t);
|
|
|
|
|
|
|
|
/* Set the readsize */
|
|
|
|
|
|
|
|
*ptr = txdr_unsigned(readsize);
|
|
|
|
reqlen += sizeof(uint32_t);
|
|
|
|
|
|
|
|
/* Perform the read */
|
2012-06-14 02:47:42 +02:00
|
|
|
|
2022-03-18 16:47:00 +01:00
|
|
|
finfo("Reading %zu bytes\n", readsize);
|
2012-06-12 19:36:48 +02:00
|
|
|
nfs_statistics(NFSPROC_READ);
|
2020-03-30 17:00:51 +02:00
|
|
|
ret = nfs_request(nmp, NFSPROC_READ,
|
2022-09-06 08:18:45 +02:00
|
|
|
&nmp->nm_msgbuffer.read, reqlen,
|
|
|
|
nmp->nm_iobuffer, nmp->nm_buflen);
|
2020-03-30 17:00:51 +02:00
|
|
|
if (ret)
|
2012-06-11 01:17:10 +02:00
|
|
|
{
|
2020-03-30 17:00:51 +02:00
|
|
|
ferr("ERROR: nfs_request failed: %d\n", ret);
|
2022-09-06 08:18:45 +02:00
|
|
|
goto errout_with_lock;
|
2012-06-11 01:17:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* The read was successful. Get a pointer to the beginning of the NFS
|
|
|
|
* response data.
|
|
|
|
*/
|
|
|
|
|
2020-03-30 17:00:51 +02:00
|
|
|
ptr = (FAR uint32_t *)
|
|
|
|
&((FAR struct rpc_reply_read *)nmp->nm_iobuffer)->read;
|
2012-06-11 01:17:10 +02:00
|
|
|
|
|
|
|
/* Check if attributes are included in the responses */
|
|
|
|
|
|
|
|
tmp = *ptr++;
|
2020-03-01 21:53:45 +01:00
|
|
|
if (tmp != 0)
|
2012-06-11 01:17:10 +02:00
|
|
|
{
|
2020-03-01 21:53:45 +01:00
|
|
|
/* Yes.. Update the cached file status in the file structure. */
|
2012-06-11 01:17:10 +02:00
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
nfs_attrupdate(np, (FAR struct nfs_fattr *)ptr);
|
2012-06-11 01:17:10 +02:00
|
|
|
ptr += uint32_increment(sizeof(struct nfs_fattr));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This is followed by the count of data read. Isn't this
|
|
|
|
* the same as the length that is included in the read data?
|
|
|
|
*
|
|
|
|
* Just skip over if for now.
|
|
|
|
*/
|
|
|
|
|
|
|
|
ptr++;
|
|
|
|
|
|
|
|
/* Next comes an EOF indication. Save that in tmp for now. */
|
|
|
|
|
|
|
|
tmp = *ptr++;
|
|
|
|
|
|
|
|
/* Then the length of the read data followed by the read data itself */
|
|
|
|
|
|
|
|
readsize = fxdr_unsigned(uint32_t, *ptr);
|
|
|
|
ptr++;
|
|
|
|
|
|
|
|
/* Copy the read data into the user buffer */
|
|
|
|
|
|
|
|
memcpy(buffer, ptr, readsize);
|
|
|
|
|
|
|
|
/* Update the read state data */
|
|
|
|
|
|
|
|
filep->f_pos += readsize;
|
|
|
|
bytesread += readsize;
|
|
|
|
buffer += readsize;
|
|
|
|
|
|
|
|
/* Check if we hit the end of file */
|
|
|
|
|
|
|
|
if (tmp != 0)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2012-04-28 01:29:24 +02:00
|
|
|
}
|
2012-04-10 01:35:45 +02:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
errout_with_lock:
|
|
|
|
nxmutex_unlock(&nmp->nm_lock);
|
2020-03-30 17:00:51 +02:00
|
|
|
return bytesread > 0 ? bytesread : ret;
|
2012-03-27 02:23:40 +02:00
|
|
|
}
|
|
|
|
|
2012-04-14 02:27:44 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: nfs_write
|
2012-06-07 18:53:46 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* The (non-negative) number of bytes written on success; a negated errno
|
|
|
|
* value on failure.
|
|
|
|
*
|
2012-04-14 02:27:44 +02:00
|
|
|
****************************************************************************/
|
2012-04-12 02:42:01 +02:00
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
static ssize_t nfs_write(FAR struct file *filep, FAR const char *buffer,
|
2012-06-10 02:13:59 +02:00
|
|
|
size_t buflen)
|
2012-03-27 02:23:40 +02:00
|
|
|
{
|
2022-09-06 08:18:45 +02:00
|
|
|
FAR struct nfsmount *nmp;
|
|
|
|
FAR struct nfsnode *np;
|
|
|
|
ssize_t writesize;
|
|
|
|
ssize_t bufsize;
|
|
|
|
ssize_t byteswritten = 0;
|
|
|
|
size_t reqlen;
|
|
|
|
FAR uint32_t *ptr;
|
|
|
|
uint32_t tmp;
|
|
|
|
int commit = 0;
|
|
|
|
int committed = NFSV3WRITE_FILESYNC;
|
|
|
|
int ret;
|
2012-06-12 18:11:31 +02:00
|
|
|
|
2020-11-25 12:09:09 +01:00
|
|
|
finfo("Write %zu bytes to offset %jd\n",
|
|
|
|
buflen, (intmax_t)filep->f_pos);
|
2012-03-27 02:23:40 +02:00
|
|
|
|
2012-04-14 02:27:44 +02:00
|
|
|
/* Sanity checks */
|
2012-04-12 02:42:01 +02:00
|
|
|
|
2023-08-28 11:17:05 +02:00
|
|
|
DEBUGASSERT(filep->f_priv != NULL);
|
2012-04-12 02:42:01 +02:00
|
|
|
|
|
|
|
/* Recover our private data from the struct file instance */
|
|
|
|
|
2023-08-29 06:16:49 +02:00
|
|
|
nmp = filep->f_inode->i_private;
|
2015-10-11 19:39:29 +02:00
|
|
|
np = (FAR struct nfsnode *)filep->f_priv;
|
2012-04-12 02:42:01 +02:00
|
|
|
|
|
|
|
DEBUGASSERT(nmp != NULL);
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxmutex_lock(&nmp->nm_lock);
|
2020-03-30 17:00:51 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return (ssize_t)ret;
|
|
|
|
}
|
2012-04-12 02:42:01 +02:00
|
|
|
|
|
|
|
/* Check if the file size would exceed the range of off_t */
|
|
|
|
|
|
|
|
if (np->n_size + buflen < np->n_size)
|
|
|
|
{
|
2020-03-30 17:00:51 +02:00
|
|
|
ret = -EFBIG;
|
2022-09-06 08:18:45 +02:00
|
|
|
goto errout_with_lock;
|
2012-04-10 01:35:45 +02:00
|
|
|
}
|
|
|
|
|
2012-06-12 18:11:31 +02:00
|
|
|
/* Now loop until we send the entire user buffer */
|
|
|
|
|
|
|
|
for (byteswritten = 0; byteswritten < buflen; )
|
2012-03-27 02:23:40 +02:00
|
|
|
{
|
2019-10-27 18:48:14 +01:00
|
|
|
/* Make sure that the attempted write size does not exceed the RPC
|
|
|
|
* maximum.
|
|
|
|
*/
|
2012-06-14 02:47:42 +02:00
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
writesize = buflen - byteswritten;
|
2012-06-12 18:11:31 +02:00
|
|
|
if (writesize > nmp->nm_wsize)
|
|
|
|
{
|
|
|
|
writesize = nmp->nm_wsize;
|
|
|
|
}
|
2012-05-23 02:15:53 +02:00
|
|
|
|
2019-10-27 18:48:14 +01:00
|
|
|
/* Make sure that the attempted read size does not exceed the IO
|
|
|
|
* buffer size.
|
|
|
|
*/
|
2012-03-27 02:23:40 +02:00
|
|
|
|
2012-06-12 18:11:31 +02:00
|
|
|
bufsize = SIZEOF_rpc_call_write(writesize);
|
2012-06-14 02:47:42 +02:00
|
|
|
if (bufsize > nmp->nm_buflen)
|
2012-06-12 18:11:31 +02:00
|
|
|
{
|
2012-06-14 02:47:42 +02:00
|
|
|
writesize -= (bufsize - nmp->nm_buflen);
|
2012-06-12 18:11:31 +02:00
|
|
|
}
|
2012-06-11 01:17:10 +02:00
|
|
|
|
2012-06-12 18:11:31 +02:00
|
|
|
/* Initialize the request. Here we need an offset pointer to the write
|
|
|
|
* arguments, skipping over the RPC header. Write is unique among the
|
2020-03-30 17:00:51 +02:00
|
|
|
* RPC calls in that the entry RPC calls message lies in the I/O buffer
|
2012-06-12 18:11:31 +02:00
|
|
|
*/
|
2012-06-11 01:17:10 +02:00
|
|
|
|
2019-10-27 18:48:14 +01:00
|
|
|
ptr = (FAR uint32_t *)&((FAR struct rpc_call_write *)
|
|
|
|
nmp->nm_iobuffer)->write;
|
2012-06-12 18:11:31 +02:00
|
|
|
reqlen = 0;
|
2012-06-11 01:17:10 +02:00
|
|
|
|
2012-06-12 18:11:31 +02:00
|
|
|
/* Copy the variable length, file handle */
|
2012-06-11 01:17:10 +02:00
|
|
|
|
2012-06-12 18:11:31 +02:00
|
|
|
*ptr++ = txdr_unsigned((uint32_t)np->n_fhsize);
|
|
|
|
reqlen += sizeof(uint32_t);
|
2012-06-11 01:17:10 +02:00
|
|
|
|
2012-06-12 18:11:31 +02:00
|
|
|
memcpy(ptr, &np->n_fhandle, np->n_fhsize);
|
2020-03-01 21:53:45 +01:00
|
|
|
reqlen += uint32_alignup(np->n_fhsize);
|
|
|
|
ptr += uint32_increment(np->n_fhsize);
|
2012-03-27 02:23:40 +02:00
|
|
|
|
2012-06-12 18:11:31 +02:00
|
|
|
/* Copy the file offset */
|
2012-06-11 01:17:10 +02:00
|
|
|
|
2012-06-12 18:11:31 +02:00
|
|
|
txdr_hyper((uint64_t)filep->f_pos, ptr);
|
|
|
|
ptr += 2;
|
|
|
|
reqlen += 2*sizeof(uint32_t);
|
2012-06-11 01:17:10 +02:00
|
|
|
|
2012-06-12 18:11:31 +02:00
|
|
|
/* Copy the count and stable values */
|
2012-06-11 01:17:10 +02:00
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
*ptr++ = txdr_unsigned(writesize);
|
2012-06-12 18:11:31 +02:00
|
|
|
*ptr++ = txdr_unsigned(committed);
|
|
|
|
reqlen += 2*sizeof(uint32_t);
|
2012-06-11 01:17:10 +02:00
|
|
|
|
2012-06-12 18:11:31 +02:00
|
|
|
/* Copy a chunk of the user data into the I/O buffer */
|
2012-03-27 02:23:40 +02:00
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
*ptr++ = txdr_unsigned(writesize);
|
2012-06-12 18:11:31 +02:00
|
|
|
reqlen += sizeof(uint32_t);
|
|
|
|
memcpy(ptr, buffer, writesize);
|
2012-06-12 19:36:48 +02:00
|
|
|
reqlen += uint32_alignup(writesize);
|
2012-03-27 02:23:40 +02:00
|
|
|
|
2012-06-12 18:11:31 +02:00
|
|
|
/* Perform the write */
|
2012-04-10 01:35:45 +02:00
|
|
|
|
2012-06-12 19:36:48 +02:00
|
|
|
nfs_statistics(NFSPROC_WRITE);
|
2020-03-30 17:00:51 +02:00
|
|
|
ret = nfs_request(nmp, NFSPROC_WRITE,
|
2022-09-06 08:18:45 +02:00
|
|
|
nmp->nm_iobuffer, reqlen,
|
|
|
|
&nmp->nm_msgbuffer.write,
|
2020-03-30 17:00:51 +02:00
|
|
|
sizeof(struct rpc_reply_write));
|
|
|
|
if (ret)
|
2012-06-12 18:11:31 +02:00
|
|
|
{
|
2020-03-30 17:00:51 +02:00
|
|
|
ferr("ERROR: nfs_request failed: %d\n", ret);
|
2022-09-06 08:18:45 +02:00
|
|
|
goto errout_with_lock;
|
2012-06-12 18:11:31 +02:00
|
|
|
}
|
2012-04-10 01:35:45 +02:00
|
|
|
|
2012-06-12 18:11:31 +02:00
|
|
|
/* Get a pointer to the WRITE reply data */
|
2012-04-10 01:35:45 +02:00
|
|
|
|
2012-06-14 02:47:42 +02:00
|
|
|
ptr = (FAR uint32_t *)&nmp->nm_msgbuffer.write.write;
|
2012-06-12 18:11:31 +02:00
|
|
|
|
|
|
|
/* Parse file_wcc. First, check if WCC attributes follow. */
|
|
|
|
|
|
|
|
tmp = *ptr++;
|
|
|
|
if (tmp != 0)
|
|
|
|
{
|
|
|
|
/* Yes.. WCC attributes follow. But we just skip over them. */
|
|
|
|
|
|
|
|
ptr += uint32_increment(sizeof(struct wcc_attr));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if normal file attributes follow */
|
|
|
|
|
|
|
|
tmp = *ptr++;
|
|
|
|
if (tmp != 0)
|
|
|
|
{
|
|
|
|
/* Yes.. Update the cached file status in the file structure. */
|
|
|
|
|
|
|
|
nfs_attrupdate(np, (FAR struct nfs_fattr *)ptr);
|
|
|
|
ptr += uint32_increment(sizeof(struct nfs_fattr));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the count of bytes actually written */
|
|
|
|
|
|
|
|
tmp = fxdr_unsigned(uint32_t, *ptr);
|
|
|
|
ptr++;
|
|
|
|
|
|
|
|
if (tmp < 1 || tmp > writesize)
|
|
|
|
{
|
2020-03-30 17:00:51 +02:00
|
|
|
ret = -EIO;
|
2022-09-06 08:18:45 +02:00
|
|
|
goto errout_with_lock;
|
2012-06-12 18:11:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
writesize = tmp;
|
|
|
|
|
2020-02-22 19:31:14 +01:00
|
|
|
/* Determine the lowest commitment level obtained by any of the RPCs. */
|
2012-06-12 18:11:31 +02:00
|
|
|
|
|
|
|
commit = *ptr++;
|
|
|
|
if (committed == NFSV3WRITE_FILESYNC)
|
|
|
|
{
|
|
|
|
committed = commit;
|
|
|
|
}
|
|
|
|
else if (committed == NFSV3WRITE_DATASYNC &&
|
|
|
|
commit == NFSV3WRITE_UNSTABLE)
|
|
|
|
{
|
|
|
|
committed = commit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update the read state data */
|
|
|
|
|
|
|
|
filep->f_pos += writesize;
|
|
|
|
byteswritten += writesize;
|
|
|
|
buffer += writesize;
|
|
|
|
}
|
2012-04-14 02:27:44 +02:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
errout_with_lock:
|
|
|
|
nxmutex_unlock(&nmp->nm_lock);
|
2020-03-30 17:00:51 +02:00
|
|
|
return byteswritten > 0 ? byteswritten : ret;
|
2012-03-27 02:23:40 +02:00
|
|
|
}
|
|
|
|
|
2023-07-25 10:15:56 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: nfs_seek
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Returns the resulting offset location as measured in bytes from the
|
|
|
|
* beginning of the file.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static off_t nfs_seek(FAR struct file *filep, off_t offset, int whence)
|
|
|
|
{
|
|
|
|
FAR struct nfsmount *nmp;
|
|
|
|
FAR struct nfsnode *np;
|
|
|
|
off_t ret;
|
|
|
|
|
|
|
|
/* Sanity checks */
|
|
|
|
|
2023-08-28 11:17:05 +02:00
|
|
|
DEBUGASSERT(filep->f_priv != NULL);
|
2023-07-25 10:15:56 +02:00
|
|
|
|
|
|
|
/* Recover our private data from the struct file instance */
|
|
|
|
|
2023-08-29 06:16:49 +02:00
|
|
|
nmp = filep->f_inode->i_private;
|
2023-07-25 10:15:56 +02:00
|
|
|
np = (FAR struct nfsnode *)filep->f_priv;
|
|
|
|
|
|
|
|
DEBUGASSERT(nmp != NULL);
|
|
|
|
|
|
|
|
ret = nxmutex_lock(&nmp->nm_lock);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Map the offset according to the whence option */
|
|
|
|
|
|
|
|
switch (whence)
|
|
|
|
{
|
|
|
|
case SEEK_SET:
|
2023-08-01 03:58:01 +02:00
|
|
|
break;
|
2023-07-25 10:15:56 +02:00
|
|
|
|
|
|
|
case SEEK_CUR:
|
2023-08-01 03:58:01 +02:00
|
|
|
offset += filep->f_pos;
|
|
|
|
break;
|
2023-07-25 10:15:56 +02:00
|
|
|
|
|
|
|
case SEEK_END:
|
2023-08-01 03:58:01 +02:00
|
|
|
offset += np->n_size;
|
|
|
|
break;
|
2023-07-25 10:15:56 +02:00
|
|
|
|
|
|
|
default:
|
2023-08-01 03:58:01 +02:00
|
|
|
nxmutex_unlock(&nmp->nm_lock);
|
|
|
|
return -EINVAL;
|
2023-07-25 10:15:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (offset >= 0)
|
|
|
|
{
|
|
|
|
filep->f_pos = offset;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
nxmutex_unlock(&nmp->nm_lock);
|
|
|
|
return ret < 0 ? ret : offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nfs_sync
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Synchronize the file state on disk to match internal, in memory state.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int nfs_sync(FAR struct file *filep)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-14 20:22:32 +01:00
|
|
|
/****************************************************************************
|
2017-02-12 20:42:27 +01:00
|
|
|
* Name: nfs_dup
|
2013-01-14 20:22:32 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Duplicate open file data in the new file structure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int nfs_dup(FAR const struct file *oldp, FAR struct file *newp)
|
|
|
|
{
|
2020-03-01 21:53:45 +01:00
|
|
|
FAR struct nfsmount *nmp;
|
2013-01-14 20:22:32 +01:00
|
|
|
FAR struct nfsnode *np;
|
2020-03-30 17:00:51 +02:00
|
|
|
int ret;
|
2013-01-14 20:22:32 +01:00
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("Dup %p->%p\n", oldp, newp);
|
2013-01-14 20:22:32 +01:00
|
|
|
|
|
|
|
/* Sanity checks */
|
|
|
|
|
|
|
|
DEBUGASSERT(oldp->f_priv != NULL && oldp->f_inode != NULL);
|
|
|
|
|
|
|
|
/* Recover our private data from the struct file instance */
|
|
|
|
|
2023-08-29 06:16:49 +02:00
|
|
|
nmp = oldp->f_inode->i_private;
|
2015-10-11 19:39:29 +02:00
|
|
|
np = (FAR struct nfsnode *)oldp->f_priv;
|
2013-01-14 20:22:32 +01:00
|
|
|
|
|
|
|
DEBUGASSERT(nmp != NULL);
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxmutex_lock(&nmp->nm_lock);
|
2020-03-30 17:00:51 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2013-01-14 20:22:32 +01:00
|
|
|
|
|
|
|
/* Increment the reference count on the NFS node structure */
|
|
|
|
|
|
|
|
DEBUGASSERT(np->n_crefs < 0xff);
|
|
|
|
np->n_crefs++;
|
|
|
|
|
|
|
|
/* And save this as the file data for the new node */
|
|
|
|
|
|
|
|
newp->f_priv = np;
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&nmp->nm_lock);
|
2013-01-14 20:22:32 +01:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2017-02-12 20:42:27 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: nfs_fstat
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Obtain information about an open file associated with the file
|
2018-01-04 17:54:54 +01:00
|
|
|
* structure 'filep', and will write it to the area pointed to by 'buf'.
|
2017-02-12 20:42:27 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int nfs_fstat(FAR const struct file *filep, FAR struct stat *buf)
|
|
|
|
{
|
2017-02-13 17:07:43 +01:00
|
|
|
FAR struct nfsmount *nmp;
|
|
|
|
FAR struct nfsnode *np;
|
2020-03-30 17:00:51 +02:00
|
|
|
int ret;
|
2017-02-13 17:07:43 +01:00
|
|
|
|
|
|
|
finfo("Buf %p\n", buf);
|
2023-08-28 11:17:05 +02:00
|
|
|
DEBUGASSERT(buf != NULL);
|
2017-02-13 17:07:43 +01:00
|
|
|
|
|
|
|
/* Recover our private data from the struct file instance */
|
|
|
|
|
2023-08-28 11:17:05 +02:00
|
|
|
DEBUGASSERT(filep->f_priv != NULL);
|
2017-02-13 17:07:43 +01:00
|
|
|
np = (FAR struct nfsnode *)filep->f_priv;
|
|
|
|
|
2023-08-29 06:16:49 +02:00
|
|
|
nmp = filep->f_inode->i_private;
|
2017-02-13 17:07:43 +01:00
|
|
|
DEBUGASSERT(nmp != NULL);
|
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
memset(buf, 0, sizeof(*buf));
|
2017-02-13 17:07:43 +01:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxmutex_lock(&nmp->nm_lock);
|
2020-03-30 17:00:51 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2017-02-13 17:07:43 +01:00
|
|
|
|
|
|
|
/* Extract the file mode, file type, and file size from the nfsnode
|
|
|
|
* structure.
|
|
|
|
*/
|
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
buf->st_mode = nfs_stat_mode(np->n_mode, np->n_type);
|
|
|
|
buf->st_size = (off_t)np->n_size;
|
2017-02-13 17:07:43 +01:00
|
|
|
|
|
|
|
/* Extract time values as type time_t in units of seconds. */
|
|
|
|
|
2021-08-10 09:38:51 +02:00
|
|
|
buf->st_atim = np->n_atime;
|
|
|
|
buf->st_mtim = np->n_mtime;
|
|
|
|
buf->st_ctim = np->n_ctime;
|
2017-02-13 17:07:43 +01:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&nmp->nm_lock);
|
2020-03-01 21:53:45 +01:00
|
|
|
return OK;
|
2017-02-12 20:42:27 +01:00
|
|
|
}
|
|
|
|
|
2021-08-10 09:35:43 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: nfs_fchstat
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Change information about an open file associated with the file
|
|
|
|
* structure 'filep'.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int nfs_fchstat(FAR const struct file *filep,
|
|
|
|
FAR const struct stat *buf, int flags)
|
|
|
|
{
|
|
|
|
FAR struct nfsmount *nmp;
|
|
|
|
FAR struct nfsnode *np;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
finfo("Buf %p\n", buf);
|
2023-08-28 11:17:05 +02:00
|
|
|
DEBUGASSERT(buf != NULL);
|
2021-08-10 09:35:43 +02:00
|
|
|
|
|
|
|
/* Recover our private data from the struct file instance */
|
|
|
|
|
2023-08-28 11:17:05 +02:00
|
|
|
DEBUGASSERT(filep->f_priv != NULL);
|
2021-08-10 09:35:43 +02:00
|
|
|
np = (FAR struct nfsnode *)filep->f_priv;
|
|
|
|
|
2023-08-29 06:16:49 +02:00
|
|
|
nmp = filep->f_inode->i_private;
|
2021-08-10 09:35:43 +02:00
|
|
|
DEBUGASSERT(nmp != NULL);
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxmutex_lock(&nmp->nm_lock);
|
2021-08-10 09:35:43 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Change the file mode, owner, group and time. */
|
|
|
|
|
|
|
|
ret = nfs_filechstat(nmp, np, buf, flags);
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&nmp->nm_lock);
|
2021-08-10 09:35:43 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-01-04 17:54:54 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: nfs_truncate
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Set the length of the open, regular file associated with the file
|
|
|
|
* structure 'filep' to 'length'.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int nfs_truncate(FAR struct file *filep, off_t length)
|
|
|
|
{
|
2020-03-01 21:53:45 +01:00
|
|
|
FAR struct nfsmount *nmp;
|
|
|
|
FAR struct nfsnode *np;
|
2020-03-30 17:00:51 +02:00
|
|
|
int ret;
|
2018-01-04 17:54:54 +01:00
|
|
|
|
|
|
|
finfo("Truncate to %ld bytes\n", (long)length);
|
2023-08-28 11:17:05 +02:00
|
|
|
DEBUGASSERT(filep->f_priv != NULL);
|
2018-01-04 17:54:54 +01:00
|
|
|
|
|
|
|
/* Recover our private data from the struct file instance */
|
|
|
|
|
2023-08-29 06:16:49 +02:00
|
|
|
nmp = filep->f_inode->i_private;
|
2018-01-04 17:54:54 +01:00
|
|
|
np = (FAR struct nfsnode *)filep->f_priv;
|
|
|
|
|
|
|
|
DEBUGASSERT(nmp != NULL);
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxmutex_lock(&nmp->nm_lock);
|
2020-03-30 17:00:51 +02:00
|
|
|
if (ret >= 0)
|
|
|
|
{
|
2021-08-10 09:35:43 +02:00
|
|
|
struct stat buf;
|
|
|
|
|
2020-03-30 17:00:51 +02:00
|
|
|
/* Then perform the SETATTR RPC to set the new file size */
|
2018-01-04 17:54:54 +01:00
|
|
|
|
2021-08-10 09:35:43 +02:00
|
|
|
buf.st_size = length;
|
|
|
|
ret = nfs_filechstat(nmp, np, &buf, CH_STAT_SIZE);
|
2018-01-04 17:54:54 +01:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&nmp->nm_lock);
|
2020-03-30 17:00:51 +02:00
|
|
|
}
|
2018-01-04 17:54:54 +01:00
|
|
|
|
2020-03-30 17:00:51 +02:00
|
|
|
return ret;
|
2018-01-04 17:54:54 +01:00
|
|
|
}
|
|
|
|
|
2012-05-29 01:40:20 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: nfs_opendir
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Open a directory for read access
|
|
|
|
*
|
2012-06-07 18:53:46 +02:00
|
|
|
* Returned Value:
|
|
|
|
* 0 on success; a negated errno value on failure.
|
|
|
|
*
|
2012-05-29 01:40:20 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
static int nfs_opendir(FAR struct inode *mountpt, FAR const char *relpath,
|
2022-08-05 06:31:25 +02:00
|
|
|
FAR struct fs_dirent_s **dir)
|
2012-05-29 01:40:20 +02:00
|
|
|
{
|
2020-03-01 21:53:45 +01:00
|
|
|
FAR struct nfsmount *nmp;
|
2022-08-05 06:31:25 +02:00
|
|
|
FAR struct nfs_dir_s *ndir;
|
|
|
|
struct file_handle fhandle;
|
2012-06-10 20:16:01 +02:00
|
|
|
struct nfs_fattr obj_attributes;
|
|
|
|
uint32_t objtype;
|
2020-03-30 17:00:51 +02:00
|
|
|
int ret;
|
2012-05-29 01:40:20 +02:00
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("relpath: \"%s\"\n", relpath ? relpath : "NULL");
|
2012-05-29 01:40:20 +02:00
|
|
|
|
|
|
|
/* Sanity checks */
|
|
|
|
|
2012-06-10 20:16:01 +02:00
|
|
|
DEBUGASSERT(mountpt != NULL && mountpt->i_private != NULL && dir);
|
2012-05-29 01:40:20 +02:00
|
|
|
|
|
|
|
/* Recover our private data from the inode instance */
|
|
|
|
|
|
|
|
nmp = mountpt->i_private;
|
2024-09-09 14:28:16 +02:00
|
|
|
ndir = fs_heap_zalloc(sizeof(*ndir));
|
2022-08-05 06:31:25 +02:00
|
|
|
if (ndir == NULL)
|
|
|
|
{
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2012-05-29 01:40:20 +02:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxmutex_lock(&nmp->nm_lock);
|
2020-03-30 17:00:51 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2022-08-05 06:31:25 +02:00
|
|
|
goto errout_with_ndir;
|
2020-03-30 17:00:51 +02:00
|
|
|
}
|
2012-05-29 01:40:20 +02:00
|
|
|
|
2012-06-10 20:16:01 +02:00
|
|
|
/* Find the NFS node associate with the path */
|
2012-05-29 01:40:20 +02:00
|
|
|
|
2020-03-30 17:00:51 +02:00
|
|
|
ret = nfs_findnode(nmp, relpath, &fhandle, &obj_attributes, NULL);
|
|
|
|
if (ret != OK)
|
2012-05-31 01:21:37 +02:00
|
|
|
{
|
2020-03-30 17:00:51 +02:00
|
|
|
ferr("ERROR: nfs_findnode failed: %d\n", ret);
|
2022-09-06 08:18:45 +02:00
|
|
|
goto errout_with_lock;
|
2012-05-31 01:21:37 +02:00
|
|
|
}
|
|
|
|
|
2012-06-10 20:16:01 +02:00
|
|
|
/* The entry is a directory */
|
2012-06-06 23:51:03 +02:00
|
|
|
|
2012-06-10 20:16:01 +02:00
|
|
|
objtype = fxdr_unsigned(uint32_t, obj_attributes.fa_type);
|
|
|
|
if (objtype != NFDIR)
|
2012-06-06 23:51:03 +02:00
|
|
|
{
|
2020-11-25 12:09:09 +01:00
|
|
|
ferr("ERROR: Not a directory, type=%" PRId32 "\n", objtype);
|
2020-03-30 17:00:51 +02:00
|
|
|
ret = -ENOTDIR;
|
2022-09-06 08:18:45 +02:00
|
|
|
goto errout_with_lock;
|
2012-06-06 23:51:03 +02:00
|
|
|
}
|
|
|
|
|
2012-06-10 20:16:01 +02:00
|
|
|
/* Save the directory information in struct fs_dirent_s so that it can be
|
|
|
|
* used later when readdir() is called.
|
|
|
|
*/
|
2012-06-02 01:12:17 +02:00
|
|
|
|
2022-08-05 06:31:25 +02:00
|
|
|
ndir->nfs_fhsize = (uint8_t)fhandle.length;
|
2012-06-10 20:16:01 +02:00
|
|
|
DEBUGASSERT(fhandle.length <= DIRENT_NFS_MAXHANDLE);
|
|
|
|
|
2022-08-05 06:31:25 +02:00
|
|
|
memcpy(ndir->nfs_fhandle, &fhandle.handle, fhandle.length);
|
|
|
|
*dir = &ndir->nfs_base;
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&nmp->nm_lock);
|
2022-08-05 06:31:25 +02:00
|
|
|
return 0;
|
2012-05-29 01:40:20 +02:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
errout_with_lock:
|
|
|
|
nxmutex_unlock(&nmp->nm_lock);
|
2022-08-05 06:31:25 +02:00
|
|
|
errout_with_ndir:
|
2024-09-09 14:28:16 +02:00
|
|
|
fs_heap_free(ndir);
|
2020-03-30 17:00:51 +02:00
|
|
|
return ret;
|
2012-05-29 01:40:20 +02:00
|
|
|
}
|
|
|
|
|
2022-08-05 06:31:25 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: nfs_closedir
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Close directory
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* 0 on success; a negated errno value on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int nfs_closedir(FAR struct inode *mountpt,
|
|
|
|
FAR struct fs_dirent_s *dir)
|
|
|
|
{
|
|
|
|
DEBUGASSERT(dir);
|
2024-09-09 14:28:16 +02:00
|
|
|
fs_heap_free(dir);
|
2022-08-05 06:31:25 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-04-17 01:01:21 +02:00
|
|
|
/****************************************************************************
|
2012-06-10 20:16:01 +02:00
|
|
|
* Name: nfs_readdir
|
2012-04-17 01:01:21 +02:00
|
|
|
*
|
2012-06-10 20:16:01 +02:00
|
|
|
* Description: Read from directory
|
2012-06-07 18:53:46 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
2012-06-10 20:16:01 +02:00
|
|
|
* 0 on success; a negated errno value on failure.
|
2012-06-07 18:53:46 +02:00
|
|
|
*
|
2012-04-17 01:01:21 +02:00
|
|
|
****************************************************************************/
|
2012-03-27 02:23:40 +02:00
|
|
|
|
2020-03-30 17:00:51 +02:00
|
|
|
static int nfs_readdir(FAR struct inode *mountpt,
|
2022-07-26 08:56:41 +02:00
|
|
|
FAR struct fs_dirent_s *dir,
|
|
|
|
FAR struct dirent *entry)
|
2012-03-27 02:23:40 +02:00
|
|
|
{
|
2020-03-01 21:53:45 +01:00
|
|
|
FAR struct nfsmount *nmp;
|
2022-08-05 06:31:25 +02:00
|
|
|
FAR struct nfs_dir_s *ndir;
|
2012-06-10 02:13:59 +02:00
|
|
|
struct file_handle fhandle;
|
|
|
|
struct nfs_fattr obj_attributes;
|
2018-08-26 21:11:24 +02:00
|
|
|
uint32_t readsize;
|
2012-06-09 02:08:18 +02:00
|
|
|
uint32_t tmp;
|
2020-03-01 21:53:45 +01:00
|
|
|
FAR uint32_t *ptr;
|
|
|
|
FAR uint8_t *name;
|
2012-06-09 02:08:18 +02:00
|
|
|
unsigned int length;
|
2012-06-10 20:16:01 +02:00
|
|
|
int reqlen;
|
2020-03-30 17:00:51 +02:00
|
|
|
int ret;
|
2012-03-27 02:23:40 +02:00
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("Entry\n");
|
2012-06-10 20:16:01 +02:00
|
|
|
|
|
|
|
/* Sanity checks */
|
|
|
|
|
|
|
|
DEBUGASSERT(mountpt != NULL && mountpt->i_private != NULL);
|
|
|
|
|
|
|
|
/* Recover our private data from the inode instance */
|
|
|
|
|
|
|
|
nmp = mountpt->i_private;
|
2022-08-05 06:31:25 +02:00
|
|
|
ndir = (FAR struct nfs_dir_s *)dir;
|
2012-06-10 20:16:01 +02:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxmutex_lock(&nmp->nm_lock);
|
2020-03-30 17:00:51 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2012-06-10 20:16:01 +02:00
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
read_dir:
|
2012-06-11 23:16:35 +02:00
|
|
|
/* Request a block directory entries, copying directory information from
|
|
|
|
* the dirent structure.
|
2012-06-09 02:08:18 +02:00
|
|
|
*/
|
|
|
|
|
2015-10-11 19:39:29 +02:00
|
|
|
ptr = (FAR uint32_t *)&nmp->nm_msgbuffer.readdir.readdir;
|
2012-06-11 23:16:35 +02:00
|
|
|
reqlen = 0;
|
2012-06-10 20:16:01 +02:00
|
|
|
|
2012-06-11 23:16:35 +02:00
|
|
|
/* Copy the variable length, directory file handle */
|
2012-06-10 20:16:01 +02:00
|
|
|
|
2022-08-05 06:31:25 +02:00
|
|
|
*ptr++ = txdr_unsigned((uint32_t)ndir->nfs_fhsize);
|
2012-06-11 23:16:35 +02:00
|
|
|
reqlen += sizeof(uint32_t);
|
2012-06-10 20:16:01 +02:00
|
|
|
|
2022-08-05 06:31:25 +02:00
|
|
|
memcpy(ptr, ndir->nfs_fhandle, ndir->nfs_fhsize);
|
|
|
|
reqlen += uint32_alignup(ndir->nfs_fhsize);
|
|
|
|
ptr += uint32_increment(ndir->nfs_fhsize);
|
2012-06-10 20:16:01 +02:00
|
|
|
|
2012-06-11 23:16:35 +02:00
|
|
|
/* Cookie and cookie verifier */
|
2012-06-10 20:16:01 +02:00
|
|
|
|
2022-08-05 06:31:25 +02:00
|
|
|
ptr[0] = ndir->nfs_cookie[0];
|
|
|
|
ptr[1] = ndir->nfs_cookie[1];
|
2012-06-11 23:16:35 +02:00
|
|
|
ptr += 2;
|
|
|
|
reqlen += 2*sizeof(uint32_t);
|
2012-03-27 02:23:40 +02:00
|
|
|
|
2022-08-05 06:31:25 +02:00
|
|
|
memcpy(ptr, ndir->nfs_verifier, DIRENT_NFS_VERFLEN);
|
2012-06-11 23:16:35 +02:00
|
|
|
ptr += uint32_increment(DIRENT_NFS_VERFLEN);
|
|
|
|
reqlen += DIRENT_NFS_VERFLEN;
|
2012-06-10 20:16:01 +02:00
|
|
|
|
2020-07-02 16:03:27 +02:00
|
|
|
/* Number of directory entries (We currently only process one entry at a
|
|
|
|
* time)
|
|
|
|
*/
|
2012-06-10 20:16:01 +02:00
|
|
|
|
2018-08-26 21:11:24 +02:00
|
|
|
readsize = nmp->nm_readdirsize;
|
|
|
|
tmp = SIZEOF_rpc_reply_readdir(readsize);
|
|
|
|
if (tmp > nmp->nm_buflen)
|
|
|
|
{
|
|
|
|
readsize -= (tmp - nmp->nm_buflen);
|
|
|
|
}
|
|
|
|
|
|
|
|
*ptr = txdr_unsigned(readsize);
|
|
|
|
reqlen += sizeof(uint32_t);
|
2012-06-10 20:16:01 +02:00
|
|
|
|
2012-06-11 23:16:35 +02:00
|
|
|
/* And read the directory */
|
2012-06-10 20:16:01 +02:00
|
|
|
|
2012-06-12 19:36:48 +02:00
|
|
|
nfs_statistics(NFSPROC_READDIR);
|
2020-03-30 17:00:51 +02:00
|
|
|
ret = nfs_request(nmp, NFSPROC_READDIR,
|
2022-09-06 08:18:45 +02:00
|
|
|
&nmp->nm_msgbuffer.readdir, reqlen,
|
|
|
|
nmp->nm_iobuffer, nmp->nm_buflen);
|
2020-03-30 17:00:51 +02:00
|
|
|
if (ret != OK)
|
2012-06-11 23:16:35 +02:00
|
|
|
{
|
2020-03-30 17:00:51 +02:00
|
|
|
ferr("ERROR: nfs_request failed: %d\n", ret);
|
2022-09-06 08:18:45 +02:00
|
|
|
goto errout_with_lock;
|
2012-06-11 23:16:35 +02:00
|
|
|
}
|
2012-06-07 20:47:20 +02:00
|
|
|
|
2012-06-11 23:16:35 +02:00
|
|
|
/* A new group of entries was successfully read. Process the
|
|
|
|
* information contained in the response header. This information
|
|
|
|
* includes:
|
|
|
|
*
|
|
|
|
* 1) Attributes follow indication - 4 bytes
|
|
|
|
* 2) Directory attributes - sizeof(struct nfs_fattr)
|
|
|
|
* 3) Cookie verifier - NFSX_V3COOKIEVERF bytes
|
|
|
|
* 4) Values follows indication - 4 bytes
|
|
|
|
*/
|
2012-06-07 20:47:20 +02:00
|
|
|
|
2020-03-30 17:00:51 +02:00
|
|
|
ptr = (FAR uint32_t *)
|
|
|
|
&((FAR struct rpc_reply_readdir *)nmp->nm_iobuffer)->readdir;
|
2012-06-07 20:47:20 +02:00
|
|
|
|
2012-06-11 23:16:35 +02:00
|
|
|
/* Check if attributes follow, if 0 so Skip over the attributes */
|
2012-03-31 01:56:35 +02:00
|
|
|
|
2012-06-11 23:16:35 +02:00
|
|
|
tmp = *ptr++;
|
|
|
|
if (tmp != 0)
|
|
|
|
{
|
|
|
|
/* Attributes are not currently used */
|
2012-06-09 02:08:18 +02:00
|
|
|
|
2012-06-11 23:16:35 +02:00
|
|
|
ptr += uint32_increment(sizeof(struct nfs_fattr));
|
|
|
|
}
|
2012-06-09 02:08:18 +02:00
|
|
|
|
2012-06-11 23:16:35 +02:00
|
|
|
/* Save the verification cookie */
|
2012-06-09 02:08:18 +02:00
|
|
|
|
2022-08-05 06:31:25 +02:00
|
|
|
memcpy(ndir->nfs_verifier, ptr, DIRENT_NFS_VERFLEN);
|
2012-06-11 23:16:35 +02:00
|
|
|
ptr += uint32_increment(DIRENT_NFS_VERFLEN);
|
2012-06-09 02:08:18 +02:00
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
next_entry:
|
2012-06-11 23:16:35 +02:00
|
|
|
/* Check if values follow. If no values follow, then the EOF indication
|
|
|
|
* will appear next.
|
|
|
|
*/
|
2012-06-09 02:08:18 +02:00
|
|
|
|
2012-06-11 23:16:35 +02:00
|
|
|
tmp = *ptr++;
|
|
|
|
if (tmp == 0)
|
|
|
|
{
|
|
|
|
/* No values follow, then the reply should consist only of a 4-byte
|
|
|
|
* end-of-directory indication.
|
2012-03-31 01:56:35 +02:00
|
|
|
*/
|
|
|
|
|
2012-06-11 23:16:35 +02:00
|
|
|
tmp = *ptr++;
|
|
|
|
if (tmp != 0)
|
2012-06-09 02:08:18 +02:00
|
|
|
{
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("End of directory\n");
|
2020-03-30 17:00:51 +02:00
|
|
|
ret = -ENOENT;
|
2022-09-06 08:18:45 +02:00
|
|
|
goto errout_with_lock;
|
2012-06-09 02:08:18 +02:00
|
|
|
}
|
2012-06-11 23:16:35 +02:00
|
|
|
|
|
|
|
/* What would it mean if there were not data and we not at the end of
|
|
|
|
* file?
|
|
|
|
*/
|
|
|
|
|
|
|
|
else
|
2019-10-27 18:48:14 +01:00
|
|
|
{
|
|
|
|
finfo("No data but not end of directory???\n");
|
2020-03-01 21:53:45 +01:00
|
|
|
goto read_dir;
|
2012-06-09 02:08:18 +02:00
|
|
|
}
|
2012-03-27 02:23:40 +02:00
|
|
|
}
|
|
|
|
|
2012-06-09 02:08:18 +02:00
|
|
|
/* If we are not at the end of the directory listing, then a set of entries
|
|
|
|
* will follow the header. Each entry is of the form:
|
|
|
|
*
|
|
|
|
* File ID (8 bytes)
|
|
|
|
* Name length (4 bytes)
|
2020-02-23 09:50:23 +01:00
|
|
|
* Name string (variable size but in multiples of 4 bytes)
|
2012-06-09 02:08:18 +02:00
|
|
|
* Cookie (8 bytes)
|
|
|
|
* next entry (4 bytes)
|
|
|
|
*/
|
2012-06-08 17:45:40 +02:00
|
|
|
|
2012-06-11 23:16:35 +02:00
|
|
|
/* There is an entry. Skip over the file ID and point to the length */
|
2012-06-08 17:45:40 +02:00
|
|
|
|
2012-06-11 23:16:35 +02:00
|
|
|
ptr += 2;
|
2012-06-08 17:45:40 +02:00
|
|
|
|
2012-06-11 23:16:35 +02:00
|
|
|
/* Get the length and point to the name */
|
2012-06-08 17:45:40 +02:00
|
|
|
|
2012-06-11 23:16:35 +02:00
|
|
|
tmp = *ptr++;
|
|
|
|
length = fxdr_unsigned(uint32_t, tmp);
|
2015-10-11 19:39:29 +02:00
|
|
|
name = (FAR uint8_t *)ptr;
|
2012-06-09 02:08:18 +02:00
|
|
|
|
2012-06-11 23:16:35 +02:00
|
|
|
/* Increment the pointer past the name (allowing for padding). ptr
|
|
|
|
* now points to the cookie.
|
|
|
|
*/
|
2012-06-09 02:08:18 +02:00
|
|
|
|
2012-06-11 23:16:35 +02:00
|
|
|
ptr += uint32_increment(length);
|
2012-06-09 02:08:18 +02:00
|
|
|
|
2012-06-11 23:16:35 +02:00
|
|
|
/* Save the cookie and increment the pointer to the next entry */
|
2012-06-09 02:08:18 +02:00
|
|
|
|
2022-08-05 06:31:25 +02:00
|
|
|
ndir->nfs_cookie[0] = *ptr++;
|
|
|
|
ndir->nfs_cookie[1] = *ptr++;
|
2012-06-09 02:08:18 +02:00
|
|
|
|
2012-06-11 23:16:35 +02:00
|
|
|
/* Return the name of the node to the caller */
|
2012-06-10 02:13:59 +02:00
|
|
|
|
2012-06-11 23:16:35 +02:00
|
|
|
if (length > NAME_MAX)
|
|
|
|
{
|
|
|
|
length = NAME_MAX;
|
|
|
|
}
|
2012-06-10 02:13:59 +02:00
|
|
|
|
2022-07-26 08:56:41 +02:00
|
|
|
memcpy(entry->d_name, name, length);
|
|
|
|
entry->d_name[length] = '\0';
|
|
|
|
finfo("name: \"%s\"\n", entry->d_name);
|
2012-06-08 17:45:40 +02:00
|
|
|
|
2022-07-26 08:56:41 +02:00
|
|
|
if (strcmp(entry->d_name, ".") == 0 ||
|
|
|
|
strcmp(entry->d_name, "..") == 0)
|
2020-03-01 21:53:45 +01:00
|
|
|
{
|
|
|
|
goto next_entry; /* Skip . and .. */
|
|
|
|
}
|
|
|
|
|
2012-06-11 23:16:35 +02:00
|
|
|
/* Get the file attributes associated with this name and return
|
|
|
|
* the file type.
|
|
|
|
*/
|
2012-06-08 17:45:40 +02:00
|
|
|
|
2022-08-05 06:31:25 +02:00
|
|
|
fhandle.length = (uint32_t)ndir->nfs_fhsize;
|
|
|
|
memcpy(&fhandle.handle, ndir->nfs_fhandle, fhandle.length);
|
2012-06-10 02:13:59 +02:00
|
|
|
|
2022-07-26 08:56:41 +02:00
|
|
|
ret = nfs_lookup(nmp, entry->d_name, &fhandle, &obj_attributes, NULL);
|
2020-03-30 17:00:51 +02:00
|
|
|
if (ret != OK)
|
2012-06-11 23:16:35 +02:00
|
|
|
{
|
2020-03-30 17:00:51 +02:00
|
|
|
ferr("ERROR: nfs_lookup failed: %d\n", ret);
|
2022-09-06 08:18:45 +02:00
|
|
|
goto errout_with_lock;
|
2012-06-11 23:16:35 +02:00
|
|
|
}
|
2012-06-10 02:13:59 +02:00
|
|
|
|
2012-06-11 23:16:35 +02:00
|
|
|
/* Set the dirent file type */
|
2012-06-10 02:13:59 +02:00
|
|
|
|
2012-06-11 23:16:35 +02:00
|
|
|
tmp = fxdr_unsigned(uint32_t, obj_attributes.fa_type);
|
|
|
|
switch (tmp)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case NFNON: /* Unknown type */
|
2020-03-01 21:53:45 +01:00
|
|
|
break;
|
|
|
|
|
2012-06-11 23:16:35 +02:00
|
|
|
case NFSOCK: /* Socket */
|
2022-07-26 08:56:41 +02:00
|
|
|
entry->d_type = DTYPE_SOCK;
|
2020-03-01 21:53:45 +01:00
|
|
|
break;
|
|
|
|
|
2012-06-11 23:16:35 +02:00
|
|
|
case NFLNK: /* Symbolic link */
|
2022-07-26 08:56:41 +02:00
|
|
|
entry->d_type = DTYPE_LINK;
|
2012-06-11 23:16:35 +02:00
|
|
|
break;
|
2012-06-10 02:13:59 +02:00
|
|
|
|
2012-06-11 23:16:35 +02:00
|
|
|
case NFREG: /* Regular file */
|
2022-07-26 08:56:41 +02:00
|
|
|
entry->d_type = DTYPE_FILE;
|
2012-06-11 23:16:35 +02:00
|
|
|
break;
|
2012-06-08 20:56:01 +02:00
|
|
|
|
2012-06-11 23:16:35 +02:00
|
|
|
case NFDIR: /* Directory */
|
2022-07-26 08:56:41 +02:00
|
|
|
entry->d_type = DTYPE_DIRECTORY;
|
2012-06-11 23:16:35 +02:00
|
|
|
break;
|
2012-06-08 17:45:40 +02:00
|
|
|
|
2012-06-11 23:16:35 +02:00
|
|
|
case NFBLK: /* Block special device file */
|
2022-07-26 08:56:41 +02:00
|
|
|
entry->d_type = DTYPE_BLK;
|
2012-06-11 23:16:35 +02:00
|
|
|
break;
|
2012-06-08 17:45:40 +02:00
|
|
|
|
2012-06-11 23:16:35 +02:00
|
|
|
case NFFIFO: /* Named FIFO */
|
2022-07-26 08:56:41 +02:00
|
|
|
entry->d_type = DTYPE_FIFO;
|
2020-03-01 21:53:45 +01:00
|
|
|
break;
|
|
|
|
|
2012-06-11 23:16:35 +02:00
|
|
|
case NFCHR: /* Character special device file */
|
2022-07-26 08:56:41 +02:00
|
|
|
entry->d_type = DTYPE_CHR;
|
2012-06-11 23:16:35 +02:00
|
|
|
break;
|
2012-04-17 01:01:21 +02:00
|
|
|
}
|
2019-10-27 18:48:14 +01:00
|
|
|
|
2022-07-26 08:56:41 +02:00
|
|
|
finfo("type: %d->%d\n", (int)tmp, entry->d_type);
|
2012-06-07 18:53:46 +02:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
errout_with_lock:
|
|
|
|
nxmutex_unlock(&nmp->nm_lock);
|
2020-03-30 17:00:51 +02:00
|
|
|
return ret;
|
2012-04-17 01:01:21 +02:00
|
|
|
}
|
|
|
|
|
2012-06-14 23:54:50 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: nfs_rewinddir
|
|
|
|
*
|
|
|
|
* Description:
|
2020-02-23 09:50:23 +01:00
|
|
|
* Reset the directory traversal logic to the first entry in the open
|
2012-06-14 23:54:50 +02:00
|
|
|
* directory.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* 0 on success; a negated errno value on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-03-07 18:43:40 +01:00
|
|
|
static int nfs_rewinddir(FAR struct inode *mountpt,
|
|
|
|
FAR struct fs_dirent_s *dir)
|
2012-06-14 23:54:50 +02:00
|
|
|
{
|
2022-08-05 06:31:25 +02:00
|
|
|
FAR struct nfs_dir_s *ndir;
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("Entry\n");
|
2012-06-14 23:54:50 +02:00
|
|
|
|
|
|
|
/* Sanity checks */
|
|
|
|
|
|
|
|
DEBUGASSERT(mountpt != NULL && dir != NULL);
|
|
|
|
|
2022-08-05 06:31:25 +02:00
|
|
|
ndir = (FAR struct nfs_dir_s *)dir;
|
|
|
|
|
2012-06-14 23:54:50 +02:00
|
|
|
/* Reset the NFS-specific portions of dirent structure, retaining only the
|
|
|
|
* file handle.
|
|
|
|
*/
|
|
|
|
|
2022-08-05 06:31:25 +02:00
|
|
|
memset(&ndir->nfs_verifier, 0, DIRENT_NFS_VERFLEN);
|
|
|
|
ndir->nfs_cookie[0] = 0;
|
|
|
|
ndir->nfs_cookie[1] = 0;
|
2012-06-14 23:54:50 +02:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2012-04-17 01:01:21 +02:00
|
|
|
/****************************************************************************
|
2012-04-19 01:31:47 +02:00
|
|
|
* Name: nfs_decode_args
|
2012-06-07 18:53:46 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
2012-04-17 01:01:21 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2012-06-14 23:54:50 +02:00
|
|
|
static void nfs_decode_args(FAR struct nfs_mount_parameters *nprmt,
|
|
|
|
FAR struct nfs_args *argp)
|
2012-04-17 01:01:21 +02:00
|
|
|
{
|
2012-04-19 01:31:47 +02:00
|
|
|
int maxio;
|
2012-04-17 01:01:21 +02:00
|
|
|
|
2012-06-14 23:54:50 +02:00
|
|
|
/* Get the selected timeout value */
|
2012-04-17 01:01:21 +02:00
|
|
|
|
2012-06-14 16:35:31 +02:00
|
|
|
if ((argp->flags & NFSMNT_TIMEO) != 0 && argp->timeo > 0)
|
2012-04-19 01:31:47 +02:00
|
|
|
{
|
2020-03-01 21:53:45 +01:00
|
|
|
if (argp->timeo < NFS_MINTIMEO)
|
2012-04-17 01:01:21 +02:00
|
|
|
{
|
2020-03-01 21:53:45 +01:00
|
|
|
nprmt->timeo = NFS_MINTIMEO;
|
2012-04-17 01:01:21 +02:00
|
|
|
}
|
2020-03-01 21:53:45 +01:00
|
|
|
else if (argp->timeo > NFS_MAXTIMEO)
|
2012-04-17 01:01:21 +02:00
|
|
|
{
|
2020-03-01 21:53:45 +01:00
|
|
|
nprmt->timeo = NFS_MAXTIMEO;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nprmt->timeo = argp->timeo;
|
2012-04-17 01:01:21 +02:00
|
|
|
}
|
2012-04-19 01:31:47 +02:00
|
|
|
}
|
2012-04-17 01:01:21 +02:00
|
|
|
|
2012-06-14 23:54:50 +02:00
|
|
|
/* Get the selected retransmission count */
|
|
|
|
|
2012-06-14 16:35:31 +02:00
|
|
|
if ((argp->flags & NFSMNT_RETRANS) != 0 && argp->retrans > 1)
|
2012-04-19 01:31:47 +02:00
|
|
|
{
|
2012-06-14 16:35:31 +02:00
|
|
|
if (argp->retrans < NFS_MAXREXMIT)
|
|
|
|
{
|
|
|
|
nprmt->retry = argp->retrans;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nprmt->retry = NFS_MAXREXMIT;
|
|
|
|
}
|
2012-04-19 01:31:47 +02:00
|
|
|
}
|
2012-04-17 01:01:21 +02:00
|
|
|
|
2012-06-14 16:35:31 +02:00
|
|
|
if ((argp->flags & NFSMNT_SOFT) == 0)
|
2012-04-19 01:31:47 +02:00
|
|
|
{
|
2012-06-14 02:47:42 +02:00
|
|
|
nprmt->retry = NFS_MAXREXMIT + 1; /* Past clip limit */
|
2012-04-19 01:31:47 +02:00
|
|
|
}
|
2012-04-17 01:01:21 +02:00
|
|
|
|
2012-06-14 23:54:50 +02:00
|
|
|
/* Get the maximum amount of data that can be transferred in one packet */
|
|
|
|
|
2020-03-01 10:24:29 +01:00
|
|
|
if (argp->sotype == SOCK_DGRAM)
|
2012-04-19 01:31:47 +02:00
|
|
|
{
|
2012-06-14 16:35:31 +02:00
|
|
|
maxio = NFS_MAXDGRAMDATA;
|
2012-04-19 01:31:47 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-06-14 16:35:31 +02:00
|
|
|
maxio = NFS_MAXDATA;
|
2012-04-19 01:31:47 +02:00
|
|
|
}
|
2012-04-17 01:01:21 +02:00
|
|
|
|
2020-03-01 10:24:29 +01:00
|
|
|
if (maxio > MAXBSIZE)
|
|
|
|
{
|
|
|
|
maxio = MAXBSIZE;
|
|
|
|
}
|
|
|
|
|
2020-07-02 16:03:27 +02:00
|
|
|
/* Get the maximum amount of data that can be transferred in one write
|
|
|
|
* transfer
|
|
|
|
*/
|
2012-06-14 23:54:50 +02:00
|
|
|
|
2012-06-14 16:35:31 +02:00
|
|
|
if ((argp->flags & NFSMNT_WSIZE) != 0 && argp->wsize > 0)
|
2012-04-19 01:31:47 +02:00
|
|
|
{
|
2012-06-14 02:47:42 +02:00
|
|
|
nprmt->wsize = argp->wsize;
|
2012-04-17 01:01:21 +02:00
|
|
|
|
2012-04-19 01:31:47 +02:00
|
|
|
/* Round down to multiple of blocksize */
|
2012-04-17 01:01:21 +02:00
|
|
|
|
2012-06-14 02:47:42 +02:00
|
|
|
nprmt->wsize &= ~(NFS_FABLKSIZE - 1);
|
|
|
|
if (nprmt->wsize <= 0)
|
2012-04-19 01:31:47 +02:00
|
|
|
{
|
2012-06-14 02:47:42 +02:00
|
|
|
nprmt->wsize = NFS_FABLKSIZE;
|
2012-04-19 01:31:47 +02:00
|
|
|
}
|
|
|
|
}
|
2012-04-17 01:01:21 +02:00
|
|
|
|
2012-06-14 02:47:42 +02:00
|
|
|
if (nprmt->wsize > maxio)
|
2012-04-17 01:01:21 +02:00
|
|
|
{
|
2012-06-14 02:47:42 +02:00
|
|
|
nprmt->wsize = maxio;
|
2012-04-17 01:01:21 +02:00
|
|
|
}
|
|
|
|
|
2020-07-02 16:03:27 +02:00
|
|
|
/* Get the maximum amount of data that can be transferred in one read
|
|
|
|
* transfer
|
|
|
|
*/
|
2012-06-14 23:54:50 +02:00
|
|
|
|
2012-06-14 16:35:31 +02:00
|
|
|
if ((argp->flags & NFSMNT_RSIZE) != 0 && argp->rsize > 0)
|
2012-04-19 01:31:47 +02:00
|
|
|
{
|
2012-06-14 02:47:42 +02:00
|
|
|
nprmt->rsize = argp->rsize;
|
2012-04-19 01:31:47 +02:00
|
|
|
|
|
|
|
/* Round down to multiple of blocksize */
|
|
|
|
|
2012-06-14 02:47:42 +02:00
|
|
|
nprmt->rsize &= ~(NFS_FABLKSIZE - 1);
|
|
|
|
if (nprmt->rsize <= 0)
|
2012-04-19 01:31:47 +02:00
|
|
|
{
|
2012-06-14 02:47:42 +02:00
|
|
|
nprmt->rsize = NFS_FABLKSIZE;
|
2012-04-19 01:31:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-14 02:47:42 +02:00
|
|
|
if (nprmt->rsize > maxio)
|
2012-04-19 01:31:47 +02:00
|
|
|
{
|
2012-06-14 02:47:42 +02:00
|
|
|
nprmt->rsize = maxio;
|
2012-04-19 01:31:47 +02:00
|
|
|
}
|
|
|
|
|
2020-07-02 16:03:27 +02:00
|
|
|
/* Get the maximum amount of data that can be transferred in directory
|
|
|
|
* transfer
|
|
|
|
*/
|
2012-06-14 23:54:50 +02:00
|
|
|
|
2012-06-14 16:35:31 +02:00
|
|
|
if ((argp->flags & NFSMNT_READDIRSIZE) != 0 && argp->readdirsize > 0)
|
2012-04-19 01:31:47 +02:00
|
|
|
{
|
2012-06-14 02:47:42 +02:00
|
|
|
nprmt->readdirsize = argp->readdirsize;
|
2012-04-19 01:31:47 +02:00
|
|
|
|
|
|
|
/* Round down to multiple of blocksize */
|
|
|
|
|
2012-06-14 02:47:42 +02:00
|
|
|
nprmt->readdirsize &= ~(NFS_DIRBLKSIZ - 1);
|
|
|
|
if (nprmt->readdirsize < NFS_DIRBLKSIZ)
|
2012-04-19 01:31:47 +02:00
|
|
|
{
|
2012-06-14 02:47:42 +02:00
|
|
|
nprmt->readdirsize = NFS_DIRBLKSIZ;
|
2012-04-19 01:31:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (argp->flags & NFSMNT_RSIZE)
|
|
|
|
{
|
2012-06-14 02:47:42 +02:00
|
|
|
nprmt->readdirsize = nprmt->rsize;
|
2012-04-19 01:31:47 +02:00
|
|
|
}
|
|
|
|
|
2012-06-14 02:47:42 +02:00
|
|
|
if (nprmt->readdirsize > maxio)
|
2012-04-19 01:31:47 +02:00
|
|
|
{
|
2012-06-14 02:47:42 +02:00
|
|
|
nprmt->readdirsize = maxio;
|
2012-04-19 01:31:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-06-14 16:35:31 +02:00
|
|
|
* Name: nfs_bind
|
2012-04-19 01:31:47 +02:00
|
|
|
*
|
2012-06-14 23:54:50 +02:00
|
|
|
* Description:
|
|
|
|
* This implements a portion of the mount operation. This function allocates
|
|
|
|
* and initializes the mountpoint private data and gets mount information
|
|
|
|
* from the NFS server. The final binding of the private data (containing
|
|
|
|
* NFS server mount information) to the mountpoint is performed by mount().
|
2012-06-07 18:53:46 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
2012-06-14 16:35:31 +02:00
|
|
|
* 0 on success; a negated errno value on failure.
|
2012-04-19 01:31:47 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-06-14 16:35:31 +02:00
|
|
|
static int nfs_bind(FAR struct inode *blkdriver, FAR const void *data,
|
|
|
|
FAR void **handle)
|
2012-04-19 01:31:47 +02:00
|
|
|
{
|
2012-06-14 16:35:31 +02:00
|
|
|
FAR struct nfs_args *argp = (FAR struct nfs_args *)data;
|
2012-06-14 02:47:42 +02:00
|
|
|
FAR struct nfsmount *nmp;
|
2020-03-01 21:53:45 +01:00
|
|
|
FAR struct rpcclnt *rpc;
|
2012-06-14 02:47:42 +02:00
|
|
|
struct nfs_mount_parameters nprmt;
|
|
|
|
uint32_t buflen;
|
|
|
|
uint32_t tmp;
|
2020-03-30 17:00:51 +02:00
|
|
|
int ret = 0;
|
2012-06-14 02:47:42 +02:00
|
|
|
|
2012-06-14 16:35:31 +02:00
|
|
|
DEBUGASSERT(data && handle);
|
|
|
|
|
|
|
|
/* Set default values of the parameters. These may be overridden by
|
|
|
|
* settings in the argp->flags.
|
|
|
|
*/
|
2012-06-14 02:47:42 +02:00
|
|
|
|
|
|
|
nprmt.timeo = NFS_TIMEO;
|
|
|
|
nprmt.retry = NFS_RETRANS;
|
|
|
|
nprmt.wsize = NFS_WSIZE;
|
|
|
|
nprmt.rsize = NFS_RSIZE;
|
|
|
|
nprmt.readdirsize = NFS_READDIRSIZE;
|
|
|
|
|
|
|
|
nfs_decode_args(&nprmt, argp);
|
|
|
|
|
2015-10-11 19:39:29 +02:00
|
|
|
/* Determine the size of a buffer that will hold one RPC data transfer.
|
|
|
|
* First, get the maximum size of a read and a write transfer.
|
|
|
|
*/
|
2012-06-14 02:47:42 +02:00
|
|
|
|
|
|
|
buflen = SIZEOF_rpc_call_write(nprmt.wsize);
|
|
|
|
tmp = SIZEOF_rpc_reply_read(nprmt.rsize);
|
|
|
|
|
|
|
|
/* The buffer size will be the maximum of those two sizes */
|
|
|
|
|
2020-03-01 10:24:29 +01:00
|
|
|
if (tmp > buflen)
|
|
|
|
{
|
|
|
|
buflen = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* And consider the maximum size of a read dir transfer too */
|
|
|
|
|
|
|
|
tmp = SIZEOF_rpc_reply_readdir(nprmt.readdirsize);
|
2012-06-14 02:47:42 +02:00
|
|
|
if (tmp > buflen)
|
|
|
|
{
|
|
|
|
buflen = tmp;
|
|
|
|
}
|
|
|
|
|
2014-11-15 20:13:23 +01:00
|
|
|
/* But don't let the buffer size exceed the MSS of the socket type.
|
|
|
|
*
|
|
|
|
* In the case where there are multiple network devices with different
|
2017-08-08 23:26:09 +02:00
|
|
|
* link layer protocols, each network device may support a different
|
|
|
|
* UDP MSS value. Here we arbitrarily select the minimum MSS for
|
|
|
|
* that case.
|
2014-11-15 20:13:23 +01:00
|
|
|
*/
|
2012-06-14 02:47:42 +02:00
|
|
|
|
2020-03-01 10:24:29 +01:00
|
|
|
if (argp->sotype == SOCK_DGRAM && buflen > MIN_UDP_MSS)
|
2012-06-14 02:47:42 +02:00
|
|
|
{
|
2020-03-01 10:24:29 +01:00
|
|
|
buflen = MIN_UDP_MSS;
|
2012-06-14 02:47:42 +02:00
|
|
|
}
|
2012-04-19 01:31:47 +02:00
|
|
|
|
|
|
|
/* Create an instance of the mountpt state structure */
|
2012-04-26 01:22:09 +02:00
|
|
|
|
2024-09-09 14:28:16 +02:00
|
|
|
nmp = fs_heap_zalloc(SIZEOF_nfsmount(buflen));
|
2012-04-19 01:31:47 +02:00
|
|
|
if (!nmp)
|
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: Failed to allocate mountpoint structure\n");
|
2020-03-01 21:53:45 +01:00
|
|
|
return -ENOMEM;
|
2012-04-19 01:31:47 +02:00
|
|
|
}
|
2012-04-26 01:22:09 +02:00
|
|
|
|
2012-06-14 02:47:42 +02:00
|
|
|
/* Save the allocated I/O buffer size */
|
|
|
|
|
|
|
|
nmp->nm_buflen = (uint16_t)buflen;
|
|
|
|
|
2012-06-07 18:53:46 +02:00
|
|
|
/* Initialize the allocated mountpt state structure. */
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
/* Initialize the mutex that controls access.
|
|
|
|
* nxmutex_lock() is called at the completion of
|
2020-03-30 17:00:51 +02:00
|
|
|
* initialization, incrementing the count to one.
|
2012-04-19 01:31:47 +02:00
|
|
|
*/
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_init(&nmp->nm_lock); /* Initialize the mutex that
|
|
|
|
* controls access */
|
2012-04-19 01:31:47 +02:00
|
|
|
|
2012-06-07 18:53:46 +02:00
|
|
|
/* Initialize NFS */
|
|
|
|
|
2012-06-28 00:03:32 +02:00
|
|
|
nfs_true = txdr_unsigned(TRUE);
|
|
|
|
nfs_false = txdr_unsigned(FALSE);
|
|
|
|
nfs_xdrneg1 = txdr_unsigned(-1);
|
|
|
|
|
|
|
|
rpcclnt_init();
|
2012-06-07 03:03:34 +02:00
|
|
|
|
2012-06-07 18:53:46 +02:00
|
|
|
/* Set initial values of other fields */
|
|
|
|
|
2012-06-14 02:47:42 +02:00
|
|
|
nmp->nm_wsize = nprmt.wsize;
|
|
|
|
nmp->nm_rsize = nprmt.rsize;
|
|
|
|
nmp->nm_readdirsize = nprmt.readdirsize;
|
2012-06-08 00:00:19 +02:00
|
|
|
|
2022-03-18 16:47:00 +01:00
|
|
|
strlcpy(nmp->nm_path, argp->path, sizeof(nmp->nm_path));
|
2012-06-08 00:00:19 +02:00
|
|
|
memcpy(&nmp->nm_nam, &argp->addr, argp->addrlen);
|
|
|
|
|
2020-03-01 10:24:29 +01:00
|
|
|
/* Create an instance of the rpc state structure */
|
2012-05-31 01:21:37 +02:00
|
|
|
|
2024-09-09 14:28:16 +02:00
|
|
|
rpc = fs_heap_zalloc(sizeof(struct rpcclnt));
|
2020-03-01 10:24:29 +01:00
|
|
|
if (!rpc)
|
2012-05-31 01:21:37 +02:00
|
|
|
{
|
2020-03-01 10:24:29 +01:00
|
|
|
ferr("ERROR: Failed to allocate rpc structure\n");
|
2022-10-16 18:50:59 +02:00
|
|
|
goto bad;
|
2020-03-01 10:24:29 +01:00
|
|
|
}
|
2012-06-28 00:03:32 +02:00
|
|
|
|
2020-03-01 10:24:29 +01:00
|
|
|
finfo("Connecting\n");
|
2012-06-28 00:03:32 +02:00
|
|
|
|
2020-03-01 10:24:29 +01:00
|
|
|
/* Translate nfsmnt flags -> rpcclnt flags */
|
2012-06-28 00:03:32 +02:00
|
|
|
|
2022-10-16 18:50:59 +02:00
|
|
|
rpc->rc_path = nmp->nm_path;
|
|
|
|
rpc->rc_name = &nmp->nm_nam;
|
|
|
|
rpc->rc_sotype = argp->sotype;
|
|
|
|
rpc->rc_timeo = nprmt.timeo;
|
|
|
|
rpc->rc_retry = nprmt.retry;
|
2012-06-28 00:03:32 +02:00
|
|
|
|
2022-10-16 18:50:59 +02:00
|
|
|
nmp->nm_rpcclnt = rpc;
|
2012-06-28 00:03:32 +02:00
|
|
|
|
2020-03-30 17:00:51 +02:00
|
|
|
ret = rpcclnt_connect(nmp->nm_rpcclnt);
|
|
|
|
if (ret != OK)
|
2020-03-01 10:24:29 +01:00
|
|
|
{
|
2020-03-30 17:00:51 +02:00
|
|
|
ferr("ERROR: nfs_connect failed: %d\n", ret);
|
2020-03-01 10:24:29 +01:00
|
|
|
goto bad;
|
2012-05-31 01:21:37 +02:00
|
|
|
}
|
|
|
|
|
2022-10-16 18:50:59 +02:00
|
|
|
nmp->nm_fhsize = nmp->nm_rpcclnt->rc_fhsize;
|
|
|
|
nmp->nm_fh = &nmp->nm_rpcclnt->rc_fh;
|
2012-06-06 23:51:03 +02:00
|
|
|
|
2021-02-25 13:48:46 +01:00
|
|
|
/* Get the file system info */
|
2012-06-06 23:51:03 +02:00
|
|
|
|
2020-03-30 17:00:51 +02:00
|
|
|
ret = nfs_fsinfo(nmp);
|
|
|
|
if (ret)
|
2012-06-06 23:51:03 +02:00
|
|
|
{
|
2020-03-30 17:00:51 +02:00
|
|
|
ferr("ERROR: nfs_fsinfo failed: %d\n", ret);
|
2012-06-06 23:51:03 +02:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Mounted! */
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
*handle = nmp;
|
2012-04-19 01:31:47 +02:00
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("Successfully mounted\n");
|
2012-06-14 02:47:42 +02:00
|
|
|
return OK;
|
2012-04-19 01:31:47 +02:00
|
|
|
|
|
|
|
bad:
|
2020-03-07 18:43:40 +01:00
|
|
|
|
2020-03-01 10:24:29 +01:00
|
|
|
/* Disconnect from the server */
|
2012-06-07 03:03:34 +02:00
|
|
|
|
2020-03-01 10:24:29 +01:00
|
|
|
if (nmp->nm_rpcclnt)
|
|
|
|
{
|
|
|
|
rpcclnt_disconnect(nmp->nm_rpcclnt);
|
2024-09-09 14:28:16 +02:00
|
|
|
fs_heap_free(nmp->nm_rpcclnt);
|
2020-03-01 10:24:29 +01:00
|
|
|
}
|
2014-04-14 00:22:22 +02:00
|
|
|
|
2020-03-01 10:24:29 +01:00
|
|
|
/* Free connection-related resources */
|
2020-03-01 21:53:45 +01:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_destroy(&nmp->nm_lock);
|
2024-09-09 14:28:16 +02:00
|
|
|
fs_heap_free(nmp);
|
2013-01-14 20:22:32 +01:00
|
|
|
|
2020-03-30 17:00:51 +02:00
|
|
|
return ret;
|
2012-04-19 01:31:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-04-26 01:22:09 +02:00
|
|
|
* Name: nfs_unbind
|
2012-04-19 01:31:47 +02:00
|
|
|
*
|
|
|
|
* Description: This implements the filesystem portion of the umount
|
|
|
|
* operation.
|
|
|
|
*
|
2012-06-07 18:53:46 +02:00
|
|
|
* Returned Value:
|
|
|
|
* 0 on success; a negated errno value on failure.
|
|
|
|
*
|
2012-04-19 01:31:47 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2015-06-26 15:06:53 +02:00
|
|
|
static int nfs_unbind(FAR void *handle, FAR struct inode **blkdriver,
|
|
|
|
unsigned int flags)
|
2012-04-19 01:31:47 +02:00
|
|
|
{
|
2012-06-14 02:47:42 +02:00
|
|
|
FAR struct nfsmount *nmp = (FAR struct nfsmount *)handle;
|
2020-03-30 17:00:51 +02:00
|
|
|
int ret;
|
2012-04-19 01:31:47 +02:00
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("Entry\n");
|
2012-06-14 02:47:42 +02:00
|
|
|
DEBUGASSERT(nmp);
|
2012-04-19 01:31:47 +02:00
|
|
|
|
2012-06-14 02:47:42 +02:00
|
|
|
/* Get exclusive access to the mount structure */
|
2012-04-19 01:31:47 +02:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxmutex_lock(&nmp->nm_lock);
|
2020-03-30 17:00:51 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2012-05-12 02:11:24 +02:00
|
|
|
|
2020-03-30 17:00:51 +02:00
|
|
|
/* Are there any open files? We can tell if there are open files by
|
|
|
|
* looking at the list of file structures in the mount structure. If this
|
|
|
|
* list not empty, then there are open files and we cannot unmount now (or
|
|
|
|
* a crash is sure to follow).
|
2012-06-14 02:47:42 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (nmp->nm_head != NULL)
|
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR; There are open files: %p\n", nmp->nm_head);
|
2015-03-15 00:22:02 +01:00
|
|
|
|
|
|
|
/* This implementation currently only supports unmounting if there are
|
|
|
|
* no open file references.
|
|
|
|
*/
|
|
|
|
|
2020-03-30 17:00:51 +02:00
|
|
|
ret = (flags != 0) ? -ENOSYS : -EBUSY;
|
2022-09-06 08:18:45 +02:00
|
|
|
goto errout_with_lock;
|
2012-06-14 02:47:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Disconnect from the server */
|
2012-06-07 18:53:46 +02:00
|
|
|
|
2012-06-28 00:03:32 +02:00
|
|
|
rpcclnt_disconnect(nmp->nm_rpcclnt);
|
2012-06-07 18:53:46 +02:00
|
|
|
|
2012-06-14 02:47:42 +02:00
|
|
|
/* And free any allocated resources */
|
2012-06-07 18:53:46 +02:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_destroy(&nmp->nm_lock);
|
2024-09-09 14:28:16 +02:00
|
|
|
fs_heap_free(nmp->nm_rpcclnt);
|
|
|
|
fs_heap_free(nmp);
|
2012-04-17 01:01:21 +02:00
|
|
|
|
2020-03-01 10:24:29 +01:00
|
|
|
return OK;
|
2012-06-14 02:47:42 +02:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
errout_with_lock:
|
|
|
|
nxmutex_unlock(&nmp->nm_lock);
|
2020-03-30 17:00:51 +02:00
|
|
|
return ret;
|
2012-06-14 02:47:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nfs_fsinfo
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Return information about root directory.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
2020-03-01 21:53:45 +01:00
|
|
|
* 0 on success; negative errno value on failure
|
2012-06-14 02:47:42 +02:00
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* The caller has exclusive access to the NFS mount structure
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
static int nfs_fsinfo(FAR struct nfsmount *nmp)
|
2012-06-14 02:47:42 +02:00
|
|
|
{
|
2020-03-01 21:53:45 +01:00
|
|
|
FAR struct rpc_call_fs *fsinfo;
|
|
|
|
FAR struct rpc_reply_getattr *attr;
|
|
|
|
FAR uint32_t *ptr;
|
2012-06-14 02:47:42 +02:00
|
|
|
uint32_t pref;
|
|
|
|
uint32_t max;
|
2020-03-30 17:00:51 +02:00
|
|
|
int ret = 0;
|
2012-06-14 02:47:42 +02:00
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
fsinfo = &nmp->nm_msgbuffer.fsinfo;
|
|
|
|
fsinfo->fs.fsroot.length = txdr_unsigned(nmp->nm_fhsize);
|
|
|
|
memcpy(&fsinfo->fs.fsroot.handle, nmp->nm_fh, nmp->nm_fhsize);
|
2012-06-14 02:47:42 +02:00
|
|
|
|
|
|
|
/* Request FSINFO from the server */
|
|
|
|
|
|
|
|
nfs_statistics(NFSPROC_FSINFO);
|
2020-03-30 17:00:51 +02:00
|
|
|
ret = nfs_request(nmp, NFSPROC_FSINFO,
|
2022-09-06 08:18:45 +02:00
|
|
|
fsinfo, sizeof(struct FS3args),
|
|
|
|
nmp->nm_iobuffer, nmp->nm_buflen);
|
2020-03-30 17:00:51 +02:00
|
|
|
if (ret)
|
2012-06-14 02:47:42 +02:00
|
|
|
{
|
2020-03-30 17:00:51 +02:00
|
|
|
return ret;
|
2012-06-14 02:47:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Save the root file system attributes */
|
|
|
|
|
2020-03-30 17:00:51 +02:00
|
|
|
ptr = (FAR uint32_t *)
|
|
|
|
&((FAR struct rpc_reply_fsinfo *)nmp->nm_iobuffer)->fsinfo;
|
2020-03-01 21:53:45 +01:00
|
|
|
if (*ptr++ != 0)
|
2012-06-14 02:47:42 +02:00
|
|
|
{
|
2020-03-01 21:53:45 +01:00
|
|
|
memcpy(&nmp->nm_fattr, ptr, sizeof(struct nfs_fattr));
|
|
|
|
ptr += uint32_increment(sizeof(struct nfs_fattr));
|
2012-06-14 02:47:42 +02:00
|
|
|
}
|
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
max = fxdr_unsigned(uint32_t, *ptr++);
|
|
|
|
pref = fxdr_unsigned(uint32_t, *ptr++);
|
|
|
|
ptr += 1; /* Skip fs_rtmult */
|
2012-06-14 02:47:42 +02:00
|
|
|
|
|
|
|
if (pref < nmp->nm_rsize)
|
|
|
|
{
|
|
|
|
nmp->nm_rsize = (pref + NFS_FABLKSIZE - 1) & ~(NFS_FABLKSIZE - 1);
|
|
|
|
}
|
2020-03-07 18:43:40 +01:00
|
|
|
|
2012-06-14 02:47:42 +02:00
|
|
|
if (max < nmp->nm_rsize)
|
|
|
|
{
|
|
|
|
nmp->nm_rsize = max & ~(NFS_FABLKSIZE - 1);
|
|
|
|
if (nmp->nm_rsize == 0)
|
|
|
|
{
|
|
|
|
nmp->nm_rsize = max;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
max = fxdr_unsigned(uint32_t, *ptr++);
|
|
|
|
pref = fxdr_unsigned(uint32_t, *ptr++);
|
|
|
|
ptr += 1; /* Skip fs_wtmult */
|
|
|
|
|
|
|
|
if (pref < nmp->nm_wsize)
|
|
|
|
{
|
|
|
|
nmp->nm_wsize = (pref + NFS_FABLKSIZE - 1) & ~(NFS_FABLKSIZE - 1);
|
|
|
|
}
|
2020-03-07 18:43:40 +01:00
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
if (max < nmp->nm_wsize)
|
|
|
|
{
|
|
|
|
nmp->nm_wsize = max & ~(NFS_FABLKSIZE - 1);
|
|
|
|
if (nmp->nm_wsize == 0)
|
|
|
|
{
|
|
|
|
nmp->nm_wsize = max;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pref = fxdr_unsigned(uint32_t, *ptr++);
|
2012-06-14 02:47:42 +02:00
|
|
|
if (pref < nmp->nm_readdirsize)
|
|
|
|
{
|
2020-03-07 18:43:40 +01:00
|
|
|
nmp->nm_readdirsize = (pref + NFS_DIRBLKSIZ - 1) &
|
|
|
|
~(NFS_DIRBLKSIZ - 1);
|
2012-06-14 02:47:42 +02:00
|
|
|
}
|
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
/* Get the file attributes if needed */
|
|
|
|
|
|
|
|
if (nmp->nm_fattr.fa_type == 0)
|
2012-06-14 02:47:42 +02:00
|
|
|
{
|
2020-03-01 21:53:45 +01:00
|
|
|
nfs_statistics(NFSPROC_GETATTR);
|
2020-03-30 17:00:51 +02:00
|
|
|
ret = nfs_request(nmp, NFSPROC_GETATTR,
|
2022-09-06 08:18:45 +02:00
|
|
|
fsinfo, sizeof(struct FS3args),
|
|
|
|
nmp->nm_iobuffer, nmp->nm_buflen);
|
2020-03-30 17:00:51 +02:00
|
|
|
if (ret)
|
2012-06-14 02:47:42 +02:00
|
|
|
{
|
2020-03-30 17:00:51 +02:00
|
|
|
return ret;
|
2012-06-14 02:47:42 +02:00
|
|
|
}
|
2020-03-01 21:53:45 +01:00
|
|
|
|
|
|
|
attr = (FAR struct rpc_reply_getattr *)nmp->nm_iobuffer;
|
|
|
|
memcpy(&nmp->nm_fattr, &attr->attr, sizeof(struct nfs_fattr));
|
2012-06-14 02:47:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
2012-04-17 01:01:21 +02:00
|
|
|
}
|
|
|
|
|
2012-03-29 01:27:24 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: nfs_statfs
|
|
|
|
*
|
2012-06-07 18:53:46 +02:00
|
|
|
* Description:
|
|
|
|
* Return filesystem statistics
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* 0 on success; a negated errno value on failure.
|
2012-03-29 01:27:24 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
2012-03-22 01:51:01 +01:00
|
|
|
|
2012-06-14 17:45:38 +02:00
|
|
|
static int nfs_statfs(FAR struct inode *mountpt, FAR struct statfs *sbp)
|
2012-03-22 01:51:01 +01:00
|
|
|
{
|
2012-06-14 17:45:38 +02:00
|
|
|
FAR struct nfsmount *nmp;
|
|
|
|
FAR struct rpc_call_fs *fsstat;
|
|
|
|
FAR struct rpc_reply_fsstat *sfp;
|
2012-03-22 01:51:01 +01:00
|
|
|
uint64_t tquad;
|
2020-03-30 17:00:51 +02:00
|
|
|
int ret;
|
2012-03-29 01:27:24 +02:00
|
|
|
|
|
|
|
/* Sanity checks */
|
|
|
|
|
|
|
|
DEBUGASSERT(mountpt && mountpt->i_private);
|
2012-03-22 01:51:01 +01:00
|
|
|
|
2012-03-29 01:27:24 +02:00
|
|
|
/* Get the mountpoint private data from the inode structure */
|
|
|
|
|
2023-08-29 06:16:49 +02:00
|
|
|
nmp = mountpt->i_private;
|
2012-03-29 01:27:24 +02:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxmutex_lock(&nmp->nm_lock);
|
2020-03-30 17:00:51 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2012-04-10 01:35:45 +02:00
|
|
|
|
2012-03-27 02:23:40 +02:00
|
|
|
/* Fill in the statfs info */
|
|
|
|
|
|
|
|
sbp->f_type = NFS_SUPER_MAGIC;
|
2012-03-22 01:51:01 +01:00
|
|
|
|
2012-06-14 17:45:38 +02:00
|
|
|
fsstat = &nmp->nm_msgbuffer.fsstat;
|
|
|
|
fsstat->fs.fsroot.length = txdr_unsigned(nmp->nm_fhsize);
|
2020-03-01 21:53:45 +01:00
|
|
|
memcpy(&fsstat->fs.fsroot.handle, nmp->nm_fh, nmp->nm_fhsize);
|
2012-06-13 17:00:34 +02:00
|
|
|
|
|
|
|
nfs_statistics(NFSPROC_FSSTAT);
|
2020-03-30 17:00:51 +02:00
|
|
|
ret = nfs_request(nmp, NFSPROC_FSSTAT,
|
2022-09-06 08:18:45 +02:00
|
|
|
fsstat, sizeof(struct FS3args),
|
|
|
|
nmp->nm_iobuffer, nmp->nm_buflen);
|
2020-03-30 17:00:51 +02:00
|
|
|
if (ret)
|
2012-04-10 01:35:45 +02:00
|
|
|
{
|
2022-09-06 08:18:45 +02:00
|
|
|
goto errout_with_lock;
|
2012-04-10 01:35:45 +02:00
|
|
|
}
|
|
|
|
|
2012-06-14 17:45:38 +02:00
|
|
|
sfp = (FAR struct rpc_reply_fsstat *)nmp->nm_iobuffer;
|
2012-06-08 02:14:54 +02:00
|
|
|
sbp->f_bsize = NFS_FABLKSIZE;
|
2012-06-14 17:45:38 +02:00
|
|
|
tquad = fxdr_hyper(&sfp->fsstat.sf_tbytes);
|
2012-06-08 02:14:54 +02:00
|
|
|
sbp->f_blocks = tquad / (uint64_t) NFS_FABLKSIZE;
|
2012-06-14 17:45:38 +02:00
|
|
|
tquad = fxdr_hyper(&sfp->fsstat.sf_fbytes);
|
2012-06-08 02:14:54 +02:00
|
|
|
sbp->f_bfree = tquad / (uint64_t) NFS_FABLKSIZE;
|
2012-06-14 17:45:38 +02:00
|
|
|
tquad = fxdr_hyper(&sfp->fsstat.sf_abytes);
|
2012-06-08 02:14:54 +02:00
|
|
|
sbp->f_bavail = tquad / (uint64_t) NFS_FABLKSIZE;
|
2012-06-14 17:45:38 +02:00
|
|
|
tquad = fxdr_hyper(&sfp->fsstat.sf_tfiles);
|
2012-06-08 02:14:54 +02:00
|
|
|
sbp->f_files = tquad;
|
2012-06-14 17:45:38 +02:00
|
|
|
tquad = fxdr_hyper(&sfp->fsstat.sf_ffiles);
|
2012-06-08 02:14:54 +02:00
|
|
|
sbp->f_ffree = tquad;
|
|
|
|
sbp->f_namelen = NAME_MAX;
|
2012-04-10 01:35:45 +02:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
errout_with_lock:
|
|
|
|
nxmutex_unlock(&nmp->nm_lock);
|
2020-03-30 17:00:51 +02:00
|
|
|
return ret;
|
2012-03-22 01:51:01 +01:00
|
|
|
}
|
|
|
|
|
2012-04-17 01:01:21 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: nfs_remove
|
|
|
|
*
|
2012-06-07 18:53:46 +02:00
|
|
|
* Description:
|
|
|
|
* Remove a file
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* 0 on success; a negated errno value on failure.
|
2012-04-17 01:01:21 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
static int nfs_remove(FAR struct inode *mountpt, FAR const char *relpath)
|
2012-03-27 02:23:40 +02:00
|
|
|
{
|
2022-09-06 08:18:45 +02:00
|
|
|
FAR struct nfsmount *nmp;
|
|
|
|
struct file_handle fhandle;
|
|
|
|
struct nfs_fattr fattr;
|
|
|
|
char filename[NAME_MAX + 1];
|
|
|
|
FAR uint32_t *ptr;
|
|
|
|
int namelen;
|
|
|
|
int reqlen;
|
|
|
|
int ret;
|
2012-04-17 01:01:21 +02:00
|
|
|
|
|
|
|
/* Sanity checks */
|
|
|
|
|
|
|
|
DEBUGASSERT(mountpt && mountpt->i_private);
|
|
|
|
|
|
|
|
/* Get the mountpoint private data from the inode structure */
|
|
|
|
|
2023-08-29 06:16:49 +02:00
|
|
|
nmp = mountpt->i_private;
|
2012-04-17 01:01:21 +02:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxmutex_lock(&nmp->nm_lock);
|
2020-03-30 17:00:51 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2012-04-17 01:01:21 +02:00
|
|
|
|
2012-06-11 20:55:58 +02:00
|
|
|
/* Find the NFS node of the directory containing the file to be deleted */
|
2012-04-17 01:01:21 +02:00
|
|
|
|
2020-03-30 17:00:51 +02:00
|
|
|
ret = nfs_finddir(nmp, relpath, &fhandle, &fattr, filename);
|
|
|
|
if (ret != OK)
|
2012-06-11 20:55:58 +02:00
|
|
|
{
|
2020-03-30 17:00:51 +02:00
|
|
|
ferr("ERROR: nfs_finddir returned: %d\n", ret);
|
2022-09-06 08:18:45 +02:00
|
|
|
goto errout_with_lock;
|
2012-06-11 20:55:58 +02:00
|
|
|
}
|
2012-04-17 01:01:21 +02:00
|
|
|
|
2012-06-11 20:55:58 +02:00
|
|
|
/* Create the REMOVE RPC call arguments */
|
2012-04-17 01:01:21 +02:00
|
|
|
|
2012-06-14 02:47:42 +02:00
|
|
|
ptr = (FAR uint32_t *)&nmp->nm_msgbuffer.removef.remove;
|
2012-06-11 20:55:58 +02:00
|
|
|
reqlen = 0;
|
2012-04-17 01:01:21 +02:00
|
|
|
|
2012-06-11 20:55:58 +02:00
|
|
|
/* Copy the variable length, directory file handle */
|
|
|
|
|
|
|
|
*ptr++ = txdr_unsigned(fhandle.length);
|
|
|
|
reqlen += sizeof(uint32_t);
|
|
|
|
|
|
|
|
memcpy(ptr, &fhandle.handle, fhandle.length);
|
2020-03-01 21:53:45 +01:00
|
|
|
reqlen += uint32_alignup(fhandle.length);
|
2012-06-11 20:55:58 +02:00
|
|
|
ptr += uint32_increment(fhandle.length);
|
|
|
|
|
|
|
|
/* Copy the variable-length file name */
|
|
|
|
|
|
|
|
namelen = strlen(filename);
|
|
|
|
|
|
|
|
*ptr++ = txdr_unsigned(namelen);
|
|
|
|
reqlen += sizeof(uint32_t);
|
|
|
|
|
|
|
|
memcpy(ptr, filename, namelen);
|
|
|
|
reqlen += uint32_alignup(namelen);
|
|
|
|
|
|
|
|
/* Perform the REMOVE RPC call */
|
|
|
|
|
2012-06-12 19:36:48 +02:00
|
|
|
nfs_statistics(NFSPROC_REMOVE);
|
2020-03-30 17:00:51 +02:00
|
|
|
ret = nfs_request(nmp, NFSPROC_REMOVE,
|
2022-09-06 08:18:45 +02:00
|
|
|
&nmp->nm_msgbuffer.removef, reqlen,
|
|
|
|
nmp->nm_iobuffer, nmp->nm_buflen);
|
2012-06-11 20:55:58 +02:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
errout_with_lock:
|
|
|
|
nxmutex_unlock(&nmp->nm_lock);
|
2020-03-30 17:00:51 +02:00
|
|
|
return ret;
|
2012-04-17 01:01:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nfs_mkdir
|
|
|
|
*
|
2012-06-07 18:53:46 +02:00
|
|
|
* Description:
|
|
|
|
* Create a directory
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* 0 on success; a negated errno value on failure.
|
2012-04-17 01:01:21 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-03-07 18:43:40 +01:00
|
|
|
static int nfs_mkdir(FAR struct inode *mountpt, FAR const char *relpath,
|
|
|
|
mode_t mode)
|
2012-04-17 01:01:21 +02:00
|
|
|
{
|
2022-09-06 08:18:45 +02:00
|
|
|
FAR struct nfsmount *nmp;
|
|
|
|
struct file_handle fhandle;
|
|
|
|
struct nfs_fattr fattr;
|
|
|
|
char dirname[NAME_MAX + 1];
|
|
|
|
FAR uint32_t *ptr;
|
|
|
|
uint32_t tmp;
|
|
|
|
int namelen;
|
|
|
|
int reqlen;
|
|
|
|
int ret;
|
2012-04-17 01:01:21 +02:00
|
|
|
|
|
|
|
/* Sanity checks */
|
|
|
|
|
|
|
|
DEBUGASSERT(mountpt && mountpt->i_private);
|
|
|
|
|
|
|
|
/* Get the mountpoint private data from the inode structure */
|
|
|
|
|
2023-08-29 06:16:49 +02:00
|
|
|
nmp = mountpt->i_private;
|
2012-05-03 01:40:11 +02:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxmutex_lock(&nmp->nm_lock);
|
2020-03-30 17:00:51 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2012-04-17 01:01:21 +02:00
|
|
|
|
2020-07-02 16:03:27 +02:00
|
|
|
/* Find the NFS node of the directory containing the directory to be
|
|
|
|
* created
|
|
|
|
*/
|
2012-06-11 23:16:35 +02:00
|
|
|
|
2020-03-30 17:00:51 +02:00
|
|
|
ret = nfs_finddir(nmp, relpath, &fhandle, &fattr, dirname);
|
|
|
|
if (ret != OK)
|
2012-06-11 23:16:35 +02:00
|
|
|
{
|
2020-03-30 17:00:51 +02:00
|
|
|
ferr("ERROR: nfs_finddir returned: %d\n", ret);
|
2022-09-06 08:18:45 +02:00
|
|
|
goto errout_with_lock;
|
2012-06-11 23:16:35 +02:00
|
|
|
}
|
2012-04-17 01:01:21 +02:00
|
|
|
|
2012-06-11 23:16:35 +02:00
|
|
|
/* Format the MKDIR call message arguments */
|
|
|
|
|
2012-06-14 02:47:42 +02:00
|
|
|
ptr = (FAR uint32_t *)&nmp->nm_msgbuffer.mkdir.mkdir;
|
2012-06-11 23:16:35 +02:00
|
|
|
reqlen = 0;
|
|
|
|
|
|
|
|
/* Copy the variable length, directory file handle */
|
|
|
|
|
|
|
|
*ptr++ = txdr_unsigned(fhandle.length);
|
|
|
|
reqlen += sizeof(uint32_t);
|
|
|
|
|
|
|
|
memcpy(ptr, &fhandle.handle, fhandle.length);
|
|
|
|
ptr += uint32_increment(fhandle.length);
|
2020-03-01 21:53:45 +01:00
|
|
|
reqlen += uint32_alignup(fhandle.length);
|
2012-06-11 23:16:35 +02:00
|
|
|
|
|
|
|
/* Copy the variable-length directory name */
|
|
|
|
|
|
|
|
namelen = strlen(dirname);
|
|
|
|
|
|
|
|
*ptr++ = txdr_unsigned(namelen);
|
|
|
|
reqlen += sizeof(uint32_t);
|
|
|
|
|
|
|
|
memcpy(ptr, dirname, namelen);
|
|
|
|
ptr += uint32_increment(namelen);
|
|
|
|
reqlen += uint32_alignup(namelen);
|
|
|
|
|
|
|
|
/* Set the mode. NOTE: Here we depend on the fact that the NuttX and NFS
|
|
|
|
* bit settings are the same (at least for the bits of interest).
|
|
|
|
*/
|
|
|
|
|
|
|
|
*ptr++ = nfs_true; /* True: mode value follows */
|
|
|
|
reqlen += sizeof(uint32_t);
|
|
|
|
|
|
|
|
tmp = mode & (NFSMODE_IXOTH | NFSMODE_IWOTH | NFSMODE_IROTH |
|
|
|
|
NFSMODE_IXGRP | NFSMODE_IWGRP | NFSMODE_IRGRP |
|
2020-03-01 21:53:45 +01:00
|
|
|
NFSMODE_IXUSR | NFSMODE_IWUSR | NFSMODE_IRUSR |
|
|
|
|
NFSMODE_SAVETEXT | NFSMODE_ISGID | NFSMODE_ISUID);
|
2012-06-11 23:16:35 +02:00
|
|
|
*ptr++ = txdr_unsigned(tmp);
|
|
|
|
reqlen += sizeof(uint32_t);
|
|
|
|
|
|
|
|
/* Set the user ID to zero */
|
|
|
|
|
2012-06-12 01:51:39 +02:00
|
|
|
*ptr++ = nfs_true; /* True: Uid value follows */
|
|
|
|
*ptr++ = 0; /* UID = 0 (nobody) */
|
|
|
|
reqlen += 2*sizeof(uint32_t);
|
2012-06-14 02:47:42 +02:00
|
|
|
|
2012-06-11 23:16:35 +02:00
|
|
|
/* Set the group ID to one */
|
|
|
|
|
2012-06-12 01:51:39 +02:00
|
|
|
*ptr++ = nfs_true; /* True: Gid value follows */
|
2020-03-02 13:07:09 +01:00
|
|
|
*ptr++ = 0; /* GID = 0 (nogroup) */
|
2012-06-12 01:51:39 +02:00
|
|
|
reqlen += 2*sizeof(uint32_t);
|
2012-06-14 02:47:42 +02:00
|
|
|
|
2012-06-11 23:16:35 +02:00
|
|
|
/* No size */
|
|
|
|
|
|
|
|
*ptr++ = nfs_false; /* False: No size value follows */
|
|
|
|
reqlen += sizeof(uint32_t);
|
|
|
|
|
|
|
|
/* Don't change times */
|
|
|
|
|
|
|
|
*ptr++ = HTONL(NFSV3SATTRTIME_DONTCHANGE); /* Don't change atime */
|
|
|
|
*ptr++ = HTONL(NFSV3SATTRTIME_DONTCHANGE); /* Don't change mtime */
|
2012-06-12 01:51:39 +02:00
|
|
|
reqlen += 2*sizeof(uint32_t);
|
2012-06-11 23:16:35 +02:00
|
|
|
|
|
|
|
/* Perform the MKDIR RPC */
|
|
|
|
|
2012-06-12 19:36:48 +02:00
|
|
|
nfs_statistics(NFSPROC_MKDIR);
|
2020-03-30 17:00:51 +02:00
|
|
|
ret = nfs_request(nmp, NFSPROC_MKDIR,
|
2022-09-06 08:18:45 +02:00
|
|
|
&nmp->nm_msgbuffer.mkdir, reqlen,
|
|
|
|
&nmp->nm_iobuffer, nmp->nm_buflen);
|
2020-03-30 17:00:51 +02:00
|
|
|
if (ret)
|
2012-04-17 01:01:21 +02:00
|
|
|
{
|
2020-03-30 17:00:51 +02:00
|
|
|
ferr("ERROR: nfs_request failed: %d\n", ret);
|
2012-04-17 01:01:21 +02:00
|
|
|
}
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
errout_with_lock:
|
|
|
|
nxmutex_unlock(&nmp->nm_lock);
|
2020-03-30 17:00:51 +02:00
|
|
|
return ret;
|
2012-04-17 01:01:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nfs_rmdir
|
|
|
|
*
|
2012-06-07 18:53:46 +02:00
|
|
|
* Description:
|
|
|
|
* Remove a directory
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* 0 on success; a negated errno value on failure.
|
2012-04-17 01:01:21 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
static int nfs_rmdir(FAR struct inode *mountpt, FAR const char *relpath)
|
2012-04-17 01:01:21 +02:00
|
|
|
{
|
2022-09-06 08:18:45 +02:00
|
|
|
FAR struct nfsmount *nmp;
|
|
|
|
struct file_handle fhandle;
|
|
|
|
struct nfs_fattr fattr;
|
|
|
|
char dirname[NAME_MAX + 1];
|
|
|
|
FAR uint32_t *ptr;
|
|
|
|
int namelen;
|
|
|
|
int reqlen;
|
|
|
|
int ret;
|
2012-04-17 01:01:21 +02:00
|
|
|
|
|
|
|
/* Sanity checks */
|
|
|
|
|
|
|
|
DEBUGASSERT(mountpt && mountpt->i_private);
|
|
|
|
|
|
|
|
/* Get the mountpoint private data from the inode structure */
|
|
|
|
|
2023-08-29 06:16:49 +02:00
|
|
|
nmp = mountpt->i_private;
|
2012-04-17 01:01:21 +02:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxmutex_lock(&nmp->nm_lock);
|
2020-03-30 17:00:51 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2012-04-17 01:01:21 +02:00
|
|
|
|
2020-07-02 16:03:27 +02:00
|
|
|
/* Find the NFS node of the directory containing the directory to be
|
|
|
|
* removed
|
|
|
|
*/
|
2012-06-11 23:16:35 +02:00
|
|
|
|
2020-03-30 17:00:51 +02:00
|
|
|
ret = nfs_finddir(nmp, relpath, &fhandle, &fattr, dirname);
|
|
|
|
if (ret != OK)
|
2012-06-11 23:16:35 +02:00
|
|
|
{
|
2020-03-30 17:00:51 +02:00
|
|
|
ferr("ERROR: nfs_finddir returned: %d\n", ret);
|
2022-09-06 08:18:45 +02:00
|
|
|
goto errout_with_lock;
|
2012-06-11 23:16:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set up the RMDIR call message arguments */
|
2012-04-17 01:01:21 +02:00
|
|
|
|
2012-06-14 02:47:42 +02:00
|
|
|
ptr = (FAR uint32_t *)&nmp->nm_msgbuffer.rmdir.rmdir;
|
2012-06-11 23:16:35 +02:00
|
|
|
reqlen = 0;
|
|
|
|
|
|
|
|
/* Copy the variable length, directory file handle */
|
2012-04-28 01:29:24 +02:00
|
|
|
|
2012-06-11 23:16:35 +02:00
|
|
|
*ptr++ = txdr_unsigned(fhandle.length);
|
|
|
|
reqlen += sizeof(uint32_t);
|
|
|
|
|
|
|
|
memcpy(ptr, &fhandle.handle, fhandle.length);
|
2020-03-01 21:53:45 +01:00
|
|
|
reqlen += uint32_alignup(fhandle.length);
|
2012-06-11 23:16:35 +02:00
|
|
|
ptr += uint32_increment(fhandle.length);
|
2012-04-28 01:29:24 +02:00
|
|
|
|
2012-06-11 23:16:35 +02:00
|
|
|
/* Copy the variable-length directory name */
|
|
|
|
|
|
|
|
namelen = strlen(dirname);
|
|
|
|
|
|
|
|
*ptr++ = txdr_unsigned(namelen);
|
|
|
|
reqlen += sizeof(uint32_t);
|
|
|
|
|
|
|
|
memcpy(ptr, dirname, namelen);
|
|
|
|
reqlen += uint32_alignup(namelen);
|
|
|
|
|
|
|
|
/* Perform the RMDIR RPC */
|
|
|
|
|
2012-06-12 19:36:48 +02:00
|
|
|
nfs_statistics(NFSPROC_RMDIR);
|
2020-03-30 17:00:51 +02:00
|
|
|
ret = nfs_request(nmp, NFSPROC_RMDIR,
|
2022-09-06 08:18:45 +02:00
|
|
|
&nmp->nm_msgbuffer.rmdir, reqlen,
|
|
|
|
nmp->nm_iobuffer, nmp->nm_buflen);
|
2012-04-17 01:01:21 +02:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
errout_with_lock:
|
|
|
|
nxmutex_unlock(&nmp->nm_lock);
|
2020-03-30 17:00:51 +02:00
|
|
|
return ret;
|
2012-04-17 01:01:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nfs_rename
|
|
|
|
*
|
2012-06-07 18:53:46 +02:00
|
|
|
* Description:
|
|
|
|
* Rename a file or directory
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* 0 on success; a negated errno value on failure.
|
2012-04-17 01:01:21 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
static int nfs_rename(FAR struct inode *mountpt, FAR const char *oldrelpath,
|
|
|
|
FAR const char *newrelpath)
|
2012-04-17 01:01:21 +02:00
|
|
|
{
|
2022-09-06 08:18:45 +02:00
|
|
|
FAR struct nfsmount *nmp;
|
|
|
|
struct file_handle from_handle;
|
|
|
|
struct file_handle to_handle;
|
|
|
|
char from_name[NAME_MAX + 1];
|
|
|
|
char to_name[NAME_MAX + 1];
|
|
|
|
struct nfs_fattr fattr;
|
|
|
|
FAR uint32_t *ptr;
|
|
|
|
int namelen;
|
|
|
|
int reqlen;
|
|
|
|
int ret;
|
2012-04-17 01:01:21 +02:00
|
|
|
|
|
|
|
/* Sanity checks */
|
|
|
|
|
|
|
|
DEBUGASSERT(mountpt && mountpt->i_private);
|
|
|
|
|
|
|
|
/* Get the mountpoint private data from the inode structure */
|
|
|
|
|
2023-08-29 06:16:49 +02:00
|
|
|
nmp = mountpt->i_private;
|
2012-04-17 01:01:21 +02:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxmutex_lock(&nmp->nm_lock);
|
2020-03-30 17:00:51 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2012-04-17 01:01:21 +02:00
|
|
|
|
2012-06-12 01:47:31 +02:00
|
|
|
/* Find the NFS node of the directory containing the 'from' object */
|
|
|
|
|
2020-03-30 17:00:51 +02:00
|
|
|
ret = nfs_finddir(nmp, oldrelpath, &from_handle, &fattr, from_name);
|
|
|
|
if (ret != OK)
|
2012-04-17 01:01:21 +02:00
|
|
|
{
|
2020-03-30 17:00:51 +02:00
|
|
|
ferr("ERROR: nfs_finddir returned: %d\n", ret);
|
2022-09-06 08:18:45 +02:00
|
|
|
goto errout_with_lock;
|
2012-04-17 01:01:21 +02:00
|
|
|
}
|
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
/* Find the NFS node of the directory containing the 'to' object */
|
2012-06-12 01:47:31 +02:00
|
|
|
|
2020-03-30 17:00:51 +02:00
|
|
|
ret = nfs_finddir(nmp, newrelpath, &to_handle, &fattr, to_name);
|
|
|
|
if (ret != OK)
|
2012-06-12 01:47:31 +02:00
|
|
|
{
|
2020-03-30 17:00:51 +02:00
|
|
|
ferr("ERROR: nfs_finddir returned: %d\n", ret);
|
2022-09-06 08:18:45 +02:00
|
|
|
goto errout_with_lock;
|
2012-06-12 01:47:31 +02:00
|
|
|
}
|
|
|
|
|
2012-06-12 18:11:31 +02:00
|
|
|
/* Format the RENAME RPC arguments */
|
2012-06-12 01:47:31 +02:00
|
|
|
|
2012-06-14 02:47:42 +02:00
|
|
|
ptr = (FAR uint32_t *)&nmp->nm_msgbuffer.renamef.rename;
|
2012-06-12 01:47:31 +02:00
|
|
|
reqlen = 0;
|
|
|
|
|
|
|
|
/* Copy the variable length, 'from' directory file handle */
|
|
|
|
|
|
|
|
*ptr++ = txdr_unsigned(from_handle.length);
|
|
|
|
reqlen += sizeof(uint32_t);
|
|
|
|
|
|
|
|
memcpy(ptr, &from_handle.handle, from_handle.length);
|
2020-03-01 21:53:45 +01:00
|
|
|
reqlen += uint32_alignup(from_handle.length);
|
2012-06-12 01:47:31 +02:00
|
|
|
ptr += uint32_increment(from_handle.length);
|
2012-04-17 01:01:21 +02:00
|
|
|
|
2012-06-12 01:47:31 +02:00
|
|
|
/* Copy the variable-length 'from' object name */
|
|
|
|
|
|
|
|
namelen = strlen(from_name);
|
|
|
|
|
|
|
|
*ptr++ = txdr_unsigned(namelen);
|
|
|
|
reqlen += sizeof(uint32_t);
|
|
|
|
|
|
|
|
memcpy(ptr, from_name, namelen);
|
|
|
|
reqlen += uint32_alignup(namelen);
|
|
|
|
ptr += uint32_increment(namelen);
|
|
|
|
|
|
|
|
/* Copy the variable length, 'to' directory file handle */
|
|
|
|
|
|
|
|
*ptr++ = txdr_unsigned(to_handle.length);
|
|
|
|
reqlen += sizeof(uint32_t);
|
|
|
|
|
|
|
|
memcpy(ptr, &to_handle.handle, to_handle.length);
|
|
|
|
ptr += uint32_increment(to_handle.length);
|
2020-03-01 21:53:45 +01:00
|
|
|
reqlen += uint32_alignup(to_handle.length);
|
2012-06-12 01:47:31 +02:00
|
|
|
|
|
|
|
/* Copy the variable-length 'to' object name */
|
|
|
|
|
|
|
|
namelen = strlen(to_name);
|
|
|
|
|
|
|
|
*ptr++ = txdr_unsigned(namelen);
|
|
|
|
reqlen += sizeof(uint32_t);
|
|
|
|
|
|
|
|
memcpy(ptr, to_name, namelen);
|
|
|
|
reqlen += uint32_alignup(namelen);
|
|
|
|
|
|
|
|
/* Perform the RENAME RPC */
|
|
|
|
|
2012-06-12 19:36:48 +02:00
|
|
|
nfs_statistics(NFSPROC_RENAME);
|
2020-03-30 17:00:51 +02:00
|
|
|
ret = nfs_request(nmp, NFSPROC_RENAME,
|
2022-09-06 08:18:45 +02:00
|
|
|
&nmp->nm_msgbuffer.renamef, reqlen,
|
|
|
|
nmp->nm_iobuffer, nmp->nm_buflen);
|
2012-04-17 01:01:21 +02:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
errout_with_lock:
|
|
|
|
nxmutex_unlock(&nmp->nm_lock);
|
2020-03-30 17:00:51 +02:00
|
|
|
return ret;
|
2012-04-17 01:01:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2020-03-01 21:53:45 +01:00
|
|
|
* Name: nfs_stat_mode
|
2012-04-17 01:01:21 +02:00
|
|
|
*
|
2012-06-07 18:53:46 +02:00
|
|
|
* Description:
|
2020-03-01 21:53:45 +01:00
|
|
|
* Convert NFSv3's type and mode to NuttX's mode
|
2012-06-07 18:53:46 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
2020-03-01 21:53:45 +01:00
|
|
|
* Return NuttX's mode
|
2012-04-17 01:01:21 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
static mode_t nfs_stat_mode(unsigned int mode, unsigned int type)
|
2012-04-17 01:01:21 +02:00
|
|
|
{
|
2020-03-01 21:53:45 +01:00
|
|
|
/* Here we exploit the fact all mode bits are the same in NuttX
|
2012-06-09 21:29:49 +02:00
|
|
|
* as in the NFSv3 spec.
|
|
|
|
*/
|
2012-04-10 01:35:45 +02:00
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
mode &= (NFSMODE_IXOTH | NFSMODE_IWOTH | NFSMODE_IROTH |
|
|
|
|
NFSMODE_IXGRP | NFSMODE_IWGRP | NFSMODE_IRGRP |
|
|
|
|
NFSMODE_IXUSR | NFSMODE_IWUSR | NFSMODE_IRUSR |
|
|
|
|
NFSMODE_SAVETEXT | NFSMODE_ISGID | NFSMODE_ISUID);
|
2012-03-22 01:51:01 +01:00
|
|
|
|
2012-06-09 21:29:49 +02:00
|
|
|
/* Now OR in the file type */
|
2012-06-07 18:53:46 +02:00
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
switch (type)
|
2012-06-07 18:53:46 +02:00
|
|
|
{
|
2012-06-09 21:29:49 +02:00
|
|
|
default:
|
|
|
|
case NFNON: /* Unknown type */
|
|
|
|
break;
|
2012-06-09 02:08:18 +02:00
|
|
|
|
2012-06-09 21:29:49 +02:00
|
|
|
case NFREG: /* Regular file */
|
|
|
|
mode |= S_IFREG;
|
|
|
|
break;
|
2012-06-09 02:08:18 +02:00
|
|
|
|
2012-06-09 21:29:49 +02:00
|
|
|
case NFDIR: /* Directory */
|
|
|
|
mode |= S_IFDIR;
|
|
|
|
break;
|
2012-06-09 02:08:18 +02:00
|
|
|
|
2012-06-09 21:29:49 +02:00
|
|
|
case NFBLK: /* Block special device file */
|
|
|
|
mode |= S_IFBLK;
|
|
|
|
break;
|
2012-06-09 02:08:18 +02:00
|
|
|
|
2012-06-09 21:29:49 +02:00
|
|
|
case NFCHR: /* Character special device file */
|
|
|
|
mode |= S_IFCHR;
|
|
|
|
break;
|
2012-06-09 02:08:18 +02:00
|
|
|
|
2012-06-09 21:29:49 +02:00
|
|
|
case NFLNK: /* Symbolic link */
|
|
|
|
mode |= S_IFLNK;
|
|
|
|
break;
|
2012-06-09 02:08:18 +02:00
|
|
|
|
2012-06-09 21:29:49 +02:00
|
|
|
case NFSOCK: /* Socket */
|
|
|
|
mode |= S_IFSOCK;
|
|
|
|
break;
|
2012-06-09 02:08:18 +02:00
|
|
|
|
2012-06-09 21:29:49 +02:00
|
|
|
case NFFIFO: /* Named pipe */
|
2020-03-01 21:53:45 +01:00
|
|
|
mode |= S_IFIFO;
|
2012-06-09 21:29:49 +02:00
|
|
|
break;
|
2012-06-07 18:53:46 +02:00
|
|
|
}
|
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
return mode;
|
2017-02-13 17:07:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nfs_stat
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Return information about the file system object at 'relpath'
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* 0 on success; a negated errno value on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
static int nfs_stat(FAR struct inode *mountpt, FAR const char *relpath,
|
|
|
|
FAR struct stat *buf)
|
2017-02-13 17:07:43 +01:00
|
|
|
{
|
2020-03-01 21:53:45 +01:00
|
|
|
FAR struct nfsmount *nmp;
|
2017-02-13 17:07:43 +01:00
|
|
|
struct file_handle fhandle;
|
2020-03-01 21:53:45 +01:00
|
|
|
struct nfs_fattr attributes;
|
2017-02-13 17:07:43 +01:00
|
|
|
struct timespec ts;
|
2020-03-30 17:00:51 +02:00
|
|
|
int ret;
|
2017-02-13 17:07:43 +01:00
|
|
|
|
|
|
|
/* Sanity checks */
|
|
|
|
|
|
|
|
DEBUGASSERT(mountpt && mountpt->i_private);
|
|
|
|
|
|
|
|
/* Get the mountpoint private data from the inode structure */
|
|
|
|
|
2023-08-29 06:16:49 +02:00
|
|
|
nmp = mountpt->i_private;
|
2017-02-13 17:07:43 +01:00
|
|
|
DEBUGASSERT(nmp && buf);
|
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
memset(buf, 0, sizeof(*buf));
|
2017-02-13 17:07:43 +01:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxmutex_lock(&nmp->nm_lock);
|
2020-03-30 17:00:51 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2017-02-13 17:07:43 +01:00
|
|
|
|
|
|
|
/* Get the file handle attributes of the requested node */
|
|
|
|
|
2020-03-30 17:00:51 +02:00
|
|
|
ret = nfs_findnode(nmp, relpath, &fhandle, &attributes, NULL);
|
|
|
|
if (ret != OK)
|
2017-02-13 17:07:43 +01:00
|
|
|
{
|
2020-03-30 17:00:51 +02:00
|
|
|
ferr("ERROR: nfs_findnode failed: %d\n", ret);
|
2022-09-06 08:18:45 +02:00
|
|
|
goto errout_with_lock;
|
2017-02-13 17:07:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Extract the file mode, file type, and file size. */
|
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
buf->st_mode = nfs_stat_mode(fxdr_unsigned(uint16_t, attributes.fa_mode),
|
|
|
|
fxdr_unsigned(uint8_t, attributes.fa_type));
|
|
|
|
buf->st_size = fxdr_hyper(&attributes.fa_size);
|
2017-02-13 17:07:43 +01:00
|
|
|
|
|
|
|
/* Extract time values as type time_t in units of seconds */
|
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
fxdr_nfsv3time(&attributes.fa_mtime, &ts);
|
|
|
|
buf->st_mtime = ts.tv_sec;
|
2017-02-13 17:07:43 +01:00
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
fxdr_nfsv3time(&attributes.fa_atime, &ts);
|
|
|
|
buf->st_atime = ts.tv_sec;
|
2017-02-13 17:07:43 +01:00
|
|
|
|
2020-03-01 21:53:45 +01:00
|
|
|
fxdr_nfsv3time(&attributes.fa_ctime, &ts);
|
|
|
|
buf->st_ctime = ts.tv_sec;
|
2012-06-07 18:53:46 +02:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
errout_with_lock:
|
|
|
|
nxmutex_unlock(&nmp->nm_lock);
|
2020-03-30 17:00:51 +02:00
|
|
|
return ret;
|
2012-03-22 01:51:01 +01:00
|
|
|
}
|
2021-08-10 09:35:43 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nfs_chstat
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Change information about the file system object at 'relpath'
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* 0 on success; a negated errno value on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int nfs_chstat(FAR struct inode *mountpt, FAR const char *relpath,
|
|
|
|
FAR const struct stat *buf, int flags)
|
|
|
|
{
|
|
|
|
FAR struct nfsmount *nmp;
|
|
|
|
struct file_handle fhandle;
|
|
|
|
struct nfsnode np;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Sanity checks */
|
|
|
|
|
|
|
|
DEBUGASSERT(mountpt && mountpt->i_private);
|
|
|
|
|
|
|
|
/* Get the mountpoint private data from the inode structure */
|
|
|
|
|
2023-08-29 06:16:49 +02:00
|
|
|
nmp = mountpt->i_private;
|
2021-08-10 09:35:43 +02:00
|
|
|
DEBUGASSERT(nmp && buf);
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxmutex_lock(&nmp->nm_lock);
|
2021-08-10 09:35:43 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the file handle of the requested node */
|
|
|
|
|
|
|
|
ret = nfs_findnode(nmp, relpath, &fhandle, NULL, NULL);
|
|
|
|
if (ret != OK)
|
|
|
|
{
|
|
|
|
ferr("ERROR: nfs_findnode failed: %d\n", ret);
|
2022-09-06 08:18:45 +02:00
|
|
|
goto errout_with_lock;
|
2021-08-10 09:35:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the nfs node */
|
|
|
|
|
|
|
|
np.n_fhsize = (uint8_t)fhandle.length;
|
|
|
|
memcpy(&np.n_fhandle, &fhandle.handle, fhandle.length);
|
|
|
|
|
|
|
|
/* Change the file mode, owner, group and time. */
|
|
|
|
|
|
|
|
ret = nfs_filechstat(nmp, &np, buf, flags);
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
errout_with_lock:
|
|
|
|
nxmutex_unlock(&nmp->nm_lock);
|
2021-08-10 09:35:43 +02:00
|
|
|
return ret;
|
|
|
|
}
|