static int rand_seed_initlized = 0;
static unsigned short rand_seed[3];
+struct btrfs_config bconf;
+
const char *get_argv0_buf(void)
{
return argv0_buf;
* Split into small blocks and reuse codes.
* TODO: Reuse tree operation facilities by introducing new flags
*/
-static int make_convert_btrfs(int fd, struct btrfs_mkfs_config *cfg,
+int make_convert_btrfs(int fd, struct btrfs_mkfs_config *cfg,
struct btrfs_convert_context *cctx)
{
struct cache_tree *free = &cctx->free;
* The superblock signature is not valid, denotes a partially created
* filesystem, needs to be finalized.
*/
-int make_btrfs(int fd, struct btrfs_mkfs_config *cfg,
- struct btrfs_convert_context *cctx)
+int make_btrfs(int fd, struct btrfs_mkfs_config *cfg)
{
struct btrfs_super_block super;
struct extent_buffer *buf;
BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA);
u64 num_bytes;
- if (cctx)
- return make_convert_btrfs(fd, cfg, cctx);
buf = malloc(sizeof(*buf) + max(cfg->sectorsize, cfg->nodesize));
if (!buf)
return -ENOMEM;
*/
if (discard_range(fd, 0, 0) == 0) {
if (opflags & PREP_DEVICE_VERBOSE)
- printf("Performing full device TRIM (%s) ...\n",
- pretty_size(block_count));
+ printf("Performing full device TRIM %s (%s) ...\n",
+ file, pretty_size(block_count));
discard_blocks(fd, 0, block_count);
}
}
* Note: this function uses a static per-thread buffer. Do not call this
* function more than 10 times within one argument list!
*/
-const char *pretty_size_mode(s64 size, unsigned mode)
+const char *pretty_size_mode(u64 size, unsigned mode)
{
static __thread int ps_index = 0;
static __thread char ps_array[10][32];
static const char* unit_suffix_decimal[] =
{ "B", "kB", "MB", "GB", "TB", "PB", "EB"};
-int pretty_size_snprintf(s64 size, char *str, size_t str_size, unsigned unit_mode)
+int pretty_size_snprintf(u64 size, char *str, size_t str_size, unsigned unit_mode)
{
int num_divs;
float fraction;
- s64 base = 0;
+ u64 base = 0;
int mult = 0;
const char** suffix = NULL;
- s64 last_size;
+ u64 last_size;
+ int negative;
if (str_size == 0)
return 0;
+ negative = !!(unit_mode & UNITS_NEGATIVE);
+ unit_mode &= ~UNITS_NEGATIVE;
+
if ((unit_mode & ~UNITS_MODE_MASK) == UNITS_RAW) {
- snprintf(str, str_size, "%lld", size);
+ if (negative)
+ snprintf(str, str_size, "%lld", size);
+ else
+ snprintf(str, str_size, "%llu", size);
return 0;
}
num_divs = 0;
break;
default:
- while ((size < 0 ? -size : size) >= mult) {
- last_size = size;
- size /= mult;
- num_divs++;
+ if (negative) {
+ s64 ssize = (s64)size;
+ s64 last_ssize = ssize;
+
+ while ((ssize < 0 ? -ssize : ssize) >= mult) {
+ last_ssize = ssize;
+ ssize /= mult;
+ num_divs++;
+ }
+ last_size = (u64)last_ssize;
+ } else {
+ while (size >= mult) {
+ last_size = size;
+ size /= mult;
+ num_divs++;
+ }
}
/*
* If the value is smaller than base, we didn't do any
assert(0);
return -1;
}
- fraction = (float)last_size / base;
+
+ if (negative) {
+ fraction = (float)(s64)last_size / base;
+ } else {
+ fraction = (float)last_size / base;
+ }
return snprintf(str, str_size, "%.2f%s", fraction, suffix[num_divs]);
}
*/
return (unsigned int)(jrand48(rand_seed) % upper);
}
+
+void btrfs_config_init(void)
+{
+}