vol_id.c revision 22c89d3fd78d7ef3f231fc837a47860efcc4cc9e
/*
* vol_id - read filesystem label and uuid
*
* Copyright (C) 2005-2008 Kay Sievers <kay.sievers@vrfy.org>
*
* 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/>.
*/
#ifndef _GNU_SOURCE
#define _GNU_SOURCE 1
#endif
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <pwd.h>
#include <grp.h>
#include <getopt.h>
#include <fcntl.h>
#include "lib/libvolume_id.h"
static int debug;
{
if (debug) {
} else {
}
}
{
return;
}
{
/* strip trailing whitespace */
len--;
/* strip leading whitespace */
i = 0;
i++;
j = 0;
while (i < len) {
/* substitute multiple whitespace */
i++;
to[j++] = '_';
}
/* skip chars */
if (from[i] == '/') {
i++;
continue;
}
}
to[j] = '\0';
}
void *data)
{
const char *type;
return 0;
}
{
{}
};
enum print_type {
} print = PRINT_EXPORT;
char label_safe[256];
char label_enc[256];
char uuid_enc[256];
int skip_raid = 0;
int probe_all = 0;
const char *node;
int fd;
int retval;
int rc = 0;
goto exit;
logging_init("vol_id");
/* hook in our debug into libvolume_id */
while (1) {
int option;
if (option == -1)
break;
switch (option) {
case 'd':
debug = 1;
break;
case 'l':
print = PRINT_LABEL;
break;
case 'L':
break;
case 'u':
print = PRINT_UUID;
break;
case 't':
print = PRINT_TYPE;
break;
case 'x':
break;
case 's':
skip_raid = 1;
break;
case 'a':
probe_all = 1;
break;
case 'S':
if (optarg[0] != '\0')
break;
case 'o':
if (optarg[0] != '\0')
break;
case 'h':
printf("Usage: vol_id [options] <device>\n"
" --type filesystem type\n"
" --label filesystem label\n"
" --label-raw raw label\n"
" --uuid filesystem uuid\n"
" --skip-raid don't probe for raid\n"
" --probe-all find possibly conflicting signatures\n"
" --offset=<bytes> probe at the given offset\n"
" --size=<bytes> overwrite device size\n"
" --debug print debug output to stderr\n"
" --help\n\n");
goto exit;
default:
retval = 1;
goto exit;
}
}
if (!node) {
rc = 1;
goto exit;
}
if (fd < 0) {
rc = 2;
goto exit;
}
rc = 2;
goto exit;
}
if (size == 0) {
size = 0;
info(udev_ctx, "BLKGETSIZE64=%llu (%lluGB)\n", (unsigned long long)size, (unsigned long long)size >> 30);
}
/* try to drop all privileges before reading disk content */
if (getuid() == 0) {
}
}
if (probe_all) {
goto exit;
}
if (skip_raid)
else
if (retval != 0) {
rc = 4;
goto exit;
}
rc = 4;
goto exit;
}
switch (print) {
case PRINT_EXPORT:
break;
case PRINT_TYPE:
break;
case PRINT_LABEL:
rc = 3;
goto exit;
}
break;
case PRINT_UUID:
rc = 4;
goto exit;
}
break;
case PRINT_LABEL_RAW:
rc = 3;
goto exit;
}
break;
}
exit:
return rc;
}