1 // SPDX-License-Identifier: GPL-2.0
6 * Daniel Pirkl <daniel.pirkl@email.cz>
7 * Charles University, Faculty of Mathematics and Physics
10 #include <linux/string.h>
11 #include <linux/slab.h>
12 #include <linux/buffer_head.h>
19 struct ufs_buffer_head * _ubh_bread_ (struct ufs_sb_private_info * uspi,
20 struct super_block *sb, u64 fragment, u64 size)
22 struct ufs_buffer_head * ubh;
25 if (size & ~uspi->s_fmask)
27 count = size >> uspi->s_fshift;
28 if (count > UFS_MAXFRAG)
30 ubh = kmalloc (sizeof (struct ufs_buffer_head), GFP_NOFS);
33 ubh->fragment = fragment;
35 for (i = 0; i < count; i++)
36 if (!(ubh->bh[i] = sb_bread(sb, fragment + i)))
38 for (; i < UFS_MAXFRAG; i++)
42 for (j = 0; j < i; j++)
48 struct ufs_buffer_head * ubh_bread_uspi (struct ufs_sb_private_info * uspi,
49 struct super_block *sb, u64 fragment, u64 size)
53 if (size & ~uspi->s_fmask)
55 count = size >> uspi->s_fshift;
56 if (count <= 0 || count > UFS_MAXFRAG)
58 USPI_UBH(uspi)->fragment = fragment;
59 USPI_UBH(uspi)->count = count;
60 for (i = 0; i < count; i++)
61 if (!(USPI_UBH(uspi)->bh[i] = sb_bread(sb, fragment + i)))
63 for (; i < UFS_MAXFRAG; i++)
64 USPI_UBH(uspi)->bh[i] = NULL;
65 return USPI_UBH(uspi);
67 for (j = 0; j < i; j++)
68 brelse (USPI_UBH(uspi)->bh[j]);
72 void ubh_brelse (struct ufs_buffer_head * ubh)
77 for (i = 0; i < ubh->count; i++)
82 void ubh_brelse_uspi (struct ufs_sb_private_info * uspi)
87 for ( i = 0; i < USPI_UBH(uspi)->count; i++ ) {
88 brelse (USPI_UBH(uspi)->bh[i]);
89 USPI_UBH(uspi)->bh[i] = NULL;
93 void ubh_mark_buffer_dirty (struct ufs_buffer_head * ubh)
98 for ( i = 0; i < ubh->count; i++ )
99 mark_buffer_dirty (ubh->bh[i]);
102 void ubh_sync_block(struct ufs_buffer_head *ubh)
107 for (i = 0; i < ubh->count; i++)
108 write_dirty_buffer(ubh->bh[i], 0);
110 for (i = 0; i < ubh->count; i++)
111 wait_on_buffer(ubh->bh[i]);
115 void ubh_bforget (struct ufs_buffer_head * ubh)
120 for ( i = 0; i < ubh->count; i++ ) if ( ubh->bh[i] )
121 bforget (ubh->bh[i]);
124 int ubh_buffer_dirty (struct ufs_buffer_head * ubh)
130 for ( i = 0; i < ubh->count; i++ )
131 result |= buffer_dirty(ubh->bh[i]);
136 ufs_get_inode_dev(struct super_block *sb, struct ufs_inode_info *ufsi)
141 if ((UFS_SB(sb)->s_flags & UFS_ST_MASK) == UFS_ST_SUNx86)
142 fs32 = fs32_to_cpu(sb, ufsi->i_u1.i_data[1]);
144 fs32 = fs32_to_cpu(sb, ufsi->i_u1.i_data[0]);
145 switch (UFS_SB(sb)->s_flags & UFS_ST_MASK) {
148 if ((fs32 & 0xffff0000) == 0 ||
149 (fs32 & 0xffff0000) == 0xffff0000)
150 dev = old_decode_dev(fs32 & 0x7fff);
152 dev = MKDEV(sysv_major(fs32), sysv_minor(fs32));
156 dev = old_decode_dev(fs32);
163 ufs_set_inode_dev(struct super_block *sb, struct ufs_inode_info *ufsi, dev_t dev)
167 switch (UFS_SB(sb)->s_flags & UFS_ST_MASK) {
170 fs32 = sysv_encode_dev(dev);
171 if ((fs32 & 0xffff8000) == 0) {
172 fs32 = old_encode_dev(dev);
177 fs32 = old_encode_dev(dev);
180 if ((UFS_SB(sb)->s_flags & UFS_ST_MASK) == UFS_ST_SUNx86)
181 ufsi->i_u1.i_data[1] = cpu_to_fs32(sb, fs32);
183 ufsi->i_u1.i_data[0] = cpu_to_fs32(sb, fs32);
187 * ufs_get_locked_folio() - locate, pin and lock a pagecache folio, if not exist
189 * @mapping: the address_space to search
190 * @index: the page index
192 * Locates the desired pagecache folio, if not exist we'll read it,
193 * locks it, increments its reference
194 * count and returns its address.
197 struct folio *ufs_get_locked_folio(struct address_space *mapping,
200 struct inode *inode = mapping->host;
201 struct folio *folio = filemap_lock_folio(mapping, index);
203 folio = read_mapping_folio(mapping, index, NULL);
206 printk(KERN_ERR "ufs_change_blocknr: read_mapping_folio error: ino %lu, index: %lu\n",
207 mapping->host->i_ino, index);
213 if (unlikely(folio->mapping == NULL)) {
214 /* Truncate got there first */
220 if (!folio_buffers(folio))
221 create_empty_buffers(folio, 1 << inode->i_blkbits, 0);