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/locks.h>
16 #undef UFS_UTILS_DEBUG
18 #ifdef UFS_UTILS_DEBUG
19 #define UFSD(x) printk("(%s, %d), %s: ", __FILE__, __LINE__, __FUNCTION__); printk x;
25 struct ufs_buffer_head * _ubh_bread_ (struct ufs_sb_private_info * uspi,
26 struct super_block *sb, unsigned fragment, unsigned size)
28 struct ufs_buffer_head * ubh;
30 if (size & ~uspi->s_fmask)
32 count = size >> uspi->s_fshift;
33 if (count > UFS_MAXFRAG)
35 ubh = (struct ufs_buffer_head *)
36 kmalloc (sizeof (struct ufs_buffer_head), GFP_KERNEL);
39 ubh->fragment = fragment;
41 for (i = 0; i < count; i++)
42 if (!(ubh->bh[i] = sb_bread(sb, fragment + i)))
44 for (; i < UFS_MAXFRAG; i++)
48 for (j = 0; j < i; j++)
54 struct ufs_buffer_head * ubh_bread_uspi (struct ufs_sb_private_info * uspi,
55 struct super_block *sb, unsigned fragment, unsigned size)
58 if (size & ~uspi->s_fmask)
60 count = size >> uspi->s_fshift;
61 if (count <= 0 || count > UFS_MAXFRAG)
63 USPI_UBH->fragment = fragment;
64 USPI_UBH->count = count;
65 for (i = 0; i < count; i++)
66 if (!(USPI_UBH->bh[i] = sb_bread(sb, fragment + i)))
68 for (; i < UFS_MAXFRAG; i++)
69 USPI_UBH->bh[i] = NULL;
72 for (j = 0; j < i; j++)
73 brelse (USPI_UBH->bh[j]);
77 void ubh_brelse (struct ufs_buffer_head * ubh)
82 for (i = 0; i < ubh->count; i++)
87 void ubh_brelse_uspi (struct ufs_sb_private_info * uspi)
92 for ( i = 0; i < USPI_UBH->count; i++ ) {
93 brelse (USPI_UBH->bh[i]);
94 USPI_UBH->bh[i] = NULL;
98 void ubh_mark_buffer_dirty (struct ufs_buffer_head * ubh)
103 for ( i = 0; i < ubh->count; i++ )
104 mark_buffer_dirty (ubh->bh[i]);
107 void ubh_mark_buffer_uptodate (struct ufs_buffer_head * ubh, int flag)
112 for ( i = 0; i < ubh->count; i++ )
113 mark_buffer_uptodate (ubh->bh[i], flag);
116 void ubh_ll_rw_block (int rw, unsigned nr, struct ufs_buffer_head * ubh[])
121 for ( i = 0; i < nr; i++ )
122 ll_rw_block (rw, ubh[i]->count, ubh[i]->bh);
125 void ubh_wait_on_buffer (struct ufs_buffer_head * ubh)
130 for ( i = 0; i < ubh->count; i++ )
131 wait_on_buffer (ubh->bh[i]);
134 unsigned ubh_max_bcount (struct ufs_buffer_head * ubh)
140 for ( i = 0; i < ubh->count; i++ )
141 if ( atomic_read(&ubh->bh[i]->b_count) > max )
142 max = atomic_read(&ubh->bh[i]->b_count);
146 void ubh_bforget (struct ufs_buffer_head * ubh)
151 for ( i = 0; i < ubh->count; i++ ) if ( ubh->bh[i] )
152 bforget (ubh->bh[i]);
155 int ubh_buffer_dirty (struct ufs_buffer_head * ubh)
161 for ( i = 0; i < ubh->count; i++ )
162 result |= buffer_dirty(ubh->bh[i]);
166 void _ubh_ubhcpymem_(struct ufs_sb_private_info * uspi,
167 unsigned char * mem, struct ufs_buffer_head * ubh, unsigned size)
170 if (size > (ubh->count << uspi->s_fshift))
171 size = ubh->count << uspi->s_fshift;
174 len = min_t(unsigned int, size, uspi->s_fsize);
175 memcpy (mem, ubh->bh[bhno]->b_data, len);
176 mem += uspi->s_fsize;
182 void _ubh_memcpyubh_(struct ufs_sb_private_info * uspi,
183 struct ufs_buffer_head * ubh, unsigned char * mem, unsigned size)
186 if (size > (ubh->count << uspi->s_fshift))
187 size = ubh->count << uspi->s_fshift;
190 len = min_t(unsigned int, size, uspi->s_fsize);
191 memcpy (ubh->bh[bhno]->b_data, mem, len);
192 mem += uspi->s_fsize;