Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions include/wimlib/file_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@
struct filedes {
int fd;
unsigned int is_pipe : 1;
off_t offset;
Copy link

@pbatard pbatard Apr 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can avoid this whole patch by adding the following in the MSVC preprocessor definitions:

_OFF_T_DEFINED;_off_t=__int64;off_t=_off_t;_FILE_OFFSET_BITS=64;

If you do just that, then off_t will be 64-bit, even when compiling for x86.

uint64_t offset;
};

int
full_read(struct filedes *fd, void *buf, size_t n);

int
full_pread(struct filedes *fd, void *buf, size_t nbyte, off_t offset);
full_pread(struct filedes *fd, void *buf, size_t nbyte, uint64_t offset);

int
full_write(struct filedes *fd, const void *buf, size_t n);

int
full_pwrite(struct filedes *fd, const void *buf, size_t count, off_t offset);
full_pwrite(struct filedes *fd, const void *buf, size_t count, uint64_t offset);

#ifndef _WIN32
# define O_BINARY 0
#endif

off_t
filedes_seek(struct filedes *fd, off_t offset);
uint64_t
filedes_seek(struct filedes *fd, uint64_t offset);

bool
filedes_is_seekable(struct filedes *fd);
Expand Down
4 changes: 2 additions & 2 deletions include/wimlib/integrity.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ read_integrity_table(WIMStruct *wim, u64 num_checked_bytes,

int
write_integrity_table(WIMStruct *wim,
off_t new_blob_table_end,
off_t old_blob_table_end,
uint64_t new_blob_table_end,
uint64_t old_blob_table_end,
struct integrity_table *old_table);

int
Expand Down
2 changes: 1 addition & 1 deletion include/wimlib/wim.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ read_wim_header(WIMStruct *wim, struct wim_header *hdr);

int
write_wim_header(const struct wim_header *hdr, struct filedes *out_fd,
off_t offset);
uint64_t offset);

int
write_wim_header_flags(u32 hdr_flags, struct filedes *out_fd);
Expand Down
6 changes: 3 additions & 3 deletions include/wimlib/win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ int
win32_rename_replacement(const tchar *oldpath, const tchar *newpath);

int
win32_truncate_replacement(const tchar *path, off_t size);
win32_truncate_replacement(const tchar *path, uint64_t size);

int
win32_strerror_r_replacement(int errnum, tchar *buf, size_t buflen);
Expand All @@ -62,10 +62,10 @@ ssize_t
win32_write(int fd, const void *buf, size_t count);

ssize_t
win32_pread(int fd, void *buf, size_t count, off_t offset);
win32_pread(int fd, void *buf, size_t count, uint64_t offset);

ssize_t
win32_pwrite(int fd, const void *buf, size_t count, off_t offset);
win32_pwrite(int fd, const void *buf, size_t count, uint64_t offset);

#endif /* _WIN32 */

