Skip to content

Commit

Permalink
fat: ignore . and .. subdirs and always add links to dirs
Browse files Browse the repository at this point in the history
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 microsoft/pxt-ev3#980
And microsoft/uf2-linux#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 <[email protected]>
Cc: Gwendal Grignou <[email protected]>
Link: https://lore.kernel.org/all/[email protected]/
Cc: [email protected]
  • Loading branch information
Thadeu Lima de Souza Cascardo authored and intel-lab-lkp committed Jun 25, 2024
1 parent 55027e6 commit ed5a3cb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion fs/fat/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion fs/fat/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ed5a3cb

Please sign in to comment.