gpt-auto-generator.c revision 1ebab691c7749779072741f71865bd0e055b7ecf
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/>.
0dd25fb9f005d8ab7ac4bc10a609d00569f8c56aLennart PoetteringDEFINE_TRIVIAL_CLEANUP_FUNC(blkid_probe, blkid_free_probe);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#define _cleanup_blkid_freep_probe_ _cleanup_(blkid_free_probep)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic int verify_gpt_partition(const char *node, sd_id128_t *type, unsigned *nr, char **fstype) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering _cleanup_blkid_freep_probe_ blkid_probe b = NULL;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering const char *v;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering blkid_probe_set_superblocks_flags(b, BLKID_SUBLKS_TYPE);
0dd25fb9f005d8ab7ac4bc10a609d00569f8c56aLennart Poettering blkid_probe_set_partitions_flags(b, BLKID_PARTS_ENTRY_DETAILS);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (r == -2 || r == 1) /* no result or uncertain */
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering else if (r != 0)
2c27fbca2d88214bd305272308a370a962818f1eLennart Poettering r = blkid_probe_lookup_value(b, "PART_ENTRY_SCHEME", &v, NULL);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering /* return 0 if we're not on GPT */
if (type) {
errno = 0;
if (nr) {
errno = 0;
if (fstype) {
errno = 0;
char *fst;
if (!fst)
return -ENOMEM;
if (!name)
return log_oom();
if (!unit)
return log_oom();
return -errno;
fprintf(f,
path);
fflush(f);
if (ferror(f)) {
return -errno;
if (!lnk)
return log_oom();
return -errno;
return log_oom();
return log_oom();
return log_oom();
return log_oom();
return -errno;
fprintf(f,
"Conflicts=umount.target\n"
"Before=umount.target cryptsetup.target\n"
"After=systemd-readahead-collect.service systemd-readahead-replay.service\n\n"
id);
fflush(f);
if (ferror(f)) {
return -errno;
if (!to)
return log_oom();
return -errno;
if (!to)
return log_oom();
return -errno;
if (!to)
return log_oom();
return -errno;
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, const char *description) {
if (!unit)
return log_oom();
return log_oom();
return -errno;
fprintf(f,
fprintf(f,
if (fstype) {
fprintf(f,
fstype);
fflush(f);
if (ferror(f)) {
return -errno;
if (!lnk)
return log_oom();
return -errno;
return log_oom();
return log_oom();
if (!parent)
return log_oom();
return log_oom();
return log_oom();
r = udev_enumerate_scan_devices(e);
log_error("Failed to enumerate partitions on /dev/block/%u:%u: %s", major(dev), minor(dev), strerror(-r));
unsigned nr;
return log_oom();
if (!node)
return log_oom();
if (r == -EBADSLT)
if (!home)
return log_oom();
if (!srv)
return log_oom();
if (fd < 0)
return -errno;
return -errno;
return -errno;
return -errno;
return -ENODEV;
return -ENODEV;
return -ENODEV;
return -errno;
return -errno;
return log_oom();
t = udev_device_get_devnode(d);
return -ENODEV;
n = strdup(t);
return -ENOMEM;
*ret = n;
return EXIT_FAILURE;
log_open();
if (in_initrd()) {
return EXIT_SUCCESS;
return EXIT_SUCCESS;
return EXIT_FAILURE;
return EXIT_SUCCESS;
if (!udev) {
log_oom();
return EXIT_FAILURE;
return EXIT_FAILURE;
return EXIT_FAILURE;
return EXIT_SUCCESS;
return EXIT_FAILURE;
return EXIT_SUCCESS;