internal.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2017-2018 HUAWEI, Inc.
  4. * https://www.huawei.com/
  5. * Copyright (C) 2021, Alibaba Cloud
  6. */
  7. #ifndef __EROFS_INTERNAL_H
  8. #define __EROFS_INTERNAL_H
  9. #include <linux/fs.h>
  10. #include <linux/dax.h>
  11. #include <linux/dcache.h>
  12. #include <linux/mm.h>
  13. #include <linux/module.h>
  14. #include <linux/pagemap.h>
  15. #include <linux/bio.h>
  16. #include <linux/magic.h>
  17. #include <linux/slab.h>
  18. #include <linux/vmalloc.h>
  19. #include <linux/iomap.h>
  20. #include "erofs_fs.h"
  21. __printf(2, 3) void _erofs_printk(struct super_block *sb, const char *fmt, ...);
  22. #define erofs_err(sb, fmt, ...) \
  23. _erofs_printk(sb, KERN_ERR fmt "\n", ##__VA_ARGS__)
  24. #define erofs_info(sb, fmt, ...) \
  25. _erofs_printk(sb, KERN_INFO fmt "\n", ##__VA_ARGS__)
  26. #ifdef CONFIG_EROFS_FS_DEBUG
  27. #define DBG_BUGON BUG_ON
  28. #else
  29. #define DBG_BUGON(x) ((void)(x))
  30. #endif /* !CONFIG_EROFS_FS_DEBUG */
  31. /* EROFS_SUPER_MAGIC_V1 to represent the whole file system */
  32. #define EROFS_SUPER_MAGIC EROFS_SUPER_MAGIC_V1
  33. typedef u64 erofs_nid_t;
  34. typedef u64 erofs_off_t;
  35. typedef u64 erofs_blk_t;
  36. struct erofs_device_info {
  37. char *path;
  38. struct erofs_fscache *fscache;
  39. struct file *file;
  40. struct dax_device *dax_dev;
  41. u64 fsoff, dax_part_off;
  42. erofs_blk_t blocks;
  43. erofs_blk_t uniaddr;
  44. };
  45. enum {
  46. EROFS_SYNC_DECOMPRESS_AUTO,
  47. EROFS_SYNC_DECOMPRESS_FORCE_ON,
  48. EROFS_SYNC_DECOMPRESS_FORCE_OFF
  49. };
  50. struct erofs_mount_opts {
  51. /* current strategy of how to use managed cache */
  52. unsigned char cache_strategy;
  53. unsigned int mount_opt;
  54. };
  55. struct erofs_dev_context {
  56. struct idr tree;
  57. struct rw_semaphore rwsem;
  58. unsigned int extra_devices;
  59. bool flatdev;
  60. };
  61. /* all filesystem-wide lz4 configurations */
  62. struct erofs_sb_lz4_info {
  63. /* # of pages needed for EROFS lz4 rolling decompression */
  64. u16 max_distance_pages;
  65. /* maximum possible blocks for pclusters in the filesystem */
  66. u16 max_pclusterblks;
  67. };
  68. struct erofs_domain {
  69. refcount_t ref;
  70. struct list_head list;
  71. struct fscache_volume *volume;
  72. char *domain_id;
  73. };
  74. struct erofs_fscache {
  75. struct fscache_cookie *cookie;
  76. struct inode *inode; /* anonymous inode for the blob */
  77. /* used for share domain mode */
  78. struct erofs_domain *domain;
  79. struct list_head node;
  80. refcount_t ref;
  81. char *name;
  82. };
  83. struct erofs_xattr_prefix_item {
  84. struct erofs_xattr_long_prefix *prefix;
  85. u8 infix_len;
  86. };
  87. struct erofs_sb_info {
  88. struct erofs_device_info dif0;
  89. struct erofs_mount_opts opt; /* options */
  90. #ifdef CONFIG_EROFS_FS_ZIP
  91. /* list for all registered superblocks, mainly for shrinker */
  92. struct list_head list;
  93. struct mutex umount_mutex;
  94. /* managed XArray arranged in physical block number */
  95. struct xarray managed_pslots;
  96. unsigned int sync_decompress; /* strategy for sync decompression */
  97. unsigned int shrinker_run_no;
  98. /* pseudo inode to manage cached pages */
  99. struct inode *managed_cache;
  100. struct erofs_sb_lz4_info lz4;
  101. #endif /* CONFIG_EROFS_FS_ZIP */
  102. struct inode *packed_inode;
  103. struct inode *metabox_inode;
  104. struct erofs_dev_context *devs;
  105. u64 total_blocks;
  106. u32 meta_blkaddr;
  107. #ifdef CONFIG_EROFS_FS_XATTR
  108. u32 xattr_blkaddr;
  109. u32 xattr_prefix_start;
  110. u8 xattr_prefix_count;
  111. u8 ishare_xattr_prefix_id;
  112. struct erofs_xattr_prefix_item *xattr_prefixes;
  113. unsigned int xattr_filter_reserved;
  114. #endif
  115. u16 device_id_mask; /* valid bits of device id to be used */
  116. unsigned char islotbits; /* inode slot unit size in bit shift */
  117. unsigned char blkszbits; /* filesystem block size in bit shift */
  118. u32 sb_size; /* total superblock size */
  119. u32 fixed_nsec;
  120. s64 epoch;
  121. /* what we really care is nid, rather than ino.. */
  122. erofs_nid_t root_nid;
  123. erofs_nid_t packed_nid;
  124. erofs_nid_t metabox_nid;
  125. /* used for statfs, f_files - f_favail */
  126. u64 inos;
  127. char *volume_name;
  128. u32 feature_compat;
  129. u32 feature_incompat;
  130. u16 available_compr_algs;
  131. /* sysfs support */
  132. struct kobject s_kobj; /* /sys/fs/erofs/<devname> */
  133. struct completion s_kobj_unregister;
  134. erofs_off_t dir_ra_bytes;
  135. /* fscache support */
  136. struct fscache_volume *volume;
  137. struct erofs_domain *domain;
  138. char *fsid;
  139. char *domain_id;
  140. };
  141. #define EROFS_SB(sb) ((struct erofs_sb_info *)(sb)->s_fs_info)
  142. #define EROFS_I_SB(inode) ((struct erofs_sb_info *)(inode)->i_sb->s_fs_info)
  143. /* Mount flags set via mount options or defaults */
  144. #define EROFS_MOUNT_XATTR_USER 0x00000010
  145. #define EROFS_MOUNT_POSIX_ACL 0x00000020
  146. #define EROFS_MOUNT_DAX_ALWAYS 0x00000040
  147. #define EROFS_MOUNT_DAX_NEVER 0x00000080
  148. #define EROFS_MOUNT_DIRECT_IO 0x00000100
  149. #define EROFS_MOUNT_INODE_SHARE 0x00000200
  150. #define clear_opt(opt, option) ((opt)->mount_opt &= ~EROFS_MOUNT_##option)
  151. #define set_opt(opt, option) ((opt)->mount_opt |= EROFS_MOUNT_##option)
  152. #define test_opt(opt, option) ((opt)->mount_opt & EROFS_MOUNT_##option)
  153. static inline bool erofs_is_fileio_mode(struct erofs_sb_info *sbi)
  154. {
  155. return IS_ENABLED(CONFIG_EROFS_FS_BACKED_BY_FILE) && sbi->dif0.file;
  156. }
  157. extern struct file_system_type erofs_anon_fs_type;
  158. static inline bool erofs_is_fscache_mode(struct super_block *sb)
  159. {
  160. return IS_ENABLED(CONFIG_EROFS_FS_ONDEMAND) &&
  161. !erofs_is_fileio_mode(EROFS_SB(sb)) && !sb->s_bdev;
  162. }
  163. enum {
  164. EROFS_ZIP_CACHE_DISABLED,
  165. EROFS_ZIP_CACHE_READAHEAD,
  166. EROFS_ZIP_CACHE_READAROUND
  167. };
  168. struct erofs_buf {
  169. struct address_space *mapping;
  170. struct file *file;
  171. u64 off;
  172. struct page *page;
  173. void *base;
  174. };
  175. #define __EROFS_BUF_INITIALIZER ((struct erofs_buf){ .page = NULL })
  176. #define erofs_blknr(sb, pos) ((erofs_blk_t)((pos) >> (sb)->s_blocksize_bits))
  177. #define erofs_blkoff(sb, pos) ((pos) & ((sb)->s_blocksize - 1))
  178. #define erofs_pos(sb, blk) ((erofs_off_t)(blk) << (sb)->s_blocksize_bits)
  179. #define erofs_iblks(i) (round_up((i)->i_size, i_blocksize(i)) >> (i)->i_blkbits)
  180. #define EROFS_FEATURE_FUNCS(name, compat, feature) \
  181. static inline bool erofs_sb_has_##name(struct erofs_sb_info *sbi) \
  182. { \
  183. return sbi->feature_##compat & EROFS_FEATURE_##feature; \
  184. }
  185. EROFS_FEATURE_FUNCS(lz4_0padding, incompat, INCOMPAT_LZ4_0PADDING)
  186. EROFS_FEATURE_FUNCS(compr_cfgs, incompat, INCOMPAT_COMPR_CFGS)
  187. EROFS_FEATURE_FUNCS(big_pcluster, incompat, INCOMPAT_BIG_PCLUSTER)
  188. EROFS_FEATURE_FUNCS(chunked_file, incompat, INCOMPAT_CHUNKED_FILE)
  189. EROFS_FEATURE_FUNCS(device_table, incompat, INCOMPAT_DEVICE_TABLE)
  190. EROFS_FEATURE_FUNCS(compr_head2, incompat, INCOMPAT_COMPR_HEAD2)
  191. EROFS_FEATURE_FUNCS(ztailpacking, incompat, INCOMPAT_ZTAILPACKING)
  192. EROFS_FEATURE_FUNCS(fragments, incompat, INCOMPAT_FRAGMENTS)
  193. EROFS_FEATURE_FUNCS(dedupe, incompat, INCOMPAT_DEDUPE)
  194. EROFS_FEATURE_FUNCS(xattr_prefixes, incompat, INCOMPAT_XATTR_PREFIXES)
  195. EROFS_FEATURE_FUNCS(48bit, incompat, INCOMPAT_48BIT)
  196. EROFS_FEATURE_FUNCS(metabox, incompat, INCOMPAT_METABOX)
  197. EROFS_FEATURE_FUNCS(sb_chksum, compat, COMPAT_SB_CHKSUM)
  198. EROFS_FEATURE_FUNCS(xattr_filter, compat, COMPAT_XATTR_FILTER)
  199. EROFS_FEATURE_FUNCS(shared_ea_in_metabox, compat, COMPAT_SHARED_EA_IN_METABOX)
  200. EROFS_FEATURE_FUNCS(plain_xattr_pfx, compat, COMPAT_PLAIN_XATTR_PFX)
  201. EROFS_FEATURE_FUNCS(ishare_xattrs, compat, COMPAT_ISHARE_XATTRS)
  202. static inline u64 erofs_nid_to_ino64(struct erofs_sb_info *sbi, erofs_nid_t nid)
  203. {
  204. if (!erofs_sb_has_metabox(sbi))
  205. return nid;
  206. /*
  207. * When metadata compression is enabled, avoid generating excessively
  208. * large inode numbers for metadata-compressed inodes. Shift NIDs in
  209. * the 31-62 bit range left by one and move the metabox flag to bit 31.
  210. *
  211. * Note: on-disk NIDs remain unchanged as they are primarily used for
  212. * compatibility with non-LFS 32-bit applications.
  213. */
  214. return ((nid << 1) & GENMASK_ULL(63, 32)) | (nid & GENMASK(30, 0)) |
  215. ((nid >> EROFS_DIRENT_NID_METABOX_BIT) << 31);
  216. }
  217. /* atomic flag definitions */
  218. #define EROFS_I_EA_INITED_BIT 0
  219. #define EROFS_I_Z_INITED_BIT 1
  220. /* bitlock definitions (arranged in reverse order) */
  221. #define EROFS_I_BL_XATTR_BIT (BITS_PER_LONG - 1)
  222. #define EROFS_I_BL_Z_BIT (BITS_PER_LONG - 2)
  223. /* default readahead size of directories */
  224. #define EROFS_DIR_RA_BYTES 16384
  225. struct erofs_inode_fingerprint {
  226. u8 *opaque;
  227. int size;
  228. };
  229. struct erofs_inode {
  230. erofs_nid_t nid;
  231. /* atomic flags (including bitlocks) */
  232. unsigned long flags;
  233. unsigned char datalayout;
  234. unsigned char inode_isize;
  235. bool dot_omitted;
  236. unsigned int xattr_isize;
  237. unsigned int xattr_name_filter;
  238. unsigned int xattr_shared_count;
  239. unsigned int *xattr_shared_xattrs;
  240. union {
  241. erofs_blk_t startblk;
  242. struct {
  243. unsigned short chunkformat;
  244. unsigned char chunkbits;
  245. };
  246. #ifdef CONFIG_EROFS_FS_ZIP
  247. struct {
  248. unsigned short z_advise;
  249. unsigned char z_algorithmtype[2];
  250. unsigned char z_lclusterbits;
  251. union {
  252. u64 z_tailextent_headlcn;
  253. u64 z_extents;
  254. };
  255. erofs_off_t z_fragmentoff;
  256. unsigned short z_idata_size;
  257. };
  258. #endif /* CONFIG_EROFS_FS_ZIP */
  259. };
  260. #ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE
  261. struct list_head ishare_list;
  262. union {
  263. /* for each anon shared inode */
  264. struct {
  265. struct erofs_inode_fingerprint fingerprint;
  266. spinlock_t ishare_lock;
  267. };
  268. /* for each real inode */
  269. struct inode *sharedinode;
  270. };
  271. #endif
  272. /* the corresponding vfs inode */
  273. struct inode vfs_inode;
  274. };
  275. #define EROFS_I(ptr) container_of(ptr, struct erofs_inode, vfs_inode)
  276. static inline bool erofs_inode_in_metabox(struct inode *inode)
  277. {
  278. return EROFS_I(inode)->nid & BIT_ULL(EROFS_DIRENT_NID_METABOX_BIT);
  279. }
  280. static inline erofs_off_t erofs_iloc(struct inode *inode)
  281. {
  282. struct erofs_sb_info *sbi = EROFS_I_SB(inode);
  283. erofs_nid_t nid_lo = EROFS_I(inode)->nid & EROFS_DIRENT_NID_MASK;
  284. if (erofs_inode_in_metabox(inode))
  285. return nid_lo << sbi->islotbits;
  286. return erofs_pos(inode->i_sb, sbi->meta_blkaddr) +
  287. (nid_lo << sbi->islotbits);
  288. }
  289. static inline unsigned int erofs_inode_version(unsigned int ifmt)
  290. {
  291. return (ifmt >> EROFS_I_VERSION_BIT) & EROFS_I_VERSION_MASK;
  292. }
  293. static inline unsigned int erofs_inode_datalayout(unsigned int ifmt)
  294. {
  295. return (ifmt >> EROFS_I_DATALAYOUT_BIT) & EROFS_I_DATALAYOUT_MASK;
  296. }
  297. /* reclaiming is never triggered when allocating new folios. */
  298. static inline struct folio *erofs_grab_folio_nowait(struct address_space *as,
  299. pgoff_t index)
  300. {
  301. return __filemap_get_folio(as, index,
  302. FGP_LOCK|FGP_CREAT|FGP_NOFS|FGP_NOWAIT,
  303. readahead_gfp_mask(as) & ~__GFP_RECLAIM);
  304. }
  305. /* Has a disk mapping */
  306. #define EROFS_MAP_MAPPED 0x0001
  307. /* Located in metadata (could be copied from bd_inode) */
  308. #define EROFS_MAP_META 0x0002
  309. /* The extent is encoded */
  310. #define EROFS_MAP_ENCODED 0x0004
  311. /* The length of extent is full */
  312. #define EROFS_MAP_FULL_MAPPED 0x0008
  313. /* Located in the special packed inode */
  314. #define __EROFS_MAP_FRAGMENT 0x0010
  315. /* The extent refers to partial decompressed data */
  316. #define EROFS_MAP_PARTIAL_REF 0x0020
  317. #define EROFS_MAP_FRAGMENT (EROFS_MAP_MAPPED | __EROFS_MAP_FRAGMENT)
  318. struct erofs_map_blocks {
  319. struct erofs_buf buf;
  320. erofs_off_t m_pa, m_la;
  321. u64 m_plen, m_llen;
  322. unsigned short m_deviceid;
  323. char m_algorithmformat;
  324. unsigned int m_flags;
  325. };
  326. /*
  327. * Used to get the exact decompressed length, e.g. fiemap (consider lookback
  328. * approach instead if possible since it's more metadata lightweight.)
  329. */
  330. #define EROFS_GET_BLOCKS_FIEMAP 0x0001
  331. /* Used to map the whole extent if non-negligible data is requested for LZMA */
  332. #define EROFS_GET_BLOCKS_READMORE 0x0002
  333. /* Used to map tail extent for tailpacking inline or fragment pcluster */
  334. #define EROFS_GET_BLOCKS_FINDTAIL 0x0004
  335. enum {
  336. Z_EROFS_COMPRESSION_SHIFTED = Z_EROFS_COMPRESSION_MAX,
  337. Z_EROFS_COMPRESSION_INTERLACED,
  338. Z_EROFS_COMPRESSION_RUNTIME_MAX
  339. };
  340. struct erofs_map_dev {
  341. struct super_block *m_sb;
  342. struct erofs_device_info *m_dif;
  343. struct block_device *m_bdev;
  344. erofs_off_t m_pa;
  345. unsigned int m_deviceid;
  346. };
  347. extern const struct super_operations erofs_sops;
  348. extern const struct address_space_operations erofs_aops;
  349. extern const struct address_space_operations erofs_fileio_aops;
  350. extern const struct address_space_operations z_erofs_aops;
  351. extern const struct address_space_operations erofs_fscache_access_aops;
  352. extern const struct inode_operations erofs_generic_iops;
  353. extern const struct inode_operations erofs_symlink_iops;
  354. extern const struct inode_operations erofs_fast_symlink_iops;
  355. extern const struct inode_operations erofs_dir_iops;
  356. extern const struct file_operations erofs_file_fops;
  357. extern const struct file_operations erofs_dir_fops;
  358. extern const struct file_operations erofs_ishare_fops;
  359. extern const struct iomap_ops z_erofs_iomap_report_ops;
  360. /* flags for erofs_fscache_register_cookie() */
  361. #define EROFS_REG_COOKIE_SHARE 0x0001
  362. #define EROFS_REG_COOKIE_NEED_NOEXIST 0x0002
  363. void *erofs_read_metadata(struct super_block *sb, struct erofs_buf *buf,
  364. erofs_off_t *offset, int *lengthp);
  365. void erofs_unmap_metabuf(struct erofs_buf *buf);
  366. void erofs_put_metabuf(struct erofs_buf *buf);
  367. void *erofs_bread(struct erofs_buf *buf, erofs_off_t offset, bool need_kmap);
  368. int erofs_init_metabuf(struct erofs_buf *buf, struct super_block *sb,
  369. bool in_metabox);
  370. void *erofs_read_metabuf(struct erofs_buf *buf, struct super_block *sb,
  371. erofs_off_t offset, bool in_metabox);
  372. int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *dev);
  373. int erofs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
  374. u64 start, u64 len);
  375. int erofs_map_blocks(struct inode *inode, struct erofs_map_blocks *map);
  376. void erofs_onlinefolio_init(struct folio *folio);
  377. void erofs_onlinefolio_split(struct folio *folio);
  378. void erofs_onlinefolio_end(struct folio *folio, int err, bool dirty);
  379. struct inode *erofs_iget(struct super_block *sb, erofs_nid_t nid);
  380. int erofs_getattr(struct mnt_idmap *idmap, const struct path *path,
  381. struct kstat *stat, u32 request_mask,
  382. unsigned int query_flags);
  383. int erofs_namei(struct inode *dir, const struct qstr *name,
  384. erofs_nid_t *nid, unsigned int *d_type);
  385. static inline void *erofs_vm_map_ram(struct page **pages, unsigned int count)
  386. {
  387. int retried = 0;
  388. while (1) {
  389. void *p = vm_map_ram(pages, count, -1);
  390. /* retry two more times (totally 3 times) */
  391. if (p || ++retried >= 3)
  392. return p;
  393. vm_unmap_aliases();
  394. }
  395. return NULL;
  396. }
  397. static inline const struct address_space_operations *
  398. erofs_get_aops(struct inode *realinode, bool no_fscache)
  399. {
  400. if (erofs_inode_is_data_compressed(EROFS_I(realinode)->datalayout)) {
  401. if (!IS_ENABLED(CONFIG_EROFS_FS_ZIP))
  402. return ERR_PTR(-EOPNOTSUPP);
  403. DO_ONCE_LITE_IF(realinode->i_blkbits != PAGE_SHIFT,
  404. erofs_info, realinode->i_sb,
  405. "EXPERIMENTAL EROFS subpage compressed block support in use. Use at your own risk!");
  406. return &z_erofs_aops;
  407. }
  408. if (IS_ENABLED(CONFIG_EROFS_FS_ONDEMAND) && !no_fscache &&
  409. erofs_is_fscache_mode(realinode->i_sb))
  410. return &erofs_fscache_access_aops;
  411. if (IS_ENABLED(CONFIG_EROFS_FS_BACKED_BY_FILE) &&
  412. erofs_is_fileio_mode(EROFS_SB(realinode->i_sb)))
  413. return &erofs_fileio_aops;
  414. return &erofs_aops;
  415. }
  416. int erofs_register_sysfs(struct super_block *sb);
  417. void erofs_unregister_sysfs(struct super_block *sb);
  418. int __init erofs_init_sysfs(void);
  419. void erofs_exit_sysfs(void);
  420. struct page *__erofs_allocpage(struct page **pagepool, gfp_t gfp, bool tryrsv);
  421. static inline struct page *erofs_allocpage(struct page **pagepool, gfp_t gfp)
  422. {
  423. return __erofs_allocpage(pagepool, gfp, false);
  424. }
  425. static inline void erofs_pagepool_add(struct page **pagepool, struct page *page)
  426. {
  427. set_page_private(page, (unsigned long)*pagepool);
  428. *pagepool = page;
  429. }
  430. void erofs_release_pages(struct page **pagepool);
  431. #ifdef CONFIG_EROFS_FS_ZIP
  432. #define MNGD_MAPPING(sbi) ((sbi)->managed_cache->i_mapping)
  433. extern atomic_long_t erofs_global_shrink_cnt;
  434. void erofs_shrinker_register(struct super_block *sb);
  435. void erofs_shrinker_unregister(struct super_block *sb);
  436. int __init erofs_init_shrinker(void);
  437. void erofs_exit_shrinker(void);
  438. int __init z_erofs_init_subsystem(void);
  439. void z_erofs_exit_subsystem(void);
  440. int z_erofs_init_super(struct super_block *sb);
  441. unsigned long z_erofs_shrink_scan(struct erofs_sb_info *sbi,
  442. unsigned long nr_shrink);
  443. int z_erofs_map_blocks_iter(struct inode *inode, struct erofs_map_blocks *map,
  444. int flags);
  445. void *z_erofs_get_gbuf(unsigned int requiredpages);
  446. void z_erofs_put_gbuf(void *ptr);
  447. int z_erofs_gbuf_growsize(unsigned int nrpages);
  448. int __init z_erofs_gbuf_init(void);
  449. void z_erofs_gbuf_exit(void);
  450. #else
  451. static inline void erofs_shrinker_register(struct super_block *sb) {}
  452. static inline void erofs_shrinker_unregister(struct super_block *sb) {}
  453. static inline int erofs_init_shrinker(void) { return 0; }
  454. static inline void erofs_exit_shrinker(void) {}
  455. static inline int z_erofs_init_subsystem(void) { return 0; }
  456. static inline void z_erofs_exit_subsystem(void) {}
  457. static inline int z_erofs_init_super(struct super_block *sb) { return 0; }
  458. #endif /* !CONFIG_EROFS_FS_ZIP */
  459. int z_erofs_parse_cfgs(struct super_block *sb, struct erofs_super_block *dsb);
  460. #ifdef CONFIG_EROFS_FS_BACKED_BY_FILE
  461. struct bio *erofs_fileio_bio_alloc(struct erofs_map_dev *mdev);
  462. void erofs_fileio_submit_bio(struct bio *bio);
  463. #else
  464. static inline struct bio *erofs_fileio_bio_alloc(struct erofs_map_dev *mdev) { return NULL; }
  465. static inline void erofs_fileio_submit_bio(struct bio *bio) {}
  466. #endif
  467. #ifdef CONFIG_EROFS_FS_ONDEMAND
  468. int erofs_fscache_register_fs(struct super_block *sb);
  469. void erofs_fscache_unregister_fs(struct super_block *sb);
  470. struct erofs_fscache *erofs_fscache_register_cookie(struct super_block *sb,
  471. char *name, unsigned int flags);
  472. void erofs_fscache_unregister_cookie(struct erofs_fscache *fscache);
  473. struct bio *erofs_fscache_bio_alloc(struct erofs_map_dev *mdev);
  474. void erofs_fscache_submit_bio(struct bio *bio);
  475. #else
  476. static inline int erofs_fscache_register_fs(struct super_block *sb)
  477. {
  478. return -EOPNOTSUPP;
  479. }
  480. static inline void erofs_fscache_unregister_fs(struct super_block *sb) {}
  481. static inline
  482. struct erofs_fscache *erofs_fscache_register_cookie(struct super_block *sb,
  483. char *name, unsigned int flags)
  484. {
  485. return ERR_PTR(-EOPNOTSUPP);
  486. }
  487. static inline void erofs_fscache_unregister_cookie(struct erofs_fscache *fscache)
  488. {
  489. }
  490. static inline struct bio *erofs_fscache_bio_alloc(struct erofs_map_dev *mdev) { return NULL; }
  491. static inline void erofs_fscache_submit_bio(struct bio *bio) {}
  492. #endif
  493. #ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE
  494. int __init erofs_init_ishare(void);
  495. void erofs_exit_ishare(void);
  496. bool erofs_ishare_fill_inode(struct inode *inode);
  497. void erofs_ishare_free_inode(struct inode *inode);
  498. struct inode *erofs_real_inode(struct inode *inode, bool *need_iput);
  499. #else
  500. static inline int erofs_init_ishare(void) { return 0; }
  501. static inline void erofs_exit_ishare(void) {}
  502. static inline bool erofs_ishare_fill_inode(struct inode *inode) { return false; }
  503. static inline void erofs_ishare_free_inode(struct inode *inode) {}
  504. static inline struct inode *erofs_real_inode(struct inode *inode, bool *need_iput)
  505. {
  506. *need_iput = false;
  507. return inode;
  508. }
  509. #endif
  510. long erofs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
  511. long erofs_compat_ioctl(struct file *filp, unsigned int cmd,
  512. unsigned long arg);
  513. #endif /* __EROFS_INTERNAL_H */