core.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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_CORE_H
  18. #define _SDFAT_CORE_H
  19. #include <asm/byteorder.h>
  20. #include "config.h"
  21. #include "api.h"
  22. #include "upcase.h"
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif /* __cplusplus */
  26. /*----------------------------------------------------------------------*/
  27. /* Constant & Macro Definitions */
  28. /*----------------------------------------------------------------------*/
  29. #define get_next_clus(sb, pclu) fat_ent_get(sb, *(pclu), pclu)
  30. #define get_next_clus_safe(sb, pclu) fat_ent_get_safe(sb, *(pclu), pclu)
  31. /* file status */
  32. /* this prevents
  33. * fscore_write_inode, fscore_map_clus, ... with the unlinked inodes
  34. * from corrupting on-disk dentry data.
  35. *
  36. * The fid->dir value of unlinked inode will be DIR_DELETED
  37. * and those functions must check if fid->dir is valid prior to
  38. * the calling of get_dentry_in_dir()
  39. */
  40. #define DIR_DELETED 0xFFFF0321
  41. /*----------------------------------------------------------------------*/
  42. /* Type Definitions */
  43. /*----------------------------------------------------------------------*/
  44. #define ES_2_ENTRIES 2
  45. #define ES_3_ENTRIES 3
  46. #define ES_ALL_ENTRIES 0
  47. typedef struct {
  48. u64 sector; // sector number that contains file_entry
  49. u32 offset; // byte offset in the sector
  50. s32 alloc_flag; // flag in stream entry. 01 for cluster chain, 03 for contig. clusters.
  51. u32 num_entries;
  52. void *__buf; // __buf should be the last member
  53. } ENTRY_SET_CACHE_T;
  54. /*----------------------------------------------------------------------*/
  55. /* Inline Functions */
  56. /*----------------------------------------------------------------------*/
  57. static inline bool is_valid_clus(FS_INFO_T *fsi, u32 clus)
  58. {
  59. if (clus < CLUS_BASE || fsi->num_clusters <= clus)
  60. return false;
  61. return true;
  62. }
  63. /*----------------------------------------------------------------------*/
  64. /* External Function Declarations */
  65. /*----------------------------------------------------------------------*/
  66. /* file system initialization & shutdown functions */
  67. s32 fscore_init(void);
  68. s32 fscore_shutdown(void);
  69. /* bdev management */
  70. s32 fscore_check_bdi_valid(struct super_block *sb);
  71. /* chain management */
  72. s32 chain_cont_cluster(struct super_block *sb, u32 chain, u32 len);
  73. /* volume management functions */
  74. s32 fscore_mount(struct super_block *sb);
  75. s32 fscore_umount(struct super_block *sb);
  76. s32 fscore_statfs(struct super_block *sb, VOL_INFO_T *info);
  77. s32 fscore_sync_fs(struct super_block *sb, s32 do_sync);
  78. s32 fscore_set_vol_flags(struct super_block *sb, u16 new_flag, s32 always_sync);
  79. u32 fscore_get_au_stat(struct super_block *sb, s32 mode);
  80. /* file management functions */
  81. s32 fscore_lookup(struct inode *inode, u8 *path, FILE_ID_T *fid);
  82. s32 fscore_create(struct inode *inode, u8 *path, u8 mode, FILE_ID_T *fid);
  83. s32 fscore_read_link(struct inode *inode, FILE_ID_T *fid, void *buffer, u64 count, u64 *rcount);
  84. s32 fscore_write_link(struct inode *inode, FILE_ID_T *fid, void *buffer, u64 count, u64 *wcount);
  85. s32 fscore_truncate(struct inode *inode, u64 old_size, u64 new_size);
  86. s32 fscore_rename(struct inode *old_parent_inode, FILE_ID_T *fid,
  87. struct inode *new_parent_inode, struct dentry *new_dentry);
  88. s32 fscore_remove(struct inode *inode, FILE_ID_T *fid);
  89. s32 fscore_read_inode(struct inode *inode, DIR_ENTRY_T *info);
  90. s32 fscore_write_inode(struct inode *inode, DIR_ENTRY_T *info, int sync);
  91. s32 fscore_map_clus(struct inode *inode, u32 clu_offset, u32 *clu, int dest);
  92. s32 fscore_reserve_clus(struct inode *inode);
  93. s32 fscore_unlink(struct inode *inode, FILE_ID_T *fid);
  94. /* directory management functions */
  95. s32 fscore_mkdir(struct inode *inode, u8 *path, FILE_ID_T *fid);
  96. s32 fscore_readdir(struct inode *inode, DIR_ENTRY_T *dir_ent);
  97. s32 fscore_rmdir(struct inode *inode, FILE_ID_T *fid);
  98. /*----------------------------------------------------------------------*/
  99. /* External Function Declarations (NOT TO UPPER LAYER) */
  100. /*----------------------------------------------------------------------*/
  101. /* core.c : core code for common */
  102. /* dir entry management functions */
  103. DENTRY_T *get_dentry_in_dir(struct super_block *sb, CHAIN_T *p_dir, s32 entry, u64 *sector);
  104. /* name conversion functions */
  105. void get_uniname_from_dos_entry(struct super_block *sb, DOS_DENTRY_T *ep, UNI_NAME_T *p_uniname, u8 mode);
  106. /* file operation functions */
  107. s32 walk_fat_chain(struct super_block *sb, CHAIN_T *p_dir, u32 byte_offset, u32 *clu);
  108. /* sdfat/cache.c */
  109. s32 meta_cache_init(struct super_block *sb);
  110. s32 meta_cache_shutdown(struct super_block *sb);
  111. u8 *fcache_getblk(struct super_block *sb, u64 sec);
  112. s32 fcache_modify(struct super_block *sb, u64 sec);
  113. s32 fcache_release_all(struct super_block *sb);
  114. s32 fcache_flush(struct super_block *sb, u32 sync);
  115. u8 *dcache_getblk(struct super_block *sb, u64 sec);
  116. s32 dcache_modify(struct super_block *sb, u64 sec);
  117. s32 dcache_lock(struct super_block *sb, u64 sec);
  118. s32 dcache_unlock(struct super_block *sb, u64 sec);
  119. s32 dcache_release(struct super_block *sb, u64 sec);
  120. s32 dcache_release_all(struct super_block *sb);
  121. s32 dcache_flush(struct super_block *sb, u32 sync);
  122. s32 dcache_readahead(struct super_block *sb, u64 sec);
  123. /* fatent.c */
  124. s32 fat_ent_ops_init(struct super_block *sb);
  125. s32 fat_ent_get(struct super_block *sb, u32 loc, u32 *content);
  126. s32 fat_ent_set(struct super_block *sb, u32 loc, u32 content);
  127. s32 fat_ent_get_safe(struct super_block *sb, u32 loc, u32 *content);
  128. /* core_fat.c : core code for fat */
  129. s32 fat_generate_dos_name_new(struct super_block *sb, CHAIN_T *p_dir, DOS_NAME_T *p_dosname, s32 n_entries);
  130. s32 mount_fat16(struct super_block *sb, pbr_t *p_pbr);
  131. s32 mount_fat32(struct super_block *sb, pbr_t *p_pbr);
  132. /* core_exfat.c : core code for exfat */
  133. s32 load_alloc_bmp(struct super_block *sb);
  134. void free_alloc_bmp(struct super_block *sb);
  135. ENTRY_SET_CACHE_T *get_dentry_set_in_dir(struct super_block *sb,
  136. CHAIN_T *p_dir, s32 entry, u32 type, DENTRY_T **file_ep);
  137. void release_dentry_set(ENTRY_SET_CACHE_T *es);
  138. s32 update_dir_chksum(struct super_block *sb, CHAIN_T *p_dir, s32 entry);
  139. s32 update_dir_chksum_with_entry_set(struct super_block *sb, ENTRY_SET_CACHE_T *es);
  140. bool is_dir_empty(struct super_block *sb, CHAIN_T *p_dir);
  141. s32 mount_exfat(struct super_block *sb, pbr_t *p_pbr);
  142. /* amap_smart.c : creation on mount / destroy on umount */
  143. int amap_create(struct super_block *sb, u32 pack_ratio, u32 sect_per_au, u32 hidden_sect);
  144. void amap_destroy(struct super_block *sb);
  145. /* amap_smart.c : (de)allocation functions */
  146. s32 amap_fat_alloc_cluster(struct super_block *sb, u32 num_alloc, CHAIN_T *p_chain, s32 dest);
  147. s32 amap_free_cluster(struct super_block *sb, CHAIN_T *p_chain, s32 do_relse);/* Not impelmented */
  148. s32 amap_release_cluster(struct super_block *sb, u32 clu); /* Only update AMAP */
  149. /* amap_smart.c : misc (for defrag) */
  150. s32 amap_mark_ignore(struct super_block *sb, u32 clu);
  151. s32 amap_unmark_ignore(struct super_block *sb, u32 clu);
  152. s32 amap_unmark_ignore_all(struct super_block *sb);
  153. s32 amap_check_working(struct super_block *sb, u32 clu);
  154. s32 amap_get_freeclus(struct super_block *sb, u32 clu);
  155. /* amap_smart.c : stat AU */
  156. u32 amap_get_au_stat(struct super_block *sb, s32 mode);
  157. /* blkdev.c */
  158. s32 bdev_open_dev(struct super_block *sb);
  159. s32 bdev_close_dev(struct super_block *sb);
  160. s32 bdev_check_bdi_valid(struct super_block *sb);
  161. s32 bdev_readahead(struct super_block *sb, u64 secno, u64 num_secs);
  162. s32 bdev_mread(struct super_block *sb, u64 secno, struct buffer_head **bh, u64 num_secs, s32 read);
  163. s32 bdev_mwrite(struct super_block *sb, u64 secno, struct buffer_head *bh, u64 num_secs, s32 sync);
  164. s32 bdev_sync_all(struct super_block *sb);
  165. /* blkdev.c : sector read/write functions */
  166. s32 read_sect(struct super_block *sb, u64 sec, struct buffer_head **bh, s32 read);
  167. s32 write_sect(struct super_block *sb, u64 sec, struct buffer_head *bh, s32 sync);
  168. s32 read_msect(struct super_block *sb, u64 sec, struct buffer_head **bh, s64 num_secs, s32 read);
  169. s32 write_msect(struct super_block *sb, u64 sec, struct buffer_head *bh, s64 num_secs, s32 sync);
  170. s32 write_msect_zero(struct super_block *sb, u64 sec, u64 num_secs);
  171. /* misc.c */
  172. u8 calc_chksum_1byte(void *data, s32 len, u8 chksum);
  173. u16 calc_chksum_2byte(void *data, s32 len, u16 chksum, s32 type);
  174. /* extent.c */
  175. s32 extent_cache_init(void);
  176. void extent_cache_shutdown(void);
  177. void extent_cache_init_inode(struct inode *inode);
  178. void extent_cache_inval_inode(struct inode *inode);
  179. s32 extent_get_clus(struct inode *inode, u32 cluster, u32 *fclus,
  180. u32 *dclus, u32 *last_dclus, s32 allow_eof);
  181. /*----------------------------------------------------------------------*/
  182. /* Wrapper Function */
  183. /*----------------------------------------------------------------------*/
  184. void set_sb_dirty(struct super_block *sb);
  185. #ifdef __cplusplus
  186. }
  187. #endif /* __cplusplus */
  188. #endif /* _SDFAT_CORE_H */
  189. /* end of core.h */