fstab-generator.c revision 7fd1b19bc9e9f5574f2877936b8ac267c7706947
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen/***
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen This file is part of systemd.
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen Copyright 2012 Lennart Poettering
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen systemd is free software; you can redistribute it and/or modify it
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen under the terms of the GNU Lesser General Public License as published by
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen the Free Software Foundation; either version 2.1 of the License, or
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen (at your option) any later version.
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen systemd is distributed in the hope that it will be useful, but
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen WITHOUT ANY WARRANTY; without even the implied warranty of
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen Lesser General Public License for more details.
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen You should have received a copy of the GNU Lesser General Public License
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen along with systemd; If not, see <http://www.gnu.org/licenses/>.
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen***/
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen#include <stdio.h>
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen#include <mntent.h>
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen#include <errno.h>
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen#include <string.h>
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen#include <unistd.h>
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
1346b1f0388f4100bb3c2a2bb23bc881769c020cTom Gundersen#include "log.h"
f5be560181d092c5f52a2b819aedcd48220f36abTom Gundersen#include "util.h"
dd43110f781a9245ec00531456fee68ed763a179Tom Gundersen#include "unit-name.h"
5c1d3fc93d91384bbac29adf01074fa4375317eaUmut Tezduyar Lindskog#include "path-util.h"
4138fb2c7936758da709eaed3f6b4f3df1d04effPatrik Flykt#include "mount-setup.h"
4138fb2c7936758da709eaed3f6b4f3df1d04effPatrik Flykt#include "special.h"
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen#include "mkdir.h"
ce43e484465050c619ea9a1991d49b3d6215028bSusant Sahani#include "virt.h"
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen#include "fileio.h"
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersenstatic const char *arg_dest = "/tmp";
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersenstatic bool arg_enabled = true;
06f021a8048583d66202e3ac5cd0a12386d33ac2Tom Gundersen
134e56dcc53970a20a858283650bb92cd5da1d17Lennart Poetteringstatic int device_name(const char *path, char **unit) {
3b653205cf7bd3851befd0a9f6a3ded6e267c173Lennart Poettering char *p;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
aba496a58acf9d9c61314de71353550e579f85eeUmut Tezduyar Lindskog assert(path);
4faefc7ff884eae65a80e82313fd9f4bb859d6dbLennart Poettering
4faefc7ff884eae65a80e82313fd9f4bb859d6dbLennart Poettering if (!is_device_path(path))
aba496a58acf9d9c61314de71353550e579f85eeUmut Tezduyar Lindskog return 0;
1a436809498faf6486815baa0338fb6b8e5def07Tom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen p = unit_name_from_path(path, ".device");
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen if (!p)
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen return log_oom();
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen *unit = p;
11bf3cced13c885ca215c108cb0bdb7a148520d6Lennart Poettering return 1;
b98b483bac585af754e8a22ea890db8486905d8aAlin Rauta}
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
cb9fc36a1211967e8c58b0502a26c42552ac8060Lennart Poetteringstatic int mount_find_pri(struct mntent *me, int *ret) {
769d324c99aab129148bd25f5f663ef441287d86Lennart Poettering char *end, *pri;
769d324c99aab129148bd25f5f663ef441287d86Lennart Poettering unsigned long r;
769d324c99aab129148bd25f5f663ef441287d86Lennart Poettering
769d324c99aab129148bd25f5f663ef441287d86Lennart Poettering assert(me);
769d324c99aab129148bd25f5f663ef441287d86Lennart Poettering assert(ret);
cb9fc36a1211967e8c58b0502a26c42552ac8060Lennart Poettering
cb9fc36a1211967e8c58b0502a26c42552ac8060Lennart Poettering pri = hasmntopt(me, "pri");
cb9fc36a1211967e8c58b0502a26c42552ac8060Lennart Poettering if (!pri)
ed942a9eb22d50f667909ad6184b45015d28d054Tom Gundersen return 0;
bd8f65387673e29f46136a4ed172097035002c23Tom Gundersen
bd8f65387673e29f46136a4ed172097035002c23Tom Gundersen pri += 4;
bd8f65387673e29f46136a4ed172097035002c23Tom Gundersen
bd8f65387673e29f46136a4ed172097035002c23Tom Gundersen errno = 0;
bd8f65387673e29f46136a4ed172097035002c23Tom Gundersen r = strtoul(pri, &end, 10);
bd8f65387673e29f46136a4ed172097035002c23Tom Gundersen if (errno > 0)
bd8f65387673e29f46136a4ed172097035002c23Tom Gundersen return -errno;
bd8f65387673e29f46136a4ed172097035002c23Tom Gundersen
e331e24649213f2e093e16e4d3d64ee823dfc375Tom Gundersen if (end == pri || (*end != ',' && *end != 0))
e331e24649213f2e093e16e4d3d64ee823dfc375Tom Gundersen return -EINVAL;
e331e24649213f2e093e16e4d3d64ee823dfc375Tom Gundersen
e331e24649213f2e093e16e4d3d64ee823dfc375Tom Gundersen *ret = (int) r;
e331e24649213f2e093e16e4d3d64ee823dfc375Tom Gundersen return 1;
e331e24649213f2e093e16e4d3d64ee823dfc375Tom Gundersen}
e331e24649213f2e093e16e4d3d64ee823dfc375Tom Gundersen
e331e24649213f2e093e16e4d3d64ee823dfc375Tom Gundersenstatic int add_swap(const char *what, struct mntent *me) {
e331e24649213f2e093e16e4d3d64ee823dfc375Tom Gundersen _cleanup_free_ char *name = NULL, *unit = NULL, *lnk = NULL, *device = NULL;
e331e24649213f2e093e16e4d3d64ee823dfc375Tom Gundersen _cleanup_fclose_ FILE *f = NULL;
e331e24649213f2e093e16e4d3d64ee823dfc375Tom Gundersen bool noauto, nofail;
b98b483bac585af754e8a22ea890db8486905d8aAlin Rauta int r, pri = -1;
b98b483bac585af754e8a22ea890db8486905d8aAlin Rauta
b98b483bac585af754e8a22ea890db8486905d8aAlin Rauta assert(what);
b98b483bac585af754e8a22ea890db8486905d8aAlin Rauta assert(me);
b98b483bac585af754e8a22ea890db8486905d8aAlin Rauta
b98b483bac585af754e8a22ea890db8486905d8aAlin Rauta r = mount_find_pri(me, &pri);
b98b483bac585af754e8a22ea890db8486905d8aAlin Rauta if (r < 0) {
b98b483bac585af754e8a22ea890db8486905d8aAlin Rauta log_error("Failed to parse priority");
b98b483bac585af754e8a22ea890db8486905d8aAlin Rauta return pri;
b98b483bac585af754e8a22ea890db8486905d8aAlin Rauta }
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen noauto = !!hasmntopt(me, "noauto");
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen nofail = !!hasmntopt(me, "nofail");
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
dbffab87f1504abc9f189dd253111693c99fbd9aTom Gundersen name = unit_name_from_path(what, ".swap");
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen if (!name)
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen return log_oom();
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen unit = strjoin(arg_dest, "/", name, NULL);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen if (!unit)
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen return log_oom();
edb85f0d8d0a84f27308a3728f3fde3c52b9dce2Susant Sahani
edb85f0d8d0a84f27308a3728f3fde3c52b9dce2Susant Sahani f = fopen(unit, "wxe");
2cc412b59353576cece2d5b30c6a39c70552f0a0Tom Gundersen if (!f) {
2cc412b59353576cece2d5b30c6a39c70552f0a0Tom Gundersen if (errno == EEXIST)
2cc412b59353576cece2d5b30c6a39c70552f0a0Tom Gundersen log_error("Failed to create swap unit file %s, as it already exists. Duplicate entry in /etc/fstab?", unit);
edbb03e95a3c31bf719d5c6c46eec14d0bcb9c8fTom Gundersen else
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen log_error("Failed to create unit file %s: %m", unit);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen return -errno;
1a436809498faf6486815baa0338fb6b8e5def07Tom Gundersen }
1a436809498faf6486815baa0338fb6b8e5def07Tom Gundersen
6a0a2f860f1ca4a10932da3b41dbc3c0139757ccTom Gundersen fputs("# Automatically generated by systemd-fstab-generator\n\n"
cb9fc36a1211967e8c58b0502a26c42552ac8060Lennart Poettering "[Unit]\n"
5be4d38e31281727b6f45ae869136bb01a1f7790Tom Gundersen "SourcePath=/etc/fstab\n"
bcb7a07e0a785bda1eed658e984ff6b4a11cba9aTom Gundersen "DefaultDependencies=no\n"
4f882b2a5007e51032459e29d15a86df6b5ea9f4Tom Gundersen "Conflicts=" SPECIAL_UMOUNT_TARGET "\n"
1346b1f0388f4100bb3c2a2bb23bc881769c020cTom Gundersen "Before=" SPECIAL_UMOUNT_TARGET "\n", f);
ad0734e890b25751ef8229e47210ff11ae8fa3f3Tom Gundersen
4cc7a82c9490a3c5ae03b1d6d168ce40ba499e23Eugene Yakubovich if (!noauto && !nofail)
f5de5b00204f041aaec828d336c8afd9e860a5c3Tom Gundersen fputs("Before=" SPECIAL_SWAP_TARGET "\n", f);
eb27aeca247a4cf8816fffc4c0dbcab55ead3864Tom Gundersen
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich fprintf(f,
84b5b79a8f7b423c5b7cad4170eb68d57fe5e26cAngus Gibson "\n"
5c1d3fc93d91384bbac29adf01074fa4375317eaUmut Tezduyar Lindskog "[Swap]\n"
bfa695b5cc37aeb78737c57c84e9e69ea08152c0Tom Gundersen "What=%s\n",
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen what);
dd43110f781a9245ec00531456fee68ed763a179Tom Gundersen
dd43110f781a9245ec00531456fee68ed763a179Tom Gundersen if (pri >= 0)
e1853b00ef7cb56cafd908327dd44b3ab48b402cSusant Sahani fprintf(f,
e1853b00ef7cb56cafd908327dd44b3ab48b402cSusant Sahani "Priority=%i\n",
769d324c99aab129148bd25f5f663ef441287d86Lennart Poettering pri);
5a8bcb674f71a20e95df55319b34c556638378ceLennart Poettering
5a8bcb674f71a20e95df55319b34c556638378ceLennart Poettering fflush(f);
c106cc36b9b8e8998eb95299b02f1db9c1209122Tom Gundersen if (ferror(f)) {
c106cc36b9b8e8998eb95299b02f1db9c1209122Tom Gundersen log_error("Failed to write unit file %s: %m", unit);
c106cc36b9b8e8998eb95299b02f1db9c1209122Tom Gundersen return -errno;
ce43e484465050c619ea9a1991d49b3d6215028bSusant Sahani }
ce43e484465050c619ea9a1991d49b3d6215028bSusant Sahani
f048a16b464295a4e0a4f4c1210f06343ad31231Tom Gundersen if (!noauto) {
f048a16b464295a4e0a4f4c1210f06343ad31231Tom Gundersen lnk = strjoin(arg_dest, "/" SPECIAL_SWAP_TARGET ".wants/", name, NULL);
b98b483bac585af754e8a22ea890db8486905d8aAlin Rauta if (!lnk)
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen return log_oom();
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersen
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersen mkdir_parents_label(lnk, 0755);
b98b483bac585af754e8a22ea890db8486905d8aAlin Rauta if (symlink(unit, lnk) < 0) {
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersen log_error("Failed to create symlink %s: %m", lnk);
67272d157a35e5cda4e5c904eafdcc23d20541d1Tom Gundersen return -errno;
6192b846ca0d15602e94ddb5da4420b7c60d64a5Tom Gundersen }
06f021a8048583d66202e3ac5cd0a12386d33ac2Tom Gundersen
bd8f65387673e29f46136a4ed172097035002c23Tom Gundersen r = device_name(what, &device);
bd8f65387673e29f46136a4ed172097035002c23Tom Gundersen if (r < 0)
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen return r;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen if (r > 0) {
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen free(lnk);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen lnk = strjoin(arg_dest, "/", device, ".wants/", name, NULL);
16aa63a00b5b1db23a9c0b8de350ebf482d90cd0Tom Gundersen if (!lnk)
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen return log_oom();
0dd25fb9f005d8ab7ac4bc10a609d00569f8c56aLennart Poettering
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen mkdir_parents_label(lnk, 0755);
5c1d3fc93d91384bbac29adf01074fa4375317eaUmut Tezduyar Lindskog if (symlink(unit, lnk) < 0) {
81163121e649523b4071f67ddc03c2db649036c5Tom Gundersen log_error("Failed to create symlink %s: %m", lnk);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen return -errno;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen }
eb0ea358b688a6f83ff305c6b825c61f12b6dcb8Tom Gundersen }
aba496a58acf9d9c61314de71353550e579f85eeUmut Tezduyar Lindskog }
8cd11a0f0f4ca05199e1166f6a07472b296f7455Tom Gundersen
5d3de3fe9cc452f1bfe3c2dcafecbd7f904da4dcLennart Poettering return 0;
c081882f07617e56bcbce54105068137e4e0bb52Susant Sahani}
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
fd6d906cf46ecef45ebbb5a361e1dc436f031d7aLennart Poetteringstatic bool mount_is_bind(struct mntent *me) {
5a8bcb674f71a20e95df55319b34c556638378ceLennart Poettering assert(me);
3d3d425547a3f38473fcf8737b85dfebb630479dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen return
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen hasmntopt(me, "bind") ||
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen streq(me->mnt_type, "bind") ||
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen hasmntopt(me, "rbind") ||
16aa63a00b5b1db23a9c0b8de350ebf482d90cd0Tom Gundersen streq(me->mnt_type, "rbind");
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen}
0dd25fb9f005d8ab7ac4bc10a609d00569f8c56aLennart Poettering
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersenstatic bool mount_is_network(struct mntent *me) {
9e7e440835c43d81ffdbc299d2c07daaa641ed50Tom Gundersen assert(me);
5c1d3fc93d91384bbac29adf01074fa4375317eaUmut Tezduyar Lindskog
5c1d3fc93d91384bbac29adf01074fa4375317eaUmut Tezduyar Lindskog return
28cc555d8504c9429776aedbbe1fee7101258578Dan Williams hasmntopt(me, "_netdev") ||
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen fstype_is_network(me->mnt_type);
5d3de3fe9cc452f1bfe3c2dcafecbd7f904da4dcLennart Poettering}
5d3de3fe9cc452f1bfe3c2dcafecbd7f904da4dcLennart Poettering
9e7e440835c43d81ffdbc299d2c07daaa641ed50Tom Gundersenstatic bool mount_in_initrd(struct mntent *me) {
46b0c76e2c355c0d0cc4792abb98cde07b28bc53Emil Renner Berthing assert(me);
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersen
3d3d425547a3f38473fcf8737b85dfebb630479dTom Gundersen return
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen hasmntopt(me, "x-initrd.mount") ||
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen streq(me->mnt_dir, "/usr");
11bf3cced13c885ca215c108cb0bdb7a148520d6Lennart Poettering}
11bf3cced13c885ca215c108cb0bdb7a148520d6Lennart Poettering
11bf3cced13c885ca215c108cb0bdb7a148520d6Lennart Poetteringstatic int add_mount(
0dd25fb9f005d8ab7ac4bc10a609d00569f8c56aLennart Poettering const char *what,
11bf3cced13c885ca215c108cb0bdb7a148520d6Lennart Poettering const char *where,
11bf3cced13c885ca215c108cb0bdb7a148520d6Lennart Poettering const char *type,
11bf3cced13c885ca215c108cb0bdb7a148520d6Lennart Poettering const char *opts,
11bf3cced13c885ca215c108cb0bdb7a148520d6Lennart Poettering int passno,
11bf3cced13c885ca215c108cb0bdb7a148520d6Lennart Poettering bool noauto,
11bf3cced13c885ca215c108cb0bdb7a148520d6Lennart Poettering bool nofail,
11bf3cced13c885ca215c108cb0bdb7a148520d6Lennart Poettering bool automount,
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen bool isbind,
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen const char *pre,
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen const char *pre2,
9c0a72f961e00b0447767973e7117e131bea5b5dTom Gundersen const char *online,
1346b1f0388f4100bb3c2a2bb23bc881769c020cTom Gundersen const char *post,
9c0a72f961e00b0447767973e7117e131bea5b5dTom Gundersen const char *source) {
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen _cleanup_free_ char
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen *name = NULL, *unit = NULL, *lnk = NULL, *device = NULL,
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen *automount_name = NULL, *automount_unit = NULL;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen _cleanup_fclose_ FILE *f = NULL;
6a24f1484fcc1f59f89617afbe4282667a358eabTom Gundersen int r;
6a24f1484fcc1f59f89617afbe4282667a358eabTom Gundersen
bbf7c04821a71fec67eaf0e7a34d17afc5913c13Tom Gundersen assert(what);
e331e24649213f2e093e16e4d3d64ee823dfc375Tom Gundersen assert(where);
bbf7c04821a71fec67eaf0e7a34d17afc5913c13Tom Gundersen assert(type);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen assert(opts);
52433f6b65eccd1c54606dde999610640f3458acTom Gundersen assert(source);
dbffab87f1504abc9f189dd253111693c99fbd9aTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen if (streq(type, "autofs"))
11bf3cced13c885ca215c108cb0bdb7a148520d6Lennart Poettering return 0;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen if (!is_path(where)) {
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen log_warning("Mount point %s is not a valid path, ignoring.", where);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen return 0;
2ad8416dd057e7e3185169609ca3006e7649f576Zbigniew Jędrzejewski-Szmek }
2ad8416dd057e7e3185169609ca3006e7649f576Zbigniew Jędrzejewski-Szmek
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen if (mount_point_is_api(where) ||
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen mount_point_ignore(where))
e331e24649213f2e093e16e4d3d64ee823dfc375Tom Gundersen return 0;
e331e24649213f2e093e16e4d3d64ee823dfc375Tom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen name = unit_name_from_path(where, ".mount");
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen if (!name)
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen return log_oom();
8f203c166ecb24f904a068f2d8f0c636c1511a8fTom Gundersen
a97dcc12e486ecff531809802930a26c4da827f2Tom Gundersen unit = strjoin(arg_dest, "/", name, NULL);
a97dcc12e486ecff531809802930a26c4da827f2Tom Gundersen if (!unit)
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen return log_oom();
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen f = fopen(unit, "wxe");
505f8da7325591defe5f751f328bd26915267602Tom Gundersen if (!f) {
45af44d47da6933b260c734ad9ff721f63f80a4dTom Gundersen if (errno == EEXIST)
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen log_error("Failed to create mount unit file %s, as it already exists. Duplicate entry in /etc/fstab?", unit);
e331e24649213f2e093e16e4d3d64ee823dfc375Tom Gundersen else
bbf7c04821a71fec67eaf0e7a34d17afc5913c13Tom Gundersen log_error("Failed to create unit file %s: %m", unit);
3bef724f7e7f7eaca69881548b06e221b77d7031Tom Gundersen return -errno;
0dd25fb9f005d8ab7ac4bc10a609d00569f8c56aLennart Poettering }
11bf3cced13c885ca215c108cb0bdb7a148520d6Lennart Poettering
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen fprintf(f,
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen "# Automatically generated by systemd-fstab-generator\n\n"
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen "[Unit]\n"
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen "SourcePath=%s\n"
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen "DefaultDependencies=no\n",
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen source);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen if (!path_equal(where, "/")) {
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen if (pre)
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen fprintf(f,
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen "After=%s\n",
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen pre);
dbffab87f1504abc9f189dd253111693c99fbd9aTom Gundersen
505f8da7325591defe5f751f328bd26915267602Tom Gundersen if (pre2)
505f8da7325591defe5f751f328bd26915267602Tom Gundersen fprintf(f,
505f8da7325591defe5f751f328bd26915267602Tom Gundersen "After=%s\n",
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen pre2);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
69a93e7db47addc4495a6ec9dc0fc74092a6ebeeTom Gundersen if (online)
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen fprintf(f,
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen "After=%s\n"
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen "Wants=%s\n",
6192b846ca0d15602e94ddb5da4420b7c60d64a5Tom Gundersen online,
6192b846ca0d15602e94ddb5da4420b7c60d64a5Tom Gundersen online);
6192b846ca0d15602e94ddb5da4420b7c60d64a5Tom Gundersen
6192b846ca0d15602e94ddb5da4420b7c60d64a5Tom Gundersen fprintf(f,
6192b846ca0d15602e94ddb5da4420b7c60d64a5Tom Gundersen "Conflicts=" SPECIAL_UMOUNT_TARGET "\n"
6192b846ca0d15602e94ddb5da4420b7c60d64a5Tom Gundersen "Before=" SPECIAL_UMOUNT_TARGET "\n");
6192b846ca0d15602e94ddb5da4420b7c60d64a5Tom Gundersen }
6192b846ca0d15602e94ddb5da4420b7c60d64a5Tom Gundersen
6192b846ca0d15602e94ddb5da4420b7c60d64a5Tom Gundersen if (post && !noauto && !nofail && !automount)
6192b846ca0d15602e94ddb5da4420b7c60d64a5Tom Gundersen fprintf(f,
6192b846ca0d15602e94ddb5da4420b7c60d64a5Tom Gundersen "Before=%s\n",
7951dea20911969287878e6897b3eca348721adeSusant Sahani post);
7951dea20911969287878e6897b3eca348721adeSusant Sahani
7951dea20911969287878e6897b3eca348721adeSusant Sahani fprintf(f,
7951dea20911969287878e6897b3eca348721adeSusant Sahani "\n"
7951dea20911969287878e6897b3eca348721adeSusant Sahani "[Mount]\n"
7951dea20911969287878e6897b3eca348721adeSusant Sahani "What=%s\n"
7951dea20911969287878e6897b3eca348721adeSusant Sahani "Where=%s\n"
7951dea20911969287878e6897b3eca348721adeSusant Sahani "Type=%s\n"
7951dea20911969287878e6897b3eca348721adeSusant Sahani "FsckPassNo=%i\n",
7951dea20911969287878e6897b3eca348721adeSusant Sahani what,
7951dea20911969287878e6897b3eca348721adeSusant Sahani where,
7951dea20911969287878e6897b3eca348721adeSusant Sahani type,
7951dea20911969287878e6897b3eca348721adeSusant Sahani passno);
7951dea20911969287878e6897b3eca348721adeSusant Sahani
7951dea20911969287878e6897b3eca348721adeSusant Sahani if (!isempty(opts) &&
7951dea20911969287878e6897b3eca348721adeSusant Sahani !streq(opts, "defaults"))
7951dea20911969287878e6897b3eca348721adeSusant Sahani fprintf(f,
7951dea20911969287878e6897b3eca348721adeSusant Sahani "Options=%s\n",
7951dea20911969287878e6897b3eca348721adeSusant Sahani opts);
7951dea20911969287878e6897b3eca348721adeSusant Sahani
7951dea20911969287878e6897b3eca348721adeSusant Sahani fflush(f);
7951dea20911969287878e6897b3eca348721adeSusant Sahani if (ferror(f)) {
85a8eeee36b57c1ab382b0225fa9a87525bbeee9Susant Sahani log_error("Failed to write unit file %s: %m", unit);
85a8eeee36b57c1ab382b0225fa9a87525bbeee9Susant Sahani return -errno;
85a8eeee36b57c1ab382b0225fa9a87525bbeee9Susant Sahani }
85a8eeee36b57c1ab382b0225fa9a87525bbeee9Susant Sahani
85a8eeee36b57c1ab382b0225fa9a87525bbeee9Susant Sahani if (!noauto) {
85a8eeee36b57c1ab382b0225fa9a87525bbeee9Susant Sahani if (post) {
85a8eeee36b57c1ab382b0225fa9a87525bbeee9Susant Sahani lnk = strjoin(arg_dest, "/", post, nofail || automount ? ".wants/" : ".requires/", name, NULL);
85a8eeee36b57c1ab382b0225fa9a87525bbeee9Susant Sahani if (!lnk)
85a8eeee36b57c1ab382b0225fa9a87525bbeee9Susant Sahani return log_oom();
85a8eeee36b57c1ab382b0225fa9a87525bbeee9Susant Sahani
85a8eeee36b57c1ab382b0225fa9a87525bbeee9Susant Sahani mkdir_parents_label(lnk, 0755);
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen if (symlink(unit, lnk) < 0) {
c0dda18697e0994272c0c9616d36f6777b60e2c7Tom Gundersen log_error("Failed to create symlink %s: %m", lnk);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen return -errno;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen }
f048a16b464295a4e0a4f4c1210f06343ad31231Tom Gundersen }
28cc555d8504c9429776aedbbe1fee7101258578Dan Williams
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen if (!isbind &&
f882c247ad59776c3a7753bb963c1f8e2386cb79Tom Gundersen !path_equal(where, "/")) {
5c1d3fc93d91384bbac29adf01074fa4375317eaUmut Tezduyar Lindskog
5c1d3fc93d91384bbac29adf01074fa4375317eaUmut Tezduyar Lindskog r = device_name(what, &device);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen if (r < 0)
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen return r;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen if (r > 0) {
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen free(lnk);
71a6151083d842b2f5bf04e50239f0bf85d34d2eTom Gundersen lnk = strjoin(arg_dest, "/", device, ".wants/", name, NULL);
71a6151083d842b2f5bf04e50239f0bf85d34d2eTom Gundersen if (!lnk)
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen return log_oom();
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersen
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersen mkdir_parents_label(lnk, 0755);
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersen if (symlink(unit, lnk) < 0) {
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersen log_error("Failed to create symlink %s: %m", lnk);
5d8e593dce074bff966fc0a46579c61b4f3bc33aSusant Sahani return -errno;
5d8e593dce074bff966fc0a46579c61b4f3bc33aSusant Sahani }
5d8e593dce074bff966fc0a46579c61b4f3bc33aSusant Sahani }
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen }
f048a16b464295a4e0a4f4c1210f06343ad31231Tom Gundersen }
f048a16b464295a4e0a4f4c1210f06343ad31231Tom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen if (automount && !path_equal(where, "/")) {
f882c247ad59776c3a7753bb963c1f8e2386cb79Tom Gundersen automount_name = unit_name_from_path(where, ".automount");
aba496a58acf9d9c61314de71353550e579f85eeUmut Tezduyar Lindskog if (!name)
407fe036a24834203aca6c1eec7d74d9ad3e9ee0Tom Gundersen return log_oom();
5a8bcb674f71a20e95df55319b34c556638378ceLennart Poettering
5a8bcb674f71a20e95df55319b34c556638378ceLennart Poettering automount_unit = strjoin(arg_dest, "/", automount_name, NULL);
9505d3c6deda0452c22ab2ed47bca74b98d87a17Tom Gundersen if (!automount_unit)
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen return log_oom();
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen fclose(f);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen f = fopen(automount_unit, "wxe");
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen if (!f) {
71a6151083d842b2f5bf04e50239f0bf85d34d2eTom Gundersen log_error("Failed to create unit file %s: %m", automount_unit);
71a6151083d842b2f5bf04e50239f0bf85d34d2eTom Gundersen return -errno;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen }
eb0ea358b688a6f83ff305c6b825c61f12b6dcb8Tom Gundersen
eb0ea358b688a6f83ff305c6b825c61f12b6dcb8Tom Gundersen fprintf(f,
eb0ea358b688a6f83ff305c6b825c61f12b6dcb8Tom Gundersen "# Automatically generated by systemd-fstab-generator\n\n"
eb0ea358b688a6f83ff305c6b825c61f12b6dcb8Tom Gundersen "[Unit]\n"
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersen "SourcePath=%s\n"
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersen "DefaultDependencies=no\n"
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersen "Conflicts=" SPECIAL_UMOUNT_TARGET "\n"
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersen "Before=" SPECIAL_UMOUNT_TARGET "\n",
b98b483bac585af754e8a22ea890db8486905d8aAlin Rauta source);
b98b483bac585af754e8a22ea890db8486905d8aAlin Rauta
b98b483bac585af754e8a22ea890db8486905d8aAlin Rauta if (post)
b98b483bac585af754e8a22ea890db8486905d8aAlin Rauta fprintf(f,
b98b483bac585af754e8a22ea890db8486905d8aAlin Rauta "Before= %s\n",
b98b483bac585af754e8a22ea890db8486905d8aAlin Rauta post);
b98b483bac585af754e8a22ea890db8486905d8aAlin Rauta
b98b483bac585af754e8a22ea890db8486905d8aAlin Rauta fprintf(f,
b98b483bac585af754e8a22ea890db8486905d8aAlin Rauta "[Automount]\n"
b98b483bac585af754e8a22ea890db8486905d8aAlin Rauta "Where=%s\n",
b98b483bac585af754e8a22ea890db8486905d8aAlin Rauta where);
b98b483bac585af754e8a22ea890db8486905d8aAlin Rauta
b98b483bac585af754e8a22ea890db8486905d8aAlin Rauta fflush(f);
b98b483bac585af754e8a22ea890db8486905d8aAlin Rauta if (ferror(f)) {
b98b483bac585af754e8a22ea890db8486905d8aAlin Rauta log_error("Failed to write unit file %s: %m", automount_unit);
b98b483bac585af754e8a22ea890db8486905d8aAlin Rauta return -errno;
ed942a9eb22d50f667909ad6184b45015d28d054Tom Gundersen }
ed942a9eb22d50f667909ad6184b45015d28d054Tom Gundersen
ed942a9eb22d50f667909ad6184b45015d28d054Tom Gundersen free(lnk);
ed942a9eb22d50f667909ad6184b45015d28d054Tom Gundersen lnk = strjoin(arg_dest, "/", post, nofail ? ".wants/" : ".requires/", automount_name, NULL);
ed942a9eb22d50f667909ad6184b45015d28d054Tom Gundersen if (!lnk)
ed942a9eb22d50f667909ad6184b45015d28d054Tom Gundersen return log_oom();
bd8f65387673e29f46136a4ed172097035002c23Tom Gundersen
bd8f65387673e29f46136a4ed172097035002c23Tom Gundersen mkdir_parents_label(lnk, 0755);
bd8f65387673e29f46136a4ed172097035002c23Tom Gundersen if (symlink(automount_unit, lnk) < 0) {
bd8f65387673e29f46136a4ed172097035002c23Tom Gundersen log_error("Failed to create symlink %s: %m", lnk);
bd8f65387673e29f46136a4ed172097035002c23Tom Gundersen return -errno;
bd8f65387673e29f46136a4ed172097035002c23Tom Gundersen }
bd8f65387673e29f46136a4ed172097035002c23Tom Gundersen }
bd8f65387673e29f46136a4ed172097035002c23Tom Gundersen
bd8f65387673e29f46136a4ed172097035002c23Tom Gundersen return 0;
11bf3cced13c885ca215c108cb0bdb7a148520d6Lennart Poettering}
11bf3cced13c885ca215c108cb0bdb7a148520d6Lennart Poettering
0dd25fb9f005d8ab7ac4bc10a609d00569f8c56aLennart Poetteringstatic int parse_fstab(const char *prefix, bool initrd) {
0dd25fb9f005d8ab7ac4bc10a609d00569f8c56aLennart Poettering _cleanup_free_ char *fstab_path = NULL;
11bf3cced13c885ca215c108cb0bdb7a148520d6Lennart Poettering FILE *f;
11bf3cced13c885ca215c108cb0bdb7a148520d6Lennart Poettering int r = 0;
11bf3cced13c885ca215c108cb0bdb7a148520d6Lennart Poettering struct mntent *me;
cb9fc36a1211967e8c58b0502a26c42552ac8060Lennart Poettering
cb9fc36a1211967e8c58b0502a26c42552ac8060Lennart Poettering fstab_path = strjoin(strempty(prefix), "/etc/fstab", NULL);
cb9fc36a1211967e8c58b0502a26c42552ac8060Lennart Poettering if (!fstab_path)
769d324c99aab129148bd25f5f663ef441287d86Lennart Poettering return log_oom();
769d324c99aab129148bd25f5f663ef441287d86Lennart Poettering
e331e24649213f2e093e16e4d3d64ee823dfc375Tom Gundersen f = setmntent(fstab_path, "r");
e331e24649213f2e093e16e4d3d64ee823dfc375Tom Gundersen if (!f) {
e331e24649213f2e093e16e4d3d64ee823dfc375Tom Gundersen if (errno == ENOENT)
e331e24649213f2e093e16e4d3d64ee823dfc375Tom Gundersen return 0;
e331e24649213f2e093e16e4d3d64ee823dfc375Tom Gundersen
log_error("Failed to open %s/etc/fstab: %m", strempty(prefix));
return -errno;
}
while ((me = getmntent(f))) {
_cleanup_free_ char *where = NULL, *what = NULL;
int k;
if (initrd && !mount_in_initrd(me))
continue;
what = fstab_node_to_udev_node(me->mnt_fsname);
where = strjoin(strempty(prefix), me->mnt_dir, NULL);
if (!what || !where) {
r = log_oom();
goto finish;
}
if (is_path(where))
path_kill_slashes(where);
log_debug("Found entry what=%s where=%s type=%s", what, where, me->mnt_type);
if (streq(me->mnt_type, "swap"))
k = add_swap(what, me);
else {
bool noauto, nofail, automount, isbind;
const char *pre, *pre2, *post, *online;
noauto = !!hasmntopt(me, "noauto");
nofail = !!hasmntopt(me, "nofail");
automount =
hasmntopt(me, "comment=systemd.automount") ||
hasmntopt(me, "x-systemd.automount");
isbind = mount_is_bind(me);
if (initrd) {
pre = pre2 = online = NULL;
post = SPECIAL_INITRD_FS_TARGET;
} else if (mount_in_initrd(me)) {
pre = pre2 = online = NULL;
post = SPECIAL_INITRD_ROOT_FS_TARGET;
} else if (mount_is_network(me)) {
pre = SPECIAL_REMOTE_FS_PRE_TARGET;
pre2 = SPECIAL_NETWORK_TARGET;
online = SPECIAL_NETWORK_ONLINE_TARGET;
post = SPECIAL_REMOTE_FS_TARGET;
} else {
pre = SPECIAL_LOCAL_FS_PRE_TARGET;
pre2 = online = NULL;
post = SPECIAL_LOCAL_FS_TARGET;
}
k = add_mount(what, where, me->mnt_type, me->mnt_opts,
me->mnt_passno, noauto, nofail, automount,
isbind, pre, pre2, online, post, fstab_path);
}
if (k < 0)
r = k;
}
finish:
endmntent(f);
return r;
}
static int parse_new_root_from_proc_cmdline(void) {
_cleanup_free_ char *what = NULL, *type = NULL, *opts = NULL, *line = NULL;
char *w, *state;
int r;
size_t l;
r = read_one_line_file("/proc/cmdline", &line);
if (r < 0) {
log_error("Failed to read /proc/cmdline, ignoring: %s", strerror(-r));
return 0;
}
opts = strdup("ro");
type = strdup("auto");
if (!opts || !type)
return log_oom();
/* root= and roofstype= may occur more than once, the last instance should take precedence.
* In the case of multiple rootflags= the arguments should be concatenated */
FOREACH_WORD_QUOTED(w, l, line, state) {
_cleanup_free_ char *word;
word = strndup(w, l);
if (!word)
return log_oom();
else if (startswith(word, "root=")) {
free(what);
what = fstab_node_to_udev_node(word+5);
if (!what)
return log_oom();
} else if (startswith(word, "rootfstype=")) {
free(type);
type = strdup(word + 11);
if (!type)
return log_oom();
} else if (startswith(word, "rootflags=")) {
char *o;
o = strjoin(opts, ",", word + 10, NULL);
if (!o)
return log_oom();
free(opts);
opts = o;
} else if (streq(word, "ro") || streq(word, "rw")) {
char *o;
o = strjoin(opts, ",", word, NULL);
if (!o)
return log_oom();
free(opts);
opts = o;
}
}
if (!what) {
log_debug("Could not find a root= entry on the kernel commandline.");
return 0;
}
if (what[0] != '/') {
log_debug("Skipping entry what=%s where=/sysroot type=%s", what, type);
return 0;
}
log_debug("Found entry what=%s where=/sysroot type=%s", what, type);
r = add_mount(what, "/sysroot", type, opts, 0, false, false, false,
false, NULL, NULL, NULL, SPECIAL_INITRD_ROOT_FS_TARGET, "/proc/cmdline");
return (r < 0) ? r : 0;
}
static int parse_proc_cmdline(void) {
_cleanup_free_ char *line = NULL;
char *w, *state;
int r;
size_t l;
if (detect_container(NULL) > 0)
return 0;
r = read_one_line_file("/proc/cmdline", &line);
if (r < 0) {
log_warning("Failed to read /proc/cmdline, ignoring: %s", strerror(-r));
return 0;
}
FOREACH_WORD_QUOTED(w, l, line, state) {
_cleanup_free_ char *word = NULL;
word = strndup(w, l);
if (!word)
return log_oom();
if (startswith(word, "fstab=")) {
r = parse_boolean(word + 6);
if (r < 0)
log_warning("Failed to parse fstab switch %s. Ignoring.", word + 6);
else
arg_enabled = r;
} else if (startswith(word, "rd.fstab=")) {
if (in_initrd()) {
r = parse_boolean(word + 6);
if (r < 0)
log_warning("Failed to parse fstab switch %s. Ignoring.", word + 6);
else
arg_enabled = r;
}
} else if (startswith(word, "fstab.") ||
(in_initrd() && startswith(word, "rd.fstab."))) {
log_warning("Unknown kernel switch %s. Ignoring.", word);
}
}
return 0;
}
int main(int argc, char *argv[]) {
int r = 0, k, l = 0;
if (argc > 1 && argc != 4) {
log_error("This program takes three or no arguments.");
return EXIT_FAILURE;
}
if (argc > 1)
arg_dest = argv[1];
log_set_target(LOG_TARGET_SAFE);
log_parse_environment();
log_open();
umask(0022);
if (parse_proc_cmdline() < 0)
return EXIT_FAILURE;
if (in_initrd())
r = parse_new_root_from_proc_cmdline();
if (!arg_enabled)
return (r < 0) ? EXIT_FAILURE : EXIT_SUCCESS;
k = parse_fstab(NULL, false);
if (in_initrd())
l = parse_fstab("/sysroot", true);
return (r < 0) || (k < 0) || (l < 0) ? EXIT_FAILURE : EXIT_SUCCESS;
}