util.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  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. extern int __ufs_write_begin(struct file *file, struct address_space *mapping,
  211. loff_t pos, unsigned len, unsigned flags,
  212. struct page **pagep, void **fsdata);
  213. /*
  214. * These functions manipulate ufs buffers
  215. */
  216. #define ubh_bread(sb,fragment,size) _ubh_bread_(uspi,sb,fragment,size)
  217. extern struct ufs_buffer_head * _ubh_bread_(struct ufs_sb_private_info *, struct super_block *, u64 , u64);
  218. extern struct ufs_buffer_head * ubh_bread_uspi(struct ufs_sb_private_info *, struct super_block *, u64, u64);
  219. extern void ubh_brelse (struct ufs_buffer_head *);
  220. extern void ubh_brelse_uspi (struct ufs_sb_private_info *);
  221. extern void ubh_mark_buffer_dirty (struct ufs_buffer_head *);
  222. extern void ubh_mark_buffer_uptodate (struct ufs_buffer_head *, int);
  223. extern void ubh_ll_rw_block(int, struct ufs_buffer_head *);
  224. extern void ubh_wait_on_buffer (struct ufs_buffer_head *);
  225. extern void ubh_bforget (struct ufs_buffer_head *);
  226. extern int ubh_buffer_dirty (struct ufs_buffer_head *);
  227. #define ubh_ubhcpymem(mem,ubh,size) _ubh_ubhcpymem_(uspi,mem,ubh,size)
  228. extern void _ubh_ubhcpymem_(struct ufs_sb_private_info *, unsigned char *, struct ufs_buffer_head *, unsigned);
  229. #define ubh_memcpyubh(ubh,mem,size) _ubh_memcpyubh_(uspi,ubh,mem,size)
  230. extern void _ubh_memcpyubh_(struct ufs_sb_private_info *, struct ufs_buffer_head *, unsigned char *, unsigned);
  231. /* This functions works with cache pages*/
  232. extern struct page *ufs_get_locked_page(struct address_space *mapping,
  233. pgoff_t index);
  234. static inline void ufs_put_locked_page(struct page *page)
  235. {
  236. unlock_page(page);
  237. page_cache_release(page);
  238. }
  239. /*
  240. * macros and inline function to get important structures from ufs_sb_private_info
  241. */
  242. static inline void *get_usb_offset(struct ufs_sb_private_info *uspi,
  243. unsigned int offset)
  244. {
  245. unsigned int index;
  246. index = offset >> uspi->s_fshift;
  247. offset &= ~uspi->s_fmask;
  248. return uspi->s_ubh.bh[index]->b_data + offset;
  249. }
  250. #define ubh_get_usb_first(uspi) \
  251. ((struct ufs_super_block_first *)get_usb_offset((uspi), 0))
  252. #define ubh_get_usb_second(uspi) \
  253. ((struct ufs_super_block_second *)get_usb_offset((uspi), UFS_SECTOR_SIZE))
  254. #define ubh_get_usb_third(uspi) \
  255. ((struct ufs_super_block_third *)get_usb_offset((uspi), 2*UFS_SECTOR_SIZE))
  256. #define ubh_get_ucg(ubh) \
  257. ((struct ufs_cylinder_group *)((ubh)->bh[0]->b_data))
  258. /*
  259. * Extract byte from ufs_buffer_head
  260. * Extract the bits for a block from a map inside ufs_buffer_head
  261. */
  262. #define ubh_get_addr8(ubh,begin) \
  263. ((u8*)(ubh)->bh[(begin) >> uspi->s_fshift]->b_data + \
  264. ((begin) & ~uspi->s_fmask))
  265. #define ubh_get_addr16(ubh,begin) \
  266. (((__fs16*)((ubh)->bh[(begin) >> (uspi->s_fshift-1)]->b_data)) + \
  267. ((begin) & ((uspi->fsize>>1) - 1)))
  268. #define ubh_get_addr32(ubh,begin) \
  269. (((__fs32*)((ubh)->bh[(begin) >> (uspi->s_fshift-2)]->b_data)) + \
  270. ((begin) & ((uspi->s_fsize>>2) - 1)))
  271. #define ubh_get_addr64(ubh,begin) \
  272. (((__fs64*)((ubh)->bh[(begin) >> (uspi->s_fshift-3)]->b_data)) + \
  273. ((begin) & ((uspi->s_fsize>>3) - 1)))
  274. #define ubh_get_addr ubh_get_addr8
  275. static inline void *ubh_get_data_ptr(struct ufs_sb_private_info *uspi,
  276. struct ufs_buffer_head *ubh,
  277. u64 blk)
  278. {
  279. if (uspi->fs_magic == UFS2_MAGIC)
  280. return ubh_get_addr64(ubh, blk);
  281. else
  282. return ubh_get_addr32(ubh, blk);
  283. }
  284. #define ubh_blkmap(ubh,begin,bit) \
  285. ((*ubh_get_addr(ubh, (begin) + ((bit) >> 3)) >> ((bit) & 7)) & (0xff >> (UFS_MAXFRAG - uspi->s_fpb)))
  286. /*
  287. * Determine the number of available frags given a
  288. * percentage to hold in reserve.
  289. */
  290. static inline u64
  291. ufs_freespace(struct ufs_sb_private_info *uspi, int percentreserved)
  292. {
  293. return ufs_blkstofrags(uspi->cs_total.cs_nbfree) +
  294. uspi->cs_total.cs_nffree -
  295. (uspi->s_dsize * (percentreserved) / 100);
  296. }
  297. /*
  298. * Macros to access cylinder group array structures
  299. */
  300. #define ubh_cg_blktot(ucpi,cylno) \
  301. (*((__fs32*)ubh_get_addr(UCPI_UBH(ucpi), (ucpi)->c_btotoff + ((cylno) << 2))))
  302. #define ubh_cg_blks(ucpi,cylno,rpos) \
  303. (*((__fs16*)ubh_get_addr(UCPI_UBH(ucpi), \
  304. (ucpi)->c_boff + (((cylno) * uspi->s_nrpos + (rpos)) << 1 ))))
  305. /*
  306. * Bitmap operations
  307. * These functions work like classical bitmap operations.
  308. * The difference is that we don't have the whole bitmap
  309. * in one contiguous chunk of memory, but in several buffers.
  310. * The parameters of each function are super_block, ufs_buffer_head and
  311. * position of the beginning of the bitmap.
  312. */
  313. #define ubh_setbit(ubh,begin,bit) \
  314. (*ubh_get_addr(ubh, (begin) + ((bit) >> 3)) |= (1 << ((bit) & 7)))
  315. #define ubh_clrbit(ubh,begin,bit) \
  316. (*ubh_get_addr (ubh, (begin) + ((bit) >> 3)) &= ~(1 << ((bit) & 7)))
  317. #define ubh_isset(ubh,begin,bit) \
  318. (*ubh_get_addr (ubh, (begin) + ((bit) >> 3)) & (1 << ((bit) & 7)))
  319. #define ubh_isclr(ubh,begin,bit) (!ubh_isset(ubh,begin,bit))
  320. #define ubh_find_first_zero_bit(ubh,begin,size) _ubh_find_next_zero_bit_(uspi,ubh,begin,size,0)
  321. #define ubh_find_next_zero_bit(ubh,begin,size,offset) _ubh_find_next_zero_bit_(uspi,ubh,begin,size,offset)
  322. static inline unsigned _ubh_find_next_zero_bit_(
  323. struct ufs_sb_private_info * uspi, struct ufs_buffer_head * ubh,
  324. unsigned begin, unsigned size, unsigned offset)
  325. {
  326. unsigned base, count, pos;
  327. size -= offset;
  328. begin <<= 3;
  329. offset += begin;
  330. base = offset >> uspi->s_bpfshift;
  331. offset &= uspi->s_bpfmask;
  332. for (;;) {
  333. count = min_t(unsigned int, size + offset, uspi->s_bpf);
  334. size -= count - offset;
  335. pos = ext2_find_next_zero_bit (ubh->bh[base]->b_data, count, offset);
  336. if (pos < count || !size)
  337. break;
  338. base++;
  339. offset = 0;
  340. }
  341. return (base << uspi->s_bpfshift) + pos - begin;
  342. }
  343. static inline unsigned find_last_zero_bit (unsigned char * bitmap,
  344. unsigned size, unsigned offset)
  345. {
  346. unsigned bit, i;
  347. unsigned char * mapp;
  348. unsigned char map;
  349. mapp = bitmap + (size >> 3);
  350. map = *mapp--;
  351. bit = 1 << (size & 7);
  352. for (i = size; i > offset; i--) {
  353. if ((map & bit) == 0)
  354. break;
  355. if ((i & 7) != 0) {
  356. bit >>= 1;
  357. } else {
  358. map = *mapp--;
  359. bit = 1 << 7;
  360. }
  361. }
  362. return i;
  363. }
  364. #define ubh_find_last_zero_bit(ubh,begin,size,offset) _ubh_find_last_zero_bit_(uspi,ubh,begin,size,offset)
  365. static inline unsigned _ubh_find_last_zero_bit_(
  366. struct ufs_sb_private_info * uspi, struct ufs_buffer_head * ubh,
  367. unsigned begin, unsigned start, unsigned end)
  368. {
  369. unsigned base, count, pos, size;
  370. size = start - end;
  371. begin <<= 3;
  372. start += begin;
  373. base = start >> uspi->s_bpfshift;
  374. start &= uspi->s_bpfmask;
  375. for (;;) {
  376. count = min_t(unsigned int,
  377. size + (uspi->s_bpf - start), uspi->s_bpf)
  378. - (uspi->s_bpf - start);
  379. size -= count;
  380. pos = find_last_zero_bit (ubh->bh[base]->b_data,
  381. start, start - count);
  382. if (pos > start - count || !size)
  383. break;
  384. base--;
  385. start = uspi->s_bpf;
  386. }
  387. return (base << uspi->s_bpfshift) + pos - begin;
  388. }
  389. #define ubh_isblockclear(ubh,begin,block) (!_ubh_isblockset_(uspi,ubh,begin,block))
  390. #define ubh_isblockset(ubh,begin,block) _ubh_isblockset_(uspi,ubh,begin,block)
  391. static inline int _ubh_isblockset_(struct ufs_sb_private_info * uspi,
  392. struct ufs_buffer_head * ubh, unsigned begin, unsigned block)
  393. {
  394. switch (uspi->s_fpb) {
  395. case 8:
  396. return (*ubh_get_addr (ubh, begin + block) == 0xff);
  397. case 4:
  398. return (*ubh_get_addr (ubh, begin + (block >> 1)) == (0x0f << ((block & 0x01) << 2)));
  399. case 2:
  400. return (*ubh_get_addr (ubh, begin + (block >> 2)) == (0x03 << ((block & 0x03) << 1)));
  401. case 1:
  402. return (*ubh_get_addr (ubh, begin + (block >> 3)) == (0x01 << (block & 0x07)));
  403. }
  404. return 0;
  405. }
  406. #define ubh_clrblock(ubh,begin,block) _ubh_clrblock_(uspi,ubh,begin,block)
  407. static inline void _ubh_clrblock_(struct ufs_sb_private_info * uspi,
  408. struct ufs_buffer_head * ubh, unsigned begin, unsigned block)
  409. {
  410. switch (uspi->s_fpb) {
  411. case 8:
  412. *ubh_get_addr (ubh, begin + block) = 0x00;
  413. return;
  414. case 4:
  415. *ubh_get_addr (ubh, begin + (block >> 1)) &= ~(0x0f << ((block & 0x01) << 2));
  416. return;
  417. case 2:
  418. *ubh_get_addr (ubh, begin + (block >> 2)) &= ~(0x03 << ((block & 0x03) << 1));
  419. return;
  420. case 1:
  421. *ubh_get_addr (ubh, begin + (block >> 3)) &= ~(0x01 << ((block & 0x07)));
  422. return;
  423. }
  424. }
  425. #define ubh_setblock(ubh,begin,block) _ubh_setblock_(uspi,ubh,begin,block)
  426. static inline void _ubh_setblock_(struct ufs_sb_private_info * uspi,
  427. struct ufs_buffer_head * ubh, unsigned begin, unsigned block)
  428. {
  429. switch (uspi->s_fpb) {
  430. case 8:
  431. *ubh_get_addr(ubh, begin + block) = 0xff;
  432. return;
  433. case 4:
  434. *ubh_get_addr(ubh, begin + (block >> 1)) |= (0x0f << ((block & 0x01) << 2));
  435. return;
  436. case 2:
  437. *ubh_get_addr(ubh, begin + (block >> 2)) |= (0x03 << ((block & 0x03) << 1));
  438. return;
  439. case 1:
  440. *ubh_get_addr(ubh, begin + (block >> 3)) |= (0x01 << ((block & 0x07)));
  441. return;
  442. }
  443. }
  444. static inline void ufs_fragacct (struct super_block * sb, unsigned blockmap,
  445. __fs32 * fraglist, int cnt)
  446. {
  447. struct ufs_sb_private_info * uspi;
  448. unsigned fragsize, pos;
  449. uspi = UFS_SB(sb)->s_uspi;
  450. fragsize = 0;
  451. for (pos = 0; pos < uspi->s_fpb; pos++) {
  452. if (blockmap & (1 << pos)) {
  453. fragsize++;
  454. }
  455. else if (fragsize > 0) {
  456. fs32_add(sb, &fraglist[fragsize], cnt);
  457. fragsize = 0;
  458. }
  459. }
  460. if (fragsize > 0 && fragsize < uspi->s_fpb)
  461. fs32_add(sb, &fraglist[fragsize], cnt);
  462. }
  463. static inline void *ufs_get_direct_data_ptr(struct ufs_sb_private_info *uspi,
  464. struct ufs_inode_info *ufsi,
  465. unsigned blk)
  466. {
  467. BUG_ON(blk > UFS_TIND_BLOCK);
  468. return uspi->fs_magic == UFS2_MAGIC ?
  469. (void *)&ufsi->i_u1.u2_i_data[blk] :
  470. (void *)&ufsi->i_u1.i_data[blk];
  471. }
  472. static inline u64 ufs_data_ptr_to_cpu(struct super_block *sb, void *p)
  473. {
  474. return UFS_SB(sb)->s_uspi->fs_magic == UFS2_MAGIC ?
  475. fs64_to_cpu(sb, *(__fs64 *)p) :
  476. fs32_to_cpu(sb, *(__fs32 *)p);
  477. }
  478. static inline void ufs_cpu_to_data_ptr(struct super_block *sb, void *p, u64 val)
  479. {
  480. if (UFS_SB(sb)->s_uspi->fs_magic == UFS2_MAGIC)
  481. *(__fs64 *)p = cpu_to_fs64(sb, val);
  482. else
  483. *(__fs32 *)p = cpu_to_fs32(sb, val);
  484. }
  485. static inline void ufs_data_ptr_clear(struct ufs_sb_private_info *uspi,
  486. void *p)
  487. {
  488. if (uspi->fs_magic == UFS2_MAGIC)
  489. *(__fs64 *)p = 0;
  490. else
  491. *(__fs32 *)p = 0;
  492. }
  493. static inline int ufs_is_data_ptr_zero(struct ufs_sb_private_info *uspi,
  494. void *p)
  495. {
  496. if (uspi->fs_magic == UFS2_MAGIC)
  497. return *(__fs64 *)p == 0;
  498. else
  499. return *(__fs32 *)p == 0;
  500. }