fstab-generator.c revision a6903061530cac5fbaa99a080a93221c02c349f9
/*-*- 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"
static const char *arg_dest = "/tmp";
char *p;
if (!is_device_path(path))
return 0;
if (!p)
return -ENOMEM;
*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) {
log_error("Out of memory");
r = -ENOMEM;
goto finish;
}
if (!unit) {
log_error("Out of memory");
r = -ENOMEM;
goto finish;
}
if (!f) {
r = -errno;
log_error("Failed to create unit file: %m");
goto finish;
}
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)) {
log_error("Failed to write unit file: %m");
r = -errno;
goto finish;
}
if (!noauto) {
if (!lnk) {
log_error("Out of memory");
r = -ENOMEM;
goto finish;
}
log_error("Failed to create symlink: %m");
r = -errno;
goto finish;
}
if (r < 0) {
log_error("Out of memory");
r = -ENOMEM;
goto finish;
}
if (r > 0) {
if (!lnk) {
log_error("Out of memory");
r = -ENOMEM;
goto finish;
}
log_error("Failed to create symlink: %m");
r = -errno;
goto finish;
}
}
}
r = 0;
if (f)
fclose(f);
return r;
}
return
}
return
}
char *name = NULL, *unit = NULL, *lnk = NULL, *device = NULL, *automount_name = NULL, *automount_unit = NULL;
int r;
return 0;
return 0;
}
if (mount_point_is_api(where) ||
return 0;
if (isnetwork) {
} else {
}
if (!name) {
log_error("Out of memory");
r = -ENOMEM;
goto finish;
}
if (!unit) {
log_error("Out of memory");
r = -ENOMEM;
goto finish;
}
if (!f) {
r = -errno;
log_error("Failed to create unit file: %m");
goto finish;
}
fputs("# Automatically generated by systemd-fstab-generator\n\n"
"[Unit]\n"
"DefaultDependencies=no\n", f);
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,
me->mnt_passno);
fprintf(f,
"Options=%s\n",
fflush(f);
if (ferror(f)) {
log_error("Failed to write unit file: %m");
r = -errno;
goto finish;
}
if (!noauto) {
if (!lnk) {
log_error("Out of memory");
r = -ENOMEM;
goto finish;
}
log_error("Failed to create symlink: %m");
r = -errno;
goto finish;
}
if (!isbind &&
if (r < 0) {
log_error("Out of memory");
r = -ENOMEM;
goto finish;
}
if (r > 0) {
if (!lnk) {
log_error("Out of memory");
r = -ENOMEM;
goto finish;
}
log_error("Failed to creat symlink: %m");
r = -errno;
goto finish;
}
}
}
}
if (!name) {
log_error("Out of memory");
r = -ENOMEM;
goto finish;
}
if (!automount_unit) {
log_error("Out of memory");
r = -ENOMEM;
goto finish;
}
fclose(f);
if (!f) {
r = -errno;
log_error("Failed to create unit file: %m");
goto finish;
}
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)) {
log_error("Failed to write unit file: %m");
r = -errno;
goto finish;
}
if (!lnk) {
log_error("Out of memory");
r = -ENOMEM;
goto finish;
}
log_error("Failed to create symlink: %m");
r = -errno;
goto finish;
}
}
r = 0;
if (f)
fclose(f);
return r;
}
static int parse_fstab(void) {
FILE *f;
int r = 0;
errno = 0;
if (!f) {
return 0;
return -errno;
}
int k;
if (!what) {
log_error("Out of memory");
r = -ENOMEM;
goto finish;
}
if (!where) {
log_error("Out of memory");
r = -ENOMEM;
goto finish;
}
else
if (k < 0)
r = k;
}
endmntent(f);
return r;
}
int r;
if (argc > 2) {
log_error("This program takes one or no arguments.");
return EXIT_FAILURE;
}
if (argc > 1)
log_open();
umask(0022);
r = parse_fstab();
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}