From: Thadeu Lima de Souza Cascardo <cascardo@igalia.com>
To: linux-fsdevel@vger.kernel.org
Cc: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>,
linux-kernel@vger.kernel.org,
Gwendal Grignou <gwendal@chromium.org>,
dlunev@chromium.org,
Thadeu Lima de Souza Cascardo <cascardo@igalia.com>
Subject: [PATCH v2 1/2] fat: ignore . and .. subdirs and always add links to dirs
Date: Tue, 25 Jun 2024 14:51:32 -0300 [thread overview]
Message-ID: <20240625175133.922758-2-cascardo@igalia.com> (raw)
In-Reply-To: <20240625175133.922758-1-cascardo@igalia.com>
The tools used for creating images for the Lego Mindstrom EV3 are not
adding '.' and '..' entry in the 'Projects' directory.
Without this fix, the kernel can not fill the inode structure for
'Projects' directory.
See https://github.com/microsoft/pxt-ev3/issues/980
And https://github.com/microsoft/uf2-linux/issues/6
When counting the number of subdirs, ignore . and .. subdirs and add two
when setting the initial link count for directories. This way, the number
of links is always correctly accounted for.
With this fix applied, we can mount an image with such empty directories,
access them, create subdirectories and remove them.
This also prevents corrupting such filesystems as when the inodes would be
put, since no links were accounted for, all of its clusters would be marked
as free.
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@igalia.com>
Cc: Gwendal Grignou <gwendal@chromium.org>
Link: https://lore.kernel.org/all/20220204062232.3410036-1-gwendal@chromium.org/
Cc: dlunev@chromium.org
---
fs/fat/dir.c | 4 +++-
fs/fat/inode.c | 2 +-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/fs/fat/dir.c b/fs/fat/dir.c
index acbec5bdd521..4e4a359a1ea3 100644
--- a/fs/fat/dir.c
+++ b/fs/fat/dir.c
@@ -949,7 +949,9 @@ int fat_subdirs(struct inode *dir)
bh = NULL;
cpos = 0;
while (fat_get_short_entry(dir, &cpos, &bh, &de) >= 0) {
- if (de->attr & ATTR_DIR)
+ if (de->attr & ATTR_DIR &&
+ strncmp(de->name, MSDOS_DOT , MSDOS_NAME) &&
+ strncmp(de->name, MSDOS_DOTDOT, MSDOS_NAME))
count++;
}
brelse(bh);
diff --git a/fs/fat/inode.c b/fs/fat/inode.c
index d9e6fbb6f246..234c244d1252 100644
--- a/fs/fat/inode.c
+++ b/fs/fat/inode.c
@@ -534,7 +534,7 @@ int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de)
return error;
MSDOS_I(inode)->mmu_private = inode->i_size;
- set_nlink(inode, fat_subdirs(inode));
+ set_nlink(inode, fat_subdirs(inode)+2);
error = fat_validate_dir(inode);
if (error < 0)
--
2.34.1
next prev parent reply other threads:[~2024-06-25 17:51 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-25 17:51 [PATCH v2 0/2] fat: add support for directories without . and .. entries Thadeu Lima de Souza Cascardo
2024-06-25 17:51 ` Thadeu Lima de Souza Cascardo [this message]
2024-06-25 17:51 ` [PATCH v2 2/2] fat: always use dir_emit_dots and ignore " Thadeu Lima de Souza Cascardo
2024-06-25 21:47 ` OGAWA Hirofumi
2024-06-26 19:46 ` Thadeu Lima de Souza Cascardo
2024-06-26 20:10 ` OGAWA Hirofumi
2024-06-27 12:51 ` Thadeu Lima de Souza Cascardo
2024-06-27 15:28 ` 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=20240625175133.922758-2-cascardo@igalia.com \
--to=cascardo@igalia.com \
--cc=dlunev@chromium.org \
--cc=gwendal@chromium.org \
--cc=hirofumi@mail.parknet.co.jp \
--cc=linux-fsdevel@vger.kernel.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®