Speeding up VFS - no more mc_stat("..")

Andrew V. Samoilov kai at cmail.ru
Thu Jan 24 10:45:01 UTC 2002


Hello!

>That's the second part of the patch that speeds up VFS.  If there is no 
>".." in the directory list, then a fake ".." is added.  However, mc will 
>no longer go up the hierarchy to find the size of the ".." directory.
>
>So, it you have an account of a system foo and your home directory is bar, 
>then going to /#sh:foo/home/bar/subdir won't cause mc to get the listing 
>of all users under /home.
>
>
>============================
>--- ChangeLog
>+++ ChangeLog
>@@ -2,2 +2,5 @@
> 
>+	* dir.c (add_dotdot_to_list): Don't use costly stat() - just put
>+	realistic (i.e. bogus) data to the list.
>+
> 	* screen.c (string_file_size): Don't display size of ".." - it
>--- dir.c
>+++ dir.c
>@@ -342,10 +342,6 @@ clean_dir (dir_list *list, int count)
> static int
> add_dotdot_to_list (dir_list *list, int index)
> {
>-    char buffer [MC_MAXPATHLEN + MC_MAXPATHLEN];
>-    char *p;
>-    int i = 0;
>-
>     /* Need to grow the *list? */
>     if (index == list->size) {
> 	list->list = g_realloc (list->list, sizeof (file_entry) *
>@@ -355,40 +351,14 @@ add_dotdot_to_list (dir_list *list, int 
> 	list->size += RESIZE_STEPS;
. . .
>-    mc_get_current_wd (buffer, sizeof (buffer) - 1 );
>-    if (buffer [strlen (buffer) - 1] == PATH_SEP)
>-    	buffer [strlen (buffer) - 1] = 0;
>-    for (;;) {
>-    	strcat (buffer, PATH_SEP_STR "..");
>-        p = vfs_canon (buffer);
>-        if (mc_stat (p, &((list->list) [index].buf)) != -1){
>-	    g_free (p);
>-            break;
>-	}
>-        i = 1;
>-        if (!strcmp (p, PATH_SEP_STR)){
>-	    g_free (p);
>-            return 1;
>-	}
>-	strcpy (buffer, p);
>-	g_free (p);
>-    }

This patch also fixes a rare buffer overflow. If p cannot be mc_stat()ed for any reason it will
append PATH_SEP_STR ".." again and again without checks for buffer size.  This was a reson
why mc-4.5.x crashes when extfs archives with leading ~ in name browsed before vfs_canon
behavior was fixed.

--
Regards,
Andrew.



More information about the mc-devel mailing list