summaryrefslogtreecommitdiff
path: root/libfstools
Commit message (Collapse)AuthorAgeFilesLines
* libfstools: Rename move_mount() function to ovl_move_mount() for glibc 2.36Hauke Mehrtens2022-08-071-3/+3
| | | | | | | | glibc in version 2.36 defines an own function named move_mount() in some header. The definition from glibc collides with our definition, just rename the function in fstools. Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
* libfstools: handle gzip return value in block_volume_formatChristian Marangi2022-07-171-1/+5
| | | | | | | | | | | | Fix the following compilation warning: libfstools/common.c: In function 'block_volume_format': libfstools/common.c:120:17: error: ignoring return value of 'system' declared with attribute 'warn_unused_result' [-Werror=unused-result] 120 | system(str); | ^~~~~~~~~~~ Correctly handle return value from gzip and print an error on such case. Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
* Revert "fstools: remove SELinux restorecon hack"Daniel Golle2022-06-023-0/+27
| | | | | | | | | | Now that procd only relables the filesystem in case of the system beging started with initramfs we will again need to take care of labeling newly created /overlay. This reverts commit 9e11b3723ce30b9b8c94ad7d15072a10cf13c0b4. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* fstools: remove SELinux restorecon hackDaniel Golle2022-05-033-27/+0
| | | | | | | Now that procd takes care of it properly we no longer need this hack. Remove it to safe some space also on non-SELinux systems. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* libfstools: mtd: improve error handlingDaniel Golle2022-05-011-6/+4
| | | | | | | | Use -1 to mark invalid file descriptors as 0 can theoretically be a valid open file descriptor. Do not ignore lseek() return value and check if an error has occured. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* libfstools: avoid segfault in find_mount_pointStijn Tintel2022-02-051-0/+3
| | | | | | | | If block is NULL, find_mount_point will segfault when comparing it against the device name found in /proc/self/mountinfo. Avoid this by checking if block is NULL. Signed-off-by: Stijn Tintel <stijn@linux-ipv6.be>
* libfstools: use variable for overlay mount-pointRafał Miłecki2022-01-111-9/+10
| | | | | | This avoids duplicating path over and over. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* libfstools: get rid of "extroot_prefix" global variableRafał Miłecki2022-01-113-10/+3
| | | | | | | Replace it with mount_extroot() argument. It's cleaner than a global var. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* Update / fix extroot commentsRafał Miłecki2022-01-111-0/+4
| | | | | | | | Comment in start() was invalid as mount_extroot() doesn't handle any mounting internally. It was a misunderstanding coming from block.c function called just the same. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* libfstools: check for overlay mounting errorsRafał Miłecki2022-01-111-1/+4
| | | | Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* fstools: fix a couple of minor code problemsDaniel Golle2021-11-165-14/+39
| | | | | | Improve error handling and fix a resource leak inside an error path. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* libfstools: use uevent instead of relying on custom kernel patchDaniel Golle2021-11-011-10/+13
| | | | | | | | Detect partition name based on 'uevent' instead of relying in custom kernel patch exposing 'name' in sysfs directly. This will allow to drop the custom patch again. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* libfstools: make sure file is closed on errorDaniel Golle2021-11-011-1/+3
| | | | | Coverity CID: 1330286 Resource leak Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* libfstools: handle open() return value properly in F2FS checkDaniel Golle2021-08-251-0/+4
| | | | | | Coverity CID: 1490101 Argument cannot be negative Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* overlay: fix syncronizing typoPetr Štetiar2021-04-071-1/+1
| | | | | | So it's now correct `synchronizing`. Signed-off-by: Petr Štetiar <ynezz@true.cz>
* partname: allow skipping existing 'rootfs_data' partitionDaniel Golle2021-03-191-1/+6
| | | | | | | | | | | | Apparently some devices with eMMC (e.g. ZyXEL NBG6817) got an exsiting GPT partition called 'rootfs_data'. This partition is then selected as rootfs_data eventhough it may not be suitable for that (too small) or serve another purpose (ie. used by vendor firmware). To avoid this, check if the kernel cmdline contains a variable fstools_ignore_partname=1 and if so, skip partname detection of volumes alltogether. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* libfstools: remove superflus includeDaniel Golle2021-03-081-3/+0
| | | | | | | Turns out C header file <stropts.h> is unneeded after all. Remove it. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* libfstools: fix build with glibcDaniel Golle2021-03-051-0/+2
| | | | | | | | | stropts.h which is unavailable under glibc (and not needed when building against glibc). Include it only if not building against glibc. Reported by: @DazzyWalkman Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* libfstools: partname: several fixesDaniel Golle2021-03-021-16/+30
| | | | | | | | | | | partname driver didn't allow mount_root to identify the filesystem and hence the overlay filesystem state remained PENDING which lead to overlay being cleared again at every reboot. Fix that by setting v->blk early and, while at it, eliminate unneeded strdup's by storing the full device paths in a union allowing accessing the full path or the device name only. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* fstools: add partname volume driverDaniel Golle2021-02-276-126/+325
| | | | | | | | | | | | Add driver to handle block devices with (GPT) partition table which can include a partition name. If 'root=' is set on the kernel cmdline, only search for partitions on the same device. Among with other changes (ptgen, image*.mk, base-files, ...) this allows for a much more straight forward storage model on block based devices. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* mount: restorecon: guard against execl() errorsDaniel Golle2020-12-121-1/+1
| | | | | | | | | | In the current implementation, in case of execl("/sbin/restorecon") failing, the child process will also return and that will lead to even more disasterous effects. Though it seems unlikely that execl() would fail given that the file exists, simply catch that case by exiting in case execl() returns. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* mount: apply SELinux labels before overlayfs mountDaniel Golle2020-10-163-0/+28
| | | | | | Use restorecon to apply SELinux labels if applicable. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* overlay: use precompiler macros for reoccuring path namesDaniel Golle2020-10-161-4/+5
| | | | Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* mount: fix log format string and indentationDaniel Golle2020-10-161-2/+2
| | | | Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* mount: remove support for legacy overlayfs before v2.3Daniel Golle2020-10-161-36/+22
| | | | | | | overlayfs has been in mainline since Linux v3.18 (OpenWrt CC 15.05). Remove support for pre-mainline overlayfs. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* fstoools: add define for GLOB_ONLYDIRRosen Penev2020-07-111-0/+4
| | | | | | | | | This was originally a patch for musl. It is not present in musl as it is a GNU extension. Place it here where it belongs. Signed-off-by: Rosen Penev <rosenp@gmail.com>
* Use autoclear for overlay loopback deviceDavid Woodhouse2020-06-171-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | During a sysupgrade on a block-based device, the partition table might get updated. The partitions have to be completely unused by the time partx is invoked, or it fails thus: partx: /dev/mmcblk1: error deleting partition 3 partx: /dev/mmcblk1: error adding partition 3 That's cosmetic in some cases, but in others where the old root partition overlaps with the new partition where the config is stored during the reboot, it causes a sysugprade failure (resulting in the backup being lost and a completely clean system image). Although we carefully unmount the root and overlay file systems, the problem is that the loopback device used for the overlay isn't being torn down, and it still has a refcount on the root block partition (in the above case, /dev/mmcblk1p3). Installing losetup and adding 'losetup -D' to the switch_to_ramfs() function makes it work nicely. But the better option that doesn't add a new dependency is to use the autoclear flag when setting up the loop device, so it goes away automatically when the overlay file system is unmounted. To make that work sanely, we have to *not* close the fd right after configuring it — or it'll go away immediately. We could store the fd in the volume struct and either add destructor method or close it after performing the mount… but honestly it just seems simpler and saner to "leak" the fd in the knowledge that it'll get closed when the process exits in a few milliseconds anyway. We can revisit that if anyone really feels strongly about it. Dissent is best expressed in 'diff -up' form. Signed-off-by: David Woodhouse <dwmw2@infradead.org>
* libfstools/mtd: attempt to read from OOB data if empty space is foundFelix Fietkau2020-04-091-4/+12
| | | | | | | When using jffs2 on NAND flash, it stores its magic in the OOB data on newly erased blocks. This change fixes identifying the filesystem type. Signed-off-by: Felix Fietkau <nbd@nbd.name>
* Revert "fstools: Add support to read-only MTD partitions (eg. recovery images)"Petr Štetiar2020-01-211-15/+4
| | | | | | | | | | | | | This reverts commit f5c7c1813f52e6d7b59ecfb2f9f95e69b05b1980 which needs more work and testing as it broke at least jffs2 overlays at least on ath79 platform, marking them as read-only, thus unusable: jffs2_build_filesystem(): erasing all blocks after the end marker... jffs2: Erase at 0x009e0000 failed immediately: -EROFS. Is the sector locked? Ref: http://lists.infradead.org/pipermail/openwrt-devel/2020-January/021344.html Reported-by: Steve Brown <sbrown@ewol.com> Signed-off-by: Petr Štetiar <ynezz@true.cz>
* fstools: Add support to read-only MTD partitions (eg. recovery images)Bruno Pena2020-01-181-4/+15
| | | | | | | | | | | | This patch enables fstools to open read-only MTD partitions, which in turn also enables OpenWrt to boot from read-only partitions. The use of read-only partitions is of special importance for WiFi-only devices, where a protected read-only recovery image can be used in case something goes wrong with the main firmware (eg. user gets locked out due to bad settings, flash of an unbootable dev firmware, etc). Signed-off-by: Bruno Pena <brunompena@gmail.com>
* libfstools: avoid false positives when matching devices and volumesJo-Philipp Wich2019-03-312-4/+4
| | | | | | | | Revise matching code using strncmp() in order to avoid returning wrong items, e.g. /dev/sda1 when /dev/sda was requested. Ref: https://bugs.openwrt.org/index.php?do=details&task_id=2196 Signed-off-by: Jo-Philipp Wich <jo@mein.io>
* libfstools: Fix overflow of F2FS_MINSIZE constantPetr Štetiar2019-03-281-1/+1
| | | | | | | | | I wasn't able to to use f2fs on armvirt/32 platform and I've found out that it was due to F2FS_MINSIZE constant overflow leading to value of 13 exabytes instead of 100 megabytes. Acked-by: Jo-Philipp Wich <jo@mein.io> Signed-off-by: Petr Štetiar <ynezz@true.cz>
* libfstools: Print error in case of loop blkdev failurePetr Štetiar2019-03-281-1/+3
| | | | | | | | | | It took me quite some time today(while fixing squashfs+overlay on armvirt) to find out, that I was missing support for loop block device in kernel, so I'm adding error message which might be helpful for someone else in the future as well. Acked-by: Jo-Philipp Wich <jo@mein.io> Signed-off-by: Petr Štetiar <ynezz@true.cz>
* fstools: allow the mounting with full access time accountingPierre Lebleu2018-05-241-1/+6
| | | | | | | | In order to allow the mounting of the filesystem with full access time accounting, a new CMake option (eg: CMAKE_OVL_MOUNT_FULL_ACCESS_TIME) has been added. Signed-off-by: Pierre Lebleu <pme.lebleu@gmail.com>
* fstools: allow to compress the filesystemPierre Lebleu2018-05-241-1/+7
| | | | | | | In order to allow the mounting of the filesystem with the zlib compression, a new CMake option (eg: CMAKE_OVL_MOUNT_COMPRESS_ZLIB) has been added. Signed-off-by: Pierre Lebleu <pme.lebleu@gmail.com>
* libfstools: move mount points when switching to JFFS2Rafał Miłecki2018-04-161-1/+45
| | | | | | | | | | | | | | | Switching from "tmpfs" to "jffs2" happens after JFFS2 formatting is done. During that time user can use filesystem (thanks to RAM) and the role of switch2jffs() is to copy all changes to the JFFS2 overlay partition. What wasn't handled so far was moving mount points. User can create custom mounts, cp command won't copy them and umounting "tmpfs" will cause these mounts to go away. To preserve them switch2jffs() has to find all custom mount points and move them to the new filesystem. Signed-off-by: Rafał Miłecki <rafal@milecki.pl> Acked-by: John Crispin <john@phrozen.org>
* libfstools: add "const" to char pointer arguments in mount_move()Rafał Miłecki2018-04-162-2/+2
| | | | | | | | That function never modifies these strings so it can/should use consts. It makes it a bit more flexible as now callers can also pass consts. Signed-off-by: Rafał Miłecki <rafal@milecki.pl> Acked-by: John Crispin <john@phrozen.org>
* libfstools: fix foreachdir() to pass dir with a trailing slashRafał Miłecki2018-04-161-2/+12
| | | | | | | | | | | | | | | | | | | | | | | Commit cc63723d886fd ("overlay: use lstat rather than stat and make sure there are no trailing spaces") changed behavior of foreachdir() breaking some callbacks. Before that modification all callbacks were getting directory with a trailing slash. Above commit started removing them. This broke handle_whiteout() which doesn't work at all since then. It constructs file paths incorrectly: slash is missing between directory and a file name. It seems noone noticed it for years because this issue got hidden by switch2jffs() which also handles whiteouts with its system command "cp -a" call. Fix that regression by setting trailing slash back - right after calling lstat(). Also to keep code simple just skip all entries that aren't directories. This keeps conditions for removing/setting trailing slash trivial. A side effect is not calling callbacks for files which is a free bonus optimization. Fixes: cc63723d886fd ("overlay: use lstat rather than stat and make sure there are no trailing spaces") Signed-off-by: Rafał Miłecki <rafal@milecki.pl> Acked-by: John Crispin <john@phrozen.org>
* overlay: fix compilation with glibcRoman Yeryomin2018-01-131-1/+2
| | | | | | | | | | | | | glibc fails with: warn_unused_result [-Wunused-result] system("cp -a /tmp/root/upper/* / 2>/dev/null"); Regression intoroduced with 11efbf3b90f031ce634fc38cad07a4aef2985777 Reported here: https://www.mail-archive.com/lede-dev@lists.infradead.org/msg10502.html Signed-off-by: Roman Yeryomin <roman@advem.lv> Acked-by: Florian Fainelli <f.fainelli@gmail.com>
* libfstools: optimize building directory string for globRafał Miłecki2018-01-071-4/+1
| | | | | | | glob should handle paths like /foo/bar//* so we probably don't need this extra check & code. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* libfstools: support file paths longer than 255 charsRafał Miłecki2018-01-051-4/+18
| | | | | | | | Alloc globdir buffer dynamically and simply use realloc when needed. This fixes e.g. segmentation fault in jffs2reset due to an infinite recurrency when dealing with longs paths. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* overlay: fix race condition when switching to jffs2Roman Yeryomin2018-01-021-0/+4
| | | | | | | | | | | | | | | | There is a race between `cp -a /tmp/root/* /rom/overlay` from libfstools/overlay.c and a process creating new file(s) before pivot(/rom, /mnt) occured. That is a process can create a file and it will not be copied. To workaround this, do additional copy after jffs2 is ready. This doesn't completely solve the problem but since there was no other fix provided since original RFC [1], it is better than nothiing. [1] https://www.mail-archive.com/openwrt-devel@lists.openwrt.org/msg38218.html Signed-off-by: Roman Yeryomin <roman@advem.lv>
* fstools: Replace strerror(errno) with %m format.Rosen Penev2017-12-124-17/+16
| | | | | | Saves 1472 bytes under glibc. No other difference. Signed-off-by: Rosen Penev <rosenp@gmail.com>
* libfstools: fix matching device nameDaniel Golle2017-06-301-3/+2
| | | | | | | | | | compare strlen()+1 characters to make sure we match the trailing \0 as well. Otherwise things get fishy when using lvm2, see this example: /dev/mapper/data: UUID="xxxxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxxxx" MOUNT="/mnt" TYPE="LVM2_member" /dev/mapper/data-fs: UUID="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" LABEL="xxxxxxxx" VERSION="1.0" MOUNT="/mnt" TYPE="ext4" Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* libfstools: fix multiple volume_identify usages with the same volumePieter Smith2017-05-091-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes e.g. factory-flashed startup issue with jffs2 on ubi overlay Commit ba019965 ("libfstools: accept volume as argument in most calls") broke startup for factory-flashed jffs2 on ubi systems, causing substantial slowdown in factory environments. When starting up with a factory-flashed jffs2 on ubi system, the "rootfs_data" volume contains a deadcode marker. In the start phase, mount_root then mounts a tmpfs overlay, and postpones remounting of the jffs2 overlay until the done phase of the startup. The refactoring in ba019965 eliminated an unneeded call to volume_find() when done() called jffs2_switch(). Unfortunately the refactoring did not take into account that volume_identify() does not function correctly when called twice in a row on the same struct volume when using an mtd driver. mtd_volume_identify() uses mtd_volume_load() to open an fd to the mtd device and reads a potential deadcode marker from the fd. The first time this works, and FS_DEADCODE is returned. When volume_identify() is called a second time however, mtd_volume_load() notices that we already have an open fd, does nothing further and returns 0 without resetting the file offset to 0. mtd_volume_identify() now reads past the deadcode marker and now returns FS_JFFS2 if the mtd device is a UBIVOLUME. jffs2_switch() then handles the wrong case, either pulling the root out from under user-space in Chaos Calmer, or indefinitely sticking to a tmpfs overlay in later OpenWRT builds. Signed-off-by: Pieter Smith <pieter.smith@philips.com> Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* libfstools: silence mkfs.{ext4,f2fs}Daniel Golle2017-04-201-2/+2
| | | | | | | Reduce noise during firstboot when creating overlay fs on block rootdisk devices. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* libfstools: add basic documentation of mount functionsRafał Miłecki2017-03-281-0/+15
| | | | | Signed-off-by: Rafał Miłecki <rafal@milecki.pl> Acked-by: John Crispin <john@phrozen.org>
* add missing includesFelix Fietkau2017-02-111-0/+1
| | | | | | | On glibc 2.25, sys/sysmacros.h needs to be included for makedev, major and minor. Signed-off-by: Felix Fietkau <nbd@nbd.name>
* libfstools: Check return values for fread and systemFlorian Fainelli2016-12-051-4/+10
| | | | | | | | | | | | | | | | | libfstools/rootdisk.c: In function 'rootdisk_volume_identify': libfstools/rootdisk.c:172:7: error: ignoring return value of 'fread', declared with attribute warn_unused_result [-Werror=unused-result] fread(&magic, sizeof(magic), 1, f); ^ libfstools/rootdisk.c:179:7: error: ignoring return value of 'fread', declared with attribute warn_unused_result [-Werror=unused-result] fread(&magic, sizeof(magic), 1, f); ^ libfstools/rootdisk.c: In function 'rootdisk_volume_init': libfstools/rootdisk.c:268:9: error: ignoring return value of 'system', declared with attribute warn_unused_result [-Werror=unused-result] system(str); ^ cc1: all warnings being treated as errors Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
* libfstools: properly label ext4 overlayDaniel Golle2016-09-231-1/+1
| | | | Signed-off-by: Daniel Golle <daniel@makrotopia.org>