CernVM-FS  2.10.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
xattr.h
Go to the documentation of this file.
1 
5 #ifndef CVMFS_XATTR_H_
6 #define CVMFS_XATTR_H_
7 
8 #include <inttypes.h>
9 
10 #include <map>
11 #include <string>
12 #include <vector>
13 
27 class XattrList {
28  public:
29  static const uint8_t kVersion;
30 
32  static XattrList *CreateFromFile(const std::string &path);
33 
34  std::vector<std::string> ListKeys() const;
35  std::string ListKeysPosix(const std::string &merge_with) const;
36  bool Has(const std::string &key) const;
37  bool Get(const std::string &key, std::string *value) const;
38  bool Set(const std::string &key, const std::string &value);
39  bool Remove(const std::string &key);
40  bool IsEmpty() const { return xattrs_.empty(); }
41  void Clear() { xattrs_.clear(); }
42 
43  void Serialize(unsigned char **outbuf, unsigned *size,
44  const std::vector<std::string> *blacklist = NULL) const;
45  static XattrList *Deserialize(const unsigned char *inbuf,
46  const unsigned size);
47 
48  uint8_t version() { return version_; }
49 
50  private:
51  struct XattrHeader {
53  explicit XattrHeader(const uint8_t num_xattrs) :
55  num_xattrs(num_xattrs)
56  { }
57  uint8_t version;
58  uint8_t num_xattrs;
59  };
60  struct XattrEntry {
61  XattrEntry(const std::string &key, const std::string &value);
62  XattrEntry() : len_key(0), len_value(0) { }
63  uint16_t GetSize() const;
64  std::string GetKey() const;
65  std::string GetValue() const;
66  uint8_t len_key;
67  uint8_t len_value;
68  // Concatenate the key the value. When written out or read in, data is cut
69  // off at len_key+len_value
70  char data[512];
71  };
72 
73  uint8_t version_;
74  std::map<std::string, std::string> xattrs_;
75 };
76 
77 #endif // CVMFS_XATTR_H_
std::string ListKeysPosix(const std::string &merge_with) const
Definition: xattr.cc:137
char data[512]
Definition: xattr.h:70
void Clear()
Definition: xattr.h:41
bool Set(const std::string &key, const std::string &value)
Definition: xattr.cc:160
bool IsEmpty() const
Definition: xattr.h:40
std::map< std::string, std::string > xattrs_
Definition: xattr.h:74
uint16_t GetSize() const
Definition: xattr.cc:269
bool Get(const std::string &key, std::string *value) const
Definition: xattr.cc:108
std::string GetValue() const
Definition: xattr.cc:275
void Serialize(unsigned char **outbuf, unsigned *size, const std::vector< std::string > *blacklist=NULL) const
Definition: xattr.cc:196
Definition: xattr.h:60
bool Has(const std::string &key) const
Definition: xattr.cc:103
std::string GetKey() const
Definition: xattr.cc:262
uint8_t version_
Definition: xattr.h:73
static XattrList * Deserialize(const unsigned char *inbuf, const unsigned size)
Definition: xattr.cc:67
XattrHeader(const uint8_t num_xattrs)
Definition: xattr.h:53
uint8_t len_key
Definition: xattr.h:66
static XattrList * CreateFromFile(const std::string &path)
Definition: xattr.cc:30
static const uint8_t kVersion
Definition: xattr.h:29
uint8_t num_xattrs
Definition: xattr.h:58
std::vector< std::string > ListKeys() const
Definition: xattr.cc:119
XattrEntry()
Definition: xattr.h:62
uint8_t len_value
Definition: xattr.h:67
static void size_t size
Definition: smalloc.h:47
bool Remove(const std::string &key)
Definition: xattr.cc:182
uint8_t version()
Definition: xattr.h:48
XattrList()
Definition: xattr.h:31