Rockbox.org home
release
dev builds
extras
themes manual
wiki
device status forums
mailing lists
IRC bugs
patches
dev guide



Rockbox mail archive

Subject: Patch for hidden files/dirs and dotfiles

Patch for hidden files/dirs and dotfiles

From: Bill Napier <napier_at_pobox.com>
Date: 09 Aug 2002 15:44:51 -0400

This is in reference to feature request #538249 (and was already fixed
with the m3u/mp3 filtering patch, but improved with this patch).

This patch provides two things:

1. Has an option to show any file/dir that has the "hidden" attribute
set to show up with a "." in front of thier name (as if you mapped a
FAT filesystem into an UNIX environment).

2. Has an option to ignore any file/dir that has a "." as the first
character in the filename. This can come in handy with the above
feature to hide "hidden" files. Can also come in handy if you have no
easy way to set the "hidden" bit on a file (ie. you're doing stuff
from the command line or from a UNIX OS and can't set those attributes
on a file). Just give it a name starting with "." and it won't be
shown in the list (unless you want it to).

Both of these options default to "on".

Things I had to change to get this working:
1. Had to remove the mp3filter option's check for the hidden
attribute. Was this an unadvertised feature?

2. Had to fix the check for "." and ".." as file's in tree.c. The
previous code was checking for any file that begins with "." or ".."
rather than checking for a file named just "." or "..".

This has been checked on on my Player, but I don't have a Recorder to
test it on.

And as promised, here's a patch:
----------- Begin patch -----------
Index: apps/settings.c
===================================================================
RCS file: /cvsroot/rockbox/apps/settings.c,v
retrieving revision 1.20
diff -u -b -r1.20 settings.c
--- apps/settings.c 9 Aug 2002 13:50:58 -0000 1.20
+++ apps/settings.c 9 Aug 2002 19:33:11 -0000
_at__at_ -268,7 +268,9 _at__at_
          ((global_settings.mp3filter & 1) << 1) |
          ((global_settings.sort_case & 1) << 2) |
          ((global_settings.discharge & 1) << 3) |
- ((global_settings.statusbar & 1) << 4));
+ ((global_settings.statusbar & 1) << 4) |
+ ((global_settings.hidden_as_dotfile & 1) << 5) |
+ ((global_settings.hide_dotfiles & 1) << 6));
 
     rtc_config_block[0xf] = (unsigned char)
         ((global_settings.scroll_speed << 3) |
_at__at_ -337,6 +339,8 _at__at_
             global_settings.sort_case = (rtc_config_block[0xe] >> 2) & 1;
             global_settings.discharge = (rtc_config_block[0xe] >> 3) & 1;
             global_settings.statusbar = (rtc_config_block[0xe] >> 4) & 1;
+ global_settings.hidden_as_dotfile = (rtc_config_block[0xe] >> 5) & 1;
+ global_settings.hide_dotfiles = (rtc_config_block[0xe] >> 6) & 1;
         }
         
         c = rtc_config_block[0xf] >> 3;
_at__at_ -386,6 +390,15 _at__at_
     global_settings.discharge = 0;
     global_settings.total_uptime = 0;
     global_settings.scroll_speed = 8;
+ global_settings.hidden_as_dotfile = true;
+ global_settings.hide_dotfiles = true;
+#ifndef SIMULATOR
+ /* It's safer to set it then to ensure that the firware default
+ * stays matched up with the app default (without having the
+ * firmware depend on the application)
+ */
+ fat_usedotfiles(global_settings.hidden_as_dotfile);
+#endif
 }
 
 
Index: apps/settings.h
===================================================================
RCS file: /cvsroot/rockbox/apps/settings.h,v
retrieving revision 1.12
diff -u -b -r1.12 settings.h
--- apps/settings.h 9 Aug 2002 12:38:45 -0000 1.12
+++ apps/settings.h 9 Aug 2002 19:33:11 -0000
_at__at_ -65,6 +65,10 _at__at_
 
     /* show status bar */
     bool statusbar; /* 0=hide, 1=show */
