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 unsigned ubh_max_bcount (struct ufs_buffer_head
* ubh
)
148 for ( i
= 0; i
< ubh
->count
; i
++ )
149 if ( atomic_read(&ubh
->bh
[i
]->b_count
) > max
)
150 max
= atomic_read(&ubh
->bh
[i
]->b_count
);
154 void ubh_bforget (struct ufs_buffer_head
* ubh
)
159 for ( i
= 0; i
< ubh
->count
; i
++ ) if ( ubh
->bh
[i
] )
160 bforget (ubh
->bh
[i
]);
163 int ubh_buffer_dirty (struct ufs_buffer_head
* ubh
)
169 for ( i
= 0; i
< ubh
->count
; i
++ )
170 result
|= buffer_dirty(ubh
->bh
[i
]);
174 void _ubh_ubhcpymem_(struct ufs_sb_private_info
* uspi
,
175 unsigned char * mem
, struct ufs_buffer_head
* ubh
, unsigned size
)
178 if (size
> (ubh
->count
<< uspi
->s_fshift
))
179 size
= ubh
->count
<< uspi
->s_fshift
;
182 len
= min_t(unsigned int, size
, uspi
->s_fsize
);
183 memcpy (mem
, ubh
->bh
[bhno
]->b_data
, len
);
184 mem
+= uspi
->s_fsize
;
190 void _ubh_memcpyubh_(struct ufs_sb_private_info
* uspi
,
191 struct ufs_buffer_head
* ubh
, unsigned char * mem
, unsigned size
)
194 if (size
> (ubh
->count
<< uspi
->s_fshift
))
195 size
= ubh
->count
<< uspi
->s_fshift
;
198 len
= min_t(unsigned int, size
, uspi
->s_fsize
);
199 memcpy (ubh
->bh
[bhno
]->b_data
, mem
, len
);
200 mem
+= uspi
->s_fsize
;