From: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
To: akpm@linux-foundation.org
Cc: linux-kernel@vger.kernel.org, hirofumi@mail.parknet.co.jp
Subject: [PATCH 5/7] fat: use same logic in fat_search_long() and __fat_readdir()
Date: Tue, 01 Jul 2008 11:57:03 +0900 [thread overview]
Message-ID: <555b858b3e848699cff511608.ps@mail.parknet.co.jp> (raw)
In-Reply-To: <5be8ad613e848699cff411608.ps@mail.parknet.co.jp>
This uses uses stack for shortname, and uses __getname() for longname
in fat_search_long() and __fat_readdir(). By this, it removes
unneeded __getname() for shortname.
Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
---
fs/fat/dir.c | 42 ++++++++++++++++++++++++++----------------
1 file changed, 26 insertions(+), 16 deletions(-)
diff -puN fs/fat/dir.c~fat_dir-mem-cleanup fs/fat/dir.c
--- linux-2.6/fs/fat/dir.c~fat_dir-mem-cleanup 2008-07-01 10:01:52.000000000 +0900
+++ linux-2.6-hirofumi/fs/fat/dir.c 2008-07-01 10:01:52.000000000 +0900
@@ -325,6 +325,19 @@ parse_long:
}
/*
+ * Maximum buffer size of short name.
+ * [(MSDOS_NAME + '.') * max one char + nul]
+ * For msdos style, ['.' (hidden) + MSDOS_NAME + '.' + nul]
+ */
+#define FAT_MAX_SHORT_SIZE ((MSDOS_NAME + 1) * NLS_MAX_CHARSET_SIZE + 1)
+/*
+ * Maximum buffer size of unicode chars from slots.
+ * [(max longname slots * 13 (size in a slot) + nul) * sizeof(wchar_t)]
+ */
+#define FAT_MAX_UNI_CHARS ((MSDOS_SLOTS - 1) * 13 + 1)
+#define FAT_MAX_UNI_SIZE (FAT_MAX_UNI_CHARS * sizeof(wchar_t))
+
+/*
* Return values: negative -> error, 0 -> not found, positive -> found,
* value is the total amount of slots, including the shortname entry.
*/
@@ -340,15 +353,11 @@ int fat_search_long(struct inode *inode,
wchar_t bufuname[14];
wchar_t *unicode = NULL;
unsigned char work[MSDOS_NAME];
- unsigned char *bufname = NULL;
+ unsigned char bufname[FAT_MAX_SHORT_SIZE];
unsigned short opt_shortname = sbi->options.shortname;
loff_t cpos = 0;
int chl, i, j, last_u, err, len;
- bufname = __getname();
- if (!bufname)
- return -ENOMEM;
-
err = -ENOENT;
while (1) {
if (fat_get_entry(inode, &cpos, &bh, &de) == -1)
@@ -414,14 +423,17 @@ parse_record:
/* Compare shortname */
bufuname[last_u] = 0x0000;
- len = fat_uni_to_x8(sbi, bufuname, bufname, PATH_MAX);
+ len = fat_uni_to_x8(sbi, bufuname, bufname, sizeof(bufname));
if (fat_name_match(sbi, name, name_len, bufname, len))
goto found;
if (nr_slots) {
+ void *longname = unicode + FAT_MAX_UNI_CHARS;
+ int size = PATH_MAX - FAT_MAX_UNI_SIZE;
+
/* Compare longname */
- len = fat_uni_to_x8(sbi, unicode, bufname, PATH_MAX);
- if (fat_name_match(sbi, name, name_len, bufname, len))
+ len = fat_uni_to_x8(sbi, unicode, longname, size);
+ if (fat_name_match(sbi, name, name_len, longname, len))
goto found;
}
}
@@ -435,8 +447,6 @@ found:
sinfo->i_pos = fat_make_i_pos(sb, sinfo->bh, sinfo->de);
err = 0;
end_of_dir:
- if (bufname)
- __putname(bufname);
if (unicode)
__putname(unicode);
@@ -466,7 +476,8 @@ static int __fat_readdir(struct inode *i
unsigned char nr_slots;
wchar_t bufuname[14];
wchar_t *unicode = NULL;
- unsigned char c, work[MSDOS_NAME], bufname[56], *ptname = bufname;
+ unsigned char c, work[MSDOS_NAME];
+ unsigned char bufname[FAT_MAX_SHORT_SIZE], *ptname = bufname;
unsigned short opt_shortname = sbi->options.shortname;
int isvfat = sbi->options.isvfat;
int nocase = sbi->options.nocase;
@@ -620,11 +631,10 @@ parse_record:
fill_name = bufname;
fill_len = i;
if (!short_only && nr_slots) {
- /* convert the unicode long name. 261 is maximum size
- * of unicode buffer. (13 * slots + nul) */
- void *longname = unicode + 261;
- int buf_size = PATH_MAX - (261 * sizeof(unicode[0]));
- int long_len = fat_uni_to_x8(sbi, unicode, longname, buf_size);
+ void *longname = unicode + FAT_MAX_UNI_CHARS;
+ int long_len, size = PATH_MAX - FAT_MAX_UNI_SIZE;
+
+ long_len = fat_uni_to_x8(sbi, unicode, longname, size);
if (!both) {
fill_name = longname;
_
next prev parent reply other threads:[~2008-07-01 2:57 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-01 2:57 [PATCH 1/7] fat: Fix parse_options() OGAWA Hirofumi
2008-07-01 2:57 ` [PATCH 2/7] fat: Fix VFAT_IOCTL_READDIR_xxx and cleanup for userland OGAWA Hirofumi
2008-07-01 2:57 ` [PATCH 3/7] fat/dir.c: switch to struct __fat_dirent OGAWA Hirofumi
2008-07-01 2:57 ` [PATCH 4/7] fat: cleanup fs/fat/dir.c OGAWA Hirofumi
2008-07-01 2:57 ` OGAWA Hirofumi [this message]
2008-07-01 2:57 ` [PATCH 6/7] fat: small optimaize __fat_readdir() OGAWA Hirofumi
2008-07-01 2:57 ` [PATCH 7/7] Fix the case of jiffies wrapping in mm/pdflush.c OGAWA Hirofumi
2008-07-01 3:34 ` Andrew Morton
2008-07-01 4:05 ` OGAWA Hirofumi
2008-07-01 12:22 ` [PATCH 4/7] fat: cleanup fs/fat/dir.c Christoph Hellwig
2008-07-01 14:16 ` OGAWA Hirofumi
2008-07-01 3:32 ` [PATCH 3/7] fat/dir.c: switch to struct __fat_dirent Andrew Morton
2008-07-01 3:54 ` OGAWA Hirofumi
2008-07-01 7:40 ` [PATCH 2/7] fat: Fix VFAT_IOCTL_READDIR_xxx and cleanup for userland Christoph Hellwig
2008-07-01 8:33 ` OGAWA Hirofumi
2008-07-01 11:22 ` Adrian Bunk
2008-07-01 12:18 ` Christoph Hellwig
2008-07-01 12:20 ` Christoph Hellwig
2008-07-01 13:15 ` OGAWA Hirofumi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=555b858b3e848699cff511608.ps@mail.parknet.co.jp \
--to=hirofumi@mail.parknet.co.jp \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®