1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-10-28 20:25:52 +03:00
lvm2/lib/display/display.c
Joe Thornber e6efb2b0bd o got dbg_malloc_t working, Alasdair could you look at the Makefile.in it
seems to be having trouble with the dependencies.

o removed some files from the lib makefile that don't compile yet.
2001-10-04 10:13:07 +00:00

95 lines
2.2 KiB
C

/*
* Copyright (C) 2001 Sistina Software
*
* This LVM library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This LVM library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this LVM library; if not, write to the Free
* Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA
*
*/
#include <sys/types.h>
#include <string.h>
#include "display.h"
#include "metadata.h"
#include "dbg_malloc.h"
#include "log.h"
#define SIZE_BUF 128
char *display_size(unsigned long long size, size_len_t sl)
{
int s;
ulong byte = 1024 * 1024 * 1024;
char *size_buf = NULL;
char *size_str[][2] = {
{"Terabyte", "TB"},
{"Gigabyte", "GB"},
{"Megabyte", "MB"},
{"Kilobyte", "KB"},
{"", ""}
};
if (!(size_buf = dbg_malloc(SIZE_BUF))) {
log_error("no memory for size display buffer");
return NULL;
}
if (size == 0LL)
sprintf(size_buf, "0");
else {
s = 0;
while (size_str[s] && size < byte)
s++, byte /= 1024;
snprintf(size_buf, SIZE_BUF - 1,
"%.2f %s", (float) size / byte, size_str[s][sl]);
}
/* Caller to deallocate */
return size_buf;
}
/*
* FIXME: this function is badly named, it doesn't display the data it
* creates a new uuid string with -'s in it. It would be better if
* the destination was passed in as well. EJT
*/
char *display_uuid(char *uuidstr) {
int i, j;
char *uuid;
if ((!uuidstr) || !(uuid = dbg_malloc(NAME_LEN))) {
log_error("no memory for uuid display buffer");
return NULL;
}
memset(uuid, 0, NAME_LEN);
i = 6;
memcpy(uuid, uuidstr, i);
uuidstr += i;
for (j = 0; j < 6; j++) {
uuid[i++] = '-';
memcpy(&uuid[i], uuidstr, 4);
uuidstr += 4;
i += 4;
}
memcpy(&uuid[i], uuidstr, 2);
/* Caller must free */
return uuid;
}