2 * linux/fs/hpfs/buffer.c
8 #include <linux/sched.h>
9 #include <linux/slab.h>
10 #include <linux/blkdev.h>
13 void hpfs_prefetch_sectors(struct super_block *s, unsigned secno, int n)
15 struct buffer_head *bh;
18 if (n <= 0 || unlikely(secno >= hpfs_sb(s)->sb_fs_size))
21 bh = sb_find_get_block(s, secno);
23 if (buffer_uptodate(bh)) {
30 blk_start_plug(&plug);
32 if (unlikely(secno >= hpfs_sb(s)->sb_fs_size))
34 sb_breadahead(s, secno);
38 blk_finish_plug(&plug);
41 /* Map a sector into a buffer and return pointers to it and to the buffer. */
43 void *hpfs_map_sector(struct super_block *s, unsigned secno, struct buffer_head **bhp,
46 struct buffer_head *bh;
50 hpfs_prefetch_sectors(s, secno, ahead);
54 *bhp = bh = sb_bread(s, secno);
58 printk("HPFS: hpfs_map_sector: read error\n");
63 /* Like hpfs_map_sector but don't read anything */
65 void *hpfs_get_sector(struct super_block *s, unsigned secno, struct buffer_head **bhp)
67 struct buffer_head *bh;
68 /*return hpfs_map_sector(s, secno, bhp, 0);*/
74 if ((*bhp = bh = sb_getblk(s, secno)) != NULL) {
75 if (!buffer_uptodate(bh)) wait_on_buffer(bh);
76 set_buffer_uptodate(bh);
79 printk("HPFS: hpfs_get_sector: getblk failed\n");
84 /* Map 4 sectors into a 4buffer and return pointers to it and to the buffer. */
86 void *hpfs_map_4sectors(struct super_block *s, unsigned secno, struct quad_buffer_head *qbh,
89 struct buffer_head *bh;
97 printk("HPFS: hpfs_map_4sectors: unaligned read\n");
101 hpfs_prefetch_sectors(s, secno, 4 + ahead);
103 qbh->data = data = kmalloc(2048, GFP_NOFS);
105 printk("HPFS: hpfs_map_4sectors: out of memory\n");
109 qbh->bh[0] = bh = sb_bread(s, secno);
112 memcpy(data, bh->b_data, 512);
114 qbh->bh[1] = bh = sb_bread(s, secno + 1);
117 memcpy(data + 512, bh->b_data, 512);
119 qbh->bh[2] = bh = sb_bread(s, secno + 2);
122 memcpy(data + 2 * 512, bh->b_data, 512);
124 qbh->bh[3] = bh = sb_bread(s, secno + 3);
127 memcpy(data + 3 * 512, bh->b_data, 512);
139 printk("HPFS: hpfs_map_4sectors: read error\n");
144 /* Don't read sectors */
146 void *hpfs_get_4sectors(struct super_block *s, unsigned secno,
147 struct quad_buffer_head *qbh)
154 printk("HPFS: hpfs_get_4sectors: unaligned read\n");
158 /*return hpfs_map_4sectors(s, secno, qbh, 0);*/
159 if (!(qbh->data = kmalloc(2048, GFP_NOFS))) {
160 printk("HPFS: hpfs_get_4sectors: out of memory\n");
163 if (!(hpfs_get_sector(s, secno, &qbh->bh[0]))) goto bail0;
164 if (!(hpfs_get_sector(s, secno + 1, &qbh->bh[1]))) goto bail1;
165 if (!(hpfs_get_sector(s, secno + 2, &qbh->bh[2]))) goto bail2;
166 if (!(hpfs_get_sector(s, secno + 3, &qbh->bh[3]))) goto bail3;
167 memcpy(qbh->data, qbh->bh[0]->b_data, 512);
168 memcpy(qbh->data + 512, qbh->bh[1]->b_data, 512);
169 memcpy(qbh->data + 2*512, qbh->bh[2]->b_data, 512);
170 memcpy(qbh->data + 3*512, qbh->bh[3]->b_data, 512);
173 bail3: brelse(qbh->bh[2]);
174 bail2: brelse(qbh->bh[1]);
175 bail1: brelse(qbh->bh[0]);
181 void hpfs_brelse4(struct quad_buffer_head *qbh)
190 void hpfs_mark_4buffers_dirty(struct quad_buffer_head *qbh)
192 memcpy(qbh->bh[0]->b_data, qbh->data, 512);
193 memcpy(qbh->bh[1]->b_data, qbh->data + 512, 512);
194 memcpy(qbh->bh[2]->b_data, qbh->data + 2 * 512, 512);
195 memcpy(qbh->bh[3]->b_data, qbh->data + 3 * 512, 512);
196 mark_buffer_dirty(qbh->bh[0]);
197 mark_buffer_dirty(qbh->bh[1]);
198 mark_buffer_dirty(qbh->bh[2]);
199 mark_buffer_dirty(qbh->bh[3]);