util.c revision b5e694267142042228a6cac99ecad6c4b4ef8759
/*
* volume_id - reads filesystem label and uuid
*
* Copyright (C) 2005 Kay Sievers <kay.sievers@vrfy.org>
*
* under the terms of the GNU General Public License as published by the
* Free Software Foundation version 2 of the License.
*/
#ifndef _GNU_SOURCE
#define _GNU_SOURCE 1
#endif
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include <fcntl.h>
#include "libvolume_id.h"
#include "util.h"
void volume_id_set_unicode16(char *str, size_t len, const uint8_t *buf, enum endian endianess, size_t count)
{
unsigned int i, j;
uint16_t c;
j = 0;
else
if (c == 0) {
str[j] = '\0';
break;
} else if (c < 0x80) {
if (j+1 >= len)
break;
} else if (c < 0x800) {
if (j+2 >= len)
break;
} else {
if (j+3 >= len)
break;
}
}
str[j] = '\0';
}
{
switch (usage_id) {
case VOLUME_ID_FILESYSTEM:
return "filesystem";
case VOLUME_ID_OTHER:
return "other";
case VOLUME_ID_RAID:
return "raid";
case VOLUME_ID_DISKLABEL:
return "disklabel";
case VOLUME_ID_CRYPTO:
return "crypto";
case VOLUME_ID_UNPROBED:
return "unprobed";
case VOLUME_ID_UNUSED:
return "unused";
}
return NULL;
}
{
}
{
}
{
unsigned int i;
/* remove trailing whitespace */
while (i--) {
break;
}
}
void volume_id_set_label_unicode16(struct volume_id *id, const uint8_t *buf, enum endian endianess, size_t count)
{
}
{
unsigned int i;
unsigned int count = 0;
switch(format) {
case UUID_DOS:
count = 4;
break;
case UUID_NTFS:
case UUID_HFS:
count = 8;
break;
case UUID_DCE:
count = 16;
break;
case UUID_DCE_STRING:
count = 36;
break;
}
/* if set, create string in the same format, the native platform uses */
for (i = 0; i < count; i++)
if (buf[i] != 0)
goto set;
return;
set:
switch(format) {
case UUID_DOS:
break;
case UUID_NTFS:
break;
case UUID_HFS:
break;
case UUID_DCE:
"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
break;
case UUID_DCE_STRING:
break;
}
}
{
dbg("get buffer off 0x%llx(%llu), len 0x%zx", (unsigned long long) off, (unsigned long long) off, len);
/* check if requested area fits in superblock buffer */
dbg("error malloc");
return NULL;
}
}
/* check if we need to read */
return NULL;
}
if (buf_len < 0) {
return NULL;
}
return NULL;
}
}
} else {
if (len > SEEK_BUFFER_SIZE) {
return NULL;
}
/* get seek buffer */
dbg("error malloc");
return NULL;
}
}
/* check if we need to read */
return NULL;
}
if (buf_len < 0) {
return NULL;
}
return NULL;
}
}
}
}
{
}
id->seekbuf_len = 0;
}
}