1 /* Low-level protocol for MCFS.
3 Copyright (C) 1995, 1996 Miguel de Icaza
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License
7 as published by the Free Software Foundation; either version 2 of
8 the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
21 * \brief Source: Low-level protocol for MCFS
22 * \author Miguel de Icaza
28 #ifdef ENABLE_VFS_MCFS
35 #include <sys/types.h>
37 #include <sys/socket.h>
38 #include <netinet/in.h>
39 #ifdef HAVE_ARPA_INET_H
40 #include <arpa/inet.h>
45 #include <rpc/pmap_prot.h>
46 #ifdef HAVE_RPC_PMAP_CLNT_H
47 #include <rpc/pmap_clnt.h>
53 #include "../src/global.h"
54 #include "../src/wtools.h" /* message() */
55 #include "../src/main.h" /* print_vfs_message */
59 #include "mcfs.h" /* tcp_invalidate_socket() */
61 #define CHECK_SIG_PIPE(sock) if (got_sigpipe) \
62 { tcp_invalidate_socket (sock); return got_sigpipe = 0; }
64 /* Reads a block on dest for len bytes from sock */
65 /* Returns a boolean indicating the success status */
67 socket_read_block (int sock
, char *dest
, int len
)
71 for (nread
= 0; nread
< len
;) {
72 n
= read (sock
, dest
+ nread
, len
- nread
);
74 tcp_invalidate_socket (sock
);
83 socket_write_block (int sock
, const char *buffer
, int len
)
87 for (left
= len
; left
> 0;) {
88 status
= write (sock
, buffer
, left
);
89 CHECK_SIG_PIPE (sock
);
99 rpc_send (int sock
, ...)
101 long int tmp
, len
, cmd
;
108 cmd
= va_arg (ap
, int);
115 tmp
= htonl (va_arg (ap
, int));
116 write (sock
, &tmp
, sizeof (tmp
));
117 CHECK_SIG_PIPE (sock
);
121 text
= va_arg (ap
, char *);
124 write (sock
, &tmp
, sizeof (tmp
));
125 CHECK_SIG_PIPE (sock
);
126 write (sock
, text
, len
);
127 CHECK_SIG_PIPE (sock
);
131 len
= va_arg (ap
, int);
132 text
= va_arg (ap
, char *);
134 write (sock
, text
, len
);
135 CHECK_SIG_PIPE (sock
);
139 vfs_die ("Unknown rpc message\n");
145 rpc_get (int sock
, ...)
148 char *text
, **str_dest
;
155 cmd
= va_arg (ap
, int);
162 if (socket_read_block (sock
, (char *) &tmp
, sizeof (tmp
)) == 0) {
166 dest
= va_arg (ap
, int *);
170 /* returns an allocated string */
171 case RPC_LIMITED_STRING
:
173 if (socket_read_block (sock
, (char *) &tmp
, sizeof (tmp
)) == 0) {
178 if (cmd
== RPC_LIMITED_STRING
)
179 if (len
> 16 * 1024) {
183 if (len
> 128 * 1024)
186 /* Don't use glib functions here - this code is used by mcserv */
187 text
= malloc (len
+ 1);
188 if (socket_read_block (sock
, text
, len
) == 0) {
195 str_dest
= va_arg (ap
, char **);
200 len
= va_arg (ap
, int);
201 text
= va_arg (ap
, char *);
202 if (socket_read_block (sock
, text
, len
) == 0) {
209 vfs_die ("Unknown rpc message\n");
214 void mcfsutil__unused(void)
217 CFLAGS="-ansi -pedantic -Wall -Wextra -Werror"
220 #endif /* ENABLE_VFS_MCFS */