Commit Graph

247 Commits

Author SHA1 Message Date
Karel Zak 2d87a7dc84 libmount: add debug message to guess FS function
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-04-12 15:04:57 +02:00
Karel Zak 4569bbeab7 libmount: fix mount.nfs segfault, rely on assert() rather than on nonnull
We use
   mnt_optstr_append_option(&o, mnt_fs_get_vfs_options(fs), NULL);

in mount.nfs, unfortunately mnt_optstr_append_option() has been marked
ass nonnull(1, 2). That's wrong because append and prepend should
robust enough to accept NULL as option name.

The patch also removes almost all __attribute__((nonnull). It seems
better to rely on assert() to have usable feedback. In many cases
(nonnull) is premature optimization for the library. This attribute
makes sense for things like strlen() or so...

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=948274
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-04-12 12:35:34 +02:00
Sami Kerola 9e01635e32 libmount, col: remove redundant null checks [smatch scan]
libmount/src/context_umount.c:174 mnt_context_find_umount_fs() info: redundant null check on loopdev calling free()
libmount/src/context_umount.c:179 mnt_context_find_umount_fs() info: redundant null check on loopdev calling free()
text-utils/col.c:406 flush_lines() info: redundant null check on l->l_line calling free()

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-04-09 12:26:42 +02:00
Sami Kerola c9f63764dc various: fix shadow declarations [smatch scan]
libmount/src/tab.c:990:34: warning: symbol 'fs' shadows an earlier one
libmount/src/tab.c:970:26: originally declared here
misc-utils/findmnt.c:492:30: warning: symbol 'tmp' shadows an earlier one
misc-utils/findmnt.c:473:14: originally declared here
fdisks/fdiskdoslabel.c:211:36: warning: symbol 'pe' shadows an earlier one
fdisks/fdiskdoslabel.c:180:20: originally declared here
fdisks/fdiskdoslabel.c:639:34: warning: symbol 'i' shadows an earlier one
fdisks/fdiskdoslabel.c:578:16: originally declared here
fdisks/fdiskdoslabel.c:947:21: warning: symbol 'i' shadows an earlier one
fdisks/fdiskdoslabel.c:924:16: originally declared here
fdisks/fdiskdoslabel.c:976:29: warning: symbol 'i' shadows an earlier one
fdisks/fdiskdoslabel.c:924:16: originally declared here
fdisks/fdiskdoslabel.c:984:29: warning: symbol 'i' shadows an earlier one
fdisks/fdiskdoslabel.c:924:16: originally declared here

[kzak@redhat.com: - don't use local 'tmp' in findmnt.c]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-04-09 12:19:25 +02:00
Ville Skyttä 58c41e15b3 Spelling fixes.
Signed-off-by: Ville Skyttä <ville.skytta@iki.fi>
2013-04-08 17:06:55 +02:00
Karel Zak 1eb8539d3b libmount: use O_CLOEXEC
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-04-03 16:14:03 +02:00
Karel Zak 39de73f5f1 libmount: add version and features to debug output
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-04-02 22:26:12 +02:00
Karel Zak 4cd271adc1 libmount: make mnt_table_find_* more robust [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-03-27 16:47:46 +01:00
Karel Zak 66c00f1f95 libmount: fix __mnt_optstr_append_option() nonull attribute [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-03-27 14:28:42 +01:00
Karel Zak b48d80fbe0 libmount: fix __mnt_cache_find_tag_value() [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-03-27 14:22:31 +01:00
Karel Zak 17206c059d libmount: fix user-mount by root for mount.<type> helpers
Append options like "exec" "suid" and "dev" to mount.<type> helpers
command line if the options are in fstab. This is relevant for root
user who calls mount(8) for fstab entries with "user,exec" etc.

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-03-26 16:05:07 +01:00
Karel Zak dcc15ce5af libmount: add mnt_table_find_mountpoint()
This is more robust implementation of mnt_get_mountpoint() that does
not ignore bind mountpoints (mount --bind /mnt /mnt) as it does not
depend on st_dev numbers.

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-03-25 13:56:31 +01:00
Karel Zak ece5d1136b libmount: make libmount.h consistent with code
The function with nonnull attribute are silently optimized by gcc so
all "if (foo)" are removed if the "foo" is expected as non-null. It
make the code less usable and robust in some situations.

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-03-25 13:40:06 +01:00
Karel Zak 52a285bf4e libmount: umount crashes when trying to umount a non-mountpoint
Reported-by: Mantas Mikulėnas <grawity@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-03-25 09:17:52 +01:00
Karel Zak 2029dbd9b1 docs: update year
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-03-15 15:18:22 +01:00
Karel Zak a3bb7e65c4 libmount: clean up header file
* don't teach people C by header files, so use warn_unused_result
   attribute only on places where we return allocated memory (to avoid
   leaks in applications).

 * merge multiple function attributes to the one list to make it
   usable with gtk-doc

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-03-15 14:59:22 +01:00
Karel Zak 6a83f8ecd7 libmount: ignore name=value if only 'name' is expected
For example

	mount /srv/www /mnt -o rw,group=woven,dev,suid

the group= should not be interpreted as userspace mount option, because
umount(8) expects 'group' (without =<value>).

Reported-by: Jan Engelhardt <jengelh@inai.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-02-28 12:55:30 +01:00
Karel Zak 6506a86601 libmount: export umount mountpoint look up code
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-02-26 14:19:05 +01:00
Karel Zak 2b90c471de libmount: don't prepare update for empty mtab/utab on umount
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-02-26 14:17:42 +01:00
Karel Zak dad88cb357 libmount: optimize tab files parsing
- ignore empty files
 - ignore empty tables

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-02-26 14:16:53 +01:00
Karel Zak 45b6445fe1 libmount: fix a mem leak
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-02-18 12:59:33 +01:00
Karel Zak 190b5ee3d2 libmount: add missing MNT_ERR_AMBIFS
Sorry, the last commit into libmount has been incomplete.

Reported-by: Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-02-14 09:20:30 +01:00
Karel Zak 82a2c1600d libmount: correctly propagate ambivalent blkid probing results
libmount ignores "ambivalent probing result" from libblkid and tries
filesystems /etc/filesystems. This is incorrect behavior.

Reported-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-02-13 12:36:10 +01:00
Karel Zak b8f2d06ed7 libmount: tags does not start with '/'
References: https://bugzilla.redhat.com/show_bug.cgi?id=909866
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-02-11 16:53:11 +01:00
Benno Schulenberg 123ddced43 textual: fix two misencodings in comments
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2013-02-06 11:15:05 +01:00
Karel Zak 56a21c9336 libmount: keep MS_PROPAGATION flags in mnt_context_set_mflags() result
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-01-15 16:08:41 +01:00
Karel Zak 6498ece0e7 libmount: allow to use propagation flags in fstab
Linux kernel does not allow to change more than one propagation flag
by one mount(2) syscall. The flags also cannot be mixed with another
mount options. It means that the propagation flags cannot be stored in
/etc/fstab, manual "mount --make-* <mountpoint>" is always necessary
after successful mount. Painful...

This patch implements additional mount(2) after previous successful
mount(2) (or exec /sbin/mount.<type>).

For example:

  mount /dev/sda1 /A -o private,unbindable,ro

or fstab entry:

  /dev/sda1   /A  auto  ro,private,unbindable

is implemented by three mount(2) calls:

	- 1st mounts /dev/sda1 with MS_RDONLY
	- 2nd sets MS_PRIVATE flag
        - 3rd sets MS_UNBINDABLE flag.

It's the same as as to manually call:

  mount /dev/sda1 /A -o ro
  mount --make-private /A
  mount --make-unbindable /A

This solution is not atomic, and umount(2) is not called if
propagation flags are not successfully applied, only error is
returned.

This change does not affect libmount API, so one beautiful day when
mount(2) syscall will be improved we can drop this nasty patch.

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-01-15 13:55:29 +01:00
Karel Zak 4b9d67a23d libmount: add mnt_fs_get_propagation()
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-01-10 15:58:52 +01:00
Ondrej Oprala e47a19312f libmount: read optional mountinfo fields
[kzak@redhat.com: - rename struct member and functions from
                    "propagation" to "optional fields"
                  - split the original patch
                  - fix parser]

Signed-off-by: Ondrej Oprala <ondrej.oprala@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-01-10 14:52:24 +01:00
Ondrej Oprala 0770effc00 libmount: fix regression test helper
Signed-off-by: Ondrej Oprala <ondrej.oprala@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-01-10 14:52:12 +01:00
Ondrej Oprala 701c69617e mount: add support for x-mount.mkdir[=<mode>] option
If the target directory (mountpoint) does not exist then mount(8) will create
it before mount.<type> is executed or mount(2) syscall is called.

Co-Author: Karel Zak <kzak@redhat.com>
Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-01-09 18:52:32 +01:00
Karel Zak fd73f46830 libmount; add recursive mkdir
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-01-09 18:05:08 +01:00
Karel Zak 51479069e1 libmount: fix typos
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-12-12 21:02:11 +01:00
Karel Zak 6fc8122490 libmount: make mkstemp() more robust [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-12-12 13:32:52 +01:00
Karel Zak cd79396704 libmount: don't use safe_getenv() for test
Reported-by: Bernhard Voelker <mail@bernhard-voelker.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-12-10 13:31:08 +01:00
Bernhard Voelker 2c0ba1ce30 libmount: avoid endless loop in mnt_get_kernel_cmdline_option
The above function infloops when the name to search for can only
be found at the beginning of /proc/cmdline but doesn't match,
e.g. when searching for "ro" in "root=/dev/sda1 quiet vga=0x31a".

* libmount/src/utils.c (mnt_get_kernel_cmdline_option): Replace
while by for loop to ensure the pointer p is incremented.

Signed-off-by: Bernhard Voelker <mail@bernhard-voelker.de>
2012-12-10 13:15:19 +01:00
Karel Zak ba2bdf41c4 libmount: clean nonnull attribute usage
- use __attribute__((nonnull) for functions where we not able to
   return an return code ("is", "has" and some "get" functions).

 - use __attribute__((nonnull) for small functions where we
   always modify any of the function argument (some mnt_optstr_* functions)

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-12-04 14:22:39 +01:00
Ondrej Oprala 90cd46cbbd libmount: add function attributes to private API
Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-11-30 10:34:08 +01:00
Ondrej Oprala a639778557 libmount: add function attributes to public API
[kzak@redhat.com: - use __ul prefix in public API,
                  - define minimal requirement gcc 3.4]

Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-11-30 10:34:01 +01:00
Karel Zak 1e7f2e6cf4 libmount: make debug stuff more robust
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-11-26 12:19:02 +01:00
Karel Zak ec8121b103 libmount: correctly interpret '*' from /etc/filesystems
- single line with '*' in /etc/filesystems means that libmount has to
   read /proc/filesystems, otherwise /proc/filesystems has to be ignored

 - mount(2) ENODEV is no reason to break the do_mount_by_pattern()
   loop when trying to mount by /{etc,proc}/filesystems

Reported-by: NeilBrown <neilb@suse.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-11-26 11:21:40 +01:00
Gleb Fotengauer-Malinovskiy bbf9ce79ec libmount: fix support of comma-separated fs types lists
# grep cdrom /etc/fstab
	/dev/sr0 /media/cdrom udf,iso9660 ro,noauto,user,utf8 0 0
	# mount /media/cdrom
	mount: unknown filesystem type 'udf,iso9660'

	# mount -t udf,iso9660 /dev/sr0 /media/cdrom
	mount: /dev/sr0 is write-protected, mounting read-only

[kzak@redhat.com: - add some comments
                  - don't try to found external helpers for the types]

Signed-off-by: Gleb Fotengauer-Malinovskiy <glebfm@altlinux.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-11-16 10:31:49 +01:00
Karel Zak ae978c4d6c umount: (recursive) don't call umount(2) for already unmounted targets
In the umount --recursive we follow entries from mountinfo, but the
entries maybe already obsolete. Especially if the hierarchy of the
mountpoints contains shared subtrees and umount(2) for one entry may
generate umount for some other entry too.

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-11-15 16:44:07 +01:00
Karel Zak f3107fc244 libmount: don't reset NOSWAPMATCH context flag
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-11-15 16:42:05 +01:00
Karel Zak 224f5b92ac libmount: don't try to play with loopdevs if umount argument is really mountpoint
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-11-15 15:59:59 +01:00
Karel Zak 9be1607fa3 libmount: more robust tab filter usage
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-11-15 15:35:24 +01:00
Karel Zak 3da7f698c1 libmount: convert /dev/root from mountinfo to the device name
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-11-08 14:43:38 +01:00
Karel Zak f308ec19a7 libmount: add private mnt_get_kernel_cmdline_option()
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-11-08 11:59:36 +01:00
Karel Zak b2cbe99f33 libmount: support loopdevs in mnt_table_is_fs_mounted()
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-10-24 23:44:11 +02:00
Karel Zak 449a7646d0 libmount: tiny refactoring in mnt_table_is_fs_mounted()
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-10-23 15:45:50 +02:00