diff --git a/include/ircd/fs/fd.h b/include/ircd/fs/fd.h index 1d29dfab8..15a90c26e 100644 --- a/include/ircd/fs/fd.h +++ b/include/ircd/fs/fd.h @@ -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 diff --git a/ircd/fs.cc b/ircd/fs.cc index 6591a029f..ec24da13e 100644 --- a/ircd/fs.cc +++ b/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) {