From: Rosen Penev Date: Sat, 8 Apr 2017 17:38:12 +0000 (-0700) Subject: make_ext4fs: Remove off64_t in favor of standard off_t X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fmake_ext4fs.git;a=commitdiff_plain;h=bb9cf91795e1254584bf6a38a070646597724089;hp=484903e4332be6c317f531b008cb2a841a18c506 make_ext4fs: Remove off64_t in favor of standard off_t This fixes building against cygwin which does not define off64_t. off_t under modern versions of OS X(or macOS) defaults to 64-bit. Furthermore, _FILE_OFFSET_BITS is defined to 64-bit which eliminates the need for using off64_t directly. Also, musl just like OS X defines off_t as 64-bit in all situations. Also removed some code related to this. Signed-off by: Rosen Penev --- diff --git a/ext4_utils.c b/ext4_utils.c index 2f1dbb2..1a886d7 100644 --- a/ext4_utils.c +++ b/ext4_utils.c @@ -94,9 +94,9 @@ int ext4_bg_has_super_block(int bg) /* Function to read the primary superblock */ void read_sb(int fd, struct ext4_super_block *sb) { - off64_t ret; + off_t ret; - ret = lseek64(fd, 1024, SEEK_SET); + ret = lseek(fd, 1024, SEEK_SET); if (ret < 0) critical_error_errno("failed to seek to superblock"); @@ -110,9 +110,9 @@ void read_sb(int fd, struct ext4_super_block *sb) /* Function to write a primary or backup superblock at a given offset */ void write_sb(int fd, unsigned long long offset, struct ext4_super_block *sb) { - off64_t ret; + off_t ret; - ret = lseek64(fd, offset, SEEK_SET); + ret = lseek(fd, offset, SEEK_SET); if (ret < 0) critical_error_errno("failed to seek to superblock"); @@ -492,18 +492,18 @@ u64 parse_num(const char *arg) int read_ext(int fd, int verbose) { - off64_t ret; + off_t ret; struct ext4_super_block sb; read_sb(fd, &sb); ext4_parse_sb_info(&sb); - ret = lseek64(fd, info.len, SEEK_SET); + ret = lseek(fd, info.len, SEEK_SET); if (ret < 0) critical_error_errno("failed to seek to end of input image"); - ret = lseek64(fd, info.block_size * (aux_info.first_data_block + 1), SEEK_SET); + ret = lseek(fd, info.block_size * (aux_info.first_data_block + 1), SEEK_SET); if (ret < 0) critical_error_errno("failed to seek to block group descriptors"); diff --git a/ext4_utils.h b/ext4_utils.h index 71f1cd6..a5c1ae0 100644 --- a/ext4_utils.h +++ b/ext4_utils.h @@ -41,13 +41,6 @@ extern "C" { #include #include -#if defined(__APPLE__) && defined(__MACH__) -#define lseek64 lseek -#define ftruncate64 ftruncate -#define mmap64 mmap -#define off64_t off_t -#endif - #include "ext4_sb.h" extern int force; diff --git a/ext4fixup.c b/ext4fixup.c index c919176..f33315a 100644 --- a/ext4fixup.c +++ b/ext4fixup.c @@ -27,11 +27,6 @@ #include #include -#if defined(__APPLE__) && defined(__MACH__) -#define lseek64 lseek -#define off64_t off_t -#endif - /* The inode block count for a file/directory is in units of 512 byte blocks, * _NOT_ the filesystem block size! */ @@ -88,7 +83,7 @@ static int get_fs_fixup_state(int fd) return no_write_fixup_state; } - lseek64(fd, 0, SEEK_SET); + lseek(fd, 0, SEEK_SET); len = read(fd, &magic, sizeof(magic)); if (len != sizeof(magic)) { critical_error("cannot read fixup_state\n"); @@ -137,7 +132,7 @@ static int set_fs_fixup_state(int fd, int state) break; } - lseek64(fd, 0, SEEK_SET); + lseek(fd, 0, SEEK_SET); len = write(fd, &magic, sizeof(magic)); if (len != sizeof(magic)) { critical_error("cannot write fixup_state\n"); @@ -162,7 +157,7 @@ static int set_fs_fixup_state(int fd, int state) static int read_inode(int fd, unsigned int inum, struct ext4_inode *inode) { unsigned int bg_num, bg_offset; - off64_t inode_offset; + off_t inode_offset; int len; bg_num = (inum-1) / info.inodes_per_group; @@ -171,7 +166,7 @@ static int read_inode(int fd, unsigned int inum, struct ext4_inode *inode) inode_offset = ((unsigned long long)aux_info.bg_desc[bg_num].bg_inode_table * info.block_size) + (bg_offset * info.inode_size); - if (lseek64(fd, inode_offset, SEEK_SET) < 0) { + if (lseek(fd, inode_offset, SEEK_SET) < 0) { critical_error_errno("failed to seek to inode %d\n", inum); } @@ -185,12 +180,12 @@ static int read_inode(int fd, unsigned int inum, struct ext4_inode *inode) static int read_block(int fd, unsigned long long block_num, void *block) { - off64_t off; + off_t off; unsigned int len; off = block_num * info.block_size; - if (lseek64(fd, off, SEEK_SET) , 0) { + if (lseek(fd, off, SEEK_SET) , 0) { critical_error_errno("failed to seek to block %lld\n", block_num); } @@ -204,7 +199,7 @@ static int read_block(int fd, unsigned long long block_num, void *block) static int write_block(int fd, unsigned long long block_num, void *block) { - off64_t off; + off_t off; unsigned int len; if (no_write) { @@ -213,7 +208,7 @@ static int write_block(int fd, unsigned long long block_num, void *block) off = block_num * info.block_size; - if (lseek64(fd, off, SEEK_SET) < 0) { + if (lseek(fd, off, SEEK_SET) < 0) { critical_error_errno("failed to seek to block %lld\n", block_num); } @@ -259,7 +254,7 @@ static void check_inode_bitmap(int fd, unsigned int bg_num) /* Update the superblock and bgdesc of the specified block group */ static int update_superblocks_and_bg_desc(int fd, int state) { - off64_t ret; + off_t ret; struct ext4_super_block sb; unsigned int num_block_groups, total_new_inodes; unsigned int i; @@ -323,7 +318,7 @@ static int update_superblocks_and_bg_desc(int fd, int state) &sb); } - ret = lseek64(fd, ((unsigned long long)i * info.blocks_per_group * info.block_size) + + ret = lseek(fd, ((unsigned long long)i * info.blocks_per_group * info.block_size) + (info.block_size * (aux_info.first_data_block + 1)), SEEK_SET); if (ret < 0) critical_error_errno("failed to seek to block group descriptors"); @@ -409,7 +404,7 @@ static int get_extent_ents(struct ext4_extent_header *ext_hdr, unsigned long lon { int i, j; struct ext4_extent *extent; - off64_t fs_block_num; + off_t fs_block_num; if (ext_hdr->eh_depth != 0) { critical_error("get_extent_ents called with eh_depth != 0\n"); @@ -421,7 +416,7 @@ static int get_extent_ents(struct ext4_extent_header *ext_hdr, unsigned long lon extent = (struct ext4_extent *)(ext_hdr + 1); for (i = 0; i < ext_hdr->eh_entries; i++) { - fs_block_num = ((off64_t)extent->ee_start_hi << 32) | extent->ee_start_lo; + fs_block_num = ((off_t)extent->ee_start_hi << 32) | extent->ee_start_lo; for (j = 0; j < extent->ee_len; j++) { block_list[extent->ee_block+j] = fs_block_num+j; } @@ -436,7 +431,7 @@ static int get_extent_idx(int fd, struct ext4_extent_header *ext_hdr, unsigned l int i; struct ext4_extent_idx *extent_idx; struct ext4_extent_header *tmp_ext_hdr; - off64_t fs_block_num; + off_t fs_block_num; unsigned char block[MAX_EXT4_BLOCK_SIZE]; /* Sanity check */ @@ -450,7 +445,7 @@ static int get_extent_idx(int fd, struct ext4_extent_header *ext_hdr, unsigned l extent_idx = (struct ext4_extent_idx *)(ext_hdr + 1); for (i = 0; i < ext_hdr->eh_entries; i++) { - fs_block_num = ((off64_t)extent_idx->ei_leaf_hi << 32) | extent_idx->ei_leaf_lo; + fs_block_num = ((off_t)extent_idx->ei_leaf_hi << 32) | extent_idx->ei_leaf_lo; read_block(fd, fs_block_num, block); tmp_ext_hdr = (struct ext4_extent_header *)block; diff --git a/extent.c b/extent.c index 1900b10..7c5515e 100644 --- a/extent.c +++ b/extent.c @@ -55,7 +55,7 @@ static u8 *extent_create_backing(struct block_allocation *alloc, static void extent_create_backing_file(struct block_allocation *alloc, u64 backing_len, const char *filename) { - off64_t offset = 0; + off_t offset = 0; for (; alloc != NULL && backing_len > 0; get_next_region(alloc)) { u32 region_block; u32 region_len; diff --git a/libsparse/output_file.c b/libsparse/output_file.c index a581c45..d435b1c 100644 --- a/libsparse/output_file.c +++ b/libsparse/output_file.c @@ -35,13 +35,6 @@ #include "sparse_crc32.h" #include "sparse_format.h" -#if defined(__APPLE__) && defined(__MACH__) -#define lseek64 lseek -#define ftruncate64 ftruncate -#define mmap64 mmap -#define off64_t off_t -#endif - #define min(a, b) \ ({ typeof(a) _a = (a); typeof(b) _b = (b); (_a < _b) ? _a : _b; }) @@ -119,12 +112,12 @@ static int file_open(struct output_file *out, int fd) static int file_skip(struct output_file *out, int64_t cnt) { - off64_t ret; + off_t ret; struct output_file_normal *outn = to_output_file_normal(out); - ret = lseek64(outn->fd, cnt, SEEK_CUR); + ret = lseek(outn->fd, cnt, SEEK_CUR); if (ret < 0) { - error_errno("lseek64"); + error_errno("lseek"); return -1; } return 0; @@ -135,7 +128,7 @@ static int file_pad(struct output_file *out, int64_t len) int ret; struct output_file_normal *outn = to_output_file_normal(out); - ret = ftruncate64(outn->fd, len); + ret = ftruncate(outn->fd, len); if (ret < 0) { return -errno; } @@ -191,7 +184,7 @@ static int gz_file_open(struct output_file *out, int fd) static int gz_file_skip(struct output_file *out, int64_t cnt) { - off64_t ret; + off_t ret; struct output_file_gz *outgz = to_output_file_gz(out); ret = gzseek(outgz->gz_fd, cnt, SEEK_CUR); @@ -204,7 +197,7 @@ static int gz_file_skip(struct output_file *out, int64_t cnt) static int gz_file_pad(struct output_file *out, int64_t len) { - off64_t ret; + off_t ret; struct output_file_gz *outgz = to_output_file_gz(out); ret = gztell(outgz->gz_fd); @@ -699,7 +692,7 @@ int write_fd_chunk(struct output_file *out, unsigned int len, aligned_diff = offset - aligned_offset; buffer_size = len + aligned_diff; - char *data = mmap64(NULL, buffer_size, PROT_READ, MAP_SHARED, fd, + char *data = mmap(NULL, buffer_size, PROT_READ, MAP_SHARED, fd, aligned_offset); if (data == MAP_FAILED) { return -errno; diff --git a/libsparse/sparse_read.c b/libsparse/sparse_read.c index 641d451..dd19eb4 100644 --- a/libsparse/sparse_read.c +++ b/libsparse/sparse_read.c @@ -35,11 +35,6 @@ #include "sparse_file.h" #include "sparse_format.h" -#if defined(__APPLE__) && defined(__MACH__) -#define lseek64 lseek -#define off64_t off_t -#endif - #define SPARSE_HEADER_MAJOR_VER 1 #define SPARSE_HEADER_LEN (sizeof(sparse_header_t)) #define CHUNK_HEADER_LEN (sizeof(chunk_header_t)) @@ -126,7 +121,7 @@ static int process_raw_chunk(struct sparse_file *s, unsigned int chunk_size, len -= chunk; } } else { - lseek64(fd, len, SEEK_CUR); + lseek(fd, len, SEEK_CUR); } return 0; @@ -216,7 +211,7 @@ static int process_crc32_chunk(int fd, unsigned int chunk_size, uint32_t crc32) return 0; } -static int process_chunk(struct sparse_file *s, int fd, off64_t offset, +static int process_chunk(struct sparse_file *s, int fd, off_t offset, unsigned int chunk_hdr_sz, chunk_header_t *chunk_header, unsigned int cur_block, uint32_t *crc_ptr) { @@ -277,7 +272,7 @@ static int sparse_file_read_sparse(struct sparse_file *s, int fd, bool crc) uint32_t crc32 = 0; uint32_t *crc_ptr = 0; unsigned int cur_block = 0; - off64_t offset; + off_t offset; if (!copybuf) { copybuf = malloc(COPY_BUF_SIZE); @@ -316,7 +311,7 @@ static int sparse_file_read_sparse(struct sparse_file *s, int fd, bool crc) /* Skip the remaining bytes in a header that is longer than * we expected. */ - lseek64(fd, sparse_header.file_hdr_sz - SPARSE_HEADER_LEN, SEEK_CUR); + lseek(fd, sparse_header.file_hdr_sz - SPARSE_HEADER_LEN, SEEK_CUR); } for (i = 0; i < sparse_header.total_chunks; i++) { @@ -329,10 +324,10 @@ static int sparse_file_read_sparse(struct sparse_file *s, int fd, bool crc) /* Skip the remaining bytes in a header that is longer than * we expected. */ - lseek64(fd, sparse_header.chunk_hdr_sz - CHUNK_HEADER_LEN, SEEK_CUR); + lseek(fd, sparse_header.chunk_hdr_sz - CHUNK_HEADER_LEN, SEEK_CUR); } - offset = lseek64(fd, 0, SEEK_CUR); + offset = lseek(fd, 0, SEEK_CUR); ret = process_chunk(s, fd, offset, sparse_header.chunk_hdr_sz, &chunk_header, cur_block, crc_ptr); @@ -451,7 +446,7 @@ struct sparse_file *sparse_file_import(int fd, bool verbose, bool crc) return NULL; } - ret = lseek64(fd, 0, SEEK_SET); + ret = lseek(fd, 0, SEEK_SET); if (ret < 0) { verbose_error(verbose, ret, "seeking"); sparse_file_destroy(s); @@ -480,12 +475,12 @@ struct sparse_file *sparse_file_import_auto(int fd, bool crc, bool verbose) return s; } - len = lseek64(fd, 0, SEEK_END); + len = lseek(fd, 0, SEEK_END); if (len < 0) { return NULL; } - lseek64(fd, 0, SEEK_SET); + lseek(fd, 0, SEEK_SET); s = sparse_file_new(4096, len); if (!s) {