1 /* Virtual File System: Midnight Commander file system.
3 Copyright (C) 1995, 1996, 1997 The Free Software Foundation
5 Written by Miguel de Icaza
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Library General Public License
11 as published by the Free Software Foundation; either version 2 of
12 the License, or (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU Library General Public License for more details.
19 You should have received a copy of the GNU Library General Public
20 License along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
23 /* Namespace: exports mcfs_vfs_ops, tcp_invalidate_socket */
34 #include <netdb.h> /* struct hostent */
35 #include <sys/socket.h> /* AF_INET */
36 #include <netinet/in.h> /* struct in_addr */
37 #include <arpa/inet.h>
39 #include <sys/timeb.h> /* alex: for struct timeb definition */
40 #endif /* SCO_FLAVOR */
52 #include "../src/dialog.h"
54 #define MCFS_MAX_CONNECTIONS 32
55 #define mcserver_port 9876
57 static mcfs_open_connections
= 0;
58 static struct _mcfs_connection
{
65 } mcfs_connections
[MCFS_MAX_CONNECTIONS
];
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 static void mcfs_free_bucket (int bucket
)
100 g_free (mcfs_connections
[bucket
].host
);
101 g_free (mcfs_connections
[bucket
].user
);
102 g_free (mcfs_connections
[bucket
].home
);
104 /* Set all the fields to zero */
105 mcfs_connections
[bucket
].host
=
106 mcfs_connections
[bucket
].user
=
107 mcfs_connections
[bucket
].home
= 0;
108 mcfs_connections
[bucket
].sock
=
109 mcfs_connections
[bucket
].version
= 0;
112 /* FIXME: This part should go to another c module, perhaps tcp.c */
113 static int mcfs_invalidate_socket (int);
115 void tcp_invalidate_socket (int sock
)
117 mcfs_invalidate_socket (sock
);
119 /* FIXME end: 'cause it is used not only by mcfs */
121 static int mcfs_invalidate_socket (int sock
)
124 extern int mc_chdir (char *);
126 for (i
= 0; i
< MCFS_MAX_CONNECTIONS
; i
++)
127 if (mcfs_connections
[i
].sock
== sock
) {
128 mcfs_free_bucket (i
);
133 return -1; /* It was not our sock */
134 /* Break from any possible loop */
139 /* This routine checks the server RPC version and logs the user in */
140 static int mcfs_login_server (int my_socket
, char *user
, int port
,
141 int port_autodetected
, char *netrcpass
,
147 /* Send the version number */
148 rpc_send (my_socket
, RPC_INT
, *version
, RPC_END
);
149 if (0 == rpc_get (my_socket
, RPC_INT
, &result
, RPC_END
))
152 if (result
!= MC_VERSION_OK
){
153 message_1s (1, _(" MCFS "), _(" The server does not support this version "));
158 /* FIXME: figure out why last_current_dir used to be passed here */
159 rpc_send (my_socket
, RPC_INT
, MC_LOGIN
, RPC_STRING
, "/",
160 RPC_STRING
, user
, RPC_END
);
162 if (0 == rpc_get (my_socket
, RPC_INT
, &result
, RPC_END
))
165 if (result
== MC_NEED_PASSWORD
){
166 if (port
> 1024 && port_autodetected
){
168 #ifndef VFS_STANDALONE
169 v
= query_dialog (_(" Warning "),
170 _(" The remote server is not running on a system port \n"
171 " you need a password to log in, but the information may \n"
172 " not be safe on the remote side. Continue? \n"), 3, 2,
173 _(" Yes "), _(" No "));
175 message_1s( 1, " MCFS ", _(" The remote server is running on strange port. Giving up.\n"));
184 if (netrcpass
!= NULL
)
185 pass
= g_strdup (netrcpass
);
187 pass
= vfs_get_password (_(" MCFS Password required "));
189 rpc_send (my_socket
, RPC_INT
, MC_QUIT
, RPC_END
);
193 rpc_send (my_socket
, RPC_INT
, MC_PASS
, RPC_STRING
, pass
, RPC_END
);
195 wipe_password (pass
);
197 if (0 == rpc_get (my_socket
, RPC_INT
, &result
, RPC_END
))
200 if (result
!= MC_LOGINOK
){
201 message_1s (1, " MCFS ", _(" Invalid password "));
202 rpc_send (my_socket
, RPC_INT
, MC_QUIT
, RPC_END
);
210 /* This used to be in utilvfs.c, but as it deals with portmapper, it
211 is probably usefull for mcfs */
213 open_tcp_link (char *host
, int *port
, int *version
, char *caller
)
215 struct sockaddr_in server_address
;
216 unsigned long inaddr
;
223 bzero ((char *) &server_address
, sizeof (server_address
));
224 server_address
.sin_family
= AF_INET
;
226 /* Try to use the dotted decimal number */
227 if ((inaddr
= inet_addr (host
)) != -1)
228 bcopy ((char *) &inaddr
, (char *) &server_address
.sin_addr
,
231 if ((hp
= gethostbyname (host
)) == NULL
){
232 message_2s (1, caller
, " Can't locate hostname: %s ", host
);
235 bcopy ((char *) hp
->h_addr
, (char *) &server_address
.sin_addr
,
239 /* Try to contact a remote portmapper to obtain the listening port */
241 *port
= get_remote_port (&server_address
, version
);
247 server_address
.sin_port
= htons (*port
);
249 if ((my_socket
= socket (AF_INET
, SOCK_STREAM
, 0)) < 0){
250 message_2s (1, caller
, " Can't create socket: %s ",
251 unix_error_string(errno
));
254 if (connect (my_socket
, (struct sockaddr
*) &server_address
,
255 sizeof (server_address
)) < 0){
256 message_2s (1, caller
, " Can't connect to server: %s ",
257 unix_error_string (errno
));
264 static int mcfs_open_tcp_link (char *host
, char *user
,
265 int *port
, char *netrcpass
, int *version
)
268 int old_port
= *port
;
270 my_socket
= open_tcp_link (host
, port
, version
, " MCfs ");
274 /* We got the connection to the server, verify if the server
275 implements our version of the RPC mechanism and then login
278 return mcfs_login_server (my_socket
, user
, *port
, old_port
== 0,
282 static int mcfs_get_free_bucket_init
= 1;
283 static mcfs_connection
*mcfs_get_free_bucket ()
287 if (mcfs_get_free_bucket_init
) {
288 mcfs_get_free_bucket_init
= 0;
289 for (i
= 0; i
< MCFS_MAX_CONNECTIONS
; i
++)
290 mcfs_connections
[i
].host
= 0;
292 for (i
= 0; i
< MCFS_MAX_CONNECTIONS
; i
++){
293 if (!mcfs_connections
[i
].host
)
294 return &mcfs_connections
[i
];
296 /* This can't happend, since we have checked for max connections before */
297 vfs_die("Internal error: mcfs_get_free_bucket");
298 return 0; /* shut up, stupid gcc */
301 /* This routine keeps track of open connections */
302 /* Returns a connected socket to host */
303 static mcfs_connection
*mcfs_open_link (char *host
, char *user
, int *port
, char *netrcpass
)
305 int i
, sock
, version
;
306 mcfs_connection
*bucket
;
308 /* Is the link actually open? */
309 if (mcfs_get_free_bucket_init
) {
310 mcfs_get_free_bucket_init
= 0;
311 for (i
= 0; i
< MCFS_MAX_CONNECTIONS
; i
++)
312 mcfs_connections
[i
].host
= 0;
313 } else for (i
= 0; i
< MCFS_MAX_CONNECTIONS
; i
++){
314 if (!mcfs_connections
[i
].host
)
316 if ((strcmp (host
, mcfs_connections
[i
].host
) == 0) &&
317 (strcmp (user
, mcfs_connections
[i
].user
) == 0))
318 return &mcfs_connections
[i
];
320 if (mcfs_open_connections
== MCFS_MAX_CONNECTIONS
){
321 message_1s (1, MSG_ERROR
, _(" Too many open connections "));
325 if (!(sock
= mcfs_open_tcp_link (host
, user
, port
, netrcpass
, &version
)))
328 bucket
= mcfs_get_free_bucket ();
329 mcfs_open_connections
++;
330 bucket
->host
= g_strdup (host
);
331 bucket
->user
= g_strdup (user
);
333 bucket
->port
= *port
;
335 bucket
->version
= version
;
340 static int is_error (int result
, int errno_num
)
345 my_errno
= errno_num
;
349 static int the_error (int result
, int errno_num
)
352 my_errno
= errno_num
;
358 static char *mcfs_get_path (mcfs_connection
**mc
, char *path
)
360 char *user
, *host
, *remote_path
;
364 /* An absolute path name, try to determine connection socket */
365 if (strncmp (path
, "/#mc:", 5))
369 /* Port = 0 means that open_tcp_link will try to contact the
370 * remote portmapper to get the port number
373 if ((remote_path
= mcfs_get_host_and_username(path
, &host
, &user
, &port
, &pass
)))
374 if (!(*mc
= mcfs_open_link (host
, user
, &port
, pass
))){
375 g_free (remote_path
);
381 wipe_password (pass
);
386 /* NOTE: tildes are deprecated. See ftpfs.c */
388 int f
= !strcmp( remote_path
, "/~" );
389 if (f
|| !strncmp( remote_path
, "/~/", 3 )) {
391 s
= concat_dir_and_file( mcfs_gethome (*mc
), remote_path
+3-f
);
392 g_free (remote_path
);
399 /* Simple function for routines returning only an integer from the server */
400 static int mcfs_handle_simple_error (int sock
, int return_status
)
404 if (0 == rpc_get (sock
, RPC_INT
, &status
, RPC_INT
, &error
, RPC_END
))
405 return the_error (-1, EIO
);
407 if (is_error (status
, error
))
415 static int mcfs_rpc_two_paths (int command
, char *s1
, char *s2
)
420 if ((r1
= mcfs_get_path (&mc
, s1
)) == 0)
423 if ((r2
= mcfs_get_path (&mc
, s2
)) == 0){
435 return mcfs_handle_simple_error (mc
->sock
, 0);
438 static int mcfs_rpc_path (int command
, char *path
)
443 if ((remote_file
= mcfs_get_path (&mc
, path
)) == 0)
448 RPC_STRING
, remote_file
,
451 g_free (remote_file
);
452 return mcfs_handle_simple_error (mc
->sock
, 0);
455 static int mcfs_rpc_path_int (int command
, char *path
, int data
)
460 if ((remote_file
= mcfs_get_path (&mc
, path
)) == 0)
465 RPC_STRING
, remote_file
,
466 RPC_INT
, data
, RPC_END
);
468 g_free (remote_file
);
469 return mcfs_handle_simple_error (mc
->sock
, 0);
472 static int mcfs_rpc_path_int_int (int command
, char *path
, int n1
, int n2
)
477 if ((remote_file
= mcfs_get_path (&mc
, path
)) == 0)
482 RPC_STRING
, remote_file
,
487 g_free (remote_file
);
488 return mcfs_handle_simple_error (mc
->sock
, 0);
491 static char *mcfs_gethome (mcfs_connection
*mc
)
496 return g_strdup (mc
->home
);
498 rpc_send (mc
->sock
, RPC_INT
, MC_GETHOME
, RPC_END
);
499 if (0 == rpc_get (mc
->sock
, RPC_STRING
, &buffer
, RPC_END
))
500 return g_strdup (PATH_SEP_STR
);
502 return g_strdup (buffer
);
507 static void *mcfs_open (vfs
*me
, char *file
, int flags
, int mode
)
511 int result
, error_num
;
512 mcfs_handle
*remote_handle
;
514 if (!(remote_file
= mcfs_get_path (&mc
, file
)))
517 rpc_send (mc
->sock
, RPC_INT
, MC_OPEN
, RPC_STRING
, remote_file
,
518 RPC_INT
, flags
, RPC_INT
, mode
, RPC_END
);
519 g_free (remote_file
);
521 if (0 == rpc_get (mc
->sock
, RPC_INT
, &result
, RPC_INT
, &error_num
, RPC_END
))
524 if (is_error (result
, error_num
))
527 remote_handle
= g_new (mcfs_handle
, 2);
528 remote_handle
->handle
= result
;
529 remote_handle
->conn
= mc
;
531 return remote_handle
;
534 static int mcfs_read (void *data
, char *buffer
, int count
)
536 mcfs_handle
*info
= (mcfs_handle
*) data
;
542 handle
= info
->handle
;
544 rpc_send (mc
->sock
, RPC_INT
, MC_READ
, RPC_INT
, handle
,
545 RPC_INT
, count
, RPC_END
);
547 if (0 == rpc_get (mc
->sock
, RPC_INT
, &result
, RPC_INT
, &error
, RPC_END
))
548 return the_error (-1, EIO
);
550 if (is_error (result
, error
))
553 if (0 == rpc_get (mc
->sock
, RPC_BLOCK
, result
, buffer
, RPC_END
))
554 return the_error (-1, EIO
);
559 static int mcfs_write (void *data
, char *buf
, int nbyte
)
561 mcfs_handle
*info
= (mcfs_handle
*) data
;
566 handle
= info
->handle
;
572 RPC_BLOCK
, nbyte
, buf
,
575 return mcfs_handle_simple_error (mc
->sock
, 1);
578 static int mcfs_close (void *data
)
580 mcfs_handle
*info
= (mcfs_handle
*) data
;
582 int handle
, result
, error
;
587 handle
= info
->handle
;
590 rpc_send (mc
->sock
, RPC_INT
, MC_CLOSE
, RPC_INT
, handle
, RPC_END
);
592 if (0 == rpc_get (mc
->sock
, RPC_INT
, &result
, RPC_INT
, &error
, RPC_END
))
593 return the_error (-1, EIO
);
595 is_error (result
, error
);
601 static int mcfs_errno (vfs
*me
)
606 typedef struct dir_entry
{
608 struct dir_entry
*next
;
614 mcfs_connection
*conn
;
620 static void *mcfs_opendir (vfs
*me
, char *dirname
)
622 opendir_info
*mcfs_info
;
624 int handle
, error_num
;
628 if (!(remote_dir
= mcfs_get_path (&mc
, dirname
)))
631 rpc_send (mc
->sock
, RPC_INT
, MC_OPENDIR
, RPC_STRING
, remote_dir
, RPC_END
);
634 if (0 == rpc_get (mc
->sock
, RPC_INT
, &result
, RPC_INT
, &error_num
, RPC_END
))
637 if (is_error (result
, error_num
))
642 mcfs_info
= g_new (opendir_info
, 1);
643 mcfs_info
->conn
= mc
;
644 mcfs_info
->handle
= handle
;
645 mcfs_info
->entries
= 0;
646 mcfs_info
->current
= 0;
651 static int get_stat_info (mcfs_connection
*mc
, struct stat
*buf
);
653 static int mcfs_loaddir (opendir_info
*mcfs_info
)
656 mcfs_connection
*mc
= mcfs_info
->conn
;
660 rpc_send (link
, RPC_INT
, MC_READDIR
, RPC_INT
, mcfs_info
->handle
, RPC_END
);
664 dir_entry
*new_entry
;
666 if (!rpc_get (link
, RPC_INT
, &entry_len
, RPC_END
))
672 new_entry
= g_new (dir_entry
, 1);
673 new_entry
->text
= g_new0 (char, entry_len
+ 1);
677 mcfs_info
->entries
= new_entry
;
678 mcfs_info
->current
= new_entry
;
681 mcfs_info
->current
->next
= new_entry
;
682 mcfs_info
->current
= new_entry
;
685 if (!rpc_get (link
, RPC_BLOCK
, entry_len
, new_entry
->text
, RPC_END
))
688 /* Then we get the status from the lstat */
689 if (!rpc_get (link
, RPC_INT
, &status
, RPC_INT
, &error
, RPC_END
))
692 if (is_error (status
, error
))
693 new_entry
->merrno
= error
;
695 new_entry
->merrno
= 0;
696 if (!get_stat_info (mc
, &(new_entry
->my_stat
)))
700 mcfs_info
->current
= mcfs_info
->entries
;
705 static void mcfs_free_dir (dir_entry
*de
)
709 mcfs_free_dir (de
->next
);
715 * On some operating systems (Slowaris 2 for example)
716 * the d_name member is just a char long (Nice trick that break everything,
717 * so we need to set up some space for the filename.
721 #ifdef NEED_EXTRA_DIRENT_BUFFER
722 char extra_buffer
[MC_MAXPATHLEN
];
726 /* The readdir routine loads the complete directory */
727 /* It's too slow to ask the server each time */
728 /* It now also sends the complete lstat information for each file */
729 static struct stat
*cached_lstat_info
;
730 static void *mcfs_readdir (void *info
)
732 opendir_info
*mcfs_info
;
735 mcfs_info
= (opendir_info
*) info
;
737 if (!mcfs_info
->entries
)
738 if (!mcfs_loaddir (mcfs_info
))
741 if (mcfs_info
->current
== 0){
742 cached_lstat_info
= 0;
743 mcfs_free_dir (mcfs_info
->entries
);
744 mcfs_info
->entries
= 0;
747 dirent_dest
= &(mcfs_readdir_data
.dent
.d_name
[0]);
748 strcpy (dirent_dest
, mcfs_info
->current
->text
);
749 cached_lstat_info
= &mcfs_info
->current
->my_stat
;
750 mcfs_info
->current
= mcfs_info
->current
->next
;
752 #ifndef DIRENT_LENGTH_COMPUTED
753 mcfs_readdir_data
.dent
.d_namlen
= strlen (mcfs_readdir_data
.dent
.d_name
);
756 return &mcfs_readdir_data
;
759 static int mcfs_closedir (void *info
)
761 opendir_info
*mcfs_info
= (opendir_info
*) info
;
764 rpc_send (mcfs_info
->conn
->sock
, RPC_INT
, MC_CLOSEDIR
,
765 RPC_INT
, mcfs_info
->handle
, RPC_END
);
767 for (p
= mcfs_info
->entries
; p
;){
777 static time_t mcfs_get_time (mcfs_connection
*mc
)
781 if (mc
->version
== 1) {
787 RPC_INT
, &tt
.tm_hour
,
788 RPC_INT
, &tt
.tm_mday
,
789 RPC_INT
, &tt
.tm_year
,
803 sscanf (buf
, "%lx", &tm
);
810 static int get_stat_info (mcfs_connection
*mc
, struct stat
*buf
)
819 rpc_get (sock
, RPC_INT
, &mylong
, RPC_END
);
820 buf
->st_dev
= mylong
;
821 rpc_get (sock
, RPC_INT
, &mylong
, RPC_END
);
822 buf
->st_ino
= mylong
;
823 rpc_get (sock
, RPC_INT
, &mylong
, RPC_END
);
824 buf
->st_mode
= mylong
;
825 rpc_get (sock
, RPC_INT
, &mylong
, RPC_END
);
826 buf
->st_nlink
= mylong
;
827 rpc_get (sock
, RPC_INT
, &mylong
, RPC_END
);
828 buf
->st_uid
= mylong
;
829 rpc_get (sock
, RPC_INT
, &mylong
, RPC_END
);
830 buf
->st_gid
= mylong
;
831 rpc_get (sock
, RPC_INT
, &mylong
, RPC_END
);
832 buf
->st_size
= mylong
;
834 if (!rpc_get (sock
, RPC_INT
, &mylong
, RPC_END
))
836 #ifdef HAVE_ST_BLOCKS
837 buf
->st_blocks
= mylong
;
839 buf
->st_atime
= mcfs_get_time (mc
);
840 buf
->st_mtime
= mcfs_get_time (mc
);
841 buf
->st_ctime
= mcfs_get_time (mc
);
845 static int mcfs_stat_cmd (int cmd
, char *path
, struct stat
*buf
)
851 if ((remote_file
= mcfs_get_path (&mc
, path
)) == 0)
854 rpc_send (mc
->sock
, RPC_INT
, cmd
, RPC_STRING
, remote_file
, RPC_END
);
855 g_free (remote_file
);
856 if (!rpc_get (mc
->sock
, RPC_INT
, &status
, RPC_INT
, &error
, RPC_END
))
857 return the_error (-1, errno
);
859 if (is_error (status
, error
))
862 if (get_stat_info (mc
, buf
))
865 return the_error (-1, EIO
);
868 static int mcfs_stat (vfs
*me
, char *path
, struct stat
*buf
)
870 return mcfs_stat_cmd (MC_STAT
, path
, buf
);
873 static int mcfs_lstat (vfs
*me
, char *path
, struct stat
*buf
)
875 int path_len
= strlen (path
);
876 int entry_len
= strlen (mcfs_readdir_data
.dent
.d_name
);
879 if (strcmp (path
+ path_len
- entry_len
,
880 mcfs_readdir_data
.dent
.d_name
) == 0 &&
882 *buf
= *cached_lstat_info
;
885 return mcfs_stat_cmd (MC_LSTAT
, path
, buf
);
888 static int mcfs_fstat (void *data
, struct stat
*buf
)
890 mcfs_handle
*info
= (mcfs_handle
*) data
;
894 sock
= info
->conn
->sock
;
895 handle
= info
->handle
;
897 rpc_send (sock
, RPC_INT
, MC_FSTAT
, RPC_INT
, handle
, RPC_END
);
898 if (!rpc_get (sock
, RPC_INT
, &result
, RPC_INT
, &error
, RPC_END
))
899 return the_error (-1, EIO
);
901 if (is_error (result
, error
))
904 if (get_stat_info (info
->conn
, buf
))
907 return the_error (-1, EIO
);
910 static int mcfs_chmod (vfs
*me
, char *path
, int mode
)
912 return mcfs_rpc_path_int (MC_CHMOD
, path
, mode
);
915 static int mcfs_chown (vfs
*me
, char *path
, int owner
, int group
)
917 return mcfs_rpc_path_int_int (MC_CHOWN
, path
, owner
, group
);
920 static int mcfs_utime (vfs
*me
, char *path
, struct utimbuf
*times
)
926 if (!(file
= mcfs_get_path (&mc
, path
)))
930 if (mc
->version
>= 2) {
931 char abuf
[BUF_SMALL
];
932 char mbuf
[BUF_SMALL
];
935 atime
= (long) times
->actime
;
936 mtime
= (long) times
->modtime
;
938 g_snprintf (abuf
, sizeof(abuf
), "%lx", atime
);
939 g_snprintf (mbuf
, sizeof(mbuf
), "%lx", mtime
);
941 rpc_send (mc
->sock
, RPC_INT
, MC_UTIME
,
946 status
= mcfs_handle_simple_error (mc
->sock
, 0);
953 static int mcfs_readlink (vfs
*me
, char *path
, char *buf
, int size
)
955 char *remote_file
, *stat_str
;
959 if (!(remote_file
= mcfs_get_path (&mc
, path
)))
962 rpc_send (mc
->sock
, RPC_INT
, MC_READLINK
, RPC_STRING
, remote_file
, RPC_END
);
963 g_free (remote_file
);
964 if (!rpc_get (mc
->sock
, RPC_INT
, &status
, RPC_INT
, &error
, RPC_END
))
965 return the_error (-1, EIO
);
967 if (is_error (status
, errno
))
970 if (!rpc_get (mc
->sock
, RPC_STRING
, &stat_str
, RPC_END
))
971 return the_error (-1, EIO
);
973 strncpy (buf
, stat_str
, size
);
978 static int mcfs_unlink (vfs
*me
, char *path
)
980 return mcfs_rpc_path (MC_UNLINK
, path
);
983 static int mcfs_symlink (vfs
*me
, char *n1
, char *n2
)
985 return mcfs_rpc_two_paths (MC_SYMLINK
, n1
, n2
);
988 static int mcfs_rename (vfs
*me
, char *a
, char *b
)
990 return mcfs_rpc_two_paths (MC_RENAME
, a
, b
);
993 static int mcfs_chdir (vfs
*me
, char *path
)
999 if (!(remote_dir
= mcfs_get_path (&mc
, path
)))
1002 rpc_send (mc
->sock
, RPC_INT
, MC_CHDIR
, RPC_STRING
, remote_dir
, RPC_END
);
1003 g_free (remote_dir
);
1004 if (!rpc_get (mc
->sock
, RPC_INT
, &status
, RPC_INT
, &error
, RPC_END
))
1005 return the_error (-1, EIO
);
1007 if (is_error (status
, error
))
1012 static int mcfs_lseek (void *data
, off_t offset
, int whence
)
1014 mcfs_handle
*info
= (mcfs_handle
*) data
;
1017 sock
= info
->conn
->sock
;
1018 handle
= info
->handle
;
1026 return mcfs_handle_simple_error (sock
, 1);
1029 static int mcfs_mknod (vfs
*me
, char *path
, int mode
, int dev
)
1031 return mcfs_rpc_path_int_int (MC_MKNOD
, path
, mode
, dev
);
1034 static int mcfs_mkdir (vfs
*me
, char *path
, mode_t mode
)
1036 return mcfs_rpc_path_int (MC_MKDIR
, path
, mode
);
1039 static int mcfs_rmdir (vfs
*me
, char *path
)
1041 return mcfs_rpc_path (MC_RMDIR
, path
);
1044 static int mcfs_link (vfs
*me
, char *p1
, char *p2
)
1046 return mcfs_rpc_two_paths (MC_LINK
, p1
, p2
);
1049 /* We do not free anything right now: we free resources when we run
1052 static vfsid
mcfs_getid (vfs
*me
, char *p
, struct vfs_stamping
**parent
)
1059 static int mcfs_nothingisopen (vfsid id
)
1064 static void mcfs_free (vfsid id
)
1066 /* FIXME: Should not be empty */
1069 /* Gives up on a socket and reopnes the connection, the child own the socket
1073 my_forget (char *path
)
1075 char *host
, *user
, *pass
, *p
;
1078 if (strncmp (path
, "/#mc:", 5))
1082 if (path
[0] == '/' && path
[1] == '/')
1085 if ((p
= mcfs_get_host_and_username (path
, &host
, &user
, &port
, &pass
)) == 0) {
1089 wipe_password (pass
);
1092 for (i
= 0; i
< MCFS_MAX_CONNECTIONS
; i
++){
1093 if ((strcmp (host
, mcfs_connections
[i
].host
) == 0) &&
1094 (strcmp (user
, mcfs_connections
[i
].user
) == 0) &&
1095 (port
== mcfs_connections
[i
].port
)){
1097 /* close socket: the child owns it now */
1098 close (mcfs_connections
[i
].sock
);
1100 /* reopen the connection */
1101 mcfs_connections
[i
].sock
= mcfs_open_tcp_link (host
, user
, &port
, pass
, &vers
);
1108 wipe_password (pass
);
1112 mcfs_setctl (vfs
*me
, char *path
, int ctlop
, char *arg
)
1115 case MCCTL_FORGET_ABOUT
:
1122 vfs vfs_mcfs_ops
= {
1123 NULL
, /* This is place of next pointer */
1124 "Midnight Commander's private remote filesystem",