fstab-generator.c revision 7fd1b19bc9e9f5574f2877936b8ac267c7706947
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen This file is part of systemd.
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen Copyright 2012 Lennart Poettering
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 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 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 Gundersenstatic bool arg_enabled = true;
134e56dcc53970a20a858283650bb92cd5da1d17Lennart Poetteringstatic int device_name(const char *path, char **unit) {
cb9fc36a1211967e8c58b0502a26c42552ac8060Lennart Poetteringstatic int mount_find_pri(struct mntent *me, int *ret) {
769d324c99aab129148bd25f5f663ef441287d86Lennart Poettering unsigned long r;
e331e24649213f2e093e16e4d3d64ee823dfc375Tom Gundersenstatic int add_swap(const char *what, struct mntent *me) {
e331e24649213f2e093e16e4d3d64ee823dfc375Tom Gundersen _cleanup_free_ char *name = NULL, *unit = NULL, *lnk = NULL, *device = NULL;
b98b483bac585af754e8a22ea890db8486905d8aAlin Rauta if (r < 0) {
2cc412b59353576cece2d5b30c6a39c70552f0a0Tom Gundersen log_error("Failed to create swap unit file %s, as it already exists. Duplicate entry in /etc/fstab?", unit);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen log_error("Failed to create unit file %s: %m", unit);
6a0a2f860f1ca4a10932da3b41dbc3c0139757ccTom Gundersen fputs("# Automatically generated by systemd-fstab-generator\n\n"
5be4d38e31281727b6f45ae869136bb01a1f7790Tom Gundersen "SourcePath=/etc/fstab\n"
bcb7a07e0a785bda1eed658e984ff6b4a11cba9aTom Gundersen "DefaultDependencies=no\n"
e1853b00ef7cb56cafd908327dd44b3ab48b402cSusant Sahani "Priority=%i\n",
c106cc36b9b8e8998eb95299b02f1db9c1209122Tom Gundersen log_error("Failed to write unit file %s: %m", unit);
f048a16b464295a4e0a4f4c1210f06343ad31231Tom Gundersen lnk = strjoin(arg_dest, "/" SPECIAL_SWAP_TARGET ".wants/", name, NULL);
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersen log_error("Failed to create symlink %s: %m", lnk);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen lnk = strjoin(arg_dest, "/", device, ".wants/", name, NULL);
81163121e649523b4071f67ddc03c2db649036c5Tom Gundersen log_error("Failed to create symlink %s: %m", lnk);
fd6d906cf46ecef45ebbb5a361e1dc436f031d7aLennart Poetteringstatic bool mount_is_bind(struct mntent *me) {
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersenstatic bool mount_is_network(struct mntent *me) {
9e7e440835c43d81ffdbc299d2c07daaa641ed50Tom Gundersenstatic bool mount_in_initrd(struct mntent *me) {
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen const char *pre,
9c0a72f961e00b0447767973e7117e131bea5b5dTom Gundersen const char *source) {
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen *name = NULL, *unit = NULL, *lnk = NULL, *device = NULL,
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen *automount_name = NULL, *automount_unit = NULL;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen log_warning("Mount point %s is not a valid path, ignoring.", where);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen log_error("Failed to create mount unit file %s, as it already exists. Duplicate entry in /etc/fstab?", unit);
bbf7c04821a71fec67eaf0e7a34d17afc5913c13Tom Gundersen log_error("Failed to create unit file %s: %m", unit);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen "# Automatically generated by systemd-fstab-generator\n\n"
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen "SourcePath=%s\n"
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen "DefaultDependencies=no\n",
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen "After=%s\n",
505f8da7325591defe5f751f328bd26915267602Tom Gundersen "After=%s\n",
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen "Wants=%s\n",
6192b846ca0d15602e94ddb5da4420b7c60d64a5Tom Gundersen "Before=%s\n",
7951dea20911969287878e6897b3eca348721adeSusant Sahani "FsckPassNo=%i\n",
7951dea20911969287878e6897b3eca348721adeSusant Sahani "Options=%s\n",
85a8eeee36b57c1ab382b0225fa9a87525bbeee9Susant Sahani log_error("Failed to write unit file %s: %m", unit);
85a8eeee36b57c1ab382b0225fa9a87525bbeee9Susant Sahani lnk = strjoin(arg_dest, "/", post, nofail || automount ? ".wants/" : ".requires/", name, NULL);
c0dda18697e0994272c0c9616d36f6777b60e2c7Tom Gundersen log_error("Failed to create symlink %s: %m", lnk);
71a6151083d842b2f5bf04e50239f0bf85d34d2eTom Gundersen lnk = strjoin(arg_dest, "/", device, ".wants/", name, NULL);
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersen log_error("Failed to create symlink %s: %m", lnk);
f882c247ad59776c3a7753bb963c1f8e2386cb79Tom Gundersen automount_name = unit_name_from_path(where, ".automount");
5a8bcb674f71a20e95df55319b34c556638378ceLennart Poettering automount_unit = strjoin(arg_dest, "/", automount_name, NULL);
71a6151083d842b2f5bf04e50239f0bf85d34d2eTom Gundersen log_error("Failed to create unit file %s: %m", automount_unit);
eb0ea358b688a6f83ff305c6b825c61f12b6dcb8Tom Gundersen "# Automatically generated by systemd-fstab-generator\n\n"
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersen "SourcePath=%s\n"
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersen "DefaultDependencies=no\n"
b98b483bac585af754e8a22ea890db8486905d8aAlin Rauta "Before= %s\n",
b98b483bac585af754e8a22ea890db8486905d8aAlin Rauta "[Automount]\n"
b98b483bac585af754e8a22ea890db8486905d8aAlin Rauta "Where=%s\n",
b98b483bac585af754e8a22ea890db8486905d8aAlin Rauta log_error("Failed to write unit file %s: %m", automount_unit);
ed942a9eb22d50f667909ad6184b45015d28d054Tom Gundersen lnk = strjoin(arg_dest, "/", post, nofail ? ".wants/" : ".requires/", automount_name, NULL);
bd8f65387673e29f46136a4ed172097035002c23Tom Gundersen log_error("Failed to create symlink %s: %m", lnk);
0dd25fb9f005d8ab7ac4bc10a609d00569f8c56aLennart Poetteringstatic int parse_fstab(const char *prefix, bool initrd) {
cb9fc36a1211967e8c58b0502a26c42552ac8060Lennart Poettering fstab_path = strjoin(strempty(prefix), "/etc/fstab", NULL);
return -errno;
r = log_oom();
goto finish;
if (initrd) {
endmntent(f);
static int parse_new_root_from_proc_cmdline(void) {
char *w, *state;
size_t l;
return log_oom();
if (!word)
return log_oom();
if (!what)
return log_oom();
if (!type)
return log_oom();
return log_oom();
opts = o;
return log_oom();
opts = o;
if (!what) {
static int parse_proc_cmdline(void) {
char *w, *state;
size_t l;
if (!word)
return log_oom();
arg_enabled = r;
if (in_initrd()) {
arg_enabled = r;
return EXIT_FAILURE;
log_open();
if (parse_proc_cmdline() < 0)
return EXIT_FAILURE;
if (in_initrd())
if (!arg_enabled)
if (in_initrd())