project/mountd.git
15 months agomount: drop duplicated includes master
Rafał Miłecki [Mon, 26 Feb 2018 05:21:05 +0000 (06:21 +0100)]
mount: drop duplicated includes

All these headers are being included few lines above.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
15 months agomount: call hotplug-call with ACTION=remove before trying to unmount
Rafał Miłecki [Wed, 21 Feb 2018 12:32:17 +0000 (13:32 +0100)]
mount: call hotplug-call with ACTION=remove before trying to unmount

This increases a chance of successfully unmounting a drive as calling
hotplug.d scripts may result in stopping applications using it.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
15 months agomount: try lazy unmount if normal one fails
Rafał Miłecki [Wed, 21 Feb 2018 12:32:16 +0000 (13:32 +0100)]
mount: try lazy unmount if normal one fails

If umount call fails (e.g. because of some application accessing old
path) the only chance of getting mount entry cleaned is receiving autofs
expire packet. This isn't fully reliable:
1) Sometimes expire can happen before closing all handles. In such case
   a second unmount try will fail as well and there won't be a next one.
2) Expire happens after specified timeout. If device reappears quickly
   (e.g. due to being replugged or USB controller restart) it may be
   worth having old mount cleaned up earlier for better user experience.

This problem can be easily handled by using MNT_DETACH (lazy) umount as
a fallback.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
15 months agomount: create not working symlink when unmounting fails
Rafał Miłecki [Fri, 16 Feb 2018 15:01:12 +0000 (16:01 +0100)]
mount: create not working symlink when unmounting fails

If device disappears but there is still some application trying to
access it, unmounting will fail with the EBUSY errno. Unlinking
/tmp/mounts/<symlink> would succeed but things could go wrong depending
on the application accessing that path.

If some app doesn't check if /tmp/mounts/<symlink> exists it could just
create it and start writing to it filling RAM instead of saving data to
a mounted drive.

Moreover the next time mountd tries to create that symlink it will fail
because there will be already a directory under that path. Things could
go even worse once mountd fires /sbin/hotplug-call and other apps start
using /tmp/mounts/<symlink> believing there's a mounteg storage there.

To fix this, detect failed umount call and replace /tmp/mounts/<symlink>
with a new symlink pointing to the not existing file. That will prevent
applications from re-creating that directory and writing to it filling
the RAM.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
15 months agomount: reorder deleting code in the mount_enum_drives()
Rafał Miłecki [Fri, 16 Feb 2018 11:50:24 +0000 (12:50 +0100)]
mount: reorder deleting code in the mount_enum_drives()

Make it execute required unmount code first and then take care of
removing entry from the internal list. This is a small cleanup grouping
code by their purpose.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
16 months agomount: rename tmp variables in the mount_add_list()
Rafał Miłecki [Fri, 16 Feb 2018 14:32:26 +0000 (15:32 +0100)]
mount: rename tmp variables in the mount_add_list()

Both of them are used once only so there is no real need for the tmp(2)
variables. We can just name them nicer to make code easier to read.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
16 months agomount: drop duplicated rmdir() call from the mount_enum_drives()
Rafał Miłecki [Mon, 12 Feb 2018 11:01:53 +0000 (12:01 +0100)]
mount: drop duplicated rmdir() call from the mount_enum_drives()

Call to rmdir() for the same path is already executed in the
mount_dev_del().

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
16 months agomount: drop duplicated unlink() call from the mount_dev_del()
Rafał Miłecki [Mon, 12 Feb 2018 11:01:52 +0000 (12:01 +0100)]
mount: drop duplicated unlink() call from the mount_dev_del()

There is no need to call unlink() there as mount_enum_drives() does it
too, soon after calling mount_dev_del(). Also mount_enum_drives() does
that for STATUS_EXPIRED - which is expected - as there is no unlink()
call when device expires.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
16 months agomount: fix/improve unmounting log messages
Rafał Miłecki [Mon, 12 Feb 2018 10:19:42 +0000 (11:19 +0100)]
mount: fix/improve unmounting log messages

The message in mount_dev_del() had a typo and was printing non-existing
directory:
1) mount->dev is valid for /tmp/run/mountd/
2) mount->name is valid for uci_path (e.g. /tmp/mounts/)
The old message was mixing /tmp/run/mountd/ with mount->name.

While at it change mount_remove() to match updated mount_dev_del().

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
16 months agomount: fix removing mount point if it's expired
Rafał Miłecki [Fri, 9 Feb 2018 16:18:21 +0000 (17:18 +0100)]
mount: fix removing mount point if it's expired

Kernel can report mount point as expired and when that happens mountd
unmounts it. When such a device disappears it's still important to:
1) Cleanup directories
2) Call hotplug scripts
Fix this by adding a new EXPIRED status and checking it when block
device disappears.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
16 months agomount: struct mount: replace "mounted" and "ignore" fileds with a "status"
Rafał Miłecki [Fri, 9 Feb 2018 16:18:20 +0000 (17:18 +0100)]
mount: struct mount: replace "mounted" and "ignore" fileds with a "status"

