util.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. /*
  2. * linux/fs/ufs/util.h
  3. *
  4. * Copyright (C) 1998
  5. * Daniel Pirkl <daniel.pirkl@email.cz>
  6. * Charles University, Faculty of Mathematics and Physics
  7. */
  8. #include <linux/buffer_head.h>
  9. #include <linux/fs.h>
  10. #include "swab.h"
  11. /*
  12. * some useful macros
  13. */
  14. #define in_range(b,first,len) ((b)>=(first)&&(b)<(first)+(len))
  15. /*
  16. * functions used for retyping
  17. */
  18. static inline struct ufs_buffer_head *UCPI_UBH(struct ufs_cg_private_info *cpi)
  19. {
  20. return &cpi->c_ubh;
  21. }
  22. static inline struct ufs_buffer_head *USPI_UBH(struct ufs_sb_private_info *spi)
  23. {
  24. return &spi->s_ubh;
  25. }
  26. /*
  27. * macros used for accessing structures
  28. */
  29. static inline s32
  30. ufs_get_fs_state(struct super_block *sb, struct ufs_super_block_first *usb1,
  31. struct ufs_super_block_third *usb3)
  32. {
  33. switch (UFS_SB(sb)->s_flags & UFS_ST_MASK) {
  34. case UFS_ST_SUN:
  35. return fs32_to_cpu(sb, usb3->fs_un2.fs_sun.fs_state);
  36. case UFS_ST_SUNx86:
  37. return fs32_to_cpu(sb, usb1->fs_u1.fs_sunx86.fs_state);
  38. case UFS_ST_44BSD:
  39. default:
  40. return fs32_to_cpu(sb, usb3->fs_un2.fs_44.fs_state);
  41. }
  42. }
  43. static inline void
  44. ufs_set_fs_state(struct super_block *sb, struct ufs_super_block_first *usb1,
  45. struct ufs_super_block_third *usb3, s32 value)
  46. {
  47. switch (UFS_SB(sb)->s_flags & UFS_ST_MASK) {
  48. case UFS_ST_SUN:
  49. usb3->fs_un2.fs_sun.fs_state = cpu_to_fs32(sb, value);
  50. break;
  51. case UFS_ST_SUNx86:
  52. usb1->fs_u1.fs_sunx86.fs_state = cpu_to_fs32(sb, value);
  53. break;
  54. case UFS_ST_44BSD:
  55. usb3->fs_un2.fs_44.fs_state = cpu_to_fs32(sb, value);
  56. break;
  57. }
  58. }
  59. static inline u32
  60. ufs_get_fs_npsect(struct super_block *sb, struct ufs_super_block_first *usb1,
  61. struct ufs_super_block_third *usb3)
  62. {
  63. if ((UFS_SB(sb)->s_flags & UFS_ST_MASK) == UFS_ST_SUNx86)
  64. return fs32_to_cpu(sb, usb3->fs_un2.fs_sunx86.fs_npsect);
  65. else
  66. return fs32_to_cpu(sb, usb1->fs_u1.fs_sun.fs_npsect);
  67. }
  68. static inline u64
  69. ufs_get_fs_qbmask(struct super_block *sb, struct ufs_super_block_third *usb3)
  70. {
  71. __fs64 tmp;
  72. switch (UFS_SB(sb)->s_flags & UFS_ST_MASK) {
  73. case UFS_ST_SUN:
  74. ((__fs32 *)&tmp)[0] = usb3->fs_un2.fs_sun.fs_qbmask[0];
  75. ((__fs32 *)&tmp)[1] = usb3->fs_un2.fs_sun.fs_qbmask[1];
  76. break;
  77. case UFS_ST_SUNx86:
  78. ((__fs32 *)&tmp)[0] = usb3->fs_un2.fs_sunx86.fs_qbmask[0];
  79. ((__fs32 *)&tmp)[1] = usb3->fs_un2.fs_sunx86.fs_qbmask[1];
  80. break;
  81. case UFS_ST_44BSD:
  82. ((__fs32 *)&tmp)[0] = usb3->fs_un2.fs_44.fs_qbmask[0];
  83. ((__fs32 *)&tmp)[1] = usb3->fs_un2.fs_44.fs_qbmask[1];
  84. break;
  85. }
  86. return fs64_to_cpu(sb, tmp);
  87. }
  88. static inline u64
  89. ufs_get_fs_qfmask(struct super_block *sb, struct ufs_super_block_third *usb3)
  90. {
  91. __fs64 tmp;
  92. switch (UFS_SB(sb)->s_flags & UFS_ST_MASK) {
  93. case UFS_ST_SUN:
  94. ((__fs32 *)&tmp)[0] = usb3->fs_un2.fs_sun.fs_qfmask[0];
  95. ((__fs32 *)&tmp)[1] = usb3->fs_un2.fs_sun.fs_qfmask[1];
  96. break;
  97. case UFS_ST_SUNx86:
  98. ((__fs32 *)&tmp)[0] = usb3->fs_un2.fs_sunx86.fs_qfmask[0];
  99. ((__fs32 *)&tmp)[1] = usb3->fs_un2.fs_sunx86.fs_qfmask[1];
  100. break;
  101. case UFS_ST_44BSD:
  102. ((__fs32 *)&tmp)[0] = usb3->fs_un2.fs_44.fs_qfmask[0];
  103. ((__fs32 *)&tmp)[1] = usb3->fs_un2.fs_44.fs_qfmask[1];
  104. break;
  105. }
  106. return fs64_to_cpu(sb, tmp);
  107. }
  108. static inline u16
  109. ufs_get_de_namlen(struct super_block *sb, struct ufs_dir_entry *de)
  110. {
  111. if ((UFS_SB(sb)->s_flags & UFS_DE_MASK) == UFS_DE_OLD)
  112. return fs16_to_cpu(sb, de->d_u.d_namlen);
  113. else
  114. return de->d_u.d_44.d_namlen; /* XXX this seems wrong */
  115. }
  116. static inline void
  117. ufs_set_de_namlen(struct super_block *sb, struct ufs_dir_entry *de, u16 value)
  118. {
  119. if ((UFS_SB(sb)->s_flags & UFS_DE_MASK) == UFS_DE_OLD)
  120. de->d_u.d_namlen = cpu_to_fs16(sb, value);
  121. else
  122. de->d_u.d_44.d_namlen = value; /* XXX this seems wrong */
  123. }
  124. static inline void
  125. ufs_set_de_type(struct super_block *sb, struct ufs_dir_entry *de, int mode)
  126. {
  127. if ((UFS_SB(sb)->s_flags & UFS_DE_MASK) != UFS_DE_44BSD)
  128. return;
  129. /*
  130. * TODO turn this into a table lookup
  131. */
  132. switch (mode & S_IFMT) {
  133. case S_IFSOCK:
  134. de->d_u.d_44.d_type = DT_SOCK;
  135. break;
  136. case S_IFLNK:
  137. de->d_u.d_44.d_type = DT_LNK;
  138. break;
  139. case S_IFREG:
  140. de->d_u.d_44.d_type = DT_REG;
  141. break;
  142. case S_IFBLK:
  143. de->d_u.d_44.d_type = DT_BLK;
  144. break;
  145. case S_IFDIR:
  146. de->d_u.d_44.d_type = DT_DIR;
  147. break;
  148. case S_IFCHR:
  149. de->d_u.d_44.d_type = DT_CHR;
  150. break;
  151. case S_IFIFO:
  152. de->d_u.d_44.d_type = DT_FIFO;
  153. break;
  154. default:
  155. de->d_u.d_44.d_type = DT_UNKNOWN;
  156. }
  157. }
  158. static inline u32
  159. ufs_get_inode_uid(struct super_block *sb, struct ufs_inode *inode)
  160. {
  161. switch (UFS_SB(sb)->s_flags & UFS_UID_MASK) {
  162. case UFS_UID_EFT:
  163. return fs32_to_cpu(sb, inode->ui_u3.ui_sun.ui_uid);
  164. case UFS_UID_44BSD:
  165. return fs32_to_cpu(sb, inode->ui_u3.ui_44.ui_uid);
  166. default:
  167. return fs16_to_cpu(sb, inode->ui_u1.oldids.ui_suid);
  168. }
  169. }
  170. static inline void
  171. ufs_set_inode_uid(struct super_block *sb, struct ufs_inode *inode, u32 value)
  172. {
  173. switch (UFS_SB(sb)->s_flags & UFS_UID_MASK) {
  174. case UFS_UID_EFT:
  175. inode->ui_u3.ui_sun.ui_uid = cpu_to_fs32(sb, value);
  176. break;
  177. case UFS_UID_44BSD:
  178. inode->ui_u3.ui_44.ui_uid = cpu_to_fs32(sb, value);
  179. break;
  180. }
  181. inode->ui_u1.oldids.ui_suid = cpu_to_fs16(sb, value);
  182. }
  183. static inline u32
  184. ufs_get_inode_gid(struct super_block *sb, struct ufs_inode *inode)
  185. {
  186. switch (UFS_SB(sb)->s_flags & UFS_UID_MASK) {
  187. case UFS_UID_EFT:
  188. return fs32_to_cpu(sb, inode->ui_u3.ui_sun.ui_gid);
  189. case UFS_UID_44BSD:
  190. return fs32_to_cpu(sb, inode->ui_u3.ui_44.ui_gid);
  191. default:
  192. return fs16_to_cpu(sb, inode->ui_u1.oldids.ui_sgid);
  193. }
  194. }
  195. static inline void
  196. ufs_set_inode_gid(struct super_block *sb, struct ufs_inode *inode, u32 value)
  197. {
  198. switch (UFS_SB(sb)->s_flags & UFS_UID_MASK) {
  199. case UFS_UID_EFT:
  200. inode->ui_u3.ui_sun.ui_gid = cpu_to_fs32(sb, value);
  201. break;
  202. case UFS_UID_44BSD:
  203. inode->ui_u3.ui_44.ui_gid = cpu_to_fs32(sb, value);
  204. break;
  205. }
  206. inode->ui_u1.oldids.ui_sgid = cpu_to_fs16(sb, value);
  207. }
  208. extern dev_t ufs_get_inode_dev(struct super_block *, struct ufs_inode_info *);
  209. extern void ufs_set_inode_dev(struct super_block *, struct ufs_inode_info *, dev_t);
  210. /*
  211. * These functions manipulate ufs buffers
  212. */
  213. #define ubh_bread(sb,fragment,size) _ubh_bread_(uspi,sb,fragment,size)
  214. extern struct ufs_buffer_head * _ubh_bread_(struct ufs_sb_private_info *, struct super_block *, u64 , u64);
  215. extern struct ufs_buffer_head * ubh_bread_uspi(struct ufs_sb_private_info *, struct super_block *, u64, u64);
  216. extern void ubh_brelse (struct ufs_buffer_head *);
  217. extern void ubh_brelse_uspi (struct ufs_sb_private_info *);
  218. extern void ubh_mark_buffer_dirty (struct ufs_buffer_head *);
  219. extern void ubh_mark_buffer_uptodate (struct ufs_buffer_head *, int);
  220. extern void ubh_ll_rw_block(int, struct ufs_buffer_head *);
  221. extern void ubh_wait_on_buffer (struct ufs_buffer_head *);
  222. extern void ubh_bforget (struct ufs_buffer_head *);
  223. extern int ubh_buffer_dirty (struct ufs_buffer_head *);
  224. #define ubh_ubhcpymem(mem,ubh,size) _ubh_ubhcpymem_(uspi,mem,ubh,size)
  225. extern void _ubh_ubhcpymem_(struct ufs_sb_private_info *, unsigned char *, struct ufs_buffer_head *, unsigned);
  226. #define ubh_memcpyubh(ubh,mem,size) _ubh_memcpyubh_(uspi,ubh,mem,size)
  227. extern void _ubh_memcpyubh_(struct ufs_sb_private_info *, struct ufs_buffer_head *, unsigned char *, unsigned);
  228. /* This functions works with cache pages*/
  229. extern struct page *ufs_get_locked_page(struct address_space *mapping,
  230. pgoff_t index);
  231. static inline void ufs_put_locked_page(struct page *page)
  232. {
  233. unlock_page(page);
  234. page_cache_release(page);
  235. }
  236. /*
  237. * macros and inline function to get important structures from ufs_sb_private_info
  238. */
  239. static inline void *get_usb_offset(struct ufs_sb_private_info *uspi,
  240. unsigned int offset)
  241. {
  242. unsigned int index;
  243. index = offset >> uspi->s_fshift;
  244. offset &= ~uspi->s_fmask;
  245. return uspi->s_ubh.bh[index]->b_data + offset;
  246. }
  247. #define ubh_get_usb_first(uspi) \
  248. ((struct ufs_super_block_first *)get_usb_offset((uspi), 0))
  249. #define ubh_get_usb_second(uspi) \
  250. ((struct ufs_super_block_second *)get_usb_offset((uspi), UFS_SECTOR_SIZE))
  251. #define ubh_get_usb_third(uspi) \
  252. ((struct ufs_super_block_third *)get_usb_offset((uspi), 2*UFS_SECTOR_SIZE))
  253. #define ubh_get_ucg(ubh) \
  254. ((struct ufs_cylinder_group *)((ubh)->bh[0]->b_data))
  255. /*
  256. * Extract byte from ufs_buffer_head
  257. * Extract the bits for a block from a map inside ufs_buffer_head
  258. */
  259. #define ubh_get_addr8(ubh,begin) \
  260. ((u8*)(ubh)->bh[(begin) >> uspi->s_fshift]->b_data + \
  261. ((begin) & ~uspi->s_fmask))
  262. #define ubh_get_addr16(ubh,begin) \
  263. (((__fs16*)((ubh)->bh[(begin) >> (uspi->s_fshift-1)]->b_data)) + \
  264. ((begin) & ((uspi->fsize>>1) - 1)))
  265. #define ubh_get_addr32(ubh,begin) \
  266. (((__fs32*)((ubh)->bh[(begin) >> (uspi->s_fshift-2)]->b_data)) + \
  267. ((begin) & ((uspi->s_fsize>>2) - 1)))
  268. #define ubh_get_addr64(ubh,begin) \
  269. (((__fs64*)((ubh)->bh[(begin) >> (uspi->s_fshift-3)]->b_data)) + \
  270. ((begin) & ((uspi->s_fsize>>3) - 1)))
  271. #define ubh_get_addr ubh_get_addr8
  272. static inline void *ubh_get_data_ptr(struct ufs_sb_private_info *uspi,
  273. struct ufs_buffer_head *ubh,
  274. u64 blk)
  275. {
  276. if (uspi->fs_magic == UFS2_MAGIC)
  277. return ubh_get_addr64(ubh, blk);
  278. else
  279. return ubh_get_addr32(ubh, blk);
  280. }
  281. #define ubh_blkmap(ubh,begin,bit) \
  282. ((*ubh_get_addr(ubh, (begin) + ((bit) >> 3)) >> ((bit) & 7)) & (0xff >> (UFS_MAXFRAG - uspi->s_fpb)))
  283. /*
  284. * Determine the number of available frags given a
  285. * percentage to hold in reserve.
  286. */
  287. static inline u64
  288. ufs_freespace(struct ufs_sb_private_info *uspi, int percentreserved)
  289. {
  290. return ufs_blkstofrags(uspi->cs_total.cs_nbfree) +
  291. uspi->cs_total.cs_nffree -
  292. (uspi->s_dsize * (percentreserved) / 100);
  293. }
  294. /*
  295. * Macros to access cylinder group array structures
  296. */
  297. #define ubh_cg_blktot(ucpi,cylno) \
  298. (*((__fs32*)ubh_get_addr(UCPI_UBH(ucpi), (ucpi)->c_btotoff + ((cylno) << 2))))
  299. #define ubh_cg_blks(ucpi,cylno,rpos) \
  300. (*((__fs16*)ubh_get_addr(UCPI_UBH(ucpi), \
  301. (ucpi)->c_boff + (((cylno) * uspi->s_nrpos + (rpos)) << 1 ))))
  302. /*
  303. * Bitmap operations
  304. * These functions work like classical bitmap operations.
  305. * The difference is that we don't have the whole bitmap
  306. * in one contiguous chunk of memory, but in several buffers.
  307. * The parameters of each function are super_block, ufs_buffer_head and
  308. * position of the beginning of the bitmap.
  309. */
  310. #define ubh_setbit(ubh,begin,bit) \
  311. (*ubh_get_addr(ubh, (begin) + ((bit) >> 3)) |= (1 << ((bit) & 7)))
  312. #define ubh_clrbit(ubh,begin,bit) \
  313. (*ubh_get_addr (ubh, (begin) + ((bit) >> 3)) &= ~(1 << ((bit) & 7)))
  314. #define ubh_isset(ubh,begin,bit) \
  315. (*ubh_get_addr (ubh, (begin) + ((bit) >> 3)) & (1 << ((bit) & 7)))
  316. #define ubh_isclr(ubh,begin,bit) (!ubh_isset(ubh,begin,bit))
  317. #define ubh_find_first_zero_bit(ubh,begin,size) _ubh_find_next_zero_bit_(uspi,ubh,begin,size,0)
  318. #define ubh_find_next_zero_bit(ubh,begin,size,offset) _ubh_find_next_zero_bit_(uspi,ubh,begin,size,offset)
  319. static inline unsigned _ubh_find_next_zero_bit_(
  320. struct ufs_sb_private_info * uspi, struct ufs_buffer_head * ubh,
  321. unsigned begin, unsigned size, unsigned offset)
  322. {
  323. unsigned base, count, pos;
  324. size -= offset;
  325. begin <<= 3;
  326. offset += begin;
  327. base = offset >> uspi->s_bpfshift;
  328. offset &= uspi->s_bpfmask;
  329. for (;;) {
  330. count = min_t(unsigned int, size + offset, uspi->s_bpf);
  331. size -= count - offset;
  332. pos = ext2_find_next_zero_bit (ubh->bh[base]->b_data, count, offset);
  333. if (pos < count || !size)
  334. break;
  335. base++;
  336. offset = 0;
  337. }
  338. return (base << uspi->s_bpfshift) + pos - begin;
  339. }
  340. static inline unsigned find_last_zero_bit (unsigned char * bitmap,
  341. unsigned size, unsigned offset)
  342. {
  343. unsigned bit, i;
  344. unsigned char * mapp;
  345. unsigned char map;
  346. mapp = bitmap + (size >> 3);
  347. map = *mapp--;
  348. bit = 1 << (size & 7);
  349. for (i = size; i > offset; i--) {
  350. if ((map & bit) == 0)
  351. break;
  352. if ((i & 7) != 0) {
  353. bit >>= 1;
  354. } else {
  355. map = *mapp--;
  356. bit = 1 << 7;
  357. }
  358. }
  359. return i;
  360. }
  361. #define ubh_find_last_zero_bit(ubh,begin,size,offset) _ubh_find_last_zero_bit_(uspi,ubh,begin,size,offset)
  362. static inline unsigned _ubh_find_last_zero_bit_(
  363. struct ufs_sb_private_info * uspi, struct ufs_buffer_head * ubh,
  364. unsigned begin, unsigned start, unsigned end)
  365. {
  366. unsigned base, count, pos, size;
  367. size = start - end;
  368. begin <<= 3;
  369. start += begin;
  370. base = start >> uspi->s_bpfshift;
  371. start &= uspi->s_bpfmask;
  372. for (;;) {
  373. count = min_t(unsigned int,
  374. size + (uspi->s_bpf - start), uspi->s_bpf)
  375. - (uspi->s_bpf - start);
  376. size -= count;
  377. pos = find_last_zero_bit (ubh->bh[base]->b_data,
  378. start, start - count);
  379. if (pos > start - count || !size)
  380. break;
  381. base--;
  382. start = uspi->s_bpf;
  383. }
  384. return (base << uspi->s_bpfshift) + pos - begin;
  385. }
  386. #define ubh_isblockclear(ubh,begin,block) (!_ubh_isblockset_(uspi,ubh,begin,block))
  387. #define ubh_isblockset(ubh,begin,block) _ubh_isblockset_(uspi,ubh,begin,block)
  388. static inline int _ubh_isblockset_(struct ufs_sb_private_info * uspi,
  389. struct ufs_buffer_head * ubh, unsigned begin, unsigned block)
  390. {
  391. switch (uspi->s_fpb) {
  392. case 8:
  393. return (*ubh_get_addr (ubh, begin + block) == 0xff);
  394. case 4:
  395. return (*ubh_get_addr (ubh, begin + (block >> 1)) == (0x0f << ((block & 0x01) << 2)));
  396. case 2:
  397. return (*ubh_get_addr (ubh, begin + (block >> 2)) == (0x03 << ((block & 0x03) << 1)));
  398. case 1:
  399. return (*ubh_get_addr (ubh, begin + (block >> 3)) == (0x01 << (block & 0x07)));
  400. }
  401. return 0;
  402. }
  403. #define ubh_clrblock(ubh,begin,block) _ubh_clrblock_(uspi,ubh,begin,block)
  404. static inline void _ubh_clrblock_(struct ufs_sb_private_info * uspi,
  405. struct ufs_buffer_head * ubh, unsigned begin, unsigned block)
  406. {
  407. switch (uspi->s_fpb) {
  408. case 8:
  409. *ubh_get_addr (ubh, begin + block) = 0x00;
  410. return;
  411. case 4:
  412. *ubh_get_addr (ubh, begin + (block >> 1)) &= ~(0x0f << ((block & 0x01) << 2));
  413. return;
  414. case 2:
  415. *ubh_get_addr (ubh, begin + (block >> 2)) &= ~(0x03 << ((block & 0x03) << 1));
  416. return;
  417. case 1:
  418. *ubh_get_addr (ubh, begin + (block >> 3)) &= ~(0x01 << ((block & 0x07)));
  419. return;
  420. }
  421. }
  422. #define ubh_setblock(ubh,begin,block) _ubh_setblock_(uspi,ubh,begin,block)
  423. static inline void _ubh_setblock_(struct ufs_sb_private_info * uspi,
  424. struct ufs_buffer_head * ubh, unsigned begin, unsigned block)
  425. {
  426. switch (uspi->s_fpb) {
  427. case 8:
  428. *ubh_get_addr(ubh, begin + block) = 0xff;
  429. return;
  430. case 4:
  431. *ubh_get_addr(ubh, begin + (block >> 1)) |= (0x0f << ((block & 0x01) << 2));
  432. return;
  433. case 2:
  434. *ubh_get_addr(ubh, begin + (block >> 2)) |= (0x03 << ((block & 0x03) << 1));
  435. return;
  436. case 1:
  437. *ubh_get_addr(ubh, begin + (block >> 3)) |= (0x01 << ((block & 0x07)));
  438. return;
  439. }
  440. }
  441. static inline void ufs_fragacct (struct super_block * sb, unsigned blockmap,
  442. __fs32 * fraglist, int cnt)
  443. {
  444. struct ufs_sb_private_info * uspi;
  445. unsigned fragsize, pos;
  446. uspi = UFS_SB(sb)->s_uspi;
  447. fragsize = 0;
  448. for (pos = 0; pos < uspi->s_fpb; pos++) {
  449. if (blockmap & (1 << pos)) {
  450. fragsize++;
  451. }
  452. else if (fragsize > 0) {
  453. fs32_add(sb, &fraglist[fragsize], cnt);
  454. fragsize = 0;
  455. }
  456. }
  457. if (fragsize > 0 && fragsize < uspi->s_fpb)
  458. fs32_add(sb, &fraglist[fragsize], cnt);
  459. }
  460. static inline void *ufs_get_direct_data_ptr(struct ufs_sb_private_info *uspi,
  461. struct ufs_inode_info *ufsi,
  462. unsigned blk)
  463. {
  464. BUG_ON(blk > UFS_TIND_BLOCK);
  465. return uspi->fs_magic == UFS2_MAGIC ?
  466. (void *)&ufsi->i_u1.u2_i_data[blk] :
  467. (void *)&ufsi->i_u1.i_data[blk];
  468. }
  469. static inline u64 ufs_data_ptr_to_cpu(struct super_block *sb, void *p)
  470. {
  471. return UFS_SB(sb)->s_uspi->fs_magic == UFS2_MAGIC ?
  472. fs64_to_cpu(sb, *(__fs64 *)p) :
  473. fs32_to_cpu(sb, *(__fs32 *)p);
  474. }
  475. static inline void ufs_cpu_to_data_ptr(struct super_block *sb, void *p, u64 val)
  476. {
  477. if (UFS_SB(sb)->s_uspi->fs_magic == UFS2_MAGIC)
  478. *(__fs64 *)p = cpu_to_fs64(sb, val);
  479. else
  480. *(__fs32 *)p = cpu_to_fs32(sb, val);
  481. }
  482. static inline void ufs_data_ptr_clear(struct ufs_sb_private_info *uspi,
  483. void *p)
  484. {
  485. if (uspi->fs_magic == UFS2_MAGIC)
  486. *(__fs64 *)p = 0;
  487. else
  488. *(__fs32 *)p = 0;
  489. }
  490. static inline int ufs_is_data_ptr_zero(struct ufs_sb_private_info *uspi,
  491. void *p)
  492. {
  493. if (uspi->fs_magic == UFS2_MAGIC)
  494. return *(__fs64 *)p == 0;
  495. else
  496. return *(__fs32 *)p == 0;
  497. }