root/fs/sysv/inode.c

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

DEFINITIONS

This source file includes following definitions.
  1. _coh_wait_on_inode
  2. sysv_put_inode
  3. detected_bs512
  4. detected_bs1024
  5. detect_xenix
  6. detect_sysv4
  7. detect_sysv2
  8. detect_coherent
  9. sysv_read_super
  10. sysv_write_super
  11. sysv_put_super
  12. sysv_statfs
  13. inode_bmap
  14. block_bmap
  15. sysv_bmap
  16. inode_getblk
  17. block_getblk
  18. sysv_getblk
  19. sysv_file_bread
  20. read3byte
  21. write3byte
  22. coh_read3byte
  23. coh_write3byte
  24. sysv_read_inode
  25. sysv_notify_change
  26. sysv_update_inode
  27. sysv_write_inode
  28. sysv_sync_inode

   1 /*
   2  *  linux/fs/sysv/inode.c
   3  *
   4  *  minix/inode.c
   5  *  Copyright (C) 1991, 1992  Linus Torvalds
   6  *
   7  *  xenix/inode.c
   8  *  Copyright (C) 1992  Doug Evans
   9  *
  10  *  coh/inode.c
  11  *  Copyright (C) 1993  Pascal Haible, Bruno Haible
  12  *
  13  *  sysv/inode.c
  14  *  Copyright (C) 1993  Paul B. Monday
  15  *
  16  *  sysv/inode.c
  17  *  Copyright (C) 1993  Bruno Haible
  18  *
  19  *  This file contains code for allocating/freeing inodes and for read/writing
  20  *  the superblock.
  21  */
  22 
  23 #include <linux/sched.h>
  24 #include <linux/kernel.h>
  25 #include <linux/fs.h>
  26 #include <linux/sysv_fs.h>
  27 #include <linux/stat.h>
  28 #include <linux/string.h>
  29 #include <linux/locks.h>
  30 
  31 #include <asm/segment.h>
  32 
  33 void _coh_wait_on_inode (struct inode * inode)
     /* [previous][next][first][last][top][bottom][index][help] */
  34 {
  35         struct wait_queue wait = { current, NULL };
  36 
  37         add_wait_queue(&inode->u.sysv_i.i_wait, &wait);
  38 repeat:
  39         current->state = TASK_UNINTERRUPTIBLE;
  40         if (inode->u.sysv_i.i_lock) {
  41                 schedule();
  42                 goto repeat;
  43         }
  44         remove_wait_queue(&inode->u.sysv_i.i_wait, &wait);
  45         current->state = TASK_RUNNING;
  46 }
  47 
  48 void sysv_put_inode(struct inode *inode)
     /* [previous][next][first][last][top][bottom][index][help] */
  49 {
  50         if (inode->i_nlink)
  51                 return;
  52         inode->i_size = 0;
  53         sysv_truncate(inode);
  54         sysv_free_inode(inode);
  55 }
  56 
  57 
  58 static struct super_operations sysv_sops = { 
  59         sysv_read_inode,
  60         sysv_notify_change,
  61         sysv_write_inode,
  62         sysv_put_inode,
  63         sysv_put_super,
  64         sysv_write_super,
  65         sysv_statfs,
  66         NULL
  67 };
  68 
  69 /* The following functions try to recognize specific filesystems.
  70  * We recognize:
  71  * - Xenix FS by its magic number.
  72  * - SystemV FS by its magic number.
  73  * - Coherent FS by its funny fname/fpack field.
  74  * We discriminate among SystemV4 and SystemV2 FS by the assumption that
  75  * the time stamp is not < 01-01-1980.
  76  */
  77 
  78 static void detected_bs512 (struct super_block *sb)
     /* [previous][next][first][last][top][bottom][index][help] */
  79 {
  80         sb->sv_block_size = 512;
  81         sb->sv_block_size_1 = 512-1;
  82         sb->sv_block_size_bits = 9;
  83         sb->sv_block_size_ratio = 2;
  84         sb->sv_block_size_ratio_1 = 2-1;
  85         sb->sv_block_size_ratio_bits = 1;
  86         sb->sv_inodes_per_block = 512/64;
  87         sb->sv_inodes_per_block_1 = 512/64-1;
  88         sb->sv_inodes_per_block_bits = 9-6;
  89         sb->sv_toobig_block = 10 + 
  90           (sb->sv_ind_per_block = 512/4) +
  91           (sb->sv_ind_per_block_2 = (512/4)*(512/4)) +
  92           (sb->sv_ind_per_block_3 = (512/4)*(512/4)*(512/4));
  93         sb->sv_ind_per_block_1 = 512/4-1;
  94         sb->sv_ind_per_block_2_1 = (512/4)*(512/4)-1;
  95         sb->sv_ind_per_block_2_bits = 2 *
  96           (sb->sv_ind_per_block_bits = 9-2);
  97 }
  98 
  99 static void detected_bs1024 (struct super_block *sb)
     /* [previous][next][first][last][top][bottom][index][help] */
 100 {
 101         sb->sv_block_size = 1024;
 102         sb->sv_block_size_1 = 1024-1;
 103         sb->sv_block_size_bits = 10;
 104         sb->sv_block_size_ratio = 1;
 105         sb->sv_block_size_ratio_1 = 1-1;
 106         sb->sv_block_size_ratio_bits = 0;
 107         sb->sv_inodes_per_block = 1024/64;
 108         sb->sv_inodes_per_block_1 = 1024/64-1;
 109         sb->sv_inodes_per_block_bits = 10-6;
 110         sb->sv_toobig_block = 10 + 
 111           (sb->sv_ind_per_block = 1024/4) +
 112           (sb->sv_ind_per_block_2 = (1024/4)*(1024/4)) +
 113           (sb->sv_ind_per_block_3 = (1024/4)*(1024/4)*(1024/4));
 114         sb->sv_ind_per_block_1 = 1024/4-1;
 115         sb->sv_ind_per_block_2_1 = (1024/4)*(1024/4)-1;
 116         sb->sv_ind_per_block_2_bits = 2 *
 117           (sb->sv_ind_per_block_bits = 10-2);
 118 }
 119 
 120 static const char* detect_xenix (struct super_block *sb, struct buffer_head *bh)
     /* [previous][next][first][last][top][bottom][index][help] */
 121 {
 122         struct xenix_super_block * sbd;
 123 
 124         sbd = (struct xenix_super_block *) bh->b_data;
 125         if (sbd->s_magic != 0x2b5544)
 126                 return NULL;
 127         sb->sv_type = FSTYPE_XENIX;
 128         sb->sv_convert = 0;
 129         sb->sv_kludge_symlinks = 1;
 130         sb->sv_truncate = 1;
 131         sb->sv_link_max = XENIX_LINK_MAX;
 132         sb->sv_fic_size = XENIX_NICINOD;
 133         sb->sv_flc_size = XENIX_NICFREE;
 134         sb->sv_bh = bh;
 135         sb->sv_sbd = (char *) sbd;
 136         sb->sv_sb_fic_count = &sbd->s_ninode;
 137         sb->sv_sb_fic_inodes = &sbd->s_inode[0];
 138         sb->sv_sb_total_free_inodes = &sbd->s_tinode;
 139         sb->sv_sb_flc_count = &sbd->s_nfree;
 140         sb->sv_sb_flc_blocks = &sbd->s_free[0];
 141         sb->sv_sb_total_free_blocks = &sbd->s_tfree;
 142         sb->sv_sb_time = &sbd->s_time;
 143         sb->sv_block_base = 0;
 144         sb->sv_firstinodezone = 2;
 145         sb->sv_firstdatazone = sbd->s_isize;
 146         sb->sv_nzones = sbd->s_fsize;
 147         sb->sv_ndatazones = sb->sv_nzones - sb->sv_firstdatazone;
 148         switch (sbd->s_type) {
 149                 case 1: detected_bs512(sb); break;
 150                 case 2: detected_bs1024(sb); break;
 151                 default: return NULL;
 152         }
 153         return "Xenix";
 154 }
 155 
 156 static const char* detect_sysv4 (struct super_block *sb, struct buffer_head *bh)
     /* [previous][next][first][last][top][bottom][index][help] */
 157 {
 158         struct sysv4_super_block * sbd;
 159 
 160         sbd = (struct sysv4_super_block *) (bh->b_data + BLOCK_SIZE/2);
 161         if (sbd->s_magic != 0xfd187e20)
 162                 return NULL;
 163         if (sbd->s_time < 315532800) /* this is likely to happen on SystemV2 FS */
 164                 return NULL;
 165         sb->sv_type = FSTYPE_SYSV4;
 166         sb->sv_convert = 0;
 167         sb->sv_kludge_symlinks = 0; /* ?? */
 168         sb->sv_truncate = 1;
 169         sb->sv_link_max = SYSV_LINK_MAX;
 170         sb->sv_fic_size = SYSV_NICINOD;
 171         sb->sv_flc_size = SYSV_NICFREE;
 172         sb->sv_bh = bh;
 173         sb->sv_sbd = (char *) sbd;
 174         sb->sv_sb_fic_count = &sbd->s_ninode;
 175         sb->sv_sb_fic_inodes = &sbd->s_inode[0];
 176         sb->sv_sb_total_free_inodes = &sbd->s_tinode;
 177         sb->sv_sb_flc_count = &sbd->s_nfree;
 178         sb->sv_sb_flc_blocks = &sbd->s_free[0];
 179         sb->sv_sb_total_free_blocks = &sbd->s_tfree;
 180         sb->sv_sb_time = &sbd->s_time;
 181         sb->sv_block_base = 0;
 182         sb->sv_firstinodezone = 2;
 183         sb->sv_firstdatazone = sbd->s_isize;
 184         sb->sv_nzones = sbd->s_fsize;
 185         sb->sv_ndatazones = sb->sv_nzones - sb->sv_firstdatazone;
 186         switch (sbd->s_type) {
 187                 case 1: detected_bs512(sb); break;
 188                 case 2: detected_bs1024(sb); break;
 189                 default: return NULL;
 190         }
 191         return "SystemV";
 192 }
 193 
 194 static const char* detect_sysv2 (struct super_block *sb, struct buffer_head *bh)
     /* [previous][next][first][last][top][bottom][index][help] */
 195 {
 196         struct sysv2_super_block * sbd;
 197 
 198         sbd = (struct sysv2_super_block *) (bh->b_data + BLOCK_SIZE/2);
 199         if (sbd->s_magic != 0xfd187e20)
 200                 return NULL;
 201         if (sbd->s_time < 315532800) /* this is likely to happen on SystemV4 FS */
 202                 return NULL;
 203         sb->sv_type = FSTYPE_SYSV2;
 204         sb->sv_convert = 0;
 205         sb->sv_kludge_symlinks = 0; /* ?? */
 206         sb->sv_truncate = 1;
 207         sb->sv_link_max = SYSV_LINK_MAX;
 208         sb->sv_fic_size = SYSV_NICINOD;
 209         sb->sv_flc_size = SYSV_NICFREE;
 210         sb->sv_bh = bh;
 211         sb->sv_sbd = (char *) sbd;
 212         sb->sv_sb_fic_count = &sbd->s_ninode;
 213         sb->sv_sb_fic_inodes = &sbd->s_inode[0];
 214         sb->sv_sb_total_free_inodes = &sbd->s_tinode;
 215         sb->sv_sb_flc_count = &sbd->s_nfree;
 216         sb->sv_sb_flc_blocks = &sbd->s_free[0];
 217         sb->sv_sb_total_free_blocks = &sbd->s_tfree;
 218         sb->sv_sb_time = &sbd->s_time;
 219         sb->sv_block_base = 0;
 220         sb->sv_firstinodezone = 2;
 221         sb->sv_firstdatazone = sbd->s_isize;
 222         sb->sv_nzones = sbd->s_fsize;
 223         sb->sv_ndatazones = sb->sv_nzones - sb->sv_firstdatazone;
 224         switch (sbd->s_type) {
 225                 case 1: detected_bs512(sb); break;
 226                 case 2: detected_bs1024(sb); break;
 227                 default: return NULL;
 228         }
 229         return "SystemV Release 2";
 230 }
 231 
 232 static const char* detect_coherent (struct super_block *sb, struct buffer_head *bh)
     /* [previous][next][first][last][top][bottom][index][help] */
 233 {
 234         struct coh_super_block * sbd;
 235 
 236         sbd = (struct coh_super_block *) (bh->b_data + BLOCK_SIZE/2);
 237         if ((memcmp(sbd->s_fname,"noname",6) && memcmp(sbd->s_fname,"xxxxx ",6))
 238             || (memcmp(sbd->s_fpack,"nopack",6) && memcmp(sbd->s_fpack,"xxxxx\n",6)))
 239                 return NULL;
 240         sb->sv_type = FSTYPE_COH;
 241         sb->sv_convert = 1;
 242         sb->sv_kludge_symlinks = 1;
 243         sb->sv_truncate = 1;
 244         sb->sv_link_max = COH_LINK_MAX;
 245         sb->sv_fic_size = COH_NICINOD;
 246         sb->sv_flc_size = COH_NICFREE;
 247         sb->sv_bh = bh;
 248         sb->sv_sbd = (char *) sbd;
 249         sb->sv_sb_fic_count = &sbd->s_ninode;
 250         sb->sv_sb_fic_inodes = &sbd->s_inode[0];
 251         sb->sv_sb_total_free_inodes = &sbd->s_tinode;
 252         sb->sv_sb_flc_count = &sbd->s_nfree;
 253         sb->sv_sb_flc_blocks = &sbd->s_free[0];
 254         sb->sv_sb_total_free_blocks = &sbd->s_tfree;
 255         sb->sv_sb_time = &sbd->s_time;
 256         sb->sv_block_base = 0;
 257         sb->sv_firstinodezone = 2;
 258         sb->sv_firstdatazone = sbd->s_isize;
 259         sb->sv_nzones = from_coh_ulong(sbd->s_fsize);
 260         sb->sv_ndatazones = sb->sv_nzones - sb->sv_firstdatazone;
 261         detected_bs512(sb);
 262         return "Coherent";
 263 }
 264 
 265 struct super_block *sysv_read_super(struct super_block *sb,void *data, 
     /* [previous][next][first][last][top][bottom][index][help] */
 266                                      int silent)
 267 {
 268         struct buffer_head *bh;
 269         const char *found;
 270         int dev = sb->s_dev;
 271 
 272         if (1024 != sizeof (struct xenix_super_block))
 273                 panic("Xenix FS: bad super-block size");
 274         if ((512 != sizeof (struct sysv4_super_block))
 275             || (512 != sizeof (struct sysv2_super_block)))
 276                 panic("SystemV FS: bad super-block size");
 277         if (500 != sizeof (struct coh_super_block))
 278                 panic("Coherent FS: bad super-block size");
 279         if (64 != sizeof (struct sysv_inode))
 280                 panic("sysv fs: bad i-node size");
 281         lock_super(sb);
 282         sb->s_blocksize = BLOCK_SIZE; /* anything else not supported by the block device drivers */
 283         sb->s_blocksize_bits = BLOCK_SIZE_BITS;
 284 
 285         /* Try to read Xenix superblock */
 286         if ((bh = bread(dev, 1, BLOCK_SIZE)) != NULL) {
 287                 if ((found = detect_xenix(sb,bh)) != NULL)
 288                         goto ok;
 289                 brelse(bh);
 290         }
 291         if ((bh = bread(dev, 0, BLOCK_SIZE)) != NULL) {
 292                 /* Try to recognize SystemV superblock */
 293                 if ((found = detect_sysv4(sb,bh)) != NULL)
 294                         goto ok;
 295                 if ((found = detect_sysv2(sb,bh)) != NULL)
 296                         goto ok;
 297                 /* Try to recognize Coherent superblock */
 298                 if ((found = detect_coherent(sb,bh)) != NULL)
 299                         goto ok;
 300                 brelse(bh);
 301         }
 302         /* Try to recognize SystemV2 superblock */
 303         /* Offset by 1 track, i.e. most probably 9, 15, or 18 kilobytes. */
 304         {       static int offsets[] = { 9, 15, 18, };
 305                 int i;
 306                 for (i = 0; i < sizeof(offsets)/sizeof(offsets[0]); i++)
 307                         if ((bh = bread(dev, offsets[i], BLOCK_SIZE)) != NULL) {
 308                                 /* Try to recognize SystemV superblock */
 309                                 if ((found = detect_sysv4(sb,bh)) != NULL) {
 310                                         sb->sv_block_base = offsets[i];
 311                                         goto ok;
 312                                 }
 313                                 if ((found = detect_sysv2(sb,bh)) != NULL) {
 314                                         sb->sv_block_base = offsets[i];
 315                                         goto ok;
 316                                 }
 317                                 brelse(bh);
 318                         }
 319         }
 320         sb->s_dev=0;
 321         unlock_super(sb);
 322         if (!silent)
 323                 printk("VFS: unable to read Xenix/SystemV/Coherent superblock on device %d/%d\n",MAJOR(dev),MINOR(dev));
 324         return NULL;
 325 
 326         ok:
 327         sb->sv_ninodes = (sb->sv_firstdatazone - sb->sv_firstinodezone) << sb->sv_inodes_per_block_bits;
 328         if (!silent)
 329                 printk("VFS: Found a %s FS (block size = %d) on device %d/%d\n",found,sb->sv_block_size,MAJOR(dev),MINOR(dev));
 330         sb->s_magic = SYSV_MAGIC_BASE + sb->sv_type;
 331         /* set up enough so that it can read an inode */
 332         sb->s_dev = dev;
 333         sb->s_op = &sysv_sops;
 334         sb->s_mounted = iget(sb,SYSV_ROOT_INO);
 335         unlock_super(sb);
 336         if (!sb->s_mounted) {
 337                 brelse(bh);
 338                 sb->s_dev = 0;
 339                 printk("SysV FS: get root inode failed\n");
 340                 return NULL;
 341         }
 342         sb->s_dirt = 1; /* brelse(bh); occurs when the disk is unmounted. */
 343         return sb;
 344 }
 345 
 346 /* This is only called on sync() and umount(), when s_dirt=1. */
 347 void sysv_write_super (struct super_block *sb)
     /* [previous][next][first][last][top][bottom][index][help] */
 348 {
 349         lock_super(sb);
 350         if (sb->sv_bh->b_dirt) {
 351                 /* If we are going to write out the super block,
 352                    then attach current time stamp. */
 353                 unsigned long time = CURRENT_TIME;
 354                 if (sb->sv_convert)
 355                         time = to_coh_ulong(time);
 356                 *sb->sv_sb_time = time;
 357         }
 358         sb->s_dirt = 0;
 359         unlock_super(sb);
 360 }
 361 
 362 void sysv_put_super(struct super_block *sb)
     /* [previous][next][first][last][top][bottom][index][help] */
 363 {
 364         /* we can assume sysv_write_super() has already been called */
 365         lock_super(sb);
 366         brelse(sb->sv_bh);
 367         sb->s_dev = 0;
 368         unlock_super(sb);
 369 }
 370 
 371 void sysv_statfs(struct super_block *sb, struct statfs *buf)
     /* [previous][next][first][last][top][bottom][index][help] */
 372 {
 373         long tmp;
 374 
 375         put_fs_long(sb->s_magic, &buf->f_type);         /* type of filesystem */
 376         put_fs_long(sb->sv_block_size, &buf->f_bsize);  /* block size */
 377         put_fs_long(sb->sv_ndatazones, &buf->f_blocks); /* total data blocks in file system */
 378         tmp = sysv_count_free_blocks(sb);
 379         put_fs_long(tmp, &buf->f_bfree);                /* free blocks in fs */
 380         put_fs_long(tmp, &buf->f_bavail);               /* free blocks available to non-superuser */
 381         put_fs_long(sb->sv_ninodes, &buf->f_files);     /* total file nodes in file system */
 382         put_fs_long(sysv_count_free_inodes(sb), &buf->f_ffree); /* free file nodes in fs */
 383         put_fs_long(SYSV_NAMELEN, &buf->f_namelen);
 384         /* Don't know what value to put in buf->f_fsid */       /* file system id */
 385 }
 386 
 387 
 388 /* bmap support for running executables and shared libraries.
 389    Used only if block_size = BLOCK_SIZE. */
 390 
 391 #define IND_PER_BLOCK   (BLOCK_SIZE / sizeof(sysv_zone_t))
 392 
 393 static inline int inode_bmap(struct super_block * sb, struct inode * inode, int nr)
     /* [previous][next][first][last][top][bottom][index][help] */
 394 {
 395         int tmp = inode->u.sysv_i.i_data[nr];
 396         if (!tmp)
 397                 return 0;
 398         return tmp + sb->sv_block_base;
 399 }
 400 
 401 static int block_bmap(struct super_block * sb, struct buffer_head * bh, int nr, int convert)
     /* [previous][next][first][last][top][bottom][index][help] */
 402 {
 403         int tmp;
 404 
 405         if (!bh)
 406                 return 0;
 407         tmp = ((sysv_zone_t *) bh->b_data) [nr];
 408         if (convert)
 409                 tmp = from_coh_ulong(tmp);
 410         brelse(bh);
 411         if (!tmp)
 412                 return 0;
 413         return tmp + sb->sv_block_base;
 414 }
 415 
 416 int sysv_bmap(struct inode * inode,int block_nr)
     /* [previous][next][first][last][top][bottom][index][help] */
 417 {
 418         unsigned int block = block_nr;
 419         struct super_block * sb = inode->i_sb;
 420         int convert;
 421         int i;
 422         struct buffer_head * bh;
 423 
 424         if (block < 10)
 425                 return inode_bmap(sb,inode,block);
 426         block -= 10;
 427         convert = sb->sv_convert;
 428         if (block < IND_PER_BLOCK) {
 429                 i = inode_bmap(sb,inode,10);
 430                 if (!i)
 431                         return 0;
 432                 bh = bread(inode->i_dev,i,BLOCK_SIZE);
 433                 return block_bmap(sb,bh,block,convert);
 434         }
 435         block -= IND_PER_BLOCK;
 436         if (block < IND_PER_BLOCK*IND_PER_BLOCK) {
 437                 i = inode_bmap(sb,inode,11);
 438                 if (!i)
 439                         return 0;
 440                 bh = bread(inode->i_dev,i,BLOCK_SIZE);
 441                 i = block_bmap(sb,bh,block/IND_PER_BLOCK,convert);
 442                 if (!i)
 443                         return 0;
 444                 bh = bread(inode->i_dev,i,BLOCK_SIZE);
 445                 return block_bmap(sb,bh,block%IND_PER_BLOCK,convert);
 446         }
 447         block -= IND_PER_BLOCK*IND_PER_BLOCK;
 448         if (block < IND_PER_BLOCK*IND_PER_BLOCK*IND_PER_BLOCK) {
 449                 i = inode_bmap(sb,inode,12);
 450                 if (!i)
 451                         return 0;
 452                 bh = bread(inode->i_dev,i,BLOCK_SIZE);
 453                 i = block_bmap(sb,bh,block/(IND_PER_BLOCK*IND_PER_BLOCK),convert);
 454                 if (!i)
 455                         return 0;
 456                 bh = bread(inode->i_dev,i,BLOCK_SIZE);
 457                 i = block_bmap(sb,bh,(block/IND_PER_BLOCK)%IND_PER_BLOCK,convert);
 458                 if (!i)
 459                         return 0;
 460                 bh = bread(inode->i_dev,i,BLOCK_SIZE);
 461                 return block_bmap(sb,bh,block%IND_PER_BLOCK,convert);
 462         }
 463         if ((int)block<0) {
 464                 printk("sysv_bmap: block<0");
 465                 return 0;
 466         }
 467         printk("sysv_bmap: block>big");
 468         return 0;
 469 }
 470 
 471 /* End of bmap support. */
 472 
 473 
 474 /* Access selected blocks of regular files (or directories) */
 475 
 476 static struct buffer_head * inode_getblk(struct inode * inode, int nr, int create, char * *start)
     /* [previous][next][first][last][top][bottom][index][help] */
 477 {
 478         struct super_block *sb;
 479         unsigned long tmp;
 480         unsigned long *p;
 481         struct buffer_head * result;
 482 
 483         sb = inode->i_sb;
 484         p = inode->u.sysv_i.i_data + nr;
 485 repeat:
 486         tmp = *p;
 487         if (tmp) {
 488                 result = getblk(inode->i_dev, (tmp >> sb->sv_block_size_ratio_bits) + sb->sv_block_base, BLOCK_SIZE);
 489                 if (tmp == *p) {
 490                         *start = result->b_data + ((tmp & sb->sv_block_size_ratio_1) << sb->sv_block_size_bits);
 491                         return result;
 492                 }
 493                 brelse(result);
 494                 goto repeat;
 495         }
 496         if (!create)
 497                 return NULL;
 498         tmp = sysv_new_block(sb);
 499         if (!tmp)
 500                 return NULL;
 501         result = getblk(inode->i_dev, (tmp >> sb->sv_block_size_ratio_bits) + sb->sv_block_base, BLOCK_SIZE);
 502         if (*p) {
 503                 sysv_free_block(sb,tmp);
 504                 brelse(result);
 505                 goto repeat;
 506         }
 507         *p = tmp;
 508         inode->i_ctime = CURRENT_TIME;
 509         inode->i_dirt = 1;
 510         *start = result->b_data + ((tmp & sb->sv_block_size_ratio_1) << sb->sv_block_size_bits);
 511         return result;
 512 }
 513 
 514 static struct buffer_head * block_getblk(struct inode * inode, 
     /* [previous][next][first][last][top][bottom][index][help] */
 515         struct buffer_head * bh, int nr, int create, char * *start)
 516 {
 517         struct super_block *sb;
 518         unsigned long tmp, block;
 519         sysv_zone_t *p;
 520         struct buffer_head * result;
 521 
 522         if (!bh)
 523                 return NULL;
 524         if (!bh->b_uptodate) {
 525                 ll_rw_block(READ, 1, &bh);
 526                 wait_on_buffer(bh);
 527                 if (!bh->b_uptodate) {
 528                         brelse(bh);
 529                         return NULL;
 530                 }
 531         }
 532         sb = inode->i_sb;
 533         p = nr + (sysv_zone_t *) *start;
 534 repeat:
 535         block = tmp = *p;
 536         if (sb->sv_convert)
 537                 block = from_coh_ulong(block);
 538         if (tmp) {
 539                 result = getblk(bh->b_dev, (block >> sb->sv_block_size_ratio_bits) + sb->sv_block_base, BLOCK_SIZE);
 540                 if (tmp == *p) {
 541                         brelse(bh);
 542                         *start = result->b_data + ((block & sb->sv_block_size_ratio_1) << sb->sv_block_size_bits);
 543                         return result;
 544                 }
 545                 brelse(result);
 546                 goto repeat;
 547         }
 548         if (!create) {
 549                 brelse(bh);
 550                 return NULL;
 551         }
 552         block = sysv_new_block(sb);
 553         if (!block) {
 554                 brelse(bh);
 555                 return NULL;
 556         }
 557         result = getblk(bh->b_dev, (block >> sb->sv_block_size_ratio_bits) + sb->sv_block_base, BLOCK_SIZE);
 558         if (*p) {
 559                 sysv_free_block(sb,block);
 560                 brelse(result);
 561                 goto repeat;
 562         }
 563         *p = (sb->sv_convert ? to_coh_ulong(block) : block);
 564         mark_buffer_dirty(bh, 1);
 565         brelse(bh);
 566         *start = result->b_data + ((block & sb->sv_block_size_ratio_1) << sb->sv_block_size_bits);
 567         return result;
 568 }
 569 
 570 struct buffer_head * sysv_getblk(struct inode * inode, unsigned int block,
     /* [previous][next][first][last][top][bottom][index][help] */
 571         int create, char * *start)
 572 {
 573         struct super_block * sb = inode->i_sb;
 574         struct buffer_head * bh;
 575 
 576         if (block < 10)
 577                 return inode_getblk(inode,block,create,start);
 578         block -= 10;
 579         if (block < sb->sv_ind_per_block) {
 580                 bh = inode_getblk(inode,10,create,start);
 581                 return block_getblk(inode, bh, block, create, start);
 582         }
 583         block -= sb->sv_ind_per_block;
 584         if (block < sb->sv_ind_per_block_2) {
 585                 bh = inode_getblk(inode,11,create,start);
 586                 bh = block_getblk(inode, bh, block >> sb->sv_ind_per_block_bits, create, start);
 587                 return block_getblk(inode, bh, block & sb->sv_ind_per_block_1, create, start);
 588         }
 589         block -= sb->sv_ind_per_block_2;
 590         if (block < sb->sv_ind_per_block_3) {
 591                 bh = inode_getblk(inode,12,create,start);
 592                 bh = block_getblk(inode, bh, block >> sb->sv_ind_per_block_2_bits, create, start);
 593                 bh = block_getblk(inode, bh, (block >> sb->sv_ind_per_block_bits) & sb->sv_ind_per_block_1, create, start);
 594                 return block_getblk(inode, bh, block & sb->sv_ind_per_block_1, create, start);
 595         }
 596         if ((int)block<0) {
 597                 printk("sysv_getblk: block<0");
 598                 return NULL;
 599         }
 600         printk("sysv_getblk: block>big");
 601         return NULL;
 602 }
 603 
 604 struct buffer_head * sysv_file_bread(struct inode * inode, int block, int create, char * *start)
     /* [previous][next][first][last][top][bottom][index][help] */
 605 {
 606         struct buffer_head * bh;
 607 
 608         bh = sysv_getblk(inode,block,create,start);
 609         if (!bh || bh->b_uptodate)
 610                 return bh;
 611         ll_rw_block(READ, 1, &bh);
 612         wait_on_buffer(bh);
 613         if (bh->b_uptodate)
 614                 return bh;
 615         brelse(bh);
 616         return NULL;
 617 }
 618 
 619 
 620 static inline unsigned long read3byte (char * p)
     /* [previous][next][first][last][top][bottom][index][help] */
 621 {
 622         return (unsigned long)(*(unsigned short *)p)
 623              | (unsigned long)(*(unsigned char *)(p+2)) << 16;
 624 }
 625 
 626 static inline void write3byte (char * p, unsigned long val)
     /* [previous][next][first][last][top][bottom][index][help] */
 627 {
 628         *(unsigned short *)p = (unsigned short) val;
 629         *(unsigned char *)(p+2) = val >> 16;
 630 }
 631 
 632 static inline unsigned long coh_read3byte (char * p)
     /* [previous][next][first][last][top][bottom][index][help] */
 633 {
 634         return (unsigned long)(*(unsigned char *)p) << 16
 635              | (unsigned long)(*(unsigned short *)(p+1));
 636 }
 637 
 638 static inline void coh_write3byte (char * p, unsigned long val)
     /* [previous][next][first][last][top][bottom][index][help] */
 639 {
 640         *(unsigned char *)p = val >> 16;
 641         *(unsigned short *)(p+1) = (unsigned short) val;
 642 }
 643 
 644 void sysv_read_inode(struct inode * inode)
     /* [previous][next][first][last][top][bottom][index][help] */
 645 {
 646         struct super_block * sb = inode->i_sb;
 647         struct buffer_head * bh;
 648         char * bh_data;
 649         struct sysv_inode * raw_inode;
 650         unsigned int block, ino;
 651         umode_t mode;
 652 
 653         ino = inode->i_ino;
 654         inode->i_op = NULL;
 655         inode->i_mode = 0;
 656         if (!ino || ino > sb->sv_ninodes) {
 657                 printk("Bad inode number on dev 0x%04x: %d is out of range\n",
 658                         inode->i_dev, ino);
 659                 return;
 660         }
 661         block = sb->sv_firstinodezone + ((ino-1) >> sb->sv_inodes_per_block_bits);
 662         if (!(bh=sysv_bread(sb,inode->i_dev,block,&bh_data))) {
 663                 printk("Major problem: unable to read inode from dev 0x%04x\n",
 664                         inode->i_dev);
 665                 return;
 666         }
 667         raw_inode = (struct sysv_inode *) bh_data + ((ino-1) & sb->sv_inodes_per_block_1);
 668         mode = raw_inode->i_mode;
 669         if (sb->sv_kludge_symlinks)
 670                 mode = from_coh_imode(mode);
 671         /* SystemV FS: kludge permissions if ino==SYSV_ROOT_INO ?? */
 672         inode->i_mode = mode;
 673         inode->i_uid = raw_inode->i_uid;
 674         inode->i_gid = raw_inode->i_gid;
 675         inode->i_nlink = raw_inode->i_nlink;
 676         if (sb->sv_convert) {
 677                 inode->i_size = from_coh_ulong(raw_inode->i_size);
 678                 inode->i_atime = from_coh_ulong(raw_inode->i_atime);
 679                 inode->i_mtime = from_coh_ulong(raw_inode->i_mtime);
 680                 inode->i_ctime = from_coh_ulong(raw_inode->i_ctime);
 681         } else {
 682                 inode->i_size = raw_inode->i_size;
 683                 inode->i_atime = raw_inode->i_atime;
 684                 inode->i_mtime = raw_inode->i_mtime;
 685                 inode->i_ctime = raw_inode->i_ctime;
 686         }
 687         inode->i_blocks = inode->i_blksize = 0;
 688         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
 689                 inode->i_rdev = raw_inode->i_a.i_rdev;
 690         else
 691         if (sb->sv_convert)
 692                 for (block = 0; block < 10+1+1+1; block++)
 693                         inode->u.sysv_i.i_data[block] =
 694                                 coh_read3byte(&raw_inode->i_a.i_addb[3*block]);
 695         else
 696                 for (block = 0; block < 10+1+1+1; block++)
 697                         inode->u.sysv_i.i_data[block] =
 698                                 read3byte(&raw_inode->i_a.i_addb[3*block]);
 699         brelse(bh);
 700         if (S_ISREG(inode->i_mode))
 701                 if (sb->sv_block_size_ratio_bits == 0) /* block_size == BLOCK_SIZE ? */
 702                         inode->i_op = &sysv_file_inode_operations_with_bmap;
 703                 else
 704                         inode->i_op = &sysv_file_inode_operations;
 705         else if (S_ISDIR(inode->i_mode))
 706                 inode->i_op = &sysv_dir_inode_operations;
 707         else if (S_ISLNK(inode->i_mode))
 708                 inode->i_op = &sysv_symlink_inode_operations;
 709         else if (S_ISCHR(inode->i_mode))
 710                 inode->i_op = &chrdev_inode_operations;
 711         else if (S_ISBLK(inode->i_mode))
 712                 inode->i_op = &blkdev_inode_operations;
 713         else if (S_ISFIFO(inode->i_mode))
 714                 init_fifo(inode);
 715 }
 716 
 717 /* To avoid inconsistencies between inodes in memory and inodes on disk. */
 718 extern int sysv_notify_change(int flags, struct inode *inode)
     /* [previous][next][first][last][top][bottom][index][help] */
 719 {
 720         if (flags & NOTIFY_MODE)
 721                 if (inode->i_sb->sv_kludge_symlinks)
 722                         if (inode->i_mode == COH_KLUDGE_SYMLINK_MODE) {
 723                                 inode->i_mode = COH_KLUDGE_NOT_SYMLINK;
 724                                 inode->i_dirt = 1;
 725                         }
 726         return 0;
 727 }
 728 
 729 static struct buffer_head * sysv_update_inode(struct inode * inode)
     /* [previous][next][first][last][top][bottom][index][help] */
 730 {
 731         struct super_block * sb = inode->i_sb;
 732         struct buffer_head * bh;
 733         char * bh_data;
 734         struct sysv_inode * raw_inode;
 735         unsigned int ino, block;
 736         umode_t mode;
 737 
 738         ino = inode->i_ino;
 739         if (!ino || ino > sb->sv_ninodes) {
 740                 printk("Bad inode number on dev 0x%04x: %d is out of range\n",
 741                         inode->i_dev, ino);
 742                 inode->i_dirt = 0;
 743                 return 0;
 744         }
 745         block = sb->sv_firstinodezone + ((ino-1) >> sb->sv_inodes_per_block_bits);
 746         if (!(bh = sysv_bread(sb,inode->i_dev,block,&bh_data))) {
 747                 printk("unable to read i-node block\n");
 748                 inode->i_dirt = 0;
 749                 return 0;
 750         }
 751         raw_inode = (struct sysv_inode *) bh_data + ((ino-1) & sb->sv_inodes_per_block_1);
 752         mode = inode->i_mode;
 753         if (sb->sv_kludge_symlinks)
 754                 mode = to_coh_imode(mode);
 755         raw_inode->i_mode = mode;
 756         raw_inode->i_uid = inode->i_uid;
 757         raw_inode->i_gid = inode->i_gid;
 758         raw_inode->i_nlink = inode->i_nlink;
 759         if (sb->sv_convert) {
 760                 raw_inode->i_size = to_coh_ulong(inode->i_size);
 761                 raw_inode->i_atime = to_coh_ulong(inode->i_atime);
 762                 raw_inode->i_mtime = to_coh_ulong(inode->i_mtime);
 763                 raw_inode->i_ctime = to_coh_ulong(inode->i_ctime);
 764         } else {
 765                 raw_inode->i_size = inode->i_size;
 766                 raw_inode->i_atime = inode->i_atime;
 767                 raw_inode->i_mtime = inode->i_mtime;
 768                 raw_inode->i_ctime = inode->i_ctime;
 769         }
 770         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
 771                 raw_inode->i_a.i_rdev = inode->i_rdev; /* write 2 or 3 bytes ?? */
 772         else
 773         if (sb->sv_convert)
 774                 for (block = 0; block < 10+1+1+1; block++)
 775                         coh_write3byte(&raw_inode->i_a.i_addb[3*block],inode->u.sysv_i.i_data[block]);
 776         else
 777                 for (block = 0; block < 10+1+1+1; block++)
 778                         write3byte(&raw_inode->i_a.i_addb[3*block],inode->u.sysv_i.i_data[block]);
 779         inode->i_dirt=0;
 780         mark_buffer_dirty(bh, 1);
 781         return bh;
 782 }
 783 
 784 void sysv_write_inode(struct inode * inode)
     /* [previous][next][first][last][top][bottom][index][help] */
 785 {
 786         struct buffer_head *bh;
 787         bh = sysv_update_inode(inode);
 788         brelse(bh);
 789 }
 790 
 791 int sysv_sync_inode(struct inode * inode)
     /* [previous][next][first][last][top][bottom][index][help] */
 792 {
 793         int err = 0;
 794         struct buffer_head *bh;
 795 
 796         bh = sysv_update_inode(inode);
 797         if (bh && bh->b_dirt) {
 798                 ll_rw_block(WRITE, 1, &bh);
 799                 wait_on_buffer(bh);
 800                 if (bh->b_req && !bh->b_uptodate)
 801                 {
 802                         printk ("IO error syncing sysv inode [%04x:%08lx]\n",
 803                                 inode->i_dev, inode->i_ino);
 804                         err = -1;
 805                 }
 806         }
 807         else if (!bh)
 808                 err = -1;
 809         brelse (bh);
 810         return err;
 811 }
 812 

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