fstab-generator.c revision 3f85ef0f05ffc51e19f86fb83a1c51e8e3cd6817
d360705f0f1262d49cccb6507abeafb7cfb5bbe0Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
d360705f0f1262d49cccb6507abeafb7cfb5bbe0Lennart Poettering This file is part of systemd.
d360705f0f1262d49cccb6507abeafb7cfb5bbe0Lennart Poettering Copyright 2012 Lennart Poettering
d360705f0f1262d49cccb6507abeafb7cfb5bbe0Lennart Poettering systemd is free software; you can redistribute it and/or modify it
d360705f0f1262d49cccb6507abeafb7cfb5bbe0Lennart Poettering under the terms of the GNU Lesser General Public License as published by
d360705f0f1262d49cccb6507abeafb7cfb5bbe0Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
d360705f0f1262d49cccb6507abeafb7cfb5bbe0Lennart Poettering (at your option) any later version.
d360705f0f1262d49cccb6507abeafb7cfb5bbe0Lennart Poettering systemd is distributed in the hope that it will be useful, but
d360705f0f1262d49cccb6507abeafb7cfb5bbe0Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
d360705f0f1262d49cccb6507abeafb7cfb5bbe0Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
d360705f0f1262d49cccb6507abeafb7cfb5bbe0Lennart Poettering Lesser General Public License for more details.
along with systemd; If not, see <http://www.gnu.org/licenses/>.
#include <stdio.h>
#include <mntent.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include "log.h"
#include "util.h"
#include "unit-name.h"
#include "path-util.h"
#include "mount-setup.h"
#include "special.h"
#include "mkdir.h"
#include "fileio.h"
#include "generator.h"
#include "strv.h"
#include "virt.h"
static bool arg_fstab_enabled = true;
if (!opt)
return -EINVAL;
errno = 0;
if (errno > 0)
return -errno;
return -EINVAL;
*ret = (int) r;
bool noauto;
if (!name)
return log_oom();
if (!unit)
return log_oom();
log_error("Failed to create swap unit file %s, as it already exists. Duplicate entry in /etc/fstab?", unit);
return -errno;
fprintf(f,
what);
if (pri >= 0)
r = fflush_and_check(f);
if (!noauto) {
if (!lnk)
return log_oom();
return -errno;
static int add_mount(
const char *what,
const char *where,
const char *fstype,
const char *opts,
int passno,
bool noauto,
bool nofail,
bool automount,
const char *post,
const char *source) {
_cleanup_free_ char
automount = false;
noauto = false;
nofail = false;
if (!name)
return log_oom();
if (!unit)
return log_oom();
log_error("Failed to create mount unit file %s, as it already exists. Duplicate entry in /etc/fstab?", unit);
return -errno;
fprintf(f,
source);
if (passno != 0) {
fprintf(f,
what,
where);
fflush(f);
if (ferror(f)) {
return -errno;
if (!lnk)
return log_oom();
return -errno;
if (automount) {
if (!automount_name)
return log_oom();
if (!automount_unit)
return log_oom();
fclose(f);
return -errno;
fprintf(f,
source);
if (post)
fprintf(f,
post);
fprintf(f,
where);
fflush(f);
if (ferror(f)) {
return -errno;
if (!lnk)
return log_oom();
return -errno;
const char *fstab_path;
return -errno;
if (!what)
return log_oom();
if (!where)
return log_oom();
const char *post;
if (initrd)
post,
static int add_root_mount(void) {
const char *opts;
if (!arg_root_options)
else if (arg_root_rw >= 0 ||
opts,
static int add_usr_mount(void) {
const char *opts;
if (!arg_usr_what)
return log_oom();
if (!arg_usr_fstype)
return log_oom();
if (!arg_usr_options)
return log_oom();
opts,
arg_fstab_enabled = r;
return log_oom();
return log_oom();
o = arg_root_options ?
return log_oom();
arg_root_options = o;
return log_oom();
return log_oom();
o = arg_usr_options ?
return log_oom();
arg_usr_options = o;
arg_root_rw = true;
arg_root_rw = false;
return EXIT_FAILURE;
log_open();
return EXIT_FAILURE;
if (in_initrd()) {
r = add_root_mount();
r = add_usr_mount();
if (arg_fstab_enabled) {
k = parse_fstab(false);
if (in_initrd()) {
k = parse_fstab(true);