1 | #ifndef lint |
---|
2 | /* @(#)mountxdr.c 2.1 86/04/14 NFSSRC */ |
---|
3 | static char sccsid[] = "@(#)mountxdr.c 1.1 86/02/05 Copyr 1984 Sun Micro"; |
---|
4 | #endif |
---|
5 | |
---|
6 | #include <stdio.h> |
---|
7 | #include <sys/types.h> |
---|
8 | #ifdef _IBMR2 |
---|
9 | #include <sys/select.h> |
---|
10 | #endif |
---|
11 | #include <rpc/rpc.h> |
---|
12 | #include <sys/time.h> |
---|
13 | #include <sys/errno.h> |
---|
14 | #ifndef sgi |
---|
15 | #include <nfs/nfs.h> |
---|
16 | #else |
---|
17 | #include <sys/fs/nfs.h> |
---|
18 | #endif |
---|
19 | #include <rpcsvc/mount.h> |
---|
20 | |
---|
21 | #define xdr_dev_t xdr_short |
---|
22 | |
---|
23 | xdr_fhstatus(xdrs, fhsp) |
---|
24 | XDR *xdrs; |
---|
25 | struct fhstatus *fhsp; |
---|
26 | { |
---|
27 | if (!xdr_int(xdrs, &fhsp->fhs_status)) |
---|
28 | return FALSE; |
---|
29 | if (fhsp->fhs_status == 0) { |
---|
30 | if (!xdr_fhandle(xdrs, &fhsp->fhs_fh)) |
---|
31 | return FALSE; |
---|
32 | } |
---|
33 | } |
---|
34 | |
---|
35 | xdr_fhandle(xdrs, fhp) |
---|
36 | XDR *xdrs; |
---|
37 | fhandle_t *fhp; |
---|
38 | { |
---|
39 | if (xdr_opaque(xdrs, fhp, NFS_FHSIZE)) { |
---|
40 | return (TRUE); |
---|
41 | } |
---|
42 | return (FALSE); |
---|
43 | } |
---|
44 | |
---|
45 | bool_t |
---|
46 | xdr_path(xdrs, pathp) |
---|
47 | XDR *xdrs; |
---|
48 | char **pathp; |
---|
49 | { |
---|
50 | if (xdr_string(xdrs, pathp, 1024)) { |
---|
51 | return(TRUE); |
---|
52 | } |
---|
53 | return(FALSE); |
---|
54 | } |
---|
55 | |
---|
56 | /* |
---|
57 | * body of a mountlist |
---|
58 | */ |
---|
59 | bool_t |
---|
60 | xdr_mountbody(xdrs, mlp) |
---|
61 | XDR *xdrs; |
---|
62 | struct mountlist *mlp; |
---|
63 | { |
---|
64 | if (!xdr_path(xdrs, &mlp->ml_name)) |
---|
65 | return FALSE; |
---|
66 | if (!xdr_path(xdrs, &mlp->ml_path)) |
---|
67 | return FALSE; |
---|
68 | return(TRUE); |
---|
69 | } |
---|
70 | |
---|
71 | bool_t |
---|
72 | xdr_mountlist(xdrs, mlp) |
---|
73 | register XDR *xdrs; |
---|
74 | register struct mountlist **mlp; |
---|
75 | { |
---|
76 | /* |
---|
77 | * more_elements is pre-computed in case the direction is |
---|
78 | * XDR_ENCODE or XDR_FREE. more_elements is overwritten by |
---|
79 | * xdr_bool when the direction is XDR_DECODE. |
---|
80 | */ |
---|
81 | int more_elements; |
---|
82 | register int freeing = (xdrs->x_op == XDR_FREE); |
---|
83 | register struct mountlist **nxt; |
---|
84 | |
---|
85 | while (TRUE) { |
---|
86 | more_elements = (*mlp != NULL); |
---|
87 | if (! xdr_bool(xdrs, &more_elements)) |
---|
88 | return (FALSE); |
---|
89 | if (! more_elements) |
---|
90 | return (TRUE); /* we are done */ |
---|
91 | /* |
---|
92 | * the unfortunate side effect of non-recursion is that in |
---|
93 | * the case of freeing we must remember the nxt object |
---|
94 | * before we free the current object ... |
---|
95 | */ |
---|
96 | if (freeing) |
---|
97 | nxt = &((*mlp)->ml_nxt); |
---|
98 | if (! xdr_reference(xdrs, mlp, sizeof(struct mountlist), |
---|
99 | xdr_mountbody)) |
---|
100 | return (FALSE); |
---|
101 | mlp = (freeing) ? nxt : &((*mlp)->ml_nxt); |
---|
102 | } |
---|
103 | } |
---|
104 | |
---|
105 | /* |
---|
106 | * Strange but true: the boolean that tells if another element |
---|
107 | * in the list is present has already been checked. We handle the |
---|
108 | * body of this element then check on the next element. YUK. |
---|
109 | */ |
---|
110 | bool_t |
---|
111 | xdr_groups(xdrs, gr) |
---|
112 | register XDR *xdrs; |
---|
113 | register struct groups *gr; |
---|
114 | { |
---|
115 | /* |
---|
116 | * more_elements is pre-computed in case the direction is |
---|
117 | * XDR_ENCODE or XDR_FREE. more_elements is overwritten by |
---|
118 | * xdr_bool when the direction is XDR_DECODE. |
---|
119 | */ |
---|
120 | int more_elements; |
---|
121 | register int freeing = (xdrs->x_op == XDR_FREE); |
---|
122 | register struct groups *nxt; |
---|
123 | |
---|
124 | if (! xdr_path(xdrs, &(gr->g_name))) |
---|
125 | return (FALSE); |
---|
126 | more_elements = (gr->g_next != NULL); |
---|
127 | if (! xdr_bool(xdrs, &more_elements)) |
---|
128 | return (FALSE); |
---|
129 | if (! more_elements) { |
---|
130 | gr->g_next = NULL; |
---|
131 | return (TRUE); /* we are done */ |
---|
132 | } |
---|
133 | return (xdr_reference(xdrs, &(gr->g_next), sizeof(struct groups), |
---|
134 | xdr_groups)); |
---|
135 | } |
---|
136 | |
---|
137 | /* |
---|
138 | * body of a exportlist |
---|
139 | */ |
---|
140 | bool_t |
---|
141 | xdr_exportbody(xdrs, ex) |
---|
142 | XDR *xdrs; |
---|
143 | struct exports *ex; |
---|
144 | { |
---|
145 | int more_elements; |
---|
146 | |
---|
147 | if (!xdr_path(xdrs, &ex->ex_name)) |
---|
148 | return FALSE; |
---|
149 | more_elements = (ex->ex_groups != NULL); |
---|
150 | if (! xdr_bool(xdrs, &more_elements)) |
---|
151 | return (FALSE); |
---|
152 | if (! more_elements) { |
---|
153 | ex->ex_groups = NULL; |
---|
154 | return (TRUE); /* we are done */ |
---|
155 | } |
---|
156 | if (! xdr_reference(xdrs, &(ex->ex_groups), sizeof(struct groups), |
---|
157 | xdr_groups)) |
---|
158 | return (FALSE); |
---|
159 | return(TRUE); |
---|
160 | } |
---|
161 | |
---|
162 | |
---|
163 | /* |
---|
164 | * Encodes the export list structure "exports" on the |
---|
165 | * wire as: |
---|
166 | * bool_t eol; |
---|
167 | * if (!eol) { |
---|
168 | * char *name; |
---|
169 | * struct groups *groups; |
---|
170 | * } |
---|
171 | * where groups look like: |
---|
172 | * if (!eog) { |
---|
173 | * char *gname; |
---|
174 | * } |
---|
175 | */ |
---|
176 | bool_t |
---|
177 | xdr_exports(xdrs, exp) |
---|
178 | register XDR *xdrs; |
---|
179 | register struct exports **exp; |
---|
180 | { |
---|
181 | /* |
---|
182 | * more_elements is pre-computed in case the direction is |
---|
183 | * XDR_ENCODE or XDR_FREE. more_elements is overwritten by |
---|
184 | * xdr_bool when the direction is XDR_DECODE. |
---|
185 | */ |
---|
186 | int more_elements; |
---|
187 | register int freeing = (xdrs->x_op == XDR_FREE); |
---|
188 | register struct exports **nxt; |
---|
189 | |
---|
190 | while (TRUE) { |
---|
191 | more_elements = (*exp != NULL); |
---|
192 | if (! xdr_bool(xdrs, &more_elements)) |
---|
193 | return (FALSE); |
---|
194 | if (! more_elements) |
---|
195 | return (TRUE); /* we are done */ |
---|
196 | /* |
---|
197 | * the unfortunate side effect of non-recursion is that in |
---|
198 | * the case of freeing we must remember the nxt object |
---|
199 | * before we free the current object ... |
---|
200 | */ |
---|
201 | if (freeing) |
---|
202 | nxt = &((*exp)->ex_next); |
---|
203 | if (! xdr_reference(xdrs, exp, sizeof(struct exports), |
---|
204 | xdr_exportbody)) |
---|
205 | return (FALSE); |
---|
206 | exp = (freeing) ? nxt : &((*exp)->ex_next); |
---|
207 | } |
---|
208 | } |
---|