2 * linux/fs/hpfs/buffer.c
4 * Mikulas Patocka (mikulas@artax.karlin.mff.cuni.cz), 1998-1999
8 #include <linux/sched.h>
9 #include <linux/slab.h>
12 /* Map a sector into a buffer and return pointers to it and to the buffer. */
14 void *hpfs_map_sector(struct super_block
*s
, unsigned secno
, struct buffer_head
**bhp
,
17 struct buffer_head
*bh
;
23 *bhp
= bh
= sb_bread(s
, secno
);
27 printk("HPFS: hpfs_map_sector: read error\n");
32 /* Like hpfs_map_sector but don't read anything */
34 void *hpfs_get_sector(struct super_block
*s
, unsigned secno
, struct buffer_head
**bhp
)
36 struct buffer_head
*bh
;
37 /*return hpfs_map_sector(s, secno, bhp, 0);*/
43 if ((*bhp
= bh
= sb_getblk(s
, secno
)) != NULL
) {
44 if (!buffer_uptodate(bh
)) wait_on_buffer(bh
);
45 set_buffer_uptodate(bh
);
48 printk("HPFS: hpfs_get_sector: getblk failed\n");
53 /* Map 4 sectors into a 4buffer and return pointers to it and to the buffer. */
55 void *hpfs_map_4sectors(struct super_block
*s
, unsigned secno
, struct quad_buffer_head
*qbh
,
58 struct buffer_head
*bh
;
66 printk("HPFS: hpfs_map_4sectors: unaligned read\n");
70 qbh
->data
= data
= kmalloc(2048, GFP_NOFS
);
72 printk("HPFS: hpfs_map_4sectors: out of memory\n");
76 qbh
->bh
[0] = bh
= sb_bread(s
, secno
);
79 memcpy(data
, bh
->b_data
, 512);
81 qbh
->bh
[1] = bh
= sb_bread(s
, secno
+ 1);
84 memcpy(data
+ 512, bh
->b_data
, 512);
86 qbh
->bh
[2] = bh
= sb_bread(s
, secno
+ 2);
89 memcpy(data
+ 2 * 512, bh
->b_data
, 512);
91 qbh
->bh
[3] = bh
= sb_bread(s
, secno
+ 3);
94 memcpy(data
+ 3 * 512, bh
->b_data
, 512);
106 printk("HPFS: hpfs_map_4sectors: read error\n");
111 /* Don't read sectors */
113 void *hpfs_get_4sectors(struct super_block
*s
, unsigned secno
,
114 struct quad_buffer_head
*qbh
)
121 printk("HPFS: hpfs_get_4sectors: unaligned read\n");
125 /*return hpfs_map_4sectors(s, secno, qbh, 0);*/
126 if (!(qbh
->data
= kmalloc(2048, GFP_NOFS
))) {
127 printk("HPFS: hpfs_get_4sectors: out of memory\n");
130 if (!(hpfs_get_sector(s
, secno
, &qbh
->bh
[0]))) goto bail0
;
131 if (!(hpfs_get_sector(s
, secno
+ 1, &qbh
->bh
[1]))) goto bail1
;
132 if (!(hpfs_get_sector(s
, secno
+ 2, &qbh
->bh
[2]))) goto bail2
;
133 if (!(hpfs_get_sector(s
, secno
+ 3, &qbh
->bh
[3]))) goto bail3
;
134 memcpy(qbh
->data
, qbh
->bh
[0]->b_data
, 512);
135 memcpy(qbh
->data
+ 512, qbh
->bh
[1]->b_data
, 512);
136 memcpy(qbh
->data
+ 2*512, qbh
->bh
[2]->b_data
, 512);
137 memcpy(qbh
->data
+ 3*512, qbh
->bh
[3]->b_data
, 512);
140 bail3
: brelse(qbh
->bh
[2]);
141 bail2
: brelse(qbh
->bh
[1]);
142 bail1
: brelse(qbh
->bh
[0]);
148 void hpfs_brelse4(struct quad_buffer_head
*qbh
)
157 void hpfs_mark_4buffers_dirty(struct quad_buffer_head
*qbh
)
159 memcpy(qbh
->bh
[0]->b_data
, qbh
->data
, 512);
160 memcpy(qbh
->bh
[1]->b_data
, qbh
->data
+ 512, 512);
161 memcpy(qbh
->bh
[2]->b_data
, qbh
->data
+ 2 * 512, 512);
162 memcpy(qbh
->bh
[3]->b_data
, qbh
->data
+ 3 * 512, 512);
163 mark_buffer_dirty(qbh
->bh
[0]);
164 mark_buffer_dirty(qbh
->bh
[1]);
165 mark_buffer_dirty(qbh
->bh
[2]);
166 mark_buffer_dirty(qbh
->bh
[3]);