Expand Down
8 changes: 4 additions & 4 deletions programs/imagex.c
Original file line number Diff line number Diff line change
Expand Up @@ -833,14 +833,14 @@ do_metadata_not_found_warning(const tchar *wimfile,

/* Returns the size of a file given its name, or -1 if the file does not exist
* or its size cannot be determined. */
static off_t
static uint64_t
file_get_size(const tchar *filename)
{
struct _stat st;
if (tstat(filename, &st) == 0)
return st.st_size;
else
return (off_t)-1;
return (uint64_t)-1;
}

enum {
Expand Down Expand Up @@ -3788,8 +3788,8 @@ imagex_optimize(int argc, tchar **argv, int cmd)
WIMStruct *wim;
struct wimlib_wim_info info;
const tchar *wimfile;
off_t old_size;
off_t new_size;
uint64_t old_size;
uint64_t new_size;
unsigned num_threads = 0;

for_opt(c, optimize_options) {
Expand Down
8 changes: 4 additions & 4 deletions src/file_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ full_read(struct filedes *fd, void *buf, size_t count)
}

static int
pipe_read(struct filedes *fd, void *buf, size_t count, off_t offset)
pipe_read(struct filedes *fd, void *buf, size_t count, uint64_t offset)
{
int ret;

Expand Down Expand Up @@ -115,7 +115,7 @@ pipe_read(struct filedes *fd, void *buf, size_t count, off_t offset)
* WIMLIB_ERR_RESOURCE_ORDER (errno set to ESPIPE)
*/
int
full_pread(struct filedes *fd, void *buf, size_t count, off_t offset)
full_pread(struct filedes *fd, void *buf, size_t count, uint64_t offset)
{
if (fd->is_pipe)
goto is_pipe;
Expand Down Expand Up @@ -180,7 +180,7 @@ full_write(struct filedes *fd, const void *buf, size_t count)
* WIMLIB_ERR_WRITE (errno set)
*/
int
full_pwrite(struct filedes *fd, const void *buf, size_t count, off_t offset)
full_pwrite(struct filedes *fd, const void *buf, size_t count, uint64_t offset)
{
while (count) {
ssize_t ret = pwrite(fd->fd, buf, count, offset);
Expand All @@ -196,7 +196,7 @@ full_pwrite(struct filedes *fd, const void *buf, size_t count, off_t offset)
return 0;
}

off_t filedes_seek(struct filedes *fd, off_t offset)
uint64_t filedes_seek(struct filedes *fd, uint64_t offset)
{
if (fd->is_pipe) {
errno = ESPIPE;
Expand Down
2 changes: 1 addition & 1 deletion src/header.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ read_wim_header(WIMStruct *wim, struct wim_header *hdr)
* header. */
int
write_wim_header(const struct wim_header *hdr, struct filedes *out_fd,
off_t offset)
uint64_t offset)
{
#ifdef _MSC_VER
#pragma pack(push, 8)
Expand Down
10 changes: 5 additions & 5 deletions src/integrity.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ struct integrity_table {
#endif
static int
calculate_chunk_sha1(struct filedes *in_fd, size_t this_chunk_size,
off_t offset, u8 sha1_md[])
uint64_t offset, u8 sha1_md[])
{
u8 buf[BUFFER_SIZE];
struct sha1_ctx ctx;
Expand Down Expand Up @@ -178,9 +178,9 @@ read_integrity_table(WIMStruct *wim, u64 num_checked_bytes,
*/
static int
calculate_integrity_table(struct filedes *in_fd,
off_t new_check_end,
uint64_t new_check_end,
const struct integrity_table *old_table,
off_t old_check_end,
uint64_t old_check_end,
struct integrity_table **integrity_table_ret,
wimlib_progress_func_t progfunc,
void *progctx)
Expand Down Expand Up @@ -301,8 +301,8 @@ calculate_integrity_table(struct filedes *in_fd,
*/
int
write_integrity_table(WIMStruct *wim,
off_t new_blob_table_end,
off_t old_blob_table_end,
uint64_t new_blob_table_end,
uint64_t old_blob_table_end,
struct integrity_table *old_table)
{
struct integrity_table *new_table;
Expand Down
14 changes: 7 additions & 7 deletions src/mount_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -726,13 +726,13 @@ create_staging_file(const struct wimfs_context *ctx, char **name_ret)
static int
extract_blob_to_staging_dir(struct wim_inode *inode,
struct wim_inode_stream *strm,
off_t size, const struct wimfs_context *ctx)
uint64_t size, const struct wimfs_context *ctx)
{
struct blob_descriptor *old_blob;
struct blob_descriptor *new_blob;
char *staging_file_name;
int staging_fd;
off_t extract_size;
uint64_t extract_size;
int result;
int ret;

Expand Down Expand Up @@ -1729,7 +1729,7 @@ wimfs_opendir(const char *path, struct fuse_file_info *fi)

static int
wimfs_read(const char *path, char *buf, size_t size,
off_t offset, struct fuse_file_info *fi)
uint64_t offset, struct fuse_file_info *fi)
{
struct wimfs_fd *fd = WIMFS_FD(fi);
const struct blob_descriptor *blob;
Expand Down Expand Up @@ -1773,7 +1773,7 @@ wimfs_read(const char *path, char *buf, size_t size,

static int
wimfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
off_t offset, struct fuse_file_info *fi,
uint64_t offset, struct fuse_file_info *fi,
enum fuse_readdir_flags flags)
{
struct wimfs_fd *fd = WIMFS_FD(fi);
Expand Down Expand Up @@ -2004,7 +2004,7 @@ wimfs_symlink(const char *to, const char *from)
}

static int
do_truncate(int staging_fd, off_t size,
do_truncate(int staging_fd, uint64_t size,
struct wim_inode *inode, struct blob_descriptor *blob)
{
if (ftruncate(staging_fd, size))
Expand All @@ -2015,7 +2015,7 @@ do_truncate(int staging_fd, off_t size,
}

static int
wimfs_truncate(const char *path, off_t size, struct fuse_file_info *fi)
wimfs_truncate(const char *path, uint64_t size, struct fuse_file_info *fi)
{
const struct wimfs_context *ctx = wimfs_get_context();
struct wim_dentry *dentry;
Expand Down Expand Up @@ -2114,7 +2114,7 @@ wimfs_utimens(const char *path, const struct timespec tv[2],

static int
wimfs_write(const char *path, const char *buf, size_t size,
off_t offset, struct fuse_file_info *fi)
uint64_t offset, struct fuse_file_info *fi)
{
struct wimfs_fd *fd = WIMFS_FD(fi);
ssize_t ret;
Expand Down
8 changes: 4 additions & 4 deletions src/win32_replacements.c
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ win32_rename_replacement(const wchar_t *srcpath, const wchar_t *dstpath)
#define MAX_IO_AMOUNT 1048576

static int
do_pread_or_pwrite(int fd, void *buf, size_t count, off_t offset,
do_pread_or_pwrite(int fd, void *buf, size_t count, uint64_t offset,
bool is_pwrite)
{
HANDLE h;
Expand Down Expand Up @@ -513,7 +513,7 @@ do_pread_or_pwrite(int fd, void *buf, size_t count, off_t offset,
if (!bret) {
err = GetLastError();
win32_error(err, L"Failed to %s %zu bytes at offset %"PRIu64,
(is_pwrite ? "write" : "read"), count, offset);
(is_pwrite ? L"write" : L"read"), count, offset);
goto error;
}

Expand All @@ -539,7 +539,7 @@ do_pread_or_pwrite(int fd, void *buf, size_t count, off_t offset,
* offset, so it is not safe to use with readers/writers on the same file
* descriptor. */
ssize_t
win32_pread(int fd, void *buf, size_t count, off_t offset)
win32_pread(int fd, void *buf, size_t count, uint64_t offset)
{
return do_pread_or_pwrite(fd, buf, count, offset, false);
}
Expand All @@ -548,7 +548,7 @@ win32_pread(int fd, void *buf, size_t count, off_t offset)
* offset, so it is not safe to use with readers/writers on the same file
* descriptor. */
ssize_t
win32_pwrite(int fd, const void *buf, size_t count, off_t offset)
win32_pwrite(int fd, const void *buf, size_t count, uint64_t offset)
{
return do_pread_or_pwrite(fd, (void*)buf, count, offset, true);
}
Expand Down
10 changes: 5 additions & 5 deletions src/write.c
Original file line number Diff line number Diff line change
Expand Up @@ -2331,9 +2331,9 @@ finish_write(WIMStruct *wim, int image, int write_flags,
struct list_head *blob_table_list)
{
int write_resource_flags;
off_t old_blob_table_end = 0;
uint64_t old_blob_table_end = 0;
struct integrity_table *old_integrity_table = NULL;
off_t new_blob_table_end;
uint64_t new_blob_table_end;
u64 xml_totalbytes;
int ret;

Expand Down Expand Up @@ -2932,7 +2932,7 @@ static int
check_resource_offset(struct blob_descriptor *blob, void *_wim)
{
const WIMStruct *wim = _wim;
off_t end_offset = *(const off_t*)wim->private;
uint64_t end_offset = *(const uint64_t*)wim->private;

if (blob->blob_location == BLOB_IN_WIM &&
blob->rdesc->wim == wim &&
Expand All @@ -2945,7 +2945,7 @@ check_resource_offset(struct blob_descriptor *blob, void *_wim)
* integrity table if present)--- otherwise we can't safely append to the WIM
* file and we return WIMLIB_ERR_RESOURCE_ORDER. */
static int
check_resource_offsets(WIMStruct *wim, off_t end_offset)
check_resource_offsets(WIMStruct *wim, uint64_t end_offset)
{
int ret;
unsigned i;
Expand Down Expand Up @@ -3050,7 +3050,7 @@ static int
overwrite_wim_inplace(WIMStruct *wim, int write_flags, unsigned num_threads)
{
int ret;
off_t old_wim_end;
uint64_t old_wim_end;
struct list_head blob_list;
struct list_head blob_table_list;
struct filter_context filter_ctx;
Expand Down