Skip to content

Commit

Permalink
Changed off_t to loff_t
Browse files Browse the repository at this point in the history
- off_t is long, loff_t is long long (32bit vs. 64bit)
- exfat requites 64 bit to support larger than 2GB fs

Change-Id: I71e856cc6fa23dda254cc60fe1ecab2ce8608b8e
  • Loading branch information
spegelius committed Nov 23, 2014
1 parent cfb6370 commit 82c6627
Show file tree
Hide file tree
Showing 16 changed files with 85 additions and 85 deletions.
2 changes: 1 addition & 1 deletion dump/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ static int dump_sb(const char* spec)

static void dump_sectors(struct exfat* ef)
{
off_t a = 0, b = 0;
loff_t a = 0, b = 0;

printf("Used sectors ");
while (exfat_find_used_sectors(ef, &a, &b) == 0)
Expand Down
8 changes: 4 additions & 4 deletions fuse/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ static int fuse_exfat_getattr(const char* path, struct stat* stbuf)
return 0;
}

static int fuse_exfat_truncate(const char* path, off_t size)
static int fuse_exfat_truncate(const char* path, loff_t size)
{
struct exfat_node* node;
int rc;
Expand All @@ -88,7 +88,7 @@ static int fuse_exfat_truncate(const char* path, off_t size)
}

