5 * Daniel Pirkl <daniel.pirkl@email.cz>
6 * Charles University, Faculty of Mathematics and Physics
9 #include <linux/string.h>
10 #include <linux/malloc.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 kdev_t dev
, 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
] = bread (dev
, fragment
+ i
, uspi
->s_fsize
)))
44 for (; i
< UFS_MAXFRAG
; i
++)
48 for (j
= 0; j
< i
; j
++)
53 struct ufs_buffer_head
* ubh_bread_uspi (struct ufs_sb_private_info
* uspi
,
54 kdev_t dev
, unsigned fragment
, unsigned size
)
57 if (size
& ~uspi
->s_fmask
)
59 count
= size
>> uspi
->s_fshift
;
60 if (count
<= 0 || count
> UFS_MAXFRAG
)
62 USPI_UBH
->fragment
= fragment
;
63 USPI_UBH
->count
= count
;
64 for (i
= 0; i
< count
; i
++)
65 if (!(USPI_UBH
->bh
[i
] = bread (dev
, fragment
+ i
, uspi
->s_fsize
)))
67 for (; i
< UFS_MAXFRAG
; i
++)
68 USPI_UBH
->bh
[i
] = NULL
;
71 for (j
= 0; j
< i
; j
++)
72 brelse (USPI_UBH
->bh
[j
]);
76 void ubh_brelse (struct ufs_buffer_head
* ubh
)
81 for (i
= 0; i
< ubh
->count
; i
++)
86 void ubh_brelse_uspi (struct ufs_sb_private_info
* uspi
)
91 for ( i
= 0; i
< USPI_UBH
->count
; i
++ ) {
92 brelse (USPI_UBH
->bh
[i
]);
93 USPI_UBH
->bh
[i
] = NULL
;
97 void ubh_mark_buffer_dirty (struct ufs_buffer_head
* ubh
)
102 for ( i
= 0; i
< ubh
->count
; i
++ )
103 mark_buffer_dirty (ubh
->bh
[i
]);
106 void ubh_mark_buffer_uptodate (struct ufs_buffer_head
* ubh
, int flag
)
111 for ( i
= 0; i
< ubh
->count
; i
++ )
112 mark_buffer_uptodate (ubh
->bh
[i
], flag
);
115 void ubh_ll_rw_block (int rw
, unsigned nr
, struct ufs_buffer_head
* ubh
[])
120 for ( i
= 0; i
< nr
; i
++ )
121 ll_rw_block (rw
, ubh
[i
]->count
, ubh
[i
]->bh
);
124 void ubh_wait_on_buffer (struct ufs_buffer_head
* ubh
)
129 for ( i
= 0; i
< ubh
->count
; i
++ )
130 wait_on_buffer (ubh
->bh
[i
]);
133 unsigned ubh_max_bcount (struct ufs_buffer_head
* ubh
)
139 for ( i
= 0; i
< ubh
->count
; i
++ )
140 if ( atomic_read(&ubh
->bh
[i
]->b_count
) > max
)
141 max
= atomic_read(&ubh
->bh
[i
]->b_count
);
145 void ubh_bforget (struct ufs_buffer_head
* ubh
)
150 for ( i
= 0; i
< ubh
->count
; i
++ ) if ( ubh
->bh
[i
] )
151 bforget (ubh
->bh
[i
]);
154 int ubh_buffer_dirty (struct ufs_buffer_head
* ubh
)
160 for ( i
= 0; i
< ubh
->count
; i
++ )
161 result
|= buffer_dirty(ubh
->bh
[i
]);
165 void _ubh_ubhcpymem_(struct ufs_sb_private_info
* uspi
,
166 unsigned char * mem
, struct ufs_buffer_head
* ubh
, unsigned size
)
169 if ( size
> (ubh
->count
<< uspi
->s_fshift
) )
170 size
= ubh
->count
<< uspi
->s_fshift
;
173 len
= min (size
, uspi
->s_fsize
);
174 memcpy (mem
, ubh
->bh
[bhno
]->b_data
, len
);
175 mem
+= uspi
->s_fsize
;
181 void _ubh_memcpyubh_(struct ufs_sb_private_info
* uspi
,
182 struct ufs_buffer_head
* ubh
, unsigned char * mem
, unsigned size
)
185 if ( size
> (ubh
->count
<< uspi
->s_fshift
) )
186 size
= ubh
->count
<< uspi
->s_fshift
;
189 len
= min (size
, uspi
->s_fsize
);
190 memcpy (ubh
->bh
[bhno
]->b_data
, mem
, len
);
191 mem
+= uspi
->s_fsize
;