b24413180f560 (Greg Kroah-Hartman 2017-11-01 15:07:57 +0100 1) /* SPDX-License-Identifier: GPL-2.0 */
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 2) /*
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 3) * linux/fs/ufs/util.h
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 4) *
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 5) * Copyright (C) 1998
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 6) * Daniel Pirkl <daniel.pirkl@email.cz>
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 7) * Charles University, Faculty of Mathematics and Physics
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 8) */
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 9)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 10) #include <linux/buffer_head.h>
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 11) #include <linux/fs.h>
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 12) #include "swab.h"
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 13)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 14)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 15) /*
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 16) * some useful macros
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 17) */
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 18) #define in_range(b,first,len) ((b)>=(first)&&(b)<(first)+(len))
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 19)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 20) /*
9695ef16ed4e0 (Evgeniy Dushistov 2006-06-25 05:47:22 -0700 21) * functions used for retyping
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 22) */
9695ef16ed4e0 (Evgeniy Dushistov 2006-06-25 05:47:22 -0700 23) static inline struct ufs_buffer_head *UCPI_UBH(struct ufs_cg_private_info *cpi)
9695ef16ed4e0 (Evgeniy Dushistov 2006-06-25 05:47:22 -0700 24) {
9695ef16ed4e0 (Evgeniy Dushistov 2006-06-25 05:47:22 -0700 25) return &cpi->c_ubh;
9695ef16ed4e0 (Evgeniy Dushistov 2006-06-25 05:47:22 -0700 26) }
9695ef16ed4e0 (Evgeniy Dushistov 2006-06-25 05:47:22 -0700 27) static inline struct ufs_buffer_head *USPI_UBH(struct ufs_sb_private_info *spi)
9695ef16ed4e0 (Evgeniy Dushistov 2006-06-25 05:47:22 -0700 28) {
9695ef16ed4e0 (Evgeniy Dushistov 2006-06-25 05:47:22 -0700 29) return &spi->s_ubh;
9695ef16ed4e0 (Evgeniy Dushistov 2006-06-25 05:47:22 -0700 30) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 31)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 32)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 33)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 34) /*
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 35) * macros used for accessing structures
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 36) */
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 37) static inline s32
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 38) ufs_get_fs_state(struct super_block *sb, struct ufs_super_block_first *usb1,
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 39) struct ufs_super_block_third *usb3)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 40) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 41) switch (UFS_SB(sb)->s_flags & UFS_ST_MASK) {
252e211e90ce5 (Mark Fortescue 2007-10-16 23:26:31 -0700 42) case UFS_ST_SUNOS:
252e211e90ce5 (Mark Fortescue 2007-10-16 23:26:31 -0700 43) if (fs32_to_cpu(sb, usb3->fs_postblformat) == UFS_42POSTBLFMT)
252e211e90ce5 (Mark Fortescue 2007-10-16 23:26:31 -0700 44) return fs32_to_cpu(sb, usb1->fs_u0.fs_sun.fs_state);
df561f6688fef (Gustavo A. R. Silva 2020-08-23 17:36:59 -0500 45) fallthrough; /* to UFS_ST_SUN */
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 46) case UFS_ST_SUN:
647b7e87b56f5 (Evgeniy Dushistov 2006-06-25 05:47:29 -0700 47) return fs32_to_cpu(sb, usb3->fs_un2.fs_sun.fs_state);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 48) case UFS_ST_SUNx86:
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 49) return fs32_to_cpu(sb, usb1->fs_u1.fs_sunx86.fs_state);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 50) case UFS_ST_44BSD:
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 51) default:
647b7e87b56f5 (Evgeniy Dushistov 2006-06-25 05:47:29 -0700 52) return fs32_to_cpu(sb, usb3->fs_un2.fs_44.fs_state);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 53) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 54) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 55)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 56) static inline void
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 57) ufs_set_fs_state(struct super_block *sb, struct ufs_super_block_first *usb1,
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 58) struct ufs_super_block_third *usb3, s32 value)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 59) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 60) switch (UFS_SB(sb)->s_flags & UFS_ST_MASK) {
252e211e90ce5 (Mark Fortescue 2007-10-16 23:26:31 -0700 61) case UFS_ST_SUNOS:
f81e8a43871f4 (Roel Kluin 2008-02-23 15:23:29 -0800 62) if (fs32_to_cpu(sb, usb3->fs_postblformat) == UFS_42POSTBLFMT) {
252e211e90ce5 (Mark Fortescue 2007-10-16 23:26:31 -0700 63) usb1->fs_u0.fs_sun.fs_state = cpu_to_fs32(sb, value);
252e211e90ce5 (Mark Fortescue 2007-10-16 23:26:31 -0700 64) break;
252e211e90ce5 (Mark Fortescue 2007-10-16 23:26:31 -0700 65) }
df561f6688fef (Gustavo A. R. Silva 2020-08-23 17:36:59 -0500 66) fallthrough; /* to UFS_ST_SUN */
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 67) case UFS_ST_SUN:
647b7e87b56f5 (Evgeniy Dushistov 2006-06-25 05:47:29 -0700 68) usb3->fs_un2.fs_sun.fs_state = cpu_to_fs32(sb, value);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 69) break;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 70) case UFS_ST_SUNx86:
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 71) usb1->fs_u1.fs_sunx86.fs_state = cpu_to_fs32(sb, value);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 72) break;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 73) case UFS_ST_44BSD:
647b7e87b56f5 (Evgeniy Dushistov 2006-06-25 05:47:29 -0700 74) usb3->fs_un2.fs_44.fs_state = cpu_to_fs32(sb, value);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 75) break;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 76) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 77) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 78)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 79) static inline u32
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 80) ufs_get_fs_npsect(struct super_block *sb, struct ufs_super_block_first *usb1,
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 81) struct ufs_super_block_third *usb3)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 82) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 83) if ((UFS_SB(sb)->s_flags & UFS_ST_MASK) == UFS_ST_SUNx86)
647b7e87b56f5 (Evgeniy Dushistov 2006-06-25 05:47:29 -0700 84) return fs32_to_cpu(sb, usb3->fs_un2.fs_sunx86.fs_npsect);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 85) else
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 86) return fs32_to_cpu(sb, usb1->fs_u1.fs_sun.fs_npsect);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 87) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 88)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 89) static inline u64
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 90) ufs_get_fs_qbmask(struct super_block *sb, struct ufs_super_block_third *usb3)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 91) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 92) __fs64 tmp;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 93)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 94) switch (UFS_SB(sb)->s_flags & UFS_ST_MASK) {
252e211e90ce5 (Mark Fortescue 2007-10-16 23:26:31 -0700 95) case UFS_ST_SUNOS:
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 96) case UFS_ST_SUN:
647b7e87b56f5 (Evgeniy Dushistov 2006-06-25 05:47:29 -0700 97) ((__fs32 *)&tmp)[0] = usb3->fs_un2.fs_sun.fs_qbmask[0];
647b7e87b56f5 (Evgeniy Dushistov 2006-06-25 05:47:29 -0700 98) ((__fs32 *)&tmp)[1] = usb3->fs_un2.fs_sun.fs_qbmask[1];
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 99) break;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 100) case UFS_ST_SUNx86:
647b7e87b56f5 (Evgeniy Dushistov 2006-06-25 05:47:29 -0700 101) ((__fs32 *)&tmp)[0] = usb3->fs_un2.fs_sunx86.fs_qbmask[0];
647b7e87b56f5 (Evgeniy Dushistov 2006-06-25 05:47:29 -0700 102) ((__fs32 *)&tmp)[1] = usb3->fs_un2.fs_sunx86.fs_qbmask[1];
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 103) break;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 104) case UFS_ST_44BSD:
647b7e87b56f5 (Evgeniy Dushistov 2006-06-25 05:47:29 -0700 105) ((__fs32 *)&tmp)[0] = usb3->fs_un2.fs_44.fs_qbmask[0];
647b7e87b56f5 (Evgeniy Dushistov 2006-06-25 05:47:29 -0700 106) ((__fs32 *)&tmp)[1] = usb3->fs_un2.fs_44.fs_qbmask[1];
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 107) break;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 108) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 109)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 110) return fs64_to_cpu(sb, tmp);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 111) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 112)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 113) static inline u64
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 114) ufs_get_fs_qfmask(struct super_block *sb, struct ufs_super_block_third *usb3)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 115) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 116) __fs64 tmp;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 117)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 118) switch (UFS_SB(sb)->s_flags & UFS_ST_MASK) {
252e211e90ce5 (Mark Fortescue 2007-10-16 23:26:31 -0700 119) case UFS_ST_SUNOS:
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 120) case UFS_ST_SUN:
647b7e87b56f5 (Evgeniy Dushistov 2006-06-25 05:47:29 -0700 121) ((__fs32 *)&tmp)[0] = usb3->fs_un2.fs_sun.fs_qfmask[0];
647b7e87b56f5 (Evgeniy Dushistov 2006-06-25 05:47:29 -0700 122) ((__fs32 *)&tmp)[1] = usb3->fs_un2.fs_sun.fs_qfmask[1];
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 123) break;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 124) case UFS_ST_SUNx86:
647b7e87b56f5 (Evgeniy Dushistov 2006-06-25 05:47:29 -0700 125) ((__fs32 *)&tmp)[0] = usb3->fs_un2.fs_sunx86.fs_qfmask[0];
647b7e87b56f5 (Evgeniy Dushistov 2006-06-25 05:47:29 -0700 126) ((__fs32 *)&tmp)[1] = usb3->fs_un2.fs_sunx86.fs_qfmask[1];
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 127) break;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 128) case UFS_ST_44BSD:
647b7e87b56f5 (Evgeniy Dushistov 2006-06-25 05:47:29 -0700 129) ((__fs32 *)&tmp)[0] = usb3->fs_un2.fs_44.fs_qfmask[0];
647b7e87b56f5 (Evgeniy Dushistov 2006-06-25 05:47:29 -0700 130) ((__fs32 *)&tmp)[1] = usb3->fs_un2.fs_44.fs_qfmask[1];
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 131) break;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 132) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 133)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 134) return fs64_to_cpu(sb, tmp);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 135) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 136)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 137) static inline u16
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 138) ufs_get_de_namlen(struct super_block *sb, struct ufs_dir_entry *de)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 139) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 140) if ((UFS_SB(sb)->s_flags & UFS_DE_MASK) == UFS_DE_OLD)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 141) return fs16_to_cpu(sb, de->d_u.d_namlen);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 142) else
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 143) return de->d_u.d_44.d_namlen; /* XXX this seems wrong */
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 144) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 145)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 146) static inline void
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 147) ufs_set_de_namlen(struct super_block *sb, struct ufs_dir_entry *de, u16 value)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 148) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 149) if ((UFS_SB(sb)->s_flags & UFS_DE_MASK) == UFS_DE_OLD)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 150) de->d_u.d_namlen = cpu_to_fs16(sb, value);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 151) else
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 152) de->d_u.d_44.d_namlen = value; /* XXX this seems wrong */
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 153) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 154)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 155) static inline void
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 156) ufs_set_de_type(struct super_block *sb, struct ufs_dir_entry *de, int mode)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 157) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 158) if ((UFS_SB(sb)->s_flags & UFS_DE_MASK) != UFS_DE_44BSD)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 159) return;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 160)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 161) /*
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 162) * TODO turn this into a table lookup
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 163) */
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 164) switch (mode & S_IFMT) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 165) case S_IFSOCK:
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 166) de->d_u.d_44.d_type = DT_SOCK;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 167) break;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 168) case S_IFLNK:
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 169) de->d_u.d_44.d_type = DT_LNK;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 170) break;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 171) case S_IFREG:
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 172) de->d_u.d_44.d_type = DT_REG;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 173) break;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 174) case S_IFBLK:
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 175) de->d_u.d_44.d_type = DT_BLK;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 176) break;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 177) case S_IFDIR:
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 178) de->d_u.d_44.d_type = DT_DIR;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 179) break;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 180) case S_IFCHR:
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 181) de->d_u.d_44.d_type = DT_CHR;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 182) break;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 183) case S_IFIFO:
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 184) de->d_u.d_44.d_type = DT_FIFO;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 185) break;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 186) default:
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 187) de->d_u.d_44.d_type = DT_UNKNOWN;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 188) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 189) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 190)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 191) static inline u32
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 192) ufs_get_inode_uid(struct super_block *sb, struct ufs_inode *inode)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 193) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 194) switch (UFS_SB(sb)->s_flags & UFS_UID_MASK) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 195) case UFS_UID_44BSD:
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 196) return fs32_to_cpu(sb, inode->ui_u3.ui_44.ui_uid);
252e211e90ce5 (Mark Fortescue 2007-10-16 23:26:31 -0700 197) case UFS_UID_EFT:
252e211e90ce5 (Mark Fortescue 2007-10-16 23:26:31 -0700 198) if (inode->ui_u1.oldids.ui_suid == 0xFFFF)
252e211e90ce5 (Mark Fortescue 2007-10-16 23:26:31 -0700 199) return fs32_to_cpu(sb, inode->ui_u3.ui_sun.ui_uid);
df561f6688fef (Gustavo A. R. Silva 2020-08-23 17:36:59 -0500 200) fallthrough;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 201) default:
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 202) return fs16_to_cpu(sb, inode->ui_u1.oldids.ui_suid);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 203) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 204) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 205)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 206) static inline void
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 207) ufs_set_inode_uid(struct super_block *sb, struct ufs_inode *inode, u32 value)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 208) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 209) switch (UFS_SB(sb)->s_flags & UFS_UID_MASK) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 210) case UFS_UID_44BSD:
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 211) inode->ui_u3.ui_44.ui_uid = cpu_to_fs32(sb, value);
252e211e90ce5 (Mark Fortescue 2007-10-16 23:26:31 -0700 212) inode->ui_u1.oldids.ui_suid = cpu_to_fs16(sb, value);
252e211e90ce5 (Mark Fortescue 2007-10-16 23:26:31 -0700 213) break;
252e211e90ce5 (Mark Fortescue 2007-10-16 23:26:31 -0700 214) case UFS_UID_EFT:
252e211e90ce5 (Mark Fortescue 2007-10-16 23:26:31 -0700 215) inode->ui_u3.ui_sun.ui_uid = cpu_to_fs32(sb, value);
252e211e90ce5 (Mark Fortescue 2007-10-16 23:26:31 -0700 216) if (value > 0xFFFF)
252e211e90ce5 (Mark Fortescue 2007-10-16 23:26:31 -0700 217) value = 0xFFFF;
df561f6688fef (Gustavo A. R. Silva 2020-08-23 17:36:59 -0500 218) fallthrough;
252e211e90ce5 (Mark Fortescue 2007-10-16 23:26:31 -0700 219) default:
252e211e90ce5 (Mark Fortescue 2007-10-16 23:26:31 -0700 220) inode->ui_u1.oldids.ui_suid = cpu_to_fs16(sb, value);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 221) break;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 222) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 223) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 224)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 225) static inline u32
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 226) ufs_get_inode_gid(struct super_block *sb, struct ufs_inode *inode)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 227) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 228) switch (UFS_SB(sb)->s_flags & UFS_UID_MASK) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 229) case UFS_UID_44BSD:
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 230) return fs32_to_cpu(sb, inode->ui_u3.ui_44.ui_gid);
252e211e90ce5 (Mark Fortescue 2007-10-16 23:26:31 -0700 231) case UFS_UID_EFT:
4e9036042feda (Al Viro 2019-05-01 22:46:11 -0400 232) if (inode->ui_u1.oldids.ui_sgid == 0xFFFF)
252e211e90ce5 (Mark Fortescue 2007-10-16 23:26:31 -0700 233) return fs32_to_cpu(sb, inode->ui_u3.ui_sun.ui_gid);
df561f6688fef (Gustavo A. R. Silva 2020-08-23 17:36:59 -0500 234) fallthrough;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 235) default:
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 236) return fs16_to_cpu(sb, inode->ui_u1.oldids.ui_sgid);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 237) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 238) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 239)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 240) static inline void
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 241) ufs_set_inode_gid(struct super_block *sb, struct ufs_inode *inode, u32 value)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 242) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 243) switch (UFS_SB(sb)->s_flags & UFS_UID_MASK) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 244) case UFS_UID_44BSD:
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 245) inode->ui_u3.ui_44.ui_gid = cpu_to_fs32(sb, value);
252e211e90ce5 (Mark Fortescue 2007-10-16 23:26:31 -0700 246) inode->ui_u1.oldids.ui_sgid = cpu_to_fs16(sb, value);
252e211e90ce5 (Mark Fortescue 2007-10-16 23:26:31 -0700 247) break;
252e211e90ce5 (Mark Fortescue 2007-10-16 23:26:31 -0700 248) case UFS_UID_EFT:
252e211e90ce5 (Mark Fortescue 2007-10-16 23:26:31 -0700 249) inode->ui_u3.ui_sun.ui_gid = cpu_to_fs32(sb, value);
252e211e90ce5 (Mark Fortescue 2007-10-16 23:26:31 -0700 250) if (value > 0xFFFF)
252e211e90ce5 (Mark Fortescue 2007-10-16 23:26:31 -0700 251) value = 0xFFFF;
df561f6688fef (Gustavo A. R. Silva 2020-08-23 17:36:59 -0500 252) fallthrough;
252e211e90ce5 (Mark Fortescue 2007-10-16 23:26:31 -0700 253) default:
252e211e90ce5 (Mark Fortescue 2007-10-16 23:26:31 -0700 254) inode->ui_u1.oldids.ui_sgid = cpu_to_fs16(sb, value);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 255) break;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 256) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 257) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 258)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 259) extern dev_t ufs_get_inode_dev(struct super_block *, struct ufs_inode_info *);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 260) extern void ufs_set_inode_dev(struct super_block *, struct ufs_inode_info *, dev_t);
f4e420dc42314 (Christoph Hellwig 2010-06-04 11:29:56 +0200 261) extern int ufs_prepare_chunk(struct page *page, loff_t pos, unsigned len);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 262)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 263) /*
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 264) * These functions manipulate ufs buffers
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 265) */
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 266) #define ubh_bread(sb,fragment,size) _ubh_bread_(uspi,sb,fragment,size)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 267) extern struct ufs_buffer_head * _ubh_bread_(struct ufs_sb_private_info *, struct super_block *, u64 , u64);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 268) extern struct ufs_buffer_head * ubh_bread_uspi(struct ufs_sb_private_info *, struct super_block *, u64, u64);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 269) extern void ubh_brelse (struct ufs_buffer_head *);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 270) extern void ubh_brelse_uspi (struct ufs_sb_private_info *);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 271) extern void ubh_mark_buffer_dirty (struct ufs_buffer_head *);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 272) extern void ubh_mark_buffer_uptodate (struct ufs_buffer_head *, int);
9cb569d601e0b (Christoph Hellwig 2010-08-11 17:06:24 +0200 273) extern void ubh_sync_block(struct ufs_buffer_head *);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 274) extern void ubh_bforget (struct ufs_buffer_head *);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 275) extern int ubh_buffer_dirty (struct ufs_buffer_head *);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 276) #define ubh_ubhcpymem(mem,ubh,size) _ubh_ubhcpymem_(uspi,mem,ubh,size)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 277) extern void _ubh_ubhcpymem_(struct ufs_sb_private_info *, unsigned char *, struct ufs_buffer_head *, unsigned);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 278) #define ubh_memcpyubh(ubh,mem,size) _ubh_memcpyubh_(uspi,ubh,mem,size)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 279) extern void _ubh_memcpyubh_(struct ufs_sb_private_info *, struct ufs_buffer_head *, unsigned char *, unsigned);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 280)
10e5dce07e6f8 (Evgeniy Dushistov 2006-07-01 04:36:24 -0700 281) /* This functions works with cache pages*/
10e5dce07e6f8 (Evgeniy Dushistov 2006-07-01 04:36:24 -0700 282) extern struct page *ufs_get_locked_page(struct address_space *mapping,
10e5dce07e6f8 (Evgeniy Dushistov 2006-07-01 04:36:24 -0700 283) pgoff_t index);
10e5dce07e6f8 (Evgeniy Dushistov 2006-07-01 04:36:24 -0700 284) static inline void ufs_put_locked_page(struct page *page)
10e5dce07e6f8 (Evgeniy Dushistov 2006-07-01 04:36:24 -0700 285) {
10e5dce07e6f8 (Evgeniy Dushistov 2006-07-01 04:36:24 -0700 286) unlock_page(page);
09cbfeaf1a5a6 (Kirill A. Shutemov 2016-04-01 15:29:47 +0300 287) put_page(page);
10e5dce07e6f8 (Evgeniy Dushistov 2006-07-01 04:36:24 -0700 288) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 289)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 290)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 291) /*
7b4ee73e28052 (Evgeniy 2006-01-14 11:42:06 +0300 292) * macros and inline function to get important structures from ufs_sb_private_info
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 293) */
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 294)
7b4ee73e28052 (Evgeniy 2006-01-14 11:42:06 +0300 295) static inline void *get_usb_offset(struct ufs_sb_private_info *uspi,
7b4ee73e28052 (Evgeniy 2006-01-14 11:42:06 +0300 296) unsigned int offset)
7b4ee73e28052 (Evgeniy 2006-01-14 11:42:06 +0300 297) {
7b4ee73e28052 (Evgeniy 2006-01-14 11:42:06 +0300 298) unsigned int index;
7b4ee73e28052 (Evgeniy 2006-01-14 11:42:06 +0300 299)
7b4ee73e28052 (Evgeniy 2006-01-14 11:42:06 +0300 300) index = offset >> uspi->s_fshift;
7b4ee73e28052 (Evgeniy 2006-01-14 11:42:06 +0300 301) offset &= ~uspi->s_fmask;
7b4ee73e28052 (Evgeniy 2006-01-14 11:42:06 +0300 302) return uspi->s_ubh.bh[index]->b_data + offset;
7b4ee73e28052 (Evgeniy 2006-01-14 11:42:06 +0300 303) }
7b4ee73e28052 (Evgeniy 2006-01-14 11:42:06 +0300 304)
7b4ee73e28052 (Evgeniy 2006-01-14 11:42:06 +0300 305) #define ubh_get_usb_first(uspi) \
7b4ee73e28052 (Evgeniy 2006-01-14 11:42:06 +0300 306) ((struct ufs_super_block_first *)get_usb_offset((uspi), 0))
7b4ee73e28052 (Evgeniy 2006-01-14 11:42:06 +0300 307)
7b4ee73e28052 (Evgeniy 2006-01-14 11:42:06 +0300 308) #define ubh_get_usb_second(uspi) \
7b4ee73e28052 (Evgeniy 2006-01-14 11:42:06 +0300 309) ((struct ufs_super_block_second *)get_usb_offset((uspi), UFS_SECTOR_SIZE))
7b4ee73e28052 (Evgeniy 2006-01-14 11:42:06 +0300 310)
7b4ee73e28052 (Evgeniy 2006-01-14 11:42:06 +0300 311) #define ubh_get_usb_third(uspi) \
7b4ee73e28052 (Evgeniy 2006-01-14 11:42:06 +0300 312) ((struct ufs_super_block_third *)get_usb_offset((uspi), 2*UFS_SECTOR_SIZE))
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 313)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 314)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 315) #define ubh_get_ucg(ubh) \
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 316) ((struct ufs_cylinder_group *)((ubh)->bh[0]->b_data))
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 317)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 318)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 319) /*
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 320) * Extract byte from ufs_buffer_head
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 321) * Extract the bits for a block from a map inside ufs_buffer_head
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 322) */
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 323) #define ubh_get_addr8(ubh,begin) \
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 324) ((u8*)(ubh)->bh[(begin) >> uspi->s_fshift]->b_data + \
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 325) ((begin) & ~uspi->s_fmask))
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 326)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 327) #define ubh_get_addr16(ubh,begin) \
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 328) (((__fs16*)((ubh)->bh[(begin) >> (uspi->s_fshift-1)]->b_data)) + \
71a3d1b4f7633 (Mariusz Kozlowski 2006-12-06 20:40:09 -0800 329) ((begin) & ((uspi->fsize>>1) - 1)))
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 330)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 331) #define ubh_get_addr32(ubh,begin) \
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 332) (((__fs32*)((ubh)->bh[(begin) >> (uspi->s_fshift-2)]->b_data)) + \
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 333) ((begin) & ((uspi->s_fsize>>2) - 1)))
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 334)
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 335) #define ubh_get_addr64(ubh,begin) \
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 336) (((__fs64*)((ubh)->bh[(begin) >> (uspi->s_fshift-3)]->b_data)) + \
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 337) ((begin) & ((uspi->s_fsize>>3) - 1)))
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 338)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 339) #define ubh_get_addr ubh_get_addr8
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 340)
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 341) static inline void *ubh_get_data_ptr(struct ufs_sb_private_info *uspi,
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 342) struct ufs_buffer_head *ubh,
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 343) u64 blk)
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 344) {
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 345) if (uspi->fs_magic == UFS2_MAGIC)
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 346) return ubh_get_addr64(ubh, blk);
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 347) else
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 348) return ubh_get_addr32(ubh, blk);
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 349) }
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 350)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 351) #define ubh_blkmap(ubh,begin,bit) \
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 352) ((*ubh_get_addr(ubh, (begin) + ((bit) >> 3)) >> ((bit) & 7)) & (0xff >> (UFS_MAXFRAG - uspi->s_fpb)))
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 353)
c596961d1b4cc (Al Viro 2017-06-14 16:36:29 -0400 354) static inline u64
c596961d1b4cc (Al Viro 2017-06-14 16:36:29 -0400 355) ufs_freefrags(struct ufs_sb_private_info *uspi)
ee3ffd6c12632 (Evgeniy Dushistov 2006-06-25 05:47:30 -0700 356) {
ee3ffd6c12632 (Evgeniy Dushistov 2006-06-25 05:47:30 -0700 357) return ufs_blkstofrags(uspi->cs_total.cs_nbfree) +
c596961d1b4cc (Al Viro 2017-06-14 16:36:29 -0400 358) uspi->cs_total.cs_nffree;
ee3ffd6c12632 (Evgeniy Dushistov 2006-06-25 05:47:30 -0700 359) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 360)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 361) /*
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 362) * Macros to access cylinder group array structures
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 363) */
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 364) #define ubh_cg_blktot(ucpi,cylno) \
9695ef16ed4e0 (Evgeniy Dushistov 2006-06-25 05:47:22 -0700 365) (*((__fs32*)ubh_get_addr(UCPI_UBH(ucpi), (ucpi)->c_btotoff + ((cylno) << 2))))
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 366)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 367) #define ubh_cg_blks(ucpi,cylno,rpos) \
9695ef16ed4e0 (Evgeniy Dushistov 2006-06-25 05:47:22 -0700 368) (*((__fs16*)ubh_get_addr(UCPI_UBH(ucpi), \
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 369) (ucpi)->c_boff + (((cylno) * uspi->s_nrpos + (rpos)) << 1 ))))
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 370)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 371) /*
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 372) * Bitmap operations
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 373) * These functions work like classical bitmap operations.
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 374) * The difference is that we don't have the whole bitmap
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 375) * in one contiguous chunk of memory, but in several buffers.
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 376) * The parameters of each function are super_block, ufs_buffer_head and
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 377) * position of the beginning of the bitmap.
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 378) */
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 379) #define ubh_setbit(ubh,begin,bit) \
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 380) (*ubh_get_addr(ubh, (begin) + ((bit) >> 3)) |= (1 << ((bit) & 7)))
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 381)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 382) #define ubh_clrbit(ubh,begin,bit) \
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 383) (*ubh_get_addr (ubh, (begin) + ((bit) >> 3)) &= ~(1 << ((bit) & 7)))
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 384)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 385) #define ubh_isset(ubh,begin,bit) \
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 386) (*ubh_get_addr (ubh, (begin) + ((bit) >> 3)) & (1 << ((bit) & 7)))
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 387)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 388) #define ubh_isclr(ubh,begin,bit) (!ubh_isset(ubh,begin,bit))
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 389)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 390) #define ubh_find_first_zero_bit(ubh,begin,size) _ubh_find_next_zero_bit_(uspi,ubh,begin,size,0)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 391)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 392) #define ubh_find_next_zero_bit(ubh,begin,size,offset) _ubh_find_next_zero_bit_(uspi,ubh,begin,size,offset)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 393) static inline unsigned _ubh_find_next_zero_bit_(
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 394) struct ufs_sb_private_info * uspi, struct ufs_buffer_head * ubh,
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 395) unsigned begin, unsigned size, unsigned offset)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 396) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 397) unsigned base, count, pos;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 398)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 399) size -= offset;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 400) begin <<= 3;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 401) offset += begin;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 402) base = offset >> uspi->s_bpfshift;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 403) offset &= uspi->s_bpfmask;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 404) for (;;) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 405) count = min_t(unsigned int, size + offset, uspi->s_bpf);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 406) size -= count - offset;
3cdc7125c364b (Akinobu Mita 2011-03-23 16:42:11 -0700 407) pos = find_next_zero_bit_le(ubh->bh[base]->b_data, count, offset);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 408) if (pos < count || !size)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 409) break;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 410) base++;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 411) offset = 0;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 412) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 413) return (base << uspi->s_bpfshift) + pos - begin;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 414) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 415)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 416) static inline unsigned find_last_zero_bit (unsigned char * bitmap,
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 417) unsigned size, unsigned offset)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 418) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 419) unsigned bit, i;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 420) unsigned char * mapp;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 421) unsigned char map;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 422)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 423) mapp = bitmap + (size >> 3);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 424) map = *mapp--;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 425) bit = 1 << (size & 7);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 426) for (i = size; i > offset; i--) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 427) if ((map & bit) == 0)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 428) break;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 429) if ((i & 7) != 0) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 430) bit >>= 1;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 431) } else {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 432) map = *mapp--;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 433) bit = 1 << 7;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 434) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 435) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 436) return i;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 437) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 438)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 439) #define ubh_find_last_zero_bit(ubh,begin,size,offset) _ubh_find_last_zero_bit_(uspi,ubh,begin,size,offset)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 440) static inline unsigned _ubh_find_last_zero_bit_(
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 441) struct ufs_sb_private_info * uspi, struct ufs_buffer_head * ubh,
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 442) unsigned begin, unsigned start, unsigned end)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 443) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 444) unsigned base, count, pos, size;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 445)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 446) size = start - end;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 447) begin <<= 3;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 448) start += begin;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 449) base = start >> uspi->s_bpfshift;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 450) start &= uspi->s_bpfmask;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 451) for (;;) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 452) count = min_t(unsigned int,
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 453) size + (uspi->s_bpf - start), uspi->s_bpf)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 454) - (uspi->s_bpf - start);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 455) size -= count;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 456) pos = find_last_zero_bit (ubh->bh[base]->b_data,
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 457) start, start - count);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 458) if (pos > start - count || !size)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 459) break;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 460) base--;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 461) start = uspi->s_bpf;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 462) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 463) return (base << uspi->s_bpfshift) + pos - begin;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 464) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 465)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 466) #define ubh_isblockclear(ubh,begin,block) (!_ubh_isblockset_(uspi,ubh,begin,block))
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 467)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 468) #define ubh_isblockset(ubh,begin,block) _ubh_isblockset_(uspi,ubh,begin,block)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 469) static inline int _ubh_isblockset_(struct ufs_sb_private_info * uspi,
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 470) struct ufs_buffer_head * ubh, unsigned begin, unsigned block)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 471) {
414cf7186dbec (Al Viro 2017-06-08 18:15:18 -0400 472) u8 mask;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 473) switch (uspi->s_fpb) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 474) case 8:
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 475) return (*ubh_get_addr (ubh, begin + block) == 0xff);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 476) case 4:
414cf7186dbec (Al Viro 2017-06-08 18:15:18 -0400 477) mask = 0x0f << ((block & 0x01) << 2);
414cf7186dbec (Al Viro 2017-06-08 18:15:18 -0400 478) return (*ubh_get_addr (ubh, begin + (block >> 1)) & mask) == mask;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 479) case 2:
414cf7186dbec (Al Viro 2017-06-08 18:15:18 -0400 480) mask = 0x03 << ((block & 0x03) << 1);
414cf7186dbec (Al Viro 2017-06-08 18:15:18 -0400 481) return (*ubh_get_addr (ubh, begin + (block >> 2)) & mask) == mask;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 482) case 1:
414cf7186dbec (Al Viro 2017-06-08 18:15:18 -0400 483) mask = 0x01 << (block & 0x07);
414cf7186dbec (Al Viro 2017-06-08 18:15:18 -0400 484) return (*ubh_get_addr (ubh, begin + (block >> 3)) & mask) == mask;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 485) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 486) return 0;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 487) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 488)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 489) #define ubh_clrblock(ubh,begin,block) _ubh_clrblock_(uspi,ubh,begin,block)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 490) static inline void _ubh_clrblock_(struct ufs_sb_private_info * uspi,
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 491) struct ufs_buffer_head * ubh, unsigned begin, unsigned block)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 492) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 493) switch (uspi->s_fpb) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 494) case 8:
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 495) *ubh_get_addr (ubh, begin + block) = 0x00;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 496) return;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 497) case 4:
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 498) *ubh_get_addr (ubh, begin + (block >> 1)) &= ~(0x0f << ((block & 0x01) << 2));
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 499) return;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 500) case 2:
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 501) *ubh_get_addr (ubh, begin + (block >> 2)) &= ~(0x03 << ((block & 0x03) << 1));
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 502) return;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 503) case 1:
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 504) *ubh_get_addr (ubh, begin + (block >> 3)) &= ~(0x01 << ((block & 0x07)));
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 505) return;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 506) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 507) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 508)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 509) #define ubh_setblock(ubh,begin,block) _ubh_setblock_(uspi,ubh,begin,block)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 510) static inline void _ubh_setblock_(struct ufs_sb_private_info * uspi,
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 511) struct ufs_buffer_head * ubh, unsigned begin, unsigned block)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 512) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 513) switch (uspi->s_fpb) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 514) case 8:
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 515) *ubh_get_addr(ubh, begin + block) = 0xff;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 516) return;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 517) case 4:
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 518) *ubh_get_addr(ubh, begin + (block >> 1)) |= (0x0f << ((block & 0x01) << 2));
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 519) return;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 520) case 2:
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 521) *ubh_get_addr(ubh, begin + (block >> 2)) |= (0x03 << ((block & 0x03) << 1));
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 522) return;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 523) case 1:
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 524) *ubh_get_addr(ubh, begin + (block >> 3)) |= (0x01 << ((block & 0x07)));
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 525) return;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 526) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 527) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 528)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 529) static inline void ufs_fragacct (struct super_block * sb, unsigned blockmap,
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 530) __fs32 * fraglist, int cnt)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 531) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 532) struct ufs_sb_private_info * uspi;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 533) unsigned fragsize, pos;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 534)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 535) uspi = UFS_SB(sb)->s_uspi;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 536)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 537) fragsize = 0;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 538) for (pos = 0; pos < uspi->s_fpb; pos++) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 539) if (blockmap & (1 << pos)) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 540) fragsize++;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 541) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 542) else if (fragsize > 0) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 543) fs32_add(sb, &fraglist[fragsize], cnt);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 544) fragsize = 0;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 545) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 546) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 547) if (fragsize > 0 && fragsize < uspi->s_fpb)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 548) fs32_add(sb, &fraglist[fragsize], cnt);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 549) }
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 550)
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 551) static inline void *ufs_get_direct_data_ptr(struct ufs_sb_private_info *uspi,
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 552) struct ufs_inode_info *ufsi,
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 553) unsigned blk)
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 554) {
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 555) BUG_ON(blk > UFS_TIND_BLOCK);
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 556) return uspi->fs_magic == UFS2_MAGIC ?
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 557) (void *)&ufsi->i_u1.u2_i_data[blk] :
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 558) (void *)&ufsi->i_u1.i_data[blk];
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 559) }
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 560)
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 561) static inline u64 ufs_data_ptr_to_cpu(struct super_block *sb, void *p)
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 562) {
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 563) return UFS_SB(sb)->s_uspi->fs_magic == UFS2_MAGIC ?
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 564) fs64_to_cpu(sb, *(__fs64 *)p) :
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 565) fs32_to_cpu(sb, *(__fs32 *)p);
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 566) }
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 567)
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 568) static inline void ufs_cpu_to_data_ptr(struct super_block *sb, void *p, u64 val)
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 569) {
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 570) if (UFS_SB(sb)->s_uspi->fs_magic == UFS2_MAGIC)
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 571) *(__fs64 *)p = cpu_to_fs64(sb, val);
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 572) else
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 573) *(__fs32 *)p = cpu_to_fs32(sb, val);
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 574) }
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 575)
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 576) static inline void ufs_data_ptr_clear(struct ufs_sb_private_info *uspi,
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 577) void *p)
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 578) {
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 579) if (uspi->fs_magic == UFS2_MAGIC)
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 580) *(__fs64 *)p = 0;
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 581) else
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 582) *(__fs32 *)p = 0;
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 583) }
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 584)
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 585) static inline int ufs_is_data_ptr_zero(struct ufs_sb_private_info *uspi,
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 586) void *p)
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 587) {
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 588) if (uspi->fs_magic == UFS2_MAGIC)
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 589) return *(__fs64 *)p == 0;
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 590) else
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 591) return *(__fs32 *)p == 0;
54fb996ac15c4 (Evgeniy Dushistov 2007-02-12 00:54:32 -0800 592) }
a3fda0ffeaf01 (Arnd Bergmann 2018-08-17 15:43:47 -0700 593)
a3fda0ffeaf01 (Arnd Bergmann 2018-08-17 15:43:47 -0700 594) static inline __fs32 ufs_get_seconds(struct super_block *sbp)
a3fda0ffeaf01 (Arnd Bergmann 2018-08-17 15:43:47 -0700 595) {
a3fda0ffeaf01 (Arnd Bergmann 2018-08-17 15:43:47 -0700 596) time64_t now = ktime_get_real_seconds();
a3fda0ffeaf01 (Arnd Bergmann 2018-08-17 15:43:47 -0700 597)
a3fda0ffeaf01 (Arnd Bergmann 2018-08-17 15:43:47 -0700 598) /* Signed 32-bit interpretation wraps around in 2038, which
a3fda0ffeaf01 (Arnd Bergmann 2018-08-17 15:43:47 -0700 599) * happens in ufs1 inode stamps but not ufs2 using 64-bits
a3fda0ffeaf01 (Arnd Bergmann 2018-08-17 15:43:47 -0700 600) * stamps. For superblock and blockgroup, let's assume
a3fda0ffeaf01 (Arnd Bergmann 2018-08-17 15:43:47 -0700 601) * unsigned 32-bit stamps, which are good until y2106.
a3fda0ffeaf01 (Arnd Bergmann 2018-08-17 15:43:47 -0700 602) * Wrap around rather than clamp here to make the dirty
a3fda0ffeaf01 (Arnd Bergmann 2018-08-17 15:43:47 -0700 603) * file system detection work in the superblock stamp.
a3fda0ffeaf01 (Arnd Bergmann 2018-08-17 15:43:47 -0700 604) */
a3fda0ffeaf01 (Arnd Bergmann 2018-08-17 15:43:47 -0700 605) return cpu_to_fs32(sbp, lower_32_bits(now));
a3fda0ffeaf01 (Arnd Bergmann 2018-08-17 15:43:47 -0700 606) }