summaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
...
* block: mount_action: handle mount/umount depsYousong Zhou2019-11-021-13/+30
| | | | | | | | | This is required at least in system startup when "block hotplug" will be triggered by udevtrigger. E.g. /dev/vdb needs to be mounted at /mnt/s and /dev/vdc /mnt. It does not work if /dev/vdb was triggered then mounted first Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
* block: support hierarchical mount/umountYousong Zhou2019-11-021-51/+101
| | | | | | | | | | | | | This is needed when e.g. sda1 needs to be mounted to /mnt and sda2 /mnt/srv. We need to make sure sda1 was mounted first. "devices" is now an ordered list with elements pointing to both "struct probe_info" and "struct mount". The order is firstly on presence of mount info, then strlen(mount.target), then strcmp(probe_info.dev) Resolves FS#2214 Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
* block: umount: skip / unless -a is givenYousong Zhou2019-11-021-4/+10
| | | | Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
* block: use fsck.fat instead of dosfsckYousong Zhou2019-10-271-2/+2
| | | | | | | | | | Dosfsck is only available when --enable-compat-symlinks was given when configuring dosfstools. These symlinks are not enabled in OpenWrt dosfstools package Suggested by Reiner Otto in FS#2408 Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
* libblkid-tiny: ntfs: fix use-after-freeYousong Zhou2019-10-271-5/+7
| | | | | | | | The memory pointed to by ns can be reallocated when checking mft records Fixes FS#2129 Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
* mkdev: Avoid out of bounds readHauke Mehrtens2019-09-201-2/+2
| | | | | | | | | readlink() truncates and does not null terminate the string when more bytes would be written than available. Just increase the char array by one and assume that there is a problem when all bytes are needed. Coverity: #1330087, #1329991 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
* libblkid-tiny: use blkid_probe_set_utf8label for label setAnsuel Smith2019-09-033-9/+1
| | | | Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
* libblkid-tiny: adds blkid_probe_set_utf8label supportAnsuel Smith2019-09-034-0/+93
| | | | | | Currently set_utf8label support is missing. Adds a stripped down version of encode.c file from original libblkid and adds the function to libblkid-tiny.c. Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
* probe: fallback to libblkid.so.1 when libblkid.so does not existJo-Philipp Wich2019-08-281-0/+3
| | | | | | | | | | | | OpenWrt commit 0e70f69a35 ("treewide: revise library packaging") removed the unversioned library symlink from the libblkid package, breaking dynamic loading of the library at runtime. Add a fallback to "libblkid.so.1" to allow using the dynamic library for filesystem probing again. Fixes: FS#2274 Signed-off-by: Jo-Philipp Wich <jo@mein.io>
* libblkid-tiny: increment label size to 256Ansuel Smith2019-07-011-1/+1
| | | | | | Btrfs max label lenght is 255. Increment the blkid_struct_probe struct to respect this new max value. Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
* libblkid-tiny: fix wrong btrfs label lengthAnsuel Smith2019-07-011-1/+1
| | | | | | Btrfs label length is 256 included the termination char ( '\0' ) as the real max length is 255 (less than 256 from the wiki). Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
* block: prevent mount point confusionJo-Philipp Wich2019-03-311-2/+1
| | | | | | | | | | Do not perform substring matches when identifying mount points to avoid returning wrong entries, e.g. "/dev/mmcblk0p10" when "/dev/mmcblk0p1" was requested. Fixes: FS#2196 Ref: https://bugs.openwrt.org/index.php?do=details&task_id=2196 Signed-off-by: Jo-Philipp Wich <jo@mein.io>
* 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>
* block(d): improve hotplug.d "mount" events for the autofsRafał Miłecki2018-12-282-9/+26
| | | | | | | | | | | | | | | | | | | | | | | So far - when using autofs - "add" and "remove" action events were triggered on every (un)mount. It wasn't very helpful when using autofs due to its nature. The point of blockd & autofs is to have block devices mounted on an access request. Its users should not care / know if it's currently mounted or not. Mounting should be handled transparently. To make that work it requires informing listeners whenever device: 1) Becomes *ready* for mounting (by triggering "add" action) 2) Becomes *unavailable* (by triggering "remove" action) The current mounting state is something that autofs & blockd should handle internally and should not notify listeners about. This is implemented by: 1) block generating events for non-autofs cases only (when (un)mounting) 2) blockd informing block when autofs resource becomes (un)available Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* blockd: unmount device explicitly when it disappearsRafał Miłecki2018-12-281-1/+12
| | | | | | | | | | | | To keep autofs behavior consistent blockd should request both: mounting and unmounting when needed. It's important as autofs-related actions may require slightly different handling. Without this patch: 1) autofs mounts were handled using TYPE_AUTOFS 2) autofs unmounts were handled using TYPE_HOTPLUG Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* block: remove target directory after unmountingRafał Miłecki2018-12-121-2/+4
| | | | | | | | | | | | | | | This removes dangling directory fixing two issues: 1) Non autofs case Leaving directory in /mnt/ and switching to autofs would result in blockd failing to symlink(). 2) autofs case Leaving directory in /var/run/blockd/ could result in apps trying to access it causing errors like: blockd: kernel is requesting a mount -> sda1 blockd: failed to run block. add/sda1 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* block: cleanup handling "start" action of the "autofs" commandRafał Miłecki2018-12-121-5/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | When blockd starts it uses "start" action for getting current state of block devices. The way main_autofs() was implemented was a bit hacky though: 1) It was calling mount_device() with TYPE_HOTPLUG First of all that made code harder to understand. Faking TYPE_HOTPLUG for a TYPE_AUTOFS made following mount_device() logic more complex. Secondly the only reason for that seems to be to trigger "swap" and extroot checks in the mount_device(). Other than that it was only about calling blockd_notify() anyway. 2) It wasn't consistent Consider a "swap" or extroot without an "autofs" set (a pretty expected case). a) During original TYPE_HOTPLUG event mount_device() would detect both cases early and return without calling blockd_notify(). b) With previous main_autofs() implementation blockd_notify() was called for both cases. With this change main_autofs() doesn't fake TYPE_HOTPLUG and it follows mount_device() logic which should result in an expected & consistent state of devices in blockd. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* block: make blockd_notify() return an int instead of voidRafał Miłecki2018-12-091-3/+8
| | | | | | It allows improving block by handling blockd_notify() errors. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* block: generate hotplug.d mount eventsRafał Miłecki2018-12-091-0/+33
| | | | | | | | | | | | | | | | | | With this change block generates 2 "mount" hotplug.d subsystem events: 1) "add" when block device gets mounted 2) "remove" when block device gets unmounted This allows e.g. controlling USB storage dependant software using hotplug.d listeners. A very similar solution was implemented in mountd which was replaced by blockd. Right now this is implemented using a call to the /sbin/hotplug-call. A possible improvement is to rewrite above shell script into a C lib function. For now let's just assume that script exists. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* block: validate amount of arguments for the "autofs" commandRafał Miłecki2018-12-091-0/+4
| | | | | | | | | Using argv[3] without checking argc value could result in undefined behavior. It could result in a crash or accessing a NULL that separates argv from envp on UNIX. Signed-off-by: Rafał Miłecki <rafal@milecki.pl> Acked-by: John Crispin <john@phrozen.org>
* blockd: don't reparse blob msg in the vlist callbacksRafał Miłecki2018-12-071-13/+3
| | | | | | | | | | | | ubus message is parsed in the block_hotplug() which fills all the struct device fields. Once that is done there is no need to parse original message again - it's enough to get required data from the struct. This also fixes handling messages with "autofs" set to 0. They were incorrectly interpreted due to the missing blobmsg_get_u32(). Signed-off-by: Rafał Miłecki <rafal@milecki.pl> Acked-by: John Crispin <john@phrozen.org>
* blockd: don't unmount device when removing it from the listRafał Miłecki2018-12-061-24/+2
| | | | | | | | | | | | | | | | | | | | | | | | | Device gets removed from the list (vlist_delete()) when block calls "hotplug" method of blockd using ubus. Right after that block unmounts that device on its own. blockd shouldn't care about unmounting on its own for following reasons: 1) To avoid code/behavior duplication with block 2) To keep behavior consistent with mounting (blockd doesn't mount) 3) To allow implementing more features in block (e.g. hotplug.d events) To make unmounting the most reliable the plan is to have: 1) block receiving hotplug.d "block" subsystem events "remove" 2) blockd stopping reporting device (so we avoid new users & let existing ones realize mount can't be used anymore) 3) block notifying (through hotplug.d "mount" subsystem) all users about device being unmounted - that should stop all apps accessing it 4) block unmount device That should allow storage users stop accessing mount point & let block unmount device cleanly. Signed-off-by: Rafał Miłecki <rafal@milecki.pl> Acked-by: John Crispin <john@phrozen.org>
* block: don't duplicate unmounting code in the mount_action()Rafał Miłecki2018-12-051-11/+1
| | | | | | Use umount_device() helper instead. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* block: make umount_device() function more genericRafał Miłecki2018-12-051-20/+17
| | | | | | | | | | Make it accept device path instead of struct probe_info. This way it can be reused by code fired when device is already gone. To keep existing functionality two checks have been moved to the main_umount(). Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* block: don't duplicate mounting code in the mount_device()Rafał Miłecki2018-12-041-29/+20
| | | | | | | | Once target directory gets specified mounting code is identical for devices having and not having UCI config entry. Share it. Signed-off-by: Rafał Miłecki <rafal@milecki.pl> Reviewed-by: Michael Heimpold <mhei@heimpold.de>
* block: simplify code picking mount target directoryRafał Miłecki2018-12-041-3/+4
| | | | | | | | Using a set of 3 conditional block each setting "target" variable makes code easier to follow. Signed-off-by: Rafał Miłecki <rafal@milecki.pl> Reviewed-by: Michael Heimpold <mhei@heimpold.de>
* block: move blockd_notify() call out of the conditional blocksRafał Miłecki2018-12-041-9/+7
| | | | | | | | | That function is called no matter if "m" variable is null or not. This saves a one duplicated line & allows merging two conditional blocks starting with if (m). It doesn't change code execution order. Signed-off-by: Rafał Miłecki <rafal@milecki.pl> Reviewed-by: Michael Heimpold <mhei@heimpold.de>
* block: fix formatting & indent in the mount_device()Rafał Miłecki2018-12-041-16/+18
| | | | | | | | There was some misformatted code that seemed like switch block having an else block. This improves code readability. Signed-off-by: Rafał Miłecki <rafal@milecki.pl> Reviewed-by: Michael Heimpold <mhei@heimpold.de>
* fstools: use EXIT_FAILURE when indicating error on exitMichael Heimpold2018-11-262-6/+6
| | | | | | | According to man page, using the EXIT_* macros is more portable than using plain integer values. Signed-off-by: Michael Heimpold <mhei@heimpold.de>
* fstools: guard usage of WEXITSTATUSMichael Heimpold2018-11-261-1/+3
| | | | | | | | | | According to man page, using WEXITSTATUS should be guarded by a check of WIFEXITED, so add this check. While at, also print an error message in case fsck was terminated by a signal. Signed-off-by: Michael Heimpold <mhei@heimpold.de>
* fstools: add ntfs supportAnsuel Smith2018-10-111-1/+8
| | | | | | This adds ntfs support to block-mount Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
* fstools: allow the mounting with full access time accountingPierre Lebleu2018-05-242-1/+10
| | | | | | | | 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-242-1/+11
| | | | | | | 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>
* strip trailing spaces from vfat labelsJohn Crispin2018-02-111-1/+8
| | | | Signed-off-by: John Crispin <john@phrozen.org>
* fix vfat volume labelJohn Crispin2018-02-111-1/+1
| | | | | | the libblkid copies len+1 bytes causing a buffer overrun. Signed-off-by: John Crispin <john@phrozen.org>
* block: support /dev/nvme* nodesDaniel Golle2018-02-021-0/+1
| | | | | | | Add glob for NVM Express SSD device nodes to support systems with such PCIe SSDs. Signed-off-by: Daniel Golle <daniel@makrotopia.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>
* libblkid-tiny: add support for NTFS superblockRafał Miłecki2017-12-293-0/+230
| | | | | | | | | Its copied from the util-linux project and its libblkid. Call to the blkid_probe_set_utf8label was commented out due to libblkid-tiny not supporting it yet. Signed-off-by: Rafał Miłecki <rafal@milecki.pl> Acked-by: John Crispin <john@phrozen.org>
* fstools: Replace strerror(errno) with %m format.Rosen Penev2017-12-127-35/+34
| | | | | | Saves 1472 bytes under glibc. No other difference. Signed-off-by: Rosen Penev <rosenp@gmail.com>
* libblkid-tiny: add support for UBI superblockRafał Miłecki2017-08-074-0/+54
| | | | | | | | | | | Detecting UBI superblock may be useful for tools wanting to simplify or automate attaching UBI. Please note it's not directly related to the ubifs support which is just a filesystem working on top of UBI volume. This patch adds simple code reading UBI version and unique number and setting it in the blkid_probe. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* fstools: add btrfs supportRobert Young2017-07-311-1/+8
| | | | Signed-off-by: Robert Young <yayooo@gmail.com>
* block: support /dev/xvd* nodesW. Michael Petullo2017-07-161-0/+1
| | | | | | | | | Xen provides paravirtualized block devices which most often appear as /dev/xvd*. This patch adds this pattern to those known to the block utilitiy. These devices require a kernel compiled with the xen-blkfront driver. Signed-off-by: W. Michael Petullo <mike@flyn.org>