Case insensitive filename for NTFS
PATCH 1/1 Case insensitive filename for NTFS
Hi,
This patch allow case insensitive filename in Win32 and DOS namespace. Names in POSIX namespace would still be case sensitive. It also remove names in the DOS namespace, as they will reappear in Win32 namespace.
2008-08-29 Bean <[email protected]>
* fs/fshelp.c (grub_fshelp_find_file): Handle case insensitive names.
* fs/ntfs.c (list_file): Ignore names in DOS namespace, set the case insensitive bit for names in Win32 and Win32 & DOS namespace.
* include/grub/fshelp.h (GRUB_FSHELP_CASE_INSENSITIVE): New macro.
* include/grub/types (LONG_MAX): Likewise.
Signature · 1 line
Bean
fs/fshelp.c +7 -1
@@ -80,7 +80,13 @@ grub_fshelp_find_file (const char *path, grub_fshelp_node_t rootnode,enum grub_fshelp_filetype filetype, grub_fshelp_node_t node) { -if (type ==GRUB_FSHELP_UNKNOWN ||grub_strcmp (name, filename)) + int case_insensitive = (filetype & GRUB_FSHELP_CASE_INSENSITIVE); + + filetype &= ~GRUB_FSHELP_CASE_INSENSITIVE ; +if (filetype ==GRUB_FSHELP_UNKNOWN || + (grub_strcmp (name, filename) && + (! case_insensitive || +grub_strncasecmp (name, filename,LONG_MAX )))) {grub_free (node);return 0 ;
fs/ntfs.c +14 -4
@@ -575,13 +575,20 @@ list_file (struct grub_ntfs_file *diro, char *pos,while (1 ) { -char *ustr; +char *ustr, namespace; +if (pos[0xC ] &2 )/* end signature */ break ; - np = pos +0x52 ; - ns = (unsigned char ) *(np -2 ); -if (ns) + np = pos +0x50 ; + ns = (unsigned char ) *(np++); + namespace = *(np++); + +/* +* Ignore files in DOS namespace, as they will reappear as Win32 +* names. +*/ +if ((ns) && (namespace !=2 )) {enum grub_fshelp_filetype type;struct grub_ntfs_file *fdiro;
@@ -610,6 +617,9 @@ list_file (struct grub_ntfs_file *diro, char *pos, *grub_utf16_to_utf8 ((grub_uint8_t *) ustr, (grub_uint16_t *) np, ns) ='\0' ; +if (namespace) + type |=GRUB_FSHELP_CASE_INSENSITIVE ; +if (hook (ustr, type, fdiro)) {grub_free (ustr);
include/grub/fshelp.h +2 -0
@@ -26,6 +26,8 @@typedef struct grub_fshelp_node *grub_fshelp_node_t ; +#define GRUB_FSHELP_CASE_INSENSITIVE 0x100 +enum grub_fshelp_filetype {GRUB_FSHELP_UNKNOWN ,
include/grub/types.h +2 -0
@@ -94,8 +94,10 @@ typedef grub_int32_t grub_ssize_t;#if GRUB_CPU_SIZEOF_VOID_P ==8 # define ULONG_MAX 18446744073709551615UL +# define LONG_MAX 9223372036854775807UL#else # define ULONG_MAX 4294967295UL +# define LONG_MAX 2147483647UL#endif /* The type for representing a file offset. */
Quoted 5 lines · Bean
Hi,
This patch allow case insensitive filename in Win32 and DOS namespace. Names in POSIX namespace would still be case sensitive. It also remove names in the DOS namespace, as they will reappear in Win32 namespace.
Nice work :-)
Quoted 4 lines
fs/fshelp.c +0
-0@@ -80,7 +80,13 @@ grub_fshelp_find_file (const char *path, grub_fshelp_node_t rootnode, enum grub_fshelp_filetype filetype,
fs/fshelp.c grub_fshelp_find_file (const char *path, grub_fshelp_node_t rootnode, · line 89
Quoted 10 lines
fs/fshelp.c +7
-1grub_fshelp_node_t node) { -if (type ==GRUB_FSHELP_UNKNOWN ||grub_strcmp (name, filename)) +int case_insensitive = (filetype &GRUB_FSHELP_CASE_INSENSITIVE ); + + filetype &= ~GRUB_FSHELP_CASE_INSENSITIVE ; +if (filetype ==GRUB_FSHELP_UNKNOWN || + (grub_strcmp (name, filename) && + (! case_insensitive || +grub_strncasecmp (name, filename,LONG_MAX ))))
Since `case_insensitive' is only used once, maybe we could skip this variable?
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Quoted 18 lines · Robert Millan
Quoted 5 lines · Bean
Hi,
This patch allow case insensitive filename in Win32 and DOS namespace. Names in POSIX namespace would still be case sensitive. It also remove names in the DOS namespace, as they will reappear in Win32 namespace.
Nice work :-)
Quoted 9 lines
fs/fshelp.c +2
-1@@ -80,7 +80,13 @@ grub_fshelp_find_file (const char *path, grub_fshelp_node_t rootnode,enum grub_fshelp_filetype filetype, grub_fshelp_node_t node) { - if (type == GRUB_FSHELP_UNKNOWN || grub_strcmp (name, filename)) + int case_insensitive = (filetype & GRUB_FSHELP_CASE_INSENSITIVE); +
Quoted 8 lines
fs/fshelp.c grub_fshelp_find_file (const char *path, grub_fshelp_node_t rootnode, · line 89
Quoted 5 lines
fs/fshelp.c +5
-0+ filetype &= ~GRUB_FSHELP_CASE_INSENSITIVE ; +if (filetype ==GRUB_FSHELP_UNKNOWN || + (grub_strcmp (name, filename) && + (! case_insensitive || +grub_strncasecmp (name, filename,LONG_MAX ))))Since `case_insensitive' is only used once, maybe we could skip this variable?
Committed.
Signature · 1 line
Bean