Commit 4c8bf5a0 authored by Dustin L. Howett's avatar Dustin L. Howett
Browse files

rexattr

parents
#include <ftw.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/types.h>
#include <attr/xattr.h>
#include <cstdio>
#include <cstring>
#include <vector>
std::vector<char> g_xaBuffer(16384);
std::vector<char> g_xaList(2048);
int main(int argc, char **argv, char **envp) {
struct stat sb;
struct rlimit rlim;
getrlimit(RLIMIT_NOFILE, &rlim);
nftw(argv[1], [](const char* fpath, const struct stat* sb, int typeflag, struct FTW* ftwbuf) {
ssize_t lSize = -1;
do {
lSize = llistxattr(fpath, g_xaList.data(), g_xaList.capacity());
if (lSize < 0 && errno == ERANGE) {
g_xaList.reserve(g_xaList.capacity() * 2);
} else if (lSize < 0) {
perror("failed to get xa list");
return 1;
}
} while(lSize < 0);
if(lSize == 0) {
return 0;
}
llistxattr(fpath, g_xaList.data(), lSize);
fprintf(stderr, "%s\n", fpath);
const char* lbuf = g_xaList.data();
for(const char* xa = lbuf; xa < lbuf + lSize; xa += strlen(xa) + 1) {
ssize_t xaSize = -1;
do {
xaSize = lgetxattr(fpath, xa, g_xaBuffer.data(), g_xaBuffer.capacity());
if (xaSize < 0 && errno == ERANGE) {
g_xaBuffer.reserve(g_xaBuffer.capacity() * 2);
} else if(xaSize < 0) {
perror("failed to read xattr");
return 1;
}
} while(xaSize < 0);
lremovexattr(fpath, xa);
lsetxattr(fpath, xa, g_xaBuffer.data(), xaSize, XATTR_CREATE);
}
return 0;
}, rlim.rlim_max/2, FTW_PHYS | FTW_MOUNT);
return 0;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment