core.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. /* External Function Declarations */
  56. /*----------------------------------------------------------------------*/
  57. /* file system initialization & shutdown functions */
  58. s32 fscore_init(void);
  59. s32 fscore_shutdown(void);
  60. /* bdev management */
  61. s32 fscore_check_bdi_valid(struct super_block *sb);
  62. /* chain management */
  63. s32 chain_cont_cluster(struct super_block *sb, u32 chain, u32 len);
  64. /* volume management functions */
  65. s32 fscore_mount(struct super_block *sb);
  66. s32 fscore_umount(struct super_block *sb);
  67. s32 fscore_statfs(struct super_block *sb, VOL_INFO_T *info);
  68. s32 fscore_sync_fs(struct super_block *sb, s32 do_sync);
  69. s32 fscore_set_vol_flags(struct super_block *sb, u16 new_flag, s32 always_sync);
  70. u32 fscore_get_au_stat(struct super_block *sb, s32 mode);
  71. /* file management functions */
  72. s32 fscore_lookup(struct inode *inode, u8 *path, FILE_ID_T *fid);
  73. s32 fscore_create(struct inode *inode, u8 *path, u8 mode, FILE_ID_T *fid);
  74. s32 fscore_read_link(struct inode *inode, FILE_ID_T *fid, void *buffer, u64 count, u64 *rcount);
  75. s32 fscore_write_link(struct inode *inode, FILE_ID_T *fid, void *buffer, u64 count, u64 *wcount);
  76. s32 fscore_truncate(struct inode *inode, u64 old_size, u64 new_size);
  77. s32 fscore_rename(struct inode *old_parent_inode, FILE_ID_T *fid,
  78. struct inode *new_parent_inode, struct dentry *new_dentry);
  79. s32 fscore_remove(struct inode *inode, FILE_ID_T *fid);
  80. s32 fscore_read_inode(struct inode *inode, DIR_ENTRY_T *info);
  81. s32 fscore_write_inode(struct inode *inode, DIR_ENTRY_T *info, int sync);
  82. s32 fscore_map_clus(struct inode *inode, u32 clu_offset, u32 *clu, int dest);
  83. s32 fscore_reserve_clus(struct inode *inode);
  84. s32 fscore_unlink(struct inode *inode, FILE_ID_T *fid);
  85. /* directory management functions */
  86. s32 fscore_mkdir(struct inode *inode, u8 *path, FILE_ID_T *fid);
  87. s32 fscore_readdir(struct inode *inode, DIR_ENTRY_T *dir_ent);
  88. s32 fscore_rmdir(struct inode *inode, FILE_ID_T *fid);
  89. /*----------------------------------------------------------------------*/
  90. /* External Function Declarations (NOT TO UPPER LAYER) */
  91. /*----------------------------------------------------------------------*/
  92. /* core.c : core code for common */
  93. /* dir entry management functions */
  94. DENTRY_T *get_dentry_in_dir(struct super_block *sb, CHAIN_T *p_dir, s32 entry, u64 *sector);
  95. /* name conversion functions */
  96. void get_uniname_from_dos_entry(struct super_block *sb, DOS_DENTRY_T *ep, UNI_NAME_T *p_uniname, u8 mode);
  97. /* file operation functions */
  98. s32 walk_fat_chain(struct super_block *sb, CHAIN_T *p_dir, u32 byte_offset, u32 *clu);
  99. /* sdfat/cache.c */
  100. s32 meta_cache_init(struct super_block *sb);
  101. s32 meta_cache_shutdown(struct super_block *sb);
  102. u8 *fcache_getblk(struct super_block *sb, u64 sec);
  103. s32 fcache_modify(struct super_block *sb, u64 sec);
  104. s32 fcache_release_all(struct super_block *sb);
  105. s32 fcache_flush(struct super_block *sb, u32 sync);
  106. u8 *dcache_getblk(struct super_block *sb, u64 sec);
  107. s32 dcache_modify(struct super_block *sb, u64 sec);
  108. s32 dcache_lock(struct super_block *sb, u64 sec);
  109. s32 dcache_unlock(struct super_block *sb, u64 sec);
  110. s32 dcache_release(struct super_block *sb, u64 sec);
  111. s32 dcache_release_all(struct super_block *sb);
  112. s32 dcache_flush(struct super_block *sb, u32 sync);
  113. s32 dcache_readahead(struct super_block *sb, u64 sec);
  114. /* fatent.c */
  115. s32 fat_ent_ops_init(struct super_block *sb);
  116. s32 fat_ent_get(struct super_block *sb, u32 loc, u32 *content);
  117. s32 fat_ent_set(struct super_block *sb, u32 loc, u32 content);
  118. s32 fat_ent_get_safe(struct super_block *sb, u32 loc, u32 *content);
  119. /* core_fat.c : core code for fat */
  120. s32 fat_generate_dos_name_new(struct super_block *sb, CHAIN_T *p_dir, DOS_NAME_T *p_dosname, s32 n_entries);
  121. s32 mount_fat16(struct super_block *sb, pbr_t *p_pbr);
  122. s32 mount_fat32(struct super_block *sb, pbr_t *p_pbr);
  123. /* core_exfat.c : core code for exfat */
  124. s32 load_alloc_bmp(struct super_block *sb);
  125. void free_alloc_bmp(struct super_block *sb);
  126. ENTRY_SET_CACHE_T *get_dentry_set_in_dir(struct super_block *sb,
  127. CHAIN_T *p_dir, s32 entry, u32 type, DENTRY_T **file_ep);
  128. void release_dentry_set(ENTRY_SET_CACHE_T *es);
  129. s32 update_dir_chksum(struct super_block *sb, CHAIN_T *p_dir, s32 entry);
  130. s32 update_dir_chksum_with_entry_set(struct super_block *sb, ENTRY_SET_CACHE_T *es);
  131. bool is_dir_empty(struct super_block *sb, CHAIN_T *p_dir);
  132. s32 mount_exfat(struct super_block *sb, pbr_t *p_pbr);
  133. /* amap_smart.c : creation on mount / destroy on umount */
  134. int amap_create(struct super_block *sb, u32 pack_ratio, u32 sect_per_au, u32 hidden_sect);
  135. void amap_destroy(struct super_block *sb);
  136. /* amap_smart.c : (de)allocation functions */
  137. s32 amap_fat_alloc_cluster(struct super_block *sb, u32 num_alloc, CHAIN_T *p_chain, s32 dest);
  138. s32 amap_free_cluster(struct super_block *sb, CHAIN_T *p_chain, s32 do_relse);/* Not impelmented */
  139. s32 amap_release_cluster(struct super_block *sb, u32 clu); /* Only update AMAP */
  140. /* amap_smart.c : misc (for defrag) */
  141. s32 amap_mark_ignore(struct super_block *sb, u32 clu);
  142. s32 amap_unmark_ignore(struct super_block *sb, u32 clu);
  143. s32 amap_unmark_ignore_all(struct super_block *sb);
  144. s32 amap_check_working(struct super_block *sb, u32 clu);
  145. s32 amap_get_freeclus(struct super_block *sb, u32 clu);
  146. /* amap_smart.c : stat AU */
  147. u32 amap_get_au_stat(struct super_block *sb, s32 mode);
  148. /* blkdev.c */
  149. s32 bdev_open_dev(struct super_block *sb);
  150. s32 bdev_close_dev(struct super_block *sb);
  151. s32 bdev_check_bdi_valid(struct super_block *sb);
  152. s32 bdev_readahead(struct super_block *sb, u64 secno, u64 num_secs);
  153. s32 bdev_mread(struct super_block *sb, u64 secno, struct buffer_head **bh, u64 num_secs, s32 read);
  154. s32 bdev_mwrite(struct super_block *sb, u64 secno, struct buffer_head *bh, u64 num_secs, s32 sync);
  155. s32 bdev_sync_all(struct super_block *sb);
  156. /* blkdev.c : sector read/write functions */
  157. s32 read_sect(struct super_block *sb, u64 sec, struct buffer_head **bh, s32 read);
  158. s32 write_sect(struct super_block *sb, u64 sec, struct buffer_head *bh, s32 sync);
  159. s32 read_msect(struct super_block *sb, u64 sec, struct buffer_head **bh, s64 num_secs, s32 read);
  160. s32 write_msect(struct super_block *sb, u64 sec, struct buffer_head *bh, s64 num_secs, s32 sync);
  161. s32 write_msect_zero(struct super_block *sb, u64 sec, u64 num_secs);
  162. /* misc.c */
  163. u8 calc_chksum_1byte(void *data, s32 len, u8 chksum);
  164. u16 calc_chksum_2byte(void *data, s32 len, u16 chksum, s32 type);
  165. /* extent.c */
  166. s32 extent_cache_init(void);
  167. void extent_cache_shutdown(void);
  168. void extent_cache_init_inode(struct inode *inode);
  169. void extent_cache_inval_inode(struct inode *inode);
  170. s32 extent_get_clus(struct inode *inode, u32 cluster, u32 *fclus,
  171. u32 *dclus, u32 *last_dclus, s32 allow_eof);
  172. /*----------------------------------------------------------------------*/
  173. /* Wrapper Function */
  174. /*----------------------------------------------------------------------*/
  175. void set_sb_dirty(struct super_block *sb);
  176. #ifdef __cplusplus
  177. }
  178. #endif /* __cplusplus */
  179. #endif /* _SDFAT_CORE_H */
  180. /* end of core.h */