|
@ -39,8 +39,8 @@ namespace fs |
|
|
namespace xattr |
|
|
namespace xattr |
|
|
{ |
|
|
{ |
|
|
int |
|
|
int |
|
|
list(const int fd, |
|
|
|
|
|
vector<char> &attrs) |
|
|
|
|
|
|
|
|
list(const int fd_, |
|
|
|
|
|
vector<char> *attrs_) |
|
|
{ |
|
|
{ |
|
|
ssize_t rv; |
|
|
ssize_t rv; |
|
|
|
|
|
|
|
@ -48,21 +48,21 @@ namespace fs |
|
|
errno = ERANGE; |
|
|
errno = ERANGE; |
|
|
while((rv == -1) && (errno == ERANGE)) |
|
|
while((rv == -1) && (errno == ERANGE)) |
|
|
{ |
|
|
{ |
|
|
rv = fs::flistxattr(fd,NULL,0); |
|
|
|
|
|
|
|
|
rv = fs::flistxattr(fd_,NULL,0); |
|
|
if(rv <= 0) |
|
|
if(rv <= 0) |
|
|
return rv; |
|
|
return rv; |
|
|
|
|
|
|
|
|
attrs.resize(rv); |
|
|
|
|
|
|
|
|
attrs_->resize(rv); |
|
|
|
|
|
|
|
|
rv = fs::flistxattr(fd,&attrs[0],rv); |
|
|
|
|
|
|
|
|
rv = fs::flistxattr(fd_,&(*attrs_)[0],rv); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return rv; |
|
|
return rv; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int |
|
|
int |
|
|
list(const string &path, |
|
|
|
|
|
vector<char> &attrs) |
|
|
|
|
|
|
|
|
list(const string &path_, |
|
|
|
|
|
vector<char> *attrs_) |
|
|
{ |
|
|
{ |
|
|
ssize_t rv; |
|
|
ssize_t rv; |
|
|
|
|
|
|
|
@ -70,84 +70,84 @@ namespace fs |
|
|
errno = ERANGE; |
|
|
errno = ERANGE; |
|
|
while((rv == -1) && (errno == ERANGE)) |
|
|
while((rv == -1) && (errno == ERANGE)) |
|
|
{ |
|
|
{ |
|
|
rv = fs::llistxattr(path,NULL,0); |
|
|
|
|
|
|
|
|
rv = fs::llistxattr(path_,NULL,0); |
|
|
if(rv <= 0) |
|
|
if(rv <= 0) |
|
|
return rv; |
|
|
return rv; |
|
|
|
|
|
|
|
|
attrs.resize(rv); |
|
|
|
|
|
|
|
|
attrs_->resize(rv); |
|
|
|
|
|
|
|
|
rv = fs::llistxattr(path,&attrs[0],rv); |
|
|
|
|
|
|
|
|
rv = fs::llistxattr(path_,&(*attrs_)[0],rv); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return rv; |
|
|
return rv; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int |
|
|
int |
|
|
list(const int fd, |
|
|
|
|
|
vector<string> &attrvector) |
|
|
|
|
|
|
|
|
list(const int fd_, |
|
|
|
|
|
vector<string> *attrvector_) |
|
|
{ |
|
|
{ |
|
|
int rv; |
|
|
int rv; |
|
|
vector<char> attrs; |
|
|
vector<char> attrs; |
|
|
|
|
|
|
|
|
rv = list(fd,attrs); |
|
|
|
|
|
|
|
|
rv = fs::xattr::list(fd_,&attrs); |
|
|
if(rv != -1) |
|
|
if(rv != -1) |
|
|
{ |
|
|
{ |
|
|
string tmp(attrs.begin(),attrs.end()); |
|
|
string tmp(attrs.begin(),attrs.end()); |
|
|
str::split(attrvector,tmp,'\0'); |
|
|
|
|
|
|
|
|
str::split(tmp,'\0',attrvector_); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return rv; |
|
|
return rv; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int |
|
|
int |
|
|
list(const string &path, |
|
|
|
|
|
vector<string> &attrvector) |
|
|
|
|
|
|
|
|
list(const string &path_, |
|
|
|
|
|
vector<string> *attrvector_) |
|
|
{ |
|
|
{ |
|
|
int rv; |
|
|
int rv; |
|
|
vector<char> attrs; |
|
|
vector<char> attrs; |
|
|
|
|
|
|
|
|
rv = list(path,attrs); |
|
|
|
|
|
|
|
|
rv = fs::xattr::list(path_,&attrs); |
|
|
if(rv != -1) |
|
|
if(rv != -1) |
|
|
{ |
|
|
{ |
|
|
string tmp(attrs.begin(),attrs.end()); |
|
|
string tmp(attrs.begin(),attrs.end()); |
|
|
str::split(attrvector,tmp,'\0'); |
|
|
|
|
|
|
|
|
str::split(tmp,'\0',attrvector_); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return rv; |
|
|
return rv; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int |
|
|
int |
|
|
list(const int fd, |
|
|
|
|
|
string &attrstr) |
|
|
|
|
|
|
|
|
list(const int fd_, |
|
|
|
|
|
string *attrstr_) |
|
|
{ |
|
|
{ |
|
|
int rv; |
|
|
int rv; |
|
|
vector<char> attrs; |
|
|
vector<char> attrs; |
|
|
|
|
|
|
|
|
rv = list(fd,attrs); |
|
|
|
|
|
|
|
|
rv = fs::xattr::list(fd_,&attrs); |
|
|
if(rv != -1) |
|
|
if(rv != -1) |
|
|
attrstr = string(attrs.begin(),attrs.end()); |
|
|
|
|
|
|
|
|
*attrstr_ = string(attrs.begin(),attrs.end()); |
|
|
|
|
|
|
|
|
return rv; |
|
|
return rv; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int |
|
|
int |
|
|
list(const string &path, |
|
|
|
|
|
string &attrstr) |
|
|
|
|
|
|
|
|
list(const string &path_, |
|
|
|
|
|
string *attrstr_) |
|
|
{ |
|
|
{ |
|
|
int rv; |
|
|
int rv; |
|
|
vector<char> attrs; |
|
|
vector<char> attrs; |
|
|
|
|
|
|
|
|
rv = list(path,attrs); |
|
|
|
|
|
|
|
|
rv = fs::xattr::list(path_,&attrs); |
|
|
if(rv != -1) |
|
|
if(rv != -1) |
|
|
attrstr = string(attrs.begin(),attrs.end()); |
|
|
|
|
|
|
|
|
*attrstr_ = string(attrs.begin(),attrs.end()); |
|
|
|
|
|
|
|
|
return rv; |
|
|
return rv; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int |
|
|
int |
|
|
get(const int fd, |
|
|
|
|
|
const string &attr, |
|
|
|
|
|
vector<char> &value) |
|
|
|
|
|
|
|
|
get(const int fd_, |
|
|
|
|
|
const string &attr_, |
|
|
|
|
|
vector<char> *value_) |
|
|
{ |
|
|
{ |
|
|
ssize_t rv; |
|
|
ssize_t rv; |
|
|
|
|
|
|
|
@ -155,22 +155,22 @@ namespace fs |
|
|
errno = ERANGE; |
|
|
errno = ERANGE; |
|
|
while((rv == -1) && (errno == ERANGE)) |
|
|
while((rv == -1) && (errno == ERANGE)) |
|
|
{ |
|
|
{ |
|
|
rv = fs::fgetxattr(fd,attr,NULL,0); |
|
|
|
|
|
|
|
|
rv = fs::fgetxattr(fd_,attr_,NULL,0); |
|
|
if(rv <= 0) |
|
|
if(rv <= 0) |
|
|
return rv; |
|
|
return rv; |
|
|
|
|
|
|
|
|
value.resize(rv); |
|
|
|
|
|
|
|
|
value_->resize(rv); |
|
|
|
|
|
|
|
|
rv = fs::fgetxattr(fd,attr,&value[0],rv); |
|
|
|
|
|
|
|
|
rv = fs::fgetxattr(fd_,attr_,&(*value_)[0],rv); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return rv; |
|
|
return rv; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int |
|
|
int |
|
|
get(const string &path, |
|
|
|
|
|
const string &attr, |
|
|
|
|
|
vector<char> &value) |
|
|
|
|
|
|
|
|
get(const string &path_, |
|
|
|
|
|
const string &attr_, |
|
|
|
|
|
vector<char> *value_) |
|
|
{ |
|
|
{ |
|
|
ssize_t rv; |
|
|
ssize_t rv; |
|
|
|
|
|
|
|
@ -178,56 +178,56 @@ namespace fs |
|
|
errno = ERANGE; |
|
|
errno = ERANGE; |
|
|
while((rv == -1) && (errno == ERANGE)) |
|
|
while((rv == -1) && (errno == ERANGE)) |
|
|
{ |
|
|
{ |
|
|
rv = fs::lgetxattr(path,attr,NULL,0); |
|
|
|
|
|
|
|
|
rv = fs::lgetxattr(path_,attr_,NULL,0); |
|
|
if(rv <= 0) |
|
|
if(rv <= 0) |
|
|
return rv; |
|
|
return rv; |
|
|
|
|
|
|
|
|
value.resize(rv); |
|
|
|
|
|
|
|
|
value_->resize(rv); |
|
|
|
|
|
|
|
|
rv = fs::lgetxattr(path,attr,&value[0],rv); |
|
|
|
|
|
|
|
|
rv = fs::lgetxattr(path_,attr_,&(*value_)[0],rv); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return rv; |
|
|
return rv; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int |
|
|
int |
|
|
get(const int fd, |
|
|
|
|
|
const string &attr, |
|
|
|
|
|
string &value) |
|
|
|
|
|
|
|
|
get(const int fd_, |
|
|
|
|
|
const string &attr_, |
|
|
|
|
|
string *value_) |
|
|
{ |
|
|
{ |
|
|
int rv; |
|
|
int rv; |
|
|
vector<char> tmpvalue; |
|
|
vector<char> tmpvalue; |
|
|
|
|
|
|
|
|
rv = get(fd,attr,tmpvalue); |
|
|
|
|
|
|
|
|
rv = get(fd_,attr_,&tmpvalue); |
|
|
if(rv != -1) |
|
|
if(rv != -1) |
|
|
value = string(tmpvalue.begin(),tmpvalue.end()); |
|
|
|
|
|
|
|
|
*value_ = string(tmpvalue.begin(),tmpvalue.end()); |
|
|
|
|
|
|
|
|
return rv; |
|
|
return rv; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int |
|
|
int |
|
|
get(const string &path, |
|
|
|
|
|
const string &attr, |
|
|
|
|
|
string &value) |
|
|
|
|
|
|
|
|
get(const string &path_, |
|
|
|
|
|
const string &attr_, |
|
|
|
|
|
string *value_) |
|
|
{ |
|
|
{ |
|
|
int rv; |
|
|
int rv; |
|
|
vector<char> tmpvalue; |
|
|
vector<char> tmpvalue; |
|
|
|
|
|
|
|
|
rv = get(path,attr,tmpvalue); |
|
|
|
|
|
|
|
|
rv = fs::xattr::get(path_,attr_,&tmpvalue); |
|
|
if(rv != -1) |
|
|
if(rv != -1) |
|
|
value = string(tmpvalue.begin(),tmpvalue.end()); |
|
|
|
|
|
|
|
|
*value_ = string(tmpvalue.begin(),tmpvalue.end()); |
|
|
|
|
|
|
|
|
return rv; |
|
|
return rv; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int |
|
|
int |
|
|
get(const int fd, |
|
|
|
|
|
map<string,string> &attrs) |
|
|
|
|
|
|
|
|
get(const int fd_, |
|
|
|
|
|
map<string,string> *attrs_) |
|
|
{ |
|
|
{ |
|
|
int rv; |
|
|
int rv; |
|
|
string attrstr; |
|
|
string attrstr; |
|
|
|
|
|
|
|
|
rv = list(fd,attrstr); |
|
|
|
|
|
|
|
|
rv = fs::xattr::list(fd_,&attrstr); |
|
|
if(rv == -1) |
|
|
if(rv == -1) |
|
|
return -1; |
|
|
return -1; |
|
|
|
|
|
|
|
@ -239,9 +239,9 @@ namespace fs |
|
|
{ |
|
|
{ |
|
|
string value; |
|
|
string value; |
|
|
|
|
|
|
|
|
rv = get(fd,key,value); |
|
|
|
|
|
|
|
|
rv = fs::xattr::get(fd_,key,&value); |
|
|
if(rv != -1) |
|
|
if(rv != -1) |
|
|
attrs[key] = value; |
|
|
|
|
|
|
|
|
(*attrs_)[key] = value; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -249,13 +249,13 @@ namespace fs |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int |
|
|
int |
|
|
get(const string &path, |
|
|
|
|
|
map<string,string> &attrs) |
|
|
|
|
|
|
|
|
get(const string &path_, |
|
|
|
|
|
map<string,string> *attrs_) |
|
|
{ |
|
|
{ |
|
|
int rv; |
|
|
int rv; |
|
|
string attrstr; |
|
|
string attrstr; |
|
|
|
|
|
|
|
|
rv = list(path,attrstr); |
|
|
|
|
|
|
|
|
rv = fs::xattr::list(path_,&attrstr); |
|
|
if(rv == -1) |
|
|
if(rv == -1) |
|
|
return -1; |
|
|
return -1; |
|
|
|
|
|
|
|
@ -267,9 +267,9 @@ namespace fs |
|
|
{ |
|
|
{ |
|
|
string value; |
|
|
string value; |
|
|
|
|
|
|
|
|
rv = get(path,key,value); |
|
|
|
|
|
|
|
|
rv = fs::xattr::get(path_,key,&value); |
|
|
if(rv != -1) |
|
|
if(rv != -1) |
|
|
attrs[key] = value; |
|
|
|
|
|
|
|
|
(*attrs_)[key] = value; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -277,41 +277,41 @@ namespace fs |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int |
|
|
int |
|
|
set(const int fd, |
|
|
|
|
|
const string &key, |
|
|
|
|
|
const string &value, |
|
|
|
|
|
const int flags) |
|
|
|
|
|
|
|
|
set(const int fd_, |
|
|
|
|
|
const string &key_, |
|
|
|
|
|
const string &value_, |
|
|
|
|
|
const int flags_) |
|
|
{ |
|
|
{ |
|
|
return fs::fsetxattr(fd, |
|
|
|
|
|
key.c_str(), |
|
|
|
|
|
value.data(), |
|
|
|
|
|
value.size(), |
|
|
|
|
|
flags); |
|
|
|
|
|
|
|
|
return fs::fsetxattr(fd_, |
|
|
|
|
|
key_.c_str(), |
|
|
|
|
|
value_.data(), |
|
|
|
|
|
value_.size(), |
|
|
|
|
|
flags_); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int |
|
|
int |
|
|
set(const string &path, |
|
|
|
|
|
const string &key, |
|
|
|
|
|
const string &value, |
|
|
|
|
|
const int flags) |
|
|
|
|
|
|
|
|
set(const string &path_, |
|
|
|
|
|
const string &key_, |
|
|
|
|
|
const string &value_, |
|
|
|
|
|
const int flags_) |
|
|
{ |
|
|
{ |
|
|
return fs::lsetxattr(path, |
|
|
|
|
|
key, |
|
|
|
|
|
value.data(), |
|
|
|
|
|
value.size(), |
|
|
|
|
|
flags); |
|
|
|
|
|
|
|
|
return fs::lsetxattr(path_, |
|
|
|
|
|
key_, |
|
|
|
|
|
value_.data(), |
|
|
|
|
|
value_.size(), |
|
|
|
|
|
flags_); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int |
|
|
int |
|
|
set(const int fd, |
|
|
|
|
|
const map<string,string> &attrs) |
|
|
|
|
|
|
|
|
set(const int fd_, |
|
|
|
|
|
const map<string,string> &attrs_) |
|
|
{ |
|
|
{ |
|
|
int rv; |
|
|
int rv; |
|
|
|
|
|
|
|
|
for(map<string,string>::const_iterator |
|
|
for(map<string,string>::const_iterator |
|
|
i = attrs.begin(), ei = attrs.end(); i != ei; ++i) |
|
|
|
|
|
|
|
|
i = attrs_.begin(), ei = attrs_.end(); i != ei; ++i) |
|
|
{ |
|
|
{ |
|
|
rv = set(fd,i->first,i->second,0); |
|
|
|
|
|
|
|
|
rv = fs::xattr::set(fd_,i->first,i->second,0); |
|
|
if(rv == -1) |
|
|
if(rv == -1) |
|
|
return -1; |
|
|
return -1; |
|
|
} |
|
|
} |
|
@ -320,46 +320,46 @@ namespace fs |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int |
|
|
int |
|
|
set(const string &path, |
|
|
|
|
|
const map<string,string> &attrs) |
|
|
|
|
|
|
|
|
set(const string &path_, |
|
|
|
|
|
const map<string,string> &attrs_) |
|
|
{ |
|
|
{ |
|
|
int fd; |
|
|
int fd; |
|
|
|
|
|
|
|
|
fd = fs::open(path,O_RDONLY|O_NONBLOCK); |
|
|
|
|
|
|
|
|
fd = fs::open(path_,O_RDONLY|O_NONBLOCK); |
|
|
if(fd == -1) |
|
|
if(fd == -1) |
|
|
return -1; |
|
|
return -1; |
|
|
|
|
|
|
|
|
set(fd,attrs); |
|
|
|
|
|
|
|
|
fs::xattr::set(fd,attrs_); |
|
|
|
|
|
|
|
|
return fs::close(fd); |
|
|
return fs::close(fd); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int |
|
|
int |
|
|
copy(const int fdin, |
|
|
|
|
|
const int fdout) |
|
|
|
|
|
|
|
|
copy(const int fdin_, |
|
|
|
|
|
const int fdout_) |
|
|
{ |
|
|
{ |
|
|
int rv; |
|
|
int rv; |
|
|
map<string,string> attrs; |
|
|
map<string,string> attrs; |
|
|
|
|
|
|
|
|
rv = get(fdin,attrs); |
|
|
|
|
|
|
|
|
rv = fs::xattr::get(fdin_,&attrs); |
|
|
if(rv == -1) |
|
|
if(rv == -1) |
|
|
return -1; |
|
|
return -1; |
|
|
|
|
|
|
|
|
return set(fdout,attrs); |
|
|
|
|
|
|
|
|
return fs::xattr::set(fdout_,attrs); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int |
|
|
int |
|
|
copy(const string &from, |
|
|
|
|
|
const string &to) |
|
|
|
|
|
|
|
|
copy(const string &from_, |
|
|
|
|
|
const string &to_) |
|
|
{ |
|
|
{ |
|
|
int rv; |
|
|
int rv; |
|
|
map<string,string> attrs; |
|
|
map<string,string> attrs; |
|
|
|
|
|
|
|
|
rv = get(from,attrs); |
|
|
|
|
|
|
|
|
rv = fs::xattr::get(from_,&attrs); |
|
|
if(rv == -1) |
|
|
if(rv == -1) |
|
|
return -1; |
|
|
return -1; |
|
|
|
|
|
|
|
|
return set(to,attrs); |
|
|
|
|
|
|
|
|
return fs::xattr::set(to_,attrs); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |