GCC Code Coverage Report
Directory: cvmfs/ Exec Total Coverage
File: cvmfs/xattr.h Lines: 8 8 100.0 %
Date: 2019-02-03 02:48:13 Branches: 0 0 - %

Line Branch Exec Source
1
/**
2
 * This file is part of the CernVM File System.
3
 */
4
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
14
/**
15
 * Represents extended attributes that are maintained by the system or the user
16
 * and just blindly stored and returned by cvmfs.  Note that cvmfs' magic
17
 * extended attributes (e.g. user.pid) will hide the ones maintained by the user
18
 * but they are still present in the file catalogs.
19
 *
20
 * First application of the extended attributes is security.capability in order
21
 * to support POSIX file capabilities.  Cvmfs' support for custom extended
22
 * attributes is limited to 256 attributes, with names <= 256 characters and
23
 * values <= 256 bytes.  Thus there is no need for big endian/little endian
24
 * conversion.  The name must not be the empty string and must not contain the
25
 * zero character.  There are no restrictions on the content.
26
 */
27
939
class XattrList {
28
 public:
29
  static const uint8_t kVersion;
30
31
333
  XattrList() : version_(kVersion) { }
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
365
  bool IsEmpty() const { return xattrs_.empty(); }
41
42
  void Serialize(unsigned char **outbuf, unsigned *size,
43
                 const std::vector<std::string> *blacklist = NULL) const;
44
  static XattrList *Deserialize(const unsigned char *inbuf,
45
                                const unsigned size);
46
47
  uint8_t version() { return version_; }
48
49
 private:
50
  struct XattrHeader {
51
32
    XattrHeader() : version(kVersion), num_xattrs(0) { }
52
16
    explicit XattrHeader(const uint8_t num_xattrs) :
53
      version(kVersion),
54
16
      num_xattrs(num_xattrs)
55
16
    { }
56
    uint8_t version;
57
    uint8_t num_xattrs;
58
  };
59
  struct XattrEntry {
60
    XattrEntry(const std::string &key, const std::string &value);
61
44
    XattrEntry() : len_key(0), len_value(0) { }
62
    uint16_t GetSize() const;
63
    std::string GetKey() const;
64
    std::string GetValue() const;
65
    uint8_t len_key;
66
    uint8_t len_value;
67
    // Concatenate the key the value.  When written out or read in, data is cut
68
    // off at len_key+len_value
69
    char data[512];
70
  };
71
72
  uint8_t version_;
73
  std::map<std::string, std::string> xattrs_;
74
};
75
76
#endif  // CVMFS_XATTR_H_