Mtime = stat_info.st_mtime;
Ctime = stat_info.st_atime;
+ // the stat(2) manpage for linux defines that st_blocks is given in a number of 512-byte-blocks.
+ BytesOnDisk = stat_info.st_blocks;
+ BytesOnDisk*=(long long)512;
+
IsLink= S_ISLNK( stat_info.st_mode );
IsRegular= S_ISREG( stat_info.st_mode );
IsDirectory= S_ISDIR( stat_info.st_mode );
Gid = 0;
DeviceType = 0;
Size = 0;
+ BytesOnDisk = 0;
Atime = 0;
Mtime = 0;
Ctime = 0;
#include "userfunc.hpp"
#include <set>
+// make sure we have proper large file support
+#include <features.h>
+#ifndef _GNU_SOURCE
+ #define _GNU_SOURCE
+#endif
+
namespace I2n
{
/**
time_t mtime() const { return Mtime; }
time_t ctime() const { return Ctime; }
+ // bytes used on disk, calculated from allocated blocks
+ long long bytes_on_disk() const { return BytesOnDisk; }
+
nlink_t num_hard_links() const { return NumLinks; }
dev_t device_type() const { return DeviceType; }
time_t last_modified_time() const { return Mtime; }
gid_t Gid;
dev_t DeviceType;
off_t Size;
+ long long BytesOnDisk;
time_t Atime;
time_t Mtime;
time_t Ctime;
BOOST_CHECK_EQUAL( false, stat.is_block_device() );
} // eo StatTest1
+BOOST_AUTO_TEST_CASE(StatSize)
+{
+ write_file("/tmp/test","some nice content to make sure the file system optimizations don't inline this into the inode block");
+
+ I2n::Stat stat("/tmp/test");
+
+ BOOST_CHECK_EQUAL( true, (bool)stat );
+ BOOST_CHECK_EQUAL( true, stat.is_regular_file() );
+
+ BOOST_CHECK_EQUAL( true, ( stat.bytes_on_disk() >= 512 ) );
+
+ unlink("/tmp/test");
+} // eo StatSize
+
BOOST_AUTO_TEST_CASE(StatRecheck)
{
// just to be sure