There is no need to store status using these 2 separated fields.
Obviously ignored mount should never get mounted. This change will also
allow adding more statuses easily in the future if needed.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
16 months agomount: change mount_dev_del() argument to struct mount *
Rafał Miłecki [Fri, 9 Feb 2018 15:21:49 +0000 (16:21 +0100)]
mount: change mount_dev_del() argument to struct mount *

Caller of mount_dev_del() already has struct mount * so there is no
point in passing matchin device and then looking for struct mount *
again.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
16 months agomount: rename /proc/mount parser to mount_update_mount_list()
Rafał Miłecki [Thu, 8 Feb 2018 13:50:20 +0000 (14:50 +0100)]
mount: rename /proc/mount parser to mount_update_mount_list()

Using "update" in the function name should better match its role than
"check". The main purpose of this function is to update content of the
"mounted" array.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
16 months agomount: improve handling mounts table size
Rafał Miłecki [Thu, 8 Feb 2018 13:50:19 +0000 (14:50 +0100)]
mount: improve handling mounts table size

This is static array with a size set to MAX_MOUNTED. Old code:
1) Was never using the last table entry/row
2) Was logging the same message for every mount entry above limit

This fixes off-by-one, moves limit check to the proper place and uses
"break" when needed.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
17 months agomount: check if block was mounted before cleaning it up
Rafał Miłecki [Wed, 3 Jan 2018 10:31:23 +0000 (11:31 +0100)]
mount: check if block was mounted before cleaning it up

Calling an extra rmdir and unlink isn't a big issue but triggering
hotplug.d scripts for devices that weren't mounted could be misleading
for listeners.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
17 months agomount: remove directory if mounting fails
Rafał Miłecki [Wed, 3 Jan 2018 10:31:22 +0000 (11:31 +0100)]
mount: remove directory if mounting fails

Aside from just cleaning up mountd's tmp dir it's also important for
autofs support. With such an empty directory autofs_process_request
believed device is mounted and it kept replying AUTOFS_IOC_READY to the
kernel. It was causing a log storm like:
mountd[1015]: Got a autofs packet
mountd[1015]: kernel is requesting a mount -> sda1
mountd[1015]: Got a autofs packet
mountd[1015]: kernel is requesting a mount -> sda1
mountd[1015]: Got a autofs packet
mountd[1015]: kernel is requesting a mount -> sda1

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
17 months agomount: call hotplug mount scripts only on success
Rafał Miłecki [Wed, 3 Jan 2018 10:31:21 +0000 (11:31 +0100)]
mount: call hotplug mount scripts only on success

If mounting fails for whatever reason (like unsupported file system or
something) hotplug.d scripts shouldn't be called.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
19 months agomount: add mount with ignore=1 for unsupported filesystems
Rafał Miłecki [Fri, 3 Nov 2017 09:02:40 +0000 (10:02 +0100)]
mount: add mount with ignore=1 for unsupported filesystems

So far a check for unsupported filesystem was in the mount_add_list
which was simply stopping mount from being added to the global list.

This resulted in mount_dev_add continuously not being able to find a
mount for the given block device and trying to add it over and over.
That was non-optimal becuse with unsupported filesystem present the
code was checking all its parameters every second.

Fix this by:
1) Moving check out of the mount_add_list to keep all logic in the
   caller function.
2) Adding mount with ignore=1 for unsupported filesystem instead of
   ignoring it.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Acked-by: John Crispin <john@phrozen.org>
19 months agomount: drop duplicated filesystem check from mount_add_list
Rafał Miłecki [Fri, 3 Nov 2017 09:02:39 +0000 (10:02 +0100)]
mount: drop duplicated filesystem check from mount_add_list

At the very beginning of this function there is following code:
if(fs <= MBR || fs > LASTFS)
return;

There is no point in checking for the same range again as these checks
will always evaluate into true.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Acked-by: John Crispin <john@phrozen.org>
20 months agoautofs: register SIGTERM for gracefull exit
Hans Dedecker [Wed, 18 Oct 2017 08:00:15 +0000 (10:00 +0200)]
autofs: register SIGTERM for gracefull exit

Register SIGTERM to gracefully terminate mountd.
At the same time don't handle the exit in signal handler context but
let the main bail out.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
Signed-off-by: Rutger Lejeune <rutger-lejeune@hotmail.com>
20 months agomount: fix SIGSEV crashes
Hans Dedecker [Tue, 17 Oct 2017 11:40:41 +0000 (13:40 +0200)]
mount: fix SIGSEV crashes

Don't close file descriptor in case file descriptor is NULL

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
2 years agomountd: Add static qualifier to missing variable declarations.
Rosen Penev [Sat, 17 Dec 2016 23:41:05 +0000 (15:41 -0800)]
mountd: Add static qualifier to missing variable declarations.

-Wmissing-variable-declarations is missing in gcc but available in clang.

Signed-off by: Rosen Penev <rosenp@gmail.com>

