udev-builtin-blkid.c revision f5e5c28f42a2f6d006785ec8b5e98c11a71bb039
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/*
* probe disks for filesystems and partitions
*
* Copyright (C) 2011 Kay Sievers <kay@vrfy.org>
* Copyright (C) 2011 Karel Zak <kzak@redhat.com>
*
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sd-id128.h"
#include "alloc-util.h"
#include "efivars.h"
#include "fd-util.h"
#include "gpt.h"
#include "string-util.h"
#include "udev.h"
static void print_property(struct udev_device *dev, bool test, const char *name, const char *value) {
char s[256];
s[0] = '\0';
blkid_safe_string(value, s, sizeof(s));
blkid_encode_string(value, s, sizeof(s));
blkid_safe_string(value, s, sizeof(s));
blkid_encode_string(value, s, sizeof(s));
blkid_safe_string(value, s, sizeof(s));
blkid_encode_string(value, s, sizeof(s));
blkid_encode_string(value, s, sizeof(s));
blkid_encode_string(value, s, sizeof(s));
blkid_encode_string(value, s, sizeof(s));
blkid_encode_string(value, s, sizeof(s));
blkid_encode_string(value, s, sizeof(s));
blkid_encode_string(value, s, sizeof(s));
}
}
#if defined(GPT_ROOT_NATIVE) && defined(ENABLE_EFI)
bool found_esp = false;
int i, nvals, r;
/* Iterate through the partitions on this disk, and see if the
* EFI ESP we booted from is on it. If so, find the first root
* disk, and add a property indicating its partition UUID. */
errno = 0;
if (!pl)
for (i = 0; i < nvals; i++) {
if (!pp)
continue;
if (!sid)
continue;
if (!stype)
continue;
continue;
unsigned long long flags;
if (flags & GPT_FLAG_NO_AUTO)
continue;
/* We found an ESP, let's see if it matches
* the ESP we booted from. */
continue;
if (r < 0)
return r;
found_esp = true;
/* We found a suitable root partition, let's
* remember the first one. */
if (!root_id) {
if (!root_id)
return -ENOMEM;
}
}
}
/* We found the ESP on this disk, and also found a root
* partition, nice! Let's export its UUID */
#endif
return 0;
}
int rc;
return -1;
/*
* check if the small disk is partitioned, if yes then
* don't probe for filesystems.
*/
if (rc < 0)
return rc; /* -1 = error, 1 = nothing, 0 = success */
return 0; /* partition table detected */
}
return blkid_do_safeprobe(pr);
}
const char *root_partition;
bool noraid = false;
const char *data;
const char *name;
int nvals;
int i;
int err = 0;
bool is_gpt = false;
{}
};
for (;;) {
int option;
if (option == -1)
break;
switch (option) {
case 'o':
break;
case 'R':
noraid = true;
break;
}
}
pr = blkid_new_probe();
if (!pr)
return EXIT_FAILURE;
if (noraid)
if (fd < 0) {
goto out;
}
if (err < 0)
goto out;
if (err < 0)
goto out;
log_warning("incorrect %s checksum on %s",
else
log_warning("incorrect checksum on %s",
goto out;
}
/* If we are a partition then our parent passed on the root
* partition UUID to us */
for (i = 0; i < nvals; i++) {
continue;
/* Is this a disk with GPT partition table? */
is_gpt = true;
/* Is this a partition that matches the root partition
* property we inherited from our parent? */
}
if (is_gpt)
out:
if (err < 0)
return EXIT_FAILURE;
return EXIT_SUCCESS;
}
const struct udev_builtin udev_builtin_blkid = {
.name = "blkid",
.cmd = builtin_blkid,
.help = "Filesystem and partition probing",
.run_once = true,
};