X-Git-Url: https://git.sven.stormbind.net/?p=sven%2Fexfatprogs.git;a=blobdiff_plain;f=include%2Flibexfat.h;h=062350135b76a85ff71103ceaccc702291ac128c;hp=53a82a1efb31038d3c31d574b6487f6646a154ab;hb=03290761e3849db9b13d2d3b176b36ab31c395bb;hpb=dcb4e80c267579d1a68e3f34f6b750e2940dbcc2 diff --git a/include/libexfat.h b/include/libexfat.h index 53a82a1..0623501 100644 --- a/include/libexfat.h +++ b/include/libexfat.h @@ -10,6 +10,8 @@ #include #include +typedef __u32 clus_t; + #define KB (1024) #define MB (1024*1024) #define GB (1024UL*1024UL*1024UL) @@ -35,6 +37,7 @@ #define VOLUME_LABEL_BUFFER_SIZE (VOLUME_LABEL_MAX_LEN*MB_LEN_MAX+1) /* Upcase table macro */ +#define EXFAT_UPCASE_TABLE_CHARS (0x10000) #define EXFAT_UPCASE_TABLE_SIZE (5836) /* Flags for tune.exfat and exfatlabel */ @@ -45,6 +48,10 @@ #define EXFAT_MAX_SECTOR_SIZE 4096 +#define EXFAT_CLUSTER_SIZE(pbr) (1 << ((pbr)->bsx.sect_size_bits + \ + (pbr)->bsx.sect_per_clus_bits)) +#define EXFAT_SECTOR_SIZE(pbr) (1 << (pbr)->bsx.sect_size_bits) + enum { BOOT_SEC_IDX = 0, EXBOOT_SEC_IDX, @@ -79,12 +86,51 @@ struct exfat_user_input { unsigned int volume_serial; }; +struct exfat; +struct exfat_inode; + +#ifdef WORDS_BIGENDIAN +typedef __u8 bitmap_t; +#else +typedef __u32 bitmap_t; +#endif + +#define BITS_PER (sizeof(bitmap_t) * 8) +#define BIT_MASK(__c) (1 << ((__c) % BITS_PER)) +#define BIT_ENTRY(__c) ((__c) / BITS_PER) + +#define EXFAT_BITMAP_SIZE(__c_count) \ + (DIV_ROUND_UP(__c_count, BITS_PER) * sizeof(bitmap_t)) + +static inline bool exfat_bitmap_get(char *bmap, clus_t c) +{ + clus_t cc = c - EXFAT_FIRST_CLUSTER; + + return ((bitmap_t *)(bmap))[BIT_ENTRY(cc)] & BIT_MASK(cc); +} + +static inline void exfat_bitmap_set(char *bmap, clus_t c) +{ + clus_t cc = c - EXFAT_FIRST_CLUSTER; + + (((bitmap_t *)(bmap))[BIT_ENTRY(cc)] |= BIT_MASK(cc)); +} + +static inline void exfat_bitmap_clear(char *bmap, clus_t c) +{ + clus_t cc = c - EXFAT_FIRST_CLUSTER; + (((bitmap_t *)(bmap))[BIT_ENTRY(cc)] &= ~BIT_MASK(cc)); +} + +void exfat_bitmap_set_range(struct exfat *exfat, char *bitmap, + clus_t start_clus, clus_t count); +int exfat_bitmap_find_zero(struct exfat *exfat, char *bmap, + clus_t start_clu, clus_t *next); +int exfat_bitmap_find_one(struct exfat *exfat, char *bmap, + clus_t start_clu, clus_t *next); + void show_version(void); -void exfat_set_bit(struct exfat_blk_dev *bd, char *bitmap, - unsigned int clu); -void exfat_clear_bit(struct exfat_blk_dev *bd, char *bitmap, - unsigned int clu); wchar_t exfat_bad_char(wchar_t w); void boot_calc_checksum(unsigned char *sector, unsigned short size, bool is_boot_sec, __le32 *checksum); @@ -99,9 +145,8 @@ ssize_t exfat_utf16_enc(const char *in_str, __u16 *out_str, size_t out_size); ssize_t exfat_utf16_dec(const __u16 *in_str, size_t in_len, char *out_str, size_t out_size); off_t exfat_get_root_entry_offset(struct exfat_blk_dev *bd); -int exfat_show_volume_label(struct exfat_blk_dev *bd, off_t root_clu_off); -int exfat_set_volume_label(struct exfat_blk_dev *bd, - char *label_input, off_t root_clu_off); +int exfat_read_volume_label(struct exfat *exfat); +int exfat_set_volume_label(struct exfat *exfat, char *label_input); int exfat_read_sector(struct exfat_blk_dev *bd, void *buf, unsigned int sec_off); int exfat_write_sector(struct exfat_blk_dev *bd, void *buf, @@ -114,7 +159,17 @@ int exfat_set_volume_serial(struct exfat_blk_dev *bd, struct exfat_user_input *ui); unsigned int exfat_clus_to_blk_dev_off(struct exfat_blk_dev *bd, unsigned int clu_off, unsigned int clu); - +int exfat_get_next_clus(struct exfat *exfat, clus_t clus, clus_t *next); +int exfat_get_inode_next_clus(struct exfat *exfat, struct exfat_inode *node, + clus_t clus, clus_t *next); +int exfat_set_fat(struct exfat *exfat, clus_t clus, clus_t next_clus); +off_t exfat_s2o(struct exfat *exfat, off_t sect); +off_t exfat_c2o(struct exfat *exfat, unsigned int clus); +int exfat_o2c(struct exfat *exfat, off_t device_offset, + unsigned int *clu, unsigned int *offset); +bool exfat_heap_clus(struct exfat *exfat, clus_t clus); +int exfat_root_clus_count(struct exfat *exfat); +int read_boot_sect(struct exfat_blk_dev *bdev, struct pbr **bs); /* * Exfat Print