fstab-generator.c revision a5c32cff1f56afe6f0c6c70d91a88a7a8238b2d7
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2012 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
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 "virt.h"
#include "fileio.h"
static const char *arg_dest = "/tmp";
static bool arg_enabled = true;
char *p;
if (!is_device_path(path))
return 0;
if (!p)
return log_oom();
*unit = p;
return 1;
}
unsigned long r;
if (!pri)
return 0;
pri += 4;
errno = 0;
if (errno != 0)
return -errno;
return -EINVAL;
*ret = (int) r;
return 1;
}
int r, pri = -1;
if (r < 0) {
log_error("Failed to parse priority");
return pri;
}
if (!name)
return log_oom();
if (!unit)
return log_oom();
if (!f) {
log_error("Failed to create swap unit file %s, as it already exists. Duplicate entry in /etc/fstab?", unit);
else
return -errno;
}
fputs("# Automatically generated by systemd-fstab-generator\n\n"
"[Unit]\n"
"DefaultDependencies=no\n"
fprintf(f,
"\n"
"[Swap]\n"
"What=%s\n",
what);
if (pri >= 0)
fprintf(f,
"Priority=%i\n",
pri);
fflush(f);
if (ferror(f)) {
return -errno;
}
if (!noauto) {
if (!lnk)
return log_oom();
return -errno;
}
if (r < 0)
return r;
if (r > 0) {
if (!lnk)
return log_oom();
return -errno;
}
}
}
return 0;
}
return
}
return
}
const char *source) {
char _cleanup_free_
int r;
return 0;
return 0;
}
if (mount_point_is_api(where) ||
return 0;
if (isnetwork) {
} else {
}
if (!name)
return log_oom();
if (!unit)
return log_oom();
if (!f) {
log_error("Failed to create mount unit file %s, as it already exists. Duplicate entry in /etc/fstab?", unit);
else
return -errno;
}
fprintf(f,
"# Automatically generated by systemd-fstab-generator\n\n"
"[Unit]\n"
"SourcePath=%s\n"
"DefaultDependencies=no\n",
source);
fprintf(f,
"After=%s\n"
"Wants=%s\n"
pre,
pre);
fprintf(f,
"Before=%s\n",
post);
fprintf(f,
"\n"
"[Mount]\n"
"What=%s\n"
"Where=%s\n"
"Type=%s\n"
"FsckPassNo=%i\n",
what,
type,
passno);
fprintf(f,
"Options=%s\n",
opts);
if (wait)
fprintf(f,
"TimeoutSec=0\n");
fflush(f);
if (ferror(f)) {
return -errno;
}
if (!noauto) {
if (!lnk)
return log_oom();
return -errno;
}
if (!isbind &&
if (r < 0)
return r;
if (r > 0) {
if (!lnk)
return log_oom();
return -errno;
}
}
}
}
if (!name)
return log_oom();
if (!automount_unit)
return log_oom();
fclose(f);
if (!f) {
return -errno;
}
fprintf(f,
"# Automatically generated by systemd-fstab-generator\n\n"
"[Unit]\n"
"DefaultDependencies=no\n"
"\n"
"[Automount]\n"
"Where=%s\n",
post,
where);
fflush(f);
if (ferror(f)) {
return -errno;
}
if (!lnk)
return log_oom();
return -errno;
}
}
return 0;
}
static int parse_fstab(void) {
FILE *f;
int r = 0;
errno = 0;
if (!f) {
return 0;
return -errno;
}
int k;
r = log_oom();
goto finish;
}
else {
}
if (k < 0)
r = k;
}
endmntent(f);
return r;
}
static int parse_new_root_from_proc_cmdline(void) {
char *w, *state;
int r;
size_t l;
bool wait = false;
if (r < 0) {
return 0;
}
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 */
if (!word)
return log_oom();
if (!what)
return log_oom();
if (!type)
return log_oom();
if (!opts)
return log_oom();
if (!opts)
return log_oom();
wait = true;
}
if (what) {
if (r < 0)
return r;
} else
log_error("Could not find a root= entry on the kernel commandline.");
return 0;
}
static int parse_proc_cmdline(void) {
char *w, *state;
int r;
size_t l;
if (detect_container(NULL) > 0)
return 0;
if (r < 0) {
return 0;
}
if (!word)
return log_oom();
if (r < 0)
else
arg_enabled = r;
if (in_initrd()) {
if (r < 0)
else
arg_enabled = r;
}
}
}
return 0;
}
int r, k = 0;
log_error("This program takes three or no arguments.");
return EXIT_FAILURE;
}
if (argc > 1)
log_open();
umask(0022);
if (parse_proc_cmdline() < 0)
return EXIT_FAILURE;
if (in_initrd())
if (!arg_enabled)
return EXIT_SUCCESS;
r = parse_fstab();
return (r < 0) || (k < 0) ? EXIT_FAILURE : EXIT_SUCCESS;
}