summaryrefslogtreecommitdiffstats
path: root/libmount/src/tab_parse.c
Commit message (Collapse)AuthorAgeFilesLines
* libmount: fix comment referring to passno fieldPatrick Steinhardt2019-08-201-1/+1
| | | | | | | | | | | There's an obvious copy-paste error in `mnt_parse_table_line` when referring to the 6th field of the fstab format, where it says "freq" instead of "passno". This has probably been copied from the 5th field, which is in fact correctly labelled as "freq". Fix the mistake by changing the comment to say "passno" instead. Signed-off-by: Patrick Steinhardt <ps@pks.im>
* libmount: return errno on failed fstab stat()Karel Zak2019-05-091-2/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: fix compiler warning [-Wsometimes-uninitialized]Karel Zak2019-04-151-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: fix memleak on parse errorsKarel Zak2019-04-151-3/+11
| | | | | Addresses: https://github.com/systemd/systemd/pull/12252 Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: don't use sscanf() for swaps parsingKarel Zak2019-04-081-46/+74
| | | | | Addresses: https://github.com/karelzak/util-linux/issues/780 Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: don't use sscanf() for mountinfo parsingKarel Zak2019-04-081-91/+113
| | | | | Addresses: https://github.com/karelzak/util-linux/issues/780 Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: don't use sscanf() for fstab parsingKarel Zak2019-04-081-67/+68
| | | | | Addresses: https://github.com/karelzak/util-linux/issues/780 Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: cleanup licenses sections in the filesKarel Zak2018-08-161-4/+8
| | | | | | | | | * add SPDX-License-Identifier (see https://spdx.org/licenses/) * add "This file part of libmount from util-linux project." * use proper text for LGPL-2.1-or-later * use the same texts everywhere Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/mangle: const quialifier cleanupKarel Zak2018-07-201-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: add missing constKarel Zak2018-07-201-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: use const char in swaps parserKarel Zak2018-07-201-1/+1
| | | | | | The parser does not modify the string, so let's keep it "const char". Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: use const char in mountinfo parserKarel Zak2018-07-201-2/+3
| | | | | | The parser does not modify the string, so let's keep it "const char". Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: use const char in fstab parserKarel Zak2018-07-201-19/+27
| | | | | | The parser does not modify the string, so let's keep it "const char". Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: (mountinfo) parse empty strings in sourceAlban Crequy2018-07-101-5/+28
| | | | | | | | | | | | | | | | | | | | | The source of a mount in /proc/self/mountinfo can unfortunately be an empty string. Before this patch, 'mount' and 'mountpoint' fail as following: $ sudo mount -t tmpfs "" /tmp/bb $ mount mount: /proc/self/mountinfo: parse error at line 64 -- ignored $ mountpoint /tmp/bb /tmp/bb is not a mountpoint This patch fixes the parsing. It is unfortunately more complex because sscanf() does not handle fields with empty strings easily. Other projects have their own parser for mountinfo and have similar issues. I know of runc and runtime-tools (I'll send a patch for those two) but there are probably others. Signed-off-by: Alban Crequy <alban@kinvolk.io>
* libmount: deallocate on /proc/swaps parse errorKarel Zak2018-03-201-5/+6
| | | | | Addresses: https://github.com/karelzak/util-linux/issues/596 Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: make sure we deallocate on parse errorKarel Zak2018-03-201-2/+4
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: fix access() utab write testKarel Zak2017-11-081-3/+4
| | | | | | | | | | | | | | | | | The commit c08396c7691e1e6a04b6b45892e7e4612ceed8d7 replaces open(O_CREATE) with ecaccess(). Unfortunately, another code depends on the original behavior. * let's make utab when really necessary rather than in the try_write() test * __mnt_new_table_from_file() returns NULL if tab-file does not exists. This is incorrect for tab_update.c stuff. We need empty table in this case. * we can check /run/mount/ directory for write access if eaccess(filename) return ENOENT (because file does not exist) Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: Fix various typosSebastian Rasmussen2016-05-311-2/+2
| | | | | | | Fix various typos in error messages, warnings, debug strings, comments and names of static functions. Signed-off-by: Sebastian Rasmussen <sebras@gmail.com>
* libmount: make kernel_fs_postparse() more robustKarel Zak2016-04-151-3/+5
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: fix mnt_table_parse_stream() logicKarel Zak2016-04-151-1/+7
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* tests: make tests more portable due to mtabKarel Zak2016-04-151-0/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: fix mnt_table_parse_mtab() logicKarel Zak2016-04-151-12/+21
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: don't support /etc/mtab by defaultKarel Zak2016-04-141-7/+11
| | | | | | | | | | | | | | | | | The file mtab is evil and already unused by mainstream distributions. Now libmount is able to detect mtab->/proc/mounts and use /proc/self/mountinfo if necessary. This heuristic seems overkill in many cases. It's also dangerous on systems where mountinfo is strongly required (systemd based distros). This patch #ifdefs mtab code and forces libmount to always use /proc/self/mountinfo. The new configure option --enable-libmount-support-mtab is necessary to enable old behavior to support mtab. Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: improve conversion from root= to the devnameKarel Zak2016-03-151-9/+6Star
| | | | | | | | Currently the code supports /dev/name or PARTUUID= only. We also need to support 'maj:min' and 'hexhex' notations. Reported-by: George Spelvin <linux@horizon.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* Revert "include sysmacros.h where used"Karel Zak2016-03-081-1/+0Star
| | | | This reverts commit 46a40c018438b7b2b25083a5e5a4a21055a0c1e9.
* include sysmacros.h where usedMike Frysinger2016-03-081-0/+1
| | | | | | | | BSD/Linux systems stick major/minor/makedev in sysmacros.h. Newer Linux libraries have been moving away from including sysmacros.h implicitly via sys/types.h, so include it directly. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* lib: move fopen_at() to fileutils.h, remove at.hRuediger Meier2016-03-071-1/+1
| | | | Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* lib: remove openat fallback functions (include/at.h)Ruediger Meier2016-03-071-4/+5
| | | | | | | | | | | | | | I have validated that we are still compatible at least back to - openSUSE 11.4 - SLE 11 - RHEL/CentOS 6 - OSX 10.10.x, (Xcode 6.3) - FreeBSD 10.2 Confirmed incompatibility: - OSX 10.9.x, (Xcode 6.2) Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* libmount: fix mnt_table_is_fs_mounted() loopdev useKarel Zak2016-02-161-0/+1
| | | | | | | | | | The function does not detect already mounted loop devices on systems with regular /etc/mtab file. The patch also improves test_is_mounted() to be useful with mtab. Reported-by: Ruediger Meier <sweet_f_a@gmx.de> Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: follow docs with parse-error callback return codeKarel Zak2015-10-151-1/+1
| | | | | | The docs says that recoverable errors have rc > 0. Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: fix compiler warning [-Wdiscarded-qualifiers]Karel Zak2015-08-311-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: handle arbitrary line length for mountsKarel Zak2015-08-271-32/+49
| | | | | | | | | | | | | | | | | | | | | | | | | Based on patch from Kees Cook, he wrote: > The kernel's maximum path length is PATH_MAX (4096). The use of BUFSIZ > (8192) would seem sufficient for reading mountinfo files, but it's > not. Paths may contain escaped characters (requiring 4x as many bytes > to read), and filesystem options are of unknown length. To avoid > mounts being either intentionally or unintentionally hidden from > libmount and its users, we must accept arbitrary length lines when > parsing. > > Long valid entries are currently ignored, with warnings like this: > mount: /proc/self/mountinfo: parse error: ignore entry at line 11. > mount: /proc/self/mountinfo: parse error: ignore entry at line 12. > > Instead of using a malloc on every line parsed from mount files, do it > once per mount file context, growing it as needed. The general case > will never grow it. I have moved the parser stuff to the new struct libmnt_parser, maybe we can move more things (e.g. libmnt_table->fmt) to this struct later. Reported-by: Kees Cook <keescook@chromium.org> Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: remove assert(arg) from public functionsKarel Zak2015-02-161-13/+3Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: add --enable-libmount-force-mountinfoKarel Zak2015-02-161-1/+4
| | | | | | | | | | | | | | | | | | The default libmount mtab management depends on mtan symlink. If the symlink exists than libmount parses /proc/self/mountinfo, otherwise it parses regular classic /etc/mtab. This is backwardly compatible and transparent solution. Unfortunately, this is not robust enough because some broken init scripts or 3-party mount helpers may remove the symlink and create regular mtab file. This is pretty bad if initd (systemd) depends on libmount. Fortunately we known that mtab is absolutely unwanted on some distros, so it's fine too ignore mtab at all and don't care about the symlink. Reported-by: Martin Pitt <martin.pitt@ubuntu.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: read utab always when read mtab from /procKarel Zak2015-02-121-2/+19
| | | | | | | | | | | | | Now libmount reads utab only when mtab filename is no explicitly specified, but for example: mnt_table_parse_mtab(tb, "/proc/self/mountinfo"); ignores utab because filename points to regular file. This is mistake, we wnat to read utab always when we read mount table from kernel. Reported-by: Martin Pitt <martin.pitt@ubuntu.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* maint: fix shadow declarationSami Kerola2015-01-071-3/+3
| | | | | | | | | | | | | | | | This change fixes all shadow declarations. The worth while to mention fix is with libfdisk sun geometry. It comes from bitops.h cpu_to_be16 macro that further expands from include/bits/byteswap.h that has the shadowing. libfdisk/src/sun.c:961:173: warning: declaration of '__v' shadows a previous local [-Wshadow] libfdisk/src/sun.c:961:69: warning: shadowed declaration is here [-Wshadow] libfdisk/src/sun.c:961:178: warning: declaration of '__x' shadows a previous local [-Wshadow] libfdisk/src/sun.c:961:74: warning: shadowed declaration is here [-Wshadow] That could have caused earlier some unexpected results. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* libmount: reuse allocated fs in parserKarel Zak2014-11-191-7/+15
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: use new debug functionsKarel Zak2014-03-211-24/+24
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* umount: don't use mountinfo if possibleKarel Zak2014-03-031-26/+36
| | | | | | | | | | | | | | | | | | | | | | | | The umount(8) always parses /proc/self/mountinfo to get fstype and to merge kernel mount options with userspace mount options from /run/mount/utab. This behavior is overkill in many cases and it's pretty expensive as kernel has to always compose *whole* mountinfo. This performance disadvantage is visible for crazy use-cases with huge number of mountpoints and frequently called umount(8). It seems that we can bypass /proc/self/mountinfo by statfs() to get filesystem type (statfs.f_type magic) and analyze /run/mount/utab before we parse mountinfo. This optimization is not used when: * umount(8) executed by non-root (as user= in utab is expected) * umount --lazy / --force (target is probably unreachable NFS, then use statfs() is pretty bad idea) * target is not a directory (e.g. umount /dev/sda1) * there is (deprecated) writeable mtab Reported-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: make the mountinfo parser more robustKarel Zak2014-02-171-10/+11
| | | | | | ... sorry, the previous change to the parser was too stupid. Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: accept (deleted) path suffix in mountinfo fileKarel Zak2014-02-171-0/+10
| | | | | Addresses: debian bug #711183 Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: fix scanf format string [coverity scan]Karel Zak2014-01-141-4/+4
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* strutils: add skip_space() functionOndrej Oprala2013-11-081-13/+4Star
| | | | | | | | [kzak@redhat.com: - add also skip_blank(), - remove duplicate implementation from libmount] Signed-off-by: Ondrej Oprala <ooprala@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: add reference counter to libmnt_tableKarel Zak2013-08-211-3/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: add reference counting to libmount_fsKarel Zak2013-08-211-1/+2
| | | | | | | | | | | | | | | | | | | | * 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>
* libmount: fix typosOndrej Oprala2013-08-051-26/+26
| | | | Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
* libmount: change tailing to trailing in *_tailing_comments functionsOndrej Oprala2013-08-011-2/+2
| | | | Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
* libmount: add functions to handle comments in fs tablesOndrej Oprala2013-07-031-1/+93
| | | | | | Co-Author: Karel Zak <kzak@redhat.com> Signed-off-by: Ondrej Oprala <ooprala@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: fix mount.nfs segfault, rely on assert() rather than on nonnullKarel Zak2013-04-121-3/+5
| | | | | | | | | | | | | | | | | 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>
* libmount: use O_CLOEXECKarel Zak2013-04-031-4/+4
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>