2 years agomountd: Fix fgets check.
Rosen Penev [Sun, 18 Dec 2016 00:09:24 +0000 (16:09 -0800)]
mountd: Fix fgets check.

fgets returns NULL on failure and a pointer otherwise. While comparing
it normally does not cause problems, comparing a pointer like this
is still undefined behavior.

Signed-off by: Rosen Penev <rosenp@gmail.com>

2 years agocmake: Really look for uci.h
Florian Fainelli [Wed, 28 Sep 2016 17:16:40 +0000 (10:16 -0700)]
cmake: Really look for uci.h

Commit 46063a1657c4 ("cmake: Find uci.h") introduced a check against libubus.h
but mountd actually uses uci.h, so fix that.

Fixes: 46063a1657c4 ("cmake: Find uci.h")
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
2 years agocleanup mountpoints of partitions failing to mount
Kristof Roelants [Fri, 9 Sep 2016 13:46:48 +0000 (15:46 +0200)]
cleanup mountpoints of partitions failing to mount

If a partition fails to mount, its autofs mountpoint is created and the mounted
flag is unset. When the partition expires or is removed, the autofs mountpoint
is cleaned up only if the mounted flag is set. Added cleanup of the autofs
mountpoint at removal and unset mounted flag.

Signed-off-by: Kristof Roelants <Kristof.Roelants@technicolor.com>
2 years agocmake: Find uci.h
Florian Fainelli [Mon, 11 Jul 2016 22:02:13 +0000 (15:02 -0700)]
cmake: Find uci.h

Add a CMake FIND_PATH and INCLUDE_DIRECTORIES searching for uci.h. Some
external toolchains which do not include standard locations would fail
to find the header otherwise.

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
2 years agosupport for disk without partition table
olivier.hardouin@gmail.com [Wed, 22 Jun 2016 07:51:19 +0000 (09:51 +0200)]
support for disk without partition table

if no partition found, try to mount the block device itself

Signed-off-by: Olivier Hardouin <olivier.hardouin@gmail.com>
2 years agohfs+ journal partition support as read only
olivier.hardouin@gmail.com [Wed, 22 Jun 2016 07:51:18 +0000 (09:51 +0200)]
hfs+ journal partition support as read only

use hfsplus driver to mount hfs+ partition marked as journalled,
read only mounting since partial support from the kernel for write
access (as stated in Documentatiom/filesystems/hfsplus.txt)
add new index 'LASTFS' to be used in case of support for another
driver

Signed-off-by: Olivier Hardouin <olivier.hardouin@gmail.com>
3 years agofilesystem mount options in uci as optional parameter
olivier.hardouin@gmail.com [Wed, 15 Jun 2016 14:10:24 +0000 (16:10 +0200)]
filesystem mount options in uci as optional parameter

Possibility to overwrite the default hardcoded settings by adding 'options'
and 'fstype' in the uci configuration. The fs names are changed in lowercase
to comply with UCI general naming.

Signed-off-by: Olivier Hardouin <olivier.hardouin@gmail.com>
3 years agoadd hotplug events
olivier.hardouin@gmail.com [Wed, 15 Jun 2016 14:10:23 +0000 (16:10 +0200)]
add hotplug events

add hotplug events (add, remove) to inform other subsystems
remove obsolete /etc/mountd/event call

Signed-off-by: Olivier Hardouin <olivier.hardouin@gmail.com>
3 years agofix crash if no uci config file present
olivier.hardouin@gmail.com [Wed, 15 Jun 2016 14:10:22 +0000 (16:10 +0200)]
fix crash if no uci config file present

fix also possible null dereferenced pointers

Signed-off-by: Olivier Hardouin <olivier.hardouin@gmail.com>
3 years agoalign fs_names table to indexes defined in include/fs.h
olivier.hardouin@gmail.com [Wed, 15 Jun 2016 14:10:21 +0000 (16:10 +0200)]
align fs_names table to indexes defined in include/fs.h

Signed-off-by: Olivier Hardouin <olivier.hardouin@gmail.com>
3 years agofix gcc format security errors
Hauke Mehrtens [Sun, 22 Nov 2015 14:43:09 +0000 (15:43 +0100)]
fix gcc format security errors

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
3 years agoadd exfat support
John Crispin [Thu, 10 Sep 2015 15:22:34 +0000 (17:22 +0200)]
add exfat support

Signed-off-by: John Crispin <blogic@openwrt.org>
3 years agomake mountd also work for mmc partitions
John Crispin [Mon, 3 Aug 2015 02:14:19 +0000 (04:14 +0200)]
make mountd also work for mmc partitions

Signed-off-by: John Crispin <blogic@openwrt.org>
3 years agoimport patches/ and cmake support
John Crispin [Mon, 27 Jul 2015 12:05:13 +0000 (14:05 +0200)]
import patches/ and cmake support

Signed-off-by: John Crispin <blogic@openwrt.org>
3 years agoimport v0.1
John Crispin [Mon, 27 Jul 2015 11:30:13 +0000 (13:30 +0200)]
import v0.1

Signed-off-by: John Crispin <blogic@openwrt.org>