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_BOUNDARY_ALIGNMENT (1024*1024)
33 #define DEFAULT_SECTOR_SIZE (512)
35 #define VOLUME_LABEL_BUFFER_SIZE (VOLUME_LABEL_MAX_LEN*MB_LEN_MAX+1)
37 /* Upcase tabel macro */
38 #define EXFAT_UPCASE_TABLE_SIZE (5836)
50 struct exfat_blk_dev {
52 unsigned long long size;
53 unsigned int sector_size;
54 unsigned int sector_size_bits;
55 unsigned long long num_sectors;
56 unsigned int num_clusters;
59 struct exfat_user_input {
62 unsigned int cluster_size;
63 unsigned int sec_per_clu;
64 unsigned int boundary_align;
66 __u16 volume_label[VOLUME_LABEL_MAX_LEN];
70 void show_version(void);
72 void exfat_set_bit(struct exfat_blk_dev *bd, char *bitmap,
74 void exfat_clear_bit(struct exfat_blk_dev *bd, char *bitmap,
76 wchar_t exfat_bad_char(wchar_t w);
77 void boot_calc_checksum(unsigned char *sector, unsigned short size,
78 bool is_boot_sec, __le32 *checksum);
79 void init_user_input(struct exfat_user_input *ui);
80 int exfat_get_blk_dev_info(struct exfat_user_input *ui,
81 struct exfat_blk_dev *bd);
82 ssize_t exfat_read(int fd, void *buf, size_t size, off_t offset);
83 ssize_t exfat_write(int fd, void *buf, size_t size, off_t offset);
85 size_t exfat_utf16_len(const __le16 *str, size_t max_size);
86 ssize_t exfat_utf16_enc(const char *in_str, __u16 *out_str, size_t out_size);
87 ssize_t exfat_utf16_dec(const __u16 *in_str, size_t in_len,
88 char *out_str, size_t out_size);
94 extern unsigned int print_level;
96 #define EXFAT_ERROR (1)
97 #define EXFAT_INFO (2)
98 #define EXFAT_DEBUG (3)
100 #define exfat_msg(level, dir, fmt, ...) \
102 if (print_level >= level) { \
103 fprintf(dir, fmt, ##__VA_ARGS__); \
107 #define exfat_err(fmt, ...) exfat_msg(EXFAT_ERROR, stderr, \
109 #define exfat_info(fmt, ...) exfat_msg(EXFAT_INFO, stdout, \
111 #define exfat_debug(fmt, ...) exfat_msg(EXFAT_DEBUG, stdout, \
112 "[%s:%4d] " fmt, __func__, \
113 __LINE__, ##__VA_ARGS__)
115 #endif /* !_LIBEXFAT_H */