Merge branch 'akpm' (fixes from Andrew Morton)
[linux-2.6-microblaze.git] / fs / hfsplus / dir.c
index bdec665..610a326 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/fs.h>
 #include <linux/slab.h>
 #include <linux/random.h>
+#include <linux/nls.h>
 
 #include "hfsplus_fs.h"
 #include "hfsplus_raw.h"
@@ -127,7 +128,7 @@ static int hfsplus_readdir(struct file *file, struct dir_context *ctx)
        struct inode *inode = file_inode(file);
        struct super_block *sb = inode->i_sb;
        int len, err;
-       char strbuf[HFSPLUS_MAX_STRLEN + 1];
+       char *strbuf;
        hfsplus_cat_entry entry;
        struct hfs_find_data fd;
        struct hfsplus_readdir_data *rd;
@@ -139,6 +140,11 @@ static int hfsplus_readdir(struct file *file, struct dir_context *ctx)
        err = hfs_find_init(HFSPLUS_SB(sb)->cat_tree, &fd);
        if (err)
                return err;
+       strbuf = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_MAX_STRLEN + 1, GFP_KERNEL);
+       if (!strbuf) {
+               err = -ENOMEM;
+               goto out;
+       }
        hfsplus_cat_build_key(sb, fd.search_key, inode->i_ino, NULL);
        err = hfs_brec_find(&fd, hfs_find_rec_by_key);
        if (err)
@@ -193,7 +199,7 @@ static int hfsplus_readdir(struct file *file, struct dir_context *ctx)
                hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
                        fd.entrylength);
                type = be16_to_cpu(entry.type);
-               len = HFSPLUS_MAX_STRLEN;
+               len = NLS_MAX_CHARSET_SIZE * HFSPLUS_MAX_STRLEN;
                err = hfsplus_uni2asc(sb, &fd.key->cat.name, strbuf, &len);
                if (err)
                        goto out;
@@ -212,13 +218,31 @@ static int hfsplus_readdir(struct file *file, struct dir_context *ctx)
                                    be32_to_cpu(entry.folder.id), DT_DIR))
                                break;
                } else if (type == HFSPLUS_FILE) {
+                       u16 mode;
+                       unsigned type = DT_UNKNOWN;
+
                        if (fd.entrylength < sizeof(struct hfsplus_cat_file)) {
                                pr_err("small file entry\n");
                                err = -EIO;
                                goto out;
                        }
+
+                       mode = be16_to_cpu(entry.file.permissions.mode);
+                       if (S_ISREG(mode))
+                               type = DT_REG;
+                       else if (S_ISLNK(mode))
+                               type = DT_LNK;
+                       else if (S_ISFIFO(mode))
+                               type = DT_FIFO;
+                       else if (S_ISCHR(mode))
+                               type = DT_CHR;
+                       else if (S_ISBLK(mode))
+                               type = DT_BLK;
+                       else if (S_ISSOCK(mode))
+                               type = DT_SOCK;
+
                        if (!dir_emit(ctx, strbuf, len,
-                                   be32_to_cpu(entry.file.id), DT_REG))
+                                     be32_to_cpu(entry.file.id), type))
                                break;
                } else {
                        pr_err("bad catalog entry type\n");
@@ -246,6 +270,7 @@ next:
        }
        memcpy(&rd->key, fd.key, sizeof(struct hfsplus_cat_key));
 out:
+       kfree(strbuf);
        hfs_find_exit(&fd);
        return err;
 }