Skip to contentSkip to conversation

hfsplus: emit symlinks from readdir properly

PATCH In review Sergei Antonov 2 participants 3 messages May 7, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hfsplus: emit symlinks from readdir properly

hfsplus_readdir() did not return DT_LNK record type for symbolic links. It emitted them as regular files (DT_REG). Programs relying on information from readdir did not work correctly with HFS+.

CC Al Viro <[email protected]>
CC Christoph Hellwig <[email protected]>
CC Andrew Morton <[email protected]>
CC Vyacheslav Dubeyko <[email protected]>
CC Hin-Tak Leung <[email protected]>
---
 fs/hfsplus/dir.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/hfsplus/dir.c +5 -1
index bdec665..c5ccb11 100644
@@ -212,13 +212,17 @@ 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;
+
 			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 (!dir_emit(ctx, strbuf, len,
-				    be32_to_cpu(entry.file.id), DT_REG))
+				      be32_to_cpu(entry.file.id),
+				      S_ISLNK(mode) ? DT_LNK : DT_REG))
 				break;
 		} else {
 			pr_err("bad catalog entry type\n");
Signature · 1 line
1.9.0
#1 lore raw

Hi Sergei,

Quoted 4 lines · Sergei Antonov

hfsplus_readdir() did not return DT_LNK record type for symbolic links. It emitted them as regular files (DT_REG). Programs relying on information from readdir did not work correctly with HFS+.

This patch looks good for me. But what about another file types (S_IFIFO, S_IFCHR, S_IFBLK, S_IFSOCK)?

Thanks,
Vyacheslav Dubeyko.

Quoted 33 lines
CC Al Viro <[email protected]>
CC Christoph Hellwig <[email protected]>
CC Andrew Morton <[email protected]>
CC Vyacheslav Dubeyko <[email protected]>
CC Hin-Tak Leung <[email protected]>
---
 fs/hfsplus/dir.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/hfsplus/dir.c +5 -1
index bdec665..c5ccb11 100644
@@ -212,13 +212,17 @@ 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;
+
 			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 (!dir_emit(ctx, strbuf, len,
-				    be32_to_cpu(entry.file.id), DT_REG))
+				      be32_to_cpu(entry.file.id),
+				      S_ISLNK(mode) ? DT_LNK : DT_REG))
 				break;
 		} else {
 			pr_err("bad catalog entry type\n");
#2 lore raw
Quoted 10 lines · Vyacheslav Dubeyko

Hi Sergei,

Quoted 4 lines · Sergei Antonov

hfsplus_readdir() did not return DT_LNK record type for symbolic links. It emitted them as regular files (DT_REG). Programs relying on information from readdir did not work correctly with HFS+.

This patch looks good for me. But what about another file types (S_IFIFO, S_IFCHR, S_IFBLK, S_IFSOCK)?

I will resubmit to support them too. Thanks.
In this patch I tried to fix the problem I faced (and it was with symlinks). Now I see that the fix can be broader. Resubmitting in a minute.

Quoted 38 lines

Thanks,
Vyacheslav Dubeyko.

Quoted 33 lines
CC Al Viro <[email protected]>
CC Christoph Hellwig <[email protected]>
CC Andrew Morton <[email protected]>
CC Vyacheslav Dubeyko <[email protected]>
CC Hin-Tak Leung <[email protected]>
---
 fs/hfsplus/dir.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/hfsplus/dir.c +5 -1
index bdec665..c5ccb11 100644
@@ -212,13 +212,17 @@ 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;
+
                      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 (!dir_emit(ctx, strbuf, len,
-                                 be32_to_cpu(entry.file.id), DT_REG))
+                                   be32_to_cpu(entry.file.id),
+                                   S_ISLNK(mode) ? DT_LNK : DT_REG))
                              break;
              } else {
                      pr_err("bad catalog entry type\n");