Commit Graph

452 Commits

Author SHA1 Message Date
Karel Zak 8e5c467500 build-sys: support --with-python[={2,3}]
* we use pkg-config to get CGLAGS and LIBS, use package specific
   config (e.g. python-config) is non-sense.

 * default is to follow distribution and use pkg-config module name
   "python". This is probably symlink to python2.pc or python3.pc.

 * --with-python=2 forces to pkg-module "python2 >= 2"

 * --with-python=3 forces to pkg-module "python3 >= 3"

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-09-20 12:42:45 +02:00
Dave Reisner 2afcbe139d libmount: free username after check
Leak reported by valgrind:

==14226== 7 bytes in 1 blocks are definitely lost in loss record 1 of 1
==14226==    at 0x4C2757B: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==14226==    by 0x5534839: strdup (in /usr/lib/libc-2.18.so)
==14226==    by 0x4E53FE0: mnt_get_username (utils.c:560)
==14226==    by 0x4E456A5: mnt_context_prepare_umount (context_umount.c:413)
==14226==    by 0x4E464F7: mnt_context_umount (context_umount.c:851)
==14226==    by 0x403476: umount_one (umount.c:299)
==14226==    by 0x402B34: main (umount.c:629)

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2013-09-20 10:06:01 +02:00
Dave Reisner 4e9f59d1ee libmount: use memmove when overlap possible
When unmounting some mountpoints as an unprivileged user (via the
'user' option in fstab), the umount fails. Debug output of 'umount
/opt' reveals:

17760: libmount: CXT: [0x22890e0]: do umount
17760: libmount: UTILS: moving to /opt parent
17760: libmount: CXT: current directory moved to / [last_component='opt']
17760: libmount: CXT: [0x22890e0]: umount(2) [target='pt', flags=0x00000000]

valgrind shows the problem:

==23544== Source and destination overlap in memcpy(0x58d1370, 0x58d1371, 4)
==23544==    at 0x4C2BBC3: memcpy@@GLIBC_2.14 (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==23544==    by 0x4E537C3: mnt_chdir_to_parent (utils.c:168)
==23544==    by 0x4E45E4C: mnt_context_do_umount (context_umount.c:601)
==23544==    by 0x4E46513: mnt_context_umount (context_umount.c:855)
==23544==    by 0x403476: umount_one (umount.c:299)
==23544==    by 0x402B34: main (umount.c:629)
==23544==

ref: https://bugs.archlinux.org/task/36968
Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2013-09-20 10:05:45 +02:00
Karel Zak 60f25deae7 lib: rename time-util.c to timeutils.c, fix headers
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-09-10 13:11:02 +02:00
Sami Kerola 199e939d88 lib/strutils: move *swith() functions to private library
Avoid code dublication in libmount and time-util.

Proposed-by: Karel Zak <kzak@redhat.com>
Reference: http://markmail.org/message/h7zexvqsieqngtmx
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-29 18:14:08 +01:00
Karel Zak 03d00d495f build-sys: add CFLAGS and LDFLAGS for daemons and shared libs
This is necessary for paranoid security guys who believe that things
like "-Wl,-z,relro" or "-Wl,-z,bind_now" is a way how to make the
world a safer place...

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-27 11:49:01 +02:00
Karel Zak 40e5013ce5 pylibmount: improve helps strings formatting
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-22 13:24:05 +02:00
Karel Zak b7e47ac1ac pylibmount: add debug messages
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-22 12:10:13 +02:00
Karel Zak 14104e931e libmount: cleanup libmnt_fs list after mnt_table_remove_fs()
.. otherwise mnt_free_fs() will try to remove FS from non-existing
list.

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-22 11:57:06 +02:00
Karel Zak 20b222ec5c pylibmount: use libmount reference counting
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-22 09:44:38 +02:00
Karel Zak c9f1585e67 libmount: add reference counter to libmnt_table
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-21 16:07:25 +02:00
Karel Zak 0105691d54 libmount: add reference counting to libmnt_cache
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-21 14:37:55 +02:00
Karel Zak 26d0c0aefd libmount: add reference counting to libmount_fs
* mnt_new_fs() returns object with refcount=1
 * mnt_free_fs() does not care about reference counter

 * new functions mnt_ref_fs() and mnt_unref_fs()

 * mnt_table_add_fs() and mnt_table_rem_fs() uses reference counter

 * libmmnt_context uses reference counter for internal FS (as it could be
   shared outside the context)

 * backwardly incompatible change:

	- FS could be deallocated after mnt_table_remove_fs()

 * it's recommended to use mnt_unref_fs() after mnt_table_add_fs()

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-21 12:48:42 +02:00
Karel Zak 6d5189376d pylibmount: remove Context_get_table()
It's too problematic and too low-level to support it Py binding.

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-21 10:06:15 +02:00
Karel Zak a4ac8f0385 pylibmount: cleanup cxt usage
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-21 10:02:19 +02:00
Karel Zak 32953aebdd libmount: add function for context userdata
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-21 10:01:23 +02:00
Karel Zak 73d5b4ebdb pylibmount: remove unnecessary code
It's enough to call mnt_free_fs() to remove fs from the table.

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-20 17:52:47 +02:00
Karel Zak a2f17bb24e libmount: add mnt_table_is_empty(), improve table list usage
Currently you have to use mnt_table_remove_fs() + mnt_free_fs() to
destroy the list in the table. This is complicated in same situations.
This patch allows to use mnt_free_fs() only.

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-20 14:35:13 +02:00
Karel Zak c643ad4d81 pylibmount: coding style changes, don't touch Context() status
It's better to follow libmnt_context status than allow to play any
nasty games with this important variables in Python.

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-20 14:01:39 +02:00
Karel Zak 2d59ffa15a pylibmount: use only public libmount API in tab.c
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-20 13:52:09 +02:00
Karel Zak 686a64670e libmount: add mnt_table_{first,last}_fs()
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-20 13:48:43 +02:00
Karel Zak f8271ff872 libmount: add new function to docs
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-20 12:41:53 +02:00
Karel Zak 2bc04c11f9 libmount: add mnt_table_{set,get}_userdata()
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-20 12:41:27 +02:00
Karel Zak e670df45c6 libmount: add mnt_table_with_comments()
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-20 12:32:19 +02:00
Karel Zak 278b5be599 pylibmount: cleanup *_HELP strings formatting
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-20 12:07:24 +02:00
Karel Zak 279a6d5f41 pylibmount: use mnt_fs_set_userdata() rather than ->userdata
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-20 11:32:49 +02:00
Karel Zak a2cb025024 pylibmount: fs.c - cleanup, remove libmount private stuff
* remove unnecessary comments
 * cleanup up strings format
 * remove direct access to private libmount stuff

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-20 11:08:07 +02:00
Karel Zak 71fbe15192 pylibmount: remove bindsrc from fs API
It's unnecessary and very low-level.

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-20 10:49:14 +02:00
Karel Zak 5c7664f735 pylibmount: cleanup object names
Cxt -> Context
	Tab -> Table

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-19 17:10:07 +02:00
Karel Zak 6b47d7f5c7 pylibmount: coding style changes in tab.c
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-19 16:57:50 +02:00
Karel Zak 679f086c54 pylibmount: coding style changes in fs.c
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-19 16:51:23 +02:00
Karel Zak 77733ec880 pylibmount: coding style changes in context.c
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-19 16:41:04 +02:00
Karel Zak 15c2e011a7 build-sys: install pylibmount into
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-19 15:24:33 +02:00
Ondrej Oprala 90eb39874f pylibmount: add regression tests
Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-19 15:11:06 +02:00
Ondrej Oprala 3246f4b98c pylibmount: add __init__.py
Signed-off-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
2013-08-19 15:06:37 +02:00
Ondrej Oprala 813683a352 pylibmount: basic code
[kzak@redhat.com: - split to more patches
                  - split to more .c files]

Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-19 15:00:15 +02:00
Karel Zak d78df0ac65 build-sys: add pylibmount
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-19 14:57:21 +02:00
Karel Zak 68c41a5f5f libmount: be robust when work with loopdev backing file paths
It's usually unnecessary as we compare devno and ino, but let's
use absolute paths for situations when it's necessary to compare
paths as strings.

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-05 15:35:39 +02:00
Karel Zak 3f420a49dd libmount: canonicalize for conversion from loopdev backing file
# mount foo.img /mnt
  # umount foo.img
  umount: foo.img: not mounted

The loopdev code (and sysfs backing_file) uses absolute paths, but
libmount does not canonicalize the path before lookup for the backing file.

References: https://bugzilla.redhat.com/show_bug.cgi?id=950497
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-05 13:58:01 +02:00
Ondrej Oprala d58b315704 libmount: fix typos
Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
2013-08-05 10:47:02 +02:00
Ondrej Oprala 7b1333fa6a libmount: add missing declarations to libmount.h.in and documentation
Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
2013-08-01 11:23:02 +02:00
Ondrej Oprala 3035ba93af libmount: change tailing to trailing in *_tailing_comments functions
Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
2013-08-01 11:21:47 +02:00
Karel Zak cfa44747f3 libmount: fix memory leak [clang-analyzer]
Reported-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-07-09 14:39:49 +02:00
Karel Zak d828dfdfb2 lsblk: use devno to check if the filesystem is mounted
The device (for example LVM logical volume) could be renamed and then
the device name from /proc/self/mountinfo does not match with reality.
So, we also need to check devno. Unfortunately we cannot completely
rely on devno, because for example btrfs uses psudo device numbers.

References: https://bugzilla.redhat.com/show_bug.cgi?id=980463
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-07-08 14:24:31 +02:00
Ondrej Oprala d22f2822ed libmount: add functions to safely replace a fs table
Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
2013-07-03 11:21:33 +02:00
Ondrej Oprala cb90e24e80 libmount: add functions to handle comments in fs tables
Co-Author: Karel Zak <kzak@redhat.com>
Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-07-03 10:17:37 +02:00
Karel Zak 40b2786480 libmount: add a generic append_string() function
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-07-02 11:58:58 +02:00
Karel Zak 2c6b25f018 libmount: be more restrictive about valid tag names
# mount DUMMY=filename.img /mnt

The 'DUMMY=filename.img' is a filename and should not be
interpreted as tag name. The valid tag names are LABEL, UUID,
PARTLABEL and PARTUUID only.

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-07-02 10:46:10 +02:00
Karel Zak 7ba207e781 libmount: be robust for empty target/source strings
* lib/canonicalize.c: don't interpret empty strings as relative paths
 * libmount: more robust libmnt_table find function and debug messages

References: https://bugzilla.novell.com/show_bug.cgi?id=825150
Signed-off-by: Karel Zak <kzak@redhat.com>

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-06-17 13:02:15 +02:00
Karel Zak 8225bb78a6 libmount: more robust options string parsing
# mount -o=rw /dev/sdb /mnt/test
 mount: libmount/src/optmap.c:212: mnt_optmap_get_entry: Assertion `namelen' failed.
 Aborted (core dumped)

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=968786
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-05-30 13:29:34 +02:00
Karel Zak 9104cd2850 libmount: use err.h in test
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-05-14 23:40:51 +02:00
Karel Zak 0b56c45956 libmount: don't ignore root fs on umount -a
The release v2.22 (the new umount) introduces a regression when root
fs is excluded from umount --all. There is not reason for this
exception. The libmount should be smart enough to disable mtab update
after rootfs umount.

Reported-by: Bruce Dubbs <bruce.dubbs@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-05-14 10:32:56 +02:00
Karel Zak a21aa92fd4 libmount: use MS_SILENT for /{proc,etc}/filesystems
mount(8) needs to be doing silent mounts when doing this brute
forcing or when the filesystem is not explicitly specified.

Reported-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-05-09 09:25:31 +02:00
Sami Kerola 69f1cad4ca libmount: (test) check writing to a file was successful
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-04-26 13:40:27 +02:00
Yuri Chornoivan ef75bc880e Fix various typos 2013-04-26 12:50:03 +02:00
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
Sami Kerola 913e43b8e2 libmount, eject: replace index() and rindex() with strrch() or strrchr()
Both index() and rindex() are legacy functions which may be withdrawn in
a future.

Reference: http://pubs.opengroup.org/onlinepubs/009695399/functions/index.html
Reference: http://pubs.opengroup.org/onlinepubs/009695399/functions/rindex.html
Acked-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-10-22 10:13:32 +02:00
Raul Gutierrez Segales 39e119f5dc libmount: fixed comment about param
Signed-off-by: Raul Gutierrez Segales <rgs@itevenworks.net>
2012-10-15 17:13:23 +02:00
Karel Zak 6d5d2b5fd3 libmount: don't use umount optimization for -l or -f
The options -l (lazy) and -f (force) means that the mountpoint may be
unreadable (for example because NFS server is unreadable). So we
should not try to be smart in this case and we should try to minimize
number of situations when stat() or readlink() is used for the
mountpoint.

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-10-15 11:10:50 +02:00
Karel Zak dc3ea13356 libmount: fix umount file.img
The umount optimization (commit 9cc03553f7)
has to be disabled if the umount argument is not a directory.

Reported-by: Milan Broz <mbroz@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-10-05 20:38:49 +02:00
Gilles Espinasse 45683be543 textual: typo fixes
Signed-off-by: Gilles Espinasse <g.esp@free.fr>
2012-10-02 10:24:26 +02:00
Karel Zak 1ae3d0d932 libmount: don't setup new loopdev on remount with regular mtab
[chroot-i486] root:/tmp$ mount -oloop /tmp/blob /tmp/mnt
[chroot-i486] root:/tmp$ mount -o remount,loop,ro /tmp/mnt
[chroot-i486] root:/tmp$ mount
/dev/loop0 on /tmp/mnt type ext2 (ro,loop)
[chroot-i486] root:/tmp$ losetup -a
/dev/loop0: [2051]:306957 (/tmp/blob)
/dev/loop1: [0005]:2218 (/dev/loop0)
[chroot-i486] root:/tmp$ umount /tmp/mnt
umount: /tmp/mnt: filesystem umounted, but mount(8) failed: Device or
resource busy
[chroot-i486] root:/tmp$ losetup -d /dev/loop1
[chroot-i486] root:/tmp$ losetup -d /dev/loop0

Reported-by: g.esp@free.fr
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-09-26 11:25:01 +02:00
Karel Zak ab6c01925c libmount: improve debug message
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-09-25 17:04:21 +02:00
Karel Zak 4709c9e6a1 libmount: optimize mtab and utab parsing in umount
create 8000 NFS mountpoints:
	#!/bin/bash
	mount=/tmp/mount
	if [ ! -d $mount ]; then
	    mkdir -p $mount
	fi
	for dir in {1..8000}; do
	    if [ ! -d $mount/$dir ]; then
		mkdir -p $mount/$dir
	    fi
	    echo mount $dir
	    mount -t nfs 127.0.0.1:/ $mount/$dir
	done

old version:
	time ./umount /tmp/mount/2255

	real	0m1.254s
	user	0m1.002s
	sys	0m0.238s

new version:
	time ./umount /tmp/mount/2244

	real	0m0.332s
	user	0m0.111s
	sys	0m0.218s

Reported-by: chenditang <chendt.fnst@cn.fujitsu.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-09-25 16:47:18 +02:00
Karel Zak 9af2433419 libmount: user-mounted loopback fs cannot be unmounted by user
Addresses: https://bugs.archlinux.org/task/31624
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-09-21 17:15:07 +02:00
Karel Zak e8cd181967 libmount: append loop option when automatically create loopdev
The loop option is optional, mount(8) is able to detect that the
source path is regular file (image) with known filesystem -- then a
loop device is automatically created. In this case we have to store
"loop" option to mtab on systems without autoclear loopdev flag.

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-09-18 11:40:44 +02:00
Karel Zak 475c30d061 libmount: detach loopdev on umount if loop option in mtab
[chroot-i486] root:/$ mount --version
mount from util-linux 2.22 (libmount 2.22.0: debug)
[chroot-i486] root:/$ losetup -a
[chroot-i486] root:/$ mount -oloop /tmp/foo_fs /tmp/bar_dir
[chroot-i486] root:/$ umount /tmp/foo_fs
[chroot-i486] root:/$ losetup -a
/dev/loop0: [2051]:387175 (/tmp/foo_fs)

Reported-by: g.esp@free.fr
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-09-18 11:22:17 +02:00
Karel Zak 4be900c51d libmount: don't remove user= when executed by root
The original mount(8) allows to store arbitrary user= option to mtab
file if called by root user. For example:

  # mount -f foo /bar -t xxx -o rw,user=kzak

the new mount removes the 'user=' and 'users' options at all for root
user. This is regression. The original functionality is necessary by
'sshfs' where fuse writes to mtab file by mount(8).

Reported-by: Juergen Daubert <jue@jue.li> (and 'horrorStruck' on IRC)
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-09-12 14:27:12 +02:00
Karel Zak 3de77c2173 libmount: segfaults if neither /etc/filesystems nor/proc/filesystems exists
Reported-by: Juergen Daubert <jue@jue.li>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-09-12 11:57:19 +02:00
Ludwig Nussel 5cf05c7147 mount: losetup: remove obsolete encryption support
kernel cryptoloop is deprecated since ages and support for cryptoloop
in util-linux is incomplete/broken.
- no password hashing
- last 8 bit of key are always set to zero
- no binary keys possible (stops reading key at \n and \0)

In the past some Distros added the above features with patches. So
remove cryptoloop support from util-linux completely to make sure
people won't try using it.

Signed-off-by: Ludwig Nussel <ludwig.nussel@suse.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-09-11 10:46:11 +02:00
Karel Zak c667aff93f libmount: improve mnt_table_get_root_fs() docs
Fix info about return value, improve description.

Reported-by: Amit <amit.uttam@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-09-10 10:30:11 +02:00
Karel Zak d39c2b438f libmount: use O_CLOEXEC everywhere
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-09-04 16:49:28 +02:00
Karel Zak c3085df65f libmount: remount does not add entry to mtab file
# mount -n -o ro /dev/sda1 /
 # mount -o remount,rw /dev/sda1 /

For the backward compatibility the command mount(8) should to add a
new entry to the file /etc/mtab on remount if the original entry not
found (because previous mount has been called with -n).

Reported-by: <frinnst> on IRC
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-08-27 19:26:07 +02:00
Karel Zak 975e14bd4a libmount: rewrite mnt_table_is_fs_mounted() to be less aggressive
The old implementation always canonicalizes target (mountpoint) path.
It's better to postpone this operation until the path is really
necessary (usually it's unnecessary), because readlink() on mountpoint
may trigger automounts.

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-08-24 18:29:51 +02:00
Karel Zak d4baf92e50 build-sys: expand paths at make time
autoconf docs about *dir variables (e.g bindir):

 ... A corollary is that you should not use these variables except in
 makefiles...

 ...you should not rely on AC_CONFIG_FILES to replace bindir and friends
 in your shell scripts and other files; instead, let make manage their
 replacement.

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-08-15 02:06:53 +02:00
Karel Zak 43ffdc82fa build-sys: don't compile lib{mount,blkid} tests when --disable-static specified
The tests often depend on private (non-API) library functions.

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-08-02 20:19:14 +02:00
Karel Zak f1f9a46abd libmount: deduplicate SELinux mount options
We already have a clue about SELinux specific mount options in libmount, so
it makes sense to deduplicate the options as Linux kernel does not
support duplicate SELinux options. (SELinux kernel stuff somehow
ignores standard Linux mount conventions...)

Requested-by: Niels de Vos <ndevos@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-08-01 17:52:22 +02:00
Karel Zak 6870636c7f libmount: add mnt_optstr_deduplicate_option()
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-08-01 17:51:43 +02:00
Karel Zak 922e6775e0 build-sys: move tests to check_PROGRAMS
Thanks to Mike Frysinger.

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-07-30 17:59:16 +02:00
Karel Zak aa8135f81b build-sys: add minisg COPYING files
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-07-27 00:56:28 +02:00
Sami Kerola 61d97775ef libmount: add noreturn function attribute
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-07-26 13:51:29 +02:00
Sami Kerola 8228372b0e libmount: fix shadow declaration
libmount/src/tab_update.c:203:8: warning: declaration of 'rc' shadows a previous local [-Wshadow]
libmount/src/tab_update.c:159:6: warning: shadowed declaration is here [-Wshadow]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-07-26 11:09:38 +02:00
Karel Zak 3d660e74fc libmount: fix compiler warning [-Wsign-compare]
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-07-26 09:44:37 +02:00
Karel Zak 994871c59f libmount: check VFS mount options in mnt_diff_tables()
after "-o remount,ro" in unshared namespace is the original VFS entry
still read-write:

original:
42 21 8:2 / /boot rw,relatime - ext4 /dev/sda2 ro,user_xattr,acl,barrier=1,data=ordered

unshared + ro remount:
78 51 8:2 / /boot ro,relatime - ext4 /dev/sda2 ro,user_xattr,acl,barrier=1,data=ordered

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-07-18 22:09:24 +02:00
Karel Zak e39cbb7603 libmount: allow to disable swap between source and target
In some cases (for example if only one mount argument is given) may be
mount request ambivalent:

	# mount /foo

and fstab:

	/dev/sda5	/foo	rw	0	0
	/foo		/bar	bind	0	0

The libmount allows to swap between source and target (if
source is not LABEL or UUID) by default. The new function

	mnt_context_disable_swapmatch()

allows to disable this feature.

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-07-17 21:57:22 +02:00
Karel Zak b11c9b7ee3 libmount: rename mnt_context_fstab_applied to mnt_context_tab_applied
The function is also usable in umount to detect is mtab has been
applied.

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-07-12 17:43:34 +02:00
Bernhard Voelker 7007991f6f docs: fix typos found by misspellings
The tool misspellings (https://github.com/lyda/misspell-check)
detected several typos. Command used:

  $ git ls-files | grep -v ^po/ | misspellings -f -

* Documentation/releases/v2.18-ReleaseNotes: Fix typo in news entry.
* NEWS: Likewise.
* config/texinfo.tex: Fix typo in comments.
* libmount/src/context.c: Fix typo in comment.
* libmount/src/fs.c: Likewise.
* login-utils/login.c: Likewise.
* login-utils.su.1: Fix typo in man page.
* sys-utils/chcpu.c: Fix typo in error message.

Signed-off-by: Bernhard Voelker <mail@bernhard-voelker.de>
2012-07-09 16:56:30 +02:00
Karel Zak f7f29b5640 libmount: save task ID for mountinfo tiles
Add new function mnt_fs_get_tid() to get task ID for the given filesystem.

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-06-28 15:40:16 +02:00
Karel Zak 31a938ac38 build-sys: enable libmount and libblkid docs
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-06-26 20:50:54 +02:00
Karel Zak f38e5ff355 build-sys: cleanup .gitignore files
- move all binaries to top-level .gitignore
 - remove unnecessary */.gitignore files

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-06-26 20:50:54 +02:00
Karel Zak d77ab74af7 build-sys: convert lib/ to libcommon.la
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-06-26 20:50:53 +02:00
Karel Zak bc94024d08 build-sys: convert libmount/ to module
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-06-26 17:49:37 +02:00
Karel Zak defa0710b6 lib/loopdev: use warn_unused_result forimportant functions
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-06-21 10:40:43 +02:00
Karel Zak 23966912fb libmount: improve ifdef HAVE_LIBSELINUX stuff
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-06-19 16:19:18 +02:00
Karel Zak d5f9b6e5fb Merge branch '2012wk23' of git://github.com/kerolasa/lelux-utiliteetit
* '2012wk23' of git://github.com/kerolasa/lelux-utiliteetit:
  lsblk: use blkdev_scsi_type_to_name()
  blkdev: add blkdev_scsi_type_to_name()
  wipefs: use symbolic value for markup mode
  eject: inform if CD-ROM drive is not ready
  docs: clean up partx.8 manual
  include: fix void pointer arithmetics warnings
  sysfs: fix printf format warnings
  build: fix unused parameter warnings
  build: fix redundant redeclaration warnings
  include: fix spurious list.h warnings
  uuidd: use output redirection which works [checkbashisms]
  blkid: fix realloc memory leak [cppcheck]
  setarch: do not use -1 as array index [cppcheck]
2012-06-15 12:44:17 +02:00
Karel Zak 9d670a2ab4 libmount: make some string operations more robust
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-06-15 12:26:05 +02:00
Petr Uzel 3cbc5a9559 libmount: fix trivial typos
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
2012-06-15 11:52:13 +02:00
Petr Uzel bf15afd1e7 libmount: fix read before allocated buffer
valgrind --leak-check=full ./sys-utils/mount -t cifs //127.0.0.1/users /mnt/smb -o user=root,password=linux
....
==21359== Invalid read of size 1
==21359==    at 0x415AC6: mnt_optstr_remove_option_at (optstr.c:310)
==21359==    by 0x416358: mnt_optstr_apply_flags (optstr.c:716)
==21359==    by 0x40DFBF: mnt_context_prepare_mount (context_mount.c:86)
==21359==    by 0x40EB5A: mnt_context_mount (context_mount.c:782)
==21359==    by 0x4058B0: main (mount.c:918)
==21359==  Address 0x51cd5bf is 1 bytes before a block of size 10 alloc'd
==21359==    at 0x4C297CD: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21359==    by 0x4C29957: realloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21359==    by 0x415780: __mnt_optstr_append_option (optstr.c:188)
==21359==    by 0x412822: mnt_fs_append_options (fs.c:764)
==21359==    by 0x409288: mnt_context_append_options (context.c:733)
==21359==    by 0x4053F0: main (mount.c:776)

Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
2012-06-15 11:52:10 +02:00
Petr Uzel 31821efc29 libmount: plug a memory leak in exec_helper()
valgrind --leak-check=full ./sys-utils/mount -t cifs //127.0.0.1/users /mnt/smb -o user=root,password=linux
....
==21359== 28 bytes in 1 blocks are definitely lost in loss record 1 of 1
==21359==    at 0x4C298B2: realloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21359==    by 0x415780: __mnt_optstr_append_option (optstr.c:188)
==21359==    by 0x415CB5: mnt_optstr_set_option (optstr.c:387)
==21359==    by 0x40D778: do_mount (context_mount.c:192)
==21359==    by 0x40E6A9: mnt_context_do_mount (context_mount.c:685)
==21359==    by 0x40EB7B: mnt_context_mount (context_mount.c:786)
==21359==    by 0x4058B0: main (mount.c:918)

Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
2012-06-15 11:52:05 +02:00
Karel Zak e90e7401d0 libmount: don't use nosuid,noexec,nodev for cifs user=foo
mount -t cifs //127.0.0.1/users /mnt/smb -o user=root,password=linux

is incorrectly translated to

   mount.cifs -o noexec,nosuid,nodev,user=root,password=linux ...

The command mount(8) should be sensitive to "user" (without "=<name>")
only. The correct cifs command line is:

   mount.cifs -o user=root,password=linux

Addresses: https://bugzilla.novell.com/show_bug.cgi?id=766157
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-06-14 14:19:26 +02:00
Karel Zak 6b741564d8 libmount: don't generate empty option strings
mount -t foo something /mnt/test -o user=root,password=linux

generates

 "rw,noexec,nosuid,nodev,password=linux,,user=root"

options string for /sbin/mount.foo, the ",," is incorrect.

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-06-14 11:38:53 +02:00
Sami Kerola 838c5f6bb8 build: fix unused parameter warnings
pager.c:203:14: warning: unused parameter 'argc' [-Wunused-parameter]
pager.c:203:26: warning: unused parameter 'argv' [-Wunused-parameter]

randutils.c:108:14: warning: unused parameter 'argc' [-Wunused-parameter]
randutils.c:108:26: warning: unused parameter 'argv' [-Wunused-parameter]

optstr.c:774:37: warning: unused parameter 'optstr' [-Wunused-parameter]
optstr.c:774:51: warning: unused parameter 'value' [-Wunused-parameter]
optstr.c:774:65: warning: unused parameter 'valsz' [-Wunused-parameter]
optstr.c:774:79: warning: unused parameter 'next' [-Wunused-parameter]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-06-11 19:51:35 +02:00
Sami Kerola 0e9b73d3fb build: fix redundant redeclaration warnings
env.c:24:15: warning: redundant redeclaration of 'environ' [-Wredundant-decls]
su.c:81:15: warning: redundant redeclaration of 'environ' [-Wredundant-decls]

fstab.c:581:14: warning: redundant redeclaration of 'strsignal' [-Wredundant-decls]

kill.h:1:13: note: previous declaration of 'get_pids' was here
kill.c:152:13: warning: redundant redeclaration of 'get_pids' [-Wredundant-decls]

kill.c:142:5: warning: redundant redeclaration of 'main' [-Wredundant-decls]
getopt.c:89:5: warning: redundant redeclaration of 'main' [-Wredundant-decls]

agetty.c:536:15: warning: redundant redeclaration of 'optarg' [-Wredundant-decls]
agetty.c:537:13: warning: redundant redeclaration of 'optind' [-Wredundant-decls]
script.c:161:13: warning: redundant redeclaration of 'optind' [-Wredundant-decls]
wall.c:96:13: warning: redundant redeclaration of 'optind' [-Wredundant-decls]

libmount.h:362:26: note: previous declaration of 'mnt_update_get_fs' was here
libmount.h:454:26: note: previous declaration of 'mnt_context_get_fs' was here
mountP.h:383:26: warning: redundant redeclaration of 'mnt_context_get_fs' [-Wredundant-decls]
mountP.h:398:26: warning: redundant redeclaration of 'mnt_update_get_fs' [-Wredundant-decls]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-06-11 19:51:35 +02:00
Dave Reisner 5e7b834002 libmount: trim leading commas from each options string
Fixes a bug in option string parsing wherein a line such as:

  ro,relatime,,nosuid,nodev

Will be seen as only the tokens "ro" and "relatime" after the parser
encounters a zero length (and erroneously declared NULL) option.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-06-05 15:40:11 +02:00
Bernhard Voelker 871ffd0960 Fix typos in comments and wall's man page
Culprits identified again by (newer) misspellings:

  $ git ls-files | misspellings -f - | grep -v '^po/'

* wall: Fix typo in man page.
* Fix typos in source code comments.

Signed-off-by: Bernhard Voelker <mail@bernhard-voelker.de>
2012-06-05 14:37:26 +02:00
Karel Zak 61f5ff6cb4 libmount: add MNT_ERR_MOUNTOPT
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-05-28 12:49:55 +02:00
Karel Zak 82756a747e libmount: add MNT_ERR_LOOPDEV
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-05-28 12:26:36 +02:00
Karel Zak dffdc98958 libmount: use stderr for initial debug message
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-05-23 11:05:37 +02:00
Dave Reisner 7383ebceec libmount: Use binary search to compare pseudofs
It's the responsibility of anyone adding to this list in the future to
ensure that the list remains sorted.

While we're at it, expand this list of known pseudofs types.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-05-23 09:56:51 +02:00
Karel Zak fa705b5441 libmount: don't canonicalize target
Note that mountpoint (target_ paths in /proc/mounts and /proc/self/mountinfo
are always canonicalized by kernel.

 * for umount we don't have to canonicalize target
   by default if the mountpoint is found in /proc/self/mountinfo

 * in mnt_table_find_target() is unnecessary to canonicalize target paths
   if the table of the filesystems is read from /proc/self/mountinfo

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=820707
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-05-17 12:10:43 +02:00
Karel Zak 6257e44582 libmount: close device fd (to avoid mount(2) EBUSY)
libmount uses libblkid to detect filesystem type. Unfortunately, the
blkid probe struct is not freed before mount(2), it means that the
device is still open and mount(2) may return EBUSY.

We don't need persistent blkid stuff in libmount, so let's close
all immediately after device probing.

Reported-by: David Zeuthen <zeuthen@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-04-27 10:30:08 +02:00
Dave Reisner cd3d6c5bd0 libmount: expose mnt_get_mountpoint as external API 2012-04-26 09:38:02 +02:00
Karel Zak 677ff053f6 libmount: add mnt_table_find_devno()
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-04-25 09:49:50 +02:00
Karel Zak 54a3d5eeec libmount: fix mnt_context_guess_fstype()
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-04-25 09:05:24 +02:00
Karel Zak 47dea49b4c libmount: add special MNT_ERR_ codes
... to detect some situations where standard -errno is too generic.

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-04-24 11:57:32 +02:00
Karel Zak ae5afe071f libmount: fix mount by pattern
mount /foo /bar

without entry in /etc/fstab the mount command tries all filesystems
from /{etc,proc}/filesystems. We should NOT call mount(2) more then
once if the syscall returns for example ENOENT, acceptable is only
EINVAL.

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-04-24 11:52:04 +02:00
Bernhard Voelker 455fe9a075 Fix typos found by misspellings
The tool misspellings (https://github.com/lyda/misspell-check)
detected several typos. Command used:

  $ git ls-files | grep -v ^po/ | misspellings -f -

* isosize: Fix typo in usage string.
* configure.ac: Fix typo in help string of --enable-most-builds option.
* fdisk: Fix typo in man page.
* libblkid, blkid, mount: Likewise.
* Fix various typos in docs and in source code comments.

Signed-off-by: Bernhard Voelker <mail@bernhard-voelker.de>
2012-04-23 13:16:35 +02:00
Karel Zak cff632afc9 libmount: add support for PARTUUID= and PARTLABEL=
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-04-19 14:33:59 +02:00
Karel Zak 5d451abbbf libmount: add mnt_context_get_options()
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-04-18 10:06:35 +02:00
Karel Zak e01c731992 libmount: add mnt_context_fstab_applied()
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-04-17 11:36:32 +02:00
Karel Zak ce4dd666f4 libmount: add support to parse /proc/swaps
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-04-03 13:20:32 +02:00
Karel Zak 7104bedb78 libmount: clean up MNT_FMT_* usage in parser
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-04-03 11:32:12 +02:00
Dong Hao c7b0af96bc mount: fix recursively propagation mounting
Provide the recursive flag of propagation mounting. Recursive flag could
be used together with propagation flag.

[kzak@redhat.com: - add MS_SILENT to acceptable propagation flags,
                  - fix new code in libmount too]

Signed-off-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Dong Hao <haodong@linux.vnet.ibm.com>
2012-03-21 12:35:54 +01:00
Karel Zak ce22ccd08c libmount: improve mnt_tables_is_mounted
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-03-20 11:22:09 +01:00
Karel Zak 1e1df43ca2 libmount: add configfs to pseudofs list
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-03-20 10:42:47 +01:00
Karel Zak 7293e97a42 libmount: fix "already mounted" detection on systems with mtab
For systems with regular mtab the fs->root should be ignored in
"already mounted" heuristic.

Reported-by: Matt Burgess <matthew@linuxfromscratch.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-03-09 13:11:24 +01:00
Dave Reisner bf91904c24 libmount: avoid infinite loop in child fs iteration
In early userspace, the rootfs is mounted with itself as its parent.
Example /proc/self/mountinfo:

1 1 0:1 / / rw - rootfs rootfs rw
14 1 0:3 / /proc rw,nosuid,nodev,noexec,relatime - proc proc rw
15 1 0:13 / /sys rw,nosuid,nodev,noexec,relatime - sysfs sys rw
16 1 0:5 / /dev rw,nosuid,relatime - devtmpfs dev rw,size=506956k
17 1 0:14 / /run rw,nosuid,nodev,relatime - tmpfs run rw,mode=755

This causes an infinite loop in mnt_table_next_child_fs, and is
evidenced by a crash via infinite recursion in findmnt. Simply catch the
condition where the ID of the parent is the ID of the current fs we're
examining and skip over it to the next mount in the table.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-03-08 16:06:02 +01:00
Karel Zak 379e84390a libmount: cleanup flags usage
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-03-07 10:45:48 +01:00
Karel Zak 6699e742f2 libmount: add mnt_fs_streq_target() and export all mnt_fs_streq_*
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-03-02 15:53:55 +01:00
Karel Zak ab8c6e0569 libmount: add mnt_fs_streq_srcpath()
We have to be careful with "none" or another dummy sources for pseudo
filesystems. These strings should be canonicalized or compared as a
paths.

The function is not exported by library API.

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-03-02 13:29:39 +01:00
Karel Zak 41d6af28c3 libmount: cosmetic changes around "none"
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-03-02 11:23:34 +01:00
Dave Reisner d0ce7c07e6 libmount: don't treat "none" differently
This causes more problems than it solves. In the latest edition:

  # mount -t proc none foo
  mount: foo: mount failed: Invalid argument

A check for source and target fails in mnt_context_apply_fstab()
because, even though they were indeed specified on the cmdline,
__mnt_fs_set_source_ptr() altered this and NULL'd out the source.

If you're able to mount this device via other means, other tools start
reporting oddities, such as mount's output:

  (null) on /foo type proc (rw,relatime)

or findmnt:

  TARGET      SOURCE FSTYPE OPTIONS
  /foo               proc   rw,relatime

Simply treat "none" like any other source when passed in.

[kzak@redhat.com: - don't translate NULL to "none" in mnt_fs_set_source()]

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-03-02 09:48:23 +01:00
Sami Kerola f06b43285d build-sys: enhance readability of the autotools files
Several horizontal lists are turned to vertical, and sorted to
alphabetical order. Additionally spaces are converted to tabs where
ever possible.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-02-28 13:29:35 +01:00
Karel Zak 772cce373f libmount: allow empty source for mount(2) syscall
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=797438
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-02-28 00:02:30 +01:00
Karel Zak 9bf9690114 libmount: use mount.<type> -s for NFS only
Unfortunately, it seems that for example mount.cifs don't care about
the API, so we need exception like the original mount(8).

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-02-27 16:44:38 +01:00
Karel Zak 6eba938376 libmount: canonicalize targets from fstab on mount -a
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-02-24 22:52:45 +01:00
Karel Zak ea371ea30e libmount: optimize for paths with tailing slash
mnt_table_find_target() canonicalizes paths by libmnt cache, but it's
overkill if the difference between paths is tailing slash only.

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-02-24 21:30:22 +01:00
Karel Zak 59e32a1f24 libmount: canonicalize all paths from (fs)tab
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=797216
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-02-24 20:25:43 +01:00
Sami Kerola 7cebf0bb4f docs: corrections to FSF license files, and postal address
The COPYING and Documentation/licenses/COPYING* files are being
replaced by files from GNU web site.

http://www.gnu.org/licenses/gpl-2.0.txt
http://www.gnu.org/licenses/lgpl-2.1.txt

Postal addresses to FSF in other files are updated to match with the
address in license files.

Reference: http://lists.gnu.org/archive/html/freefont-announce/2005-04/msg00001.html
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-02-24 14:13:35 +01:00
Karel Zak 94b0c44fb7 mount: distinguish between MS_COMMENT flags (netdev, nofail, ...)
Since util-linux 2.12h (year 2004) there is only one flag for all
dummy options like _netdev or nofail. Unfortunately it means that when
mount(8) composes the final mount options string for mtab (or for
mount.<type> helpers) the string is generated incorrectly.

Reported-by: Dave Reisner <d@falconindy.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-02-23 15:16:17 +01:00
Karel Zak cad39614a6 libmount: clean up context docs
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-02-23 12:31:56 +01:00
Karel Zak 3fcf5e1b79 docs: update copyright years
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-02-22 13:07:14 +01:00
Karel Zak ee3140752f libmount: cleanup docs
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-02-22 13:02:17 +01:00
Dave Reisner a33df88c45 libmount: remove teaser proto for mnt_table_get_name
This function was never implemented, but the proto has existed since the
inception of the library. As the libmnt_table struct doesn't include a
member necessary to carry the name of the table, simply discard this
prototype. If ever a need to break ABI comes up, perhaps this could be
revisited.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-02-22 11:52:44 +01:00
Karel Zak 178537eda9 libmount: use #ifdef fr selinux specific variables
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-02-03 12:35:36 +01:00
Karel Zak a9ddf316c8 libmount: don't ignore chmod/own errors
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-02-02 14:39:02 +01:00
Karel Zak 383e7a2720 libmount: remove dead assigment
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-02-02 14:27:48 +01:00
Karel Zak 2af0a8390d libmount: consolidate sysconf() usage
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-01-31 14:31:09 +01:00
Karel Zak 0113a20e93 libmount: make iter reset more robust [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-01-30 23:55:26 +01:00
Karel Zak 801401447b libmount: fix resource leak [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-01-30 23:38:18 +01:00
Karel Zak 4f69189fe7 libmount: fix resource leak [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-01-30 23:27:23 +01:00