gpt-auto-generator.c revision d736e4f3e76daca4ab1b1fc444737e5ee20a27cd
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering This file is part of systemd.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Copyright 2013 Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is free software; you can redistribute it and/or modify it
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering under the terms of the GNU Lesser General Public License as published by
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering (at your option) any later version.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is distributed in the hope that it will be useful, but
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Lesser General Public License for more details.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering You should have received a copy of the GNU Lesser General Public License
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic bool arg_enabled = true;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic bool arg_root_enabled = true;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic bool arg_root_rw = false;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering _cleanup_free_ char *name = NULL, *unit = NULL, *lnk = NULL;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering name = unit_name_from_path(path, ".swap");
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering unit = strjoin(arg_dest, "/", name, NULL);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return log_error_errno(errno, "Failed to create unit file %s: %m", unit);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering "# Automatically generated by systemd-gpt-auto-generator\n\n"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering "Description=Swap Partition\n"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering "Documentation=man:systemd-gpt-auto-generator(8)\n\n"
fflush(f);
if (ferror(f))
if (!lnk)
return log_oom();
return log_oom();
return log_oom();
return log_oom();
return log_oom();
fprintf(f,
"Conflicts=umount.target\n"
"Before=umount.target cryptsetup.target\n"
id);
fflush(f);
if (ferror(f))
if (!to)
return log_oom();
if (!to)
return log_oom();
if (!to)
return log_oom();
free(p);
return log_oom();
r = write_string_file(p,
if (!ret)
return log_oom();
static int add_mount(
const char *id,
const char *what,
const char *where,
const char *fstype,
bool rw,
const char *description,
const char *post) {
if (!unit)
return log_oom();
return log_oom();
fprintf(f,
if (post)
fprintf(f,
if (fstype)
fflush(f);
if (ferror(f))
if (post) {
if (!lnk)
return log_oom();
static int probe_and_add_mount(
const char *id,
const char *what,
const char *where,
bool rw,
const char *description,
const char *post) {
const char *fstype;
errno = 0;
if (errno == 0)
return log_oom();
return -errno;
errno = 0;
r = blkid_do_safeprobe(b);
if (errno == 0)
return -errno;
return add_mount(
id,
what,
rw,
post);
if (!udev)
return log_oom();
return log_oom();
if (!parent) {
if (!devtype) {
if (!node) {
errno = 0;
if (errno == 0)
return log_oom();
return -errno;
errno = 0;
r = blkid_do_safeprobe(b);
if (errno == 0)
return -errno;
errno = 0;
if (errno == 0)
return -errno;
errno = 0;
if (!pl) {
if (errno == 0)
return log_oom();
return -errno;
return log_oom();
return log_oom();
return log_oom();
r = udev_enumerate_scan_devices(e);
int nr;
unsigned long long flags;
if (!subnode)
if (!pp)
if (nr < 0)
if (!stype)
if (!home)
return log_oom();
if (!srv)
return log_oom();
if (home) {
if (srv) {
k = probe_and_add_mount("srv", srv, "/srv", srv_rw, "Server Data Partition", SPECIAL_LOCAL_FS_TARGET);
return -errno;
return -errno;
arg_enabled = r;
arg_root_rw = true;
arg_root_rw = false;
static int add_root_mount(void) {
#ifdef ENABLE_EFI
if (!is_efi_boot()) {
if (r == -ENOENT) {
return add_mount(
"/dev/gpt-auto-root",
NULL,
static int add_mounts(void) {
return EXIT_FAILURE;
log_open();
return EXIT_SUCCESS;
if (!arg_enabled) {
return EXIT_SUCCESS;
if (arg_root_enabled)
r = add_root_mount();
if (!in_initrd()) {
k = add_mounts();