1 |
/* XDR packing and unpacking in nfsd |
/* xdr.c - XDR packing and unpacking in nfsd. |
2 |
Copyright (C) 1996 Free Software Foundation, Inc. |
Copyright (C) 1996, 2002 Free Software Foundation, Inc. |
3 |
Written by Michael I. Bushnell, p/BSG. |
Written by Michael I. Bushnell, p/BSG. |
4 |
|
|
5 |
This file is part of the GNU Hurd. |
This file is part of the GNU Hurd. |
23 |
#include <string.h> |
#include <string.h> |
24 |
#include "nfsd.h" |
#include "nfsd.h" |
25 |
|
|
26 |
/* Any better ideas? */ |
/* Any better ideas? */ |
27 |
static int |
static int |
28 |
hurd_mode_to_nfs_mode (mode_t m) |
hurd_mode_to_nfs_mode (mode_t m) |
29 |
{ |
{ |
61 |
} |
} |
62 |
} |
} |
63 |
|
|
64 |
/* Encode ST into P and return the next thing to come after it. */ |
/* Encode ST into P and return the next thing to come after it. */ |
65 |
int * |
int * |
66 |
encode_fattr (int *p, struct stat *st, int version) |
encode_fattr (int *p, struct stat *st, int version) |
67 |
{ |
{ |
68 |
*p++ = htonl (hurd_mode_to_nfs_type (st->st_mode, version)); |
*(p++) = htonl (hurd_mode_to_nfs_type (st->st_mode, version)); |
69 |
*p++ = htonl (hurd_mode_to_nfs_mode (st->st_mode)); |
*(p++) = htonl (hurd_mode_to_nfs_mode (st->st_mode)); |
70 |
*p++ = htonl (st->st_nlink); |
*(p++) = htonl (st->st_nlink); |
71 |
*p++ = htonl (st->st_uid); |
*(p++) = htonl (st->st_uid); |
72 |
*p++ = htonl (st->st_gid); |
*(p++) = htonl (st->st_gid); |
73 |
*p++ = htonl (st->st_size); |
*(p++) = htonl (st->st_size); |
74 |
*p++ = htonl (st->st_blksize); |
*(p++) = htonl (st->st_blksize); |
75 |
*p++ = htonl (st->st_rdev); |
*(p++) = htonl (st->st_rdev); |
76 |
*p++ = htonl (st->st_blocks); |
*(p++) = htonl (st->st_blocks); |
77 |
*p++ = htonl (st->st_fsid); |
*(p++) = htonl (st->st_fsid); |
78 |
*p++ = htonl (st->st_ino); |
*(p++) = htonl (st->st_ino); |
79 |
*p++ = htonl (st->st_atime); |
*(p++) = htonl (st->st_atime); |
80 |
*p++ = htonl (st->st_atime_usec); |
*(p++) = htonl (st->st_atime_usec); |
81 |
*p++ = htonl (st->st_mtime); |
*(p++) = htonl (st->st_mtime); |
82 |
*p++ = htonl (st->st_mtime_usec); |
*(p++) = htonl (st->st_mtime_usec); |
83 |
*p++ = htonl (st->st_ctime); |
*(p++) = htonl (st->st_ctime); |
84 |
*p++ = htonl (st->st_ctime_usec); |
*(p++) = htonl (st->st_ctime_usec); |
85 |
return p; |
return p; |
86 |
} |
} |
87 |
|
|
88 |
/* Decode P into NAME and return the next thing to come after it. */ |
/* Decode P into NAME and return the next thing to come after it. */ |
89 |
int * |
int * |
90 |
decode_name (int *p, char **name) |
decode_name (int *p, char **name) |
91 |
{ |
{ |
92 |
int len; |
int len; |
93 |
|
|
94 |
len = ntohl (*p++); |
len = ntohl (*p); |
95 |
|
p++; |
96 |
*name = malloc (len + 1); |
*name = malloc (len + 1); |
97 |
bcopy (p, *name, len); |
memcpy (*name, p, len); |
98 |
(*name)[len] = '\0'; |
(*name)[len] = '\0'; |
99 |
return p + INTSIZE (len); |
return p + INTSIZE (len); |
100 |
} |
} |
101 |
|
|
102 |
/* Encode HANDLE into P and return the next thing to come after it. */ |
/* Encode HANDLE into P and return the next thing to come after it. */ |
103 |
int * |
int * |
104 |
encode_fhandle (int *p, char *handle) |
encode_fhandle (int *p, char *handle) |
105 |
{ |
{ |
106 |
bcopy (handle, p, NFS2_FHSIZE); |
memcpy (p, handle, NFS2_FHSIZE); |
107 |
return p + INTSIZE (NFS2_FHSIZE); |
return p + INTSIZE (NFS2_FHSIZE); |
108 |
} |
} |
109 |
|
|
110 |
/* Encode STRING into P and return the next thing to come after it. */ |
/* Encode STRING into P and return the next thing to come after it. */ |
111 |
int * |
int * |
112 |
encode_string (int *p, char *string) |
encode_string (int *p, char *string) |
113 |
{ |
{ |
114 |
return encode_data (p, string, strlen (string)); |
return encode_data (p, string, strlen (string)); |
115 |
} |
} |
116 |
|
|
117 |
/* Encode DATA into P and return the next thing to come after it. */ |
/* Encode DATA into P and return the next thing to come after it. */ |
118 |
int * |
int * |
119 |
encode_data (int *p, char *data, size_t len) |
encode_data (int *p, char *data, size_t len) |
120 |
{ |
{ |
121 |
int nints = INTSIZE (len); |
int nints = INTSIZE (len); |
122 |
|
|
123 |
p[nints] = 0; |
p[nints] = 0; |
124 |
*p++ = htonl (len); |
*(p++) = htonl (len); |
125 |
bcopy (data, p, len); |
memcpy (p, data, len); |
126 |
return p + nints; |
return p + nints; |
127 |
} |
} |
128 |
|
|
129 |
/* Encode ST into P and return the next thing to come after it. */ |
/* Encode ST into P and return the next thing to come after it. */ |
130 |
int * |
int * |
131 |
encode_statfs (int *p, struct statfs *st) |
encode_statfs (int *p, struct statfs *st) |
132 |
{ |
{ |
133 |
*p++ = st->f_bsize; |
*(p++) = st->f_bsize; |
134 |
*p++ = st->f_bsize; |
*(p++) = st->f_bsize; |
135 |
*p++ = st->f_blocks; |
*(p++) = st->f_blocks; |
136 |
*p++ = st->f_bfree; |
*(p++) = st->f_bfree; |
137 |
*p++ = st->f_bavail; |
*(p++) = st->f_bavail; |
138 |
return p; |
return p; |
139 |
} |
} |
140 |
|
|
141 |
/* Return an NFS error corresponding to Hurd error ERR. */ |
/* Return an NFS error corresponding to Hurd error ERR. */ |
142 |
int |
int |
143 |
nfs_error_trans (error_t err, int version) |
nfs_error_trans (error_t err, int version) |
144 |
{ |
{ |
207 |
return NFSERR_INVAL; |
return NFSERR_INVAL; |
208 |
|
|
209 |
case EOPNOTSUPP: |
case EOPNOTSUPP: |
210 |
return NFSERR_NOTSUPP; /* are we sure here? */ |
return NFSERR_NOTSUPP; /* Are we sure here? */ |
211 |
|
|
212 |
default: |
default: |
213 |
return NFSERR_IO; |
return NFSERR_IO; |
214 |
} |
} |
215 |
} |
} |
216 |
} |
} |
|
|
|
|
|
|
|
|
|