1beacf11bSopenharmony_ci/**************************************************************************** 2beacf11bSopenharmony_ci * fs/nfs/nfs_mount.h 3beacf11bSopenharmony_ci * 4beacf11bSopenharmony_ci * Copyright (C) 2012 Gregory Nutt. All rights reserved. 5beacf11bSopenharmony_ci * Copyright (C) 2012 Jose Pablo Rojas Vargas. All rights reserved. 6beacf11bSopenharmony_ci * Author: Jose Pablo Rojas Vargas <jrojas@nx-engineering.com> 7beacf11bSopenharmony_ci * Gregory Nutt <gnutt@nuttx.org> 8beacf11bSopenharmony_ci * 9beacf11bSopenharmony_ci * Leveraged from OpenBSD: 10beacf11bSopenharmony_ci * 11beacf11bSopenharmony_ci * Copyright (c) 1989, 1993 12beacf11bSopenharmony_ci * The Regents of the University of California. All rights reserved. 13beacf11bSopenharmony_ci * 14beacf11bSopenharmony_ci * This code is derived from software contributed to Berkeley by 15beacf11bSopenharmony_ci * Rick Macklem at The University of Guelph. 16beacf11bSopenharmony_ci * 17beacf11bSopenharmony_ci * Redistribution and use in source and binary forms, with or without 18beacf11bSopenharmony_ci * modification, are permitted provided that the following conditions 19beacf11bSopenharmony_ci * are met: 20beacf11bSopenharmony_ci * 21beacf11bSopenharmony_ci * 1. Redistributions of source code must retain the above copyright 22beacf11bSopenharmony_ci * notice, this list of conditions and the following disclaimer. 23beacf11bSopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright 24beacf11bSopenharmony_ci * notice, this list of conditions and the following disclaimer in the 25beacf11bSopenharmony_ci * documentation and/or other materials provided with the distribution. 26beacf11bSopenharmony_ci * 4. Neither the name of the University nor the names of its contributors 27beacf11bSopenharmony_ci * may be used to endorse or promote products derived from this software 28beacf11bSopenharmony_ci * without specific prior written permission. 29beacf11bSopenharmony_ci * 30beacf11bSopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 31beacf11bSopenharmony_ci * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 32beacf11bSopenharmony_ci * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 33beacf11bSopenharmony_ci * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 34beacf11bSopenharmony_ci * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 35beacf11bSopenharmony_ci * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 36beacf11bSopenharmony_ci * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 37beacf11bSopenharmony_ci * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 38beacf11bSopenharmony_ci * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 39beacf11bSopenharmony_ci * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 40beacf11bSopenharmony_ci * SUCH DAMAGE. 41beacf11bSopenharmony_ci * 42beacf11bSopenharmony_ci ****************************************************************************/ 43beacf11bSopenharmony_ci 44beacf11bSopenharmony_ci#ifndef __FS_NFS_NFS_MOUNT_H 45beacf11bSopenharmony_ci#define __FS_NFS_NFS_MOUNT_H 46beacf11bSopenharmony_ci 47beacf11bSopenharmony_ci/**************************************************************************** 48beacf11bSopenharmony_ci * Included Files 49beacf11bSopenharmony_ci ****************************************************************************/ 50beacf11bSopenharmony_ci 51beacf11bSopenharmony_ci#include <sys/socket.h> 52beacf11bSopenharmony_ci#include <semaphore.h> 53beacf11bSopenharmony_ci#include <netinet/in.h> 54beacf11bSopenharmony_ci#include <pthread.h> 55beacf11bSopenharmony_ci#include "rpc.h" 56beacf11bSopenharmony_ci 57beacf11bSopenharmony_ci#ifdef __cplusplus 58beacf11bSopenharmony_ci#if __cplusplus 59beacf11bSopenharmony_ciextern "C" { 60beacf11bSopenharmony_ci#endif /* __cplusplus */ 61beacf11bSopenharmony_ci#endif /* __cplusplus */ 62beacf11bSopenharmony_ci 63beacf11bSopenharmony_ci/**************************************************************************** 64beacf11bSopenharmony_ci * Pre-processor Definitions 65beacf11bSopenharmony_ci ****************************************************************************/ 66beacf11bSopenharmony_ci 67beacf11bSopenharmony_ci/* NFS mount option flags */ 68beacf11bSopenharmony_ci 69beacf11bSopenharmony_ci#define NFSMNT_SOFT (1 << 0) /* Soft mount (hard is default) */ 70beacf11bSopenharmony_ci#define NFSMNT_WSIZE (1 << 1) /* Set write size */ 71beacf11bSopenharmony_ci#define NFSMNT_RSIZE (1 << 2) /* Set read size */ 72beacf11bSopenharmony_ci#define NFSMNT_TIMEO (1 << 3) /* Set initial timeout */ 73beacf11bSopenharmony_ci#define NFSMNT_RETRANS (1 << 4) /* Set number of request retries */ 74beacf11bSopenharmony_ci#define NFSMNT_READDIRSIZE (1 << 5) /* Set readdir size */ 75beacf11bSopenharmony_ci 76beacf11bSopenharmony_ci/**************************************************************************** 77beacf11bSopenharmony_ci * Public Types 78beacf11bSopenharmony_ci ****************************************************************************/ 79beacf11bSopenharmony_ci 80beacf11bSopenharmony_ci/* Mount structure. One mount structure is allocated for each NFS mount. This 81beacf11bSopenharmony_ci * structure holds NFS specific information for mount. 82beacf11bSopenharmony_ci */ 83beacf11bSopenharmony_ci 84beacf11bSopenharmony_cistruct nfsmount 85beacf11bSopenharmony_ci{ 86beacf11bSopenharmony_ci struct nfsnode *nm_head; /* A list of all files opened on this mountpoint */ 87beacf11bSopenharmony_ci struct nfsdir_s *nm_dir; /* A list of all directories opened on this mountpoint */ 88beacf11bSopenharmony_ci pthread_mutex_t nm_mux; /* Used to assure thread-safe access */ 89beacf11bSopenharmony_ci nfsfh_t nm_fh; /* File handle of root dir */ 90beacf11bSopenharmony_ci char nm_path[NFS_MOUNT_PATH_MAX_SIZE]; /* server's path of the directory being mounted */ 91beacf11bSopenharmony_ci struct nfs_fattr nm_fattr; /* nfs file attribute cache */ 92beacf11bSopenharmony_ci struct rpcclnt *nm_rpcclnt; /* RPC state */ 93beacf11bSopenharmony_ci int32_t nm_so; /* RPC socket */ 94beacf11bSopenharmony_ci struct sockaddr nm_nam; /* Addr of server */ 95beacf11bSopenharmony_ci bool nm_mounted; /* true: The file system is ready */ 96beacf11bSopenharmony_ci uint8_t nm_fhsize; /* Size of root file handle (host order) */ 97beacf11bSopenharmony_ci uint8_t nm_sotype; /* Type of socket */ 98beacf11bSopenharmony_ci uint8_t nm_retry; /* Max retries */ 99beacf11bSopenharmony_ci uint32_t nm_timeo; /* Timeout value (in system clock ticks) */ 100beacf11bSopenharmony_ci uint16_t nm_rsize; /* Max size of read RPC */ 101beacf11bSopenharmony_ci uint16_t nm_wsize; /* Max size of write RPC */ 102beacf11bSopenharmony_ci uint16_t nm_readdirsize; /* Size of a readdir RPC */ 103beacf11bSopenharmony_ci uint16_t nm_buflen; /* Size of I/O buffer */ 104beacf11bSopenharmony_ci mode_t nm_permission; 105beacf11bSopenharmony_ci uint nm_gid; 106beacf11bSopenharmony_ci uint nm_uid; 107beacf11bSopenharmony_ci 108beacf11bSopenharmony_ci /* Set aside memory on the stack to hold the largest call message. NOTE 109beacf11bSopenharmony_ci * that for the case of the write call message, it is the reply message that 110beacf11bSopenharmony_ci * is in this union. 111beacf11bSopenharmony_ci */ 112beacf11bSopenharmony_ci 113beacf11bSopenharmony_ci union 114beacf11bSopenharmony_ci { 115beacf11bSopenharmony_ci struct rpc_call_pmap pmap; 116beacf11bSopenharmony_ci struct rpc_call_mount mountd; 117beacf11bSopenharmony_ci struct rpc_call_create create; 118beacf11bSopenharmony_ci struct rpc_call_lookup lookup; 119beacf11bSopenharmony_ci struct rpc_call_read read; 120beacf11bSopenharmony_ci struct rpc_call_remove removef; 121beacf11bSopenharmony_ci struct rpc_call_rename renamef; 122beacf11bSopenharmony_ci struct rpc_call_mkdir mkdir; 123beacf11bSopenharmony_ci struct rpc_call_rmdir rmdir; 124beacf11bSopenharmony_ci struct rpc_call_readdir readdir; 125beacf11bSopenharmony_ci struct rpc_call_fs fsstat; 126beacf11bSopenharmony_ci struct rpc_call_setattr setattr; 127beacf11bSopenharmony_ci struct rpc_call_fs fs; 128beacf11bSopenharmony_ci struct rpc_reply_write write; 129beacf11bSopenharmony_ci } nm_msgbuffer; 130beacf11bSopenharmony_ci 131beacf11bSopenharmony_ci /* I/O buffer (must be a aligned to 32-bit boundaries). This buffer used for all 132beacf11bSopenharmony_ci * reply messages EXCEPT for the WRITE RPC. In that case it is used for the WRITE 133beacf11bSopenharmony_ci * call message that contains the data to be written. This buffer must be 134beacf11bSopenharmony_ci * dynamically sized based on the characteristics of the server and upon the 135beacf11bSopenharmony_ci * configuration of the NuttX network. It must be sized to hold the largest 136beacf11bSopenharmony_ci * possible WRITE call message or READ response message. 137beacf11bSopenharmony_ci */ 138beacf11bSopenharmony_ci 139beacf11bSopenharmony_ci uint32_t nm_iobuffer[1]; /* Actual size is given by nm_buflen */ 140beacf11bSopenharmony_ci}; 141beacf11bSopenharmony_ci 142beacf11bSopenharmony_ci/* The size of the nfsmount structure will debug on the size of the allocated I/O 143beacf11bSopenharmony_ci * buffer. 144beacf11bSopenharmony_ci */ 145beacf11bSopenharmony_ci 146beacf11bSopenharmony_ci#define SIZEOF_nfsmount(n) (sizeof(struct nfsmount) + ((n + 3) & ~3) - sizeof(uint32_t)) 147beacf11bSopenharmony_ci 148beacf11bSopenharmony_ci/* Mount parameters structure. This structure is use in nfs_decode_args funtion before one 149beacf11bSopenharmony_ci * mount structure is allocated in each NFS mount. 150beacf11bSopenharmony_ci */ 151beacf11bSopenharmony_ci 152beacf11bSopenharmony_cistruct nfs_mount_parameters 153beacf11bSopenharmony_ci{ 154beacf11bSopenharmony_ci uint32_t timeo; /* Timeout value (in deciseconds) */ 155beacf11bSopenharmony_ci uint8_t retry; /* Max retries */ 156beacf11bSopenharmony_ci uint16_t rsize; /* Max size of read RPC */ 157beacf11bSopenharmony_ci uint16_t wsize; /* Max size of write RPC */ 158beacf11bSopenharmony_ci uint16_t readdirsize; /* Size of a readdir RPC */ 159beacf11bSopenharmony_ci}; 160beacf11bSopenharmony_ci 161beacf11bSopenharmony_cistruct nfs_args 162beacf11bSopenharmony_ci{ 163beacf11bSopenharmony_ci uint8_t addrlen; /* Length of address */ 164beacf11bSopenharmony_ci uint8_t sotype; /* Socket type */ 165beacf11bSopenharmony_ci uint8_t flags; /* Flags, determines if following are valid: */ 166beacf11bSopenharmony_ci uint8_t timeo; /* Time value in deciseconds (with NFSMNT_TIMEO) */ 167beacf11bSopenharmony_ci uint8_t retrans; /* Times to retry send (with NFSMNT_RETRANS) */ 168beacf11bSopenharmony_ci uint16_t wsize; /* Write size in bytes (with NFSMNT_WSIZE) */ 169beacf11bSopenharmony_ci uint16_t rsize; /* Read size in bytes (with NFSMNT_RSIZE) */ 170beacf11bSopenharmony_ci uint16_t readdirsize; /* readdir size in bytes (with NFSMNT_READDIRSIZE) */ 171beacf11bSopenharmony_ci char *path; /* Server's path of the directory being mount */ 172beacf11bSopenharmony_ci struct sockaddr addr; /* File server address (requires 32-bit alignment) */ 173beacf11bSopenharmony_ci}; 174beacf11bSopenharmony_ci 175beacf11bSopenharmony_ci#ifdef __cplusplus 176beacf11bSopenharmony_ci#if __cplusplus 177beacf11bSopenharmony_ci} 178beacf11bSopenharmony_ci#endif /* __cplusplus */ 179beacf11bSopenharmony_ci#endif /* __cplusplus */ 180beacf11bSopenharmony_ci 181beacf11bSopenharmony_ci#endif 182