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 void hpfs_lock_creation(struct super_block *s)
15 printk("lock creation\n");
17 mutex_lock(&hpfs_sb(s)->hpfs_creation_de);
20 void hpfs_unlock_creation(struct super_block *s)
23 printk("unlock creation\n");
25 mutex_unlock(&hpfs_sb(s)->hpfs_creation_de);
28 /* Map a sector into a buffer and return pointers to it and to the buffer. */
30 void *hpfs_map_sector(struct super_block *s, unsigned secno, struct buffer_head **bhp,
33 struct buffer_head *bh;
39 *bhp = bh = sb_bread(s, secno);
43 printk("HPFS: hpfs_map_sector: read error\n");
48 /* Like hpfs_map_sector but don't read anything */
50 void *hpfs_get_sector(struct super_block *s, unsigned secno, struct buffer_head **bhp)
52 struct buffer_head *bh;
53 /*return hpfs_map_sector(s, secno, bhp, 0);*/
59 if ((*bhp = bh = sb_getblk(s, secno)) != NULL) {
60 if (!buffer_uptodate(bh)) wait_on_buffer(bh);
61 set_buffer_uptodate(bh);
64 printk("HPFS: hpfs_get_sector: getblk failed\n");
69 /* Map 4 sectors into a 4buffer and return pointers to it and to the buffer. */
71 void *hpfs_map_4sectors(struct super_block *s, unsigned secno, struct quad_buffer_head *qbh,
74 struct buffer_head *bh;
82 printk("HPFS: hpfs_map_4sectors: unaligned read\n");
86 qbh->data = data = kmalloc(2048, GFP_NOFS);
88 printk("HPFS: hpfs_map_4sectors: out of memory\n");
92 qbh->bh[0] = bh = sb_bread(s, secno);
95 memcpy(data, bh->b_data, 512);
97 qbh->bh[1] = bh = sb_bread(s, secno + 1);
100 memcpy(data + 512, bh->b_data, 512);
102 qbh->bh[2] = bh = sb_bread(s, secno + 2);
105 memcpy(data + 2 * 512, bh->b_data, 512);
107 qbh->bh[3] = bh = sb_bread(s, secno + 3);
110 memcpy(data + 3 * 512, bh->b_data, 512);
122 printk("HPFS: hpfs_map_4sectors: read error\n");
127 /* Don't read sectors */
129 void *hpfs_get_4sectors(struct super_block *s, unsigned secno,
130 struct quad_buffer_head *qbh)
137 printk("HPFS: hpfs_get_4sectors: unaligned read\n");
141 /*return hpfs_map_4sectors(s, secno, qbh, 0);*/
142 if (!(qbh->data = kmalloc(2048, GFP_NOFS))) {
143 printk("HPFS: hpfs_get_4sectors: out of memory\n");
146 if (!(hpfs_get_sector(s, secno, &qbh->bh[0]))) goto bail0;
147 if (!(hpfs_get_sector(s, secno + 1, &qbh->bh[1]))) goto bail1;
148 if (!(hpfs_get_sector(s, secno + 2, &qbh->bh[2]))) goto bail2;
149 if (!(hpfs_get_sector(s, secno + 3, &qbh->bh[3]))) goto bail3;
150 memcpy(qbh->data, qbh->bh[0]->b_data, 512);
151 memcpy(qbh->data + 512, qbh->bh[1]->b_data, 512);
152 memcpy(qbh->data + 2*512, qbh->bh[2]->b_data, 512);
153 memcpy(qbh->data + 3*512, qbh->bh[3]->b_data, 512);
156 bail3: brelse(qbh->bh[2]);
157 bail2: brelse(qbh->bh[1]);
158 bail1: brelse(qbh->bh[0]);
164 void hpfs_brelse4(struct quad_buffer_head *qbh)
173 void hpfs_mark_4buffers_dirty(struct quad_buffer_head *qbh)
175 PRINTK(("hpfs_mark_4buffers_dirty\n"));
176 memcpy(qbh->bh[0]->b_data, qbh->data, 512);
177 memcpy(qbh->bh[1]->b_data, qbh->data + 512, 512);
178 memcpy(qbh->bh[2]->b_data, qbh->data + 2 * 512, 512);
179 memcpy(qbh->bh[3]->b_data, qbh->data + 3 * 512, 512);
180 mark_buffer_dirty(qbh->bh[0]);
181 mark_buffer_dirty(qbh->bh[1]);
182 mark_buffer_dirty(qbh->bh[2]);
183 mark_buffer_dirty(qbh->bh[3]);