root/fs/minix/inode.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. minix_put_inode
  2. minix_commit_super
  3. minix_write_super
  4. minix_put_super
  5. minix_remount
  6. minix_read_super
  7. minix_statfs
  8. V1_block_bmap
  9. V1_minix_bmap
  10. V2_block_bmap
  11. V2_minix_bmap
  12. minix_bmap
  13. V1_inode_getblk
  14. V1_block_getblk
  15. V1_minix_getblk
  16. V2_inode_getblk
  17. V2_block_getblk
  18. V2_minix_getblk
  19. minix_getblk
  20. minix_bread
  21. V1_minix_read_inode
  22. V2_minix_read_inode
  23. minix_read_inode
  24. V1_minix_update_inode
  25. V2_minix_update_inode
  26. minix_update_inode
  27. minix_write_inode
  28. minix_sync_inode
  29. init_module
  30. cleanup_module

   1 /*
   2  *  linux/fs/minix/inode.c
   3  *
   4  *  Copyright (C) 1991, 1992  Linus Torvalds
   5  *
   6  *  Copyright (C) 1996  Gertjan van Wingerde    (gertjan@cs.vu.nl)
   7  *      Minix V2 fs support.
   8  */
   9 
  10 #include <linux/module.h>
  11 
  12 #include <linux/sched.h>
  13 #include <linux/minix_fs.h>
  14 #include <linux/kernel.h>
  15 #include <linux/mm.h>
  16 #include <linux/string.h>
  17 #include <linux/stat.h>
  18 #include <linux/locks.h>
  19 
  20 #include <asm/system.h>
  21 #include <asm/segment.h>
  22 #include <asm/bitops.h>
  23 
  24 void minix_put_inode(struct inode *inode)
     /* [previous][next][first][last][top][bottom][index][help] */
  25 {
  26         if (inode->i_nlink)
  27                 return;
  28         inode->i_size = 0;
  29         minix_truncate(inode);
  30         minix_free_inode(inode);
  31 }
  32 
  33 static void minix_commit_super (struct super_block * sb,
     /* [previous][next][first][last][top][bottom][index][help] */
  34                                struct minix_super_block * ms)
  35 {
  36         mark_buffer_dirty(sb->u.minix_sb.s_sbh, 1);
  37         sb->s_dirt = 0;
  38 }
  39 
  40 void minix_write_super (struct super_block * sb)
     /* [previous][next][first][last][top][bottom][index][help] */
  41 {
  42         struct minix_super_block * ms;
  43 
  44         if (!(sb->s_flags & MS_RDONLY)) {
  45                 ms = sb->u.minix_sb.s_ms;
  46 
  47                 if (ms->s_state & MINIX_VALID_FS)
  48                         ms->s_state &= ~MINIX_VALID_FS;
  49                 minix_commit_super (sb, ms);
  50         }
  51         sb->s_dirt = 0;
  52 }
  53 
  54 
  55 void minix_put_super(struct super_block *sb)
     /* [previous][next][first][last][top][bottom][index][help] */
  56 {
  57         int i;
  58 
  59         lock_super(sb);
  60         if (!(sb->s_flags & MS_RDONLY)) {
  61                 sb->u.minix_sb.s_ms->s_state = sb->u.minix_sb.s_mount_state;
  62                 mark_buffer_dirty(sb->u.minix_sb.s_sbh, 1);
  63         }
  64         sb->s_dev = 0;
  65         for(i = 0 ; i < MINIX_I_MAP_SLOTS ; i++)
  66                 brelse(sb->u.minix_sb.s_imap[i]);
  67         for(i = 0 ; i < MINIX_Z_MAP_SLOTS ; i++)
  68                 brelse(sb->u.minix_sb.s_zmap[i]);
  69         brelse (sb->u.minix_sb.s_sbh);
  70         unlock_super(sb);
  71         MOD_DEC_USE_COUNT;
  72         return;
  73 }
  74 
  75 static struct super_operations minix_sops = { 
  76         minix_read_inode,
  77         NULL,
  78         minix_write_inode,
  79         minix_put_inode,
  80         minix_put_super,
  81         minix_write_super,
  82         minix_statfs,
  83         minix_remount
  84 };
  85 
  86 int minix_remount (struct super_block * sb, int * flags, char * data)
     /* [previous][next][first][last][top][bottom][index][help] */
  87 {
  88         struct minix_super_block * ms;
  89 
  90         ms = sb->u.minix_sb.s_ms;
  91         if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
  92                 return 0;
  93         if (*flags & MS_RDONLY) {
  94                 if (ms->s_state & MINIX_VALID_FS ||
  95                     !(sb->u.minix_sb.s_mount_state & MINIX_VALID_FS))
  96                         return 0;
  97                 /* Mounting a rw partition read-only. */
  98                 ms->s_state = sb->u.minix_sb.s_mount_state;
  99                 mark_buffer_dirty(sb->u.minix_sb.s_sbh, 1);
 100                 sb->s_dirt = 1;
 101                 minix_commit_super (sb, ms);
 102         }
 103         else {
 104                 /* Mount a partition which is read-only, read-write. */
 105                 sb->u.minix_sb.s_mount_state = ms->s_state;
 106                 ms->s_state &= ~MINIX_VALID_FS;
 107                 mark_buffer_dirty(sb->u.minix_sb.s_sbh, 1);
 108                 sb->s_dirt = 1;
 109 
 110                 if (!(sb->u.minix_sb.s_mount_state & MINIX_VALID_FS))
 111                         printk ("MINIX-fs warning: remounting unchecked fs, "
 112                                 "running fsck is recommended.\n");
 113                 else if ((sb->u.minix_sb.s_mount_state & MINIX_ERROR_FS))
 114                         printk ("MINIX-fs warning: remounting fs with errors, "
 115                                 "running fsck is recommended.\n");
 116         }
 117         return 0;
 118 }
 119 
 120 struct super_block *minix_read_super(struct super_block *s,void *data, 
     /* [previous][next][first][last][top][bottom][index][help] */
 121                                      int silent)
 122 {
 123         struct buffer_head *bh;
 124         struct minix_super_block *ms;
 125         int i, block;
 126         kdev_t dev = s->s_dev;
 127 
 128         if (32 != sizeof (struct minix_inode))
 129                 panic("bad V1 i-node size");
 130         if (64 != sizeof(struct minix2_inode))
 131                 panic("bad V2 i-node size");
 132         MOD_INC_USE_COUNT;
 133         lock_super(s);
 134         set_blocksize(dev, BLOCK_SIZE);
 135         if (!(bh = bread(dev,1,BLOCK_SIZE))) {
 136                 s->s_dev = 0;
 137                 unlock_super(s);
 138                 printk("MINIX-fs: unable to read superblock\n");
 139                 MOD_DEC_USE_COUNT;
 140                 return NULL;
 141         }
 142         ms = (struct minix_super_block *) bh->b_data;
 143         s->u.minix_sb.s_ms = ms;
 144         s->u.minix_sb.s_sbh = bh;
 145         s->u.minix_sb.s_mount_state = ms->s_state;
 146         s->s_blocksize = 1024;
 147         s->s_blocksize_bits = 10;
 148         s->u.minix_sb.s_ninodes = ms->s_ninodes;
 149         s->u.minix_sb.s_imap_blocks = ms->s_imap_blocks;
 150         s->u.minix_sb.s_zmap_blocks = ms->s_zmap_blocks;
 151         s->u.minix_sb.s_firstdatazone = ms->s_firstdatazone;
 152         s->u.minix_sb.s_log_zone_size = ms->s_log_zone_size;
 153         s->u.minix_sb.s_max_size = ms->s_max_size;
 154         s->s_magic = ms->s_magic;
 155         if (s->s_magic == MINIX_SUPER_MAGIC) {
 156                 s->u.minix_sb.s_version = MINIX_V1;
 157                 s->u.minix_sb.s_nzones = ms->s_nzones;
 158                 s->u.minix_sb.s_dirsize = 16;
 159                 s->u.minix_sb.s_namelen = 14;
 160         } else if (s->s_magic == MINIX_SUPER_MAGIC2) {
 161                 s->u.minix_sb.s_version = MINIX_V1;
 162                 s->u.minix_sb.s_nzones = ms->s_nzones;
 163                 s->u.minix_sb.s_dirsize = 32;
 164                 s->u.minix_sb.s_namelen = 30;
 165         } else if (s->s_magic == MINIX2_SUPER_MAGIC) {
 166                 s->u.minix_sb.s_version = MINIX_V2;
 167                 s->u.minix_sb.s_nzones = ms->s_zones;
 168                 s->u.minix_sb.s_dirsize = 16;
 169                 s->u.minix_sb.s_namelen = 14;
 170         } else if (s->s_magic == MINIX2_SUPER_MAGIC2) {
 171                 s->u.minix_sb.s_version = MINIX_V2;
 172                 s->u.minix_sb.s_nzones = ms->s_zones;
 173                 s->u.minix_sb.s_dirsize = 32;
 174                 s->u.minix_sb.s_namelen = 30;
 175         } else {
 176                 s->s_dev = 0;
 177                 unlock_super(s);
 178                 brelse(bh);
 179                 if (!silent)
 180                         printk("VFS: Can't find a minix or minix V2 filesystem on dev "
 181                                "%s.\n", kdevname(dev));
 182                 MOD_DEC_USE_COUNT;
 183                 return NULL;
 184         }
 185         for (i=0;i < MINIX_I_MAP_SLOTS;i++)
 186                 s->u.minix_sb.s_imap[i] = NULL;
 187         for (i=0;i < MINIX_Z_MAP_SLOTS;i++)
 188                 s->u.minix_sb.s_zmap[i] = NULL;
 189         block=2;
 190         for (i=0 ; i < s->u.minix_sb.s_imap_blocks ; i++)
 191                 if ((s->u.minix_sb.s_imap[i]=bread(dev,block,BLOCK_SIZE)) != NULL)
 192                         block++;
 193                 else
 194                         break;
 195         for (i=0 ; i < s->u.minix_sb.s_zmap_blocks ; i++)
 196                 if ((s->u.minix_sb.s_zmap[i]=bread(dev,block,BLOCK_SIZE)) != NULL)
 197                         block++;
 198                 else
 199                         break;
 200         if (block != 2+s->u.minix_sb.s_imap_blocks+s->u.minix_sb.s_zmap_blocks) {
 201                 for(i=0;i<MINIX_I_MAP_SLOTS;i++)
 202                         brelse(s->u.minix_sb.s_imap[i]);
 203                 for(i=0;i<MINIX_Z_MAP_SLOTS;i++)
 204                         brelse(s->u.minix_sb.s_zmap[i]);
 205                 s->s_dev = 0;
 206                 unlock_super(s);
 207                 brelse(bh);
 208                 printk("MINIX-fs: bad superblock or unable to read bitmaps\n");
 209                 MOD_DEC_USE_COUNT;
 210                 return NULL;
 211         }
 212         set_bit(0,s->u.minix_sb.s_imap[0]->b_data);
 213         set_bit(0,s->u.minix_sb.s_zmap[0]->b_data);
 214         unlock_super(s);
 215         /* set up enough so that it can read an inode */
 216         s->s_dev = dev;
 217         s->s_op = &minix_sops;
 218         s->s_mounted = iget(s,MINIX_ROOT_INO);
 219         if (!s->s_mounted) {
 220                 s->s_dev = 0;
 221                 brelse(bh);
 222                 printk("MINIX-fs: get root inode failed\n");
 223                 MOD_DEC_USE_COUNT;
 224                 return NULL;
 225         }
 226         if (!(s->s_flags & MS_RDONLY)) {
 227                 ms->s_state &= ~MINIX_VALID_FS;
 228                 mark_buffer_dirty(bh, 1);
 229                 s->s_dirt = 1;
 230         }
 231         if (!(s->u.minix_sb.s_mount_state & MINIX_VALID_FS))
 232                 printk ("MINIX-fs: mounting unchecked file system, "
 233                         "running fsck is recommended.\n");
 234         else if (s->u.minix_sb.s_mount_state & MINIX_ERROR_FS)
 235                 printk ("MINIX-fs: mounting file system with errors, "
 236                         "running fsck is recommended.\n");
 237         return s;
 238 }
 239 
 240 void minix_statfs(struct super_block *sb, struct statfs *buf, int bufsiz)
     /* [previous][next][first][last][top][bottom][index][help] */
 241 {
 242         struct statfs tmp;
 243 
 244         tmp.f_type = sb->s_magic;
 245         tmp.f_bsize = sb->s_blocksize;
 246         tmp.f_blocks = (sb->u.minix_sb.s_nzones - sb->u.minix_sb.s_firstdatazone) << sb->u.minix_sb.s_log_zone_size;
 247         tmp.f_bfree = minix_count_free_blocks(sb);
 248         tmp.f_bavail = tmp.f_bfree;
 249         tmp.f_files = sb->u.minix_sb.s_ninodes;
 250         tmp.f_ffree = minix_count_free_inodes(sb);
 251         tmp.f_namelen = sb->u.minix_sb.s_namelen;
 252         memcpy_tofs(buf, &tmp, bufsiz);
 253 }
 254 
 255 /*
 256  * The minix V1 fs bmap functions.
 257  */
 258 #define V1_inode_bmap(inode,nr) (((unsigned short *)(inode)->u.minix_i.u.i1_data)[(nr)])
 259 
 260 static int V1_block_bmap(struct buffer_head * bh, int nr)
     /* [previous][next][first][last][top][bottom][index][help] */
 261 {
 262         int tmp;
 263 
 264         if (!bh)
 265                 return 0;
 266         tmp = ((unsigned short *) bh->b_data)[nr];
 267         brelse(bh);
 268         return tmp;
 269 }
 270 
 271 static int V1_minix_bmap(struct inode * inode,int block)
     /* [previous][next][first][last][top][bottom][index][help] */
 272 {
 273         int i;
 274 
 275         if (block<0) {
 276                 printk("minix_bmap: block<0");
 277                 return 0;
 278         }
 279         if (block >= (inode->i_sb->u.minix_sb.s_max_size/BLOCK_SIZE)) {
 280                 printk("minix_bmap: block>big");
 281                 return 0;
 282         }
 283         if (block < 7)
 284                 return V1_inode_bmap(inode,block);
 285         block -= 7;
 286         if (block < 512) {
 287                 i = V1_inode_bmap(inode,7);
 288                 if (!i)
 289                         return 0;
 290                 return V1_block_bmap(bread(inode->i_dev,i,BLOCK_SIZE),block);
 291         }
 292         block -= 512;
 293         i = V1_inode_bmap(inode,8);
 294         if (!i)
 295                 return 0;
 296         i = V1_block_bmap(bread(inode->i_dev,i,BLOCK_SIZE),block>>9);
 297         if (!i)
 298                 return 0;
 299         return V1_block_bmap(bread(inode->i_dev,i,BLOCK_SIZE),block & 511);
 300 }
 301 
 302 /*
 303  * The minix V2 fs bmap functions.
 304  */
 305 #define V2_inode_bmap(inode,nr) (((unsigned long  *)(inode)->u.minix_i.u.i2_data)[(nr)])
 306 static int V2_block_bmap(struct buffer_head * bh, int nr)
     /* [previous][next][first][last][top][bottom][index][help] */
 307 {
 308         int tmp;
 309 
 310         if (!bh)
 311                 return 0;
 312         tmp = ((unsigned long *) bh->b_data)[nr];
 313         brelse(bh);
 314         return tmp;
 315 }
 316 
 317 int V2_minix_bmap(struct inode * inode,int block)
     /* [previous][next][first][last][top][bottom][index][help] */
 318 {
 319         int i;
 320 
 321         if (block<0) {
 322                 printk("minix_bmap: block<0");
 323                 return 0;
 324         }
 325         if (block >= (inode->i_sb->u.minix_sb.s_max_size/BLOCK_SIZE)) {
 326                 printk("minix_bmap: block>big");
 327                 return 0;
 328         }
 329         if (block < 7)
 330                 return V2_inode_bmap(inode,block);
 331         block -= 7;
 332         if (block < 256) {
 333                 i = V2_inode_bmap(inode,7);
 334                 if (!i)
 335                         return 0;
 336                 return V2_block_bmap(bread(inode->i_dev,i,BLOCK_SIZE),block);
 337         }
 338         block -= 256;
 339         if (block < 256*256) {
 340                 i = V2_inode_bmap(inode,8);
 341                 if (!i)
 342                         return 0;
 343                 i = V2_block_bmap(bread(inode->i_dev,i,BLOCK_SIZE),block >> 8);
 344                 if (!i)
 345                         return 0;
 346                 return V2_block_bmap(bread(inode->i_dev,i,BLOCK_SIZE),block & 255);
 347         }
 348         block -= 256*256;
 349         i = V2_inode_bmap(inode,9);
 350         if (!i)
 351                 return 0;
 352         i = V2_block_bmap(bread(inode->i_dev,i,BLOCK_SIZE),block >> 16);
 353         if (!i)
 354                 return 0;
 355         i = V2_block_bmap(bread(inode->i_dev,i,BLOCK_SIZE),(block >> 8) & 255);
 356         if (!i)
 357                 return 0;
 358         return V2_block_bmap(bread(inode->i_dev,i,BLOCK_SIZE),block & 255);
 359 }
 360 
 361 /*
 362  * The global minix fs bmap function.
 363  */
 364 int minix_bmap(struct inode * inode,int block)
     /* [previous][next][first][last][top][bottom][index][help] */
 365 {
 366         if (INODE_VERSION(inode) == MINIX_V1)
 367                 return V1_minix_bmap(inode, block);
 368         else
 369                 return V2_minix_bmap(inode, block);
 370 }
 371 
 372 /*
 373  * The minix V1 fs getblk functions.
 374  */
 375 static struct buffer_head * V1_inode_getblk(struct inode * inode, int nr, 
     /* [previous][next][first][last][top][bottom][index][help] */
 376                                             int create)
 377 {
 378         int tmp;
 379         unsigned short *p;
 380         struct buffer_head * result;
 381 
 382         p = inode->u.minix_i.u.i1_data + nr;
 383 repeat:
 384         tmp = *p;
 385         if (tmp) {
 386                 result = getblk(inode->i_dev, tmp, BLOCK_SIZE);
 387                 if (tmp == *p)
 388                         return result;
 389                 brelse(result);
 390                 goto repeat;
 391         }
 392         if (!create)
 393                 return NULL;
 394         tmp = minix_new_block(inode->i_sb);
 395         if (!tmp)
 396                 return NULL;
 397         result = getblk(inode->i_dev, tmp, BLOCK_SIZE);
 398         if (*p) {
 399                 minix_free_block(inode->i_sb,tmp);
 400                 brelse(result);
 401                 goto repeat;
 402         }
 403         *p = tmp;
 404         inode->i_ctime = CURRENT_TIME;
 405         inode->i_dirt = 1;
 406         return result;
 407 }
 408 
 409 static struct buffer_head * V1_block_getblk(struct inode * inode, 
     /* [previous][next][first][last][top][bottom][index][help] */
 410         struct buffer_head * bh, int nr, int create)
 411 {
 412         int tmp;
 413         unsigned short *p;
 414         struct buffer_head * result;
 415 
 416         if (!bh)
 417                 return NULL;
 418         if (!buffer_uptodate(bh)) {
 419                 ll_rw_block(READ, 1, &bh);
 420                 wait_on_buffer(bh);
 421                 if (!buffer_uptodate(bh)) {
 422                         brelse(bh);
 423                         return NULL;
 424                 }
 425         }
 426         p = nr + (unsigned short *) bh->b_data;
 427 repeat:
 428         tmp = *p;
 429         if (tmp) {
 430                 result = getblk(bh->b_dev, tmp, BLOCK_SIZE);
 431                 if (tmp == *p) {
 432                         brelse(bh);
 433                         return result;
 434                 }
 435                 brelse(result);
 436                 goto repeat;
 437         }
 438         if (!create) {
 439                 brelse(bh);
 440                 return NULL;
 441         }
 442         tmp = minix_new_block(inode->i_sb);
 443         if (!tmp) {
 444                 brelse(bh);
 445                 return NULL;
 446         }
 447         result = getblk(bh->b_dev, tmp, BLOCK_SIZE);
 448         if (*p) {
 449                 minix_free_block(inode->i_sb,tmp);
 450                 brelse(result);
 451                 goto repeat;
 452         }
 453         *p = tmp;
 454         mark_buffer_dirty(bh, 1);
 455         brelse(bh);
 456         return result;
 457 }
 458 
 459 static struct buffer_head * V1_minix_getblk(struct inode * inode, int block, 
     /* [previous][next][first][last][top][bottom][index][help] */
 460                                             int create)
 461 {
 462         struct buffer_head * bh;
 463 
 464         if (block<0) {
 465                 printk("minix_getblk: block<0");
 466                 return NULL;
 467         }
 468         if (block >= inode->i_sb->u.minix_sb.s_max_size/BLOCK_SIZE) {
 469                 printk("minix_getblk: block>big");
 470                 return NULL;
 471         }
 472         if (block < 7)
 473                 return V1_inode_getblk(inode,block,create);
 474         block -= 7;
 475         if (block < 512) {
 476                 bh = V1_inode_getblk(inode,7,create);
 477                 return V1_block_getblk(inode, bh, block, create);
 478         }
 479         block -= 512;
 480         bh = V1_inode_getblk(inode,8,create);
 481         bh = V1_block_getblk(inode, bh, (block>>9) & 511, create);
 482         return V1_block_getblk(inode, bh, block & 511, create);
 483 }
 484 
 485 /*
 486  * The minix V2 fs getblk functions.
 487  */
 488 static struct buffer_head * V2_inode_getblk(struct inode * inode, int nr, 
     /* [previous][next][first][last][top][bottom][index][help] */
 489                                             int create)
 490 {
 491         int tmp;
 492         unsigned long *p;
 493         struct buffer_head * result;
 494 
 495         p = (unsigned long *) inode->u.minix_i.u.i2_data + nr;
 496 repeat:
 497         tmp = *p;
 498         if (tmp) {
 499                 result = getblk(inode->i_dev, tmp, BLOCK_SIZE);
 500                 if (tmp == *p)
 501                         return result;
 502                 brelse(result);
 503                 goto repeat;
 504         }
 505         if (!create)
 506                 return NULL;
 507         tmp = minix_new_block(inode->i_sb);
 508         if (!tmp)
 509                 return NULL;
 510         result = getblk(inode->i_dev, tmp, BLOCK_SIZE);
 511         if (*p) {
 512                 minix_free_block(inode->i_sb,tmp);
 513                 brelse(result);
 514                 goto repeat;
 515         }
 516         *p = tmp;
 517         inode->i_ctime = CURRENT_TIME;
 518         inode->i_dirt = 1;
 519         return result;
 520 }
 521 
 522 static struct buffer_head * V2_block_getblk(struct inode * inode, 
     /* [previous][next][first][last][top][bottom][index][help] */
 523         struct buffer_head * bh, int nr, int create)
 524 {
 525         int tmp;
 526         unsigned long *p;
 527         struct buffer_head * result;
 528 
 529         if (!bh)
 530                 return NULL;
 531         if (!buffer_uptodate(bh)) {
 532                 ll_rw_block(READ, 1, &bh);
 533                 wait_on_buffer(bh);
 534                 if (!buffer_uptodate(bh)) {
 535                         brelse(bh);
 536                         return NULL;
 537                 }
 538         }
 539         p = nr + (unsigned long *) bh->b_data;
 540 repeat:
 541         tmp = *p;
 542         if (tmp) {
 543                 result = getblk(bh->b_dev, tmp, BLOCK_SIZE);
 544                 if (tmp == *p) {
 545                         brelse(bh);
 546                         return result;
 547                 }
 548                 brelse(result);
 549                 goto repeat;
 550         }
 551         if (!create) {
 552                 brelse(bh);
 553                 return NULL;
 554         }
 555         tmp = minix_new_block(inode->i_sb);
 556         if (!tmp) {
 557                 brelse(bh);
 558                 return NULL;
 559         }
 560         result = getblk(bh->b_dev, tmp, BLOCK_SIZE);
 561         if (*p) {
 562                 minix_free_block(inode->i_sb,tmp);
 563                 brelse(result);
 564                 goto repeat;
 565         }
 566         *p = tmp;
 567         mark_buffer_dirty(bh, 1);
 568         brelse(bh);
 569         return result;
 570 }
 571 
 572 static struct buffer_head * V2_minix_getblk(struct inode * inode, int block, 
     /* [previous][next][first][last][top][bottom][index][help] */
 573                                             int create)
 574 {
 575         struct buffer_head * bh;
 576 
 577         if (block<0) {
 578                 printk("minix_getblk: block<0");
 579                 return NULL;
 580         }
 581         if (block >= inode->i_sb->u.minix_sb.s_max_size/BLOCK_SIZE) {
 582                 printk("minix_getblk: block>big");
 583                 return NULL;
 584         }
 585         if (block < 7)
 586                 return V2_inode_getblk(inode,block,create);
 587         block -= 7;
 588         if (block < 256) {
 589                 bh = V2_inode_getblk(inode,7,create);
 590                 return V2_block_getblk(inode, bh, block, create);
 591         }
 592         block -= 256;
 593         if (block < 256*256) {
 594                 bh = V2_inode_getblk(inode,8,create);
 595                 bh = V2_block_getblk(inode, bh, (block>>8) & 255, create);
 596                 return V2_block_getblk(inode, bh, block & 255, create);
 597         }
 598         block -= 256*256;
 599         bh = V2_inode_getblk(inode,9,create);
 600         bh = V2_block_getblk(inode, bh, (block >> 16) & 255, create);
 601         bh = V2_block_getblk(inode, bh, (block >> 8) & 255, create);
 602         return V2_block_getblk(inode, bh, block & 255, create);
 603 }
 604 
 605 /*
 606  * the global minix fs getblk function.
 607  */
 608 struct buffer_head * minix_getblk(struct inode * inode, int block, int create)
     /* [previous][next][first][last][top][bottom][index][help] */
 609 {
 610         if (INODE_VERSION(inode) == MINIX_V1)
 611                 return V1_minix_getblk(inode,block,create);
 612         else
 613                 return V2_minix_getblk(inode,block,create);
 614 }
 615 
 616 struct buffer_head * minix_bread(struct inode * inode, int block, int create)
     /* [previous][next][first][last][top][bottom][index][help] */
 617 {
 618         struct buffer_head * bh;
 619 
 620         bh = minix_getblk(inode,block,create);
 621         if (!bh || buffer_uptodate(bh))
 622                 return bh;
 623         ll_rw_block(READ, 1, &bh);
 624         wait_on_buffer(bh);
 625         if (buffer_uptodate(bh))
 626                 return bh;
 627         brelse(bh);
 628         return NULL;
 629 }
 630 
 631 /*
 632  * The minix V1 function to read an inode.
 633  */
 634 static void V1_minix_read_inode(struct inode * inode)
     /* [previous][next][first][last][top][bottom][index][help] */
 635 {
 636         struct buffer_head * bh;
 637         struct minix_inode * raw_inode;
 638         int block, ino;
 639 
 640         ino = inode->i_ino;
 641         inode->i_op = NULL;
 642         inode->i_mode = 0;
 643         if (!ino || ino >= inode->i_sb->u.minix_sb.s_ninodes) {
 644                 printk("Bad inode number on dev %s"
 645                        ": %d is out of range\n",
 646                         kdevname(inode->i_dev), ino);
 647                 return;
 648         }
 649         block = 2 + inode->i_sb->u.minix_sb.s_imap_blocks +
 650                     inode->i_sb->u.minix_sb.s_zmap_blocks +
 651                     (ino-1)/MINIX_INODES_PER_BLOCK;
 652         if (!(bh=bread(inode->i_dev,block, BLOCK_SIZE))) {
 653                 printk("Major problem: unable to read inode from dev "
 654                        "%s\n", kdevname(inode->i_dev));
 655                 return;
 656         }
 657         raw_inode = ((struct minix_inode *) bh->b_data) +
 658                     (ino-1)%MINIX_INODES_PER_BLOCK;
 659         inode->i_mode = raw_inode->i_mode;
 660         inode->i_uid = raw_inode->i_uid;
 661         inode->i_gid = raw_inode->i_gid;
 662         inode->i_nlink = raw_inode->i_nlinks;
 663         inode->i_size = raw_inode->i_size;
 664         inode->i_mtime = inode->i_atime = inode->i_ctime = raw_inode->i_time;
 665         inode->i_blocks = inode->i_blksize = 0;
 666         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
 667                 inode->i_rdev = to_kdev_t(raw_inode->i_zone[0]);
 668         else for (block = 0; block < 9; block++)
 669                 inode->u.minix_i.u.i1_data[block] = raw_inode->i_zone[block];
 670         brelse(bh);
 671         if (S_ISREG(inode->i_mode))
 672                 inode->i_op = &minix_file_inode_operations;
 673         else if (S_ISDIR(inode->i_mode))
 674                 inode->i_op = &minix_dir_inode_operations;
 675         else if (S_ISLNK(inode->i_mode))
 676                 inode->i_op = &minix_symlink_inode_operations;
 677         else if (S_ISCHR(inode->i_mode))
 678                 inode->i_op = &chrdev_inode_operations;
 679         else if (S_ISBLK(inode->i_mode))
 680                 inode->i_op = &blkdev_inode_operations;
 681         else if (S_ISFIFO(inode->i_mode))
 682                 init_fifo(inode);
 683 }
 684 
 685 /*
 686  * The minix V2 function to read an inode.
 687  */
 688 static void V2_minix_read_inode(struct inode * inode)
     /* [previous][next][first][last][top][bottom][index][help] */
 689 {
 690         struct buffer_head * bh;
 691         struct minix2_inode * raw_inode;
 692         int block, ino;
 693 
 694         ino = inode->i_ino;
 695         inode->i_op = NULL;
 696         inode->i_mode = 0;
 697         if (!ino || ino >= inode->i_sb->u.minix_sb.s_ninodes) {
 698                 printk("Bad inode number on dev %s"
 699                        ": %d is out of range\n",
 700                         kdevname(inode->i_dev), ino);
 701                 return;
 702         }
 703         block = 2 + inode->i_sb->u.minix_sb.s_imap_blocks +
 704                     inode->i_sb->u.minix_sb.s_zmap_blocks +
 705                     (ino-1)/MINIX2_INODES_PER_BLOCK;
 706         if (!(bh=bread(inode->i_dev,block, BLOCK_SIZE))) {
 707                 printk("Major problem: unable to read inode from dev "
 708                        "%s\n", kdevname(inode->i_dev));
 709                 return;
 710         }
 711         raw_inode = ((struct minix2_inode *) bh->b_data) +
 712                     (ino-1)%MINIX2_INODES_PER_BLOCK;
 713         inode->i_mode = raw_inode->i_mode;
 714         inode->i_uid = raw_inode->i_uid;
 715         inode->i_gid = raw_inode->i_gid;
 716         inode->i_nlink = raw_inode->i_nlinks;
 717         inode->i_size = raw_inode->i_size;
 718         inode->i_mtime = raw_inode->i_mtime;
 719         inode->i_atime = raw_inode->i_atime;
 720         inode->i_ctime = raw_inode->i_ctime;
 721         inode->i_blocks = inode->i_blksize = 0;
 722         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
 723                 inode->i_rdev = to_kdev_t(raw_inode->i_zone[0]);
 724         else for (block = 0; block < 10; block++)
 725                 inode->u.minix_i.u.i2_data[block] = raw_inode->i_zone[block];
 726         brelse(bh);
 727         if (S_ISREG(inode->i_mode))
 728                 inode->i_op = &minix_file_inode_operations;
 729         else if (S_ISDIR(inode->i_mode))
 730                 inode->i_op = &minix_dir_inode_operations;
 731         else if (S_ISLNK(inode->i_mode))
 732                 inode->i_op = &minix_symlink_inode_operations;
 733         else if (S_ISCHR(inode->i_mode))
 734                 inode->i_op = &chrdev_inode_operations;
 735         else if (S_ISBLK(inode->i_mode))
 736                 inode->i_op = &blkdev_inode_operations;
 737         else if (S_ISFIFO(inode->i_mode))
 738                 init_fifo(inode);
 739 }
 740 
 741 /*
 742  * The global function to read an inode.
 743  */
 744 void minix_read_inode(struct inode * inode)
     /* [previous][next][first][last][top][bottom][index][help] */
 745 {
 746         if (INODE_VERSION(inode) == MINIX_V1)
 747                 V1_minix_read_inode(inode);
 748         else
 749                 V2_minix_read_inode(inode);
 750 }
 751 
 752 /*
 753  * The minix V1 function to synchronize an inode.
 754  */
 755 static struct buffer_head * V1_minix_update_inode(struct inode * inode)
     /* [previous][next][first][last][top][bottom][index][help] */
 756 {
 757         struct buffer_head * bh;
 758         struct minix_inode * raw_inode;
 759         int ino, block;
 760 
 761         ino = inode->i_ino;
 762         if (!ino || ino >= inode->i_sb->u.minix_sb.s_ninodes) {
 763                 printk("Bad inode number on dev %s"
 764                        ": %d is out of range\n",
 765                         kdevname(inode->i_dev), ino);
 766                 inode->i_dirt = 0;
 767                 return 0;
 768         }
 769         block = 2 + inode->i_sb->u.minix_sb.s_imap_blocks + inode->i_sb->u.minix_sb.s_zmap_blocks +
 770                 (ino-1)/MINIX_INODES_PER_BLOCK;
 771         if (!(bh=bread(inode->i_dev, block, BLOCK_SIZE))) {
 772                 printk("unable to read i-node block\n");
 773                 inode->i_dirt = 0;
 774                 return 0;
 775         }
 776         raw_inode = ((struct minix_inode *)bh->b_data) +
 777                 (ino-1)%MINIX_INODES_PER_BLOCK;
 778         raw_inode->i_mode = inode->i_mode;
 779         raw_inode->i_uid = inode->i_uid;
 780         raw_inode->i_gid = inode->i_gid;
 781         raw_inode->i_nlinks = inode->i_nlink;
 782         raw_inode->i_size = inode->i_size;
 783         raw_inode->i_time = inode->i_mtime;
 784         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
 785                 raw_inode->i_zone[0] = kdev_t_to_nr(inode->i_rdev);
 786         else for (block = 0; block < 9; block++)
 787                 raw_inode->i_zone[block] = inode->u.minix_i.u.i1_data[block];
 788         inode->i_dirt=0;
 789         mark_buffer_dirty(bh, 1);
 790         return bh;
 791 }
 792 
 793 /*
 794  * The minix V2 function to synchronize an inode.
 795  */
 796 static struct buffer_head * V2_minix_update_inode(struct inode * inode)
     /* [previous][next][first][last][top][bottom][index][help] */
 797 {
 798         struct buffer_head * bh;
 799         struct minix2_inode * raw_inode;
 800         int ino, block;
 801 
 802         ino = inode->i_ino;
 803         if (!ino || ino >= inode->i_sb->u.minix_sb.s_ninodes) {
 804                 printk("Bad inode number on dev %s"
 805                        ": %d is out of range\n",
 806                         kdevname(inode->i_dev), ino);
 807                 inode->i_dirt = 0;
 808                 return 0;
 809         }
 810         block = 2 + inode->i_sb->u.minix_sb.s_imap_blocks + inode->i_sb->u.minix_sb.s_zmap_blocks +
 811                 (ino-1)/MINIX2_INODES_PER_BLOCK;
 812         if (!(bh=bread(inode->i_dev, block, BLOCK_SIZE))) {
 813                 printk("unable to read i-node block\n");
 814                 inode->i_dirt = 0;
 815                 return 0;
 816         }
 817         raw_inode = ((struct minix2_inode *)bh->b_data) +
 818                 (ino-1)%MINIX2_INODES_PER_BLOCK;
 819         raw_inode->i_mode = inode->i_mode;
 820         raw_inode->i_uid = inode->i_uid;
 821         raw_inode->i_gid = inode->i_gid;
 822         raw_inode->i_nlinks = inode->i_nlink;
 823         raw_inode->i_size = inode->i_size;
 824         raw_inode->i_mtime = inode->i_mtime;
 825         raw_inode->i_atime = inode->i_atime;
 826         raw_inode->i_ctime = inode->i_ctime;
 827         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
 828                 raw_inode->i_zone[0] = kdev_t_to_nr(inode->i_rdev);
 829         else for (block = 0; block < 10; block++)
 830                 raw_inode->i_zone[block] = inode->u.minix_i.u.i2_data[block];
 831         inode->i_dirt=0;
 832         mark_buffer_dirty(bh, 1);
 833         return bh;
 834 }
 835 
 836 struct buffer_head *minix_update_inode(struct inode *inode)
     /* [previous][next][first][last][top][bottom][index][help] */
 837 {
 838         if (INODE_VERSION(inode) == MINIX_V1)
 839                 return V1_minix_update_inode(inode);
 840         else
 841                 return V2_minix_update_inode(inode);
 842 }
 843 
 844 void minix_write_inode(struct inode * inode)
     /* [previous][next][first][last][top][bottom][index][help] */
 845 {
 846         struct buffer_head *bh;
 847 
 848         bh = minix_update_inode(inode);
 849         brelse(bh);
 850 }
 851 
 852 int minix_sync_inode(struct inode * inode)
     /* [previous][next][first][last][top][bottom][index][help] */
 853 {
 854         int err = 0;
 855         struct buffer_head *bh;
 856 
 857         bh = minix_update_inode(inode);
 858         if (bh && buffer_dirty(bh))
 859         {
 860                 ll_rw_block(WRITE, 1, &bh);
 861                 wait_on_buffer(bh);
 862                 if (buffer_req(bh) && !buffer_uptodate(bh))
 863                 {
 864                         printk ("IO error syncing minix inode ["
 865                                 "%s:%08lx]\n",
 866                                 kdevname(inode->i_dev), inode->i_ino);
 867                         err = -1;
 868                 }
 869         }
 870         else if (!bh)
 871                 err = -1;
 872         brelse (bh);
 873         return err;
 874 }
 875 
 876 #ifdef MODULE
 877 
 878 static struct file_system_type minix_fs_type = {
 879         minix_read_super, "minix", 1, NULL
 880 };
 881 
 882 int init_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 883 {
 884         return register_filesystem(&minix_fs_type);
 885 }
 886 
 887 void cleanup_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 888 {
 889         unregister_filesystem(&minix_fs_type);
 890 }
 891 
 892 #endif

/* [previous][next][first][last][top][bottom][index][help] */