1 /* Virtual File System: Midnight Commander file system.
3 Copyright (C) 1995, 1996, 1997 The Free Software Foundation
5 Written by Miguel de Icaza
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU Library General Public License
13 as published by the Free Software Foundation; either version 2 of
14 the License, or (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU Library General Public License for more details.
21 You should have received a copy of the GNU Library General Public
22 License along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
25 /* Namespace: exports mcfs_vfs_ops, tcp_invalidate_socket */
36 #include <sys/types.h> /* POSIX-required by sys/socket.h and netdb.h */
37 #include <netdb.h> /* struct hostent */
38 #include <sys/socket.h> /* AF_INET */
39 #include <netinet/in.h> /* struct in_addr */
40 #include <arpa/inet.h>
51 #include "../src/dialog.h"
53 #define MCFS_MAX_CONNECTIONS 32
54 #define mcserver_port 9876
56 static struct _mcfs_connection
{
63 } mcfs_connections
[MCFS_MAX_CONNECTIONS
];
65 typedef struct _mcfs_connection mcfs_connection
;
67 typedef struct { int handle
; mcfs_connection
*conn
; } mcfs_handle
;
71 static char *mcfs_gethome (mcfs_connection
*mc
);
73 /* Extract the hostname and username from the path */
74 /* path is in the form: hostname:user/remote-dir */
75 static char *mcfs_get_host_and_username (char *path
, char **host
, char **user
,
76 int *port
, char **pass
)
78 return vfs_split_url (path
, host
, user
, port
, pass
, 0, 0);
81 static void mcfs_fill_names (vfs
*me
, void (*func
)(char *))
86 for (i
= 0; i
< MCFS_MAX_CONNECTIONS
; i
++){
87 if (mcfs_connections
[i
].host
== 0)
89 name
= g_strconcat ("/#mc:", mcfs_connections
[i
].user
,
90 "@", mcfs_connections
[i
].host
, NULL
);
96 static void mcfs_free_bucket (int bucket
)
98 g_free (mcfs_connections
[bucket
].host
);
99 g_free (mcfs_connections
[bucket
].user
);
100 g_free (mcfs_connections
[bucket
].home
);
102 /* Set all the fields to zero */
103 mcfs_connections
[bucket
].host
=
104 mcfs_connections
[bucket
].user
=
105 mcfs_connections
[bucket
].home
= 0;
106 mcfs_connections
[bucket
].sock
=
107 mcfs_connections
[bucket
].version
= 0;
110 /* FIXME: This part should go to another c module, perhaps tcp.c */
111 static int mcfs_invalidate_socket (int);
113 void tcp_invalidate_socket (int sock
)
115 mcfs_invalidate_socket (sock
);
117 /* FIXME end: 'cause it is used not only by mcfs */
119 static int mcfs_invalidate_socket (int sock
)
122 extern int mc_chdir (char *);
124 for (i
= 0; i
< MCFS_MAX_CONNECTIONS
; i
++)
125 if (mcfs_connections
[i
].sock
== sock
) {
126 mcfs_free_bucket (i
);
131 return -1; /* It was not our sock */
132 /* Break from any possible loop */
137 /* This routine checks the server RPC version and logs the user in */
138 static int mcfs_login_server (int my_socket
, char *user
, int port
,
139 int port_autodetected
, char *netrcpass
,
145 /* Send the version number */
146 rpc_send (my_socket
, RPC_INT
, *version
, RPC_END
);
147 if (0 == rpc_get (my_socket
, RPC_INT
, &result
, RPC_END
))
150 if (result
!= MC_VERSION_OK
){
151 message_1s (1, _(" MCFS "), _(" The server does not support this version "));
156 /* FIXME: figure out why last_current_dir used to be passed here */
157 rpc_send (my_socket
, RPC_INT
, MC_LOGIN
, RPC_STRING
, "/",
158 RPC_STRING
, user
, RPC_END
);
160 if (0 == rpc_get (my_socket
, RPC_INT
, &result
, RPC_END
))
163 if (result
== MC_NEED_PASSWORD
){
164 if (port
> 1024 && port_autodetected
){
166 #ifndef VFS_STANDALONE
167 v
= query_dialog (_(" Warning "),
168 _(" The remote server is not running on a system port \n"
169 " you need a password to log in, but the information may \n"
170 " not be safe on the remote side. Continue? \n"), 3, 2,
171 _(" Yes "), _(" No "));
173 message_1s( 1, _(" MCFS "), _(" The remote server is running on strange port. Giving up.\n"));
182 if (netrcpass
!= NULL
)
183 pass
= g_strdup (netrcpass
);
185 pass
= vfs_get_password (_(" MCFS Password required "));
187 rpc_send (my_socket
, RPC_INT
, MC_QUIT
, RPC_END
);
191 rpc_send (my_socket
, RPC_INT
, MC_PASS
, RPC_STRING
, pass
, RPC_END
);
193 wipe_password (pass
);
195 if (0 == rpc_get (my_socket
, RPC_INT
, &result
, RPC_END
))
198 if (result
!= MC_LOGINOK
){
199 message_1s (1, _(" MCFS "), _(" Invalid password "));
200 rpc_send (my_socket
, RPC_INT
, MC_QUIT
, RPC_END
);
208 /* This used to be in utilvfs.c, but as it deals with portmapper, it
209 is probably usefull for mcfs */
211 open_tcp_link (char *host
, int *port
, int *version
, char *caller
)
213 struct sockaddr_in server_address
;
214 unsigned long inaddr
;
221 bzero ((char *) &server_address
, sizeof (server_address
));
222 server_address
.sin_family
= AF_INET
;
224 /* Try to use the dotted decimal number */
225 if ((inaddr
= inet_addr (host
)) != -1)
226 bcopy ((char *) &inaddr
, (char *) &server_address
.sin_addr
,
229 if ((hp
= gethostbyname (host
)) == NULL
){
230 message_2s (1, caller
, _(" Can't locate hostname: %s "), host
);
233 bcopy ((char *) hp
->h_addr
, (char *) &server_address
.sin_addr
,
237 /* Try to contact a remote portmapper to obtain the listening port */
239 *port
= get_remote_port (&server_address
, version
);
245 server_address
.sin_port
= htons (*port
);
247 if ((my_socket
= socket (AF_INET
, SOCK_STREAM
, 0)) < 0){
248 message_2s (1, caller
, _(" Can't create socket: %s "),
249 unix_error_string(errno
));
252 if (connect (my_socket
, (struct sockaddr
*) &server_address
,
253 sizeof (server_address
)) < 0){
254 message_2s (1, caller
, _(" Can't connect to server: %s "),
255 unix_error_string (errno
));
262 static int mcfs_open_tcp_link (char *host
, char *user
,
263 int *port
, char *netrcpass
, int *version
)
266 int old_port
= *port
;
268 my_socket
= open_tcp_link (host
, port
, version
, " MCfs ");
272 /* We got the connection to the server, verify if the server
273 implements our version of the RPC mechanism and then login
276 return mcfs_login_server (my_socket
, user
, *port
, old_port
== 0,
280 static int mcfs_get_free_bucket_init
= 1;
281 static mcfs_connection
*mcfs_get_free_bucket (void)
285 if (mcfs_get_free_bucket_init
) {
286 mcfs_get_free_bucket_init
= 0;
287 for (i
= 0; i
< MCFS_MAX_CONNECTIONS
; i
++)
288 mcfs_connections
[i
].host
= 0;
290 for (i
= 0; i
< MCFS_MAX_CONNECTIONS
; i
++){
291 if (!mcfs_connections
[i
].host
)
292 return &mcfs_connections
[i
];
294 /* This can't happend, since we have checked for max connections before */
295 vfs_die("Internal error: mcfs_get_free_bucket");
296 return 0; /* shut up, stupid gcc */
299 /* This routine keeps track of open connections */
300 /* Returns a connected socket to host */
301 static mcfs_connection
*mcfs_open_link (char *host
, char *user
, int *port
, char *netrcpass
)
303 static int mcfs_open_connections
= 0;
304 int i
, sock
, version
;
305 mcfs_connection
*bucket
;
307 /* Is the link actually open? */
308 if (mcfs_get_free_bucket_init
) {
309 mcfs_get_free_bucket_init
= 0;
310 for (i
= 0; i
< MCFS_MAX_CONNECTIONS
; i
++)
311 mcfs_connections
[i
].host
= 0;
312 } else for (i
= 0; i
< MCFS_MAX_CONNECTIONS
; i
++){
313 if (!mcfs_connections
[i
].host
)
315 if ((strcmp (host
, mcfs_connections
[i
].host
) == 0) &&
316 (strcmp (user
, mcfs_connections
[i
].user
) == 0))
317 return &mcfs_connections
[i
];
319 if (mcfs_open_connections
== MCFS_MAX_CONNECTIONS
){
320 message_1s (1, MSG_ERROR
, _(" Too many open connections "));
324 if (!(sock
= mcfs_open_tcp_link (host
, user
, port
, netrcpass
, &version
)))
327 bucket
= mcfs_get_free_bucket ();
328 mcfs_open_connections
++;
329 bucket
->host
= g_strdup (host
);
330 bucket
->user
= g_strdup (user
);
332 bucket
->port
= *port
;
334 bucket
->version
= version
;
339 static int is_error (int result
, int errno_num
)
344 my_errno
= errno_num
;
348 static int the_error (int result
, int errno_num
)
351 my_errno
= errno_num
;
357 static char *mcfs_get_path (mcfs_connection
**mc
, char *path
)
359 char *user
, *host
, *remote_path
;
363 /* An absolute path name, try to determine connection socket */
364 if (strncmp (path
, "/#mc:", 5))
368 /* Port = 0 means that open_tcp_link will try to contact the
369 * remote portmapper to get the port number
372 if ((remote_path
= mcfs_get_host_and_username(path
, &host
, &user
, &port
, &pass
)))
373 if (!(*mc
= mcfs_open_link (host
, user
, &port
, pass
))){
374 g_free (remote_path
);
380 wipe_password (pass
);
385 /* NOTE: tildes are deprecated. See ftpfs.c */
387 int f
= !strcmp( remote_path
, "/~" );
388 if (f
|| !strncmp( remote_path
, "/~/", 3 )) {
390 s
= concat_dir_and_file( mcfs_gethome (*mc
), remote_path
+3-f
);
391 g_free (remote_path
);
398 /* Simple function for routines returning only an integer from the server */
399 static int mcfs_handle_simple_error (int sock
, int return_status
)
403 if (0 == rpc_get (sock
, RPC_INT
, &status
, RPC_INT
, &error
, RPC_END
))
404 return the_error (-1, EIO
);
406 if (is_error (status
, error
))
414 static int mcfs_rpc_two_paths (int command
, char *s1
, char *s2
)
419 if ((r1
= mcfs_get_path (&mc
, s1
)) == 0)
422 if ((r2
= mcfs_get_path (&mc
, s2
)) == 0){
434 return mcfs_handle_simple_error (mc
->sock
, 0);
437 static int mcfs_rpc_path (int command
, char *path
)
442 if ((remote_file
= mcfs_get_path (&mc
, path
)) == 0)
447 RPC_STRING
, remote_file
,
450 g_free (remote_file
);
451 return mcfs_handle_simple_error (mc
->sock
, 0);
454 static int mcfs_rpc_path_int (int command
, char *path
, int data
)
459 if ((remote_file
= mcfs_get_path (&mc
, path
)) == 0)
464 RPC_STRING
, remote_file
,
465 RPC_INT
, data
, RPC_END
);
467 g_free (remote_file
);
468 return mcfs_handle_simple_error (mc
->sock
, 0);
471 static int mcfs_rpc_path_int_int (int command
, char *path
, int n1
, int n2
)
476 if ((remote_file
= mcfs_get_path (&mc
, path
)) == 0)
481 RPC_STRING
, remote_file
,
486 g_free (remote_file
);
487 return mcfs_handle_simple_error (mc
->sock
, 0);
490 static char *mcfs_gethome (mcfs_connection
*mc
)
495 return g_strdup (mc
->home
);
497 rpc_send (mc
->sock
, RPC_INT
, MC_GETHOME
, RPC_END
);
498 if (0 == rpc_get (mc
->sock
, RPC_STRING
, &buffer
, RPC_END
))
499 return g_strdup (PATH_SEP_STR
);
501 return g_strdup (buffer
);
506 static void *mcfs_open (vfs
*me
, char *file
, int flags
, int mode
)
510 int result
, error_num
;
511 mcfs_handle
*remote_handle
;
513 if (!(remote_file
= mcfs_get_path (&mc
, file
)))
516 rpc_send (mc
->sock
, RPC_INT
, MC_OPEN
, RPC_STRING
, remote_file
,
517 RPC_INT
, flags
, RPC_INT
, mode
, RPC_END
);
518 g_free (remote_file
);
520 if (0 == rpc_get (mc
->sock
, RPC_INT
, &result
, RPC_INT
, &error_num
, RPC_END
))
523 if (is_error (result
, error_num
))
526 remote_handle
= g_new (mcfs_handle
, 2);
527 remote_handle
->handle
= result
;
528 remote_handle
->conn
= mc
;
530 return remote_handle
;
533 static int mcfs_read (void *data
, char *buffer
, int count
)
535 mcfs_handle
*info
= (mcfs_handle
*) data
;
541 handle
= info
->handle
;
543 rpc_send (mc
->sock
, RPC_INT
, MC_READ
, RPC_INT
, handle
,
544 RPC_INT
, count
, RPC_END
);
546 if (0 == rpc_get (mc
->sock
, RPC_INT
, &result
, RPC_INT
, &error
, RPC_END
))
547 return the_error (-1, EIO
);
549 if (is_error (result
, error
))
552 if (0 == rpc_get (mc
->sock
, RPC_BLOCK
, result
, buffer
, RPC_END
))
553 return the_error (-1, EIO
);
558 static int mcfs_write (void *data
, char *buf
, int nbyte
)
560 mcfs_handle
*info
= (mcfs_handle
*) data
;
565 handle
= info
->handle
;
571 RPC_BLOCK
, nbyte
, buf
,
574 return mcfs_handle_simple_error (mc
->sock
, 1);
577 static int mcfs_close (void *data
)
579 mcfs_handle
*info
= (mcfs_handle
*) data
;
581 int handle
, result
, error
;
586 handle
= info
->handle
;
589 rpc_send (mc
->sock
, RPC_INT
, MC_CLOSE
, RPC_INT
, handle
, RPC_END
);
591 if (0 == rpc_get (mc
->sock
, RPC_INT
, &result
, RPC_INT
, &error
, RPC_END
))
592 return the_error (-1, EIO
);
594 is_error (result
, error
);
600 static int mcfs_errno (vfs
*me
)
605 typedef struct dir_entry
{
607 struct dir_entry
*next
;
613 mcfs_connection
*conn
;
619 static void *mcfs_opendir (vfs
*me
, char *dirname
)
621 opendir_info
*mcfs_info
;
623 int handle
, error_num
;
627 if (!(remote_dir
= mcfs_get_path (&mc
, dirname
)))
630 rpc_send (mc
->sock
, RPC_INT
, MC_OPENDIR
, RPC_STRING
, remote_dir
, RPC_END
);
633 if (0 == rpc_get (mc
->sock
, RPC_INT
, &result
, RPC_INT
, &error_num
, RPC_END
))
636 if (is_error (result
, error_num
))
641 mcfs_info
= g_new (opendir_info
, 1);
642 mcfs_info
->conn
= mc
;
643 mcfs_info
->handle
= handle
;
644 mcfs_info
->entries
= 0;
645 mcfs_info
->current
= 0;
650 static int get_stat_info (mcfs_connection
*mc
, struct stat
*buf
);
652 static int mcfs_loaddir (opendir_info
*mcfs_info
)
655 mcfs_connection
*mc
= mcfs_info
->conn
;
659 rpc_send (link
, RPC_INT
, MC_READDIR
, RPC_INT
, mcfs_info
->handle
, RPC_END
);
663 dir_entry
*new_entry
;
665 if (!rpc_get (link
, RPC_INT
, &entry_len
, RPC_END
))
671 new_entry
= g_new (dir_entry
, 1);
672 new_entry
->text
= g_new0 (char, entry_len
+ 1);
676 mcfs_info
->entries
= new_entry
;
677 mcfs_info
->current
= new_entry
;
680 mcfs_info
->current
->next
= new_entry
;
681 mcfs_info
->current
= new_entry
;
684 if (!rpc_get (link
, RPC_BLOCK
, entry_len
, new_entry
->text
, RPC_END
))
687 /* Then we get the status from the lstat */
688 if (!rpc_get (link
, RPC_INT
, &status
, RPC_INT
, &error
, RPC_END
))
691 if (is_error (status
, error
))
692 new_entry
->merrno
= error
;
694 new_entry
->merrno
= 0;
695 if (!get_stat_info (mc
, &(new_entry
->my_stat
)))
699 mcfs_info
->current
= mcfs_info
->entries
;
704 static void mcfs_free_dir (dir_entry
*de
)
708 mcfs_free_dir (de
->next
);
714 * On some operating systems (Slowaris 2 for example)
715 * the d_name member is just a char long (Nice trick that break everything,
716 * so we need to set up some space for the filename.
720 #ifdef NEED_EXTRA_DIRENT_BUFFER
721 char extra_buffer
[MC_MAXPATHLEN
];
725 /* The readdir routine loads the complete directory */
726 /* It's too slow to ask the server each time */
727 /* It now also sends the complete lstat information for each file */
728 static struct stat
*cached_lstat_info
;
729 static void *mcfs_readdir (void *info
)
731 opendir_info
*mcfs_info
;
734 mcfs_info
= (opendir_info
*) info
;
736 if (!mcfs_info
->entries
)
737 if (!mcfs_loaddir (mcfs_info
))
740 if (mcfs_info
->current
== 0){
741 cached_lstat_info
= 0;
742 mcfs_free_dir (mcfs_info
->entries
);
743 mcfs_info
->entries
= 0;
746 dirent_dest
= &(mcfs_readdir_data
.dent
.d_name
[0]);
747 strcpy (dirent_dest
, mcfs_info
->current
->text
);
748 cached_lstat_info
= &mcfs_info
->current
->my_stat
;
749 mcfs_info
->current
= mcfs_info
->current
->next
;
751 #ifndef DIRENT_LENGTH_COMPUTED
752 mcfs_readdir_data
.dent
.d_namlen
= strlen (mcfs_readdir_data
.dent
.d_name
);
755 return &mcfs_readdir_data
;
758 static int mcfs_closedir (void *info
)
760 opendir_info
*mcfs_info
= (opendir_info
*) info
;
763 rpc_send (mcfs_info
->conn
->sock
, RPC_INT
, MC_CLOSEDIR
,
764 RPC_INT
, mcfs_info
->handle
, RPC_END
);
766 for (p
= mcfs_info
->entries
; p
;){
776 static time_t mcfs_get_time (mcfs_connection
*mc
)
780 if (mc
->version
== 1) {
786 RPC_INT
, &tt
.tm_hour
,
787 RPC_INT
, &tt
.tm_mday
,
788 RPC_INT
, &tt
.tm_year
,
802 sscanf (buf
, "%lx", &tm
);
809 static int get_stat_info (mcfs_connection
*mc
, struct stat
*buf
)
816 rpc_get (sock
, RPC_INT
, &mylong
, RPC_END
);
818 buf
->st_rdev
= mylong
;
820 rpc_get (sock
, RPC_INT
, &mylong
, RPC_END
);
821 buf
->st_ino
= mylong
;
822 rpc_get (sock
, RPC_INT
, &mylong
, RPC_END
);
823 buf
->st_mode
= mylong
;
824 rpc_get (sock
, RPC_INT
, &mylong
, RPC_END
);
825 buf
->st_nlink
= mylong
;
826 rpc_get (sock
, RPC_INT
, &mylong
, RPC_END
);
827 buf
->st_uid
= mylong
;
828 rpc_get (sock
, RPC_INT
, &mylong
, RPC_END
);
829 buf
->st_gid
= mylong
;
830 rpc_get (sock
, RPC_INT
, &mylong
, RPC_END
);
831 buf
->st_size
= mylong
;
833 if (!rpc_get (sock
, RPC_INT
, &mylong
, RPC_END
))
835 #ifdef HAVE_ST_BLOCKS
836 buf
->st_blocks
= mylong
;
838 buf
->st_atime
= mcfs_get_time (mc
);
839 buf
->st_mtime
= mcfs_get_time (mc
);
840 buf
->st_ctime
= mcfs_get_time (mc
);
844 static int mcfs_stat_cmd (int cmd
, char *path
, struct stat
*buf
)
850 if ((remote_file
= mcfs_get_path (&mc
, path
)) == 0)
853 rpc_send (mc
->sock
, RPC_INT
, cmd
, RPC_STRING
, remote_file
, RPC_END
);
854 g_free (remote_file
);
855 if (!rpc_get (mc
->sock
, RPC_INT
, &status
, RPC_INT
, &error
, RPC_END
))
856 return the_error (-1, errno
);
858 if (is_error (status
, error
))
861 if (get_stat_info (mc
, buf
))
864 return the_error (-1, EIO
);
867 static int mcfs_stat (vfs
*me
, char *path
, struct stat
*buf
)
869 return mcfs_stat_cmd (MC_STAT
, path
, buf
);
872 static int mcfs_lstat (vfs
*me
, char *path
, struct stat
*buf
)
874 int path_len
= strlen (path
);
875 int entry_len
= strlen (mcfs_readdir_data
.dent
.d_name
);
878 if (strcmp (path
+ path_len
- entry_len
,
879 mcfs_readdir_data
.dent
.d_name
) == 0 &&
881 *buf
= *cached_lstat_info
;
884 return mcfs_stat_cmd (MC_LSTAT
, path
, buf
);
887 static int mcfs_fstat (void *data
, struct stat
*buf
)
889 mcfs_handle
*info
= (mcfs_handle
*) data
;
893 sock
= info
->conn
->sock
;
894 handle
= info
->handle
;
896 rpc_send (sock
, RPC_INT
, MC_FSTAT
, RPC_INT
, handle
, RPC_END
);
897 if (!rpc_get (sock
, RPC_INT
, &result
, RPC_INT
, &error
, RPC_END
))
898 return the_error (-1, EIO
);
900 if (is_error (result
, error
))
903 if (get_stat_info (info
->conn
, buf
))
906 return the_error (-1, EIO
);
909 static int mcfs_chmod (vfs
*me
, char *path
, int mode
)
911 return mcfs_rpc_path_int (MC_CHMOD
, path
, mode
);
914 static int mcfs_chown (vfs
*me
, char *path
, int owner
, int group
)
916 return mcfs_rpc_path_int_int (MC_CHOWN
, path
, owner
, group
);
919 static int mcfs_utime (vfs
*me
, char *path
, struct utimbuf
*times
)
925 if (!(file
= mcfs_get_path (&mc
, path
)))
929 if (mc
->version
>= 2) {
930 char abuf
[BUF_SMALL
];
931 char mbuf
[BUF_SMALL
];
934 atime
= (long) times
->actime
;
935 mtime
= (long) times
->modtime
;
937 g_snprintf (abuf
, sizeof(abuf
), "%lx", atime
);
938 g_snprintf (mbuf
, sizeof(mbuf
), "%lx", mtime
);
940 rpc_send (mc
->sock
, RPC_INT
, MC_UTIME
,
945 status
= mcfs_handle_simple_error (mc
->sock
, 0);
952 static int mcfs_readlink (vfs
*me
, char *path
, char *buf
, int size
)
954 char *remote_file
, *stat_str
;
958 if (!(remote_file
= mcfs_get_path (&mc
, path
)))
961 rpc_send (mc
->sock
, RPC_INT
, MC_READLINK
, RPC_STRING
, remote_file
, RPC_END
);
962 g_free (remote_file
);
963 if (!rpc_get (mc
->sock
, RPC_INT
, &status
, RPC_INT
, &error
, RPC_END
))
964 return the_error (-1, EIO
);
966 if (is_error (status
, errno
))
969 if (!rpc_get (mc
->sock
, RPC_STRING
, &stat_str
, RPC_END
))
970 return the_error (-1, EIO
);
972 strncpy (buf
, stat_str
, size
);
977 static int mcfs_unlink (vfs
*me
, char *path
)
979 return mcfs_rpc_path (MC_UNLINK
, path
);
982 static int mcfs_symlink (vfs
*me
, char *n1
, char *n2
)
984 return mcfs_rpc_two_paths (MC_SYMLINK
, n1
, n2
);
987 static int mcfs_rename (vfs
*me
, char *a
, char *b
)
989 return mcfs_rpc_two_paths (MC_RENAME
, a
, b
);
992 static int mcfs_chdir (vfs
*me
, char *path
)
998 if (!(remote_dir
= mcfs_get_path (&mc
, path
)))
1001 rpc_send (mc
->sock
, RPC_INT
, MC_CHDIR
, RPC_STRING
, remote_dir
, RPC_END
);
1002 g_free (remote_dir
);
1003 if (!rpc_get (mc
->sock
, RPC_INT
, &status
, RPC_INT
, &error
, RPC_END
))
1004 return the_error (-1, EIO
);
1006 if (is_error (status
, error
))
1011 static int mcfs_lseek (void *data
, off_t offset
, int whence
)
1013 mcfs_handle
*info
= (mcfs_handle
*) data
;
1016 sock
= info
->conn
->sock
;
1017 handle
= info
->handle
;
1025 return mcfs_handle_simple_error (sock
, 1);
1028 static int mcfs_mknod (vfs
*me
, char *path
, int mode
, int dev
)
1030 return mcfs_rpc_path_int_int (MC_MKNOD
, path
, mode
, dev
);
1033 static int mcfs_mkdir (vfs
*me
, char *path
, mode_t mode
)
1035 return mcfs_rpc_path_int (MC_MKDIR
, path
, mode
);
1038 static int mcfs_rmdir (vfs
*me
, char *path
)
1040 return mcfs_rpc_path (MC_RMDIR
, path
);
1043 static int mcfs_link (vfs
*me
, char *p1
, char *p2
)
1045 return mcfs_rpc_two_paths (MC_LINK
, p1
, p2
);
1048 /* We do not free anything right now: we free resources when we run
1051 static vfsid
mcfs_getid (vfs
*me
, char *p
, struct vfs_stamping
**parent
)
1058 static int mcfs_nothingisopen (vfsid id
)
1063 static void mcfs_free (vfsid id
)
1065 /* FIXME: Should not be empty */
1068 /* Gives up on a socket and reopnes the connection, the child own the socket
1072 my_forget (char *path
)
1074 char *host
, *user
, *pass
, *p
;
1077 if (strncmp (path
, "/#mc:", 5))
1081 if (path
[0] == '/' && path
[1] == '/')
1084 if ((p
= mcfs_get_host_and_username (path
, &host
, &user
, &port
, &pass
)) == 0) {
1088 wipe_password (pass
);
1091 for (i
= 0; i
< MCFS_MAX_CONNECTIONS
; i
++){
1092 if ((strcmp (host
, mcfs_connections
[i
].host
) == 0) &&
1093 (strcmp (user
, mcfs_connections
[i
].user
) == 0) &&
1094 (port
== mcfs_connections
[i
].port
)){
1096 /* close socket: the child owns it now */
1097 close (mcfs_connections
[i
].sock
);
1099 /* reopen the connection */
1100 mcfs_connections
[i
].sock
= mcfs_open_tcp_link (host
, user
, &port
, pass
, &vers
);
1107 wipe_password (pass
);
1111 mcfs_setctl (vfs
*me
, char *path
, int ctlop
, char *arg
)
1114 case MCCTL_FORGET_ABOUT
:
1121 vfs vfs_mcfs_ops
= {
1122 NULL
, /* This is place of next pointer */