static int fuse_exfat_readdir(const char* path, void* buffer,
fuse_fill_dir_t filler, off_t offset, struct fuse_file_info* fi)
fuse_fill_dir_t filler, loff_t offset, struct fuse_file_info* fi)
{
struct exfat_node* parent;
struct exfat_node* node;
Expand Down Expand Up @@ -170,7 +170,7 @@ static int fuse_exfat_fsync(const char* path, int datasync,
}

static int fuse_exfat_read(const char* path, char* buffer, size_t size,
off_t offset, struct fuse_file_info* fi)
loff_t offset, struct fuse_file_info* fi)
{
ssize_t ret;

Expand All @@ -182,7 +182,7 @@ static int fuse_exfat_read(const char* path, char* buffer, size_t size,
}

static int fuse_exfat_write(const char* path, const char* buffer, size_t size,
off_t offset, struct fuse_file_info* fi)
loff_t offset, struct fuse_file_info* fi)
{
ssize_t ret;

Expand Down
18 changes: 9 additions & 9 deletions libexfat/cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,34 @@
/*
* Sector to absolute offset.
*/
static off_t s2o(const struct exfat* ef, off_t sector)
static loff_t s2o(const struct exfat* ef, loff_t sector)
{
return sector << ef->sb->sector_bits;
}

/*
* Cluster to sector.
*/
static off_t c2s(const struct exfat* ef, cluster_t cluster)
static loff_t c2s(const struct exfat* ef, cluster_t cluster)
{
if (cluster < EXFAT_FIRST_DATA_CLUSTER)
exfat_bug("invalid cluster number %u", cluster);
return le32_to_cpu(ef->sb->cluster_sector_start) +
((off_t) (cluster - EXFAT_FIRST_DATA_CLUSTER) << ef->sb->spc_bits);
((loff_t) (cluster - EXFAT_FIRST_DATA_CLUSTER) << ef->sb->spc_bits);
}

/*
* Cluster to absolute offset.
*/
off_t exfat_c2o(const struct exfat* ef, cluster_t cluster)
loff_t exfat_c2o(const struct exfat* ef, cluster_t cluster)
{
return s2o(ef, c2s(ef, cluster));
}

/*
* Sector to cluster.
*/
static cluster_t s2c(const struct exfat* ef, off_t sector)
static cluster_t s2c(const struct exfat* ef, loff_t sector)
{
return ((sector - le32_to_cpu(ef->sb->cluster_sector_start)) >>
ef->sb->spc_bits) + EXFAT_FIRST_DATA_CLUSTER;
Expand All @@ -74,7 +74,7 @@ cluster_t exfat_next_cluster(const struct exfat* ef,
const struct exfat_node* node, cluster_t cluster)
{
le32_t next;
off_t fat_offset;
loff_t fat_offset;

if (cluster < EXFAT_FIRST_DATA_CLUSTER)
exfat_bug("bad cluster 0x%x", cluster);
Expand Down Expand Up @@ -155,7 +155,7 @@ int exfat_flush(struct exfat* ef)
static bool set_next_cluster(const struct exfat* ef, bool contiguous,
cluster_t current, cluster_t next)
{
off_t fat_offset;
loff_t fat_offset;
le32_t next_le32;

if (contiguous)
Expand Down Expand Up @@ -339,7 +339,7 @@ static int shrink_file(struct exfat* ef, struct exfat_node* node,
return 0;
}

static bool erase_raw(struct exfat* ef, size_t size, off_t offset)
static bool erase_raw(struct exfat* ef, size_t size, loff_t offset)
{
if (exfat_pwrite(ef->dev, ef->zero_cluster, size, offset) < 0)
{
Expand Down Expand Up @@ -452,7 +452,7 @@ static int find_used_clusters(const struct exfat* ef,
return 0;
}

int exfat_find_used_sectors(const struct exfat* ef, off_t* a, off_t* b)
int exfat_find_used_sectors(const struct exfat* ef, loff_t* a, loff_t* b)
{
cluster_t ca, cb;

Expand Down
18 changes: 9 additions & 9 deletions libexfat/exfat.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ struct exfat_node
uint32_t fptr_index;
cluster_t fptr_cluster;
cluster_t entry_cluster;
off_t entry_offset;
loff_t entry_offset;
cluster_t start_cluster;
int flags;
uint64_t size;
Expand Down Expand Up @@ -139,18 +139,18 @@ struct exfat_dev* exfat_open(const char* spec, enum exfat_mode mode);
int exfat_close(struct exfat_dev* dev);
int exfat_fsync(struct exfat_dev* dev);
enum exfat_mode exfat_get_mode(const struct exfat_dev* dev);
off_t exfat_get_size(const struct exfat_dev* dev);
off_t exfat_seek(struct exfat_dev* dev, off_t offset, int whence);
loff_t exfat_get_size(const struct exfat_dev* dev);
loff_t exfat_seek(struct exfat_dev* dev, loff_t offset, int whence);
ssize_t exfat_read(struct exfat_dev* dev, void* buffer, size_t size);
ssize_t exfat_write(struct exfat_dev* dev, const void* buffer, size_t size);
ssize_t exfat_pread(struct exfat_dev* dev, void* buffer, size_t size,
off_t offset);
loff_t offset);
ssize_t exfat_pwrite(struct exfat_dev* dev, const void* buffer, size_t size,
off_t offset);
loff_t offset);
ssize_t exfat_generic_pread(const struct exfat* ef, struct exfat_node* node,
void* buffer, size_t size, off_t offset);
void* buffer, size_t size, loff_t offset);
ssize_t exfat_generic_pwrite(struct exfat* ef, struct exfat_node* node,
const void* buffer, size_t size, off_t offset);
const void* buffer, size_t size, loff_t offset);

int exfat_opendir(struct exfat* ef, struct exfat_node* dir,
struct exfat_iterator* it);
Expand All @@ -161,7 +161,7 @@ int exfat_lookup(struct exfat* ef, struct exfat_node** node,
int exfat_split(struct exfat* ef, struct exfat_node** parent,
struct exfat_node** node, le16_t* name, const char* path);

off_t exfat_c2o(const struct exfat* ef, cluster_t cluster);
loff_t exfat_c2o(const struct exfat* ef, cluster_t cluster);
cluster_t exfat_next_cluster(const struct exfat* ef,
const struct exfat_node* node, cluster_t cluster);
cluster_t exfat_advance_cluster(const struct exfat* ef,
Expand All @@ -170,7 +170,7 @@ int exfat_flush(struct exfat* ef);
int exfat_truncate(struct exfat* ef, struct exfat_node* node, uint64_t size,
bool erase);
uint32_t exfat_count_free_clusters(const struct exfat* ef);
int exfat_find_used_sectors(const struct exfat* ef, off_t* a, off_t* b);
int exfat_find_used_sectors(const struct exfat* ef, loff_t* a, loff_t* b);

void exfat_stat(const struct exfat* ef, const struct exfat_node* node,
struct stat* stbuf);
Expand Down
20 changes: 10 additions & 10 deletions libexfat/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ struct exfat_dev
{
int fd;
enum exfat_mode mode;
off_t size; /* in bytes */
loff_t size; /* in bytes */
#ifdef USE_UBLIO
off_t pos;
loff_t pos;
ublio_filehandle_t ufh;
#endif
};
Expand Down Expand Up @@ -243,12 +243,12 @@ enum exfat_mode exfat_get_mode(const struct exfat_dev* dev)
return dev->mode;
}

off_t exfat_get_size(const struct exfat_dev* dev)
loff_t exfat_get_size(const struct exfat_dev* dev)
{
return dev->size;
}

off_t exfat_seek(struct exfat_dev* dev, off_t offset, int whence)
loff_t exfat_seek(struct exfat_dev* dev, loff_t offset, int whence)
{
#ifdef USE_UBLIO
/* XXX SEEK_CUR will be handled incorrectly */
Expand Down Expand Up @@ -285,7 +285,7 @@ ssize_t exfat_write(struct exfat_dev* dev, const void* buffer, size_t size)
}

ssize_t exfat_pread(struct exfat_dev* dev, void* buffer, size_t size,
off_t offset)
loff_t offset)
{
#ifdef USE_UBLIO
return ublio_pread(dev->ufh, buffer, size, offset);
Expand All @@ -297,7 +297,7 @@ ssize_t exfat_pread(struct exfat_dev* dev, void* buffer, size_t size,
}

ssize_t exfat_pwrite(struct exfat_dev* dev, const void* buffer, size_t size,
off_t offset)
loff_t offset)
{
#ifdef USE_UBLIO
return ublio_pwrite(dev->ufh, buffer, size, offset);
Expand All @@ -309,11 +309,11 @@ ssize_t exfat_pwrite(struct exfat_dev* dev, const void* buffer, size_t size,
}

ssize_t exfat_generic_pread(const struct exfat* ef, struct exfat_node* node,
void* buffer, size_t size, off_t offset)
void* buffer, size_t size, loff_t offset)
{
cluster_t cluster;
char* bufp = buffer;
off_t lsize, loffset, remainder;
loff_t lsize, loffset, remainder;

if (offset >= node->size)
return 0;
Expand Down Expand Up @@ -354,11 +354,11 @@ ssize_t exfat_generic_pread(const struct exfat* ef, struct exfat_node* node,
}

ssize_t exfat_generic_pwrite(struct exfat* ef, struct exfat_node* node,
const void* buffer, size_t size, off_t offset)
const void* buffer, size_t size, loff_t offset)
{
cluster_t cluster;
const char* bufp = buffer;
off_t lsize, loffset, remainder;
loff_t lsize, loffset, remainder;

if (offset > node->size)
if (exfat_truncate(ef, node, offset, true) != 0)
Expand Down
2 changes: 1 addition & 1 deletion libexfat/mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ static void parse_options(struct exfat* ef, const char* options)
}

static int verify_vbr_checksum(struct exfat_dev* dev, void* sector,
off_t sector_size)
loff_t sector_size)
{
uint32_t vbr_checksum;
int i;
Expand Down
32 changes: 16 additions & 16 deletions libexfat/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
struct iterator
{
cluster_t cluster;
off_t offset;
loff_t offset;
int contiguous;
char* chunk;
};
Expand Down Expand Up @@ -71,7 +71,7 @@ void exfat_put_node(struct exfat* ef, struct exfat_node* node)
/**
* Cluster + offset from the beginning of the directory to absolute offset.
*/
static off_t co2o(struct exfat* ef, cluster_t cluster, off_t offset)
static loff_t co2o(struct exfat* ef, cluster_t cluster, loff_t offset)
{
return exfat_c2o(ef, cluster) + offset % CLUSTER_SIZE(*ef->sb);
}
Expand Down Expand Up @@ -545,7 +545,7 @@ void exfat_reset_cache(struct exfat* ef)
}

static void next_entry(struct exfat* ef, const struct exfat_node* parent,
cluster_t* cluster, off_t* offset)
cluster_t* cluster, loff_t* offset)
{
*offset += sizeof(struct exfat_entry);
if (*offset % CLUSTER_SIZE(*ef->sb) == 0)
Expand All @@ -556,8 +556,8 @@ static void next_entry(struct exfat* ef, const struct exfat_node* parent,
int exfat_flush_node(struct exfat* ef, struct exfat_node* node)
{
cluster_t cluster;
off_t offset;
off_t meta1_offset, meta2_offset;
loff_t offset;
loff_t meta1_offset, meta2_offset;
struct exfat_entry_meta1 meta1;
struct exfat_entry_meta2 meta2;

Expand Down Expand Up @@ -622,7 +622,7 @@ int exfat_flush_node(struct exfat* ef, struct exfat_node* node)
static bool erase_entry(struct exfat* ef, struct exfat_node* node)
{
cluster_t cluster = node->entry_cluster;
off_t offset = node->entry_offset;
loff_t offset = node->entry_offset;
int name_entries = DIV_ROUND_UP(utf16_length(node->name), EXFAT_ENAME_MAX);
uint8_t entry_type;

Expand Down Expand Up @@ -656,7 +656,7 @@ static bool erase_entry(struct exfat* ef, struct exfat_node* node)
}

static int shrink_directory(struct exfat* ef, struct exfat_node* dir,
off_t deleted_offset)
loff_t deleted_offset)
{
const struct exfat_node* node;
const struct exfat_node* last_node;
Expand Down Expand Up @@ -707,7 +707,7 @@ static int shrink_directory(struct exfat* ef, struct exfat_node* dir,
static int delete(struct exfat* ef, struct exfat_node* node)
{
struct exfat_node* parent = node->parent;
off_t deleted_offset = node->entry_offset;
loff_t deleted_offset = node->entry_offset;
int rc;

exfat_get_node(parent);
Expand Down Expand Up @@ -752,7 +752,7 @@ static int grow_directory(struct exfat* ef, struct exfat_node* dir,
}

static int find_slot(struct exfat* ef, struct exfat_node* dir,
cluster_t* cluster, off_t* offset, int subentries)
cluster_t* cluster, loff_t* offset, int subentries)
{
struct iterator it;
int rc;
Expand Down Expand Up @@ -797,7 +797,7 @@ static int find_slot(struct exfat* ef, struct exfat_node* dir,
}

static int write_entry(struct exfat* ef, struct exfat_node* dir,
const le16_t* name, cluster_t cluster, off_t offset, uint16_t attrib)
const le16_t* name, cluster_t cluster, loff_t offset, uint16_t attrib)
{
struct exfat_node* node;
struct exfat_entry_meta1 meta1;
Expand Down Expand Up @@ -873,7 +873,7 @@ static int create(struct exfat* ef, const char* path, uint16_t attrib)
struct exfat_node* dir;
struct exfat_node* existing;
cluster_t cluster = EXFAT_CLUSTER_BAD;
off_t offset = -1;
loff_t offset = -1;
le16_t name[EXFAT_NAME_MAX + 1];
int rc;

Expand Down Expand Up @@ -929,12 +929,12 @@ int exfat_mkdir(struct exfat* ef, const char* path)

static int rename_entry(struct exfat* ef, struct exfat_node* dir,
struct exfat_node* node, const le16_t* name, cluster_t new_cluster,
off_t new_offset)
loff_t new_offset)
{
struct exfat_entry_meta1 meta1;
struct exfat_entry_meta2 meta2;
cluster_t old_cluster = node->entry_cluster;
off_t old_offset = node->entry_offset;
loff_t old_offset = node->entry_offset;
const size_t name_length = utf16_length(name);
const int name_entries = DIV_ROUND_UP(name_length, EXFAT_ENAME_MAX);
int i;
Expand Down Expand Up @@ -1003,7 +1003,7 @@ int exfat_rename(struct exfat* ef, const char* old_path, const char* new_path)
struct exfat_node* existing;
struct exfat_node* dir;
cluster_t cluster = EXFAT_CLUSTER_BAD;
off_t offset = -1;
loff_t offset = -1;
le16_t name[EXFAT_NAME_MAX + 1];
int rc;

Expand Down Expand Up @@ -1103,7 +1103,7 @@ const char* exfat_get_label(struct exfat* ef)
return ef->label;
}

static int find_label(struct exfat* ef, cluster_t* cluster, off_t* offset)
static int find_label(struct exfat* ef, cluster_t* cluster, loff_t* offset)
{
struct iterator it;
int rc;
Expand Down Expand Up @@ -1141,7 +1141,7 @@ int exfat_set_label(struct exfat* ef, const char* label)
le16_t label_utf16[EXFAT_ENAME_MAX + 1];
int rc;
cluster_t cluster;
off_t offset;
loff_t offset;
struct exfat_entry_label entry;

memset(label_utf16, 0, sizeof(label_utf16));
Expand Down
4 changes: 2 additions & 2 deletions libexfat/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ void exfat_print_info(const struct exfat_super_block* sb,
uint32_t free_clusters)
{
struct exfat_human_bytes hb;
off_t total_space = le64_to_cpu(sb->sector_count) * SECTOR_SIZE(*sb);
off_t avail_space = (off_t) free_clusters * CLUSTER_SIZE(*sb);
loff_t total_space = le64_to_cpu(sb->sector_count) * SECTOR_SIZE(*sb);
loff_t avail_space = (loff_t) free_clusters * CLUSTER_SIZE(*sb);

printf("File system version %hhu.%hhu\n",
sb->version.major, sb->version.minor);
Expand Down
Loading

0 comments on commit 82c6627

Please sign in to comment.