From 52113d01f0e9d3aedf841af0c2f6ac9c0df6aca4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Franti=C5=A1ek=20Dvo=C5=99=C3=A1k?= Date: Thu, 17 Oct 2013 21:55:30 +0200 Subject: [PATCH] Implementation of setSize() using xattrs. --- src/VfsNs.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/VfsNs.cpp b/src/VfsNs.cpp index bf15ee9..6b65abc 100644 --- a/src/VfsNs.cpp +++ b/src/VfsNs.cpp @@ -277,6 +277,7 @@ ExtendedStat VfsCatalog::extendedStat(const std::string& path, bool follow) thro } vfsUpdateStat(meta, xattrs); + meta.stat.st_size = xattrs.getU64(VFS_XATTR "size", 0); meta["pool"] = std::string("vfs"); @@ -652,19 +653,24 @@ void VfsCatalog::setOwner(const std::string& path, uid_t newUid, gid_t newGid, b void VfsCatalog::setSize(const std::string& path, size_t newSize) throw (DmException) { - ExtendedStat file; + ExtendedStat meta; + char buf[20]; if (vfsCheckPermissions(path, S_IWRITE)) vfsThrow(EACCES, "not enough permissions for '%s'", clientName.c_str()); - file = this->vfsExtendedStat(path); - if (S_ISDIR(file.stat.st_mode)) - vfsThrow(EISDIR, "'%s' is directory, can not truncate", path.c_str()); - if (getUid(this->secCtx_) != file.stat.st_uid && - checkPermissions(this->secCtx_, file.acl, file.stat, S_IWRITE) != 0) { - vfsThrow(EACCES, "not enough permissions for '%s' to truncate '%s'", clientName.c_str(), path.c_str()); + meta = this->vfsExtendedStat(path); + + if (S_ISDIR(meta.stat.st_mode)) + vfsThrow(EISDIR, "'%s' is directory, can not set size", path.c_str()); + + if (getUid(this->secCtx_) != meta.stat.st_uid && + checkPermissions(this->secCtx_, meta.acl, meta.stat, S_IWRITE) != 0) { + vfsThrow(EACCES, "not enough permissions for '%s' to set size of '%s'", clientName.c_str(), path.c_str()); } - wrapCall(truncate(getLocalPath(path).c_str(), newSize)); + + snprintf(buf, sizeof buf, "%zu", newSize); + vfsSetXattr(path, getLocalPath(path), VFS_XATTR "size", buf, 0); } -- 1.8.2.3