#include <stdio.h>
-int64_t unit_to_bytesize(string val, ostream *pss)
-{
- if (val.empty()) {
- if (pss)
- *pss << "value is empty!";
- return -EINVAL;
- }
-
- char c = val[val.length()-1];
- int modifier = 0;
- if (!::isdigit(c)) {
- if (val.length() < 2) {
- if (pss)
- *pss << "invalid value: " << val;
- return -EINVAL;
- }
- val = val.substr(0,val.length()-1);
- switch (c) {
- case 'B':
- break;
- case 'k':
- case 'K':
- modifier = 10;
- break;
- case 'M':
- modifier = 20;
- break;
- case 'G':
- modifier = 30;
- break;
- case 'T':
- modifier = 40;
- break;
- case 'P':
- modifier = 50;
- break;
- case 'E':
- modifier = 60;
- break;
- default:
- if (pss)
- *pss << "unrecognized modifier '" << c << "'" << std::endl;
- return -EINVAL;
- }
- }
-
- if (val[0] == '+' || val[0] == '-') {
- if (pss)
- *pss << "expected numerical value, got: " << val;
- return -EINVAL;
- }
-
- string err;
- int64_t r = strict_strtoll(val.c_str(), 10, &err);
- if ((r == 0) && !err.empty()) {
- if (pss)
- *pss << err;
- return -1;
- }
- if (r < 0) {
- if (pss)
- *pss << "unable to parse positive integer '" << val << "'";
- return -1;
- }
- return (r * (1LL << modifier));
-}
-
int get_fs_stats(ceph_data_stats_t &stats, const char *path)
{
if (!path)
#include "common/Formatter.h"
#include "include/types.h"
-int64_t unit_to_bytesize(string val, ostream *pss);
-
std::string bytes2str(uint64_t count);
struct ceph_data_stats
#include <sstream>
-TEST(util, unit_to_bytesize)
-{
- ASSERT_EQ(1234ll, unit_to_bytesize("1234", &cerr));
- ASSERT_EQ(1024ll, unit_to_bytesize("1K", &cerr));
- ASSERT_EQ(1024ll, unit_to_bytesize("1k", &cerr));
- ASSERT_EQ(1048576ll, unit_to_bytesize("1M", &cerr));
- ASSERT_EQ(1073741824ll, unit_to_bytesize("1G", &cerr));
- ASSERT_EQ(1099511627776ll, unit_to_bytesize("1T", &cerr));
- ASSERT_EQ(1125899906842624ll, unit_to_bytesize("1P", &cerr));
- ASSERT_EQ(1152921504606846976ll, unit_to_bytesize("1E", &cerr));
-
- ASSERT_EQ(65536ll, unit_to_bytesize(" 64K", &cerr));
-}
-
#if defined(__linux__)
TEST(util, collect_sys_info)
{