mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 10:12:39 +01:00
ircd::fs: Add a uuid-ish util for an fd.
This commit is contained in:
parent
99ed82f52d
commit
32285d5dac
2 changed files with 23 additions and 0 deletions
|
@ -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
|
||||
|
|
22
ircd/fs.cc
22
ircd/fs.cc
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue