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 */
38 #include <sys/types.h> /* POSIX-required by sys/socket.h and netdb.h */
39 #include <netdb.h> /* struct hostent */
40 #include <sys/socket.h> /* AF_INET */
41 #include <netinet/in.h> /* struct in_addr */
42 #ifdef HAVE_ARPA_INET_H
43 #include <arpa/inet.h>
51 #include "../src/dialog.h"
53 #define MCFS_MAX_CONNECTIONS 32
55 static struct _mcfs_connection
{
62 } mcfs_connections
[MCFS_MAX_CONNECTIONS
];
65 #define mcserver_port 9876
67 typedef struct _mcfs_connection mcfs_connection
;
69 typedef struct { int handle
; mcfs_connection
*conn
; } mcfs_handle
;
73 static char *mcfs_gethome (mcfs_connection
*mc
);
75 /* Extract the hostname and username from the path */
76 /* path is in the form: hostname:user/remote-dir */
77 static char *mcfs_get_host_and_username (char *path
, char **host
, char **user
,
78 int *port
, char **pass
)
80 return vfs_split_url (path
, host
, user
, port
, pass
, 0, 0);
83 static void mcfs_fill_names (vfs
*me
, void (*func
)(char *))
88 for (i
= 0; i
< MCFS_MAX_CONNECTIONS
; i
++){
89 if (mcfs_connections
[i
].host
== 0)
91 name
= g_strconcat ("/#mc:", mcfs_connections
[i
].user
,
92 "@", mcfs_connections
[i
].host
, NULL
);
98 /* This routine checks the server RPC version and logs the user in */
99 static int mcfs_login_server (int my_socket
, char *user
, int port
,
100 int port_autodetected
, char *netrcpass
,
106 /* Send the version number */
107 rpc_send (my_socket
, RPC_INT
, *version
, RPC_END
);
108 if (0 == rpc_get (my_socket
, RPC_INT
, &result
, RPC_END
))
111 if (result
!= MC_VERSION_OK
){
112 message_1s (1, _(" MCFS "), _(" The server does not support this version "));
117 /* FIXME: figure out why last_current_dir used to be passed here */
118 rpc_send (my_socket
, RPC_INT
, MC_LOGIN
, RPC_STRING
, "/",
119 RPC_STRING
, user
, RPC_END
);
121 if (0 == rpc_get (my_socket
, RPC_INT
, &result
, RPC_END
))
124 if (result
== MC_NEED_PASSWORD
){
125 if (port
> 1024 && port_autodetected
){
127 v
= query_dialog (_(" Warning "),
128 _(" The remote server is not running on a system port \n"
129 " you need a password to log in, but the information may \n"
130 " not be safe on the remote side. Continue? \n"), 3, 2,
131 _(" Yes "), _(" No "));
138 if (netrcpass
!= NULL
)
139 pass
= g_strdup (netrcpass
);
141 pass
= vfs_get_password (_(" MCFS Password required "));
143 rpc_send (my_socket
, RPC_INT
, MC_QUIT
, RPC_END
);
147 rpc_send (my_socket
, RPC_INT
, MC_PASS
, RPC_STRING
, pass
, RPC_END
);
149 wipe_password (pass
);
151 if (0 == rpc_get (my_socket
, RPC_INT
, &result
, RPC_END
))
154 if (result
!= MC_LOGINOK
){
155 message_1s (1, _(" MCFS "), _(" Invalid password "));
156 rpc_send (my_socket
, RPC_INT
, MC_QUIT
, RPC_END
);
164 /* This used to be in utilvfs.c, but as it deals with portmapper, it
165 is probably usefull for mcfs */
167 open_tcp_link (char *host
, int *port
, int *version
, char *caller
)
169 struct sockaddr_in server_address
;
170 unsigned long inaddr
;
177 memset ((char *) &server_address
, 0, sizeof (server_address
));
178 server_address
.sin_family
= AF_INET
;
180 /* Try to use the dotted decimal number */
181 if ((inaddr
= inet_addr (host
)) != -1)
182 memcpy ((char *) &server_address
.sin_addr
, (char *) &inaddr
,
185 if ((hp
= gethostbyname (host
)) == NULL
){
186 message_2s (1, caller
, _(" Cannot locate hostname: %s "), host
);
189 memcpy ((char *) &server_address
.sin_addr
, (char *) hp
->h_addr
,
193 /* Try to contact a remote portmapper to obtain the listening port */
195 *port
= get_remote_port (&server_address
, version
);
201 server_address
.sin_port
= htons (*port
);
203 if ((my_socket
= socket (AF_INET
, SOCK_STREAM
, 0)) < 0){
204 message_2s (1, caller
, _(" Cannot create socket: %s "),
205 unix_error_string(errno
));
208 if (connect (my_socket
, (struct sockaddr
*) &server_address
,
209 sizeof (server_address
)) < 0){
210 message_2s (1, caller
, _(" Cannot connect to server: %s "),
211 unix_error_string (errno
));
218 static int mcfs_open_tcp_link (char *host
, char *user
,
219 int *port
, char *netrcpass
, int *version
)
222 int old_port
= *port
;
224 my_socket
= open_tcp_link (host
, port
, version
, " MCfs ");
228 /* We got the connection to the server, verify if the server
229 implements our version of the RPC mechanism and then login
232 return mcfs_login_server (my_socket
, user
, *port
, old_port
== 0,
236 static int mcfs_get_free_bucket_init
= 1;
237 static mcfs_connection
*mcfs_get_free_bucket (void)
241 if (mcfs_get_free_bucket_init
) {
242 mcfs_get_free_bucket_init
= 0;
243 for (i
= 0; i
< MCFS_MAX_CONNECTIONS
; i
++)
244 mcfs_connections
[i
].host
= 0;
246 for (i
= 0; i
< MCFS_MAX_CONNECTIONS
; i
++){
247 if (!mcfs_connections
[i
].host
)
248 return &mcfs_connections
[i
];
250 /* This can't happend, since we have checked for max connections before */
251 vfs_die("Internal error: mcfs_get_free_bucket");
252 return 0; /* shut up, stupid gcc */
255 /* This routine keeps track of open connections */
256 /* Returns a connected socket to host */
257 static mcfs_connection
*mcfs_open_link (char *host
, char *user
, int *port
, char *netrcpass
)
259 static int mcfs_open_connections
= 0;
260 int i
, sock
, version
;
261 mcfs_connection
*bucket
;
263 /* Is the link actually open? */
264 if (mcfs_get_free_bucket_init
) {
265 mcfs_get_free_bucket_init
= 0;
266 for (i
= 0; i
< MCFS_MAX_CONNECTIONS
; i
++)
267 mcfs_connections
[i
].host
= 0;
268 } else for (i
= 0; i
< MCFS_MAX_CONNECTIONS
; i
++){
269 if (!mcfs_connections
[i
].host
)
271 if ((strcmp (host
, mcfs_connections
[i
].host
) == 0) &&
272 (strcmp (user
, mcfs_connections
[i
].user
) == 0))
273 return &mcfs_connections
[i
];
275 if (mcfs_open_connections
== MCFS_MAX_CONNECTIONS
){
276 message_1s (1, MSG_ERROR
, _(" Too many open connections "));
280 if (!(sock
= mcfs_open_tcp_link (host
, user
, port
, netrcpass
, &version
)))
283 bucket
= mcfs_get_free_bucket ();
284 mcfs_open_connections
++;
285 bucket
->host
= g_strdup (host
);
286 bucket
->user
= g_strdup (user
);
288 bucket
->port
= *port
;
290 bucket
->version
= version
;
295 static int is_error (int result
, int errno_num
)
300 my_errno
= errno_num
;
304 static int the_error (int result
, int errno_num
)
307 my_errno
= errno_num
;
313 static char *mcfs_get_path (mcfs_connection
**mc
, char *path
)
315 char *user
, *host
, *remote_path
;
319 /* An absolute path name, try to determine connection socket */
320 if (strncmp (path
, "/#mc:", 5))
324 /* Port = 0 means that open_tcp_link will try to contact the
325 * remote portmapper to get the port number
328 if ((remote_path
= mcfs_get_host_and_username(path
, &host
, &user
, &port
, &pass
)))
329 if (!(*mc
= mcfs_open_link (host
, user
, &port
, pass
))){
330 g_free (remote_path
);
336 wipe_password (pass
);
341 /* NOTE: tildes are deprecated. See ftpfs.c */
343 int f
= !strcmp( remote_path
, "/~" );
344 if (f
|| !strncmp( remote_path
, "/~/", 3 )) {
346 s
= concat_dir_and_file( mcfs_gethome (*mc
), remote_path
+3-f
);
347 g_free (remote_path
);
354 /* Simple function for routines returning only an integer from the server */
355 static int mcfs_handle_simple_error (int sock
, int return_status
)
359 if (0 == rpc_get (sock
, RPC_INT
, &status
, RPC_INT
, &error
, RPC_END
))
360 return the_error (-1, EIO
);
362 if (is_error (status
, error
))
370 static int mcfs_rpc_two_paths (int command
, char *s1
, char *s2
)
375 if ((r1
= mcfs_get_path (&mc
, s1
)) == 0)
378 if ((r2
= mcfs_get_path (&mc
, s2
)) == 0){
390 return mcfs_handle_simple_error (mc
->sock
, 0);
393 static int mcfs_rpc_path (int command
, char *path
)
398 if ((remote_file
= mcfs_get_path (&mc
, path
)) == 0)
403 RPC_STRING
, remote_file
,
406 g_free (remote_file
);
407 return mcfs_handle_simple_error (mc
->sock
, 0);
410 static int mcfs_rpc_path_int (int command
, char *path
, int data
)
415 if ((remote_file
= mcfs_get_path (&mc
, path
)) == 0)
420 RPC_STRING
, remote_file
,
421 RPC_INT
, data
, RPC_END
);
423 g_free (remote_file
);
424 return mcfs_handle_simple_error (mc
->sock
, 0);
427 static int mcfs_rpc_path_int_int (int command
, char *path
, int n1
, int n2
)
432 if ((remote_file
= mcfs_get_path (&mc
, path
)) == 0)
437 RPC_STRING
, remote_file
,
442 g_free (remote_file
);
443 return mcfs_handle_simple_error (mc
->sock
, 0);
446 static char *mcfs_gethome (mcfs_connection
*mc
)
451 return g_strdup (mc
->home
);
453 rpc_send (mc
->sock
, RPC_INT
, MC_GETHOME
, RPC_END
);
454 if (0 == rpc_get (mc
->sock
, RPC_STRING
, &buffer
, RPC_END
))
455 return g_strdup (PATH_SEP_STR
);
457 return g_strdup (buffer
);
462 static void *mcfs_open (vfs
*me
, char *file
, int flags
, int mode
)
466 int result
, error_num
;
467 mcfs_handle
*remote_handle
;
469 if (!(remote_file
= mcfs_get_path (&mc
, file
)))
472 rpc_send (mc
->sock
, RPC_INT
, MC_OPEN
, RPC_STRING
, remote_file
,
473 RPC_INT
, flags
, RPC_INT
, mode
, RPC_END
);
474 g_free (remote_file
);
476 if (0 == rpc_get (mc
->sock
, RPC_INT
, &result
, RPC_INT
, &error_num
, RPC_END
))
479 if (is_error (result
, error_num
))
482 remote_handle
= g_new (mcfs_handle
, 2);
483 remote_handle
->handle
= result
;
484 remote_handle
->conn
= mc
;
486 return remote_handle
;
489 static int mcfs_read (void *data
, char *buffer
, int count
)
491 mcfs_handle
*info
= (mcfs_handle
*) data
;
497 handle
= info
->handle
;
499 rpc_send (mc
->sock
, RPC_INT
, MC_READ
, RPC_INT
, handle
,
500 RPC_INT
, count
, RPC_END
);
502 if (0 == rpc_get (mc
->sock
, RPC_INT
, &result
, RPC_INT
, &error
, RPC_END
))
503 return the_error (-1, EIO
);
505 if (is_error (result
, error
))
508 if (0 == rpc_get (mc
->sock
, RPC_BLOCK
, result
, buffer
, RPC_END
))
509 return the_error (-1, EIO
);
514 static int mcfs_write (void *data
, char *buf
, int nbyte
)
516 mcfs_handle
*info
= (mcfs_handle
*) data
;
521 handle
= info
->handle
;
527 RPC_BLOCK
, nbyte
, buf
,
530 return mcfs_handle_simple_error (mc
->sock
, 1);
533 static int mcfs_close (void *data
)
535 mcfs_handle
*info
= (mcfs_handle
*) data
;
537 int handle
, result
, error
;
542 handle
= info
->handle
;
545 rpc_send (mc
->sock
, RPC_INT
, MC_CLOSE
, RPC_INT
, handle
, RPC_END
);
547 if (0 == rpc_get (mc
->sock
, RPC_INT
, &result
, RPC_INT
, &error
, RPC_END
))
548 return the_error (-1, EIO
);
550 is_error (result
, error
);
556 static int mcfs_errno (vfs
*me
)
561 typedef struct dir_entry
{
563 struct dir_entry
*next
;
569 mcfs_connection
*conn
;
575 static void *mcfs_opendir (vfs
*me
, char *dirname
)
577 opendir_info
*mcfs_info
;
579 int handle
, error_num
;
583 if (!(remote_dir
= mcfs_get_path (&mc
, dirname
)))
586 rpc_send (mc
->sock
, RPC_INT
, MC_OPENDIR
, RPC_STRING
, remote_dir
, RPC_END
);
589 if (0 == rpc_get (mc
->sock
, RPC_INT
, &result
, RPC_INT
, &error_num
, RPC_END
))
592 if (is_error (result
, error_num
))
597 mcfs_info
= g_new (opendir_info
, 1);
598 mcfs_info
->conn
= mc
;
599 mcfs_info
->handle
= handle
;
600 mcfs_info
->entries
= 0;
601 mcfs_info
->current
= 0;
606 static int get_stat_info (mcfs_connection
*mc
, struct stat
*buf
);
608 static int mcfs_loaddir (opendir_info
*mcfs_info
)
611 mcfs_connection
*mc
= mcfs_info
->conn
;
615 rpc_send (link
, RPC_INT
, MC_READDIR
, RPC_INT
, mcfs_info
->handle
, RPC_END
);
619 dir_entry
*new_entry
;
621 if (!rpc_get (link
, RPC_INT
, &entry_len
, RPC_END
))
627 new_entry
= g_new (dir_entry
, 1);
628 new_entry
->text
= g_new0 (char, entry_len
+ 1);
632 mcfs_info
->entries
= new_entry
;
633 mcfs_info
->current
= new_entry
;
636 mcfs_info
->current
->next
= new_entry
;
637 mcfs_info
->current
= new_entry
;
640 if (!rpc_get (link
, RPC_BLOCK
, entry_len
, new_entry
->text
, RPC_END
))
643 /* Then we get the status from the lstat */
644 if (!rpc_get (link
, RPC_INT
, &status
, RPC_INT
, &error
, RPC_END
))
647 if (is_error (status
, error
))
648 new_entry
->merrno
= error
;
650 new_entry
->merrno
= 0;
651 if (!get_stat_info (mc
, &(new_entry
->my_stat
)))
655 mcfs_info
->current
= mcfs_info
->entries
;
660 static void mcfs_free_dir (dir_entry
*de
)
664 mcfs_free_dir (de
->next
);
669 static union vfs_dirent mcfs_readdir_data
;
671 /* The readdir routine loads the complete directory */
672 /* It's too slow to ask the server each time */
673 /* It now also sends the complete lstat information for each file */
674 static struct stat
*cached_lstat_info
;
676 static void *mcfs_readdir(void *info
)
678 opendir_info
*mcfs_info
;
681 mcfs_info
= (opendir_info
*) info
;
683 if (!mcfs_info
->entries
)
684 if (!mcfs_loaddir(mcfs_info
))
687 if (mcfs_info
->current
== 0) {
688 cached_lstat_info
= 0;
689 mcfs_free_dir(mcfs_info
->entries
);
690 mcfs_info
->entries
= 0;
693 dirent_dest
= mcfs_readdir_data
.dent
.d_name
;
694 strncpy(dirent_dest
, mcfs_info
->current
->text
, MC_MAXPATHLEN
);
695 dirent_dest
[MC_MAXPATHLEN
] = 0;
696 cached_lstat_info
= &mcfs_info
->current
->my_stat
;
697 mcfs_info
->current
= mcfs_info
->current
->next
;
699 compute_namelen(&mcfs_readdir_data
.dent
);
701 return &mcfs_readdir_data
;
704 static int mcfs_closedir (void *info
)
706 opendir_info
*mcfs_info
= (opendir_info
*) info
;
709 rpc_send (mcfs_info
->conn
->sock
, RPC_INT
, MC_CLOSEDIR
,
710 RPC_INT
, mcfs_info
->handle
, RPC_END
);
712 for (p
= mcfs_info
->entries
; p
;){
722 static time_t mcfs_get_time (mcfs_connection
*mc
)
726 if (mc
->version
== 1) {
732 RPC_INT
, &tt
.tm_hour
,
733 RPC_INT
, &tt
.tm_mday
,
734 RPC_INT
, &tt
.tm_year
,
748 sscanf (buf
, "%lx", &tm
);
755 static int get_stat_info (mcfs_connection
*mc
, struct stat
*buf
)
762 rpc_get (sock
, RPC_INT
, &mylong
, RPC_END
);
764 buf
->st_rdev
= mylong
;
766 rpc_get (sock
, RPC_INT
, &mylong
, RPC_END
);
767 buf
->st_ino
= mylong
;
768 rpc_get (sock
, RPC_INT
, &mylong
, RPC_END
);
769 buf
->st_mode
= mylong
;
770 rpc_get (sock
, RPC_INT
, &mylong
, RPC_END
);
771 buf
->st_nlink
= mylong
;
772 rpc_get (sock
, RPC_INT
, &mylong
, RPC_END
);
773 buf
->st_uid
= mylong
;
774 rpc_get (sock
, RPC_INT
, &mylong
, RPC_END
);
775 buf
->st_gid
= mylong
;
776 rpc_get (sock
, RPC_INT
, &mylong
, RPC_END
);
777 buf
->st_size
= mylong
;
779 if (!rpc_get (sock
, RPC_INT
, &mylong
, RPC_END
))
781 #ifdef HAVE_ST_BLOCKS
782 buf
->st_blocks
= mylong
;
784 buf
->st_atime
= mcfs_get_time (mc
);
785 buf
->st_mtime
= mcfs_get_time (mc
);
786 buf
->st_ctime
= mcfs_get_time (mc
);
790 static int mcfs_stat_cmd (int cmd
, char *path
, struct stat
*buf
)
796 if ((remote_file
= mcfs_get_path (&mc
, path
)) == 0)
799 rpc_send (mc
->sock
, RPC_INT
, cmd
, RPC_STRING
, remote_file
, RPC_END
);
800 g_free (remote_file
);
801 if (!rpc_get (mc
->sock
, RPC_INT
, &status
, RPC_INT
, &error
, RPC_END
))
802 return the_error (-1, errno
);
804 if (is_error (status
, error
))
807 if (get_stat_info (mc
, buf
))
810 return the_error (-1, EIO
);
813 static int mcfs_stat (vfs
*me
, char *path
, struct stat
*buf
)
815 return mcfs_stat_cmd (MC_STAT
, path
, buf
);
818 static int mcfs_lstat (vfs
*me
, char *path
, struct stat
*buf
)
820 int path_len
= strlen (path
);
821 int entry_len
= strlen (mcfs_readdir_data
.dent
.d_name
);
824 if (strcmp (path
+ path_len
- entry_len
,
825 mcfs_readdir_data
.dent
.d_name
) == 0 &&
827 *buf
= *cached_lstat_info
;
830 return mcfs_stat_cmd (MC_LSTAT
, path
, buf
);
833 static int mcfs_fstat (void *data
, struct stat
*buf
)
835 mcfs_handle
*info
= (mcfs_handle
*) data
;
839 sock
= info
->conn
->sock
;
840 handle
= info
->handle
;
842 rpc_send (sock
, RPC_INT
, MC_FSTAT
, RPC_INT
, handle
, RPC_END
);
843 if (!rpc_get (sock
, RPC_INT
, &result
, RPC_INT
, &error
, RPC_END
))
844 return the_error (-1, EIO
);
846 if (is_error (result
, error
))
849 if (get_stat_info (info
->conn
, buf
))
852 return the_error (-1, EIO
);
855 static int mcfs_chmod (vfs
*me
, char *path
, int mode
)
857 return mcfs_rpc_path_int (MC_CHMOD
, path
, mode
);
860 static int mcfs_chown (vfs
*me
, char *path
, int owner
, int group
)
862 return mcfs_rpc_path_int_int (MC_CHOWN
, path
, owner
, group
);
865 static int mcfs_utime (vfs
*me
, char *path
, struct utimbuf
*times
)
871 if (!(file
= mcfs_get_path (&mc
, path
)))
875 if (mc
->version
>= 2) {
876 char abuf
[BUF_SMALL
];
877 char mbuf
[BUF_SMALL
];
880 atime
= (long) times
->actime
;
881 mtime
= (long) times
->modtime
;
883 g_snprintf (abuf
, sizeof(abuf
), "%lx", atime
);
884 g_snprintf (mbuf
, sizeof(mbuf
), "%lx", mtime
);
886 rpc_send (mc
->sock
, RPC_INT
, MC_UTIME
,
891 status
= mcfs_handle_simple_error (mc
->sock
, 0);
898 static int mcfs_readlink (vfs
*me
, char *path
, char *buf
, int size
)
900 char *remote_file
, *stat_str
;
904 if (!(remote_file
= mcfs_get_path (&mc
, path
)))
907 rpc_send (mc
->sock
, RPC_INT
, MC_READLINK
, RPC_STRING
, remote_file
, RPC_END
);
908 g_free (remote_file
);
909 if (!rpc_get (mc
->sock
, RPC_INT
, &status
, RPC_INT
, &error
, RPC_END
))
910 return the_error (-1, EIO
);
912 if (is_error (status
, errno
))
915 if (!rpc_get (mc
->sock
, RPC_STRING
, &stat_str
, RPC_END
))
916 return the_error (-1, EIO
);
918 strncpy (buf
, stat_str
, size
);
923 static int mcfs_unlink (vfs
*me
, char *path
)
925 return mcfs_rpc_path (MC_UNLINK
, path
);
928 static int mcfs_symlink (vfs
*me
, char *n1
, char *n2
)
930 return mcfs_rpc_two_paths (MC_SYMLINK
, n1
, n2
);
933 static int mcfs_rename (vfs
*me
, char *a
, char *b
)
935 return mcfs_rpc_two_paths (MC_RENAME
, a
, b
);
938 static int mcfs_chdir (vfs
*me
, char *path
)
944 if (!(remote_dir
= mcfs_get_path (&mc
, path
)))
947 rpc_send (mc
->sock
, RPC_INT
, MC_CHDIR
, RPC_STRING
, remote_dir
, RPC_END
);
949 if (!rpc_get (mc
->sock
, RPC_INT
, &status
, RPC_INT
, &error
, RPC_END
))
950 return the_error (-1, EIO
);
952 if (is_error (status
, error
))
957 static int mcfs_lseek (void *data
, off_t offset
, int whence
)
959 mcfs_handle
*info
= (mcfs_handle
*) data
;
962 sock
= info
->conn
->sock
;
963 handle
= info
->handle
;
971 return mcfs_handle_simple_error (sock
, 1);
974 static int mcfs_mknod (vfs
*me
, char *path
, int mode
, int dev
)
976 return mcfs_rpc_path_int_int (MC_MKNOD
, path
, mode
, dev
);
979 static int mcfs_mkdir (vfs
*me
, char *path
, mode_t mode
)
981 return mcfs_rpc_path_int (MC_MKDIR
, path
, mode
);
984 static int mcfs_rmdir (vfs
*me
, char *path
)
986 return mcfs_rpc_path (MC_RMDIR
, path
);
989 static int mcfs_link (vfs
*me
, char *p1
, char *p2
)
991 return mcfs_rpc_two_paths (MC_LINK
, p1
, p2
);
994 /* We do not free anything right now: we free resources when we run
997 static vfsid
mcfs_getid (vfs
*me
, char *p
, struct vfs_stamping
**parent
)
1004 static int mcfs_nothingisopen (vfsid id
)
1009 static void mcfs_free (vfsid id
)
1011 /* FIXME: Should not be empty */
1014 /* Gives up on a socket and reopnes the connection, the child own the socket
1018 my_forget (char *path
)
1020 char *host
, *user
, *pass
, *p
;
1023 if (strncmp (path
, "/#mc:", 5))
1027 if (path
[0] == '/' && path
[1] == '/')
1030 if ((p
= mcfs_get_host_and_username (path
, &host
, &user
, &port
, &pass
)) == 0) {
1034 wipe_password (pass
);
1037 for (i
= 0; i
< MCFS_MAX_CONNECTIONS
; i
++){
1038 if ((strcmp (host
, mcfs_connections
[i
].host
) == 0) &&
1039 (strcmp (user
, mcfs_connections
[i
].user
) == 0) &&
1040 (port
== mcfs_connections
[i
].port
)){
1042 /* close socket: the child owns it now */
1043 close (mcfs_connections
[i
].sock
);
1045 /* reopen the connection */
1046 mcfs_connections
[i
].sock
= mcfs_open_tcp_link (host
, user
, &port
, pass
, &vers
);
1053 wipe_password (pass
);
1057 mcfs_setctl (vfs
*me
, char *path
, int ctlop
, char *arg
)
1060 case MCCTL_FORGET_ABOUT
:
1067 vfs vfs_mcfs_ops
= {
1068 NULL
, /* This is place of next pointer */
1125 /* FIXME: This part should go to another c module, perhaps tcp.c */
1127 static void mcfs_free_bucket (int bucket
)
1129 g_free (mcfs_connections
[bucket
].host
);
1130 g_free (mcfs_connections
[bucket
].user
);
1131 g_free (mcfs_connections
[bucket
].home
);
1133 /* Set all the fields to zero */
1134 mcfs_connections
[bucket
].host
=
1135 mcfs_connections
[bucket
].user
=
1136 mcfs_connections
[bucket
].home
= 0;
1137 mcfs_connections
[bucket
].sock
=
1138 mcfs_connections
[bucket
].version
= 0;
1141 static int mcfs_invalidate_socket (int sock
)
1144 extern int mc_chdir (char *);
1146 for (i
= 0; i
< MCFS_MAX_CONNECTIONS
; i
++)
1147 if (mcfs_connections
[i
].sock
== sock
) {
1148 mcfs_free_bucket (i
);
1153 return -1; /* It was not our sock */
1154 /* Break from any possible loop */
1159 void tcp_invalidate_socket (int sock
)
1161 mcfs_invalidate_socket (sock
);
1163 /* FIXME end: 'cause it is used not only by mcfs */
1165 #endif /* WITH_MCFS */