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