1
0
Fork 0
remarkable-uboot/fs
Stephen Warren 18a10d46f2 fat: handle paths that include ../
The FAT code contains a special case to parse the root directory. This
is needed since the root directory location/layout on disk is special
cased for FAT12/16. In particular, the location and size of the FAT12/16
root directory is hard-coded and contiguous, whereas all FAT12/16 non-root
directories, and all FAT32 directories, are stored in a non-contiguous
fashion, with the layout represented by a linked-list of clusters in the
FAT.

If a file path contains ../ (for example /extlinux/../bcm2835-rpi-cm.dtb),
it is possible to need to parse the root directory for the first element
in the path (requiring application of the special case), then a sub-
directory (in the general way), then re-parse the root directory (again
requiring the special case). However, the current code in U-Boot only
applies the special case for the very first path element, and never for
any later path element. When reparsing the root directory without
applying the special case, any file in a sector (or cluster?) other than
the first sector/cluster of the root directory will not be found.

This change modifies the non-root-dir-parsing loop of do_fat_read_at()
to detect if it's walked back to the root directory, and if so, jumps
back to the special case code that handles parsing of the root directory.

This change was tested using sandbox by executing:

./u-boot -c "host bind 0 ../sd-p1.bin; ls host 0:0"
./u-boot -c "host bind 0 ../sd-p1.bin; ls host 0:0 /"
./u-boot -c "host bind 0 ../sd-p1.bin; ls host 0:0 /extlinux"
./u-boot -c "host bind 0 ../sd-p1.bin; ls host 0:0 /extlinux/"
./u-boot -c "host bind 0 ../sd-p1.bin; ls host 0:0 /extlinux/.."
./u-boot -c "host bind 0 ../sd-p1.bin; ls host 0:0 /extlinux/../"
./u-boot -c "host bind 0 ../sd-p1.bin; ls host 0:0 /extlinux/../backup"
./u-boot -c "host bind 0 ../sd-p1.bin; ls host 0:0 /extlinux/../backup/"
./u-boot -c "host bind 0 ../sd-p1.bin; ls host 0:0 /extlinux/../backup/.."
./u-boot -c "host bind 0 ../sd-p1.bin; ls host 0:0 /extlinux/../backup/../"
./u-boot -c "host bind 0 ../sd-p1.bin; load host 0:0 0 /bcm2835-rpi-cm.dtb"
./u-boot -c "host bind 0 ../sd-p1.bin; load host 0:0 0 /extlinux/../bcm2835-rpi-cm.dtb"
./u-boot -c "host bind 0 ../sd-p1.bin; load host 0:0 0 /backup/../bcm2835-rpi-cm.dtb"
./u-boot -c "host bind 0 ../sd-p1.bin; load host 0:0 0 /extlinux/..backup/../bcm2835-rpi-cm.dtb"
./u-boot -c "host bind 0 ../sd-p1.bin; load host 0:0 0 /extlinux/../backup/../bcm2835-rpi-cm.dtb"

(/extlinux and /backup are in different sectors so trigger some different
cases, and bcm2835-rpi-cm.dtb is in a sector of the root directory other
than the first).

In all honesty, this change is a bit of a hack, using goto and all.
However, as demonstrated above it appears to work well in practice, is
quite minimal, likely doesn't introduce any risk of regressions, and
hopefully doesn't introduce any maintenance issues.

The correct fix would be to collapse the root and non-root loops in
do_fat_read_at() and get_dentfromdir() into a single loop that has a
small special-case when moving from one sector to the next, to handle
the layout difference of root/non-root directories. AFAIK all other
aspects of directory parsing are identical. However, that's a much
larger change which needs significantly more thought before it's
implemented.

Signed-off-by: Stephen Warren <swarren@wwwdotorg.org>
2015-09-11 14:05:33 -04:00
..
cbfs fs: descend into sub directories when it is necessary 2013-11-17 14:11:34 -05:00
cramfs kconfig: add blank Kconfig files 2014-09-24 18:30:28 -04:00
ext4 fs: ext4 write: return file len on success 2015-03-05 20:49:42 -05:00
fat fat: handle paths that include ../ 2015-09-11 14:05:33 -04:00
jffs2 JFFS2: Use merge sort when parsing filesystem 2015-08-12 20:47:32 -04:00
reiserfs kconfig: add blank Kconfig files 2014-09-24 18:30:28 -04:00
sandbox sandbox: only do sandboxfs for hostfs interface 2015-04-19 14:45:56 -06:00
ubifs mtd/nand/ubi: assortment of alignment fixes 2015-08-28 12:33:17 -04:00
yaffs2 lib, linux: move linux specific defines to linux/compat.h 2014-08-25 19:25:03 -04:00
zfs ZFS: Clean up cppcheck warnings where relevant, leaked memory etc 2014-11-10 16:25:27 -05:00
Kconfig kconfig: add blank Kconfig files 2014-09-24 18:30:28 -04:00
Makefile spl: Add EXT support to SPL 2014-10-27 17:54:03 -04:00
fs.c fs/fs.c: read up to EOF when len would read past EOF 2015-08-13 07:19:35 -04:00