#include <stddef.h>
#include <string.h>
-#ifdef USE_MINGW
-#include <winsock2.h>
-#else
#include <arpa/inet.h>
#include <sys/ioctl.h>
-#endif
#if defined(__linux__)
#include <linux/fs.h>
/* 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");
/* 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");
sb->s_inodes_count = info.inodes_per_group * aux_info.groups;
sb->s_blocks_count_lo = aux_info.len_blocks;
- sb->s_r_blocks_count_lo = 0;
+ sb->s_r_blocks_count_lo = (aux_info.len_blocks / 100) * info.reserve_pcnt;
sb->s_free_blocks_count_lo = 0;
sb->s_free_inodes_count = 0;
sb->s_first_data_block = aux_info.first_data_block;
int is_block_device_fd(int fd)
{
-#ifdef USE_MINGW
- return 0;
-#else
struct stat st;
int ret = fstat(fd, &st);
if (ret < 0)
return 0;
return S_ISBLK(st.st_mode);
-#endif
}
u64 get_file_size(int fd)
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");
return 0;
}
-