sdfat.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. /*
  2. * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version 2
  7. * of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef _SDFAT_H
  18. #define _SDFAT_H
  19. #include <linux/buffer_head.h>
  20. #include <linux/string.h>
  21. #include <linux/types.h>
  22. #include <linux/nls.h>
  23. #include <linux/fs.h>
  24. #include <linux/mutex.h>
  25. #include <linux/ratelimit.h>
  26. #include <linux/version.h>
  27. #include <linux/kobject.h>
  28. #include "api.h"
  29. #ifdef CONFIG_SDFAT_DFR
  30. #include "dfr.h"
  31. #endif
  32. /*
  33. * sdfat error flags
  34. */
  35. #define SDFAT_ERRORS_CONT (1) /* ignore error and continue */
  36. #define SDFAT_ERRORS_PANIC (2) /* panic on error */
  37. #define SDFAT_ERRORS_RO (3) /* remount r/o on error */
  38. /*
  39. * sdfat allocator flags
  40. */
  41. #define SDFAT_ALLOC_DELAY (1) /* Delayed allocation */
  42. #define SDFAT_ALLOC_SMART (2) /* Smart allocation */
  43. /*
  44. * sdfat allocator destination for smart allocation
  45. */
  46. #define ALLOC_NOWHERE (0)
  47. #define ALLOC_COLD (1)
  48. #define ALLOC_HOT (16)
  49. #define ALLOC_COLD_ALIGNED (1)
  50. #define ALLOC_COLD_PACKING (2)
  51. #define ALLOC_COLD_SEQ (4)
  52. /*
  53. * sdfat nls lossy flag
  54. */
  55. #define NLS_NAME_NO_LOSSY (0x00) /* no lossy */
  56. #define NLS_NAME_LOSSY (0x01) /* just detected incorrect filename(s) */
  57. #define NLS_NAME_OVERLEN (0x02) /* the length is over than its limit */
  58. /*
  59. * sdfat common MACRO
  60. */
  61. #define CLUSTER_16(x) ((u16)((x) & 0xFFFFU))
  62. #define CLUSTER_32(x) ((u32)((x) & 0xFFFFFFFFU))
  63. #define CLUS_EOF CLUSTER_32(~0)
  64. #define CLUS_BAD (0xFFFFFFF7U)
  65. #define CLUS_FREE (0)
  66. #define CLUS_BASE (2)
  67. #define IS_CLUS_EOF(x) ((x) == CLUS_EOF)
  68. #define IS_CLUS_BAD(x) ((x) == CLUS_BAD)
  69. #define IS_CLUS_FREE(x) ((x) == CLUS_FREE)
  70. #define IS_LAST_SECT_IN_CLUS(fsi, sec) \
  71. ((((sec) - (fsi)->data_start_sector + 1) \
  72. & ((1 << (fsi)->sect_per_clus_bits) - 1)) == 0)
  73. #define CLUS_TO_SECT(fsi, x) \
  74. ((((unsigned long long)(x) - CLUS_BASE) << (fsi)->sect_per_clus_bits) + (fsi)->data_start_sector)
  75. #define SECT_TO_CLUS(fsi, sec) \
  76. ((u32)((((sec) - (fsi)->data_start_sector) >> (fsi)->sect_per_clus_bits) + CLUS_BASE))
  77. /* variables defined at sdfat.c */
  78. extern const char *FS_TYPE_STR[];
  79. enum {
  80. FS_TYPE_AUTO,
  81. FS_TYPE_EXFAT,
  82. FS_TYPE_VFAT,
  83. FS_TYPE_MAX
  84. };
  85. /*
  86. * sdfat mount in-memory data
  87. */
  88. struct sdfat_mount_options {
  89. #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)
  90. kuid_t fs_uid;
  91. kgid_t fs_gid;
  92. #else /* LINUX_VERSION_CODE < KERNEL_VERSION(3, 5, 0) */
  93. uid_t fs_uid;
  94. gid_t fs_gid;
  95. #endif
  96. unsigned short fs_fmask;
  97. unsigned short fs_dmask;
  98. unsigned short allow_utime; /* permission for setting the [am]time */
  99. unsigned short codepage; /* codepage for shortname conversions */
  100. char *iocharset; /* charset for filename input/display */
  101. struct {
  102. unsigned int pack_ratio;
  103. unsigned int sect_per_au;
  104. unsigned int misaligned_sect;
  105. } amap_opt; /* AMAP-related options (see amap.c) */
  106. unsigned char utf8;
  107. unsigned char casesensitive;
  108. unsigned char adj_hidsect;
  109. unsigned char tz_utc;
  110. unsigned char improved_allocation;
  111. unsigned char defrag;
  112. unsigned char symlink; /* support symlink operation */
  113. unsigned char errors; /* on error: continue, panic, remount-ro */
  114. unsigned char discard; /* flag on if -o dicard specified and device support discard() */
  115. unsigned char fs_type; /* fs_type that user specified */
  116. unsigned short adj_req; /* support aligned mpage write */
  117. };
  118. #define SDFAT_HASH_BITS 8
  119. #define SDFAT_HASH_SIZE (1UL << SDFAT_HASH_BITS)
  120. /*
  121. * SDFAT file system superblock in-memory data
  122. */
  123. struct sdfat_sb_info {
  124. FS_INFO_T fsi; /* private filesystem info */
  125. struct mutex s_vlock; /* volume lock */
  126. int use_vmalloc;
  127. #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0)
  128. struct rcu_head rcu;
  129. #endif
  130. #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0)
  131. int s_dirt;
  132. struct mutex s_lock; /* superblock lock */
  133. int write_super_queued; /* Write_super work is pending? */
  134. struct delayed_work write_super_work; /* Work_queue data structrue for write_super() */
  135. spinlock_t work_lock; /* Lock for WQ */
  136. #endif
  137. struct super_block *host_sb; /* sb pointer */
  138. struct sdfat_mount_options options;
  139. struct nls_table *nls_disk; /* Codepage used on disk */
  140. struct nls_table *nls_io; /* Charset used for input and display */
  141. struct ratelimit_state ratelimit;
  142. spinlock_t inode_hash_lock;
  143. struct hlist_head inode_hashtable[SDFAT_HASH_SIZE];
  144. struct kobject sb_kobj;
  145. #ifdef CONFIG_SDFAT_DBG_IOCTL
  146. long debug_flags;
  147. #endif /* CONFIG_SDFAT_DBG_IOCTL */
  148. #ifdef CONFIG_SDFAT_DFR
  149. struct defrag_info dfr_info;
  150. struct completion dfr_complete;
  151. unsigned int *dfr_new_clus;
  152. int dfr_new_idx;
  153. unsigned int *dfr_page_wb;
  154. void **dfr_pagep;
  155. unsigned int dfr_hint_clus;
  156. unsigned int dfr_hint_idx;
  157. int dfr_reserved_clus;
  158. #ifdef CONFIG_SDFAT_DFR_DEBUG
  159. int dfr_spo_flag;
  160. #endif /* CONFIG_SDFAT_DFR_DEBUG */
  161. #endif /* CONFIG_SDFAT_DFR */
  162. #ifdef CONFIG_SDFAT_TRACE_IO
  163. /* Statistics for allocator */
  164. unsigned int stat_n_pages_written; /* # of written pages in total */
  165. unsigned int stat_n_pages_added; /* # of added blocks in total */
  166. unsigned int stat_n_bdev_pages_written; /* # of written pages owned by bdev inode */
  167. unsigned int stat_n_pages_confused;
  168. #endif
  169. atomic_t stat_n_pages_queued; /* # of pages in the request queue (approx.) */
  170. };
  171. /*
  172. * SDFAT file system inode in-memory data
  173. */
  174. struct sdfat_inode_info {
  175. FILE_ID_T fid;
  176. char *target;
  177. /* NOTE: i_size_ondisk is 64bits, so must hold ->inode_lock to access */
  178. loff_t i_size_ondisk; /* physically allocated size */
  179. loff_t i_size_aligned; /* block-aligned i_size (used in cont_write_begin) */
  180. loff_t i_pos; /* on-disk position of directory entry or 0 */
  181. struct hlist_node i_hash_fat; /* hash by i_location */
  182. #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 4, 0)
  183. struct rw_semaphore truncate_lock; /* protect bmap against truncate */
  184. #endif
  185. #ifdef CONFIG_SDFAT_DFR
  186. struct defrag_info dfr_info;
  187. #endif
  188. struct inode vfs_inode;
  189. };
  190. #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 18, 0)
  191. typedef struct timespec64 sdfat_timespec_t;
  192. #else /* LINUX_VERSION_CODE < KERNEL_VERSION(4, 18, 0) */
  193. typedef struct timespec sdfat_timespec_t;
  194. #endif
  195. #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0)
  196. #else /* LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0) */
  197. /*
  198. * sb->s_flags. Note that these mirror the equivalent MS_* flags where
  199. * represented in both.
  200. */
  201. #define SB_RDONLY 1 /* Mount read-only */
  202. #define SB_NODIRATIME 2048 /* Do not update directory access times */
  203. static inline bool sb_rdonly(const struct super_block *sb)
  204. {
  205. return sb->s_flags & MS_RDONLY;
  206. }
  207. #endif
  208. #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0)
  209. /* EMPTY */
  210. #else
  211. static inline sdfat_timespec_t current_time(struct inode *inode)
  212. {
  213. return CURRENT_TIME_SEC;
  214. }
  215. #endif
  216. /*
  217. * FIXME : needs on-disk-slot in-memory data
  218. */
  219. /* static inline functons */
  220. static inline const char *sdfat_get_vol_type_str(unsigned int type)
  221. {
  222. if (type == EXFAT)
  223. return "exfat";
  224. else if (type == FAT32)
  225. return "vfat:32";
  226. else if (type == FAT16)
  227. return "vfat:16";
  228. else if (type == FAT12)
  229. return "vfat:12";
  230. return "unknown";
  231. }
  232. static inline struct sdfat_sb_info *SDFAT_SB(struct super_block *sb)
  233. {
  234. return (struct sdfat_sb_info *)sb->s_fs_info;
  235. }
  236. static inline struct sdfat_inode_info *SDFAT_I(struct inode *inode)
  237. {
  238. return container_of(inode, struct sdfat_inode_info, vfs_inode);
  239. }
  240. /*
  241. * If ->i_mode can't hold S_IWUGO (i.e. ATTR_RO), we use ->i_attrs to
  242. * save ATTR_RO instead of ->i_mode.
  243. *
  244. * If it's directory and !sbi->options.rodir, ATTR_RO isn't read-only
  245. * bit, it's just used as flag for app.
  246. */
  247. static inline int sdfat_mode_can_hold_ro(struct inode *inode)
  248. {
  249. struct sdfat_sb_info *sbi = SDFAT_SB(inode->i_sb);
  250. if (S_ISDIR(inode->i_mode))
  251. return 0;
  252. if ((~sbi->options.fs_fmask) & S_IWUGO)
  253. return 1;
  254. return 0;
  255. }
  256. /*
  257. * FIXME : needs to check symlink option.
  258. */
  259. /* Convert attribute bits and a mask to the UNIX mode. */
  260. static inline mode_t sdfat_make_mode(struct sdfat_sb_info *sbi,
  261. u32 attr, mode_t mode)
  262. {
  263. if ((attr & ATTR_READONLY) && !(attr & ATTR_SUBDIR))
  264. mode &= ~S_IWUGO;
  265. if (attr & ATTR_SUBDIR)
  266. return (mode & ~sbi->options.fs_dmask) | S_IFDIR;
  267. else if (attr & ATTR_SYMLINK)
  268. return (mode & ~sbi->options.fs_dmask) | S_IFLNK;
  269. else
  270. return (mode & ~sbi->options.fs_fmask) | S_IFREG;
  271. }
  272. /* Return the FAT attribute byte for this inode */
  273. static inline u32 sdfat_make_attr(struct inode *inode)
  274. {
  275. u32 attrs = SDFAT_I(inode)->fid.attr;
  276. if (S_ISDIR(inode->i_mode))
  277. attrs |= ATTR_SUBDIR;
  278. if (sdfat_mode_can_hold_ro(inode) && !(inode->i_mode & S_IWUGO))
  279. attrs |= ATTR_READONLY;
  280. return attrs;
  281. }
  282. static inline void sdfat_save_attr(struct inode *inode, u32 attr)
  283. {
  284. if (sdfat_mode_can_hold_ro(inode))
  285. SDFAT_I(inode)->fid.attr = attr & ATTR_RWMASK;
  286. else
  287. SDFAT_I(inode)->fid.attr = attr & (ATTR_RWMASK | ATTR_READONLY);
  288. }
  289. /* sdfat/statistics.c */
  290. /* bigdata function */
  291. #ifdef CONFIG_SDFAT_STATISTICS
  292. extern int sdfat_statistics_init(struct kset *sdfat_kset);
  293. extern void sdfat_statistics_uninit(void);
  294. extern void sdfat_statistics_set_mnt(FS_INFO_T *fsi);
  295. extern void sdfat_statistics_set_mnt_ro(void);
  296. extern void sdfat_statistics_set_mkdir(u8 flags);
  297. extern void sdfat_statistics_set_create(u8 flags);
  298. extern void sdfat_statistics_set_rw(u8 flags, u32 clu_offset, s32 create);
  299. extern void sdfat_statistics_set_trunc(u8 flags, CHAIN_T *clu);
  300. extern void sdfat_statistics_set_vol_size(struct super_block *sb);
  301. #else
  302. static inline int sdfat_statistics_init(struct kset *sdfat_kset)
  303. {
  304. return 0;
  305. }
  306. static inline void sdfat_statistics_uninit(void) {};
  307. static inline void sdfat_statistics_set_mnt(FS_INFO_T *fsi) {};
  308. static inline void sdfat_statistics_set_mnt_ro(void) {};
  309. static inline void sdfat_statistics_set_mkdir(u8 flags) {};
  310. static inline void sdfat_statistics_set_create(u8 flags) {};
  311. static inline void sdfat_statistics_set_rw(u8 flags, u32 clu_offset, s32 create) {};
  312. static inline void sdfat_statistics_set_trunc(u8 flags, CHAIN_T *clu) {};
  313. static inline void sdfat_statistics_set_vol_size(struct super_block *sb) {};
  314. #endif
  315. /* sdfat/nls.c */
  316. /* NLS management function */
  317. s32 nls_cmp_sfn(struct super_block *sb, u8 *a, u8 *b);
  318. s32 nls_cmp_uniname(struct super_block *sb, u16 *a, u16 *b);
  319. s32 nls_uni16s_to_sfn(struct super_block *sb, UNI_NAME_T *p_uniname, DOS_NAME_T *p_dosname, s32 *p_lossy);
  320. s32 nls_sfn_to_uni16s(struct super_block *sb, DOS_NAME_T *p_dosname, UNI_NAME_T *p_uniname);
  321. s32 nls_uni16s_to_vfsname(struct super_block *sb, UNI_NAME_T *uniname, u8 *p_cstring, s32 len);
  322. s32 nls_vfsname_to_uni16s(struct super_block *sb, const u8 *p_cstring,
  323. const s32 len, UNI_NAME_T *uniname, s32 *p_lossy);
  324. /* sdfat/mpage.c */
  325. #ifdef CONFIG_SDFAT_ALIGNED_MPAGE_WRITE
  326. int sdfat_mpage_writepages(struct address_space *mapping,
  327. struct writeback_control *wbc, get_block_t *get_block);
  328. #endif
  329. /* sdfat/xattr.c */
  330. #ifdef CONFIG_SDFAT_VIRTUAL_XATTR
  331. void setup_sdfat_xattr_handler(struct super_block *sb);
  332. extern int sdfat_setxattr(struct dentry *dentry, const char *name, const void *value, size_t size, int flags);
  333. extern ssize_t sdfat_getxattr(struct dentry *dentry, const char *name, void *value, size_t size);
  334. extern ssize_t sdfat_listxattr(struct dentry *dentry, char *list, size_t size);
  335. extern int sdfat_removexattr(struct dentry *dentry, const char *name);
  336. #else
  337. static inline void setup_sdfat_xattr_handler(struct super_block *sb) {};
  338. #endif
  339. /* sdfat/misc.c */
  340. #ifdef CONFIG_SDFAT_UEVENT
  341. extern int sdfat_uevent_init(struct kset *sdfat_kset);
  342. extern void sdfat_uevent_uninit(void);
  343. extern void sdfat_uevent_ro_remount(struct super_block *sb);
  344. #else
  345. static inline int sdfat_uevent_init(struct kset *sdfat_kset)
  346. {
  347. return 0;
  348. }
  349. static inline void sdfat_uevent_uninit(void) {};
  350. static inline void sdfat_uevent_ro_remount(struct super_block *sb) {};
  351. #endif
  352. extern void
  353. __sdfat_fs_error(struct super_block *sb, int report, const char *fmt, ...)
  354. __printf(3, 4) __cold;
  355. #define sdfat_fs_error(sb, fmt, args...) \
  356. __sdfat_fs_error(sb, 1, fmt, ## args)
  357. #define sdfat_fs_error_ratelimit(sb, fmt, args...) \
  358. __sdfat_fs_error(sb, __ratelimit(&SDFAT_SB(sb)->ratelimit), fmt, ## args)
  359. extern void
  360. __sdfat_msg(struct super_block *sb, const char *lv, int st, const char *fmt, ...)
  361. __printf(4, 5) __cold;
  362. #define sdfat_msg(sb, lv, fmt, args...) \
  363. __sdfat_msg(sb, lv, 0, fmt, ## args)
  364. #define sdfat_log_msg(sb, lv, fmt, args...) \
  365. __sdfat_msg(sb, lv, 1, fmt, ## args)
  366. extern void sdfat_log_version(void);
  367. extern void sdfat_time_fat2unix(struct sdfat_sb_info *sbi, sdfat_timespec_t *ts,
  368. DATE_TIME_T *tp);
  369. extern void sdfat_time_unix2fat(struct sdfat_sb_info *sbi, sdfat_timespec_t *ts,
  370. DATE_TIME_T *tp);
  371. extern TIMESTAMP_T *tm_now(struct inode *inode, TIMESTAMP_T *tm);
  372. static inline TIMESTAMP_T *tm_now_sb(struct super_block *sb, TIMESTAMP_T *tm)
  373. {
  374. struct inode fake_inode;
  375. fake_inode.i_sb = sb;
  376. return tm_now(&fake_inode, tm);
  377. }
  378. #ifdef CONFIG_SDFAT_DEBUG
  379. #ifdef CONFIG_SDFAT_DBG_CAREFUL
  380. void sdfat_debug_check_clusters(struct inode *inode);
  381. #else
  382. #define sdfat_debug_check_clusters(inode)
  383. #endif /* CONFIG_SDFAT_DBG_CAREFUL */
  384. #ifdef CONFIG_SDFAT_DBG_BUGON
  385. #define sdfat_debug_bug_on(expr) BUG_ON(expr)
  386. #else
  387. #define sdfat_debug_bug_on(expr)
  388. #endif
  389. #ifdef CONFIG_SDFAT_DBG_WARNON
  390. #define sdfat_debug_warn_on(expr) WARN_ON(expr)
  391. #else
  392. #define sdfat_debug_warn_on(expr)
  393. #endif
  394. #else /* CONFIG_SDFAT_DEBUG */
  395. #define sdfat_debug_check_clusters(inode)
  396. #define sdfat_debug_bug_on(expr)
  397. #define sdfat_debug_warn_on(expr)
  398. #endif /* CONFIG_SDFAT_DEBUG */
  399. #ifdef CONFIG_SDFAT_TRACE_ELAPSED_TIME
  400. u32 sdfat_time_current_usec(struct timeval *tv);
  401. extern struct timeval __t1;
  402. extern struct timeval __t2;
  403. #define TIME_GET(tv) sdfat_time_current_usec(tv)
  404. #define TIME_START(s) sdfat_time_current_usec(s)
  405. #define TIME_END(e) sdfat_time_current_usec(e)
  406. #define TIME_ELAPSED(s, e) ((u32)(((e)->tv_sec - (s)->tv_sec) * 1000000 + \
  407. ((e)->tv_usec - (s)->tv_usec)))
  408. #define PRINT_TIME(n) pr_info("[SDFAT] Elapsed time %d = %d (usec)\n", n, (__t2 - __t1))
  409. #else /* CONFIG_SDFAT_TRACE_ELAPSED_TIME */
  410. #define TIME_GET(tv) (0)
  411. #define TIME_START(s)
  412. #define TIME_END(e)
  413. #define TIME_ELAPSED(s, e) (0)
  414. #define PRINT_TIME(n)
  415. #endif /* CONFIG_SDFAT_TRACE_ELAPSED_TIME */
  416. #define SDFAT_MSG_LV_NONE (0x00000000)
  417. #define SDFAT_MSG_LV_ERR (0x00000001)
  418. #define SDFAT_MSG_LV_INFO (0x00000002)
  419. #define SDFAT_MSG_LV_DBG (0x00000003)
  420. #define SDFAT_MSG_LV_MORE (0x00000004)
  421. #define SDFAT_MSG_LV_TRACE (0x00000005)
  422. #define SDFAT_MSG_LV_ALL (0x00000006)
  423. #define SDFAT_MSG_LEVEL SDFAT_MSG_LV_INFO
  424. #define SDFAT_TAG_NAME "SDFAT"
  425. #define __S(x) #x
  426. #define _S(x) __S(x)
  427. extern void __sdfat_dmsg(int level, const char *fmt, ...) __printf(2, 3) __cold;
  428. #define SDFAT_EMSG_T(level, ...) \
  429. __sdfat_dmsg(level, KERN_ERR "[" SDFAT_TAG_NAME "] [" _S(__FILE__) "(" _S(__LINE__) ")] " __VA_ARGS__)
  430. #define SDFAT_DMSG_T(level, ...) \
  431. __sdfat_dmsg(level, KERN_INFO "[" SDFAT_TAG_NAME "] " __VA_ARGS__)
  432. #define SDFAT_EMSG(...) SDFAT_EMSG_T(SDFAT_MSG_LV_ERR, __VA_ARGS__)
  433. #define SDFAT_IMSG(...) SDFAT_DMSG_T(SDFAT_MSG_LV_INFO, __VA_ARGS__)
  434. #define SDFAT_DMSG(...) SDFAT_DMSG_T(SDFAT_MSG_LV_DBG, __VA_ARGS__)
  435. #define SDFAT_MMSG(...) SDFAT_DMSG_T(SDFAT_MSG_LV_MORE, __VA_ARGS__)
  436. #define SDFAT_TMSG(...) SDFAT_DMSG_T(SDFAT_MSG_LV_TRACE, __VA_ARGS__)
  437. #define EMSG(...)
  438. #define IMSG(...)
  439. #define DMSG(...)
  440. #define MMSG(...)
  441. #define TMSG(...)
  442. #define EMSG_VAR(exp)
  443. #define IMSG_VAR(exp)
  444. #define DMSG_VAR(exp)
  445. #define MMSG_VAR(exp)
  446. #define TMSG_VAR(exp)
  447. #ifdef CONFIG_SDFAT_DBG_MSG
  448. #if (SDFAT_MSG_LEVEL >= SDFAT_MSG_LV_ERR)
  449. #undef EMSG
  450. #undef EMSG_VAR
  451. #define EMSG(...) SDFAT_EMSG(__VA_ARGS__)
  452. #define EMSG_VAR(exp) exp
  453. #endif
  454. #if (SDFAT_MSG_LEVEL >= SDFAT_MSG_LV_INFO)
  455. #undef IMSG
  456. #undef IMSG_VAR
  457. #define IMSG(...) SDFAT_IMSG(__VA_ARGS__)
  458. #define IMSG_VAR(exp) exp
  459. #endif
  460. #if (SDFAT_MSG_LEVEL >= SDFAT_MSG_LV_DBG)
  461. #undef DMSG
  462. #undef DMSG_VAR
  463. #define DMSG(...) SDFAT_DMSG(__VA_ARGS__)
  464. #define DMSG_VAR(exp) exp
  465. #endif
  466. #if (SDFAT_MSG_LEVEL >= SDFAT_MSG_LV_MORE)
  467. #undef MMSG
  468. #undef MMSG_VAR
  469. #define MMSG(...) SDFAT_MMSG(__VA_ARGS__)
  470. #define MMSG_VAR(exp) exp
  471. #endif
  472. /* should replace with trace function */
  473. #if (SDFAT_MSG_LEVEL >= SDFAT_MSG_LV_TRACE)
  474. #undef TMSG
  475. #undef TMSG_VAR
  476. #define TMSG(...) SDFAT_TMSG(__VA_ARGS__)
  477. #define TMSG_VAR(exp) exp
  478. #endif
  479. #endif /* CONFIG_SDFAT_DBG_MSG */
  480. #define ASSERT(expr) { \
  481. if (!(expr)) { \
  482. pr_err("Assertion failed! %s\n", #expr); \
  483. BUG_ON(1); \
  484. } \
  485. }
  486. #endif /* !_SDFAT_H */