Split the macros to_leXX() into separate macros for converting *from* in-memory
little endian *to* the correct in-CPU value, and for converting *from* a correct
in-CPU value *to* in-memory little-endian. In reality these macros are defined
the same, but it makes sense to distinguish the cases (as is done in other
projects such as the Linux kernel).
By the way, wimlib still has NOT actually been tested on big-endian systems.
static inline void flush_bits(struct output_bitstream *ostream)
{
static inline void flush_bits(struct output_bitstream *ostream)
{
- *(u16*)ostream->bit_output = to_le16(ostream->bitbuf);
+ *(u16*)ostream->bit_output = cpu_to_le16(ostream->bitbuf);
ostream->bit_output = ostream->next_bit_output;
ostream->next_bit_output = ostream->output;
ostream->output += 2;
ostream->bit_output = ostream->next_bit_output;
ostream->next_bit_output = ostream->output;
ostream->output += 2;
}
static inline int bitstream_put_two_bytes(struct output_bitstream *ostream,
}
static inline int bitstream_put_two_bytes(struct output_bitstream *ostream,
{
if (ostream->num_bytes_remaining < 2)
return 1;
{
if (ostream->num_bytes_remaining < 2)
return 1;
- *(u16*)ostream->output = to_le16(n);
+ *(u16*)ostream->output = cpu_to_le16(n);
ostream->output += 2;
ostream->num_bytes_remaining -= 2;
return 0;
ostream->output += 2;
ostream->num_bytes_remaining -= 2;
return 0;
uint shift = sizeof(input_bitbuf_t) * 8 - 16 -
istream->bitsleft;
uint shift = sizeof(input_bitbuf_t) * 8 - 16 -
istream->bitsleft;
- istream->bitbuf |= (input_bitbuf_t)to_le16(
+ istream->bitbuf |= (input_bitbuf_t)le16_to_cpu(
*(u16*)istream->data) << shift;
istream->data += 2;
istream->bitsleft += 16;
*(u16*)istream->data) << shift;
istream->data += 2;
istream->bitsleft += 16;
#include "config.h"
#include <inttypes.h>
#include "config.h"
#include <inttypes.h>
+/* Watch out for conflicts with ntfs-3g headers... */
#ifndef bswap16
static inline uint16_t bswap16(uint16_t n)
{
return (n << 8) | (n >> 8);
}
#ifndef bswap16
static inline uint16_t bswap16(uint16_t n)
{
return (n << 8) | (n >> 8);
}
+#endif /* ifndef bswap16 */
#ifndef bswap32
static inline uint32_t bswap32(uint32_t n)
#ifndef bswap32
static inline uint32_t bswap32(uint32_t n)
+#endif /* ifndef bswap32 */
#ifndef bswap64
static inline uint64_t bswap64(uint64_t n)
#ifndef bswap64
static inline uint64_t bswap64(uint64_t n)
((n & 0xff000000000000) >> 40) | (n >> 56);
#endif
}
((n & 0xff000000000000) >> 40) | (n >> 56);
#endif
}
+#endif /* ifndef bswap64 */
-/* Not in place */
-#define to_le16(n) bswap16(n)
-#define to_le32(n) bswap32(n)
-#define to_le64(n) bswap64(n)
-#define le16_to_cpu(n) bswap16(n)
-#define le32_to_cpu(n) bswap32(n)
-#define le64_to_cpu(n) bswap64(n)
+# ifdef WORDS_BIGENDIAN
+# define le16_to_cpu(n) bswap16(n)
+# define le32_to_cpu(n) bswap32(n)
+# define le64_to_cpu(n) bswap64(n)
+# define cpu_to_le16(n) bswap16(n)
+# define cpu_to_le32(n) bswap32(n)
+# define cpu_to_le64(n) bswap64(n)
+# else
+# define cpu_to_le16(n) (n)
+# define cpu_to_le32(n) (n)
+# define cpu_to_le64(n) (n)
+# define le16_to_cpu(n) (n)
+# define le32_to_cpu(n) (n)
+# define le64_to_cpu(n) (n)
+# endif
-/* In place */
-#define TO_LE16(n) ((n) = to_le16(n))
-#define TO_LE32(n) ((n) = to_le32(n))
-#define TO_LE64(n) ((n) = to_le64(n))
-
-static inline void array_to_le16(uint16_t *p, uint64_t n)
+static inline void array_cpu_to_le32(uint32_t *p, uint64_t n)
+ *p++ = cpu_to_le32(*p);
-static inline void array_to_le32(uint32_t *p, uint64_t n)
+
+static inline void array_le32_to_cpu(uint32_t *p, uint64_t n)
+ *p++ = le32_to_cpu(*p);
-static inline void array_to_le64(uint64_t *p, uint64_t n)
+
+static inline void array_cpu_to_le64(uint64_t *p, uint64_t n)
+ *p++ = cpu_to_le64(*p);
-#else
-
-/* Little endian. */
-
-/* Not in place */
-#define to_le16(n) (n)
-#define to_le32(n) (n)
-#define to_le64(n) (n)
-
-#ifndef _NTFS_ENDIANS_H
-#define le16_to_cpu(n) (n)
-#define le32_to_cpu(n) (n)
-#define le64_to_cpu(n) (n)
-#endif
-
-/* In place */
-#define TO_LE16(n)
-#define TO_LE32(n)
-#define TO_LE64(n)
-
-#define array_to_le16(p, n)
-#define array_to_le32(p, n)
-#define array_to_le64(p, n)
-
-#endif
-
+static inline void array_le64_to_cpu(uint64_t *p, uint64_t n)
+{
+ while (n--)
+ *p++ = le64_to_cpu(*p);
+}
#endif /* _WIMLIB_ENDIANNESS_H */
#endif /* _WIMLIB_ENDIANNESS_H */
if (bytes_read != sizeof(u32))
goto err;
if (bytes_read != sizeof(u32))
goto err;
+ hdr_size = le32_to_cpu(hdr_size);
static inline const u8 *get_u16(const u8 *p, u16 *res)
{
static inline const u8 *get_u16(const u8 *p, u16 *res)
{
- *res = to_le16(*(u16*)p);
+ *res = le16_to_cpu(*(u16*)p);
static inline const u8 *get_u32(const u8 *p, u32 *res)
{
static inline const u8 *get_u32(const u8 *p, u32 *res)
{
- *res = to_le32(*(u32*)p);
+ *res = le32_to_cpu(*(u32*)p);
return p + 4;
}
static inline const u8 *get_u56(const u8 *p, u64 *res)
{
return p + 4;
}
static inline const u8 *get_u56(const u8 *p, u64 *res)
{
- *res = to_le64(*(u64*)p) & 0x00ffffffffffffff;
+ *res = le64_to_cpu(*(u64*)p) & 0x00ffffffffffffff;
return p + 7;
}
static inline const u8 *get_u64(const u8 *p, u64 *res)
{
return p + 7;
}
static inline const u8 *get_u64(const u8 *p, u64 *res)
{
- *res = to_le64(*(u64*)p);
+ *res = le64_to_cpu(*(u64*)p);
static inline u8 *put_u16(u8 *res, u16 val)
{
static inline u8 *put_u16(u8 *res, u16 val)
{
- *(uint16_t*)res = to_le16(val);
+ *(uint16_t*)res = cpu_to_le16(val);
return res + 2;
}
static inline u8 *put_u32(u8 *res, u32 val)
{
return res + 2;
}
static inline u8 *put_u32(u8 *res, u32 val)
{
- *(uint32_t*)res = to_le32(val);
+ *(uint32_t*)res = cpu_to_le32(val);
static inline u8 *put_u64(u8 *res, u64 val)
{
static inline u8 *put_u64(u8 *res, u64 val)
{
- *(u64*)res = to_le64(val);
+ *(u64*)res = cpu_to_le64(val);
- rel_offset = to_le32(*(int32_t*)(uncompressed_data + i + 1));
+ rel_offset = le32_to_cpu(*(int32_t*)(uncompressed_data + i + 1));
if (rel_offset >= -i && rel_offset < file_size) {
if (rel_offset < file_size - i) {
if (rel_offset >= -i && rel_offset < file_size) {
if (rel_offset < file_size - i) {
/* "compensating translation" */
abs_offset = rel_offset - file_size;
}
/* "compensating translation" */
abs_offset = rel_offset - file_size;
}
- *(int32_t*)(uncompressed_data + i + 1) = to_le32(abs_offset);
+ *(int32_t*)(uncompressed_data + i + 1) = cpu_to_le32(abs_offset);
ret = bitstream_read_bits(istream, 16, &block_size);
if (ret != 0)
return ret;
ret = bitstream_read_bits(istream, 16, &block_size);
if (ret != 0)
return ret;
- block_size = to_le16(block_size);
+ block_size = le16_to_cpu(block_size);
ret = bitstream_read_bytes(istream, sizeof(R), R);
if (ret != 0)
return ret;
ret = bitstream_read_bytes(istream, sizeof(R), R);
if (ret != 0)
return ret;
- array_to_le32(R, ARRAY_LEN(R));
- queue->R0 = R[0];
- queue->R1 = R[1];
- queue->R2 = R[2];
+ queue->R0 = le32_to_cpu(R[0]);
+ queue->R1 = le32_to_cpu(R[1]);
+ queue->R2 = le32_to_cpu(R[2]);
break;
default:
LZX_DEBUG("Found invalid block.");
break;
default:
LZX_DEBUG("Found invalid block.");
- abs_offset = to_le32(*(int32_t*)(uncompressed_data + i + 1));
+ abs_offset = le32_to_cpu(*(int32_t*)(uncompressed_data + i + 1));
if (abs_offset >= -i && abs_offset < file_size) {
if (abs_offset >= 0) {
if (abs_offset >= -i && abs_offset < file_size) {
if (abs_offset >= 0) {
rel_offset = abs_offset + file_size;
}
*(int32_t*)(uncompressed_data + i + 1) =
rel_offset = abs_offset + file_size;
}
*(int32_t*)(uncompressed_data + i + 1) =
+ cpu_to_le32(rel_offset);
if (chunk_entry_size == 4) {
u32 *entries = (u32*)chunk_tab_buf;
while (num_needed_chunk_entries--)
if (chunk_entry_size == 4) {
u32 *entries = (u32*)chunk_tab_buf;
while (num_needed_chunk_entries--)
- *chunk_tab_p++ = to_le32(*entries++);
+ *chunk_tab_p++ = le32_to_cpu(*entries++);
} else {
u64 *entries = (u64*)chunk_tab_buf;
while (num_needed_chunk_entries--)
} else {
u64 *entries = (u64*)chunk_tab_buf;
while (num_needed_chunk_entries--)
- *chunk_tab_p++ = to_le64(*entries++);
+ *chunk_tab_p++ = le64_to_cpu(*entries++);
}
/* Done with the chunk table now. We must now seek to the first chunk
}
/* Done with the chunk table now. We must now seek to the first chunk
}
if (chunk_tab->bytes_per_chunk_entry == 8) {
}
if (chunk_tab->bytes_per_chunk_entry == 8) {
- array_to_le64(chunk_tab->offsets, chunk_tab->num_chunks);
+ array_cpu_to_le64(chunk_tab->offsets, chunk_tab->num_chunks);
} else {
for (u64 i = 0; i < chunk_tab->num_chunks; i++)
((u32*)chunk_tab->offsets)[i] =
} else {
for (u64 i = 0; i < chunk_tab->num_chunks; i++)
((u32*)chunk_tab->offsets)[i] =
- to_le32(chunk_tab->offsets[i]);
+ cpu_to_le32(chunk_tab->offsets[i]);
}
bytes_written = fwrite((u8*)chunk_tab->offsets +
chunk_tab->bytes_per_chunk_entry,
}
bytes_written = fwrite((u8*)chunk_tab->offsets +
chunk_tab->bytes_per_chunk_entry,
SecurityDescriptor *sd = (SecurityDescriptor*)descr;
u32 sacl_offset = le32_to_cpu(sd->sacl_offset);
if (sacl_offset == *size_p - sizeof(ACL)) {
SecurityDescriptor *sd = (SecurityDescriptor*)descr;
u32 sacl_offset = le32_to_cpu(sd->sacl_offset);
if (sacl_offset == *size_p - sizeof(ACL)) {
- sd->sacl_offset = to_le32(0);
+ sd->sacl_offset = cpu_to_le32(0);
*size_p -= sizeof(ACL);
}
}
*size_p -= sizeof(ACL);
}
}
/* Copy the sizes array in from the file data. */
p = get_bytes(p, sizes_size, sd->sizes);
/* Copy the sizes array in from the file data. */
p = get_bytes(p, sizes_size, sd->sizes);
- array_to_le64(sd->sizes, sd->num_entries);
+ array_le64_to_cpu(sd->sizes, sd->num_entries);
/* Allocate the array of pointers to descriptors, and read them in. */
sd->descriptors = CALLOC(sd->num_entries, sizeof(u8*));
/* Allocate the array of pointers to descriptors, and read them in. */
sd->descriptors = CALLOC(sd->num_entries, sizeof(u8*));
{
const ACL *acl = (const ACL*)p;
u8 revision = acl->revision;
{
const ACL *acl = (const ACL*)p;
u8 revision = acl->revision;
- u16 acl_size = to_le16(acl->acl_size);
- u16 ace_count = to_le16(acl->ace_count);
+ u16 acl_size = le16_to_cpu(acl->acl_size);
+ u16 ace_count = le16_to_cpu(acl->ace_count);
printf(" [%s ACL]\n", type);
printf(" Revision = %u\n", revision);
printf(" ACL Size = %u\n", acl_size);
printf(" [%s ACL]\n", type);
printf(" Revision = %u\n", revision);
printf(" ACL Size = %u\n", acl_size);
printf(" ACE flags = 0x%x\n", hdr->flags);
printf(" ACE size = %u\n", hdr->size);
const AccessAllowedACE *aaa = (const AccessAllowedACE*)hdr;
printf(" ACE flags = 0x%x\n", hdr->flags);
printf(" ACE size = %u\n", hdr->size);
const AccessAllowedACE *aaa = (const AccessAllowedACE*)hdr;
- printf(" ACE mask = %x\n", to_le32(aaa->mask));
- printf(" SID start = %u\n", to_le32(aaa->sid_start));
+ printf(" ACE mask = %x\n", le32_to_cpu(aaa->mask));
+ printf(" SID start = %u\n", le32_to_cpu(aaa->sid_start));
p += hdr->size;
}
putchar('\n');
p += hdr->size;
}
putchar('\n');
printf(" Revision = %u\n", sid->revision);
printf(" Subauthority count = %u\n", sid->sub_authority_count);
printf(" Identifier authority = ");
printf(" Revision = %u\n", sid->revision);
printf(" Subauthority count = %u\n", sid->sub_authority_count);
printf(" Identifier authority = ");
- print_byte_field(sid->identifier_authority, sizeof(sid->identifier_authority));
+ print_byte_field(sid->identifier_authority,
+ sizeof(sid->identifier_authority));
putchar('\n');
for (uint i = 0; i < sid->sub_authority_count; i++)
putchar('\n');
for (uint i = 0; i < sid->sub_authority_count; i++)
- printf(" Subauthority %u = %u\n", i, to_le32(sid->sub_authority[i]));
+ printf(" Subauthority %u = %u\n",
+ i, le32_to_cpu(sid->sub_authority[i]));
{
const SecurityDescriptor *sd = (const SecurityDescriptor*)p;
u8 revision = sd->revision;
{
const SecurityDescriptor *sd = (const SecurityDescriptor*)p;
u8 revision = sd->revision;
- u16 control = to_le16(sd->security_descriptor_control);
- u32 owner_offset = to_le32(sd->owner_offset);
- u32 group_offset = to_le32(sd->group_offset);
- u32 sacl_offset = to_le32(sd->sacl_offset);
- u32 dacl_offset = to_le32(sd->dacl_offset);
+ u16 control = le16_to_cpu(sd->security_descriptor_control);
+ u32 owner_offset = le32_to_cpu(sd->owner_offset);
+ u32 group_offset = le32_to_cpu(sd->group_offset);
+ u32 sacl_offset = le32_to_cpu(sd->sacl_offset);
+ u32 dacl_offset = le32_to_cpu(sd->dacl_offset);
printf("Revision = %u\n", revision);
printf("Security Descriptor Control = %#x\n", control);
printf("Owner offset = %u\n", owner_offset);
printf("Revision = %u\n", revision);
printf("Security Descriptor Control = %#x\n", control);
printf("Owner offset = %u\n", owner_offset);
return NULL;
/*DEBUG("utf16_len = %zu", utf16_len);*/
for (size_t i = 0; i < utf16_len / 2; i++)
return NULL;
/*DEBUG("utf16_len = %zu", utf16_len);*/
for (size_t i = 0; i < utf16_len / 2; i++)
- if (((u16*)name_utf16)[i] == to_le16('/'))
- ((u16*)name_utf16)[i] = to_le16('\\');
+ if (((u16*)name_utf16)[i] == cpu_to_le16('/'))
+ ((u16*)name_utf16)[i] = cpu_to_le16('\\');
size_t len = 12 + utf16_len * 2 + 4;
void *buf = MALLOC(len);
if (!buf)
size_t len = 12 + utf16_len * 2 + 4;
void *buf = MALLOC(len);
if (!buf)