0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-02 10:08:56 +02:00

ircd::fs: Add a uuid-ish util for an fd.

This commit is contained in:
Jason Volk 2018-08-20 22:44:39 -07:00
parent 99ed82f52d
commit 32285d5dac
2 changed files with 23 additions and 0 deletions

View file

@ -16,6 +16,7 @@ namespace ircd::fs
struct fd;
size_t size(const fd &);
string_view uuid(const fd &, const mutable_buffer &);
}
/// Object for maintaining state to an open file or directory. Instances can

View file

@ -447,6 +447,28 @@ namespace ircd::fs
static uint posix_flags(const std::ios::open_mode &mode);
}
/// This is not a standard UUID of any sort; this is custom, and intended for
/// rocksdb (though rocksdb has no requirement for its format specifically).
/// The format is plain-text, fs major and minor number, inode number, and
/// a three letter file type; all obtained from fstat(2).
ircd::string_view
ircd::fs::uuid(const fd &fd,
const mutable_buffer &buf)
{
struct stat stat;
syscall(::fstat, fd, &stat);
return fmt::sprintf
{
buf, "%u-%u-%lu-%s",
major(stat.st_dev),
minor(stat.st_dev),
stat.st_ino,
S_ISREG(stat.st_mode)? "reg":
S_ISDIR(stat.st_mode)? "dir":
"???"
};
}
size_t
ircd::fs::size(const fd &fd)
{