gpt-auto-generator.c revision 0b6b6787e3f0ae8906ce0212bd629edbe931b73d
feb2c590898bd03d4dfd8a77c429a471776527c5Julian Kigwana/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
208f1c0d2a321a44c504ed47bbe0378ea2a9d1f2Phil Ostler This file is part of systemd.
along with systemd; If not, see <http://www.gnu.org/licenses/>.
#include <unistd.h>
#include <stdlib.h>
#include "sd-id128.h"
#include "libudev.h"
#include "path-util.h"
#include "util.h"
#include "mkdir.h"
#include "missing.h"
#include "udev-util.h"
#include "special.h"
#include "unit-name.h"
#include "virt.h"
#include "generator.h"
#include "gpt.h"
#include "fileio.h"
#include "efivars.h"
#include "fstab-util.h"
#include "blkid-util.h"
#include "btrfs-util.h"
static bool arg_enabled = true;
static bool arg_root_enabled = true;
static bool arg_root_rw = false;
return log_oom();
return log_oom();
fprintf(f,
"Conflicts=umount.target\n"
"Before=umount.target cryptsetup.target\n"
id);
r = fflush_and_check(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 *options,
const char *description,
const char *post) {
return log_oom();
fprintf(f,
if (post)
fprintf(f,
if (fstype)
if (options)
r = fflush_and_check(f);
if (post) {
if (!lnk)
return log_oom();
if (r == -ENOENT)
static int probe_and_add_mount(
const char *id,
const char *what,
const char *where,
bool rw,
const char *description,
const char *post) {
errno = 0;
if (errno == 0)
return log_oom();
return -errno;
errno = 0;
r = blkid_do_safeprobe(b);
return add_mount(
id,
what,
rw,
NULL,
post);
if (!unit)
return log_oom();
fprintf(f,
path);
r = fflush_and_check(f);
if (!lnk)
return log_oom();
#ifdef ENABLE_EFI
static int add_automount(
const char *id,
const char *what,
const char *where,
const char *fstype,
bool rw,
const char *options,
const char *description,
if (options)
if (!opt)
return log_oom();
what,
rw,
opt,
NULL);
return log_oom();
fprintf(f,
r = fflush_and_check(f);
if (!lnk)
return log_oom();
if (!is_efi_boot()) {
if (in_initrd()) {
if (detect_container() > 0) {
if (r == -ENOENT) {
errno = 0;
if (errno == 0)
return log_oom();
return -errno;
errno = 0;
r = blkid_do_safeprobe(b);
what,
if (!udev)
return log_oom();
return log_oom();
if (!name)
if (!name) {
if (!parent) {
if (!devtype) {
if (!node) {
errno = 0;
if (errno == 0)
return log_oom();
errno = 0;
r = blkid_do_safeprobe(b);
errno = 0;
errno = 0;
if (!pl) {
if (errno == 0)
return log_oom();
return log_oom();
return log_oom();
return log_oom();
r = udev_enumerate_scan_devices(e);
unsigned long long flags;
int nr;
if (!subnode)
if (!pp)
if (nr < 0)
if (!stype)
return log_oom();
return log_oom();
return log_oom();
if (boot) {
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;
return -ENOMEM;
d = opendir(p);
goto fallback;
return -errno;
goto fallback;
if (!found)
goto fallback;
r = read_one_line_file(q, &t);
if (r == -ENOENT)
goto fallback;
return -EINVAL;
if (maj == 0)
goto fallback;
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,
NULL,
static int add_mounts(void) {
return EXIT_FAILURE;
log_open();
if (detect_container() > 0) {
return EXIT_SUCCESS;
if (!arg_enabled) {
return EXIT_SUCCESS;
if (arg_root_enabled)
r = add_root_mount();
if (!in_initrd()) {
k = add_mounts();