Daniel Golle [Fri, 23 Jul 2021 23:52:44 +0000 (00:52 +0100)]
block: support umount device basename
blockd calls the umount action with the basename of the device rather
than the full path.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Daniel Golle [Fri, 23 Jul 2021 23:14:57 +0000 (00:14 +0100)]
blockd: fix length of timeout int passed to ioctl
AUTOFS_IOC_SETTIMEOUT expects a pointer to an 'unsigned long' which
will result in out-of-bounds access when passing a pointer to an 'int'.
Change type of timeout to 'unsigned long'.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Daniel Golle [Fri, 23 Jul 2021 22:20:43 +0000 (23:20 +0100)]
block: allow remove hotplug event to arrive at blockd
As the hotplug event fires after the device has been removed, it will
never be found by _cache_load(). Hence the 'remove' event needs to
propagate in all cases and we only need to populate the cache in case
of 'add' events.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Daniel Golle [Fri, 23 Jul 2021 21:32:56 +0000 (22:32 +0100)]
block: use /dev/dm-* instead of /dev/mapper/*
This avoids a lot of problems as hotplug events also arrive for the
/dev/dm-* names.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Daniel Golle [Fri, 23 Jul 2021 21:33:46 +0000 (22:33 +0100)]
Revert "blockd: detect mountpoint of /dev/mapper/*"
This reverts commit
4d4dcfb33c5d9fa31c9916e106bee309ec7b4b01.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Daniel Golle [Fri, 23 Jul 2021 21:30:56 +0000 (22:30 +0100)]
Revert "block: resolve /dev/mapper/* name for /dev/dm-0 when hotplugging"
Turns out using the device nodes /dev/mapper/* turns out to be a bad
idea to begin with. Will use /dev/dm-* instead.
This reverts commit
2f42515977adef7c026eb380ed2423c533cf8f3d.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Daniel Golle [Sat, 17 Jul 2021 22:13:27 +0000 (23:13 +0100)]
blockd: create mountpoint parent folder if needed
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Daniel Golle [Thu, 15 Jul 2021 14:49:34 +0000 (15:49 +0100)]
blockd: move to its own POSIX process group
Not to be confused with cgroups, there are also POSIX process groups.
They do matter when it comes to autofs, as all requests coming from the
process group of the automounter itself will be ignored.
Hence, if blockd runs in the same process group as init and all
services, requests from services will be ignored.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Daniel Golle [Thu, 15 Jul 2021 01:03:38 +0000 (02:03 +0100)]
blockd: fix trigger name
Make it 'mount.add' instead of just 'add' which is more obvious when
used with procd_add_raw_trigger.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Daniel Golle [Wed, 14 Jul 2021 03:42:25 +0000 (04:42 +0100)]
blockd: also send ubus notification on mount hotplug
Also sending a ubus notification on mount hotplug provides a useful
shortcut for procd service triggers.
As the /etc/hotplug.d/mount API for now doesn't have any users and also
makes it hard to aggregate hotplug calls, we should consider removing it
in favor of only using triggers on the block notifications in future.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Daniel Golle [Wed, 14 Jul 2021 03:05:03 +0000 (04:05 +0100)]
block: resolve /dev/mapper/* name for /dev/dm-0 when hotplugging
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Daniel Golle [Wed, 14 Jul 2021 01:58:12 +0000 (02:58 +0100)]
blockd: detect mountpoint of /dev/mapper/*
If a device cannot be found in /dev, also try /dev/mapper.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Daniel Golle [Sun, 16 May 2021 08:49:24 +0000 (09:49 +0100)]
blockd: add missing #define _GNU_SOURCE
asprintf requires _GNU_SOURCE to be defined. Set it.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Daniel Golle [Wed, 12 May 2021 22:54:47 +0000 (23:54 +0100)]
block: allow autofs and umount commands also on MTD/UBI
As devices with large NAND flash are becoming more common, users may
use that resource for additional (UBI) volumes. To support that in
fstools, allow autofs and umount also on MTD/UBI devices.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Daniel Golle [Wed, 12 May 2021 17:05:37 +0000 (18:05 +0100)]
block: match device path instead of assuming /dev/%s
Block devices created by device mapper are in /dev/mapper/ folder,
hence the assumption of the 'block' tool expecting /dev/%s being the
path of a device doesn't hold true.
Match device path from cache instead.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Daniel Golle [Wed, 12 May 2021 16:07:28 +0000 (17:07 +0100)]
libblkid-tiny: fix buffer overflow
Copying device name into a fixed-length buffer is problematic as
the name can be longer than the buffer, resulting in subsequent fields
getting corrupted and potentially even worse things.
Drop strcpy of device name and use of the copied value as it is known
anyway.
Before this fix:
/dev/mapper/owrt--volumes--
e093cc66-rw_test: UUID="c66-rw_test" LABEL="test" VERSION="1.14" TYPE="f2fs"
After this fix:
/dev/mapper/owrt--volumes--
e093cc66-rw_test: UUID="
5eda3e52-3427-493a-a6d6-
ffdb5a5836fd" LABEL="test" VERSION="1.14" TYPE="f2fs"
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Daniel Golle [Wed, 12 May 2021 15:29:36 +0000 (16:29 +0100)]
blockd: use allocated strings instead of fixed buffers
device names can be pretty long when using LVM2, mount targets are
user defined and can potentially also be of PATH_MAX length.
Replace static buffers with dynamically allocated strings to avoid
buffer overflow with too long device names or mount targets.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Daniel Golle [Wed, 12 May 2021 22:35:46 +0000 (23:35 +0100)]
block: use dynamically allocated target string
Dynamically allocate string buffer for target mountpoint if needed in
order to avoid the static buffer overflowing for long (device mapper)
paths.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Daniel Danzberger [Tue, 4 May 2021 13:23:11 +0000 (15:23 +0200)]
fstools: block: fix segfault on mount with no target
When a UCI fstab mount config doesn't contain a target option,
a 'block mount' call segfaults when comparing a mount's target (NULL)
to a found mount point returned by find_mount_point()
Signed-off-by: Daniel Danzberger <daniel@dd-wrt.com>
Acked-by: Paul Spooren <mail@aparcar.org>
Petr Štetiar [Wed, 7 Apr 2021 10:07:32 +0000 (12:07 +0200)]
overlay: fix syncronizing typo
So it's now correct `synchronizing`.
Signed-off-by: Petr Štetiar <ynezz@true.cz>
Daniel Golle [Fri, 19 Mar 2021 12:13:33 +0000 (12:13 +0000)]
partname: allow skipping existing 'rootfs_data' partition
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>
Daniel Golle [Mon, 8 Mar 2021 00:05:51 +0000 (00:05 +0000)]
libfstools: remove superflus include
Turns out C header file <stropts.h> is unneeded after all.
Remove it.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Daniel Golle [Fri, 5 Mar 2021 01:33:22 +0000 (01:33 +0000)]
libfstools: fix build with glibc
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>
Daniel Golle [Tue, 2 Mar 2021 17:40:43 +0000 (17:40 +0000)]
libfstools: partname: several fixes
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>
Daniel Golle [Fri, 26 Feb 2021 19:45:55 +0000 (19:45 +0000)]
fstools: add partname volume driver
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>
Daniel Golle [Mon, 4 Jan 2021 18:05:07 +0000 (18:05 +0000)]
jffs2reset: support fristboot on unmounted UBI overlay
To erase the overlay partitions on systems using UBIFS overlay,
instead of writing the jffs2-marker, truncating the UBI volume to 0
has the desired effect.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Daniel Golle [Sat, 12 Dec 2020 23:01:15 +0000 (23:01 +0000)]
block: replace local mkdir_p implementation
Drop local mkdir_p implementation in favour of using the
implementation now added to libubox.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Daniel Golle [Fri, 16 Oct 2020 02:24:17 +0000 (03:24 +0100)]
mount: restorecon: guard against execl() errors
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>
John Crispin [Fri, 27 Nov 2020 16:20:04 +0000 (17:20 +0100)]
jffs2-reset: allow doing a factory reset and passing a sysupgrade.tgz
Signed-off-by: John Crispin <john@phrozen.org>
Daniel Golle [Sun, 11 Oct 2020 00:36:51 +0000 (01:36 +0100)]
mount: apply SELinux labels before overlayfs mount
Use restorecon to apply SELinux labels if applicable.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Daniel Golle [Thu, 15 Oct 2020 23:31:15 +0000 (00:31 +0100)]
overlay: use precompiler macros for reoccuring path names
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Daniel Golle [Thu, 15 Oct 2020 23:33:25 +0000 (00:33 +0100)]
mount: fix log format string and indentation
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Daniel Golle [Sun, 11 Oct 2020 00:06:52 +0000 (01:06 +0100)]
mount: remove support for legacy overlayfs before v2.3
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>
Rosen Penev [Wed, 25 Mar 2020 23:27:47 +0000 (16:27 -0700)]
fstoools: add define for GLOB_ONLYDIR
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>
David Woodhouse [Wed, 17 Jun 2020 18:29:56 +0000 (19:29 +0100)]
Use autoclear for overlay loopback device
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>
Daniel Golle [Mon, 11 May 2020 23:26:28 +0000 (00:26 +0100)]
blockd: fix segfault triggered by non-autofs mounts
Program received signal SIGSEGV, Segmentation fault.
main_autofs (argv=<optimized out>, argc=<optimized out>)
at fstools-2020-05-06-
eec16e2f/block.c:1193
1193: if (!m->autofs && (mp = find_mount_point(pr->dev))) {
Fixes: 9ab936d ("block(d): always call hotplug.d "mount" scripts from blockd")
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Rafał Miłecki [Wed, 6 May 2020 15:46:55 +0000 (17:46 +0200)]
blockd: add optional "device" parameter to "info" ubus method
It allows getting info about specified device.
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Rafał Miłecki [Wed, 6 May 2020 14:48:06 +0000 (16:48 +0200)]
block(d): always call hotplug.d "mount" scripts from blockd
This resolves problem on boot with "mount" scripts being called too
early to get blockd info. With this change "mount" scripts won't get
called until blockd starts. On startup it requests all devices info and
calls relevant scripts.
This fixes samba36-hotplug package hotplug.d script.
One downside of this change is handling "mount" evens on block restart
or crash. On restart "add" actions will get executed for mounted /
available (autofs) devices. On crash no events will be generated.
Ref: http://lists.infradead.org/pipermail/openwrt-devel/2019-December/020886.html
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Rafał Miłecki [Tue, 5 May 2020 19:08:03 +0000 (21:08 +0200)]
blockd: use uloop_process for calling /sbin/hotplug-call mount
As blockd uses uloop calling any script and using waitpid() can easily
result in a lock. It's enough for script to use /bin/ubus to cause that.
It's not an option to drop waitpid() as it's important to e.g. call
mount scripts with ACTION=remove before unmounting devices. So solving
this problem requires using uloop_process.
Unfortunately this means:
1. Using callbacks making code slightly more complex
2. Dropping that nice devices_update_cb()
With this change however hotplug.d "mount" scripts can safely call
"ubus".
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Mirko Vogt [Sat, 25 Apr 2020 23:47:50 +0000 (01:47 +0200)]
Truncate FAT filesystem label until 1st occurance of a blank (0x20)
According to spec the FAT filesystem label is not terminated by a
\0-byte but instead has a fixed length where the name is padded by
blanks.
Before libblkid-tiny just passed the always 11 bytes long blank padded
string through, however it makes matching for a filesystem label
inconsistent with other filesystems, which use a \0-terminated string.
Before: "foobar "
After : "foobar"
Signed-off-by: Mirko Vogt <mirko-openwrt@nanl.de>
Rafał Miłecki [Sat, 2 May 2020 12:05:11 +0000 (14:05 +0200)]
block: always use st_dev (device ID) of / when looking for root
Use this method even if UBIFS extroot support is enabled. This is needed
on x86 systems (using F2FS for overlay) as they may still come with F2FS
enabled.
Ref: https://bugs.openwrt.org/index.php?do=details&task_id=2231
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Rafał Miłecki [Tue, 5 May 2020 06:49:17 +0000 (08:49 +0200)]
block: simplify check_extroot() a bit
Avoid too big code indent.
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Rafał Miłecki [Sat, 2 May 2020 11:29:08 +0000 (13:29 +0200)]
block: add some basic extroot documentation
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Rafał Miłecki [Thu, 2 Apr 2020 12:12:13 +0000 (14:12 +0200)]
Revert "block: support hierarchical mount/umount"
This reverts commit
fb0700f0fdfc4bec220203d31df87be2b4ccc467.
Switching to AVL tree allows sorting devices by selected parameter
(mount path) but does not implement a real hierarchical layout. That
would require a tree with parent nodes being parent devices / mount
paths.
Cc: Yousong Zhou <yszhou4tech@gmail.com>
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Rafał Miłecki [Thu, 2 Apr 2020 12:12:12 +0000 (14:12 +0200)]
Revert "block: mount_action: handle mount/umount deps"
This reverts commit
32c3126b2f0464106d74317336b6aef1d7d5f82f.
Internally stored list of devices is implemented using struct vlist_tree
and keeps devices sorted by their mount target paths. This DOESN'T mean
that all preceding entires of a given device are its parent devices.
Making such an assumption and mounting all preceding devices results in
unwanted mounts in most cases.
For example having devices like:
/dev/sda1 (mount target: /mnt/foo1)
/dev/sda2 (mount target: /mnt/foo2)
/dev/sdb1 (mount target: /mnt/bar1)
/dev/sdb2 (mount target: /mnt/bar2)
will result in devices vlist_tree having entries sorted like:
/dev/sdb1 (bar1), /dev/sdb2 (bar2), /dev/sda1 (foo1), /dev/sda2 (foo2)
Using autofs and accessing /mnt/foo2 would result in mounting all 4
partitions and spinning unneeded /dev/sdb.
Cc: Yousong Zhou <yszhou4tech@gmail.com>
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Felix Fietkau [Thu, 9 Apr 2020 11:19:08 +0000 (13:19 +0200)]
libfstools/mtd: attempt to read from OOB data if empty space is found
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>
Rafał Miłecki [Sat, 28 Dec 2019 21:07:22 +0000 (22:07 +0100)]
blockd: remove symlink linkpath file if it's a dir or link
Files like that can remain from using non-autofs mounting and can cause
mounting errors after switching to autofs:
blockd: failed to symlink /mnt/sda1->/tmp/run/blockd/sda1
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Rafał Miłecki [Sat, 28 Dec 2019 21:07:21 +0000 (22:07 +0100)]
block: remove mount target file if it's a link
Links like that can remain from using autofs and can cause mounting
errors after switching to non-autofs:
block: mounting /dev/sda1 (vfat) as /mnt/sda1 failed (2) - No such file or directory
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Rafał Miłecki [Fri, 27 Dec 2019 12:09:11 +0000 (13:09 +0100)]
blockd: report "target" path as "mount" for autofs available mounts
Devices handled with autofs should be seen as available even if
currently unmounted. Mounting is handled on demand and transparently for
users.
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Rafał Miłecki [Sat, 28 Dec 2019 21:29:03 +0000 (22:29 +0100)]
blockd: print symlink error code and string message
It may help understanding failure reason, e.g.:
blockd: failed to symlink /mnt/sda1->/tmp/run/blockd/sda1 (17) - File exists
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Petr Štetiar [Tue, 21 Jan 2020 16:11:07 +0000 (17:11 +0100)]
Revert "fstools: Add support to read-only MTD partitions (eg. recovery images)"
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>
Bruno Pena [Sat, 4 Jan 2020 11:52:08 +0000 (12:52 +0100)]
fstools: Add support to read-only MTD partitions (eg. recovery images)
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>
Petr Štetiar [Tue, 14 Jan 2020 18:49:41 +0000 (19:49 +0100)]
libblkid-tiny: fix f2fs labels by increasing label buffer
f2fs max label length is 1024B (512 * uint16_t) which is way above
current 256B used in `struct blkid_struct_probe` which renders labels on
f2fs system unusable:
$ mkfs.f2fs -l drive /dev/sda1
$ block info /dev/sda1
label buffer too small 1024 > 255
So increase the label buffer again in order to make enough space for
f2fs labels.
Fixes: FS#2735
Signed-off-by: Petr Štetiar <ynezz@true.cz>
Jo-Philipp Wich [Sun, 5 Jan 2020 16:21:25 +0000 (17:21 +0100)]
block: re-discover mtd devices on extroot mount retry
When retrying extroot mounting after waiting for the underlying device to
appear, the internal device cache was rebuilt without mtd devices, leading
to the following error:
block: extroot: unable to lookup root device /dev/...
The extroot mount procedure needs access to the actual mtd root device to
temporarily mount it for uuid file verification.
Fix this error by rebuilding the cache with mtd devices to allow the
`check_extroot()` procedure to find the internal root device.
Fixes: FS#2701
Fixes: fb0700f ("block: support hierarchical mount/umount")
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Jo-Philipp Wich [Sun, 22 Dec 2019 18:46:05 +0000 (19:46 +0100)]
libblkid-tiny: fix symbol collision with full libblkid
The recent introduction of blkid_new_probe() and blkid_free_probe() in the
dynamically linked libblkid-tiny caused the dlopen'd libblkid.so to call into
the wrong version of blkid_new_probe() within blkid_new_probe_from_filename(),
leading to memory corruption and eventual segmentation faults.
Fixes: b82c5c1 ("libblkid-tiny: add functions for allocating & freeing probe struct")
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Pali Rohár [Tue, 17 Dec 2019 07:28:36 +0000 (08:28 +0100)]
libblkid-tiny: vfat: Change parsing label in special cases
commit
f0ca7e80d7a171701d0d04a3eae22d97f15d0683 upstream.
* Use only label from the root directory and do not fallback to the label
stored in boot sector. This is how MS-DOS 6.22, MS-DOS 7.10, Windows 98,
Windows XP and also Windows 10 behave. Moreover Windows XP and Windows 10
do not touch label in boot sector anymore, so removing FAT label on those
Windowses leads to having old label still stored in boot sector (which
MS-DOS and Windows fully ignore).
* Label entry "NO NAME" in root directory is treated as label "NO NAME"
instead of empty label. In root directory it has no special meaning.
String "NO NAME" has a special meaning (empty label) only for label
stored in boot sector.
* Label from the boot sector is now stored into LABEL_FATBOOT field. So if
there are applications which depends or needs to read this label, they
have ability.
After this change LABEL always correspondent to the label from the root
directory and LABEL_FATBOOT to the label stored in the boot sector. If some
of those labels is missing or is not present (e.g. "NO LABEL" in boot
sector) then particular field is not set.
Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
[rmilecki: drop unneeded now downstream hacks for handling spaces]
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Pali Rohár [Tue, 17 Dec 2019 07:28:35 +0000 (08:28 +0100)]
libblkid-tiny: vfat: Fix reading labels which starts with byte 0x05
commit
e526f503918cc29d8b1ccf36a5c3a34645d2be6e upstream.
When FAT directory entry has leading byte 0x05 it is interpreted as byte
0xE5. This is how FAT stores file name which starts with byte 0xE5 as
leading byte in 0xE5 in FAT directory entry means that file slot is empty.
Fixes: #533
Rafał Miłecki [Tue, 17 Dec 2019 07:28:34 +0000 (08:28 +0100)]
libblkid-tiny: add blkid_probe_set_id_label() stub
This stub will allow porting more upstream code without commenting out
calls and them unused variables. This will simplify maintenance.
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Rafał Miłecki [Sat, 14 Dec 2019 21:55:01 +0000 (22:55 +0100)]
libblkid-tiny: use separated buffer for each block device read
This allows reading multiple chunks of block device data and operating
on them simultaneously. Previous implementation was using a single
buffer (except for reading more data than allocated size) and subsequent
reads were corrupting memory of previously returned buffers.
This fixes e.g. problem with reading NTFS UUID and validating VFAT
signature.
Implementation is based on original libblkid code which handles it
similarly. Buffers are put on probe internal list and freed when
releasing a probe struct.
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Rafał Miłecki [Sat, 14 Dec 2019 21:55:00 +0000 (22:55 +0100)]
libblkid-tiny: add functions for allocating & freeing probe struct
This adds blkid_new_probe() and blkid_free_probe() which have to be used
in place of simple struct memory allocation. They will allow extending
probe struct by any extra initialization code and resources release.
Newly introduced probe.c file is based on original libblkid's code.
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Rafał Miłecki [Fri, 13 Dec 2019 10:05:12 +0000 (11:05 +0100)]
blockd: don't flush devices list on "hotplug" call
The point of "hotplug" call is to add or remove a single entry to/from
devices list. Using vlist_update() and vlist_flush() was clearing whole
list (and leaving the last entry in case of adding a device).
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Rafał Miłecki [Fri, 13 Dec 2019 10:05:11 +0000 (11:05 +0100)]
blockd: fix vlist memory corruption
vlist_add() expects key to point a persistent memory as it doesn't make
its copy. Passing blob_attr of current message was resulting in
undefined/random behavior including list corruption and possible
crashes.
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Yousong Zhou [Sun, 3 Nov 2019 03:06:32 +0000 (03:06 +0000)]
block: detect: use current mp as value of target option
Move down the function so that no declaration of find_mount_point() is
not needed
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
Yousong Zhou [Tue, 29 Oct 2019 12:39:50 +0000 (12:39 +0000)]
block: mount_device: err log only when mp deviates from spec
Fixes possible memleak of mp as well
Resolves FS#1523
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
Yousong Zhou [Tue, 29 Oct 2019 12:39:49 +0000 (12:39 +0000)]
block: mount_device: skip extroot earlier
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
Yousong Zhou [Tue, 29 Oct 2019 12:39:48 +0000 (12:39 +0000)]
block: mount_action: handle mount/umount deps
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>
Yousong Zhou [Tue, 29 Oct 2019 12:39:47 +0000 (12:39 +0000)]
block: support hierarchical mount/umount
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>
Yousong Zhou [Tue, 29 Oct 2019 12:39:46 +0000 (12:39 +0000)]
block: umount: skip / unless -a is given
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
Yousong Zhou [Fri, 25 Oct 2019 10:51:49 +0000 (10:51 +0000)]
block: use fsck.fat instead of dosfsck
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>
Yousong Zhou [Fri, 25 Oct 2019 10:48:47 +0000 (10:48 +0000)]
libblkid-tiny: ntfs: fix use-after-free
The memory pointed to by ns can be reallocated when checking mft records
Fixes FS#2129
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
Hauke Mehrtens [Mon, 2 Sep 2019 19:26:18 +0000 (21:26 +0200)]
mkdev: Avoid out of bounds read
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>
Ansuel Smith [Sun, 16 Jun 2019 17:00:50 +0000 (19:00 +0200)]
libblkid-tiny: use blkid_probe_set_utf8label for label set
Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
Ansuel Smith [Sun, 16 Jun 2019 17:00:49 +0000 (19:00 +0200)]
libblkid-tiny: adds blkid_probe_set_utf8label support
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>
Jo-Philipp Wich [Wed, 28 Aug 2019 10:19:29 +0000 (12:19 +0200)]
probe: fallback to libblkid.so.1 when libblkid.so does not exist
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>
Ansuel Smith [Sun, 16 Jun 2019 17:00:48 +0000 (19:00 +0200)]
libblkid-tiny: increment label size to 256
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>
Ansuel Smith [Sun, 16 Jun 2019 17:00:47 +0000 (19:00 +0200)]
libblkid-tiny: fix wrong btrfs label length
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>
Jo-Philipp Wich [Wed, 27 Mar 2019 07:59:02 +0000 (08:59 +0100)]
block: prevent mount point confusion
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>
Jo-Philipp Wich [Wed, 27 Mar 2019 07:55:07 +0000 (08:55 +0100)]
libfstools: avoid false positives when matching devices and volumes
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>
Petr Štetiar [Tue, 26 Mar 2019 22:50:47 +0000 (23:50 +0100)]
libfstools: Fix overflow of F2FS_MINSIZE constant
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>
Petr Štetiar [Tue, 26 Mar 2019 15:34:29 +0000 (16:34 +0100)]
libfstools: Print error in case of loop blkdev failure
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>
Rafał Miłecki [Wed, 12 Dec 2018 14:24:35 +0000 (15:24 +0100)]
block(d): improve hotplug.d "mount" events for the autofs
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>
Rafał Miłecki [Wed, 12 Dec 2018 14:24:34 +0000 (15:24 +0100)]
blockd: unmount device explicitly when it disappears
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>
Rafał Miłecki [Mon, 10 Dec 2018 06:48:50 +0000 (07:48 +0100)]
block: remove target directory after unmounting
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>
Rafał Miłecki [Sun, 9 Dec 2018 16:52:10 +0000 (17:52 +0100)]
block: cleanup handling "start" action of the "autofs" command
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>
Rafał Miłecki [Sun, 9 Dec 2018 15:11:59 +0000 (16:11 +0100)]
block: make blockd_notify() return an int instead of void
It allows improving block by handling blockd_notify() errors.
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Rafał Miłecki [Sun, 9 Dec 2018 14:52:32 +0000 (15:52 +0100)]
block: generate hotplug.d mount events
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>
Rafał Miłecki [Sun, 9 Dec 2018 13:22:17 +0000 (14:22 +0100)]
block: validate amount of arguments for the "autofs" command
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>
Rafał Miłecki [Fri, 7 Dec 2018 13:13:10 +0000 (14:13 +0100)]
blockd: don't reparse blob msg in the vlist callbacks
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>
Rafał Miłecki [Thu, 6 Dec 2018 08:13:39 +0000 (09:13 +0100)]
blockd: don't unmount device when removing it from the list
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>
Rafał Miłecki [Fri, 30 Nov 2018 17:26:12 +0000 (18:26 +0100)]
block: don't duplicate unmounting code in the mount_action()
Use umount_device() helper instead.
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Rafał Miłecki [Fri, 30 Nov 2018 17:26:11 +0000 (18:26 +0100)]
block: make umount_device() function more generic
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>
Rafał Miłecki [Fri, 30 Nov 2018 13:09:23 +0000 (14:09 +0100)]
block: don't duplicate mounting code in the mount_device()
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>
Rafał Miłecki [Fri, 30 Nov 2018 13:09:22 +0000 (14:09 +0100)]
block: simplify code picking mount target directory
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>
Rafał Miłecki [Fri, 30 Nov 2018 13:09:21 +0000 (14:09 +0100)]
block: move blockd_notify() call out of the conditional blocks
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>
Rafał Miłecki [Fri, 30 Nov 2018 13:09:20 +0000 (14:09 +0100)]
block: fix formatting & indent in the mount_device()
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>
Michael Heimpold [Sat, 24 Nov 2018 09:22:44 +0000 (10:22 +0100)]
fstools: use EXIT_FAILURE when indicating error on exit
According to man page, using the EXIT_* macros is more portable than using
plain integer values.
Signed-off-by: Michael Heimpold <mhei@heimpold.de>
Michael Heimpold [Sat, 24 Nov 2018 09:22:53 +0000 (10:22 +0100)]
fstools: guard usage of WEXITSTATUS
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>
Ansuel Smith [Fri, 28 Sep 2018 23:01:02 +0000 (01:01 +0200)]
fstools: add ntfs support
This adds ntfs support to block-mount
Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
Pierre Lebleu [Wed, 23 May 2018 08:55:58 +0000 (10:55 +0200)]
fstools: allow the mounting with full access time accounting
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>
Pierre Lebleu [Wed, 23 May 2018 08:55:57 +0000 (10:55 +0200)]
fstools: allow to compress the filesystem
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>