summaryrefslogtreecommitdiff
path: root/lib/backupstore/BackupClientFileAttributes.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/backupstore/BackupClientFileAttributes.cpp')
-rw-r--r--lib/backupstore/BackupClientFileAttributes.cpp100
1 files changed, 57 insertions, 43 deletions
diff --git a/lib/backupstore/BackupClientFileAttributes.cpp b/lib/backupstore/BackupClientFileAttributes.cpp
index d76432ba..37140301 100644
--- a/lib/backupstore/BackupClientFileAttributes.cpp
+++ b/lib/backupstore/BackupClientFileAttributes.cpp
@@ -55,20 +55,20 @@ BEGIN_STRUCTURE_PACKING_FOR_WIRE
typedef struct
{
int32_t AttributeType;
- u_int32_t UID;
- u_int32_t GID;
- u_int64_t ModificationTime;
- u_int64_t AttrModificationTime;
- u_int32_t UserDefinedFlags;
- u_int32_t FileGenerationNumber;
- u_int16_t Mode;
+ uint32_t UID;
+ uint32_t GID;
+ uint64_t ModificationTime;
+ uint64_t AttrModificationTime;
+ uint32_t UserDefinedFlags;
+ uint32_t FileGenerationNumber;
+ uint16_t Mode;
// Symbolic link filename may follow
// Extended attribute (xattr) information may follow, format is:
- // u_int32_t Size of extended attribute block (excluding this word)
+ // uint32_t Size of extended attribute block (excluding this word)
// For each of NumberOfAttributes (sorted by AttributeName):
- // u_int16_t AttributeNameLength
+ // uint16_t AttributeNameLength
// char AttributeName[AttributeNameLength]
- // u_int32_t AttributeValueLength
+ // uint32_t AttributeValueLength
// unsigned char AttributeValue[AttributeValueLength]
// AttributeName is 0 terminated, AttributeValue is not (and may be binary data)
} attr_StreamFormat;
@@ -117,7 +117,7 @@ namespace
BackupClientFileAttributes::BackupClientFileAttributes()
: mpClearAttributes(0)
{
- ASSERT(sizeof(u_int64_t) == sizeof(box_time_t));
+ ASSERT(sizeof(uint64_t) == sizeof(box_time_t));
}
// --------------------------------------------------------------------------
@@ -131,7 +131,7 @@ BackupClientFileAttributes::BackupClientFileAttributes()
BackupClientFileAttributes::BackupClientFileAttributes(const EMU_STRUCT_STAT &st)
: mpClearAttributes(0)
{
- ASSERT(sizeof(u_int64_t) == sizeof(box_time_t));
+ ASSERT(sizeof(uint64_t) == sizeof(box_time_t));
StreamableMemBlock *pnewAttr = new StreamableMemBlock;
FillAttributes(*pnewAttr, (const char *)NULL, st, true);
@@ -411,7 +411,7 @@ void BackupClientFileAttributes::ReadAttributes(const std::string& Filename,
// __time64_t winTime = BoxTimeToSeconds(
// pnewAttr->ModificationTime);
- u_int64_t modTime = box_ntoh64(pattr->ModificationTime);
+ uint64_t modTime = box_ntoh64(pattr->ModificationTime);
box_time_t modSecs = BoxTimeToSeconds(modTime);
__time64_t winTime = modSecs;
@@ -545,7 +545,7 @@ void BackupClientFileAttributes::FillAttributesLink(
void BackupClientFileAttributes::FillExtendedAttr(StreamableMemBlock &outputBlock,
const std::string& Filename)
{
-#ifdef HAVE_SYS_XATTR_H
+#if defined HAVE_LLISTXATTR && defined HAVE_LGETXATTR
int listBufferSize = 10000;
char* list = new char[listBufferSize];
@@ -582,30 +582,30 @@ void BackupClientFileAttributes::FillExtendedAttr(StreamableMemBlock &outputBloc
// Leave space for attr block size later
int xattrBlockSizeOffset = xattrSize;
- xattrSize += sizeof(u_int32_t);
+ xattrSize += sizeof(uint32_t);
// Loop for each attribute
for(std::vector<std::string>::const_iterator attrKeyI = attrKeys.begin(); attrKeyI!=attrKeys.end(); ++attrKeyI)
{
std::string attrKey(*attrKeyI);
- if(xattrSize+sizeof(u_int16_t)+attrKey.size()+1+sizeof(u_int32_t)>static_cast<unsigned int>(xattrBufferSize))
+ if(xattrSize+sizeof(uint16_t)+attrKey.size()+1+sizeof(uint32_t)>static_cast<unsigned int>(xattrBufferSize))
{
- xattrBufferSize = (xattrBufferSize+sizeof(u_int16_t)+attrKey.size()+1+sizeof(u_int32_t))*2;
+ xattrBufferSize = (xattrBufferSize+sizeof(uint16_t)+attrKey.size()+1+sizeof(uint32_t))*2;
outputBlock.ResizeBlock(xattrBufferSize);
buffer = static_cast<unsigned char*>(outputBlock.GetBuffer());
}
// Store length and text for attibute name
- u_int16_t keyLength = htons(attrKey.size()+1);
- std::memcpy(buffer+xattrSize, &keyLength, sizeof(u_int16_t));
- xattrSize += sizeof(u_int16_t);
+ uint16_t keyLength = htons(attrKey.size()+1);
+ std::memcpy(buffer+xattrSize, &keyLength, sizeof(uint16_t));
+ xattrSize += sizeof(uint16_t);
std::memcpy(buffer+xattrSize, attrKey.c_str(), attrKey.size()+1);
xattrSize += attrKey.size()+1;
// Leave space for value size
int valueSizeOffset = xattrSize;
- xattrSize += sizeof(u_int32_t);
+ xattrSize += sizeof(uint32_t);
// Find size of attribute (must call with buffer and length 0 on some platforms,
// as -1 is returned if the data doesn't fit.)
@@ -642,21 +642,30 @@ void BackupClientFileAttributes::FillExtendedAttr(StreamableMemBlock &outputBloc
xattrSize += valueSize;
// Fill in value size
- u_int32_t valueLength = htonl(valueSize);
- std::memcpy(buffer+valueSizeOffset, &valueLength, sizeof(u_int32_t));
+ uint32_t valueLength = htonl(valueSize);
+ std::memcpy(buffer+valueSizeOffset, &valueLength, sizeof(uint32_t));
}
// Fill in attribute block size
- u_int32_t xattrBlockLength = htonl(xattrSize-xattrBlockSizeOffset-sizeof(u_int32_t));
- std::memcpy(buffer+xattrBlockSizeOffset, &xattrBlockLength, sizeof(u_int32_t));
+ uint32_t xattrBlockLength = htonl(xattrSize-xattrBlockSizeOffset-sizeof(uint32_t));
+ std::memcpy(buffer+xattrBlockSizeOffset, &xattrBlockLength, sizeof(uint32_t));
outputBlock.ResizeBlock(xattrSize);
}
else if(listSize<0)
{
- if(errno == EOPNOTSUPP || errno == EACCES)
+ if(errno == EOPNOTSUPP || errno == EACCES
+#if HAVE_DECL_ENOTSUP
+ // NetBSD uses ENOTSUP instead
+ // https://mail-index.netbsd.org/tech-kern/2011/12/13/msg012185.html
+ || errno == ENOTSUP
+#endif
+ )
{
- // fail silently
+ // Not supported by OS, or not on this filesystem
+ BOX_TRACE(BOX_SYS_ERRNO_MESSAGE(errno,
+ BOX_FILE_MESSAGE(Filename, "Failed to "
+ "list extended attributes")));
}
else if(errno == ERANGE)
{
@@ -664,12 +673,17 @@ void BackupClientFileAttributes::FillExtendedAttr(StreamableMemBlock &outputBloc
"attributes of '" << Filename << "': "
"buffer too small, not backed up");
}
+ else if(errno == ENOENT)
+ {
+ BOX_ERROR("Failed to list extended "
+ "attributes of '" << Filename << "': "
+ "file no longer exists");
+ }
else
{
- BOX_LOG_SYS_ERROR("Failed to list extended "
- "attributes of '" << Filename << "', "
- "not backed up");
- THROW_EXCEPTION(CommonException, OSFileError);
+ THROW_SYS_FILE_ERROR("Failed to list extended "
+ "attributes for unknown reason", Filename,
+ CommonException, OSFileError);
}
}
}
@@ -679,7 +693,7 @@ void BackupClientFileAttributes::FillExtendedAttr(StreamableMemBlock &outputBloc
throw;
}
delete[] list;
-#endif
+#endif // defined HAVE_LLISTXATTR && defined HAVE_LGETXATTR
}
// --------------------------------------------------------------------------
@@ -839,7 +853,7 @@ void BackupClientFileAttributes::WriteAttributes(const std::string& Filename,
#endif
}
- if(static_cast<int>(xattrOffset+sizeof(u_int32_t))<=mpClearAttributes->GetSize())
+ if(static_cast<int>(xattrOffset+sizeof(uint32_t))<=mpClearAttributes->GetSize())
{
WriteExtendedAttr(Filename, xattrOffset);
}
@@ -978,13 +992,13 @@ void BackupClientFileAttributes::EnsureClearAvailable() const
// --------------------------------------------------------------------------
void BackupClientFileAttributes::WriteExtendedAttr(const std::string& Filename, int xattrOffset) const
{
-#ifdef HAVE_SYS_XATTR_H
+#if defined HAVE_LSETXATTR
const char* buffer = static_cast<char*>(mpClearAttributes->GetBuffer());
- u_int32_t xattrBlockLength = 0;
- std::memcpy(&xattrBlockLength, buffer+xattrOffset, sizeof(u_int32_t));
+ uint32_t xattrBlockLength = 0;
+ std::memcpy(&xattrBlockLength, buffer+xattrOffset, sizeof(uint32_t));
int xattrBlockSize = ntohl(xattrBlockLength);
- xattrOffset += sizeof(u_int32_t);
+ xattrOffset += sizeof(uint32_t);
int xattrEnd = xattrOffset+xattrBlockSize;
if(xattrEnd>mpClearAttributes->GetSize())
@@ -995,18 +1009,18 @@ void BackupClientFileAttributes::WriteExtendedAttr(const std::string& Filename,
while(xattrOffset<xattrEnd)
{
- u_int16_t keyLength = 0;
- std::memcpy(&keyLength, buffer+xattrOffset, sizeof(u_int16_t));
+ uint16_t keyLength = 0;
+ std::memcpy(&keyLength, buffer+xattrOffset, sizeof(uint16_t));
int keySize = ntohs(keyLength);
- xattrOffset += sizeof(u_int16_t);
+ xattrOffset += sizeof(uint16_t);
const char* key = buffer+xattrOffset;
xattrOffset += keySize;
- u_int32_t valueLength = 0;
- std::memcpy(&valueLength, buffer+xattrOffset, sizeof(u_int32_t));
+ uint32_t valueLength = 0;
+ std::memcpy(&valueLength, buffer+xattrOffset, sizeof(uint32_t));
int valueSize = ntohl(valueLength);
- xattrOffset += sizeof(u_int32_t);
+ xattrOffset += sizeof(uint32_t);
// FIXME: Warn on EOPNOTSUPP
if(::lsetxattr(Filename.c_str(), key, buffer+xattrOffset,