xref: /haiku/src/add-ons/kernel/file_systems/nfs/nfs_add_on.h (revision b028e77473189065f2baefc6f5e10d451cf591e2)
1 #ifndef _NFS_ADD_ON_H
2 
3 #define _NFS_ADD_ON_H
4 
5 /* wrappers */
6 #ifdef __HAIKU__
7 #	include <fs_interface.h>
8 #	include <fs_info.h>
9 #	include <NodeMonitor.h>
10 typedef dev_t nspace_id;
11 #	define WSTAT_MODE FS_WRITE_STAT_MODE
12 #	define WSTAT_UID FS_WRITE_STAT_UID
13 #	define WSTAT_GID FS_WRITE_STAT_GID
14 #	define WSTAT_SIZE FS_WRITE_STAT_SIZE
15 #	define WSTAT_ATIME FS_WRITE_STAT_ATIME
16 #	define WSTAT_MTIME FS_WRITE_STAT_MTIME
17 #	define WSTAT_CRTIME FS_WRITE_STAT_CRTIME
18 
19 #else
20 #	include "fsproto.h"
21 #	define publish_vnode new_vnode
22 typedef int socklen_t;
23 #endif
24 
25 
26 #include "RPCPendingCalls.h"
27 #include "XDROutPacket.h"
28 #include "XDRInPacket.h"
29 #include "nfs.h"
30 
31 #include <Errors.h>
32 #include <sys/stat.h>
33 #include <SupportDefs.h>
34 
35 struct mount_nfs_params
36 {
37 	unsigned int serverIP;
38 	char *server;
39 	char *_export;
40 	uid_t uid;
41 	gid_t gid;
42 	char *hostname;
43 };
44 
45 struct fs_node
46 {
47 	ino_t vnid;
48 	struct nfs_fhandle fhandle;
49 	struct fs_node *next;
50 };
51 
52 struct fs_nspace
53 {
54 	nspace_id nsid;
55 
56 	thread_id tid;
57 	bool quit;
58 	int s;
59 	struct RPCPendingCalls pendingCalls;
60 
61 	struct sockaddr_in mountAddr,nfsAddr;
62 
63 	int32 xid;
64 
65 	ino_t rootid;
66 
67 	sem_id sem;
68 	struct fs_node *first;
69 
70 	struct mount_nfs_params params;
71 
72 	bigtime_t last_rfsstat;
73 
74 };
75 
76 void fs_nspaceInit (struct fs_nspace *nspace);
77 void fs_nspaceDestroy (struct fs_nspace *nspace);
78 
79 struct fs_file_cookie
80 {
81 	int omode;
82 	off_t original_size;
83 	struct stat st;
84 };
85 
86 typedef struct fs_nspace fs_nspace;
87 typedef struct fs_node fs_node;
88 typedef struct nfs_cookie nfs_cookie;
89 typedef struct fs_file_cookie fs_file_cookie;
90 typedef struct nfs_fhandle nfs_fhandle;
91 
92 #if 0
93 int	fs_read_vnode(fs_nspace *ns, ino_t vnid, char r, fs_node **node);
94 int	fs_write_vnode(fs_nspace *ns, fs_node *node, char r);
95 
96 int	fs_walk(fs_nspace *ns, fs_node *base, const char *file, char **newpath,
97 					ino_t *vnid);
98 
99 int fs_opendir(fs_nspace *ns, fs_node *node, nfs_cookie **cookie);
100 int	fs_closedir(fs_nspace *ns, fs_node *node, nfs_cookie *cookie);
101 int	fs_rewinddir(fs_nspace *ns, fs_node *node, nfs_cookie *cookie);
102 int	fs_readdir(fs_nspace *ns, fs_node *node, nfs_cookie *cookie, long *num,
103 					struct dirent *buf, size_t bufsize);
104 
105 int fs_free_dircookie(fs_nspace *ns, fs_node *node, nfs_cookie *cookie);
106 int	fs_rstat(fs_nspace *ns, fs_node *node, struct stat *);
107 int	fs_mount(nspace_id nsid, const char *devname, ulong flags,
108 					struct mount_nfs_params *parms, size_t len, fs_nspace **data, ino_t *vnid);
109 int	fs_unmount(fs_nspace *ns);
110 int fs_rfsstat(fs_nspace *ns, struct fs_info *);
111 
112 int	fs_open(fs_nspace *ns, fs_node *node, int omode, fs_file_cookie **cookie);
113 int	fs_close(fs_nspace *ns, fs_node *node, fs_file_cookie *cookie);
114 int fs_free_cookie(fs_nspace *ns, fs_node *node, fs_file_cookie *cookie);
115 int fs_read(fs_nspace *ns, fs_node *node, fs_file_cookie *cookie, off_t pos, void *buf,
116 					size_t *len);
117 
118 int fs_write(fs_nspace *ns, fs_node *node, fs_file_cookie *cookie, off_t pos,
119 					const void *buf, size_t *len);
120 
121 int fs_wstat(fs_nspace *ns, fs_node *node, struct stat *, long mask);
122 int fs_wfsstat(fs_nspace *ns, struct fs_info *, long mask);
123 int	fs_create(fs_nspace *ns, fs_node *dir, const char *name,
124 					int omode, int perms, ino_t *vnid, fs_file_cookie **cookie);
125 
126 int	fs_unlink(fs_nspace *ns, fs_node *dir, const char *name);
127 int	fs_remove_vnode(fs_nspace *ns, fs_node *node, char r);
128 int	fs_secure_vnode(fs_nspace *ns, fs_node *node);
129 
130 int	fs_mkdir(fs_nspace *ns, fs_node *dir, const char *name,	int perms);
131 
132 int	fs_rename(fs_nspace *ns, fs_node *olddir, const char *oldname,
133 					fs_node *newdir, const char *newname);
134 
135 int	fs_rmdir(fs_nspace *ns, fs_node *dir, const char *name);
136 int	fs_readlink(fs_nspace *ns, fs_node *node, char *buf, size_t *bufsize);
137 
138 int	fs_symlink(fs_nspace *ns, fs_node *dir, const char *name,
139 					const char *path);
140 #endif
141 
142 status_t create_socket (fs_nspace *ns);
143 status_t init_postoffice (fs_nspace *ns);
144 void shutdown_postoffice (fs_nspace *ns);
145 status_t postoffice_func (fs_nspace *ns);
146 
147 extern uint8 *send_rpc_call(fs_nspace *ns, const struct sockaddr_in *addr, int32 prog, int32 vers, int32 proc, const struct XDROutPacket *packet);
148 extern bool is_successful_reply(struct XDRInPacket *reply);
149 extern status_t get_remote_address(fs_nspace *ns, int32 prog, int32 vers, int32 prot, struct sockaddr_in *addr);
150 extern status_t nfs_mount(fs_nspace *ns, const char *path, nfs_fhandle *fhandle);
151 extern status_t map_nfs_to_system_error(status_t nfsstatus);
152 extern void get_nfs_attr(struct XDRInPacket *reply, struct stat *st);
153 extern status_t nfs_lookup(fs_nspace *ns, const nfs_fhandle *dir, const char *filename, nfs_fhandle *fhandle, struct stat *st);
154 extern status_t nfs_truncate_file(fs_nspace *ns, const nfs_fhandle *fhandle, struct stat *st);
155 
156 nfs_fhandle handle_from_vnid (fs_nspace *ns, ino_t vnid);
157 
158 extern status_t nfs_getattr(fs_nspace *ns, const nfs_fhandle *fhandle, struct stat *st);
159 extern void insert_node(fs_nspace *ns, fs_node *node);
160 extern void remove_node(fs_nspace *ns, ino_t vnid);
161 
162 extern int fs_access(void *ns, void *node, int mode);
163 
164 enum
165 {
166 	C_ERROR_STALE=B_ERRORS_END+1
167 };
168 
169 #define USE_SYSTEM_AUTHENTICATION 1
170 
171 #endif
172