From d83601755cc54951f73c0d55b9d0f9dac28f5f0a Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Fri, 26 Apr 2019 12:47:04 +1000 Subject: [PATCH] emory/fs: initial experiments in xattr iteration --- CMakeLists.txt | 6 +++ cruft/util | 2 +- emory/fs/acl.cpp | 0 emory/fs/acl.hpp | 13 +++++++ emory/fs/ostream.cpp | 0 emory/fs/ostream.hpp | 16 ++++++++ emory/fs/xattr.cpp | 1 + emory/fs/xattr.hpp | 51 ++++++++++++++++++++++++++ tools/stat.cpp | 87 ++------------------------------------------ 9 files changed, 91 insertions(+), 85 deletions(-) create mode 100644 emory/fs/acl.cpp create mode 100644 emory/fs/acl.hpp create mode 100644 emory/fs/ostream.cpp create mode 100644 emory/fs/ostream.hpp create mode 100644 emory/fs/xattr.cpp create mode 100644 emory/fs/xattr.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index fe378c9..2de46d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,12 @@ add_library(emory emory/chunk/params.hpp emory/chunk/region.cpp emory/chunk/region.hpp + emory/fs/acl.cpp + emory/fs/acl.hpp + emory/fs/ostream.cpp + emory/fs/ostream.hpp + emory/fs/xattr.cpp + emory/fs/xattr.hpp ) diff --git a/cruft/util b/cruft/util index 0144018..5fb87ea 160000 --- a/cruft/util +++ b/cruft/util @@ -1 +1 @@ -Subproject commit 014401899280a15b8b05312a4f91e379b875b634 +Subproject commit 5fb87ea4c4e5f30c9ee40a56e3487c0358d69783 diff --git a/emory/fs/acl.cpp b/emory/fs/acl.cpp new file mode 100644 index 0000000..e69de29 diff --git a/emory/fs/acl.hpp b/emory/fs/acl.hpp new file mode 100644 index 0000000..16b9a9f --- /dev/null +++ b/emory/fs/acl.hpp @@ -0,0 +1,13 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Copyright 2019 Danny Robson + */ + +#pragma once + +namespace emory::fs { + +} diff --git a/emory/fs/ostream.cpp b/emory/fs/ostream.cpp new file mode 100644 index 0000000..e69de29 diff --git a/emory/fs/ostream.hpp b/emory/fs/ostream.hpp new file mode 100644 index 0000000..c035b8b --- /dev/null +++ b/emory/fs/ostream.hpp @@ -0,0 +1,16 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Copyright 2019 Danny Robson + */ + +#pragma once + +#include + +#include + +namespace emory::fs { +} diff --git a/emory/fs/xattr.cpp b/emory/fs/xattr.cpp new file mode 100644 index 0000000..7ff45ec --- /dev/null +++ b/emory/fs/xattr.cpp @@ -0,0 +1 @@ +#include "xattr.hpp" \ No newline at end of file diff --git a/emory/fs/xattr.hpp b/emory/fs/xattr.hpp new file mode 100644 index 0000000..c9c3a54 --- /dev/null +++ b/emory/fs/xattr.hpp @@ -0,0 +1,51 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Copyright 2019 Danny Robson + */ + +#pragma once + +#include +#include +#include +#include +#include + +#include + +namespace emory::fs { + class xattr { + public: + xattr (cruft::posix::fd&&); + + void set (char const *name, cruft::view data); + + cruft::expected + get (char const *name, cruft::view data); + + + struct keylist { + explicit keylist (std::string &&); + + auto begin (void)& { return m_tokeniser.begin (); } + auto end (void)& { return m_tokeniser.end (); } + + auto begin (void) const& { return m_tokeniser.begin (); } + auto end (void) const& { return m_tokeniser.end (); } + + auto & data (void) & { return m_data; } + auto const& data (void) const& { return m_data; } + + std::string m_data; + cruft::tokeniser m_tokeniser; + }; + + keylist list (void); + + private: + cruft::posix::fd m_fd; + }; +} diff --git a/tools/stat.cpp b/tools/stat.cpp index 0743b30..7b7be87 100644 --- a/tools/stat.cpp +++ b/tools/stat.cpp @@ -5,6 +5,8 @@ #include #include +#include +#include #include #include @@ -17,89 +19,6 @@ #include -/////////////////////////////////////////////////////////////////////////////// -struct type_printer { - type_printer (struct stat const &_data) - : data (_data) - { ; } - - struct stat const &data; -}; - - -//----------------------------------------------------------------------------- -std::ostream& operator<< (std::ostream &os, type_printer const &val) -{ - os << "[ "; - if (val.data.st_mode & S_ISUID) os << "SUID, "; - if (val.data.st_mode & S_ISGID) os << "SGID, "; - if (val.data.st_mode & S_ISVTX) os << "STICKY, "; - - os << "{ user: " << (val.data.st_mode & S_IRUSR ? 'r' : '_') - << (val.data.st_mode & S_IWUSR ? 'w' : '_') - << (val.data.st_mode & S_IXUSR ? 'x' : '_') - << " }, " - << "{ group: " << (val.data.st_mode & S_IRGRP ? 'r' : '_') - << (val.data.st_mode & S_IWGRP ? 'w' : '_') - << (val.data.st_mode & S_IXGRP ? 'x' : '_') - << " }, " - << "{ group: " << (val.data.st_mode & S_IROTH ? 'r' : '_') - << (val.data.st_mode & S_IWOTH ? 'w' : '_') - << (val.data.st_mode & S_IXOTH ? 'x' : '_') - << " }"; - - return os; -} - - -/////////////////////////////////////////////////////////////////////////////// -struct mode_printer { - mode_printer (struct stat const &_data) - : data (_data) - { ; } - - struct stat const &data; -}; - - -//----------------------------------------------------------------------------- -std::ostream& operator<< (std::ostream &os, mode_printer const &val) -{ - return S_ISREG (val.data.st_mode) ? os << "REGULAR" - : S_ISDIR (val.data.st_mode) ? os << "DIRECTORY" - : S_ISCHR (val.data.st_mode) ? os << "CHARACTER" - : S_ISBLK (val.data.st_mode) ? os << "BLOCK" - : S_ISFIFO (val.data.st_mode) ? os << "FIFO" - : S_ISLNK (val.data.st_mode) ? os << "SYMLINK" - : S_ISSOCK (val.data.st_mode) ? os << "SOCKET" - : (throw std::invalid_argument ("Unhandled mode_t"), os << "_error"); -} - - -//----------------------------------------------------------------------------- -std::ostream& operator<< (std::ostream &os, struct stat const &val) -{ - return os << "{ dev: " << val.st_dev - << ", ino: " << val.st_ino - << ", type: " << type_printer (val) - << ", mode: " << mode_printer (val) - << ", uid: " << val.st_uid - << ", gid: " << val.st_gid - << ", size: " << val.st_size - << ", blocksize: " << val.st_blksize - << " }"; -} - - -/////////////////////////////////////////////////////////////////////////////// -static void do_stat (char const *path) -{ - struct stat buffer; - cruft::posix::error::try_call (stat, path, &buffer); - std::cout << buffer; -} - - //----------------------------------------------------------------------------- void do_xattr (char const *path) { @@ -169,7 +88,7 @@ int main (int argc, char **argv) std::cout << "{ stat: "; char const *path = argv[i]; - do_stat (path); + std::cout << cruft::posix::stat (path); do_xattr (path); do_acl (path);