udev_volume_id.c revision c2401132bf72cbda6555f1ef4403851c14faeba5
/*
* udev_volume_id - udev callout to read filesystem label and uuid
*
* Copyright (C) 2005 Kay Sievers <kay.sievers@vrfy.org>
*
* sample udev rule for creation of a symlink with the filsystem uuid:
* KERNEL="sd*", PROGRAM="/sbin/udev_volume_id -u %N", SYMLINK="%c"
*
* under the terms of the GNU General Public License as published by the
* Free Software Foundation version 2 of the License.
*
* 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, write to the Free Software Foundation, Inc.,
* 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#ifndef _GNU_SOURCE
#define _GNU_SOURCE 1
#endif
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include "../../udev_utils.h"
#include "../../logging.h"
#include "volume_id/volume_id.h"
#ifdef USE_LOG
{
static int udev_log = -1;
if (udev_log == -1) {
const char *value;
if (value)
else
}
return;
}
#endif
extern int optind;
{
const char help[] = "usage: udev_volume_id [-t|-l|-u] <device>\n"
" -t filesystem type\n"
" -l filesystem label\n"
" -u filesystem uuid\n"
"\n";
static const char short_options[] = "htlu";
const char *device;
char print = 'a';
static char name[VOLUME_ID_LABEL_SIZE];
int len, i, j;
unsigned long long size;
int rc = 1;
logging_init("udev_volume_id");
while (1) {
int option;
if (option == -1)
break;
switch (option) {
case 't':
print = 't';
continue;
case 'l':
print = 'l';
continue;
case 'u':
print = 'u';
continue;
case 'h':
case '?':
default:
exit(1);
}
}
exit(1);
}
printf("error open volume\n");
goto exit;
}
size = 0;
goto print;
if (volume_id_probe_dasd(vid) == 0)
goto print;
printf("unknown volume type\n");
goto exit;
/* remove trailing spaces */
len--;
/* substitute chars */
i = 0;
j = 0;
while (j < len) {
case '/' :
break;
case ' ' :
name[i++] = '_';
break;
default :
}
j++;
}
name[i] = '\0';
switch (print) {
case 't':
break;
case 'l':
if (name[0] == '\0' ||
rc = 2;
goto exit;
}
break;
case 'u':
rc = 2;
goto exit;
}
break;
case 'a':
}
rc = 0;
exit:
}