| 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 |
|
15870 |
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 |
|
31953 |
bool IsEmpty() const { return xattrs_.empty(); } |
| 41 |
|
210 |
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 |
|
32 |
XattrHeader() : version(kVersion), num_xattrs(0) { } |
| 53 |
|
16 |
explicit XattrHeader(const uint8_t num_xattrs) |
| 54 |
|
16 |
: version(kVersion), num_xattrs(num_xattrs) { } |
| 55 |
|
|
uint8_t version; |
| 56 |
|
|
uint8_t num_xattrs; |
| 57 |
|
|
}; |
| 58 |
|
|
struct XattrEntry { |
| 59 |
|
|
XattrEntry(const std::string &key, const std::string &value); |
| 60 |
|
44 |
XattrEntry() : len_key(0), len_value(0) { } |
| 61 |
|
|
uint16_t GetSize() const; |
| 62 |
|
|
std::string GetKey() const; |
| 63 |
|
|
std::string GetValue() const; |
| 64 |
|
|
uint8_t len_key; |
| 65 |
|
|
uint8_t len_value; |
| 66 |
|
|
// Concatenate the key the value. When written out or read in, data is cut |
| 67 |
|
|
// off at len_key+len_value |
| 68 |
|
|
char data[512]; |
| 69 |
|
|
}; |
| 70 |
|
|
|
| 71 |
|
|
uint8_t version_; |
| 72 |
|
|
std::map<std::string, std::string> xattrs_; |
| 73 |
|
|
}; |
| 74 |
|
|
|
| 75 |
|
|
#endif // CVMFS_XATTR_H_ |
| 76 |
|
|
|