^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * linux/fs/ufs/util.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 1998
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Daniel Pirkl <daniel.pirkl@email.cz>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Charles University, Faculty of Mathematics and Physics
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/buffer_head.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "ufs_fs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include "ufs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include "swab.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include "util.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) struct ufs_buffer_head * _ubh_bread_ (struct ufs_sb_private_info * uspi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) struct super_block *sb, u64 fragment, u64 size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) struct ufs_buffer_head * ubh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) unsigned i, j ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) u64 count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) if (size & ~uspi->s_fmask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) count = size >> uspi->s_fshift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) if (count > UFS_MAXFRAG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) ubh = kmalloc (sizeof (struct ufs_buffer_head), GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) if (!ubh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) ubh->fragment = fragment;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) ubh->count = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) for (i = 0; i < count; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) if (!(ubh->bh[i] = sb_bread(sb, fragment + i)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) for (; i < UFS_MAXFRAG; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) ubh->bh[i] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) return ubh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) failed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) for (j = 0; j < i; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) brelse (ubh->bh[j]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) kfree(ubh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct ufs_buffer_head * ubh_bread_uspi (struct ufs_sb_private_info * uspi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct super_block *sb, u64 fragment, u64 size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) unsigned i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) u64 count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) if (size & ~uspi->s_fmask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) count = size >> uspi->s_fshift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) if (count <= 0 || count > UFS_MAXFRAG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) USPI_UBH(uspi)->fragment = fragment;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) USPI_UBH(uspi)->count = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) for (i = 0; i < count; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) if (!(USPI_UBH(uspi)->bh[i] = sb_bread(sb, fragment + i)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) for (; i < UFS_MAXFRAG; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) USPI_UBH(uspi)->bh[i] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) return USPI_UBH(uspi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) failed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) for (j = 0; j < i; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) brelse (USPI_UBH(uspi)->bh[j]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) void ubh_brelse (struct ufs_buffer_head * ubh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) unsigned i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) if (!ubh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) for (i = 0; i < ubh->count; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) brelse (ubh->bh[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) kfree (ubh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) void ubh_brelse_uspi (struct ufs_sb_private_info * uspi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) unsigned i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) if (!USPI_UBH(uspi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) for ( i = 0; i < USPI_UBH(uspi)->count; i++ ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) brelse (USPI_UBH(uspi)->bh[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) USPI_UBH(uspi)->bh[i] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) void ubh_mark_buffer_dirty (struct ufs_buffer_head * ubh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) unsigned i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) if (!ubh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) for ( i = 0; i < ubh->count; i++ )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) mark_buffer_dirty (ubh->bh[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) void ubh_mark_buffer_uptodate (struct ufs_buffer_head * ubh, int flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) unsigned i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) if (!ubh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) if (flag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) for ( i = 0; i < ubh->count; i++ )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) set_buffer_uptodate (ubh->bh[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) for ( i = 0; i < ubh->count; i++ )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) clear_buffer_uptodate (ubh->bh[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) void ubh_sync_block(struct ufs_buffer_head *ubh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) if (ubh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) unsigned i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) for (i = 0; i < ubh->count; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) write_dirty_buffer(ubh->bh[i], 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) for (i = 0; i < ubh->count; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) wait_on_buffer(ubh->bh[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) void ubh_bforget (struct ufs_buffer_head * ubh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) unsigned i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) if (!ubh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) for ( i = 0; i < ubh->count; i++ ) if ( ubh->bh[i] )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) bforget (ubh->bh[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) int ubh_buffer_dirty (struct ufs_buffer_head * ubh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) unsigned i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) unsigned result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) if (!ubh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) for ( i = 0; i < ubh->count; i++ )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) result |= buffer_dirty(ubh->bh[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) void _ubh_ubhcpymem_(struct ufs_sb_private_info * uspi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) unsigned char * mem, struct ufs_buffer_head * ubh, unsigned size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) unsigned len, bhno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) if (size > (ubh->count << uspi->s_fshift))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) size = ubh->count << uspi->s_fshift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) bhno = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) while (size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) len = min_t(unsigned int, size, uspi->s_fsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) memcpy (mem, ubh->bh[bhno]->b_data, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) mem += uspi->s_fsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) size -= len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) bhno++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) void _ubh_memcpyubh_(struct ufs_sb_private_info * uspi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) struct ufs_buffer_head * ubh, unsigned char * mem, unsigned size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) unsigned len, bhno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) if (size > (ubh->count << uspi->s_fshift))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) size = ubh->count << uspi->s_fshift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) bhno = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) while (size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) len = min_t(unsigned int, size, uspi->s_fsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) memcpy (ubh->bh[bhno]->b_data, mem, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) mem += uspi->s_fsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) size -= len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) bhno++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) dev_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) ufs_get_inode_dev(struct super_block *sb, struct ufs_inode_info *ufsi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) __u32 fs32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) dev_t dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) if ((UFS_SB(sb)->s_flags & UFS_ST_MASK) == UFS_ST_SUNx86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) fs32 = fs32_to_cpu(sb, ufsi->i_u1.i_data[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) fs32 = fs32_to_cpu(sb, ufsi->i_u1.i_data[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) switch (UFS_SB(sb)->s_flags & UFS_ST_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) case UFS_ST_SUNx86:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) case UFS_ST_SUN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) if ((fs32 & 0xffff0000) == 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) (fs32 & 0xffff0000) == 0xffff0000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) dev = old_decode_dev(fs32 & 0x7fff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) dev = MKDEV(sysv_major(fs32), sysv_minor(fs32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) dev = old_decode_dev(fs32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) return dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) ufs_set_inode_dev(struct super_block *sb, struct ufs_inode_info *ufsi, dev_t dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) __u32 fs32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) switch (UFS_SB(sb)->s_flags & UFS_ST_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) case UFS_ST_SUNx86:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) case UFS_ST_SUN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) fs32 = sysv_encode_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) if ((fs32 & 0xffff8000) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) fs32 = old_encode_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) fs32 = old_encode_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) if ((UFS_SB(sb)->s_flags & UFS_ST_MASK) == UFS_ST_SUNx86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) ufsi->i_u1.i_data[1] = cpu_to_fs32(sb, fs32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) ufsi->i_u1.i_data[0] = cpu_to_fs32(sb, fs32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) * ufs_get_locked_page() - locate, pin and lock a pagecache page, if not exist
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) * read it from disk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) * @mapping: the address_space to search
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) * @index: the page index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) * Locates the desired pagecache page, if not exist we'll read it,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) * locks it, increments its reference
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) * count and returns its address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) struct page *ufs_get_locked_page(struct address_space *mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) pgoff_t index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) struct inode *inode = mapping->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) struct page *page = find_lock_page(mapping, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) if (!page) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) page = read_mapping_page(mapping, index, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) if (IS_ERR(page)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) printk(KERN_ERR "ufs_change_blocknr: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) "read_mapping_page error: ino %lu, index: %lu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) mapping->host->i_ino, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) return page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) lock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) if (unlikely(page->mapping == NULL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) /* Truncate got there first */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) if (!PageUptodate(page) || PageError(page)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) printk(KERN_ERR "ufs_change_blocknr: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) "can not read page: ino %lu, index: %lu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) inode->i_ino, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) return ERR_PTR(-EIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) if (!page_has_buffers(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) create_empty_buffers(page, 1 << inode->i_blkbits, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) return page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) }