mirror of
https://github.com/GerbilSoft/rom-properties.git
synced 2025-06-18 11:35:38 -04:00
[librpfile] XAttrReader_p.hpp: Use bitflags instead of bools for all the "has*" variables.
std::bitset<> would also work, but the minimum size of std::bitset<> is `unsigned long`, so it'd take up 8 bytes.
This commit is contained in:
parent
594f379fe3
commit
21cc92b9c6
@ -53,7 +53,7 @@ int XAttrReader::lastError(void) const
|
||||
bool XAttrReader::hasExt2Attributes(void) const
|
||||
{
|
||||
RP_D(const XAttrReader);
|
||||
return d->hasExt2Attributes;
|
||||
return !!(d->hasAttributes & static_cast<uint8_t>(XAttrReaderPrivate::AttrBit::Ext2Attributes));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -73,7 +73,7 @@ int XAttrReader::ext2Attributes(void) const
|
||||
bool XAttrReader::hasXfsAttributes(void) const
|
||||
{
|
||||
RP_D(const XAttrReader);
|
||||
return d->hasXfsAttributes;
|
||||
return !!(d->hasAttributes & static_cast<uint8_t>(XAttrReaderPrivate::AttrBit::XfsAttributes));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -103,7 +103,7 @@ uint32_t XAttrReader::xfsProjectId(void) const
|
||||
bool XAttrReader::hasDosAttributes(void) const
|
||||
{
|
||||
RP_D(const XAttrReader);
|
||||
return d->hasDosAttributes;
|
||||
return !!(d->hasAttributes & static_cast<uint8_t>(XAttrReaderPrivate::AttrBit::DosAttributes));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -144,7 +144,7 @@ XAttrReader::ZAlgorithm XAttrReader::zAlgorithm(void) const
|
||||
bool XAttrReader::hasZAlgorithm(void) const
|
||||
{
|
||||
RP_D(const XAttrReader);
|
||||
return d->hasZAlgorithm;
|
||||
return !!(d->hasAttributes & static_cast<uint8_t>(XAttrReaderPrivate::AttrBit::ZAlgorithm));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -155,7 +155,7 @@ bool XAttrReader::hasZAlgorithm(void) const
|
||||
bool XAttrReader::hasGenericXAttrs(void) const
|
||||
{
|
||||
RP_D(const XAttrReader);
|
||||
return d->hasGenericXAttrs;
|
||||
return !!(d->hasAttributes & static_cast<uint8_t>(XAttrReaderPrivate::AttrBit::GenericXAttrs));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -107,11 +107,14 @@ public:
|
||||
|
||||
int lastError;
|
||||
|
||||
bool hasExt2Attributes;
|
||||
bool hasXfsAttributes;
|
||||
bool hasDosAttributes;
|
||||
bool hasZAlgorithm;
|
||||
bool hasGenericXAttrs;
|
||||
enum class AttrBit : uint8_t {
|
||||
Ext2Attributes = (1U << 0),
|
||||
XfsAttributes = (1U << 1),
|
||||
DosAttributes = (1U << 2),
|
||||
ZAlgorithm = (1U << 3),
|
||||
GenericXAttrs = (1U << 4),
|
||||
};
|
||||
uint8_t hasAttributes;
|
||||
|
||||
int ext2Attributes;
|
||||
uint32_t xfsXFlags;
|
||||
|
@ -110,11 +110,7 @@ static constexpr unsigned int VALID_DOS_ATTRIBUTES_NTFS = \
|
||||
XAttrReaderPrivate::XAttrReaderPrivate(const char *filename)
|
||||
: fd(-1)
|
||||
, lastError(0)
|
||||
, hasExt2Attributes(false)
|
||||
, hasXfsAttributes(false)
|
||||
, hasDosAttributes(false)
|
||||
, hasZAlgorithm(false)
|
||||
, hasGenericXAttrs(false)
|
||||
, hasAttributes(0)
|
||||
, ext2Attributes(0)
|
||||
, xfsXFlags(0)
|
||||
, xfsProjectId(0)
|
||||
@ -207,7 +203,7 @@ int XAttrReaderPrivate::loadExt2Attrs(void)
|
||||
int ret;
|
||||
if (!ioctl(fd, FS_IOC_GETFLAGS, &ext2Attributes)) {
|
||||
// ioctl() succeeded. We have Ext2 flags.
|
||||
hasExt2Attributes = true;
|
||||
hasAttributes |= static_cast<uint8_t>(AttrBit::Ext2Attributes);
|
||||
ret = 0;
|
||||
} else {
|
||||
// No Ext2 flags on this file.
|
||||
@ -218,7 +214,7 @@ int XAttrReaderPrivate::loadExt2Attrs(void)
|
||||
}
|
||||
|
||||
ext2Attributes = 0;
|
||||
hasExt2Attributes = false;
|
||||
hasAttributes &= ~static_cast<uint8_t>(AttrBit::Ext2Attributes);
|
||||
}
|
||||
return ret;
|
||||
#else /* !__linux__ || !FS_IOC_GETFLAGS */
|
||||
@ -245,7 +241,7 @@ int XAttrReaderPrivate::loadXfsAttrs(void)
|
||||
// ioctl() succeeded. We have XFS flags.
|
||||
xfsXFlags = fsx.fsx_xflags;
|
||||
xfsProjectId = fsx.fsx_projid;
|
||||
hasXfsAttributes = true;
|
||||
hasAttributes |= static_cast<uint8_t>(AttrBit::XfsAttributes);
|
||||
ret = 0;
|
||||
} else {
|
||||
// No XFS flags on this file.
|
||||
@ -257,7 +253,7 @@ int XAttrReaderPrivate::loadXfsAttrs(void)
|
||||
|
||||
xfsXFlags = 0;
|
||||
xfsProjectId = 0;
|
||||
hasXfsAttributes = false;
|
||||
hasAttributes &= ~static_cast<uint8_t>(AttrBit::XfsAttributes);
|
||||
}
|
||||
return ret;
|
||||
#else /* !__linux__ || !FS_IOC_FSGETXATTR */
|
||||
@ -280,7 +276,7 @@ int XAttrReaderPrivate::loadDosAttrs(void)
|
||||
if (!ioctl(fd, FAT_IOCTL_GET_ATTRIBUTES, &dosAttributes)) {
|
||||
// ioctl() succeeded. We have MS-DOS attributes.
|
||||
validDosAttributes = VALID_DOS_ATTRIBUTES_FAT;
|
||||
hasDosAttributes = true;
|
||||
hasAttributes |= static_cast<uint8_t>(AttrBit::DosAttributes);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -307,7 +303,7 @@ int XAttrReaderPrivate::loadDosAttrs(void)
|
||||
if (sz == 4) {
|
||||
dosAttributes = (p.be32) ? be32_to_cpu(buf.u32) : le32_to_cpu(buf.u32);
|
||||
validDosAttributes = VALID_DOS_ATTRIBUTES_NTFS;
|
||||
hasDosAttributes = true;
|
||||
hasAttributes |= static_cast<uint8_t>(AttrBit::DosAttributes);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -327,7 +323,7 @@ int XAttrReaderPrivate::loadDosAttrs(void)
|
||||
*/
|
||||
int XAttrReaderPrivate::loadZAlgorithm(void)
|
||||
{
|
||||
hasZAlgorithm = false;
|
||||
hasAttributes &= ~static_cast<uint8_t>(AttrBit::ZAlgorithm);
|
||||
zAlgorithm = XAttrReader::ZAlgorithm::None;
|
||||
|
||||
#if defined(__linux__) && defined(HAVE_SYS_XATTR_H) && !defined(__stub_getxattr)
|
||||
@ -355,13 +351,13 @@ int XAttrReaderPrivate::loadZAlgorithm(void)
|
||||
|
||||
if (!strcmp(value, "zlib")) {
|
||||
zAlgorithm = XAttrReader::ZAlgorithm::ZLIB;
|
||||
hasZAlgorithm = true;
|
||||
hasAttributes |= static_cast<uint8_t>(AttrBit::ZAlgorithm);
|
||||
} else if (!strcmp(value, "lzo")) {
|
||||
zAlgorithm = XAttrReader::ZAlgorithm::LZO;
|
||||
hasZAlgorithm = true;
|
||||
hasAttributes |= static_cast<uint8_t>(AttrBit::ZAlgorithm);
|
||||
} else if (!strcmp(value, "zstd")) {
|
||||
zAlgorithm = XAttrReader::ZAlgorithm::ZSTD;
|
||||
hasZAlgorithm = true;
|
||||
hasAttributes |= static_cast<uint8_t>(AttrBit::ZAlgorithm);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -429,7 +425,7 @@ int XAttrReaderPrivate::loadGenericXattrs(void)
|
||||
continue;
|
||||
} else if (listlen == 0) {
|
||||
// No extended attributes.
|
||||
hasGenericXAttrs = true;
|
||||
hasAttributes |= static_cast<uint8_t>(AttrBit::GenericXAttrs);
|
||||
return 0;
|
||||
} else if (listlen == -1 && errno == ENOTSUP) {
|
||||
// Filesystem does not support extended attributes.
|
||||
@ -532,7 +528,7 @@ int XAttrReaderPrivate::loadGenericXattrs(void)
|
||||
}
|
||||
|
||||
// Extended attributes retrieved.
|
||||
hasGenericXAttrs = true;
|
||||
hasAttributes |= static_cast<uint8_t>(AttrBit::GenericXAttrs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -89,11 +89,7 @@ XAttrReaderPrivate::XAttrReaderPrivate(const char *filename)
|
||||
#endif /* _UNICODE */
|
||||
: filename(filename)
|
||||
, lastError(0)
|
||||
, hasExt2Attributes(false)
|
||||
, hasXfsAttributes(false)
|
||||
, hasDosAttributes(false)
|
||||
, hasZAlgorithm(false)
|
||||
, hasGenericXAttrs(false)
|
||||
, hasAttributes(0)
|
||||
, ext2Attributes(0)
|
||||
, xfsXFlags(0)
|
||||
, xfsProjectId(0)
|
||||
@ -127,7 +123,7 @@ int XAttrReaderPrivate::loadExt2Attrs(void)
|
||||
{
|
||||
// FIXME: WSL support?
|
||||
ext2Attributes = 0;
|
||||
hasExt2Attributes = false;
|
||||
hasAttributes &= ~static_cast<uint8_t>(AttrBit::Ext2Attributes);
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
@ -141,7 +137,7 @@ int XAttrReaderPrivate::loadXfsAttrs(void)
|
||||
// FIXME: WSL support?
|
||||
xfsXFlags = 0;
|
||||
xfsProjectId = 0;
|
||||
hasXfsAttributes = false;
|
||||
hasAttributes &= ~static_cast<uint8_t>(AttrBit::XfsAttributes);
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
@ -153,13 +149,16 @@ int XAttrReaderPrivate::loadXfsAttrs(void)
|
||||
int XAttrReaderPrivate::loadDosAttrs(void)
|
||||
{
|
||||
dosAttributes = GetFileAttributes(filename.c_str());
|
||||
hasDosAttributes = (dosAttributes != INVALID_FILE_ATTRIBUTES);
|
||||
if (!hasDosAttributes) {
|
||||
if (dosAttributes == INVALID_FILE_ATTRIBUTES) {
|
||||
// No MS-DOS attributes?
|
||||
hasAttributes &= ~static_cast<uint8_t>(AttrBit::DosAttributes);
|
||||
validDosAttributes = 0;
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
// We have DOS attributes.
|
||||
hasAttributes |= static_cast<uint8_t>(AttrBit::DosAttributes);
|
||||
|
||||
// NOTE: Assuming generic FAT attributes if unable to determine the actual file system.
|
||||
validDosAttributes = VALID_DOS_ATTRIBUTES_FAT;
|
||||
|
||||
@ -190,7 +189,9 @@ int XAttrReaderPrivate::loadDosAttrs(void)
|
||||
if (fileSystemFlags & FILE_FILE_COMPRESSION) {
|
||||
// Compression is supported.
|
||||
validDosAttributes |= FILE_ATTRIBUTE_COMPRESSED;
|
||||
if (hasZAlgorithm && zAlgorithm > XAttrReader::ZAlgorithm::None) {
|
||||
if ((hasAttributes & static_cast<uint8_t>(AttrBit::ZAlgorithm)) &&
|
||||
zAlgorithm > XAttrReader::ZAlgorithm::None)
|
||||
{
|
||||
// File is definitely compressed.
|
||||
// GetFileAttributes() will *not* set FILE_ATTRIBUTE_COMPRESSED for
|
||||
// anything other than LZNT1, so we'll set it ourselves.
|
||||
@ -218,7 +219,7 @@ int XAttrReaderPrivate::loadZAlgorithm(void)
|
||||
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
|
||||
if (!hFile || hFile == INVALID_HANDLE_VALUE) {
|
||||
// Unable to open the file...
|
||||
hasZAlgorithm = false;
|
||||
hasAttributes &= ~static_cast<uint8_t>(AttrBit::ZAlgorithm);
|
||||
zAlgorithm = XAttrReader::ZAlgorithm::None;
|
||||
return -EIO;
|
||||
}
|
||||
@ -252,7 +253,7 @@ int XAttrReaderPrivate::loadZAlgorithm(void)
|
||||
// Supported algorithm.
|
||||
zAlgorithm = static_cast<XAttrReader::ZAlgorithm>(
|
||||
static_cast<int>(XAttrReader::ZAlgorithm::XPRESS4K) + Buffer.ProviderInfo.Algorithm);
|
||||
hasZAlgorithm = true;
|
||||
hasAttributes |= static_cast<uint8_t>(AttrBit::ZAlgorithm);
|
||||
CloseHandle(hFile);
|
||||
return 0;
|
||||
}
|
||||
@ -280,19 +281,19 @@ int XAttrReaderPrivate::loadZAlgorithm(void)
|
||||
case COMPRESSION_FORMAT_NONE:
|
||||
// No compression
|
||||
zAlgorithm = XAttrReader::ZAlgorithm::None;
|
||||
hasZAlgorithm = true;
|
||||
hasAttributes |= static_cast<uint8_t>(AttrBit::ZAlgorithm);
|
||||
break;
|
||||
|
||||
case COMPRESSION_FORMAT_LZNT1:
|
||||
// LZNT1 compression
|
||||
zAlgorithm = XAttrReader::ZAlgorithm::LZNT1;
|
||||
hasZAlgorithm = true;
|
||||
hasAttributes |= static_cast<uint8_t>(AttrBit::ZAlgorithm);
|
||||
break;
|
||||
|
||||
default:
|
||||
// Unsupported?
|
||||
zAlgorithm = XAttrReader::ZAlgorithm::None;
|
||||
hasZAlgorithm = false;
|
||||
hasAttributes &= ~static_cast<uint8_t>(AttrBit::ZAlgorithm);
|
||||
// TODO: Return an error code.
|
||||
break;
|
||||
}
|
||||
@ -300,7 +301,7 @@ int XAttrReaderPrivate::loadZAlgorithm(void)
|
||||
}
|
||||
|
||||
// Not supported.
|
||||
hasZAlgorithm = false;
|
||||
hasAttributes &= ~static_cast<uint8_t>(AttrBit::ZAlgorithm);
|
||||
zAlgorithm = XAttrReader::ZAlgorithm::None;
|
||||
return -ENOTSUP;
|
||||
}
|
||||
@ -438,7 +439,7 @@ int XAttrReaderPrivate::loadGenericXattrs_FindFirstStreamW(void)
|
||||
FindClose(hFindADS);
|
||||
|
||||
// Extended attributes retrieved.
|
||||
hasGenericXAttrs = true;
|
||||
hasAttributes |= static_cast<uint8_t>(AttrBit::GenericXAttrs);
|
||||
return 0;
|
||||
}
|
||||
#endif /* UNICODE */
|
||||
|
Loading…
Reference in New Issue
Block a user