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