5 * Daniel Pirkl <daniel.pirkl@email.cz>
6 * Charles University, Faculty of Mathematics and Physics
9 #include <linux/string.h>
10 #include <linux/slab.h>
11 #include <linux/ufs_fs.h>
12 #include <linux/buffer_head.h>
17 #undef UFS_UTILS_DEBUG
19 #ifdef UFS_UTILS_DEBUG
20 #define UFSD(x) printk("(%s, %d), %s: ", __FILE__, __LINE__, __FUNCTION__); printk x;
26 struct ufs_buffer_head * _ubh_bread_ (struct ufs_sb_private_info * uspi,
27 struct super_block *sb, u64 fragment, u64 size)
29 struct ufs_buffer_head * ubh;
32 if (size & ~uspi->s_fmask)
34 count = size >> uspi->s_fshift;
35 if (count > UFS_MAXFRAG)
37 ubh = (struct ufs_buffer_head *)
38 kmalloc (sizeof (struct ufs_buffer_head), GFP_KERNEL);
41 ubh->fragment = fragment;
43 for (i = 0; i < count; i++)
44 if (!(ubh->bh[i] = sb_bread(sb, fragment + i)))
46 for (; i < UFS_MAXFRAG; i++)
50 for (j = 0; j < i; j++)
56 struct ufs_buffer_head * ubh_bread_uspi (struct ufs_sb_private_info * uspi,
57 struct super_block *sb, u64 fragment, u64 size)
61 if (size & ~uspi->s_fmask)
63 count = size >> uspi->s_fshift;
64 if (count <= 0 || count > UFS_MAXFRAG)
66 USPI_UBH->fragment = fragment;
67 USPI_UBH->count = count;
68 for (i = 0; i < count; i++)
69 if (!(USPI_UBH->bh[i] = sb_bread(sb, fragment + i)))
71 for (; i < UFS_MAXFRAG; i++)
72 USPI_UBH->bh[i] = NULL;
75 for (j = 0; j < i; j++)
76 brelse (USPI_UBH->bh[j]);
80 void ubh_brelse (struct ufs_buffer_head * ubh)
85 for (i = 0; i < ubh->count; i++)
90 void ubh_brelse_uspi (struct ufs_sb_private_info * uspi)
95 for ( i = 0; i < USPI_UBH->count; i++ ) {
96 brelse (USPI_UBH->bh[i]);
97 USPI_UBH->bh[i] = NULL;
101 void ubh_mark_buffer_dirty (struct ufs_buffer_head * ubh)
106 for ( i = 0; i < ubh->count; i++ )
107 mark_buffer_dirty (ubh->bh[i]);
110 void ubh_mark_buffer_uptodate (struct ufs_buffer_head * ubh, int flag)
116 for ( i = 0; i < ubh->count; i++ )
117 set_buffer_uptodate (ubh->bh[i]);
119 for ( i = 0; i < ubh->count; i++ )
120 clear_buffer_uptodate (ubh->bh[i]);
124 void ubh_ll_rw_block (int rw, unsigned nr, struct ufs_buffer_head * ubh[])
129 for ( i = 0; i < nr; i++ )
130 ll_rw_block (rw, ubh[i]->count, ubh[i]->bh);
133 void ubh_wait_on_buffer (struct ufs_buffer_head * ubh)
138 for ( i = 0; i < ubh->count; i++ )
139 wait_on_buffer (ubh->bh[i]);
142 void ubh_bforget (struct ufs_buffer_head * ubh)
147 for ( i = 0; i < ubh->count; i++ ) if ( ubh->bh[i] )
148 bforget (ubh->bh[i]);
151 int ubh_buffer_dirty (struct ufs_buffer_head * ubh)
157 for ( i = 0; i < ubh->count; i++ )
158 result |= buffer_dirty(ubh->bh[i]);
162 void _ubh_ubhcpymem_(struct ufs_sb_private_info * uspi,
163 unsigned char * mem, struct ufs_buffer_head * ubh, unsigned size)
166 if (size > (ubh->count << uspi->s_fshift))
167 size = ubh->count << uspi->s_fshift;
170 len = min_t(unsigned int, size, uspi->s_fsize);
171 memcpy (mem, ubh->bh[bhno]->b_data, len);
172 mem += uspi->s_fsize;
178 void _ubh_memcpyubh_(struct ufs_sb_private_info * uspi,
179 struct ufs_buffer_head * ubh, unsigned char * mem, unsigned size)
182 if (size > (ubh->count << uspi->s_fshift))
183 size = ubh->count << uspi->s_fshift;
186 len = min_t(unsigned int, size, uspi->s_fsize);
187 memcpy (ubh->bh[bhno]->b_data, mem, len);
188 mem += uspi->s_fsize;
195 ufs_get_inode_dev(struct super_block *sb, struct ufs_inode_info *ufsi)
200 if ((UFS_SB(sb)->s_flags & UFS_ST_MASK) == UFS_ST_SUNx86)
201 fs32 = ufsi->i_u1.i_data[1];
203 fs32 = ufsi->i_u1.i_data[0];
204 fs32 = fs32_to_cpu(sb, fs32);
205 switch (UFS_SB(sb)->s_flags & UFS_ST_MASK) {
208 if ((fs32 & 0xffff0000) == 0 ||
209 (fs32 & 0xffff0000) == 0xffff0000)
210 dev = old_decode_dev(fs32 & 0x7fff);
212 dev = MKDEV(sysv_major(fs32), sysv_minor(fs32));
216 dev = old_decode_dev(fs32);
223 ufs_set_inode_dev(struct super_block *sb, struct ufs_inode_info *ufsi, dev_t dev)
227 switch (UFS_SB(sb)->s_flags & UFS_ST_MASK) {
230 fs32 = sysv_encode_dev(dev);
231 if ((fs32 & 0xffff8000) == 0) {
232 fs32 = old_encode_dev(dev);
237 fs32 = old_encode_dev(dev);
240 fs32 = cpu_to_fs32(sb, fs32);
241 if ((UFS_SB(sb)->s_flags & UFS_ST_MASK) == UFS_ST_SUNx86)
242 ufsi->i_u1.i_data[1] = fs32;
244 ufsi->i_u1.i_data[0] = fs32;