+
+ /* Hidden and dotfile settings */
+ bool hidden_as_dotfile; /* 0=not as dotfile, 1=as dotfile */
+ bool hide_dotfiles; /* 0=show dotilfes, 1=hide dotfiles */
     
     /* geeky persistent statistics */
     unsigned int total_uptime; /* total uptime since rockbox was first booted */
Index: apps/settings_menu.c
===================================================================
RCS file: /cvsroot/rockbox/apps/settings_menu.c,v
retrieving revision 1.13
diff -u -b -r1.13 settings_menu.c
--- apps/settings_menu.c 9 Aug 2002 13:50:58 -0000 1.13
+++ apps/settings_menu.c 9 Aug 2002 19:33:11 -0000
_at__at_ -32,9 +32,23 _at__at_
 #include "settings_menu.h"
 #include "backlight.h"
 #include "playlist.h" /* for playlist_shuffle */
+#include "fat.h" /* For dotfile settings */
 #include "powermgmt.h"
 #include "rtc.h"
 
+static void hide_dotfiles_set(void)
+{
+ set_bool( "[Hide dotfiles]", &global_settings.hide_dotfiles );
+}
+
+static void hidden_to_dot_set(void)
+{
+ set_bool( "[Hidden to dotfile]", &global_settings.hidden_as_dotfile );
+#ifndef SIMULATOR
+ fat_usedotfiles(global_settings.hidden_as_dotfile);
+#endif
+}
+
 static void shuffle(void)
 {
     set_bool( "[Shuffle]", &global_settings.playlist_shuffle );
_at__at_ -144,6 +158,8 _at__at_
 #ifdef HAVE_RTC
         { "Time/Date", timedate_set },
 #endif
+ { "Hide dotfiles", hide_dotfiles_set },
+ { "Hidden to dotfile", hidden_to_dot_set},
     };
     bool old_shuffle = global_settings.playlist_shuffle;
     
Index: apps/tree.c
===================================================================
RCS file: /cvsroot/rockbox/apps/tree.c,v
retrieving revision 1.82
diff -u -b -r1.82 tree.c
--- apps/tree.c 8 Aug 2002 19:03:14 -0000 1.82
+++ apps/tree.c 9 Aug 2002 19:33:13 -0000
_at__at_ -169,15 +169,26 _at__at_
             if (!entry)
                 break;
 
+ len = strlen(entry->d_name);
+
             /* skip directories . and .. */
             if ((entry->attribute & ATTR_DIRECTORY) &&
- (!strncmp(entry->d_name, ".", 1) ||
- !strncmp(entry->d_name, "..", 2))) {
+ (((len == 1) &&
+ (!strncmp(entry->d_name, ".", 1))) ||
+ ((len == 2) &&
+ (!strncmp(entry->d_name, "..", 2))))) {
                 i--;
                 continue;
             }
+
+ /* Skip dotfiles if set to skip them */
+ if (global_settings.hide_dotfiles &&
+ entry->d_name[0]=='.') {
+ i--;
+ continue;
+ }
+
             dptr->attr = entry->attribute;
- len = strlen(entry->d_name);
 
             /* mark mp3 and m3u files as such */
             if ( !(dptr->attr & ATTR_DIRECTORY) && (len > 4) ) {
_at__at_ -188,10 +199,9 _at__at_
                         dptr->attr |= TREE_ATTR_M3U;
             }
 
- /* filter hidden files and directories and non-mp3 or m3u files */
+ /* filter non-mp3 or m3u files */
             if ( global_settings.mp3filter &&
- ((dptr->attr & ATTR_HIDDEN) ||
- !(dptr->attr & (ATTR_DIRECTORY|TREE_ATTR_MP3|TREE_ATTR_M3U))) ) {
+ (!(dptr->attr & (ATTR_DIRECTORY|TREE_ATTR_MP3|TREE_ATTR_M3U))) ) {
                 i--;
                 continue;
             }
