Skip to content

Commit bb9cf91

Browse files
nehebjow-
authored andcommitted
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 <[email protected]>
1 parent 484903e commit bb9cf91

File tree

6 files changed

+38
-62
lines changed

6 files changed

+38
-62
lines changed

ext4_utils.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ int ext4_bg_has_super_block(int bg)
9494
/* Function to read the primary superblock */
9595
void read_sb(int fd, struct ext4_super_block *sb)
9696
{
97-
off64_t ret;
97+
off_t ret;
9898

99-
ret = lseek64(fd, 1024, SEEK_SET);
99+
ret = lseek(fd, 1024, SEEK_SET);
100100
if (ret < 0)
101101
critical_error_errno("failed to seek to superblock");
102102

@@ -110,9 +110,9 @@ void read_sb(int fd, struct ext4_super_block *sb)
110110
/* Function to write a primary or backup superblock at a given offset */
111111
void write_sb(int fd, unsigned long long offset, struct ext4_super_block *sb)
112112
{
113-
off64_t ret;
113+
off_t ret;
114114

115-
ret = lseek64(fd, offset, SEEK_SET);
115+
ret = lseek(fd, offset, SEEK_SET);
116116
if (ret < 0)
117117
critical_error_errno("failed to seek to superblock");
118118

@@ -492,18 +492,18 @@ u64 parse_num(const char *arg)
492492

493493
int read_ext(int fd, int verbose)
494494
{
495-
off64_t ret;
495+
off_t ret;
496496
struct ext4_super_block sb;
497497

498498
read_sb(fd, &sb);
499499

500500
ext4_parse_sb_info(&sb);
501501

502-
ret = lseek64(fd, info.len, SEEK_SET);
502+
ret = lseek(fd, info.len, SEEK_SET);
503503
if (ret < 0)
504504
critical_error_errno("failed to seek to end of input image");
505505

506-
ret = lseek64(fd, info.block_size * (aux_info.first_data_block + 1), SEEK_SET);
506+
ret = lseek(fd, info.block_size * (aux_info.first_data_block + 1), SEEK_SET);
507507
if (ret < 0)
508508
critical_error_errno("failed to seek to block group descriptors");
509509

ext4_utils.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,6 @@ extern "C" {
4141
#include <setjmp.h>
4242
#include <stdint.h>
4343

44-
#if defined(__APPLE__) && defined(__MACH__)
45-
#define lseek64 lseek
46-
#define ftruncate64 ftruncate
47-
#define mmap64 mmap
48-
#define off64_t off_t
49-
#endif
50-
5144
#include "ext4_sb.h"
5245

5346
extern int force;

ext4fixup.c

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@
2727
#include <fcntl.h>
2828
#include <unistd.h>
2929

30-
#if defined(__APPLE__) && defined(__MACH__)
31-
#define lseek64 lseek
32-
#define off64_t off_t
33-
#endif
34-
3530
/* The inode block count for a file/directory is in units of 512 byte blocks,
3631
* _NOT_ the filesystem block size!
3732
*/
@@ -88,7 +83,7 @@ static int get_fs_fixup_state(int fd)
8883
return no_write_fixup_state;
8984
}
9085

91-
lseek64(fd, 0, SEEK_SET);
86+
lseek(fd, 0, SEEK_SET);
9287
len = read(fd, &magic, sizeof(magic));
9388
if (len != sizeof(magic)) {
9489
critical_error("cannot read fixup_state\n");
@@ -137,7 +132,7 @@ static int set_fs_fixup_state(int fd, int state)
137132
break;
138133
}
139134

140-
lseek64(fd, 0, SEEK_SET);
135+
lseek(fd, 0, SEEK_SET);
141136
len = write(fd, &magic, sizeof(magic));
142137
if (len != sizeof(magic)) {
143138
critical_error("cannot write fixup_state\n");
@@ -162,7 +157,7 @@ static int set_fs_fixup_state(int fd, int state)
162157
static int read_inode(int fd, unsigned int inum, struct ext4_inode *inode)
163158
{
164159
unsigned int bg_num, bg_offset;
165-
off64_t inode_offset;
160+
off_t inode_offset;
166161
int len;
167162

168163
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)
171166
inode_offset = ((unsigned long long)aux_info.bg_desc[bg_num].bg_inode_table * info.block_size) +
172167
(bg_offset * info.inode_size);
173168

174-
if (lseek64(fd, inode_offset, SEEK_SET) < 0) {
169+
if (lseek(fd, inode_offset, SEEK_SET) < 0) {
175170
critical_error_errno("failed to seek to inode %d\n", inum);
176171
}
177172

@@ -185,12 +180,12 @@ static int read_inode(int fd, unsigned int inum, struct ext4_inode *inode)
185180

186181
static int read_block(int fd, unsigned long long block_num, void *block)
187182
{
188-
off64_t off;
183+
off_t off;
189184
unsigned int len;
190185

191186
off = block_num * info.block_size;
192187

193-
if (lseek64(fd, off, SEEK_SET) , 0) {
188+
if (lseek(fd, off, SEEK_SET) , 0) {
194189
critical_error_errno("failed to seek to block %lld\n", block_num);
195190
}
196191

@@ -204,7 +199,7 @@ static int read_block(int fd, unsigned long long block_num, void *block)
204199

205200
static int write_block(int fd, unsigned long long block_num, void *block)
206201
{
207-
off64_t off;
202+
off_t off;
208203
unsigned int len;
209204

210205
if (no_write) {
@@ -213,7 +208,7 @@ static int write_block(int fd, unsigned long long block_num, void *block)
213208

214209
off = block_num * info.block_size;
215210

216-
if (lseek64(fd, off, SEEK_SET) < 0) {
211+
if (lseek(fd, off, SEEK_SET) < 0) {
217212
critical_error_errno("failed to seek to block %lld\n", block_num);
218213
}
219214

@@ -259,7 +254,7 @@ static void check_inode_bitmap(int fd, unsigned int bg_num)
259254
/* Update the superblock and bgdesc of the specified block group */
260255
static int update_superblocks_and_bg_desc(int fd, int state)
261256
{
262-
off64_t ret;
257+
off_t ret;
263258
struct ext4_super_block sb;
264259
unsigned int num_block_groups, total_new_inodes;
265260
unsigned int i;
@@ -323,7 +318,7 @@ static int update_superblocks_and_bg_desc(int fd, int state)
323318
&sb);
324319
}
325320

326-
ret = lseek64(fd, ((unsigned long long)i * info.blocks_per_group * info.block_size) +
321+
ret = lseek(fd, ((unsigned long long)i * info.blocks_per_group * info.block_size) +
327322
(info.block_size * (aux_info.first_data_block + 1)), SEEK_SET);
328323
if (ret < 0)
329324
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
409404
{
410405
int i, j;
411406
struct ext4_extent *extent;
412-
off64_t fs_block_num;
407+
off_t fs_block_num;
413408

414409
if (ext_hdr->eh_depth != 0) {
415410
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
421416
extent = (struct ext4_extent *)(ext_hdr + 1);
422417

423418
for (i = 0; i < ext_hdr->eh_entries; i++) {
424-
fs_block_num = ((off64_t)extent->ee_start_hi << 32) | extent->ee_start_lo;
419+
fs_block_num = ((off_t)extent->ee_start_hi << 32) | extent->ee_start_lo;
425420
for (j = 0; j < extent->ee_len; j++) {
426421
block_list[extent->ee_block+j] = fs_block_num+j;
427422
}
@@ -436,7 +431,7 @@ static int get_extent_idx(int fd, struct ext4_extent_header *ext_hdr, unsigned l
436431
int i;
437432
struct ext4_extent_idx *extent_idx;
438433
struct ext4_extent_header *tmp_ext_hdr;
439-
off64_t fs_block_num;
434+
off_t fs_block_num;
440435
unsigned char block[MAX_EXT4_BLOCK_SIZE];
441436

442437
/* Sanity check */
@@ -450,7 +445,7 @@ static int get_extent_idx(int fd, struct ext4_extent_header *ext_hdr, unsigned l
450445
extent_idx = (struct ext4_extent_idx *)(ext_hdr + 1);
451446

452447
for (i = 0; i < ext_hdr->eh_entries; i++) {
453-
fs_block_num = ((off64_t)extent_idx->ei_leaf_hi << 32) | extent_idx->ei_leaf_lo;
448+
fs_block_num = ((off_t)extent_idx->ei_leaf_hi << 32) | extent_idx->ei_leaf_lo;
454449
read_block(fd, fs_block_num, block);
455450
tmp_ext_hdr = (struct ext4_extent_header *)block;
456451

extent.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static u8 *extent_create_backing(struct block_allocation *alloc,
5555
static void extent_create_backing_file(struct block_allocation *alloc,
5656
u64 backing_len, const char *filename)
5757
{
58-
off64_t offset = 0;
58+
off_t offset = 0;
5959
for (; alloc != NULL && backing_len > 0; get_next_region(alloc)) {
6060
u32 region_block;
6161
u32 region_len;

libsparse/output_file.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,6 @@
3535
#include "sparse_crc32.h"
3636
#include "sparse_format.h"
3737

38-
#if defined(__APPLE__) && defined(__MACH__)
39-
#define lseek64 lseek
40-
#define ftruncate64 ftruncate
41-
#define mmap64 mmap
42-
#define off64_t off_t
43-
#endif
44-
4538
#define min(a, b) \
4639
({ typeof(a) _a = (a); typeof(b) _b = (b); (_a < _b) ? _a : _b; })
4740

@@ -119,12 +112,12 @@ static int file_open(struct output_file *out, int fd)
119112

120113
static int file_skip(struct output_file *out, int64_t cnt)
121114
{
122-
off64_t ret;
115+
off_t ret;
123116
struct output_file_normal *outn = to_output_file_normal(out);
124117

125-
ret = lseek64(outn->fd, cnt, SEEK_CUR);
118+
ret = lseek(outn->fd, cnt, SEEK_CUR);
126119
if (ret < 0) {
127-
error_errno("lseek64");
120+
error_errno("lseek");
128121
return -1;
129122
}
130123
return 0;
@@ -135,7 +128,7 @@ static int file_pad(struct output_file *out, int64_t len)
135128
int ret;
136129
struct output_file_normal *outn = to_output_file_normal(out);
137130

138-
ret = ftruncate64(outn->fd, len);
131+
ret = ftruncate(outn->fd, len);
139132
if (ret < 0) {
140133
return -errno;
141134
}
@@ -191,7 +184,7 @@ static int gz_file_open(struct output_file *out, int fd)
191184

192185
static int gz_file_skip(struct output_file *out, int64_t cnt)
193186
{
194-
off64_t ret;
187+
off_t ret;
195188
struct output_file_gz *outgz = to_output_file_gz(out);
196189

197190
ret = gzseek(outgz->gz_fd, cnt, SEEK_CUR);
@@ -204,7 +197,7 @@ static int gz_file_skip(struct output_file *out, int64_t cnt)
204197

205198
static int gz_file_pad(struct output_file *out, int64_t len)
206199
{
207-
off64_t ret;
200+
off_t ret;
208201
struct output_file_gz *outgz = to_output_file_gz(out);
209202

210203
ret = gztell(outgz->gz_fd);
@@ -699,7 +692,7 @@ int write_fd_chunk(struct output_file *out, unsigned int len,
699692
aligned_diff = offset - aligned_offset;
700693
buffer_size = len + aligned_diff;
701694

702-
char *data = mmap64(NULL, buffer_size, PROT_READ, MAP_SHARED, fd,
695+
char *data = mmap(NULL, buffer_size, PROT_READ, MAP_SHARED, fd,
703696
aligned_offset);
704697
if (data == MAP_FAILED) {
705698
return -errno;

libsparse/sparse_read.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@
3535
#include "sparse_file.h"
3636
#include "sparse_format.h"
3737

38-
#if defined(__APPLE__) && defined(__MACH__)
39-
#define lseek64 lseek
40-
#define off64_t off_t
41-
#endif
42-
4338
#define SPARSE_HEADER_MAJOR_VER 1
4439
#define SPARSE_HEADER_LEN (sizeof(sparse_header_t))
4540
#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,
126121
len -= chunk;
127122
}
128123
} else {
129-
lseek64(fd, len, SEEK_CUR);
124+
lseek(fd, len, SEEK_CUR);
130125
}
131126

132127
return 0;
@@ -216,7 +211,7 @@ static int process_crc32_chunk(int fd, unsigned int chunk_size, uint32_t crc32)
216211
return 0;
217212
}
218213

219-
static int process_chunk(struct sparse_file *s, int fd, off64_t offset,
214+
static int process_chunk(struct sparse_file *s, int fd, off_t offset,
220215
unsigned int chunk_hdr_sz, chunk_header_t *chunk_header,
221216
unsigned int cur_block, uint32_t *crc_ptr)
222217
{
@@ -277,7 +272,7 @@ static int sparse_file_read_sparse(struct sparse_file *s, int fd, bool crc)
277272
uint32_t crc32 = 0;
278273
uint32_t *crc_ptr = 0;
279274
unsigned int cur_block = 0;
280-
off64_t offset;
275+
off_t offset;
281276

282277
if (!copybuf) {
283278
copybuf = malloc(COPY_BUF_SIZE);
@@ -316,7 +311,7 @@ static int sparse_file_read_sparse(struct sparse_file *s, int fd, bool crc)
316311
/* Skip the remaining bytes in a header that is longer than
317312
* we expected.
318313
*/
319-
lseek64(fd, sparse_header.file_hdr_sz - SPARSE_HEADER_LEN, SEEK_CUR);
314+
lseek(fd, sparse_header.file_hdr_sz - SPARSE_HEADER_LEN, SEEK_CUR);
320315
}
321316

322317
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)
329324
/* Skip the remaining bytes in a header that is longer than
330325
* we expected.
331326
*/
332-
lseek64(fd, sparse_header.chunk_hdr_sz - CHUNK_HEADER_LEN, SEEK_CUR);
327+
lseek(fd, sparse_header.chunk_hdr_sz - CHUNK_HEADER_LEN, SEEK_CUR);
333328
}
334329

335-
offset = lseek64(fd, 0, SEEK_CUR);
330+
offset = lseek(fd, 0, SEEK_CUR);
336331

337332
ret = process_chunk(s, fd, offset, sparse_header.chunk_hdr_sz, &chunk_header,
338333
cur_block, crc_ptr);
@@ -451,7 +446,7 @@ struct sparse_file *sparse_file_import(int fd, bool verbose, bool crc)
451446
return NULL;
452447
}
453448

454-
ret = lseek64(fd, 0, SEEK_SET);
449+
ret = lseek(fd, 0, SEEK_SET);
455450
if (ret < 0) {
456451
verbose_error(verbose, ret, "seeking");
457452
sparse_file_destroy(s);
@@ -480,12 +475,12 @@ struct sparse_file *sparse_file_import_auto(int fd, bool crc, bool verbose)
480475
return s;
481476
}
482477

483-
len = lseek64(fd, 0, SEEK_END);
478+
len = lseek(fd, 0, SEEK_END);
484479
if (len < 0) {
485480
return NULL;
486481
}
487482

488-
lseek64(fd, 0, SEEK_SET);
483+
lseek(fd, 0, SEEK_SET);
489484

490485
s = sparse_file_new(4096, len);
491486
if (!s) {

0 commit comments

Comments
 (0)