#include <fcntl.h>
#include <sys/ioctl.h>
-#include "../../udev.h"
+#include "../../udev/udev.h"
#include "lib/libvolume_id.h"
#define BLKGETSIZE64 _IOR(0x12,114,size_t)
{ "export", 0, NULL, 'x' },
{ "skip-raid", 0, NULL, 's' },
{ "probe-all", 0, NULL, 'a' },
+ { "offset", 1, NULL, 'o' },
{ "help", 0, NULL, 'h' },
{}
};
uint64_t size;
int skip_raid = 0;
int probe_all = 0;
+ uint64_t offset = 0;
const char *node;
- struct passwd *pw;
int fd;
const char *label, *uuid, *type, *type_version, *usage;
int retval;
while (1) {
int option;
- option = getopt_long(argc, argv, "lLutxsah", options, NULL);
+ option = getopt_long(argc, argv, "lLutxsaoh", options, NULL);
if (option == -1)
break;
case 'a':
probe_all = 1;
break;
+ case 'o':
+ offset = strtoull(optarg, NULL, 0);
+ break;
case 'h':
printf("Usage: vol_id [options] <device>\n"
" --export export key/value pairs\n"
" --uuid filesystem uuid\n"
" --skip-raid don't probe for raid\n"
" --probe-all find possibly conflicting signatures\n"
+ " --offset skip given number of bytes of input\n"
" --help\n\n");
goto exit;
default:
node = argv[optind];
if (!node) {
- err("no device");
+ err("no device\n");
fprintf(stderr, "no device\n");
rc = 1;
goto exit;
if (ioctl(fd, BLKGETSIZE64, &size) != 0)
size = 0;
- dbg("BLKGETSIZE64=%llu", (unsigned long long)size);
+ dbg("BLKGETSIZE64=%llu\n", (unsigned long long)size);
/* try to drop all privileges before reading disk content */
- pw = getpwnam ("nobody");
- if (pw != NULL && pw->pw_uid > 0 && pw->pw_gid > 0) {
- dbg("dropping privileges to %u:%u",
- (unsigned int)pw->pw_uid, (unsigned int)pw->pw_gid);
- if (setgroups(0, NULL) != 0 ||
- setgid(pw->pw_gid) != 0 ||
- setuid(pw->pw_uid) != 0) {
- fprintf(stderr, "error dropping privileges: %s\n", strerror(errno));
- rc = 3;
- goto exit;
+ if (getuid() == 0) {
+ struct passwd *pw;
+
+ pw = getpwnam("nobody");
+ if (pw != NULL && pw->pw_uid > 0 && pw->pw_gid > 0) {
+ if (setgroups(0, NULL) != 0 ||
+ setgid(pw->pw_gid) != 0 ||
+ setuid(pw->pw_uid) != 0)
+ info("unable to drop privileges: %s\n\n", strerror(errno));
}
}
if (probe_all) {
- volume_id_all_probers(all_probers, vid, 0, size, NULL);
+ volume_id_all_probers(all_probers, vid, offset, size, NULL);
goto exit;
}
if (skip_raid)
- retval = volume_id_probe_filesystem(vid, 0, size);
+ retval = volume_id_probe_filesystem(vid, offset, size);
else
- retval = volume_id_probe_all(vid, 0, size);
+ retval = volume_id_probe_all(vid, offset, size);
if (retval != 0) {
fprintf(stderr, "%s: unknown volume type\n", node);
rc = 4;