Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot reliably mount emulated storage under Linux #6

Open
JakubVanek opened this issue Mar 16, 2020 · 6 comments
Open

Cannot reliably mount emulated storage under Linux #6

JakubVanek opened this issue Mar 16, 2020 · 6 comments

Comments

@JakubVanek
Copy link

See microsoft/pxt-ev3#980

The dynamically-generated F_UF2 entries somehow cause mounting problems.

@JakubVanek
Copy link
Author

JakubVanek commented Mar 16, 2020

I think I have finally found it. Comparing the dumped file to the description on Wikipedia, there are multiple problems:

  1. Volume label directory entry (EV3) does not have cluster number set to zero.
  2. The cluster corresponding to the Projects directory table has the next cluster == 0x0000 (FREE), instead it should be 0xFFFF (EOF). (however see below, this may be caused by Linux).
  3. Linux requires a directory table to have at least two directory entries (https://github.com/torvalds/linux/blob/aeb542a1b5c507ea117d21c3e3e012ba16f065ac/fs/fat/inode.c#L497), which is not fulfilled there. The directory table contains only the DEMO.UF2 directory entry, which is not enough. There should be also the . and .. directories present. I think this may cause the issue above - when Linux detects this, it sets the next cluster pointer to zero.
  4. The dmesg.txt file has 512 blocks allocated in the FAT, but its directory entry lists it as only 256 blocks long.

@JakubVanek
Copy link
Author

Fixing just (2) and (3) in the dumped image is enough to make the drive mountable without problems. The solution is to add valid . and .. directory entries to the Projects directory table.
dirents

@JakubVanek
Copy link
Author

JakubVanek commented Mar 16, 2020

Problem no. 4 found:

c->numclusters = (c->st.st_size + 255) / 256;
(I think this should be 511/512).

EDIT: I am likely wrong with this, as it seems that the block size is supposed to be 256 bytes for passthrough files:

uf2-linux/uf2daemon/fat.c

Lines 334 to 337 in c003d65

if (c->flags & F_RAW)
c->numclusters = (c->st.st_size + 511) / 512;
else
c->numclusters = (c->st.st_size + 255) / 256;

@JakubVanek
Copy link
Author

JakubVanek commented Mar 16, 2020

Problem no. 1 maybe spotted:

It would seem to me that startCluster is what can be seen in the generated directory entry. Currently, it is set to the "current cluster", not to 0x0000.

It seems that UF2Daemon generates this correctly, but as soon as the Linux kernel mounts the FS, it sets the FAT entries to zero.

@lfrie
Copy link

lfrie commented Mar 26, 2020

when is this fixed? i have the same issue

@JakubVanek
Copy link
Author

I'm sorry but I currently don't have much time to work on this. Also, fixing this here would fix the problem only for new releases of uf2d (which is the first step though); it would then have to be fixed with a firmware update for the problematic device (if your device is not fully under your control like with Raspberry Pi).

fengguang pushed a commit to 0day-ci/linux that referenced this issue Feb 4, 2022
This reverts commit a3082d5.

The reverted commit adds check for FAT images. However, 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

With the patch reverted, we can mount an image copied from the EV3

Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
joelagnel pushed a commit to joelagnel/linux-kernel that referenced this issue Jun 19, 2022
This reverts commit a3082d5.

The reverted commit adds check for FAT images. However, 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

With the patch reverted, we can mount an image copied from the EV3

Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
(am from https://lore.kernel.org/r/20220204062232.3410036-1-gwendal@chromium.org)

BUG=b:205899437
TEST=With the patch reverted, we can mount an image copied from
the EV3

Change-Id: I731be37a6305e4d5378ac4d31817adcbd43e9c62
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/3430762
Tested-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-by: Daniil Lunev <dlunev@chromium.org>
Commit-Queue: Gwendal Grignou <gwendal@chromium.org>
(cherry picked from commit f67697eb16412d5a1b5a633b619e129425afcec0)
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/3498707
joelagnel pushed a commit to joelagnel/linux-kernel that referenced this issue Aug 9, 2022
This reverts commit a3082d5.

The reverted commit adds check for FAT images. However, 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

With the patch reverted, we can mount an image copied from the EV3

Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
(am from https://lore.kernel.org/r/20220204062232.3410036-1-gwendal@chromium.org)

BUG=b:205899437
TEST=With the patch reverted, we can mount an image copied from
the EV3

Change-Id: I731be37a6305e4d5378ac4d31817adcbd43e9c62
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/3430762
Tested-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-by: Daniil Lunev <dlunev@chromium.org>
Commit-Queue: Gwendal Grignou <gwendal@chromium.org>
(cherry picked from commit f67697eb16412d5a1b5a633b619e129425afcec0)
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/3498707
disantkumar pushed a commit to disantkumar/intel-mainline-tracking that referenced this issue Oct 16, 2023
This reverts commit a3082d5.

The reverted commit adds check for FAT images. However, 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

With the patch reverted, we can mount an image copied from the EV3

Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
(am from https://lore.kernel.org/r/20220204062232.3410036-1-gwendal@chromium.org)

BUG=b:205899437
TEST=With the patch reverted, we can mount an image copied from
the EV3

Change-Id: I731be37a6305e4d5378ac4d31817adcbd43e9c62
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/3430762
Tested-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-by: Daniil Lunev <dlunev@chromium.org>
Commit-Queue: Gwendal Grignou <gwendal@chromium.org>
(cherry picked from commit f67697eb16412d5a1b5a633b619e129425afcec0)
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/3498707
intel-lab-lkp pushed a commit to intel-lab-lkp/linux that referenced this issue Jun 25, 2024
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 <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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants