From: Eric Biggers Date: Fri, 17 May 2013 19:22:01 +0000 (-0500) Subject: Remove buffer_io.h X-Git-Tag: v1.4.0~22 X-Git-Url: https://wimlib.net/git/?p=wimlib;a=commitdiff_plain;h=5caa3dfded8e0f590112b59feeb3b55e4fa28420 Remove buffer_io.h --- diff --git a/include/wimlib/buffer_io.h b/include/wimlib/buffer_io.h deleted file mode 100644 index 43e497ba..00000000 --- a/include/wimlib/buffer_io.h +++ /dev/null @@ -1,133 +0,0 @@ -/* - * buffer_io.h - * - * A few endianness-aware macros for reading and writing data from in-memory - * buffers. - */ - -#ifndef _WIMLIB_BUFFER_IO_H -#define _WIMLIB_BUFFER_IO_H - -#include "wimlib/types.h" -#include "endianness.h" -#include - -/* Note that in the WIM format, integers are always in little-endian format. */ - -/* The get_u8, get_u16, get_u32, get_u56, and get_u64 functions take in a - * pointer to an input location as the first argument and a pointer to an output - * location as the second argument. The data in the input location is copied to - * the output location, with the size indicated in the function name, in little - * endian format. A pointer to the input location directly following the bytes - * read is returned. */ -static inline const void * -get_u8(const void *p, u8 *res) -{ - *res = *(const u8*)p; - return p + 1; -} - -static inline const void * -get_u16(const void *p, u16 *res) -{ - *res = le16_to_cpu(*(const u16*)p); - return p + 2; -} - - - -static inline const void * -get_u32(const void *p, u32 *res) -{ - *res = le32_to_cpu(*(const u32*)p); - return p + 4; -} - - -static inline const void * -get_u56(const void *p, u64 *res) -{ - *res = le64_to_cpu(*(const u64*)p) & 0x00ffffffffffffff; - return p + 7; -} - - -static inline const void * -get_u64(const void *p, u64 *res) -{ - *res = le64_to_cpu(*(const u64*)p); - return p + 8; -} - -/* The put_u8, put_u16, put_u32, put_u56, and put_u64 functions take in a - * pointer to an output location as the first argument and a value for the - * second argument. The value of the second argument is written to the output - * location in little-endian format as the data type indicated in the function - * name, and a pointer to the output location directory following the bytes - * written is returned. */ -static inline void * -put_u8(void *res, u8 val) -{ - *(u8*)res = val; - return res + 1; -} - -static inline void * -put_u16(void *res, u16 val) -{ - *(uint16_t*)res = cpu_to_le16(val); - return res + 2; -} - -static inline void * -put_u32(void *res, u32 val) -{ - *(uint32_t*)res = cpu_to_le32(val); - return res + 4; -} - -static inline void * -put_u56(void *res, u64 val) -{ - const u8 *__p = (const u8*)&val; -#ifdef WORDS_BIGENDIAN - res[0] = __p[6]; - res[1] = __p[5]; - res[2] = __p[4]; - res[3] = __p[3]; - res[4] = __p[2]; - res[5] = __p[1]; - res[6] = __p[0]; -#else - memcpy(res, __p, 7); -#endif - return res + 7; -} - -static inline void * -put_u64(void *res, u64 val) -{ - *(u64*)res = cpu_to_le64(val); - return res + 8; -} - -static inline const void * -get_bytes(const void *p, size_t num_bytes, void *res) -{ - memcpy(res, p, num_bytes); - return p + num_bytes; -} - -static inline void * -put_zeroes(void *p, size_t num_bytes) -{ - return memset(p, 0, num_bytes) + num_bytes; -} - -static inline void * -put_bytes(void *p, size_t num_bytes, const void *input) -{ - return memcpy(p, input, num_bytes) + num_bytes; -} - -#endif /* _WIMLIB_BUFFER_IO_H */ diff --git a/src/integrity.c b/src/integrity.c index 0af6fddd..1998f6c5 100644 --- a/src/integrity.c +++ b/src/integrity.c @@ -30,7 +30,7 @@ #endif #include "wimlib/assert.h" -#include "wimlib/buffer_io.h" +#include "wimlib/endianness.h" #include "wimlib/error.h" #include "wimlib/file_io.h" #include "wimlib/integrity.h" @@ -51,8 +51,8 @@ struct integrity_table { u32 size; u32 num_entries; u32 chunk_size; - u8 sha1sums[0][20]; -}; + u8 sha1sums[][20]; +} _packed_attribute; static int calculate_chunk_sha1(int in_fd, size_t this_chunk_size, diff --git a/src/ntfs-3g_apply.c b/src/ntfs-3g_apply.c index dde9a1db..0bf7989b 100644 --- a/src/ntfs-3g_apply.c +++ b/src/ntfs-3g_apply.c @@ -305,7 +305,7 @@ apply_file_attributes_and_security_data(ntfs_inode *ni, { int ret; struct SECURITY_CONTEXT ctx; - u32 attributes_le32; + le32 attributes; const struct wim_inode *inode; inode = dentry->d_inode; @@ -313,13 +313,13 @@ apply_file_attributes_and_security_data(ntfs_inode *ni, DEBUG("Setting NTFS file attributes on `%s' to %#"PRIx32, dentry->_full_path, inode->i_attributes); - attributes_le32 = cpu_to_le32(inode->i_attributes); + attributes = cpu_to_le32(inode->i_attributes); memset(&ctx, 0, sizeof(ctx)); ctx.vol = ni->vol; ret = ntfs_xattr_system_setxattr(&ctx, XATTR_NTFS_ATTRIB, ni, dir_ni, - (const char*)&attributes_le32, - sizeof(u32), 0); + (char*)&attributes, + sizeof(attributes), 0); if (ret) { ERROR("Failed to set NTFS file attributes on `%s'", dentry->_full_path); diff --git a/src/ntfs-3g_capture.c b/src/ntfs-3g_capture.c index 034bd1b0..d81248eb 100644 --- a/src/ntfs-3g_capture.c +++ b/src/ntfs-3g_capture.c @@ -53,10 +53,10 @@ #include /* This should be included last as it requires definitions from above not included by itself */ -#include "wimlib/buffer_io.h" #include "wimlib/capture.h" #include "wimlib/dentry.h" #include "wimlib/encoding.h" +#include "wimlib/endianness.h" #include "wimlib/error.h" #include "wimlib/lookup_table.h" #include "wimlib/ntfs_3g.h" @@ -151,7 +151,7 @@ read_reparse_tag(ntfs_inode *ni, struct ntfs_location *loc, u32 *reparse_tag_ret) { int ret; - u8 buf[8]; + le32 reparse_tag; ntfs_attr *na; na = open_ntfs_attr(ni, loc); @@ -160,12 +160,14 @@ read_reparse_tag(ntfs_inode *ni, struct ntfs_location *loc, goto out; } - if (ntfs_attr_pread(na, 0, 8, buf) != 8) { + if (ntfs_attr_pread(na, 0, sizeof(reparse_tag), + &reparse_tag) != sizeof(reparse_tag)) + { ERROR_WITH_ERRNO("Error reading reparse data"); ret = WIMLIB_ERR_NTFS_3G; goto out_close_ntfs_attr; } - *reparse_tag_ret = le32_to_cpu(*(u32*)buf); + *reparse_tag_ret = le32_to_cpu(reparse_tag); DEBUG("ReparseTag = %#x", *reparse_tag_ret); ret = 0; out_close_ntfs_attr: @@ -545,7 +547,7 @@ build_dentry_tree_ntfs_recursive(struct wim_dentry **root_ret, ntfs_volume *vol, struct add_image_params *params) { - u32 attributes; + le32 attributes; int ret; struct wim_dentry *root; struct wim_inode *inode; @@ -573,8 +575,8 @@ build_dentry_tree_ntfs_recursive(struct wim_dentry **root_ret, ctx.vol = vol; ret = ntfs_xattr_system_getxattr(&ctx, XATTR_NTFS_ATTRIB, ni, dir_ni, (char *)&attributes, - sizeof(u32)); - if (ret != 4) { + sizeof(attributes)); + if (ret != sizeof(attributes)) { ERROR_WITH_ERRNO("Failed to get NTFS attributes from `%s'", path); return WIMLIB_ERR_NTFS_3G; diff --git a/src/reparse.c b/src/reparse.c index 446b6f9f..50591097 100644 --- a/src/reparse.c +++ b/src/reparse.c @@ -45,6 +45,8 @@ #include #include +/* On-disk format of a symbolic link (WIM_IO_REPARSE_TAG_SYMLINK) or junction + * point (WIM_IO_REPARSE_TAG_MOUNT_POINT) reparse data buffer. */ struct reparse_buffer_disk { le32 rptag; le16 rpdatalen; diff --git a/src/security.c b/src/security.c index 192786df..628b9358 100644 --- a/src/security.c +++ b/src/security.c @@ -28,7 +28,7 @@ #endif #include "wimlib/assert.h" -#include "wimlib/buffer_io.h" +#include "wimlib/endianness.h" #include "wimlib/error.h" #include "wimlib/security.h" #include "wimlib/sha1.h" diff --git a/src/win32_capture.c b/src/win32_capture.c index 7f6df42e..c05eb192 100644 --- a/src/win32_capture.c +++ b/src/win32_capture.c @@ -519,7 +519,7 @@ win32_capture_try_rpfix(u8 *rpbuf, u16 *rpbuflen_p, &rpdata.substitute_name_nbytes, capture_root_ino, capture_root_dev, - le32_to_cpu(*(u32*)rpbuf)); + le32_to_cpu(*(le32*)rpbuf)); if (rp_status & RP_FIXED) { wimlib_assert(rpdata.substitute_name_nbytes % 2 == 0); utf16lechar substitute_name_copy[rpdata.substitute_name_nbytes / 2]; @@ -612,7 +612,7 @@ win32_get_reparse_data(HANDLE hFile, const wchar_t *path, } rpbuflen = bytesReturned; - reparse_tag = le32_to_cpu(*(u32*)rpbuf); + reparse_tag = le32_to_cpu(*(le32*)rpbuf); if (params->add_flags & WIMLIB_ADD_FLAG_RPFIX && (reparse_tag == WIM_IO_REPARSE_TAG_SYMLINK || reparse_tag == WIM_IO_REPARSE_TAG_MOUNT_POINT)) @@ -1061,7 +1061,7 @@ win32_build_dentry_tree_recursive(struct wim_dentry **root_ret, /* Reparse point: set the reparse data (which we read already) * */ inode->i_not_rpfixed = not_rpfixed; - inode->i_reparse_tag = le32_to_cpu(*(u32*)rpbuf); + inode->i_reparse_tag = le32_to_cpu(*(le32*)rpbuf); ret = inode_set_unnamed_stream(inode, rpbuf + 8, rpbuflen - 8, params->lookup_table); } else if (inode->i_attributes & FILE_ATTRIBUTE_DIRECTORY) {