Skip to content

Commit 939b00d

Browse files
aebrLinus Torvalds
authored andcommitted
[PATCH] Minix V3 support
This morning I needed to read a Minix V3 filesystem, but unfortunately my 2.6.19 did not support that, and neither did the downloaded 2.6.20rc4. Fortunately, google told me that Daniel Aragones had already done the work, patch found at http://www.terra.es/personal2/danarag/ Unfortunaly, looking at the patch was painful to my eyes, so I polished it a bit before applying. The resulting kernel boots, and reads the filesystem it needed to read. Signed-off-by: Daniel Aragones <danarag@gmail.com> Signed-off-by: Andries Brouwer <aeb@cwi.nl> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent b587b13 commit 939b00d

9 files changed

Lines changed: 233 additions & 112 deletions

File tree

‎fs/minix/bitmap.c‎

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ static unsigned long count_free(struct buffer_head *map[], unsigned numblocks, _
2626
for (i=0; i<numblocks-1; i++) {
2727
if (!(bh=map[i]))
2828
return(0);
29-
for (j=0; j<BLOCK_SIZE; j++)
29+
for (j=0; j<bh->b_size; j++)
3030
sum += nibblemap[bh->b_data[j] & 0xf]
3131
+ nibblemap[(bh->b_data[j]>>4) & 0xf];
3232
}
3333

3434
if (numblocks==0 || !(bh=map[numblocks-1]))
3535
return(0);
36-
i = ((numbits-(numblocks-1)*BLOCK_SIZE*8)/16)*2;
36+
i = ((numbits - (numblocks-1) * bh->b_size * 8) / 16) * 2;
3737
for (j=0; j<i; j++) {
3838
sum += nibblemap[bh->b_data[j] & 0xf]
3939
+ nibblemap[(bh->b_data[j]>>4) & 0xf];
@@ -48,28 +48,29 @@ static unsigned long count_free(struct buffer_head *map[], unsigned numblocks, _
4848
return(sum);
4949
}
5050

51-
void minix_free_block(struct inode * inode, int block)
51+
void minix_free_block(struct inode *inode, unsigned long block)
5252
{
53-
struct super_block * sb = inode->i_sb;
54-
struct minix_sb_info * sbi = minix_sb(sb);
55-
struct buffer_head * bh;
56-
unsigned int bit,zone;
53+
struct super_block *sb = inode->i_sb;
54+
struct minix_sb_info *sbi = minix_sb(sb);
55+
struct buffer_head *bh;
56+
int k = sb->s_blocksize_bits + 3;
57+
unsigned long bit, zone;
5758

5859
if (block < sbi->s_firstdatazone || block >= sbi->s_nzones) {
5960
printk("Trying to free block not in datazone\n");
6061
return;
6162
}
6263
zone = block - sbi->s_firstdatazone + 1;
63-
bit = zone & 8191;
64-
zone >>= 13;
64+
bit = zone & ((1<<k) - 1);
65+
zone >>= k;
6566
if (zone >= sbi->s_zmap_blocks) {
6667
printk("minix_free_block: nonexistent bitmap buffer\n");
6768
return;
6869
}
6970
bh = sbi->s_zmap[zone];
7071
lock_kernel();
71-
if (!minix_test_and_clear_bit(bit,bh->b_data))
72-
printk("free_block (%s:%d): bit already cleared\n",
72+
if (!minix_test_and_clear_bit(bit, bh->b_data))
73+
printk("minix_free_block (%s:%lu): bit already cleared\n",
7374
sb->s_id, block);
7475
unlock_kernel();
7576
mark_buffer_dirty(bh);
@@ -79,18 +80,20 @@ void minix_free_block(struct inode * inode, int block)
7980
int minix_new_block(struct inode * inode)
8081
{
8182
struct minix_sb_info *sbi = minix_sb(inode->i_sb);
83+
int bits_per_zone = 8 * inode->i_sb->s_blocksize;
8284
int i;
8385

8486
for (i = 0; i < sbi->s_zmap_blocks; i++) {
8587
struct buffer_head *bh = sbi->s_zmap[i];
8688
int j;
8789

8890
lock_kernel();
89-
if ((j = minix_find_first_zero_bit(bh->b_data, 8192)) < 8192) {
90-
minix_set_bit(j,bh->b_data);
91+
j = minix_find_first_zero_bit(bh->b_data, bits_per_zone);
92+
if (j < bits_per_zone) {
93+
minix_set_bit(j, bh->b_data);
9194
unlock_kernel();
9295
mark_buffer_dirty(bh);
93-
j += i*8192 + sbi->s_firstdatazone-1;
96+
j += i * bits_per_zone + sbi->s_firstdatazone-1;
9497
if (j < sbi->s_firstdatazone || j >= sbi->s_nzones)
9598
break;
9699
return j;
@@ -137,6 +140,7 @@ minix_V2_raw_inode(struct super_block *sb, ino_t ino, struct buffer_head **bh)
137140
int block;
138141
struct minix_sb_info *sbi = minix_sb(sb);
139142
struct minix2_inode *p;
143+
int minix2_inodes_per_block = sb->s_blocksize / sizeof(struct minix2_inode);
140144

141145
*bh = NULL;
142146
if (!ino || ino > sbi->s_ninodes) {
@@ -146,14 +150,14 @@ minix_V2_raw_inode(struct super_block *sb, ino_t ino, struct buffer_head **bh)
146150
}
147151
ino--;
148152
block = 2 + sbi->s_imap_blocks + sbi->s_zmap_blocks +
149-
ino / MINIX2_INODES_PER_BLOCK;
153+
ino / minix2_inodes_per_block;
150154
*bh = sb_bread(sb, block);
151155
if (!*bh) {
152156
printk("Unable to read inode block\n");
153157
return NULL;
154158
}
155159
p = (void *)(*bh)->b_data;
156-
return p + ino % MINIX2_INODES_PER_BLOCK;
160+
return p + ino % minix2_inodes_per_block;
157161
}
158162

159163
/* Clear the link count and mode of a deleted inode on disk. */
@@ -185,26 +189,30 @@ static void minix_clear_inode(struct inode *inode)
185189

186190
void minix_free_inode(struct inode * inode)
187191
{
192+
struct super_block *sb = inode->i_sb;
188193
struct minix_sb_info *sbi = minix_sb(inode->i_sb);
189-
struct buffer_head * bh;
190-
unsigned long ino;
194+
struct buffer_head *bh;
195+
int k = sb->s_blocksize_bits + 3;
196+
unsigned long ino, bit;
191197

192198
ino = inode->i_ino;
193199
if (ino < 1 || ino > sbi->s_ninodes) {
194200
printk("minix_free_inode: inode 0 or nonexistent inode\n");
195201
goto out;
196202
}
197-
if ((ino >> 13) >= sbi->s_imap_blocks) {
203+
bit = ino & ((1<<k) - 1);
204+
ino >>= k;
205+
if (ino >= sbi->s_imap_blocks) {
198206
printk("minix_free_inode: nonexistent imap in superblock\n");
199207
goto out;
200208
}
201209

202210
minix_clear_inode(inode); /* clear on-disk copy */
203211

204-
bh = sbi->s_imap[ino >> 13];
212+
bh = sbi->s_imap[ino];
205213
lock_kernel();
206-
if (!minix_test_and_clear_bit(ino & 8191, bh->b_data))
207-
printk("minix_free_inode: bit %lu already cleared\n", ino);
214+
if (!minix_test_and_clear_bit(bit, bh->b_data))
215+
printk("minix_free_inode: bit %lu already cleared\n", bit);
208216
unlock_kernel();
209217
mark_buffer_dirty(bh);
210218
out:
@@ -217,35 +225,38 @@ struct inode * minix_new_inode(const struct inode * dir, int * error)
217225
struct minix_sb_info *sbi = minix_sb(sb);
218226
struct inode *inode = new_inode(sb);
219227
struct buffer_head * bh;
220-
int i,j;
228+
int bits_per_zone = 8 * sb->s_blocksize;
229+
unsigned long j;
230+
int i;
221231

222232
if (!inode) {
223233
*error = -ENOMEM;
224234
return NULL;
225235
}
226-
j = 8192;
236+
j = bits_per_zone;
227237
bh = NULL;
228238
*error = -ENOSPC;
229239
lock_kernel();
230240
for (i = 0; i < sbi->s_imap_blocks; i++) {
231241
bh = sbi->s_imap[i];
232-
if ((j = minix_find_first_zero_bit(bh->b_data, 8192)) < 8192)
242+
j = minix_find_first_zero_bit(bh->b_data, bits_per_zone);
243+
if (j < bits_per_zone)
233244
break;
234245
}
235-
if (!bh || j >= 8192) {
246+
if (!bh || j >= bits_per_zone) {
236247
unlock_kernel();
237248
iput(inode);
238249
return NULL;
239250
}
240-
if (minix_test_and_set_bit(j,bh->b_data)) { /* shouldn't happen */
241-
printk("new_inode: bit already set\n");
251+
if (minix_test_and_set_bit(j, bh->b_data)) { /* shouldn't happen */
242252
unlock_kernel();
253+
printk("minix_new_inode: bit already set\n");
243254
iput(inode);
244255
return NULL;
245256
}
246257
unlock_kernel();
247258
mark_buffer_dirty(bh);
248-
j += i*8192;
259+
j += i * bits_per_zone;
249260
if (!j || j > sbi->s_ninodes) {
250261
iput(inode);
251262
return NULL;

0 commit comments

Comments
 (0)