summaryrefslogtreecommitdiff
path: root/net/nfs-common.h
blob: a19b98b7b1f0cb323d5384ee8c22bf058f6446c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/* SPDX-License-Identifier: GPL-2.0+ */
/*
 * (C) Masami Komiya <mkomiya@sonare.it> 2004
 */

#ifndef __NFS_COMMON_H__
#define __NFS_COMMON_H__

#define SUNRPC_PORT     111

#define PROG_PORTMAP    100000
#define PROG_NFS        100003
#define PROG_MOUNT      100005

#define MSG_CALL        0
#define MSG_REPLY       1

#define HASHES_PER_LINE 65	/* Number of "loading" hashes per line	*/
#define NFS_RETRY_COUNT 30

#define NFS_RPC_ERR	1
#define NFS_RPC_DROP	124

#define NFSERR_PERM     1
#define NFSERR_NOENT    2
#define NFSERR_ACCES    13
#define NFSERR_ISDIR    21
#define NFSERR_INVAL    22

/* Values for Accept State flag on RPC answers (See: rfc1831) */
enum rpc_accept_stat {
	NFS_RPC_SUCCESS = 0,	/* RPC executed successfully */
	NFS_RPC_PROG_UNAVAIL = 1,	/* remote hasn't exported program */
	NFS_RPC_PROG_MISMATCH = 2,	/* remote can't support version # */
	NFS_RPC_PROC_UNAVAIL = 3,	/* program can't support procedure */
	NFS_RPC_GARBAGE_ARGS = 4,	/* procedure can't decode params */
	NFS_RPC_SYSTEM_ERR = 5	/* errors like memory allocation failure */
};

enum nfs_version {
	NFS_UNKOWN = 0,
	NFS_V1 = 1,
	NFS_V2 = 2,
	NFS_V3 = 3,
};

extern enum net_loop_state nfs_download_state;
extern char *nfs_filename;
extern char *nfs_path;
extern char nfs_path_buff[2048];
extern struct in_addr nfs_server_ip;
extern int nfs_server_mount_port;
extern int nfs_server_port;
extern int nfs_our_port;
extern int nfs_timeout_count;
extern unsigned long rpc_id;
extern int nfs_offset;
extern int nfs_len;

extern const ulong nfs_timeout;

extern int nfs_state;
#define STATE_PRCLOOKUP_PROG_MOUNT_REQ	1
#define STATE_PRCLOOKUP_PROG_NFS_REQ	2
#define STATE_MOUNT_REQ			3
#define STATE_UMOUNT_REQ		4
#define STATE_LOOKUP_REQ		5
#define STATE_READ_REQ			6
#define STATE_READLINK_REQ		7

/*
 * Block size used for NFS read accesses.  A RPC reply packet (including  all
 * headers) must fit within a single Ethernet frame to avoid fragmentation.
 * However, if CONFIG_IP_DEFRAG is set, a bigger value could be used.  In any
 * case, most NFS servers are optimized for a power of 2.
 */
#define NFS_READ_SIZE	1024	/* biggest power of two that fits Ether frame */
#define NFS_MAX_ATTRS	26

struct rpc_t {
	union {
		u8 data[NFS_READ_SIZE + (6 + NFS_MAX_ATTRS) *
			sizeof(uint32_t)];
		struct {
			u32 id;
			u32 type;
			u32 rpcvers;
			u32 prog;
			u32 vers;
			u32 proc;
			u32 data[1];
		} call;
		struct {
			u32 id;
			u32 type;
			u32 rstatus;
			u32 verifier;
			u32 v2;
			u32 astatus;
			u32 data[NFS_READ_SIZE / sizeof(u32) +
				NFS_MAX_ATTRS];
		} reply;
	} u;
};

char *nfs_basename(char *path);
char *nfs_dirname(char *path);
void rpc_req_common(int rpc_prog, int rpc_proc, uint32_t *data, int datalen,
		    uchar *txbuff, int *pktlen, int *sport);
void nfs_send(void);
void nfs_pkt_recv(uchar *pkt, unsigned int len);

extern enum nfs_version choosen_nfs_version;

/*
 * Implementation specific functions called from common code
 */
void rpc_req(int rpc_prog, int rpc_proc, uint32_t *data, int datalen);
void nfs_refresh_timeout(void);

/**********************************************************************/

#endif /* __NFS_COMMON_H__ */