0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <linux/buffer_head.h>
0011 #include <linux/fs.h>
0012 #include "swab.h"
0013
0014
0015
0016
0017
0018 #define in_range(b,first,len) ((b)>=(first)&&(b)<(first)+(len))
0019
0020
0021
0022
0023 static inline struct ufs_buffer_head *UCPI_UBH(struct ufs_cg_private_info *cpi)
0024 {
0025 return &cpi->c_ubh;
0026 }
0027 static inline struct ufs_buffer_head *USPI_UBH(struct ufs_sb_private_info *spi)
0028 {
0029 return &spi->s_ubh;
0030 }
0031
0032
0033
0034
0035
0036
0037 static inline s32
0038 ufs_get_fs_state(struct super_block *sb, struct ufs_super_block_first *usb1,
0039 struct ufs_super_block_third *usb3)
0040 {
0041 switch (UFS_SB(sb)->s_flags & UFS_ST_MASK) {
0042 case UFS_ST_SUNOS:
0043 if (fs32_to_cpu(sb, usb3->fs_postblformat) == UFS_42POSTBLFMT)
0044 return fs32_to_cpu(sb, usb1->fs_u0.fs_sun.fs_state);
0045 fallthrough;
0046 case UFS_ST_SUN:
0047 return fs32_to_cpu(sb, usb3->fs_un2.fs_sun.fs_state);
0048 case UFS_ST_SUNx86:
0049 return fs32_to_cpu(sb, usb1->fs_u1.fs_sunx86.fs_state);
0050 case UFS_ST_44BSD:
0051 default:
0052 return fs32_to_cpu(sb, usb3->fs_un2.fs_44.fs_state);
0053 }
0054 }
0055
0056 static inline void
0057 ufs_set_fs_state(struct super_block *sb, struct ufs_super_block_first *usb1,
0058 struct ufs_super_block_third *usb3, s32 value)
0059 {
0060 switch (UFS_SB(sb)->s_flags & UFS_ST_MASK) {
0061 case UFS_ST_SUNOS:
0062 if (fs32_to_cpu(sb, usb3->fs_postblformat) == UFS_42POSTBLFMT) {
0063 usb1->fs_u0.fs_sun.fs_state = cpu_to_fs32(sb, value);
0064 break;
0065 }
0066 fallthrough;
0067 case UFS_ST_SUN:
0068 usb3->fs_un2.fs_sun.fs_state = cpu_to_fs32(sb, value);
0069 break;
0070 case UFS_ST_SUNx86:
0071 usb1->fs_u1.fs_sunx86.fs_state = cpu_to_fs32(sb, value);
0072 break;
0073 case UFS_ST_44BSD:
0074 usb3->fs_un2.fs_44.fs_state = cpu_to_fs32(sb, value);
0075 break;
0076 }
0077 }
0078
0079 static inline u32
0080 ufs_get_fs_npsect(struct super_block *sb, struct ufs_super_block_first *usb1,
0081 struct ufs_super_block_third *usb3)
0082 {
0083 if ((UFS_SB(sb)->s_flags & UFS_ST_MASK) == UFS_ST_SUNx86)
0084 return fs32_to_cpu(sb, usb3->fs_un2.fs_sunx86.fs_npsect);
0085 else
0086 return fs32_to_cpu(sb, usb1->fs_u1.fs_sun.fs_npsect);
0087 }
0088
0089 static inline u64
0090 ufs_get_fs_qbmask(struct super_block *sb, struct ufs_super_block_third *usb3)
0091 {
0092 __fs64 tmp;
0093
0094 switch (UFS_SB(sb)->s_flags & UFS_ST_MASK) {
0095 case UFS_ST_SUNOS:
0096 case UFS_ST_SUN:
0097 ((__fs32 *)&tmp)[0] = usb3->fs_un2.fs_sun.fs_qbmask[0];
0098 ((__fs32 *)&tmp)[1] = usb3->fs_un2.fs_sun.fs_qbmask[1];
0099 break;
0100 case UFS_ST_SUNx86:
0101 ((__fs32 *)&tmp)[0] = usb3->fs_un2.fs_sunx86.fs_qbmask[0];
0102 ((__fs32 *)&tmp)[1] = usb3->fs_un2.fs_sunx86.fs_qbmask[1];
0103 break;
0104 case UFS_ST_44BSD:
0105 ((__fs32 *)&tmp)[0] = usb3->fs_un2.fs_44.fs_qbmask[0];
0106 ((__fs32 *)&tmp)[1] = usb3->fs_un2.fs_44.fs_qbmask[1];
0107 break;
0108 }
0109
0110 return fs64_to_cpu(sb, tmp);
0111 }
0112
0113 static inline u64
0114 ufs_get_fs_qfmask(struct super_block *sb, struct ufs_super_block_third *usb3)
0115 {
0116 __fs64 tmp;
0117
0118 switch (UFS_SB(sb)->s_flags & UFS_ST_MASK) {
0119 case UFS_ST_SUNOS:
0120 case UFS_ST_SUN:
0121 ((__fs32 *)&tmp)[0] = usb3->fs_un2.fs_sun.fs_qfmask[0];
0122 ((__fs32 *)&tmp)[1] = usb3->fs_un2.fs_sun.fs_qfmask[1];
0123 break;
0124 case UFS_ST_SUNx86:
0125 ((__fs32 *)&tmp)[0] = usb3->fs_un2.fs_sunx86.fs_qfmask[0];
0126 ((__fs32 *)&tmp)[1] = usb3->fs_un2.fs_sunx86.fs_qfmask[1];
0127 break;
0128 case UFS_ST_44BSD:
0129 ((__fs32 *)&tmp)[0] = usb3->fs_un2.fs_44.fs_qfmask[0];
0130 ((__fs32 *)&tmp)[1] = usb3->fs_un2.fs_44.fs_qfmask[1];
0131 break;
0132 }
0133
0134 return fs64_to_cpu(sb, tmp);
0135 }
0136
0137 static inline u16
0138 ufs_get_de_namlen(struct super_block *sb, struct ufs_dir_entry *de)
0139 {
0140 if ((UFS_SB(sb)->s_flags & UFS_DE_MASK) == UFS_DE_OLD)
0141 return fs16_to_cpu(sb, de->d_u.d_namlen);
0142 else
0143 return de->d_u.d_44.d_namlen;
0144 }
0145
0146 static inline void
0147 ufs_set_de_namlen(struct super_block *sb, struct ufs_dir_entry *de, u16 value)
0148 {
0149 if ((UFS_SB(sb)->s_flags & UFS_DE_MASK) == UFS_DE_OLD)
0150 de->d_u.d_namlen = cpu_to_fs16(sb, value);
0151 else
0152 de->d_u.d_44.d_namlen = value;
0153 }
0154
0155 static inline void
0156 ufs_set_de_type(struct super_block *sb, struct ufs_dir_entry *de, int mode)
0157 {
0158 if ((UFS_SB(sb)->s_flags & UFS_DE_MASK) != UFS_DE_44BSD)
0159 return;
0160
0161
0162
0163
0164 switch (mode & S_IFMT) {
0165 case S_IFSOCK:
0166 de->d_u.d_44.d_type = DT_SOCK;
0167 break;
0168 case S_IFLNK:
0169 de->d_u.d_44.d_type = DT_LNK;
0170 break;
0171 case S_IFREG:
0172 de->d_u.d_44.d_type = DT_REG;
0173 break;
0174 case S_IFBLK:
0175 de->d_u.d_44.d_type = DT_BLK;
0176 break;
0177 case S_IFDIR:
0178 de->d_u.d_44.d_type = DT_DIR;
0179 break;
0180 case S_IFCHR:
0181 de->d_u.d_44.d_type = DT_CHR;
0182 break;
0183 case S_IFIFO:
0184 de->d_u.d_44.d_type = DT_FIFO;
0185 break;
0186 default:
0187 de->d_u.d_44.d_type = DT_UNKNOWN;
0188 }
0189 }
0190
0191 static inline u32
0192 ufs_get_inode_uid(struct super_block *sb, struct ufs_inode *inode)
0193 {
0194 switch (UFS_SB(sb)->s_flags & UFS_UID_MASK) {
0195 case UFS_UID_44BSD:
0196 return fs32_to_cpu(sb, inode->ui_u3.ui_44.ui_uid);
0197 case UFS_UID_EFT:
0198 if (inode->ui_u1.oldids.ui_suid == 0xFFFF)
0199 return fs32_to_cpu(sb, inode->ui_u3.ui_sun.ui_uid);
0200 fallthrough;
0201 default:
0202 return fs16_to_cpu(sb, inode->ui_u1.oldids.ui_suid);
0203 }
0204 }
0205
0206 static inline void
0207 ufs_set_inode_uid(struct super_block *sb, struct ufs_inode *inode, u32 value)
0208 {
0209 switch (UFS_SB(sb)->s_flags & UFS_UID_MASK) {
0210 case UFS_UID_44BSD:
0211 inode->ui_u3.ui_44.ui_uid = cpu_to_fs32(sb, value);
0212 inode->ui_u1.oldids.ui_suid = cpu_to_fs16(sb, value);
0213 break;
0214 case UFS_UID_EFT:
0215 inode->ui_u3.ui_sun.ui_uid = cpu_to_fs32(sb, value);
0216 if (value > 0xFFFF)
0217 value = 0xFFFF;
0218 fallthrough;
0219 default:
0220 inode->ui_u1.oldids.ui_suid = cpu_to_fs16(sb, value);
0221 break;
0222 }
0223 }
0224
0225 static inline u32
0226 ufs_get_inode_gid(struct super_block *sb, struct ufs_inode *inode)
0227 {
0228 switch (UFS_SB(sb)->s_flags & UFS_UID_MASK) {
0229 case UFS_UID_44BSD:
0230 return fs32_to_cpu(sb, inode->ui_u3.ui_44.ui_gid);
0231 case UFS_UID_EFT:
0232 if (inode->ui_u1.oldids.ui_sgid == 0xFFFF)
0233 return fs32_to_cpu(sb, inode->ui_u3.ui_sun.ui_gid);
0234 fallthrough;
0235 default:
0236 return fs16_to_cpu(sb, inode->ui_u1.oldids.ui_sgid);
0237 }
0238 }
0239
0240 static inline void
0241 ufs_set_inode_gid(struct super_block *sb, struct ufs_inode *inode, u32 value)
0242 {
0243 switch (UFS_SB(sb)->s_flags & UFS_UID_MASK) {
0244 case UFS_UID_44BSD:
0245 inode->ui_u3.ui_44.ui_gid = cpu_to_fs32(sb, value);
0246 inode->ui_u1.oldids.ui_sgid = cpu_to_fs16(sb, value);
0247 break;
0248 case UFS_UID_EFT:
0249 inode->ui_u3.ui_sun.ui_gid = cpu_to_fs32(sb, value);
0250 if (value > 0xFFFF)
0251 value = 0xFFFF;
0252 fallthrough;
0253 default:
0254 inode->ui_u1.oldids.ui_sgid = cpu_to_fs16(sb, value);
0255 break;
0256 }
0257 }
0258
0259 extern dev_t ufs_get_inode_dev(struct super_block *, struct ufs_inode_info *);
0260 extern void ufs_set_inode_dev(struct super_block *, struct ufs_inode_info *, dev_t);
0261 extern int ufs_prepare_chunk(struct page *page, loff_t pos, unsigned len);
0262
0263
0264
0265
0266 #define ubh_bread(sb,fragment,size) _ubh_bread_(uspi,sb,fragment,size)
0267 extern struct ufs_buffer_head * _ubh_bread_(struct ufs_sb_private_info *, struct super_block *, u64 , u64);
0268 extern struct ufs_buffer_head * ubh_bread_uspi(struct ufs_sb_private_info *, struct super_block *, u64, u64);
0269 extern void ubh_brelse (struct ufs_buffer_head *);
0270 extern void ubh_brelse_uspi (struct ufs_sb_private_info *);
0271 extern void ubh_mark_buffer_dirty (struct ufs_buffer_head *);
0272 extern void ubh_mark_buffer_uptodate (struct ufs_buffer_head *, int);
0273 extern void ubh_sync_block(struct ufs_buffer_head *);
0274 extern void ubh_bforget (struct ufs_buffer_head *);
0275 extern int ubh_buffer_dirty (struct ufs_buffer_head *);
0276 #define ubh_ubhcpymem(mem,ubh,size) _ubh_ubhcpymem_(uspi,mem,ubh,size)
0277 extern void _ubh_ubhcpymem_(struct ufs_sb_private_info *, unsigned char *, struct ufs_buffer_head *, unsigned);
0278 #define ubh_memcpyubh(ubh,mem,size) _ubh_memcpyubh_(uspi,ubh,mem,size)
0279 extern void _ubh_memcpyubh_(struct ufs_sb_private_info *, struct ufs_buffer_head *, unsigned char *, unsigned);
0280
0281
0282 extern struct page *ufs_get_locked_page(struct address_space *mapping,
0283 pgoff_t index);
0284 static inline void ufs_put_locked_page(struct page *page)
0285 {
0286 unlock_page(page);
0287 put_page(page);
0288 }
0289
0290
0291
0292
0293
0294
0295 static inline void *get_usb_offset(struct ufs_sb_private_info *uspi,
0296 unsigned int offset)
0297 {
0298 unsigned int index;
0299
0300 index = offset >> uspi->s_fshift;
0301 offset &= ~uspi->s_fmask;
0302 return uspi->s_ubh.bh[index]->b_data + offset;
0303 }
0304
0305 #define ubh_get_usb_first(uspi) \
0306 ((struct ufs_super_block_first *)get_usb_offset((uspi), 0))
0307
0308 #define ubh_get_usb_second(uspi) \
0309 ((struct ufs_super_block_second *)get_usb_offset((uspi), UFS_SECTOR_SIZE))
0310
0311 #define ubh_get_usb_third(uspi) \
0312 ((struct ufs_super_block_third *)get_usb_offset((uspi), 2*UFS_SECTOR_SIZE))
0313
0314
0315 #define ubh_get_ucg(ubh) \
0316 ((struct ufs_cylinder_group *)((ubh)->bh[0]->b_data))
0317
0318
0319
0320
0321
0322
0323 #define ubh_get_addr8(ubh,begin) \
0324 ((u8*)(ubh)->bh[(begin) >> uspi->s_fshift]->b_data + \
0325 ((begin) & ~uspi->s_fmask))
0326
0327 #define ubh_get_addr16(ubh,begin) \
0328 (((__fs16*)((ubh)->bh[(begin) >> (uspi->s_fshift-1)]->b_data)) + \
0329 ((begin) & ((uspi->fsize>>1) - 1)))
0330
0331 #define ubh_get_addr32(ubh,begin) \
0332 (((__fs32*)((ubh)->bh[(begin) >> (uspi->s_fshift-2)]->b_data)) + \
0333 ((begin) & ((uspi->s_fsize>>2) - 1)))
0334
0335 #define ubh_get_addr64(ubh,begin) \
0336 (((__fs64*)((ubh)->bh[(begin) >> (uspi->s_fshift-3)]->b_data)) + \
0337 ((begin) & ((uspi->s_fsize>>3) - 1)))
0338
0339 #define ubh_get_addr ubh_get_addr8
0340
0341 static inline void *ubh_get_data_ptr(struct ufs_sb_private_info *uspi,
0342 struct ufs_buffer_head *ubh,
0343 u64 blk)
0344 {
0345 if (uspi->fs_magic == UFS2_MAGIC)
0346 return ubh_get_addr64(ubh, blk);
0347 else
0348 return ubh_get_addr32(ubh, blk);
0349 }
0350
0351 #define ubh_blkmap(ubh,begin,bit) \
0352 ((*ubh_get_addr(ubh, (begin) + ((bit) >> 3)) >> ((bit) & 7)) & (0xff >> (UFS_MAXFRAG - uspi->s_fpb)))
0353
0354 static inline u64
0355 ufs_freefrags(struct ufs_sb_private_info *uspi)
0356 {
0357 return ufs_blkstofrags(uspi->cs_total.cs_nbfree) +
0358 uspi->cs_total.cs_nffree;
0359 }
0360
0361
0362
0363
0364 #define ubh_cg_blktot(ucpi,cylno) \
0365 (*((__fs32*)ubh_get_addr(UCPI_UBH(ucpi), (ucpi)->c_btotoff + ((cylno) << 2))))
0366
0367 #define ubh_cg_blks(ucpi,cylno,rpos) \
0368 (*((__fs16*)ubh_get_addr(UCPI_UBH(ucpi), \
0369 (ucpi)->c_boff + (((cylno) * uspi->s_nrpos + (rpos)) << 1 ))))
0370
0371
0372
0373
0374
0375
0376
0377
0378
0379 #define ubh_setbit(ubh,begin,bit) \
0380 (*ubh_get_addr(ubh, (begin) + ((bit) >> 3)) |= (1 << ((bit) & 7)))
0381
0382 #define ubh_clrbit(ubh,begin,bit) \
0383 (*ubh_get_addr (ubh, (begin) + ((bit) >> 3)) &= ~(1 << ((bit) & 7)))
0384
0385 #define ubh_isset(ubh,begin,bit) \
0386 (*ubh_get_addr (ubh, (begin) + ((bit) >> 3)) & (1 << ((bit) & 7)))
0387
0388 #define ubh_isclr(ubh,begin,bit) (!ubh_isset(ubh,begin,bit))
0389
0390 #define ubh_find_first_zero_bit(ubh,begin,size) _ubh_find_next_zero_bit_(uspi,ubh,begin,size,0)
0391
0392 #define ubh_find_next_zero_bit(ubh,begin,size,offset) _ubh_find_next_zero_bit_(uspi,ubh,begin,size,offset)
0393 static inline unsigned _ubh_find_next_zero_bit_(
0394 struct ufs_sb_private_info * uspi, struct ufs_buffer_head * ubh,
0395 unsigned begin, unsigned size, unsigned offset)
0396 {
0397 unsigned base, count, pos;
0398
0399 size -= offset;
0400 begin <<= 3;
0401 offset += begin;
0402 base = offset >> uspi->s_bpfshift;
0403 offset &= uspi->s_bpfmask;
0404 for (;;) {
0405 count = min_t(unsigned int, size + offset, uspi->s_bpf);
0406 size -= count - offset;
0407 pos = find_next_zero_bit_le(ubh->bh[base]->b_data, count, offset);
0408 if (pos < count || !size)
0409 break;
0410 base++;
0411 offset = 0;
0412 }
0413 return (base << uspi->s_bpfshift) + pos - begin;
0414 }
0415
0416 static inline unsigned find_last_zero_bit (unsigned char * bitmap,
0417 unsigned size, unsigned offset)
0418 {
0419 unsigned bit, i;
0420 unsigned char * mapp;
0421 unsigned char map;
0422
0423 mapp = bitmap + (size >> 3);
0424 map = *mapp--;
0425 bit = 1 << (size & 7);
0426 for (i = size; i > offset; i--) {
0427 if ((map & bit) == 0)
0428 break;
0429 if ((i & 7) != 0) {
0430 bit >>= 1;
0431 } else {
0432 map = *mapp--;
0433 bit = 1 << 7;
0434 }
0435 }
0436 return i;
0437 }
0438
0439 #define ubh_find_last_zero_bit(ubh,begin,size,offset) _ubh_find_last_zero_bit_(uspi,ubh,begin,size,offset)
0440 static inline unsigned _ubh_find_last_zero_bit_(
0441 struct ufs_sb_private_info * uspi, struct ufs_buffer_head * ubh,
0442 unsigned begin, unsigned start, unsigned end)
0443 {
0444 unsigned base, count, pos, size;
0445
0446 size = start - end;
0447 begin <<= 3;
0448 start += begin;
0449 base = start >> uspi->s_bpfshift;
0450 start &= uspi->s_bpfmask;
0451 for (;;) {
0452 count = min_t(unsigned int,
0453 size + (uspi->s_bpf - start), uspi->s_bpf)
0454 - (uspi->s_bpf - start);
0455 size -= count;
0456 pos = find_last_zero_bit (ubh->bh[base]->b_data,
0457 start, start - count);
0458 if (pos > start - count || !size)
0459 break;
0460 base--;
0461 start = uspi->s_bpf;
0462 }
0463 return (base << uspi->s_bpfshift) + pos - begin;
0464 }
0465
0466 #define ubh_isblockclear(ubh,begin,block) (!_ubh_isblockset_(uspi,ubh,begin,block))
0467
0468 #define ubh_isblockset(ubh,begin,block) _ubh_isblockset_(uspi,ubh,begin,block)
0469 static inline int _ubh_isblockset_(struct ufs_sb_private_info * uspi,
0470 struct ufs_buffer_head * ubh, unsigned begin, unsigned block)
0471 {
0472 u8 mask;
0473 switch (uspi->s_fpb) {
0474 case 8:
0475 return (*ubh_get_addr (ubh, begin + block) == 0xff);
0476 case 4:
0477 mask = 0x0f << ((block & 0x01) << 2);
0478 return (*ubh_get_addr (ubh, begin + (block >> 1)) & mask) == mask;
0479 case 2:
0480 mask = 0x03 << ((block & 0x03) << 1);
0481 return (*ubh_get_addr (ubh, begin + (block >> 2)) & mask) == mask;
0482 case 1:
0483 mask = 0x01 << (block & 0x07);
0484 return (*ubh_get_addr (ubh, begin + (block >> 3)) & mask) == mask;
0485 }
0486 return 0;
0487 }
0488
0489 #define ubh_clrblock(ubh,begin,block) _ubh_clrblock_(uspi,ubh,begin,block)
0490 static inline void _ubh_clrblock_(struct ufs_sb_private_info * uspi,
0491 struct ufs_buffer_head * ubh, unsigned begin, unsigned block)
0492 {
0493 switch (uspi->s_fpb) {
0494 case 8:
0495 *ubh_get_addr (ubh, begin + block) = 0x00;
0496 return;
0497 case 4:
0498 *ubh_get_addr (ubh, begin + (block >> 1)) &= ~(0x0f << ((block & 0x01) << 2));
0499 return;
0500 case 2:
0501 *ubh_get_addr (ubh, begin + (block >> 2)) &= ~(0x03 << ((block & 0x03) << 1));
0502 return;
0503 case 1:
0504 *ubh_get_addr (ubh, begin + (block >> 3)) &= ~(0x01 << ((block & 0x07)));
0505 return;
0506 }
0507 }
0508
0509 #define ubh_setblock(ubh,begin,block) _ubh_setblock_(uspi,ubh,begin,block)
0510 static inline void _ubh_setblock_(struct ufs_sb_private_info * uspi,
0511 struct ufs_buffer_head * ubh, unsigned begin, unsigned block)
0512 {
0513 switch (uspi->s_fpb) {
0514 case 8:
0515 *ubh_get_addr(ubh, begin + block) = 0xff;
0516 return;
0517 case 4:
0518 *ubh_get_addr(ubh, begin + (block >> 1)) |= (0x0f << ((block & 0x01) << 2));
0519 return;
0520 case 2:
0521 *ubh_get_addr(ubh, begin + (block >> 2)) |= (0x03 << ((block & 0x03) << 1));
0522 return;
0523 case 1:
0524 *ubh_get_addr(ubh, begin + (block >> 3)) |= (0x01 << ((block & 0x07)));
0525 return;
0526 }
0527 }
0528
0529 static inline void ufs_fragacct (struct super_block * sb, unsigned blockmap,
0530 __fs32 * fraglist, int cnt)
0531 {
0532 struct ufs_sb_private_info * uspi;
0533 unsigned fragsize, pos;
0534
0535 uspi = UFS_SB(sb)->s_uspi;
0536
0537 fragsize = 0;
0538 for (pos = 0; pos < uspi->s_fpb; pos++) {
0539 if (blockmap & (1 << pos)) {
0540 fragsize++;
0541 }
0542 else if (fragsize > 0) {
0543 fs32_add(sb, &fraglist[fragsize], cnt);
0544 fragsize = 0;
0545 }
0546 }
0547 if (fragsize > 0 && fragsize < uspi->s_fpb)
0548 fs32_add(sb, &fraglist[fragsize], cnt);
0549 }
0550
0551 static inline void *ufs_get_direct_data_ptr(struct ufs_sb_private_info *uspi,
0552 struct ufs_inode_info *ufsi,
0553 unsigned blk)
0554 {
0555 BUG_ON(blk > UFS_TIND_BLOCK);
0556 return uspi->fs_magic == UFS2_MAGIC ?
0557 (void *)&ufsi->i_u1.u2_i_data[blk] :
0558 (void *)&ufsi->i_u1.i_data[blk];
0559 }
0560
0561 static inline u64 ufs_data_ptr_to_cpu(struct super_block *sb, void *p)
0562 {
0563 return UFS_SB(sb)->s_uspi->fs_magic == UFS2_MAGIC ?
0564 fs64_to_cpu(sb, *(__fs64 *)p) :
0565 fs32_to_cpu(sb, *(__fs32 *)p);
0566 }
0567
0568 static inline void ufs_cpu_to_data_ptr(struct super_block *sb, void *p, u64 val)
0569 {
0570 if (UFS_SB(sb)->s_uspi->fs_magic == UFS2_MAGIC)
0571 *(__fs64 *)p = cpu_to_fs64(sb, val);
0572 else
0573 *(__fs32 *)p = cpu_to_fs32(sb, val);
0574 }
0575
0576 static inline void ufs_data_ptr_clear(struct ufs_sb_private_info *uspi,
0577 void *p)
0578 {
0579 if (uspi->fs_magic == UFS2_MAGIC)
0580 *(__fs64 *)p = 0;
0581 else
0582 *(__fs32 *)p = 0;
0583 }
0584
0585 static inline int ufs_is_data_ptr_zero(struct ufs_sb_private_info *uspi,
0586 void *p)
0587 {
0588 if (uspi->fs_magic == UFS2_MAGIC)
0589 return *(__fs64 *)p == 0;
0590 else
0591 return *(__fs32 *)p == 0;
0592 }
0593
0594 static inline __fs32 ufs_get_seconds(struct super_block *sbp)
0595 {
0596 time64_t now = ktime_get_real_seconds();
0597
0598
0599
0600
0601
0602
0603
0604
0605 return cpu_to_fs32(sbp, lower_32_bits(now));
0606 }