diff --git a/config.h.in b/config.h.in index 0ec3aeb0f..3798afe54 100644 --- a/config.h.in +++ b/config.h.in @@ -101,9 +101,9 @@ /* If using the C implementation of alloca, define if you know the direction of stack growth for your system; otherwise it will be automatically deduced at run-time. - STACK_DIRECTION > 0 => grows toward higher addresses - STACK_DIRECTION < 0 => grows toward lower addresses - STACK_DIRECTION = 0 => direction of growth unknown + STACK_DIRECTION > 0 => grows toward higher addresses + STACK_DIRECTION < 0 => grows toward lower addresses + STACK_DIRECTION = 0 => direction of growth unknown */ #undef STACK_DIRECTION @@ -113,9 +113,6 @@ /* Define to `int' if doesn't define. */ #undef uid_t -/* Define if the X Window System is missing or not being used. */ -#undef X_DISPLAY_MISSING - #undef VERSION #undef PACKAGE @@ -408,6 +405,9 @@ /* Define if you have the truncate function. */ #undef HAVE_TRUNCATE +/* Define if you have the valloc function. */ +#undef HAVE_VALLOC + /* Define if you have the header file. */ #undef HAVE_ARGZ_H diff --git a/src/ChangeLog b/src/ChangeLog index ecdd074a0..6aa24054e 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,14 @@ +Mon Oct 12 22:47:53 1998 Pavel Machek + + * file.c (copy_file_file): MCCTL_SETREMOTECOPY is no longer used + + * file.c (copy_file_file): do_reget is now correctly done using + open()/lseek() pair + +Wed Oct 7 22:20:37 1998 Pavel Machek + + * file.c: Ask user if (s)he wants to delete incomplete file + Sun Oct 11 20:21:20 1998 Peter Kleiweg * mfmt.c (main): When there are an even number of empty lines diff --git a/src/achown.c b/src/achown.c index 83f4baaf8..6b8854a1e 100644 --- a/src/achown.c +++ b/src/achown.c @@ -642,6 +642,8 @@ void chown_advanced_cmd (void) files_on_begin = cpanel->marked; +#if 0 + /* I think that this code is trying to be much too clever -- pavel@ucw.cz */ if (!vfs_current_is_local ()) { if (vfs_current_is_extfs ()) { message (1, _(" Oops... "), @@ -653,6 +655,7 @@ void chown_advanced_cmd (void) return; } } +#endif do { /* do while any files remaining */ init_chown_advanced (); diff --git a/src/chmod.c b/src/chmod.c index e66f4a2e6..951cb41b3 100644 --- a/src/chmod.c +++ b/src/chmod.c @@ -324,6 +324,9 @@ void chmod_cmd (void) int i; struct stat sf_stat; +#if 0 + /* Don't do things like this: you do not want to enumerate all + filesystems that can not support chmod, here. */ if (!vfs_current_is_local ()) { if (vfs_current_is_extfs ()) { message (1, _(" Oops... "), @@ -335,6 +338,7 @@ void chmod_cmd (void) return; } } +#endif do { /* do while any files remaining */ init_chmod (); diff --git a/src/chown.c b/src/chown.c index 43f8a1141..e211fe3c6 100644 --- a/src/chown.c +++ b/src/chown.c @@ -251,6 +251,8 @@ void chown_cmd (void) gid_t new_group; char buffer [15]; +#if 0 + /* Please no */ if (!vfs_current_is_local ()) { if (vfs_current_is_extfs ()) { message (1, _(" Oops... "), @@ -262,6 +264,7 @@ void chown_cmd (void) return; } } +#endif do { /* do while any files remaining */ init_chown (); diff --git a/src/file.c b/src/file.c index b117f3174..c9770b3ce 100644 --- a/src/file.c +++ b/src/file.c @@ -110,13 +110,7 @@ /* }}} */ -#if USE_VFS && USE_NETCODE -extern -#else -static -#endif - -int do_reget; +static int do_reget; /* rcsid [] = "$Id$" */ int verbose = 1; @@ -718,36 +712,25 @@ free_linklist (struct link **linklist) *linklist = NULL; } +int +is_in_linklist (struct link *lp, char *path, struct stat *sb) +{ + ino_t ino = sb->st_ino; + dev_t dev = sb->st_dev; #ifdef USE_VFS -int -is_in_linklist (struct link *lp, char *path, struct stat *sb) -{ - ino_t ino = sb->st_ino; - dev_t dev = sb->st_dev; vfs *vfs = vfs_type (path); - - while (lp) { - if (lp->vfs == vfs && lp->ino == ino && lp->dev == dev ) - return 1; - lp = lp->next; - } - return 0; -} -#else -int -is_in_linklist (struct link *lp, char *path, struct stat *sb) -{ - ino_t ino = sb->st_ino; - dev_t dev = sb->st_dev; - - while (lp) { - if (lp->ino == ino && lp->dev == dev ) - return 1; - lp = lp->next; - } - return 0; -} #endif + + while (lp) { +#ifdef USE_VFS + if (lp->vfs == vfs) +#endif + if (lp->ino == ino && lp->dev == dev ) + return 1; + lp = lp->next; + } + return 0; +} /* Returns 0 if the inode wasn't found in the cache and 1 if it was found and a hardlink was succesfully made */ @@ -761,8 +744,10 @@ check_hardlinks (char *src_name, char *dst_name, struct stat *pstat) struct stat link_stat; char *p; +#if 1 /* What will happen if we kill this line? mc_link() will fail on this and it is right behaivour... */ if (vfs_file_is_ftp (src_name)) return 0; +#endif for (lp = linklist; lp != NULL; lp = lp -> next) if (lp->vfs == my_vfs && lp->ino == ino && lp->dev == dev){ if (!mc_stat (lp->name, &link_stat) && link_stat.st_ino == ino && @@ -776,7 +761,7 @@ check_hardlinks (char *src_name, char *dst_name, struct stat *pstat) } } } - /* FIXME: Announce we couldn't make the hardlink */ + message_1s(1, MSG_ERROR, _(" Could not make the hardlink ")); return 0; } lp = (struct link *) xmalloc (sizeof (struct link) + strlen (src_name) @@ -905,6 +890,7 @@ copy_file_file (char *src_path, char *dst_path, int ask_overwrite) A single goto label is much easier to handle than a bunch of gotos ;-). */ unsigned resources = 0; + do_reget = 0; /* FIXME: We should not be using global variables! */ return_status = FILE_RETRY; if (show_source (src_path) == FILE_ABORT @@ -949,10 +935,7 @@ copy_file_file (char *src_path, char *dst_path, int ask_overwrite) /* Should we replace destination? */ if (ask_overwrite) { - if (vfs_file_is_ftp (src_path)) - do_reget = -1; - else - do_reget = 0; + do_reget = 0; return_status = query_replace (dst_path, &sb, &sb2); if (return_status != FILE_CONT) @@ -1010,10 +993,6 @@ copy_file_file (char *src_path, char *dst_path, int ask_overwrite) } } - if (!do_append && !vfs_file_is_local (src_path) && vfs_file_is_local (dst_path)){ - mc_setctl (src_path, MCCTL_SETREMOTECOPY, dst_path); - } - gettimeofday (&tv_transfer_start, (struct timezone *) NULL); retry_src_open: @@ -1027,6 +1006,12 @@ copy_file_file (char *src_path, char *dst_path, int ask_overwrite) } resources |= 1; + if (do_reget) { + if (mc_lseek (src_desc, do_reget, SEEK_SET) != do_reget) { + message_1s (1, _(" Warning "), _(" Reget failed, about to overwrite file ")); + do_reget = do_append = 0; + } + } retry_src_fstat: if (mc_fstat (src_desc, &sb)){ @@ -1080,7 +1065,6 @@ copy_file_file (char *src_path, char *dst_path, int ask_overwrite) buf = (char *) xmalloc (buf_size, "copy_file_file"); - eta_secs = 0.0; bps = 0; return_status = show_file_progress (0, file_size); @@ -1090,7 +1074,7 @@ copy_file_file (char *src_path, char *dst_path, int ask_overwrite) { struct timeval tv_current, tv_last_update, tv_last_input; - int i, size, secs, update_secs; + int secs, update_secs; long dt; char *stalled_msg; @@ -1208,7 +1192,10 @@ ret: if (resources & 4) { /* Remove short file */ - mc_unlink (dst_path); + int result; + result = query_dialog ("Copy", _("Incomplete file was retrieved. Keep it?"), D_ERROR, 2, _("&Delete"), _("&Keep")); + if (!result) + mc_unlink (dst_path); } else if (resources & (2|8)) { /* no short file and destination file exists */ #ifndef OS2_NT @@ -1513,11 +1500,6 @@ move_file_file (char *s, char *d) } if (confirm_overwrite){ - if (vfs_file_is_ftp (s)) - do_reget = -1; - else - do_reget = 0; - return_status = query_replace (d, &src_stats, &dst_stats); if (return_status != FILE_CONT) return return_status; @@ -2350,8 +2332,8 @@ panel_operate (void *source_panel, int operation, char *thedefault) /* If we are the parent */ if (v == 1){ - vfs_force_expire (panel->cwd); - vfs_force_expire (dest); + mc_setctl (panel->cwd, MCCTL_FORGET_ABOUT, NULL); + mc_setctl (dest, MCCTL_FORGET_ABOUT, NULL); return 0; } } @@ -2745,7 +2727,7 @@ init_replace (enum OperationMode mode) /* "this target..." widgets */ tk_new_frame (replace_dlg, "p."); if (!S_ISDIR (d_stat->st_mode)){ - if ((do_reget == -1 && d_stat->st_size && s_stat->st_size > d_stat->st_size)) + if ((d_stat->st_size && s_stat->st_size > d_stat->st_size)) ADD_RD_BUTTON(7); ADD_RD_BUTTON(8); @@ -2792,7 +2774,7 @@ real_query_replace (enum OperationMode mode, char *destname, struct stat *_s_sta return FILE_CONT; case REPLACE_REGET: - do_reget = _d_stat->st_size; + do_reget = _d_stat->st_size; /* Carefull: we fall through and set do_append */ case REPLACE_APPEND: do_append = 1; diff --git a/src/main.c b/src/main.c index 525352f0b..2731c3430 100644 --- a/src/main.c +++ b/src/main.c @@ -906,18 +906,6 @@ directory_history_add (WPanel * panel, char *s) panel_update_marks (panel); } -/* Translate ftp://user:password@host/directory to - /#ftp:user:password@host/directory. - */ -static char * -translate_url_to_new_syntax (const char *p) -{ - if (strncmp (p, "ftp://", 6) == 0) - return copy_strings ("/#ftp:", p + 6, 0); - else - return strdup (p); -} - /* * If we moved to the parent directory move the selection pointer to * the old directory name; If we leave VFS dir, remove FS specificator. @@ -949,7 +937,7 @@ _do_panel_cd (WPanel *panel, char *new_dir, enum cd_enum cd_type) struct vfs_stamping *parent; #endif olddir = strdup (panel->cwd); - translated_url = new_dir = translate_url_to_new_syntax (new_dir); + translated_url = new_dir = vfs_translate_url (new_dir); /* Convert *new_path to a suitable pathname, handle ~user */ @@ -1463,7 +1451,7 @@ translated_mc_chdir (char *dir) { char *newdir; - newdir = translate_url_to_new_syntax (dir); + newdir = vfs_translate_url (dir); mc_chdir (newdir); free (newdir); } diff --git a/src/screen.c b/src/screen.c index cdbeaa27d..55ee1c6b6 100644 --- a/src/screen.c +++ b/src/screen.c @@ -2053,13 +2053,17 @@ do_enter (WPanel *panel) free (cmd); } #ifdef USE_VFS - else if (vfs_current_is_extfs ()) { - char *tmp = vfs_get_current_dir(); - char *tmp2; + else { + /* if (vfs_current_is_extfs ()) - I see no reason why + filesystems other than extfs could not implement same + call... -- pavel@ucw.cz*/ + char *tmp; - tmp2 = concat_dir_and_file (tmp, selection (panel)->fname); - extfs_run(tmp2); - free (tmp2); + tmp = concat_dir_and_file (vfs_get_current_dir(), selection (panel)->fname); + if (!mc_setctl (tmp, MCCTL_EXTFS_RUN, NULL)) + message (1, _(" Warning "), _(" No action taken ")); + + free (tmp); } #endif /* USE_VFS */ return 1; @@ -2290,7 +2294,7 @@ panel_callback (Dlg_head *h, WPanel *panel, int msg, int par) #endif panel->active = 1; if (mc_chdir (panel->cwd) != 0){ - message (1, " Error ", " Can't chdir to %s \n %s ", + message (1, _(" Error "), _(" Can't chdir to %s \n %s "), panel->cwd, unix_error_string (errno)); } else subshell_chdir (panel->cwd); diff --git a/vfs/ChangeLog b/vfs/ChangeLog index 7af90a73f..3d85343ef 100644 --- a/vfs/ChangeLog +++ b/vfs/ChangeLog @@ -1,3 +1,28 @@ +Mon Oct 12 22:42:30 1998 Pavel Machek + + * sfs.c: reuse mmap from local.c + + * ftpfs.c, fish.c, shared_ftp_fish.c: horrible reget hack removed, + and replaced with open(,O_LINEAR); lseek() combination + +Sun Oct 11 01:44:37 1998 Pavel Machek + + * mcfs.c (open_tcp_link): Moved: it used to be in utilvfs.c, but + as it deals with portmapper, it is probably usefull for mcfs + + * vfs.h (MCERR_*): these are no longer needed + + * vfs.c (vfs_translate_url): translating of url's moved to vfs + code + + * all around: trying to reduce namespace pollution. All special + functions (like extfs_run) should be done using mc_setctl() + interface. At the end, all non-static functions in vfs layer + should begin with vfs_ and should be declared in vfs.h (however + that goal is far away). + + * all over the code: replace X_vfs_ops to vfs_X_ops + Mon Oct 5 20:11:01 1998 Pavel Machek * vfs.c: added stat to avoid hiding files by naming them diff --git a/vfs/extfs.c b/vfs/extfs.c index eddc2dcd6..a2f2f6c99 100644 --- a/vfs/extfs.c +++ b/vfs/extfs.c @@ -18,6 +18,8 @@ License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +/* Namespace: exports only vfs_extfs_ops */ + #include #include #include @@ -42,7 +44,6 @@ #include "../src/mem.h" #include "../src/mad.h" #include "../src/main.h" /* For shell_execute */ -#define WANT_PARSE_LS_LGA #include "vfs.h" #include "extfs.h" @@ -61,7 +62,7 @@ static char *extfs_prefixes [MAXEXTFS]; static char extfs_need_archive [MAXEXTFS]; static int extfs_no = 0; -void extfs_fill_names (vfs *me, void (*func)(char *)) +static void extfs_fill_names (vfs *me, void (*func)(char *)) { struct archive *a = first_archive; char *name; @@ -261,7 +262,7 @@ static FILE *open_archive (int fstype, char *name, struct archive **pparc) * Main loop for reading an archive. * Returns 0 on success, -1 on error. */ -int read_archive (int fstype, char *name, struct archive **pparc) +static int read_archive (int fstype, char *name, struct archive **pparc) { FILE *extfsd; char *buffer; @@ -276,7 +277,7 @@ int read_archive (int fstype, char *name, struct archive **pparc) buffer = xmalloc (4096, "Extfs: buffer"); while (fgets (buffer, 4096, extfsd) != NULL) { current_link_name = NULL; - if (parse_ls_lga (buffer, &hstat, ¤t_file_name, ¤t_link_name)) { + if (vfs_parse_ls_lga (buffer, &hstat, ¤t_file_name, ¤t_link_name)) { struct entry *entry, *pent; struct inode *inode; char *p, *q, *cfn = current_file_name; @@ -421,7 +422,7 @@ static char *get_path_mangle (char *inname, struct archive **archive, int is_dir /* This is not too secure - in some cases (/#mtools) files created under user a are probably visible to everyone else since / usually has permissions 755 */ - vfs_stamp (&extfs_vfs_ops, (vfsid) parc); + vfs_stamp (&vfs_extfs_ops, (vfsid) parc); goto return_success; } } @@ -431,7 +432,7 @@ static char *get_path_mangle (char *inname, struct archive **archive, int is_dir if (archive_name){ v = vfs_type (archive_name); - if (v == &local_vfs_ops) { + if (v == &vfs_local_ops) { parent = NULL; } else { parent = xmalloc (sizeof (struct vfs_stamping), "vfs stamping"); @@ -439,7 +440,7 @@ static char *get_path_mangle (char *inname, struct archive **archive, int is_dir parent->next = 0; parent->id = (*v->getid) (v, archive_name, &(parent->parent)); } - vfs_add_noncurrent_stamps (&extfs_vfs_ops, (vfsid) parc, parent); + vfs_add_noncurrent_stamps (&vfs_extfs_ops, (vfsid) parc, parent); vfs_rm_parents (parent); } return_success: @@ -554,6 +555,9 @@ static char *get_archive_name (struct archive *archive) return archive_name; } +/* FIXME: we really should not have non-static procedures - it + * pollutes namespace. */ + void extfs_run (char *file) { struct archive *archive; @@ -634,7 +638,7 @@ static void *extfs_open (vfs *me, char *file, int flags, int mode) extfs_info->local_handle = local_handle; /* i.e. we had no open files and now we have one */ - vfs_rmstamp (&extfs_vfs_ops, (vfsid) archive, 1); + vfs_rmstamp (&vfs_extfs_ops, (vfsid) archive, 1); archive->fd_usage++; return extfs_info; } @@ -695,7 +699,7 @@ static int extfs_close (void *data) struct vfs_stamping *parent; vfs *v; - if (!file->archive->name || !*file->archive->name || (v = vfs_type (file->archive->name)) == &local_vfs_ops) { + if (!file->archive->name || !*file->archive->name || (v = vfs_type (file->archive->name)) == &vfs_local_ops) { parent = NULL; } else { parent = xmalloc (sizeof (struct vfs_stamping), "vfs stamping"); @@ -703,7 +707,7 @@ static int extfs_close (void *data) parent->next = 0; parent->id = (*v->getid) (v, file->archive->name, &(parent->parent)); } - vfs_add_noncurrent_stamps (&extfs_vfs_ops, (vfsid) (file->archive), parent); + vfs_add_noncurrent_stamps (&vfs_extfs_ops, (vfsid) (file->archive), parent); vfs_rm_parents (parent); } @@ -939,11 +943,6 @@ static int extfs_which (vfs *me, char *path) return -1; } -static char *extfs_get_prefix (int idx) -{ - return extfs_prefixes [idx]; -} - static void extfs_done (vfs *me) { int i; @@ -956,7 +955,16 @@ static void extfs_done (vfs *me) extfs_current_dir = 0; } -vfs extfs_vfs_ops = { +static int extfs_setctl (vfs *me, char *path, int ctlop, char *arg) +{ + if (ctlop == MCCTL_EXTFS_RUN) { + extfs_run (path); + return 1; + } + return 0; +} + +vfs vfs_extfs_ops = { NULL, /* This is place of next pointer */ "Extended filesystems", F_EXEC, /* flags */ @@ -1009,7 +1017,7 @@ vfs extfs_vfs_ops = { NULL, /* mkdir */ NULL, NULL, - NULL + extfs_setctl MMAPNULL }; diff --git a/vfs/extfs.h b/vfs/extfs.h index fc620c9db..4d179bb07 100644 --- a/vfs/extfs.h +++ b/vfs/extfs.h @@ -67,8 +67,4 @@ struct archive { struct archive *next; }; -char *extfs_get_prefix (int fstype); -char *extfs_analysis (char *path, char **arc_name, int *fstype, int is_dir); -void extfs_run (char *path); - typedef struct archive extfs_archive; /* Do _not_ use this inside extfs.c */ diff --git a/vfs/extfs/unarj.diff b/vfs/extfs/unarj.diff new file mode 100644 index 000000000..95a7c126e --- /dev/null +++ b/vfs/extfs/unarj.diff @@ -0,0 +1,128 @@ +Only in unarj241a/: unarj +diff -ur -x .dep* -x .hdep* -x *.[oas] -x *~ -x #* -x *CVS* -x *.orig -x *.rej -x *.old -x .menu* -x asm -x local.h -x System.map -x autoconf.h -x compile.h -x version.h -x .version -x defkeymap.c -x uni_hash.tbl -x zImage -x vmlinu?* -x TAGS -x bootsect -x *RCS* -x conmakehash -x map -x build -x build -x configure -x *target* /elf/tmp/unarj241a.tar.gz#utar/unarj241a/unarj.c unarj241a/unarj.c +--- /elf/tmp/unarj241a.tar.gz#utar/unarj241a/unarj.c Sun Apr 10 11:00:56 1994 ++++ unarj241a/unarj.c Mon Mar 16 21:00:47 1998 +@@ -40,7 +40,8 @@ + * 11/24/91 R. Jung Added more error_count processing. + * 12/03/91 R. Jung Added backup file processing. + * 02/17/93 R. Jung Added archive modified date support. +- * 940410 aeb@cwi.nl Added automatic directory creation for x mode. ++ * 04/10/94 aeb@cwi.nl Added automatic directory creation for x mode. ++ * 02/16/98 pavel@ucw.cz Added v mode, added p mode. THIS IS MODIFIED VERSION. + * + */ + +@@ -88,6 +89,7 @@ + uchar header[HEADERSIZE_MAX]; + char arc_name[FNAME_MAX]; + int command; ++char *file_to_extract; + int bitcount; + int file_type; + int no_output; +@@ -102,6 +104,10 @@ + " UNARJ l archive (list archive)\n", + " UNARJ t archive (test archive)\n", + " UNARJ x archive (extract with pathnames)\n", ++" UNARJ v archive (list archive with pathnames)\n", ++" UNARJ p archive file (print single file from archive to stderr)\n", ++"\n", ++"Warning, this version has been modified by pavel@ucw.cz.\n" + "\n", + "This is an ARJ demonstration program and ** IS NOT OPTIMIZED ** for speed.\n", + "You may freely use, copy and distribute this program, provided that no fee\n", +@@ -744,15 +750,24 @@ + if (command == 'E') + strcpy(name, &filename[entry_pos]); + else +- { +- strcpy(name, DEFAULT_DIR); +- strcat(name, filename); +- } ++ if (command == 'X') ++ { ++ strcpy(name, DEFAULT_DIR); ++ strcat(name, filename); ++ } ++ else ++ if (strcmp( &filename[entry_pos], file_to_extract )) ++ { ++ skip(); ++ return 0; ++ } ++ else ++ strcpy( name, "stderr" ); + + if (host_os != OS) + default_case_path(name); + +- if (file_exists(name)) ++ if ((command != 'P') && file_exists(name)) + { + printf(M_FEXISTS, name); + printf(M_SKIPPED, name); +@@ -764,7 +779,10 @@ + if (command == 'X') + create_required_dirs(name); + #endif +- outfile = file_open(name, writemode[file_type & 1]); ++ if (command != 'P') ++ outfile = file_open(name, writemode[file_type & 1]); ++ else ++ outfile = stderr; + if (outfile == NULL) + { + printf(M_CANTOPEN, name); +@@ -890,8 +908,11 @@ + strcpy(fmode_str, " "); + if (host_os == OS) + get_mode_str(fmode_str, (uint) file_mode); +- if (strlen(&filename[entry_pos]) > 12) +- printf("%-12s\n ", &filename[entry_pos]); ++ if ((strlen(&filename[entry_pos]) > 12) || (command == 'V')) ++ if (command != 'V') ++ printf("%-12s\n ", &filename[entry_pos]); ++ else ++ printf("%s\n ", filename); + else + printf("%-12s ", &filename[entry_pos]); + printf("%10ld %10ld %u.%03u %s %08lX %4s%c%c%c%u%c%c%c\n", +@@ -935,11 +956,13 @@ + { + switch (command) + { ++ case 'P': + case 'E': + case 'X': + if (extract()) + file_count++; + break; ++ case 'V': + case 'L': + list_arc(file_count++); + skip(); +@@ -1002,14 +1025,20 @@ + if (strlen(argv[1]) > 1) + error(M_BADCOMND, argv[1]); + command = toupper(*argv[1]); +- if (strchr("ELTX", command) == NULL) ++ if (strchr("ELTXV", command) == NULL) + error(M_BADCOMND, argv[1]); + arc_p = argv[2]; + } + else + { +- help(); +- return EXIT_FAILURE; ++ command = toupper(*argv[1]); ++ if ((command!='P') || (argc != 4)) ++ { ++ help(); ++ return EXIT_FAILURE; ++ } ++ file_to_extract = argv[3]; ++ arc_p = argv[2]; + } + + strncopy(arc_name, arc_p, FNAME_MAX); +Only in unarj241a/: unarj.c.diff-right diff --git a/vfs/fish.c b/vfs/fish.c index 023346db5..da17cb23a 100644 --- a/vfs/fish.c +++ b/vfs/fish.c @@ -27,6 +27,8 @@ * Syntax of path is: /#sh:user@host[:Cr]/path * where C means you want compressed connection, * and r means you want to use rsh + * + * Namespace: fish_vfs_ops exported. */ #include @@ -63,7 +65,6 @@ #include #include "../src/mem.h" -#define WANT_PARSE_LS_LGA #include "vfs.h" #include "tcputil.h" #include "../src/util.h" @@ -111,7 +112,7 @@ static char *get_path (struct connection **bucket, char *path); static char *my_get_host_and_username (char *path, char **host, char **user, int *flags, char **pass) { - return get_host_and_username (path, host, user, flags, 0, 0, pass); + return vfs_get_host_and_username (path, host, user, flags, 0, 0, pass); } static int decode_reply (char *s, int was_garbage) @@ -369,7 +370,7 @@ static void my_forget (char *path) #define X "fish" #define X_myname "/#sh:" -#define X_vfs_ops fish_vfs_ops +#define vfs_X_ops vfs_fish_ops #define X_fill_names fish_fill_names #define X_hint_reread fish_hint_reread #define X_flushdir fish_flushdir @@ -500,17 +501,17 @@ retrieve_dir(struct connection *bucket, char *remote_path, int resolve_symlinks) case 'S': fe->s.st_size = atoi(buffer+1); break; case 'P': { int i; - if ((i = parse_filetype(buffer[1])) ==-1) + if ((i = vfs_parse_filetype(buffer[1])) ==-1) break; fe->s.st_mode = i; - if ((i = parse_filemode(buffer+2)) ==-1) + if ((i = vfs_parse_filemode(buffer+2)) ==-1) break; fe->s.st_mode |= i; } break; case 'd': { - split_text(buffer+1); - if (!parse_filedate(0, &fe->s.st_ctime)) + vfs_split_text(buffer+1); + if (!vfs_parse_filedate(0, &fe->s.st_ctime)) break; fe->s.st_atime = fe->s.st_mtime = fe->s.st_ctime; } @@ -633,14 +634,16 @@ error_return: return 0; } -static int linear_start(struct direntry *fe) +static int linear_start(struct direntry *fe, int offset) { + if (offset) + ERRNOR (EOPNOTSUPP, 0); fe->local_stat.st_mtime = 0; if (command(fe->bucket, WANT_STRING, "#RETR %s\nls -l %s | ( read var1 var2 var3 var4 var5 var6; echo $var5 ); echo '### 100'; cat %s; echo '### 200'\n", fe->remote_filename, fe->remote_filename, fe->remote_filename ) != PRELIM) ERRNOR (EACCES, 0); - + fe->linear_state = LS_LINEAR_OPEN; fe->got = 0; fe->total = atoi(reply_str); return 1; @@ -691,14 +694,21 @@ linear_close (struct direntry *fe) linear_abort(fe); } -int fish_ctl (void *data, int ctlop, int arg) +static int +fish_ctl (void *data, int ctlop, int arg) { struct filp *fp = data; switch (ctlop) { case MCCTL_IS_NOTREADY: { - int v = select_on_two (qsockr(fp->fe->bucket), 0); - + int v; + + if (!fp->fe->linear_state) + vfs_die ("You may not do this"); + if (fp->fe->linear_state == LS_LINEAR_CLOSED) + return 0; + + v = select_on_two (qsockr(fp->fe->bucket), 0); if (((v < 0) && (errno == EINTR)) || v == 0) return 1; return 0; @@ -715,14 +725,14 @@ send_fish_command(struct connection *bucket, char *cmd, int flags) int flush_directory_cache = (flags & OPT_FLUSH) && (normal_flush > 0); r = command (bucket, WAIT_REPLY, cmd); - vfs_add_noncurrent_stamps (&fish_vfs_ops, (vfsid) bucket, NULL); + vfs_add_noncurrent_stamps (&vfs_fish_ops, (vfsid) bucket, NULL); if (r != COMPLETE) ERRNOR (EPERM, -1); if (flush_directory_cache) flush_all_directory(bucket); return 0; } -int +static int fish_init (vfs *me) { connections_list = linklist_init(); @@ -743,7 +753,8 @@ fish_init (vfs *me) free(remote_path); \ return send_fish_command(bucket, buf, flags); -int fish_chmod (vfs *me, char *path, int mode) +static int +fish_chmod (vfs *me, char *path, int mode) { PREFIX sprintf(buf, "#CHMOD %4.4o %s\nchmod %4.4o %s; echo '### 000'\n", @@ -753,7 +764,7 @@ int fish_chmod (vfs *me, char *path, int mode) } #define FISH_OP(name, chk, string) \ -int fish_##name (vfs *me, char *path1, char *path2) \ +static int fish_##name (vfs *me, char *path1, char *path2) \ { \ char buf[120]; \ char *remote_path1 = NULL, *remote_path2 = NULL; \ @@ -775,7 +786,8 @@ FISH_OP(rename, XTEST, "#RENAME %s %s\nmv %s %s; echo '*** 000'" ); FISH_OP(link, XTEST, "#LINK %s %s\nln %s %s; echo '*** 000'" ); FISH_OP(symlink, , "#SYMLINK %s %s\nln -s %s %s; echo '*** 000'" ); -int fish_chown (vfs *me, char *path, int owner, int group) +static int +fish_chown (vfs *me, char *path, int owner, int group) { char *sowner, *sgroup; PREFIX @@ -814,7 +826,7 @@ static int fish_rmdir (vfs *me, char *path) POSTFIX(OPT_FLUSH); } -vfs fish_vfs_ops = { +vfs vfs_fish_ops = { NULL, /* This is place of next pointer */ "FIles tranferred over SHell", F_EXEC, /* flags */ @@ -867,8 +879,6 @@ vfs fish_vfs_ops = { fish_rmdir, fish_ctl, s_setctl -#ifdef HAVE_MMAP - , NULL, - NULL -#endif + +MMAPNULL }; diff --git a/vfs/fish.h b/vfs/fish.h index 9af85d0c4..47cb816d5 100644 --- a/vfs/fish.h +++ b/vfs/fish.h @@ -11,16 +11,17 @@ struct direntry char *local_filename; int local_is_temp:1; int freshly_created:1; - int linear:1; struct stat local_stat; char *remote_filename; struct stat s; struct stat *l_stat; struct connection *bucket; - int tmp_reget; - int got, total; /* Bytes transfered / bytes need to be transfered */ + int linear_state; +#define LS_NONLIN 0 /* Not using linear access at all */ +#define LS_LINEAR_CLOSED 1 /* Using linear access, but not open, yet */ +#define LS_LINEAR_OPEN 2 /* Using linear access, open */ }; struct dir diff --git a/vfs/ftpfs.c b/vfs/ftpfs.c index 4cec353f1..f9b62f1e2 100644 --- a/vfs/ftpfs.c +++ b/vfs/ftpfs.c @@ -31,6 +31,8 @@ - use hash table instead of linklist to cache ftpfs directory. */ +/* Namespace pollution: horrible */ + #include #include #include @@ -77,7 +79,6 @@ #endif #include "../src/mem.h" -#define WANT_PARSE_LS_LGA #include "vfs.h" #include "tcputil.h" #include "../src/util.h" @@ -118,9 +119,6 @@ int ftpfs_directory_timeout; /* Proxy host */ char *ftpfs_proxy_host = 0; -/* Reget flag */ -int do_reget = 0; - /* wether we have to use proxy by default? */ int ftpfs_always_use_proxy; @@ -163,7 +161,7 @@ static char *get_path (struct connection **bucket, char *path); static char *my_get_host_and_username (char *path, char **host, char **user, int *port, char **pass) { - return get_host_and_username (path, host, user, port, 21, 1, pass); + return vfs_get_host_and_username (path, host, user, port, 21, 1, pass); } /* Returns a reply code, check /usr/include/arpa/ftp.h for possible values */ @@ -572,11 +570,11 @@ ftpfs_get_proxy_host_and_port (char *proxy, char **host, int *port) #if defined(HSC_PROXY) #define HSC_DEFAULT_PORT 9875 - dir = get_host_and_username(proxy, host, &user, port, HSC_DEFAULT_PORT, 1, - &pass); + dir = vfs_get_host_and_username(proxy, host, &user, port, HSC_DEFAULT_PORT, 1, + &pass); #else - dir = get_host_and_username(proxy, host, &user, port, 21, 1, - &pass); + dir = vfs_get_host_and_username(proxy, host, &user, port, 21, 1, + &pass); #endif free(user); if (pass) @@ -957,7 +955,7 @@ error_return: static int open_data_connection (struct connection *bucket, char *cmd, char *remote, - int isbinary) + int isbinary, int reget) { struct sockaddr_in from; int s, j, data, fromlen = sizeof(from); @@ -966,9 +964,8 @@ open_data_connection (struct connection *bucket, char *cmd, char *remote, return -1; if (changetype (bucket, isbinary) == -1) return -1; - if (do_reget > 0){ - j = command (bucket, WAIT_REPLY, "REST %d", do_reget); - do_reget = 0; + if (reget > 0){ + j = command (bucket, WAIT_REPLY, "REST %d", reget); if (j != CONTINUE) return -1; } @@ -1085,7 +1082,7 @@ resolve_symlink(struct connection *bucket, struct dir *dir) #define X "ftp" #define X_myname "/#ftp:" -#define X_vfs_ops ftpfs_vfs_ops +#define vfs_X_ops vfs_ftpfs_ops #define X_fill_names ftpfs_fill_names #define X_hint_reread ftpfs_hint_reread #define X_flushdir ftpfs_flushdir @@ -1166,12 +1163,12 @@ retrieve_dir(struct connection *bucket, char *remote_path, int resolve_symlinks) dcache->symlink_status = FTPFS_NO_SYMLINKS; if (bucket->strict_rfc959_list_cmd == 1) - sock = open_data_connection (bucket, "LIST", 0, TYPE_ASCII); + sock = open_data_connection (bucket, "LIST", 0, TYPE_ASCII, 0); else if (has_spaces) - sock = open_data_connection (bucket, "LIST -la", ".", TYPE_ASCII); + sock = open_data_connection (bucket, "LIST -la", ".", TYPE_ASCII, 0); else { char *path = copy_strings (remote_path, PATH_SEP_STR, ".", (char *) 0); - sock = open_data_connection (bucket, "LIST -la", path, TYPE_ASCII); + sock = open_data_connection (bucket, "LIST -la", path, TYPE_ASCII, 0); free (path); } @@ -1212,13 +1209,12 @@ retrieve_dir(struct connection *bucket, char *remote_path, int resolve_symlinks) break; fe = xmalloc(sizeof(struct direntry), "struct direntry"); fe->freshly_created = 0; - fe->tmp_reget = 0; fe->local_filename = NULL; if (fe == NULL) { my_errno = ENOMEM; goto error_1; } - if (parse_ls_lga (buffer, &fe->s, &fe->name, &fe->linkname)) { + if (vfs_parse_ls_lga (buffer, &fe->s, &fe->name, &fe->linkname)) { fe->count = 1; fe->local_filename = fe->remote_filename = NULL; fe->l_stat = NULL; @@ -1312,7 +1308,7 @@ store_file(struct direntry *fe) unlink (fe->local_filename); if (local_handle == -1) ERRNOR (EIO, 0); fstat(local_handle, &s); - sock = open_data_connection(fe->bucket, "STOR", fe->remote_filename, TYPE_BINARY); + sock = open_data_connection(fe->bucket, "STOR", fe->remote_filename, TYPE_BINARY, 0); if (sock < 0) { close(local_handle); return 0; @@ -1372,12 +1368,13 @@ error_return: } static int -linear_start(struct direntry *fe) +linear_start(struct direntry *fe, int offset) { fe->local_stat.st_mtime = 0; - fe->data_sock = open_data_connection(fe->bucket, "RETR", fe->remote_filename, TYPE_BINARY); + fe->data_sock = open_data_connection(fe->bucket, "RETR", fe->remote_filename, TYPE_BINARY, offset); if (fe->data_sock == -1) ERRNOR (EACCES, 0); + fe->linear_state = LS_LINEAR_OPEN; return 1; } @@ -1423,8 +1420,14 @@ int ftpfs_ctl (void *data, int ctlop, int arg) switch (ctlop) { case MCCTL_IS_NOTREADY: { - int v = select_on_two (fp->fe->data_sock, 0); + int v; + if (!fp->fe->linear_state) + vfs_die ("You may not do this"); + if (fp->fe->linear_state == LS_LINEAR_CLOSED) + return 0; + + v = select_on_two (fp->fe->data_sock, 0); if (((v < 0) && (errno == EINTR)) || v == 0) return 1; return 0; @@ -1446,7 +1449,7 @@ send_ftp_command(char *filename, char *cmd, int flags) return -1; r = command (bucket, WAIT_REPLY, cmd, remote_path); free(remote_path); - vfs_add_noncurrent_stamps (&ftpfs_vfs_ops, (vfsid) bucket, NULL); + vfs_add_noncurrent_stamps (&vfs_ftpfs_ops, (vfsid) bucket, NULL); if (flags & OPT_IGNORE_ERROR) r = COMPLETE; if (r != COMPLETE) ERRNOR (EPERM, -1); @@ -1488,7 +1491,7 @@ ftpfs_init (vfs *me) return 1; } -int ftpfs_chmod (vfs *me, char *path, int mode) +static int ftpfs_chmod (vfs *me, char *path, int mode) { char buf[40]; @@ -1496,7 +1499,7 @@ int ftpfs_chmod (vfs *me, char *path, int mode) return send_ftp_command(path, buf, OPT_IGNORE_ERROR | OPT_FLUSH); } -int ftpfs_chown (vfs *me, char *path, int owner, int group) +static int ftpfs_chown (vfs *me, char *path, int owner, int group) { #if 0 my_errno = EPERM; @@ -1615,7 +1618,7 @@ static void my_forget (char *file) wipe_password (pass); } -vfs ftpfs_vfs_ops = { +vfs vfs_ftpfs_ops = { NULL, /* This is place of next pointer */ "File Tranfer Protocol (ftp)", F_NET, /* flags */ @@ -1668,10 +1671,8 @@ vfs ftpfs_vfs_ops = { ftpfs_rmdir, ftpfs_ctl, s_setctl -#ifdef HAVE_MMAP - , NULL, - NULL -#endif + +MMAPNULL }; #ifdef USE_NETRC diff --git a/vfs/ftpfs.h b/vfs/ftpfs.h index 58358a06e..061d97f31 100644 --- a/vfs/ftpfs.h +++ b/vfs/ftpfs.h @@ -11,14 +11,16 @@ struct direntry char *local_filename, *remote_filename; int local_is_temp:1; int freshly_created:1; - int linear:1; /* Did they promiss not to seek? */ - int tmp_reget; struct stat local_stat; struct stat s; struct stat *l_stat; struct connection *bucket; int data_sock; /* For linear_ operations */ + int linear_state; +#define LS_NONLIN 0 /* Not using linear access at all */ +#define LS_LINEAR_CLOSED 1 /* Using linear access, but not open, yet */ +#define LS_LINEAR_OPEN 2 /* Using linear access, open */ }; struct dir diff --git a/vfs/local.c b/vfs/local.c index ac92e0151..ed026e2b0 100644 --- a/vfs/local.c +++ b/vfs/local.c @@ -241,14 +241,14 @@ static void local_ungetlocalcopy (vfs *me, char *path, char *local, int has_chan } #ifdef HAVE_MMAP -static caddr_t local_mmap (vfs *me, caddr_t addr, size_t len, int prot, int flags, void *data, off_t offset) +caddr_t local_mmap (vfs *me, caddr_t addr, size_t len, int prot, int flags, void *data, off_t offset) { int fd = * (int *)data; return mmap (addr, len, prot, flags, fd, offset); } -static int local_munmap (vfs *me, caddr_t addr, size_t len, void *data) +int local_munmap (vfs *me, caddr_t addr, size_t len, void *data) { return munmap (addr, len); } @@ -259,7 +259,7 @@ static int local_which(vfs *me, char *path) return 0; /* Every path which other systems do not like is expected to be ours */ } -vfs local_vfs_ops = { +vfs vfs_local_ops = { NULL, /* This is place of next pointer */ "Local filesystem", 0, /* flags */ diff --git a/vfs/mcfs.c b/vfs/mcfs.c index b6508fb5e..0cc3b5cc1 100644 --- a/vfs/mcfs.c +++ b/vfs/mcfs.c @@ -20,6 +20,8 @@ License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +/* Namespace: exports mcfs_vfs_ops, tcp_invalidate_socket */ + #include #include #include @@ -55,7 +57,7 @@ #define mcserver_port 9876 static mcfs_open_connections = 0; -struct _mcfs_connection { +static struct _mcfs_connection { char *host; char *user; char *home; @@ -68,22 +70,19 @@ typedef struct _mcfs_connection mcfs_connection; typedef struct { int handle; mcfs_connection *conn; } mcfs_handle; -static int mcfs_errno_var; -static mcfs_connection *current_dir_connection; - -char *mcfs_current_dir = 0; +static int my_errno; static char *mcfs_gethome (mcfs_connection *mc); /* Extract the hostname and username from the path */ /* path is in the form: hostname:user/remote-dir */ -char *mcfs_get_host_and_username (char *path, char **host, char **user, +static char *mcfs_get_host_and_username (char *path, char **host, char **user, int *port, char **pass) { - return get_host_and_username (path, host, user, port, 0, 0, pass); + return vfs_get_host_and_username (path, host, user, port, 0, 0, pass); } -void mcfs_fill_names (vfs *me, void (*func)(char *)) +static void mcfs_fill_names (vfs *me, void (*func)(char *)) { int i; char *name; @@ -98,7 +97,7 @@ void mcfs_fill_names (vfs *me, void (*func)(char *)) } } -void mcfs_free_bucket (int bucket) +static void mcfs_free_bucket (int bucket) { free (mcfs_connections [bucket].host); free (mcfs_connections [bucket].user); @@ -113,7 +112,7 @@ void mcfs_free_bucket (int bucket) } /* FIXME: This part should go to another c module, perhaps tcp.c */ -int mcfs_invalidate_socket (int); +static int mcfs_invalidate_socket (int); void tcp_invalidate_socket (int sock) { @@ -121,7 +120,7 @@ void tcp_invalidate_socket (int sock) } /* FIXME end: 'cause it is used not only by mcfs */ -int mcfs_invalidate_socket (int sock) +static int mcfs_invalidate_socket (int sock) { int i, j = -1; extern int mc_chdir (char *); @@ -210,6 +209,59 @@ static int mcfs_login_server (int my_socket, char *user, int port, return my_socket; } +/* This used to be in utilvfs.c, but as it deals with portmapper, it + is probably usefull for mcfs */ +static int open_tcp_link (char *host, int *port, int *version, char *caller) +{ + struct sockaddr_in server_address; + unsigned long inaddr; + struct hostent *hp; + int my_socket; + + if (!*host) + return 0; + + bzero ((char *) &server_address, sizeof (server_address)); + server_address.sin_family = AF_INET; + + /* Try to use the dotted decimal number */ + if ((inaddr = inet_addr (host)) != -1) + bcopy ((char *) &inaddr, (char *) &server_address.sin_addr, + sizeof (inaddr)); + else { + if ((hp = gethostbyname (host)) == NULL){ + message_2s (1, caller, " Can't locate hostname: %s ", host); + return 0; + } + bcopy ((char *) hp->h_addr, (char *) &server_address.sin_addr, + hp->h_length); + } + + /* Try to contact a remote portmapper to obtain the listening port */ + if (*port == 0){ + *port = get_remote_port (&server_address, version); + if (*port < 1) + return 0; + } else + *version = 1; + + server_address.sin_port = htons (*port); + + if ((my_socket = socket (AF_INET, SOCK_STREAM, 0)) < 0){ + message_2s (1, caller, " Can't create socket: %s ", + unix_error_string(errno)); + return 0; + } + if (connect (my_socket, (struct sockaddr *) &server_address, + sizeof (server_address)) < 0){ + message_2s (1, caller, " Can't connect to server: %s ", + unix_error_string (errno)); + close (my_socket); + return 0; + } + return my_socket; +} + static int mcfs_open_tcp_link (char *host, char *user, int *port, char *netrcpass, int *version) { @@ -289,18 +341,18 @@ static mcfs_connection *mcfs_open_link (char *host, char *user, int *port, char static int is_error (int result, int errno_num) { if (!(result == -1)) - return mcfs_errno_var = 0; + return my_errno = 0; else - mcfs_errno_var = errno_num; + my_errno = errno_num; return 1; } static int the_error (int result, int errno_num) { if (result == -1) - mcfs_errno_var = errno_num; + my_errno = errno_num; else - mcfs_errno_var = 0; + my_errno = 0; return result; } @@ -313,7 +365,6 @@ static char *mcfs_get_path (mcfs_connection **mc, char *path) /* An absolute path name, try to determine connection socket */ if (strncmp (path, "/#mc:", 5)) { vfs_die( "Mcfs: this should not happen.\n" ); - /* We used to *mc = current_dir_connection; return strdup (path); */ } path += 5; @@ -507,7 +558,7 @@ static int mcfs_read (void *data, char *buffer, int count) return result; } -int mcfs_write (void *data, char *buf, int nbyte) +static int mcfs_write (void *data, char *buf, int nbyte) { mcfs_handle *info = (mcfs_handle *) data; mcfs_connection *mc; @@ -551,7 +602,7 @@ static int mcfs_close (void *data) static int mcfs_errno (vfs *me) { - return mcfs_errno_var; + return my_errno; } typedef struct dir_entry { @@ -654,7 +705,7 @@ static int mcfs_loaddir (opendir_info *mcfs_info) return 1; } -void mcfs_free_dir (dir_entry *de) +static void mcfs_free_dir (dir_entry *de) { if (!de) return; @@ -837,7 +888,7 @@ static int mcfs_lstat (vfs *me, char *path, struct stat *buf) return mcfs_stat_cmd (MC_LSTAT, path, buf); } -int mcfs_fstat (void *data, struct stat *buf) +static int mcfs_fstat (void *data, struct stat *buf) { mcfs_handle *info = (mcfs_handle *) data; int result, error; @@ -859,17 +910,17 @@ int mcfs_fstat (void *data, struct stat *buf) return the_error (-1, EIO); } -int mcfs_chmod (vfs *me, char *path, int mode) +static int mcfs_chmod (vfs *me, char *path, int mode) { return mcfs_rpc_path_int (MC_CHMOD, path, mode); } -int mcfs_chown (vfs *me, char *path, int owner, int group) +static int mcfs_chown (vfs *me, char *path, int owner, int group) { return mcfs_rpc_path_int_int (MC_CHOWN, path, owner, group); } -int mcfs_utime (vfs *me, char *path, struct utimbuf *times) +static int mcfs_utime (vfs *me, char *path, struct utimbuf *times) { mcfs_connection *mc; int status; @@ -927,17 +978,17 @@ static int mcfs_readlink (vfs *me, char *path, char *buf, int size) return strlen (buf); } -int mcfs_unlink (vfs *me, char *path) +static int mcfs_unlink (vfs *me, char *path) { return mcfs_rpc_path (MC_UNLINK, path); } -int mcfs_symlink (vfs *me, char *n1, char *n2) +static int mcfs_symlink (vfs *me, char *n1, char *n2) { return mcfs_rpc_two_paths (MC_SYMLINK, n1, n2); } -int mcfs_rename (vfs *me, char *a, char *b) +static int mcfs_rename (vfs *me, char *a, char *b) { return mcfs_rpc_two_paths (MC_RENAME, a, b); } @@ -951,12 +1002,6 @@ static int mcfs_chdir (vfs *me, char *path) if (!(remote_dir = mcfs_get_path (&mc, path))) return -1; - if (mcfs_current_dir) - free (mcfs_current_dir); - - mcfs_current_dir = strdup (path); - - current_dir_connection = mc; rpc_send (mc->sock, RPC_INT, MC_CHDIR, RPC_STRING, remote_dir, RPC_END); free (remote_dir); if (!rpc_get (mc->sock, RPC_INT, &status, RPC_INT, &error, RPC_END)) @@ -967,7 +1012,7 @@ static int mcfs_chdir (vfs *me, char *path) return 0; } -int mcfs_lseek (void *data, off_t offset, int whence) +static int mcfs_lseek (void *data, off_t offset, int whence) { mcfs_handle *info = (mcfs_handle *) data; int handle, sock; @@ -984,22 +1029,22 @@ int mcfs_lseek (void *data, off_t offset, int whence) return mcfs_handle_simple_error (sock, 1); } -int mcfs_mknod (vfs *me, char *path, int mode, int dev) +static int mcfs_mknod (vfs *me, char *path, int mode, int dev) { return mcfs_rpc_path_int_int (MC_MKNOD, path, mode, dev); } -int mcfs_mkdir (vfs *me, char *path, mode_t mode) +static int mcfs_mkdir (vfs *me, char *path, mode_t mode) { return mcfs_rpc_path_int (MC_MKDIR, path, mode); } -int mcfs_rmdir (vfs *me, char *path) +static int mcfs_rmdir (vfs *me, char *path) { return mcfs_rpc_path (MC_RMDIR, path); } -int mcfs_link (vfs *me, char *p1, char *p2) +static int mcfs_link (vfs *me, char *p1, char *p2) { return mcfs_rpc_two_paths (MC_LINK, p1, p2); } @@ -1077,7 +1122,7 @@ mcfs_setctl (vfs *me, char *path, int ctlop, char *arg) return 0; } -vfs mcfs_vfs_ops = { +vfs vfs_mcfs_ops = { NULL, /* This is place of next pointer */ "Midnight Commander's private remote filesystem", F_NET, /* flags */ @@ -1133,5 +1178,3 @@ vfs mcfs_vfs_ops = { MMAPNULL }; - -/* FIXME: should add mc_setctl() and make it call mcfs_forget */ diff --git a/vfs/mcfs.h b/vfs/mcfs.h index 42390336f..16f4ab3ac 100644 --- a/vfs/mcfs.h +++ b/vfs/mcfs.h @@ -47,5 +47,3 @@ enum { MC_PASS }; - -extern char *mcfs_current_dir; diff --git a/vfs/names.c b/vfs/names.c index e82354cc0..0f454d5e1 100644 --- a/vfs/names.c +++ b/vfs/names.c @@ -13,6 +13,7 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. + * Namespace: finduname, finduid, findgname, findgid. */ /* diff --git a/vfs/sfs.c b/vfs/sfs.c index 1627245c5..ae4742fb9 100644 --- a/vfs/sfs.c +++ b/vfs/sfs.c @@ -6,6 +6,8 @@ * This defines whole class of filesystems which contain single file * inside. It is somehow similar to extfs, except that extfs makes * whole virtual trees and we do only single virtual files. + * + * Namespace: exports vfs_sfs_ops, shell (FIXME) */ #include @@ -24,6 +26,7 @@ #include "vfs.h" +/* This is needed, or libvfs.so will lack symbol shell. Should look up who requires it */ char *shell = "/bin/sh"; struct cachedfile { @@ -87,7 +90,7 @@ static int vfmake( vfs *me, char *name, char *cache ) } free( name ); - if (my_system (EXECUTE_AS_SHELL | EXECUTE_SETUID, shell, pad)) { + if (my_system (EXECUTE_AS_SHELL | EXECUTE_SETUID, "/bin/sh", pad)) { return -1; } @@ -107,7 +110,7 @@ static char *redirect( vfs *me, char *name ) (uptodate( cur->name, cur->cache ))) /* FIXME: when not uptodate, we might want to kill cache * file immediately, not to wait until timeout. */ { - vfs_stamp( &sfs_vfs_ops, cur ); + vfs_stamp( &vfs_sfs_ops, cur ); return cur->cache; } cur = cur->next; @@ -122,7 +125,7 @@ static char *redirect( vfs *me, char *name ) cur->next = head; head = cur; - vfs_add_noncurrent_stamps (&sfs_vfs_ops, (vfsid) head, NULL); + vfs_add_noncurrent_stamps (&vfs_sfs_ops, (vfsid) head, NULL); vfs_rm_parents (NULL); return cache; @@ -268,25 +271,15 @@ static void sfs_ungetlocalcopy (vfs *me, char *path, char *local, int has_change { } -#ifdef HAVE_MMAP -static caddr_t sfs_mmap (vfs *me, caddr_t addr, size_t len, int prot, int flags, void *data, off_t offset) -{ - int fd = * (int *)data; - - return mmap (addr, len, prot, flags, fd, offset); -} - -static int sfs_munmap (vfs *me, caddr_t addr, size_t len, void *data) -{ - return munmap (addr, len); -} -#endif - extern int local_close (void *data); extern int local_read (void *data, char *buffer, int count); extern int local_fstat (void *data, struct stat *buf); extern int local_errno (vfs *me); extern int local_lseek (void *data, off_t offset, int whence); +#ifdef HAVE_MMAP +extern caddr_t local_mmap (vfs *me, caddr_t addr, size_t len, int prot, int flags, void *data, off_t offset); +extern int local_munmap (vfs *me, caddr_t addr, size_t len, void *data); +#endif static int sfs_init (vfs *me) { @@ -369,7 +362,7 @@ static int sfs_which (vfs *me, char *path) return -1; } -vfs sfs_vfs_ops = { +vfs vfs_sfs_ops = { NULL, /* This is place of next pointer */ "Signle file filesystems", F_EXEC, /* flags */ @@ -420,12 +413,12 @@ vfs sfs_vfs_ops = { NULL, NULL, - NULL, NULL + #ifdef HAVE_MMAP - ,sfs_mmap, - sfs_munmap + ,local_mmap, + local_munmap #endif }; diff --git a/vfs/shared_ftp_fish.c b/vfs/shared_ftp_fish.c index 45cb1b163..be2a1e597 100644 --- a/vfs/shared_ftp_fish.c +++ b/vfs/shared_ftp_fish.c @@ -1,6 +1,7 @@ /* * Shared code between the fish.c and the ftp.c file systems * + * Namespace pollution: X_hint_reread, X_flushdir. */ static int store_file (struct direntry *fe); static int retrieve_file (struct direntry *fe); @@ -10,7 +11,7 @@ static struct dir *retrieve_dir (struct connection *bucket, int resolve_symlinks); static void my_forget (char *path); -static int linear_start (struct direntry *fe); +static int linear_start (struct direntry *fe, int from); static int linear_read (struct direntry *fe, void *buf, int len); static void linear_close (struct direntry *fe); @@ -73,10 +74,6 @@ direntry_destructor (void *data) struct direntry *fe = data; fe->count--; - if ((fe->tmp_reget == 1 && fe->local_filename)){ - unlink (fe->local_filename); - fe->tmp_reget = 0; - } if (fe->count > 0) return; @@ -176,7 +173,7 @@ flush_all_directory(struct connection *bucket) linklist_delete_all(qdcache(bucket), dir_destructor); } -void X_fill_names (vfs *me, void (*func)(char *)) +static void X_fill_names (vfs *me, void (*func)(char *)) { struct linklist *lptr; char *path_name; @@ -335,8 +332,7 @@ _get_file_entry(struct connection *bucket, char *file_name, if (IS_LINEAR(flags)) { ent->local_is_temp = 0; ent->local_filename = NULL; - if (!linear_start (ent)) - return NULL; + ent->linear_state = LS_LINEAR_CLOSED; return ent; } if (!retrieve_file(ent)) @@ -355,7 +351,6 @@ _get_file_entry(struct connection *bucket, char *file_name, ent = xmalloc(sizeof(struct direntry), "struct direntry"); ent->freshly_created = 0; - ent->tmp_reget = 0; if (ent == NULL) ERRNOR (ENOMEM, NULL); ent->count = 1; ent->linkname = NULL; @@ -448,7 +443,7 @@ get_file_entry(char *path, int op, int flags) free(remote_path); #if 0 if (op & DO_FREE_RESOURCE) - vfs_add_noncurrent_stamps (&X_vfs_ops, (vfsid) bucket, NULL); + vfs_add_noncurrent_stamps (&vfs_X_ops, (vfsid) bucket, NULL); #endif return fe; } @@ -487,8 +482,8 @@ static void *s_open (vfs *me, char *file, int flags, int mode) free(fp); return NULL; } - fe->linear = IS_LINEAR(flags); - if (!fe->linear) { + fe->linear_state = IS_LINEAR(flags); + if (!fe->linear_state) { fp->local_handle = open(fe->local_filename, flags, mode); if (fp->local_handle < 0) { free(fp); @@ -512,7 +507,16 @@ static int s_read (void *data, char *buffer, int count) int n; fp = data; - if (fp->fe->linear) + if (fp->fe->linear_state == LS_LINEAR_CLOSED) { + print_vfs_message ("Starting linear transfer..."); + if (!linear_start (fp->fe, 0)) + return -1; + } + + if (fp->fe->linear_state == LS_LINEAR_CLOSED) + vfs_die ("linear_start() did not set linear_state!"); + + if (fp->fe->linear_state == LS_LINEAR_OPEN) return linear_read (fp->fe, buffer, count); n = read (fp->local_handle, buffer, count); @@ -525,6 +529,9 @@ static int s_write (void *data, char *buf, int nbyte) { struct filp *fp; int n; + + if (fp->fe->linear_state) + vfs_die ("You may not write to linear file"); fp = data; n = write (fp->local_handle, buf, nbyte); @@ -545,7 +552,7 @@ static int s_close (void *data) if (normal_flush) flush_all_directory(fp->fe->bucket); } - if (fp->fe->linear) + if (fp->fe->linear_state == LS_LINEAR_OPEN) linear_close(fp->fe); if (fp->local_handle >= 0) close(fp->local_handle); @@ -598,7 +605,7 @@ static void *s_opendir (vfs *me, char *dirname) dirp->dcache->count++; return (void *)dirp; error_return: - vfs_add_noncurrent_stamps (&X_vfs_ops, (vfsid) bucket, NULL); + vfs_add_noncurrent_stamps (&vfs_X_ops, (vfsid) bucket, NULL); free(remote_path); free(dirp); return NULL; @@ -720,7 +727,7 @@ static int s_chdir (vfs *me, char *path) qcdir(bucket) = remote_path; bucket->cwd_defered = 1; - vfs_add_noncurrent_stamps (&X_vfs_ops, (vfsid) bucket, NULL); + vfs_add_noncurrent_stamps (&vfs_X_ops, (vfsid) bucket, NULL); return 0; } @@ -728,6 +735,16 @@ static int s_lseek (void *data, off_t offset, int whence) { struct filp *fp = data; + if (fp->fe->linear_state == LS_LINEAR_OPEN) + vfs_die ("You promissed not to seek!"); + if (fp->fe->linear_state == LS_LINEAR_CLOSED) { + print_vfs_message ("Preparing reget..."); + if (whence != SEEK_SET) + vfs_die ("You may not do such seek on linear file"); + if (!linear_start (fp->fe, offset)) + return -1; + return offset; + } return lseek(fp->local_handle, offset, whence); } @@ -795,7 +812,7 @@ static void s_ungetlocalcopy (vfs *me, char *path, char *local, int has_changed) } } -void +static void X_done(vfs *me) { linklist_destroy(connections_list, connection_destructor); @@ -807,7 +824,8 @@ X_done(vfs *me) static int retrieve_file(struct direntry *fe) { - int total, tmp_reget = 0; /* do_reget; -- I think it can not work: pavel@ucw.cz */ + /* If you want reget, you'll have to open file with O_LINEAR */ + int total = 0; char buffer[8192]; int local_handle, n; int stat_size = fe->s.st_size; @@ -823,12 +841,11 @@ static int retrieve_file(struct direntry *fe) goto error_4; } - if (!linear_start (fe)) + if (!linear_start (fe, 0)) goto error_3; /* Clear the interrupt status */ enable_interrupt_key (); - total = (tmp_reget > 0) ? tmp_reget : 0; while (1) { if ((n = linear_read(fe, buffer, sizeof(buffer))) < 0) @@ -837,7 +854,7 @@ static int retrieve_file(struct direntry *fe) break; total += n; - print_vfs_stats (X, "Getting file", fe->remote_filename, total, stat_size); + vfs_print_stats (X, "Getting file", fe->remote_filename, total, stat_size); while (write(local_handle, buffer, n) < 0) { if (errno == EINTR) { @@ -859,9 +876,6 @@ static int retrieve_file(struct direntry *fe) if (stat (fe->local_filename, &fe->local_stat) < 0) fe->local_stat.st_mtime = 0; - if (tmp_reget > 0) - fe->tmp_reget = 1; - return 1; error_1: error_2: diff --git a/vfs/shared_tar_ext.c b/vfs/shared_tar_ext.c index 83b8c68dd..08f7915b1 100644 --- a/vfs/shared_tar_ext.c +++ b/vfs/shared_tar_ext.c @@ -3,6 +3,8 @@ * redundancy, so code is maintainable, again. * * 1998 Pavel Machek + * + * Namespace: no pollution. */ static char *get_path (char *inname, struct archive **archive, int is_dir, diff --git a/vfs/tar.c b/vfs/tar.c index dca5643d9..80bb1ac21 100644 --- a/vfs/tar.c +++ b/vfs/tar.c @@ -18,6 +18,8 @@ License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +/* Namespace: vfs_tarfs_ops, tar_gzipped_memlimit */ + #include #include #include @@ -50,7 +52,7 @@ int tar_gzipped_memlimit = 1*1024*1024; /* used to rotate the dash */ -int dash_number = 0; +static int dash_number = 0; #define isodigit(c) ( ((c) >= '0') && ((c) <= '7') ) /* @@ -58,7 +60,7 @@ int dash_number = 0; * * Result is -1 if the field is invalid (all blank, or nonoctal). */ -long from_oct (int digs, char *where) +static long from_oct (int digs, char *where) { register long value; @@ -85,7 +87,7 @@ static struct stat hstat; /* Stat struct corresponding */ static char *current_file_name, *current_link_name; static struct entry *find_entry (struct entry *dir, char *name, int make_dirs, int make_file); -void tarfs_fill_names (vfs *me, void (*func)(char *)) +static void tarfs_fill_names (vfs *me, void (*func)(char *)) { struct archive *a = first_archive; char *name; @@ -718,7 +720,7 @@ static int read_header (struct archive *archive, int tard) * Main loop for reading an archive. * Returns 0 on success, -1 on error. */ -int read_tar_archive (char *name, struct archive **pparc) +static int read_tar_archive (char *name, struct archive **pparc) { int status = 3; /* Initial status at start of archive */ int prev_status; @@ -800,12 +802,12 @@ static char *get_path_mangle (char *inname, struct archive **archive, int is_dir return NULL; /* Has the cached archive been changed on the disk? */ if (parc->tarstat.st_mtime < stat_buf.st_mtime) { /* Yes, reload! */ - (*tarfs_vfs_ops.free) ((vfsid) parc); - vfs_rmstamp (&tarfs_vfs_ops, (vfsid) parc, 0); + (*vfs_tarfs_ops.free) ((vfsid) parc); + vfs_rmstamp (&vfs_tarfs_ops, (vfsid) parc, 0); break; } /* Hasn't been modified, give it a new timeout */ - vfs_stamp (&tarfs_vfs_ops, (vfsid) parc); + vfs_stamp (&vfs_tarfs_ops, (vfsid) parc); goto return_success; } if (do_not_open) @@ -814,7 +816,7 @@ static char *get_path_mangle (char *inname, struct archive **archive, int is_dir result = read_tar_archive (archive_name, &parc); if (result == -1) ERRNOR (EIO, NULL); v = vfs_type (archive_name); - if (v == &local_vfs_ops) { + if (v == &vfs_local_ops) { parent = NULL; } else { parent = xmalloc (sizeof (struct vfs_stamping), "vfs stamping"); @@ -822,7 +824,7 @@ static char *get_path_mangle (char *inname, struct archive **archive, int is_dir parent->next = 0; parent->id = (*v->getid) (v, archive_name, &(parent->parent)); } - vfs_add_noncurrent_stamps (&tarfs_vfs_ops, (vfsid) parc, parent); + vfs_add_noncurrent_stamps (&vfs_tarfs_ops, (vfsid) parc, parent); vfs_rm_parents (parent); return_success: *archive = parc; @@ -918,7 +920,7 @@ static void *tar_open (vfs *me, char *file, int flags, int mode) entry->inode->is_open++; /* i.e. we had no open files and now we have one */ - vfs_rmstamp (&tarfs_vfs_ops, (vfsid) archive, 1); + vfs_rmstamp (&vfs_tarfs_ops, (vfsid) archive, 1); archive->fd_usage++; return tar_info; } @@ -978,7 +980,7 @@ static int tar_close (void *data) vfs *v; v = vfs_type (file->archive->name); - if (v == &local_vfs_ops) { + if (v == &vfs_local_ops) { parent = NULL; } else { parent = xmalloc (sizeof (struct vfs_stamping), "vfs stamping"); @@ -986,7 +988,7 @@ static int tar_close (void *data) parent->next = 0; parent->id = (*v->getid) (v, file->archive->name, &(parent->parent)); } - vfs_add_noncurrent_stamps (&tarfs_vfs_ops, (vfsid) (file->archive), parent); + vfs_add_noncurrent_stamps (&vfs_tarfs_ops, (vfsid) (file->archive), parent); vfs_rm_parents (parent); } (file->entry->inode->is_open)--; @@ -1151,12 +1153,7 @@ static void tar_ungetlocalcopy (vfs *me, char *path, char *local, int has_change since it will be freed when tar archive will be freed */ } -int tarfs_init(vfs *me) -{ - return 1; -} - -vfs tarfs_vfs_ops = +vfs vfs_tarfs_ops = { NULL, /* This is place of next pointer */ "TApe aRchiver decompressor", @@ -1164,7 +1161,7 @@ vfs tarfs_vfs_ops = "utar", /* prefix */ NULL, /* data */ 0, /* errno */ - tarfs_init, + NULL, NULL, tarfs_fill_names, NULL, @@ -1210,8 +1207,6 @@ vfs tarfs_vfs_ops = NULL, NULL, NULL -#ifdef HAVE_MMAP - , NULL, - NULL -#endif + +MMAPNULL }; diff --git a/vfs/undelfs.c b/vfs/undelfs.c index 539a4ea9e..a64123e8b 100644 --- a/vfs/undelfs.c +++ b/vfs/undelfs.c @@ -672,7 +672,7 @@ undelfs_free(vfsid id) undelfs_shutdown (); } -vfs undelfs_vfs_ops = { +vfs vfs_undelfs_ops = { NULL, /* This is place of next pointer */ "Undelete filesystem for ext2", 0, /* flags */ diff --git a/vfs/util-alone.c b/vfs/util-alone.c index 9f2cf22ee..955fd0d0c 100644 --- a/vfs/util-alone.c +++ b/vfs/util-alone.c @@ -1,5 +1,9 @@ /* + * Author: 1998 Pavel Machek + * * This is for making midnight commander's vfs stuff compile stand-alone + * + * Namespace pollution: horrible */ #include @@ -145,7 +149,7 @@ print_vfs_message (char *msg, ...) va_list args; va_start (args,msg); - vsnprintf (buf, sizeof (buf), msg, args); + vsnprintf (buf, sizeof (buf)-1, msg, args); info_puts (buf); va_end (args); } @@ -184,7 +188,8 @@ message_2s (int i, char *c1, char *c2, char *c3) box_puts (buf ); } -void message_3s( int i, char *c1, char *c2, char *c3, const char *c4 ) +void +message_3s( int i, char *c1, char *c2, char *c3, const char *c4 ) { char buf [4096]; diff --git a/vfs/utilvfs.c b/vfs/utilvfs.c index 1de214b84..b47e6a255 100644 --- a/vfs/utilvfs.c +++ b/vfs/utilvfs.c @@ -18,6 +18,8 @@ License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +/* Namespace: exports vfs_get_host_and_username */ + #ifndef test_get_host_and_username #include #endif @@ -40,65 +42,6 @@ #include -#ifndef test_get_host_and_username -#include "tcputil.h" -#include "../src/dialog.h" /* for message () */ -#include "../src/mem.h" /* for bcopy */ -#include "../src/util.h" /* for unix_error_string */ -#include "../src/mad.h" - -int open_tcp_link (char *host, int *port, int *version, char *caller) -{ - struct sockaddr_in server_address; - unsigned long inaddr; - struct hostent *hp; - int my_socket; - - if (!*host) - return 0; - - bzero ((char *) &server_address, sizeof (server_address)); - server_address.sin_family = AF_INET; - - /* Try to use the dotted decimal number */ - if ((inaddr = inet_addr (host)) != -1) - bcopy ((char *) &inaddr, (char *) &server_address.sin_addr, - sizeof (inaddr)); - else { - if ((hp = gethostbyname (host)) == NULL){ - message_2s (1, caller, " Can't locate hostname: %s ", host); - return 0; - } - bcopy ((char *) hp->h_addr, (char *) &server_address.sin_addr, - hp->h_length); - } - - /* Try to contact a remote portmapper to obtain the listening port */ - if (*port == 0){ - *port = get_remote_port (&server_address, version); - if (*port < 1) - return 0; - } else - *version = 1; - - server_address.sin_port = htons (*port); - - if ((my_socket = socket (AF_INET, SOCK_STREAM, 0)) < 0){ - message_2s (1, caller, " Can't create socket: %s ", - unix_error_string(errno)); - return 0; - } - if (connect (my_socket, (struct sockaddr *) &server_address, - sizeof (server_address)) < 0){ - message_2s (1, caller, " Can't connect to server: %s ", - unix_error_string (errno)); - close (my_socket); - return 0; - } - return my_socket; -} -#endif - /* Extract the hostname and username from the path */ /* path is in the form: [user@]hostname:port/remote-dir, e.g.: * @@ -115,8 +58,8 @@ int open_tcp_link (char *host, int *port, int *version, char *caller) * returns a malloced strings with the pathname relative to the host. * */ -char *get_host_and_username (char *path, char **host, char **user, int *port, - int default_port, int default_is_anon, char **pass) +char *vfs_get_host_and_username (char *path, char **host, char **user, int *port, + int default_port, int default_is_anon, char **pass) { struct passwd *passwd_info; char *dir, *colon, *inner_colon, *at, *rest; @@ -203,102 +146,6 @@ done: return retval; } -#ifdef old_manual_get_host_and_username -char *get_host_and_username (char *path, char **host, char **user, int *port, - int default_port, int default_is_anon, - char **pass) -{ - struct passwd *passwd_info; - char *p, *q; - - *pass = NULL; - *port = default_port; - for (p = path; ((*p != '/') && (*p != ':')) && *p; p++) - ; - - q = strchr (path, '@'); - - if (q != NULL) { - if (q > p) { - *user = (char *) xmalloc (p - path + 1, "get_host_and_username"); - strncpy (*user, path, p - path); - (*user) [p - path] = 0; - p++; - *pass = (char *) xmalloc (q - p + 1,"get_host_and_username"); - strncpy (*pass, p, q - p); - (*pass) [q - p] = 0; - for (p++; ((*p != '/') && (*p != ':')) && *p; p++); - q++; - *host = (char *) xmalloc (p - q + 1, "get_host_and_username"); - strncpy (*host, q, p - q); - (*host) [p-q] = 0; - } else { - if (q == path) - *user = NULL; - else { - *user = (char *) xmalloc (q - path + 1, "get_host_and_username"); - strncpy (*user, path, q - path); - (*user) [q - path] = 0; - } - q++; - *host = (char *) xmalloc (p - q + 1, "get_host_and_username"); - strncpy (*host, q, p - q); - (*host) [p-q] = 0; - } - } else { - *host = (char *) xmalloc (p - path + 1, "get_host_and_username"); - strncpy (*host, path, p - path); - (*host) [p-path] = 0; - *user = NULL; -#ifdef USE_NETRC - if (use_netrc) - if (lookup_netrc (*host, user, pass) < 0) { - if (*user) { free (*user); *user = NULL; } - if (*pass) { free (*pass); *pass = NULL; } - } -#endif - if (*user == NULL && default_is_anon) - *user = strdup ("anonymous"); - } - - /* If we got a port spec ... */ - if (*p == ':'){ - - q = ++p; - - for (;*q != '/' && *q; q++) - ; - - if (!*q && q == p){ - if (!(*user)) - *user = strdup (""); - /* on return: *host and *user always malloced, *pass malloced - * or NULL */ - return 0; - } - - *port = atoi (p); - - if (*port <= 0 || *port >= 65536) - *port = 21; - p = q; - } - - if (!*user){ - if ((passwd_info = getpwuid (geteuid ())) == NULL) - *user = strdup ("anonymous"); - else { - *user = strdup (passwd_info->pw_name); - } - endpwent (); - } - if (p && *p) - return strdup (p); - else - return strdup ("/"); -} -#endif - #ifdef test_get_host_and_username struct tt { char *url; diff --git a/vfs/vfs.c b/vfs/vfs.c index 9d9062e69..e586e2294 100644 --- a/vfs/vfs.c +++ b/vfs/vfs.c @@ -23,6 +23,9 @@ * strings you pass to them. This is acutally ok as you strdup what * you are passing to them, anyway; still, beware. */ +/* Namespace: exports *many* functions with vfs_ prefix; exports + parse_ls_lga and friends which do not have that prefix. */ + #include #include #include /* For atol() */ @@ -50,9 +53,8 @@ #include "../src/dialog.h" #endif #include "vfs.h" -#include "mcfs.h" +#include "extfs.h" /* FIXME: we should not know anything about our modules */ #include "names.h" -#include "extfs.h" #ifdef USE_NETCODE # include "tcputil.h" #endif @@ -65,8 +67,8 @@ int vfs_flags = 0; /* Flags */ extern int cd_symlinks; /* Defined in main.c */ /* They keep track of the current directory */ -static vfs *current_vfs = &local_vfs_ops; -char *current_dir = NULL; +static vfs *current_vfs = &vfs_local_ops; +static char *current_dir = NULL; /* * FIXME: this is broken. It depends on mc not crossing border on month! @@ -98,7 +100,7 @@ static int get_bucket (void) return 0; /* Shut up, stupid gcc */ } -static vfs *vfs_list = &local_vfs_ops; /* It _has_ to be the first */ +static vfs *vfs_list = &vfs_local_ops; /* It _has_ to be the first */ #define FOR_ALL_VFS for (vfs=vfs_list; vfs; vfs=vfs->next) @@ -118,7 +120,7 @@ vfs *vfs_type_from_op (char *path) { vfs *vfs; FOR_ALL_VFS { - if (vfs == &local_vfs_ops) /* local catches all */ + if (vfs == &vfs_local_ops) /* local catches all */ return NULL; if (vfs->which) { if ((*vfs->which) (vfs, path) != -1) @@ -133,9 +135,8 @@ vfs *vfs_type_from_op (char *path) return NULL; /* shut up stupid gcc */ } -int path_magic( char *path ) +static int path_magic( char *path ) { - int res; struct stat buf; if (vfs_flags & FL_ALWAYS_MAGIC) @@ -182,7 +183,7 @@ vfs *vfs_split (char *path, char **inpath, char **op) return ret; } -vfs* +vfs * vfs_rosplit (char *path) { char *semi = strrchr (path, '#'); @@ -209,7 +210,7 @@ vfs *vfs_type (char *path) { vfs *vfs = vfs_rosplit(path); if (!vfs) - vfs = &local_vfs_ops; + vfs = &vfs_local_ops; return vfs; } @@ -226,7 +227,7 @@ int vfs_timeouts () void vfs_addstamp (vfs *v, vfsid id, struct vfs_stamping *parent) { - if (v != &local_vfs_ops && id != (vfsid)-1){ + if (v != &vfs_local_ops && id != (vfsid)-1){ struct vfs_stamping *stamp, *st1; for (stamp = stamps; stamp != NULL; st1 = stamp, stamp = stamp->next) @@ -599,50 +600,6 @@ off_t mc_lseek (int fd, off_t offset, int whence) #define ISSLASH(a) (!a || (a == '/')) -void -vfs_kill_dots (char *path, char *local) -{ - char *s = path, *t = local; - char *last_slash = path; - - *t++ = *s++; - while (1){ - if (ISSLASH (*s)){ - if (*last_slash != '/') - vfs_die ("/ not there.\n"); - - if (ISSLASH (last_slash [1])) - t--; - - if (last_slash [1] == '.'){ - if (ISSLASH(last_slash [2])) - t -= 2; - if ((last_slash [2] == '.') && (ISSLASH (last_slash [3]))){ - t -= 4; - while ((t >= local) && (*t != '/')) - t--; - } - } - last_slash = s; - } - - if (t <= local){ - *local = '/'; - t = local; - } - if (!*s) - break; - *t++ = *s++; - *t = 0; - } - *t = 0; - if (!(*local)){ - local [0] = '/'; - local [1] = 0; - } -} - - char *vfs_canon (char *path) { if (*path == '~'){ /* Tilde expansion */ @@ -759,7 +716,7 @@ void vfs_add_noncurrent_stamps (vfs * oldvfs, vfsid oldvfsid, struct vfs_stampin } if ((*oldvfs->nothingisopen) (oldvfsid)){ - if (oldvfs == &extfs_vfs_ops && ((extfs_archive *) oldvfsid)->name == 0){ + if (oldvfs == &vfs_extfs_ops && ((extfs_archive *) oldvfsid)->name == 0){ /* Free the resources immediatly when we leave a mtools fs ('cd a:') instead of waiting for the vfs-timeout */ (oldvfs->free) (oldvfsid); @@ -772,7 +729,7 @@ void vfs_add_noncurrent_stamps (vfs * oldvfs, vfsid oldvfsid, struct vfs_stampin stamp->id == (vfsid) - 1 || !(*stamp->v->nothingisopen) (stamp->id)) break; - if (stamp->v == &extfs_vfs_ops && ((extfs_archive *) stamp->id)->name == 0){ + if (stamp->v == &vfs_extfs_ops && ((extfs_archive *) stamp->id)->name == 0){ (stamp->v->free) (stamp->id); vfs_rmstamp (stamp->v, stamp->id, 0); } else @@ -860,18 +817,21 @@ int mc_chdir (char *path) int vfs_current_is_local (void) { - return current_vfs == &local_vfs_ops; + return current_vfs == &vfs_local_ops; } +#if 0 +/* External world should not do differences between VFS-s */ int vfs_current_is_extfs (void) { - return current_vfs == &extfs_vfs_ops; + return current_vfs == &vfs_extfs_ops; } int vfs_current_is_tarfs (void) { - return current_vfs == &tarfs_vfs_ops; + return current_vfs == &vfs_tarfs_ops; } +#endif int vfs_file_is_local (char *filename) { @@ -880,7 +840,7 @@ int vfs_file_is_local (char *filename) filename = vfs_canon (filename); vfs = vfs_type (filename); free (filename); - return vfs == &local_vfs_ops; + return vfs == &vfs_local_ops; } int vfs_file_is_ftp (char *filename) @@ -891,7 +851,7 @@ int vfs_file_is_ftp (char *filename) filename = vfs_canon (filename); vfs = vfs_type (filename); free (filename); - return vfs == &ftpfs_vfs_ops; + return vfs == &vfs_ftpfs_ops; #else return 0; #endif @@ -902,7 +862,7 @@ char *vfs_get_current_dir (void) return current_dir; } -void vfs_setup_wd (void) +static void vfs_setup_wd (void) { current_dir = strdup ("/"); if (!(vfs_flags & FL_NO_CWDSETUP)) @@ -919,7 +879,7 @@ MC_NAMEOP (rmdir, (char *path), (vfs, vfs_name (path))) MC_NAMEOP (mknod, (char *path, int mode, int dev), (vfs, vfs_name (path), mode, dev)) #ifdef HAVE_MMAP -struct mc_mmapping { +static struct mc_mmapping { caddr_t addr; void *vfs_info; vfs *vfs; @@ -982,7 +942,7 @@ char *mc_def_getlocalcopy (vfs *vfs, char *filename) fdin = mc_open (filename, O_RDONLY); if (fdin == -1) return NULL; - tmp = tmpnam(NULL); + tmp = tempnam (NULL, "mclocalcopy"); fdout = creat (tmp, 0600); /* FIXME: What about symlink attack ? */ if (fdout == -1){ mc_close (fdin); @@ -1098,21 +1058,21 @@ void vfs_init (void) current_mon = t->tm_mon; current_year = t->tm_year; - /* We do not want to register local_vfs_ops */ + /* We do not want to register vfs_local_ops */ #ifdef USE_NETCODE tcp_init(); - vfs_register (&ftpfs_vfs_ops); - vfs_register (&mcfs_vfs_ops); + vfs_register (&vfs_ftpfs_ops); + vfs_register (&vfs_mcfs_ops); #endif - vfs_register (&fish_vfs_ops); - vfs_register (&extfs_vfs_ops); - vfs_register (&sfs_vfs_ops); - vfs_register (&tarfs_vfs_ops); + vfs_register (&vfs_fish_ops); + vfs_register (&vfs_extfs_ops); + vfs_register (&vfs_sfs_ops); + vfs_register (&vfs_tarfs_ops); #ifdef USE_EXT2FSLIB - vfs_register (&undelfs_vfs_ops); + vfs_register (&vfs_undelfs_ops); #endif vfs_setup_wd (); @@ -1185,7 +1145,7 @@ void vfs_fill_names (void (*func)(char *)) static char *columns [MAXCOLS]; /* Points to the string in column n */ static int column_ptr [MAXCOLS]; /* Index from 0 to the starting positions of the columns */ -int split_text (char *p) +int vfs_split_text (char *p) { char *original = p; int numcols; @@ -1254,7 +1214,7 @@ static int is_year(char *str, struct tm *tim) where "2904 1234" is filename. Well, this code decodes it as year :-(. */ -int parse_filetype (char c) +int vfs_parse_filetype (char c) { switch (c){ case 'd': return S_IFDIR; @@ -1272,7 +1232,7 @@ int parse_filetype (char c) } } -int parse_filemode (char *p) +int vfs_parse_filemode (char *p) { /* converts rw-rw-rw- into 0666 */ int res = 0; switch (*(p++)){ @@ -1329,7 +1289,7 @@ int parse_filemode (char *p) return res; } -int parse_filedate(int idx, time_t *t) +int vfs_parse_filedate(int idx, time_t *t) { /* This thing parses from idx in columns[] array */ static char *month = "JanFebMarAprMayJunJulAugSepOctNovDec"; static char *week = "SunMonTueWedThuFriSat"; @@ -1407,7 +1367,7 @@ int parse_filedate(int idx, time_t *t) } #define free_and_return(x) { free (p_copy); return (x); } -int parse_ls_lga (char *p, struct stat *s, char **filename, char **linkname) +int vfs_parse_ls_lga (char *p, struct stat *s, char **filename, char **linkname) { int idx, idx2, num_cols, isconc = 0; int i; @@ -1416,7 +1376,7 @@ int parse_ls_lga (char *p, struct stat *s, char **filename, char **linkname) if (strncmp (p, "total", 5) == 0) return 0; - if ((i = parse_filetype(*(p++))) == -1) + if ((i = vfs_parse_filetype(*(p++))) == -1) return 0; s->st_mode = i; @@ -1430,14 +1390,14 @@ int parse_ls_lga (char *p, struct stat *s, char **filename, char **linkname) s->st_mode |= (S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR); p += 9; } else { - if ((i = parse_filemode(p)) ==-1) + if ((i = vfs_parse_filemode(p)) ==-1) return 0; s->st_mode |= i; p += 9; } p_copy = strdup (p); - num_cols = split_text (p); + num_cols = vfs_split_text (p); s->st_nlink = atol (columns [0]); if (s->st_nlink <= 0) @@ -1503,7 +1463,7 @@ int parse_ls_lga (char *p, struct stat *s, char **filename, char **linkname) #endif } - idx = parse_filedate(idx, &s->st_mtime); + idx = vfs_parse_filedate(idx, &s->st_mtime); if (!idx) free_and_return (0); /* Use resulting time value */ @@ -1572,12 +1532,6 @@ int parse_ls_lga (char *p, struct stat *s, char **filename, char **linkname) free_and_return (1); } -void -vfs_force_expire (char *pathname) -{ - mc_setctl( pathname, MCCTL_FORGET_ABOUT, NULL ); -} - void vfs_die (char *m) { @@ -1586,7 +1540,7 @@ vfs_die (char *m) } void -print_vfs_stats (char *fs_name, char *action, char *file_name, int have, int need) +vfs_print_stats (char *fs_name, char *action, char *file_name, int have, int need) { if (need) print_vfs_message ("%s: %s: %s %3d%% (%ld bytes transfered)", @@ -1603,3 +1557,14 @@ vfs_get_password (char *msg) return (char *) input_dialog (msg, _("Password:"), ""); } #endif + +/* Returns vfs path corresponding to given url. If passed string is + * not recognized as url, strdup(url) is returned. */ +char * +vfs_translate_url (char *url) +{ + if (strncmp (url, "ftp://", 6) == 0) + return copy_strings ("/#ftp:", url + 6, 0); + else + return strdup (url); +} diff --git a/vfs/vfs.h b/vfs/vfs.h index 45f203733..c23c8985f 100644 --- a/vfs/vfs.h +++ b/vfs/vfs.h @@ -96,17 +96,17 @@ struct utimbuf { } vfs; /* Other file systems */ - extern vfs local_vfs_ops; - extern vfs tarfs_vfs_ops; + extern vfs vfs_local_ops; + extern vfs vfs_tarfs_ops; - extern vfs ftpfs_vfs_ops; - extern vfs fish_vfs_ops; - extern vfs mcfs_vfs_ops; + extern vfs vfs_ftpfs_ops; + extern vfs vfs_fish_ops; + extern vfs vfs_mcfs_ops; - extern vfs extfs_vfs_ops; - extern vfs sfs_vfs_ops; + extern vfs vfs_extfs_ops; + extern vfs vfs_sfs_ops; - extern vfs undelfs_vfs_ops; + extern vfs vfs_undelfs_ops; struct vfs_stamping { vfs *v; @@ -128,8 +128,10 @@ struct utimbuf { char *vfs_canon (char *path); char *mc_get_current_wd (char *buffer, int bufsize); int vfs_current_is_local (void); +#if 0 int vfs_current_is_extfs (void); int vfs_current_is_tarfs (void); +#endif int vfs_file_is_local (char *name); int vfs_file_is_ftp (char *filename); char *vfs_get_current_dir (void); @@ -142,12 +144,9 @@ struct utimbuf { void vfs_free_resources(char *path); void vfs_timeout_handler (); int vfs_timeouts (); - void vfs_force_expire (char *pathname); void vfs_fill_names (void (*)(char *)); - - /* Required for the vfs_canon routine */ - char *tarfs_analysis (char *inname, char **archive, int is_dir); + char *vfs_translate_url (char *); void ftpfs_set_debug (char *file); #ifdef USE_NETCODE @@ -257,7 +256,6 @@ struct utimbuf { # define mc_rmdir rmdir # define is_special_prefix(x) 0 # define vfs_type(x) (vfs *)(NULL) -# define vfs_setup_wd() # define vfs_init() # define vfs_shut() # define vfs_canon(p) strdup (canonicalize_pathname(p)) @@ -292,17 +290,19 @@ struct utimbuf { #define mc_errno errno -#ifdef WANT_PARSE_LS_LGA -int parse_ls_lga (char *p, struct stat *s, char **filename, char **linkname); -int split_text (char *p); -int parse_filetype (char c); -int parse_filemode (char *p); -int parse_filedate(int idx, time_t *t); -#endif +/* These functions are meant for use by vfs modules */ + +extern int vfs_parse_ls_lga (char *p, struct stat *s, char **filename, char **linkname); +extern int vfs_split_text (char *p); +extern int vfs_parse_filetype (char c); +extern int vfs_parse_filemode (char *p); +extern int vfs_parse_filedate(int idx, time_t *t); + extern void vfs_die (char *msg); extern char *vfs_get_password (char *msg); - -void print_vfs_stats (char *fs_name, char *action, char *file_name, int have, int need); +extern char *vfs_get_host_and_username (char *path, char **host, char **user, int *port, + int default_port, int default_is_anon, char **pass); +extern void vfs_print_stats (char *fs_name, char *action, char *file_name, int have, int need); #define MCCTL_SETREMOTECOPY 0 #define MCCTL_ISREMOTECOPY 1 @@ -312,14 +312,7 @@ void print_vfs_stats (char *fs_name, char *action, char *file_name, int have, in #define MCCTL_REMOVELOCALCOPY 5 #define MCCTL_IS_NOTREADY 6 #define MCCTL_FORGET_ABOUT 7 - -/* Return codes from the ${fs}_ctl routine */ - -#define MCERR_TARGETOPEN -1 /* Can't open target file */ -#define MCERR_READ -2 /* Read error on source file */ -#define MCERR_WRITE -3 /* Write error on target file */ -#define MCERR_FINISH -4 /* Finished transfer */ -#define MCERR_DATA_ON_STDIN -5 /* Data waiting on stdin to be processed */ +#define MCCTL_EXTFS_RUN 8 extern int vfs_flags; extern uid_t vfs_uid; @@ -354,7 +347,7 @@ extern void mc_vfs_done( void ); #define NO_LINEAR(a) a #else #define O_LINEAR O_APPEND -#define IS_LINEAR(a) ((a) == (O_RDONLY | O_LINEAR)) +#define IS_LINEAR(a) ((a) == (O_RDONLY | O_LINEAR)) /* Return only 0 and 1 ! */ #define NO_LINEAR(a) (((a) == (O_RDONLY | O_LINEAR)) ? O_RDONLY : (a)) #endif @@ -364,6 +357,10 @@ extern void mc_vfs_done( void ); * a) to read file linearily from beggining to the end * b) not to open another file before you close this one * (this will likely go away in future) + * as a special gift, you may + * c) lseek() immediately after open(), giving ftpfs chance to + * reget. Be warned that this lseek() can fail, and you _have_ + * to handle that gratefully. * * O_LINEAR allows filesystems not to create temporary file in some * cases (ftp transfer). -- pavel@ucw.cz