1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Copyright (C) 2019 Namjae Jeon <linkinjeon@kernel.org>
14 #define MB (1024*1024)
15 #define GB (1024UL*1024UL*1024UL)
17 #define __round_mask(x, y) ((__typeof__(x))((y)-1))
18 #define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
19 #define round_down(x, y) ((x) & ~__round_mask(x, y))
21 #define MIN(a, b) ((a) < (b) ? (a) : (b))
22 #define MAX(a, b) ((a) > (b) ? (a) : (b))
24 #define DIV_ROUND_UP(__i, __d) (((__i) + (__d) - 1) / (__d))
26 #define EXFAT_MIN_NUM_SEC_VOL (2048)
27 #define EXFAT_MAX_NUM_SEC_VOL ((2 << 64) - 1)
29 #define EXFAT_MAX_NUM_CLUSTER (0xFFFFFFF5)
31 #define DEFAULT_SECTOR_SIZE (512)
33 #define VOLUME_LABEL_BUFFER_SIZE (VOLUME_LABEL_MAX_LEN*MB_LEN_MAX+1)
35 /* Upcase tabel macro */
36 #define EXFAT_UPCASE_TABLE_SIZE (5836)
48 struct exfat_blk_dev {
50 unsigned long long size;
51 unsigned int sector_size;
52 unsigned int sector_size_bits;
53 unsigned long long num_sectors;
54 unsigned int num_clusters;
57 struct exfat_user_input {
60 unsigned int cluster_size;
61 unsigned int sec_per_clu;
63 __u16 volume_label[VOLUME_LABEL_MAX_LEN];
67 void show_version(void);
69 void exfat_set_bit(struct exfat_blk_dev *bd, char *bitmap,
71 void exfat_clear_bit(struct exfat_blk_dev *bd, char *bitmap,
73 wchar_t exfat_bad_char(wchar_t w);
74 void boot_calc_checksum(unsigned char *sector, unsigned short size,
75 bool is_boot_sec, __le32 *checksum);
76 void init_user_input(struct exfat_user_input *ui);
77 int exfat_get_blk_dev_info(struct exfat_user_input *ui,
78 struct exfat_blk_dev *bd);
79 ssize_t exfat_read(int fd, void *buf, size_t size, off_t offset);
80 ssize_t exfat_write(int fd, void *buf, size_t size, off_t offset);
82 ssize_t exfat_utf16_enc(const char *in_str, __u16 *out_str, size_t out_size);
83 ssize_t exfat_utf16_dec(const __u16 *in_str, size_t in_len,
84 char *out_str, size_t out_size);
90 extern unsigned int print_level;
92 #define EXFAT_ERROR (1)
93 #define EXFAT_INFO (2)
94 #define EXFAT_DEBUG (3)
96 #define exfat_msg(level, fmt, ...) \
98 if (print_level >= level) { \
99 if (print_level == EXFAT_INFO) \
100 printf(fmt, ##__VA_ARGS__); \
102 printf("[%s:%4d] " fmt, \
103 __func__, __LINE__, ##__VA_ARGS__); \
107 #define exfat_err(fmt, ...) exfat_msg(EXFAT_ERROR, fmt, ##__VA_ARGS__)
108 #define exfat_info(fmt, ...) exfat_msg(EXFAT_INFO, fmt, ##__VA_ARGS__)
109 #define exfat_debug(fmt, ...) exfat_msg(EXFAT_DEBUG, fmt, ##__VA_ARGS__)
111 #endif /* !_LIBEXFAT_H */