GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/xattr.h
Date: 2024-04-28 02:33:07
Exec Total Coverage
Lines: 9 9 100.0%
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 class XattrList {
28 public:
29 static const uint8_t kVersion;
30
31 487 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 930 bool IsEmpty() const { return xattrs_.empty(); }
41 10 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 {
52 8 XattrHeader() : version(kVersion), num_xattrs(0) { }
53 4 explicit XattrHeader(const uint8_t num_xattrs) :
54 4 version(kVersion),
55 4 num_xattrs(num_xattrs)
56 4 { }
57 uint8_t version;
58 uint8_t num_xattrs;
59 };
60 struct XattrEntry {
61 XattrEntry(const std::string &key, const std::string &value);
62 11 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_
78