2 * linux/fs/hpfs/buffer.c
4 * Mikulas Patocka (mikulas@artax.karlin.mff.cuni.cz), 1998-1999
11 void hpfs_lock_creation(struct super_block *s)
14 printk("lock creation\n");
16 down(&hpfs_sb(s)->hpfs_creation_de);
19 void hpfs_unlock_creation(struct super_block *s)
22 printk("unlock creation\n");
24 up(&hpfs_sb(s)->hpfs_creation_de);
27 /* Map a sector into a buffer and return pointers to it and to the buffer. */
29 void *hpfs_map_sector(struct super_block *s, unsigned secno, struct buffer_head **bhp,
32 struct buffer_head *bh;
34 *bhp = bh = sb_bread(s, secno);
38 printk("HPFS: hpfs_map_sector: read error\n");
43 /* Like hpfs_map_sector but don't read anything */
45 void *hpfs_get_sector(struct super_block *s, unsigned secno, struct buffer_head **bhp)
47 struct buffer_head *bh;
48 /*return hpfs_map_sector(s, secno, bhp, 0);*/
50 if ((*bhp = bh = sb_getblk(s, secno)) != NULL) {
51 if (!buffer_uptodate(bh)) wait_on_buffer(bh);
52 set_buffer_uptodate(bh);
55 printk("HPFS: hpfs_get_sector: getblk failed\n");
60 /* Map 4 sectors into a 4buffer and return pointers to it and to the buffer. */
62 void *hpfs_map_4sectors(struct super_block *s, unsigned secno, struct quad_buffer_head *qbh,
65 struct buffer_head *bh;
69 printk("HPFS: hpfs_map_4sectors: unaligned read\n");
73 qbh->data = data = (char *)kmalloc(2048, GFP_NOFS);
75 printk("HPFS: hpfs_map_4sectors: out of memory\n");
79 qbh->bh[0] = bh = sb_bread(s, secno);
82 memcpy(data, bh->b_data, 512);
84 qbh->bh[1] = bh = sb_bread(s, secno + 1);
87 memcpy(data + 512, bh->b_data, 512);
89 qbh->bh[2] = bh = sb_bread(s, secno + 2);
92 memcpy(data + 2 * 512, bh->b_data, 512);
94 qbh->bh[3] = bh = sb_bread(s, secno + 3);
97 memcpy(data + 3 * 512, bh->b_data, 512);
109 printk("HPFS: hpfs_map_4sectors: read error\n");
114 /* Don't read sectors */
116 void *hpfs_get_4sectors(struct super_block *s, unsigned secno,
117 struct quad_buffer_head *qbh)
120 printk("HPFS: hpfs_get_4sectors: unaligned read\n");
124 /*return hpfs_map_4sectors(s, secno, qbh, 0);*/
125 if (!(qbh->data = kmalloc(2048, GFP_NOFS))) {
126 printk("HPFS: hpfs_get_4sectors: out of memory\n");
129 if (!(hpfs_get_sector(s, secno, &qbh->bh[0]))) goto bail0;
130 if (!(hpfs_get_sector(s, secno + 1, &qbh->bh[1]))) goto bail1;
131 if (!(hpfs_get_sector(s, secno + 2, &qbh->bh[2]))) goto bail2;
132 if (!(hpfs_get_sector(s, secno + 3, &qbh->bh[3]))) goto bail3;
133 memcpy(qbh->data, qbh->bh[0]->b_data, 512);
134 memcpy(qbh->data + 512, qbh->bh[1]->b_data, 512);
135 memcpy(qbh->data + 2*512, qbh->bh[2]->b_data, 512);
136 memcpy(qbh->data + 3*512, qbh->bh[3]->b_data, 512);
139 bail3: brelse(qbh->bh[2]);
140 bail2: brelse(qbh->bh[1]);
141 bail1: brelse(qbh->bh[0]);
147 void hpfs_brelse4(struct quad_buffer_head *qbh)
156 void hpfs_mark_4buffers_dirty(struct quad_buffer_head *qbh)
158 PRINTK(("hpfs_mark_4buffers_dirty\n"));
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]);