_at__at_ -436,6 +446,9 _at__at_
             case TREE_MENU: {
                 bool lastfilter = global_settings.mp3filter;
                 bool lastsortcase = global_settings.sort_case;
+ bool lasthidden_as_dotfile = global_settings.hidden_as_dotfile;
+ bool lasthide_dotfiles = global_settings.hide_dotfiles;
+
 #ifdef HAVE_LCD_BITMAP
                 bool laststate=statusbar(false);
 #endif
_at__at_ -446,7 +459,9 _at__at_
 #endif
                 /* do we need to rescan dir? */
                 if ( lastfilter != global_settings.mp3filter ||
- lastsortcase != global_settings.sort_case)
+ lastsortcase != global_settings.sort_case ||
+ lasthidden_as_dotfile != global_settings.hidden_as_dotfile ||
+ lasthide_dotfiles != global_settings.hide_dotfiles)
                     lastdir[0] = 0;
                 restore = true;
                 break;
Index: firmware/drivers/fat.c
===================================================================
RCS file: /cvsroot/rockbox/firmware/drivers/fat.c,v
retrieving revision 1.27
diff -u -b -r1.27 fat.c
--- firmware/drivers/fat.c 24 Jul 2002 07:19:01 -0000 1.27
+++ firmware/drivers/fat.c 9 Aug 2002 19:33:15 -0000
_at__at_ -159,6 +159,8 _at__at_
 
 static struct bpb fat_bpb;
 
+static bool use_dot_files = true;
+
 static int first_sector_of_cluster(int cluster);
 static int bpb_is_sane(void);
 static void *cache_fat_sector(int secnum);
_at__at_ -850,6 +852,11 _at__at_
     de->firstcluster = BYTES2INT16(buf,FATDIR_FSTCLUSLO) |
                       (BYTES2INT16(buf,FATDIR_FSTCLUSHI) << 16);
 
+ if (use_dot_files &&
+ (de->attr & FAT_ATTR_HIDDEN)) {
+ de->name[j++]='.';
+ }
+
     /* fix the name */
     for (i=0; (i<8) && (buf[FATDIR_NAME+i] != ' '); i++)
         de->name[j++] = buf[FATDIR_NAME+i];
_at__at_ -858,6 +865,7 _at__at_
         for (i=8; (i<11) && (buf[FATDIR_NAME+i] != ' '); i++)
             de->name[j++] = buf[FATDIR_NAME+i];
     }
+
     return 1;
 }
 
_at__at_ -986,6 +994,10 _at__at_
     return 0;
 }
 
+void fat_usedotfiles(bool set) {
+ use_dot_files=set;
+}
+
 int fat_getnext(struct fat_dir *dir, struct fat_direntry *entry)
 {
     int done = 0;
_at__at_ -1029,6 +1041,11 _at__at_
                     /* replace shortname with longname? */
                     if ( longs ) {
                         int j,k,l=0;
+
+ if (use_dot_files &&
+ (entry->attr & FAT_ATTR_HIDDEN)) {
+ entry->name[l++]='.';
+ }
 
                         /* iterate backwards through the dir entries */
                         for (j=longs-1; j>=0; j--) {
Index: firmware/drivers/fat.h
===================================================================
RCS file: /cvsroot/rockbox/firmware/drivers/fat.h,v
retrieving revision 1.11
diff -u -b -r1.11 fat.h
--- firmware/drivers/fat.h 30 May 2002 19:47:56 -0000 1.11
+++ firmware/drivers/fat.h 9 Aug 2002 19:33:15 -0000
_at__at_ -62,6 +62,8 _at__at_
 
 extern int fat_mount(int startsector);
 
+extern void fat_usedotfiles(bool set);
+
 #ifdef DISK_WRITE
 extern int fat_create_file(unsigned int currdir, char *name);
 extern int fat_create_dir(unsigned int currdir, char *name);

----------- End patch -----------

-- 
If it happens once, it's a bug.
If it happens twice, it's a feature.
If it happens more than twice, it's a design philosophy.
Received on 2002-08-09

Page template was last modified "Tue Sep 7 00:00:02 2021" The Rockbox Crew -- Privacy Policy