[syslinux:pathbased] ext2: return the correct file types from readdir()
syslinux-bot for H. Peter Anvin
hpa at zytor.com
Sat Mar 6 15:09:04 PST 2010
Commit-ID: dfcce638fab9ff25660ebf5207000964a1aa64ef
Gitweb: http://syslinux.zytor.com/commit/dfcce638fab9ff25660ebf5207000964a1aa64ef
Author: H. Peter Anvin <hpa at zytor.com>
AuthorDate: Sat, 6 Mar 2010 15:07:53 -0800
Committer: H. Peter Anvin <hpa at zytor.com>
CommitDate: Sat, 6 Mar 2010 15:07:53 -0800
ext2: return the correct file types from readdir()
Return the global file types, not the ext2-specific ones.
Signed-off-by: H. Peter Anvin <hpa at zytor.com>
---
core/fs/ext2/ext2.c | 26 +++++++++++++++++++++-----
1 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/core/fs/ext2/ext2.c b/core/fs/ext2/ext2.c
index 44f28f9..cbc0378 100644
--- a/core/fs/ext2/ext2.c
+++ b/core/fs/ext2/ext2.c
@@ -3,13 +3,29 @@
#include <string.h>
#include <sys/dirent.h>
#include <minmax.h>
-#include <cache.h>
-#include <core.h>
-#include <disk.h>
-#include <fs.h>
+#include "cache.h"
+#include "core.h"
+#include "disk.h"
+#include "fs.h"
#include "ext2_fs.h"
/*
+ * Convert an ext2 file type to the global values
+ */
+static enum inode_mode ext2_cvt_type(unsigned int d_file_type)
+{
+ static const enum inode_mode inode_type[] = {
+ I_UNKNOWN, I_FILE, I_DIR, I_CHR,
+ I_BLK, I_FIFO, I_SOCK, I_SYMLINK,
+ };
+
+ if (d_file_type > sizeof inode_type / sizeof *inode_type)
+ return I_UNKNOWN;
+ else
+ return inode_type[d_file_type];
+}
+
+/*
* get the group's descriptor of group_num
*/
static const struct ext2_group_desc *
@@ -251,7 +267,7 @@ static int ext2_readdir(struct file *file, struct dirent *dirent)
dirent->d_ino = de->d_inode;
dirent->d_off = file->offset;
dirent->d_reclen = offsetof(struct dirent, d_name) + de->d_name_len + 1;
- dirent->d_type = de->d_file_type;
+ dirent->d_type = ext2_cvt_type(de->d_file_type);
memcpy(dirent->d_name, de->d_name, de->d_name_len);
dirent->d_name[de->d_name_len] = '\0';
More information about the Syslinux-commits
mailing list