root/fs/sysv/inode.c

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

DEFINITIONS

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

   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 #ifdef MODULE
  34 #include <linux/module.h>
  35 #include <linux/version.h>
  36 #else
  37 #define MOD_INC_USE_COUNT
  38 #define MOD_DEC_USE_COUNT
  39 #endif
  40 
  41 void sysv_put_inode(struct inode *inode)
     /* [previous][next][first][last][top][bottom][index][help] */
  42 {
  43         if (inode->i_nlink)
  44                 return;
  45         inode->i_size = 0;
  46         sysv_truncate(inode);
  47         sysv_free_inode(inode);
  48 }
  49 
  50 
  51 static struct super_operations sysv_sops = { 
  52         sysv_read_inode,
  53         sysv_notify_change,
  54         sysv_write_inode,
  55         sysv_put_inode,
  56         sysv_put_super,
  57         sysv_write_super,
  58         sysv_statfs,
  59         NULL
  60 };
  61 
  62 /* The following functions try to recognize specific filesystems.
  63  * We recognize:
  64  * - Xenix FS by its magic number.
  65  * - SystemV FS by its magic number.
  66  * - Coherent FS by its funny fname/fpack field.
  67  * We discriminate among SystemV4 and SystemV2 FS by the assumption that
  68  * the time stamp is not < 01-01-1980.
  69  */
  70 
  71 static void detected_bs512 (struct super_block *sb)
     /* [previous][next][first][last][top][bottom][index][help] */
  72 {
  73         sb->sv_block_size = 512;
  74         sb->sv_block_size_1 = 512-1;
  75         sb->sv_block_size_bits = 9;
  76         sb->sv_block_size_ratio = 2;
  77         sb->sv_block_size_ratio_bits = 1;
  78         sb->sv_inodes_per_block = 512/64;
  79         sb->sv_inodes_per_block_1 = 512/64-1;
  80         sb->sv_inodes_per_block_bits = 9-6;
  81         sb->sv_toobig_block = 10 + 
  82           (sb->sv_ind_per_block = 512/4) +
  83           (sb->sv_ind_per_block_2 = (512/4)*(512/4)) +
  84           (sb->sv_ind_per_block_3 = (512/4)*(512/4)*(512/4));
  85         sb->sv_ind_per_block_1 = 512/4-1;
  86         sb->sv_ind_per_block_2_1 = (512/4)*(512/4)-1;
  87         sb->sv_ind_per_block_2_bits = 2 *
  88           (sb->sv_ind_per_block_bits = 9-2);
  89         sb->sv_ind_per_block_block_size_1 = (512/4)*512-1;
  90         sb->sv_ind_per_block_block_size_bits = (9-2)+9;
  91         sb->sv_ind_per_block_2_block_size_1 = (512/4)*(512/4)*512-1;
  92         sb->sv_ind_per_block_2_block_size_bits = (9-2)+(9-2)+9;
  93         sb->sv_ind0_size = 10 * 512;
  94         sb->sv_ind1_size = (10 + (512/4))* 512;
  95         sb->sv_ind2_size = (10 + (512/4) + (512/4)*(512/4)) * 512;
  96 }
  97 
  98 static void detected_bs1024 (struct super_block *sb)
     /* [previous][next][first][last][top][bottom][index][help] */
  99 {
 100         sb->sv_block_size = 1024;
 101         sb->sv_block_size_1 = 1024-1;
 102         sb->sv_block_size_bits = 10;
 103         sb->sv_block_size_ratio = 1;
 104         sb->sv_block_size_ratio_bits = 0;
 105         sb->sv_inodes_per_block = 1024/64;
 106         sb->sv_inodes_per_block_1 = 1024/64-1;
 107         sb->sv_inodes_per_block_bits = 10-6;
 108         sb->sv_toobig_block = 10 + 
 109           (sb->sv_ind_per_block = 1024/4) +
 110           (sb->sv_ind_per_block_2 = (1024/4)*(1024/4)) +
 111           (sb->sv_ind_per_block_3 = (1024/4)*(1024/4)*(1024/4));
 112         sb->sv_ind_per_block_1 = 1024/4-1;
 113         sb->sv_ind_per_block_2_1 = (1024/4)*(1024/4)-1;
 114         sb->sv_ind_per_block_2_bits = 2 *
 115           (sb->sv_ind_per_block_bits = 10-2);
 116         sb->sv_ind_per_block_block_size_1 = (1024/4)*1024-1;
 117         sb->sv_ind_per_block_block_size_bits = (10-2)+10;
 118         sb->sv_ind_per_block_2_block_size_1 = (1024/4)*(1024/4)*1024-1;
 119         sb->sv_ind_per_block_2_block_size_bits = (10-2)+(10-2)+10;
 120         sb->sv_ind0_size = 10 * 1024;
 121         sb->sv_ind1_size = (10 + (1024/4))* 1024;
 122         sb->sv_ind2_size = (10 + (1024/4) + (1024/4)*(1024/4)) * 1024;
 123 }
 124 
 125 static const char* detect_xenix (struct super_block *sb, struct buffer_head *bh)
     /* [previous][next][first][last][top][bottom][index][help] */
 126 {
 127         struct xenix_super_block * sbd;
 128 
 129         sbd = (struct xenix_super_block *) bh->b_data;
 130         if (sbd->s_magic != 0x2b5544)
 131                 return NULL;
 132         switch (sbd->s_type) {
 133                 case 1: detected_bs512(sb); break;
 134                 case 2: detected_bs1024(sb); break;
 135                 default: return NULL;
 136         }
 137         sb->sv_type = FSTYPE_XENIX;
 138         return "Xenix";
 139 }
 140 static struct super_block * detected_xenix (struct super_block *sb, struct buffer_head *bh1, struct buffer_head *bh2)
     /* [previous][next][first][last][top][bottom][index][help] */
 141 {
 142         struct xenix_super_block * sbd1;
 143         struct xenix_super_block * sbd2;
 144 
 145         if (sb->sv_block_size == BLOCK_SIZE)
 146                 /* block size = 1024, so bh1 = bh2 */
 147                 sbd1 = sbd2 = (struct xenix_super_block *) bh1->b_data;
 148         else {
 149                 /* block size = 512, so bh1 != bh2 */
 150                 sbd1 = (struct xenix_super_block *) bh1->b_data;
 151                 sbd2 = (struct xenix_super_block *) (bh2->b_data - BLOCK_SIZE/2);
 152                 /* sanity check */
 153                 if (sbd2->s_magic != 0x2b5544)
 154                         return NULL;
 155         }
 156 
 157         sb->sv_convert = 0;
 158         sb->sv_kludge_symlinks = 1;
 159         sb->sv_truncate = 1;
 160         sb->sv_link_max = XENIX_LINK_MAX;
 161         sb->sv_fic_size = XENIX_NICINOD;
 162         sb->sv_flc_size = XENIX_NICFREE;
 163         sb->sv_bh1 = bh1;
 164         sb->sv_bh2 = bh2;
 165         sb->sv_sbd1 = (char *) sbd1;
 166         sb->sv_sbd2 = (char *) sbd2;
 167         sb->sv_sb_fic_count = &sbd1->s_ninode;
 168         sb->sv_sb_fic_inodes = &sbd1->s_inode[0];
 169         sb->sv_sb_total_free_inodes = &sbd2->s_tinode;
 170         sb->sv_sb_flc_count = &sbd1->s_nfree;
 171         sb->sv_sb_flc_blocks = &sbd1->s_free[0];
 172         sb->sv_sb_total_free_blocks = &sbd2->s_tfree;
 173         sb->sv_sb_time = &sbd2->s_time;
 174         sb->sv_block_base = 0;
 175         sb->sv_firstinodezone = 2;
 176         sb->sv_firstdatazone = sbd1->s_isize;
 177         sb->sv_nzones = sbd1->s_fsize;
 178         sb->sv_ndatazones = sb->sv_nzones - sb->sv_firstdatazone;
 179         return sb;
 180 }
 181 
 182 static const char* detect_sysv4 (struct super_block *sb, struct buffer_head *bh)
     /* [previous][next][first][last][top][bottom][index][help] */
 183 {
 184         struct sysv4_super_block * sbd;
 185 
 186         sbd = (struct sysv4_super_block *) (bh->b_data + BLOCK_SIZE/2);
 187         if (sbd->s_magic != 0xfd187e20)
 188                 return NULL;
 189         if (sbd->s_time < 315532800) /* this is likely to happen on SystemV2 FS */
 190                 return NULL;
 191         switch (sbd->s_type) {
 192                 case 1: detected_bs512(sb); break;
 193                 case 2: detected_bs1024(sb); break;
 194                 default: return NULL;
 195         }
 196         sb->sv_type = FSTYPE_SYSV4;
 197         return "SystemV";
 198 }
 199 static struct super_block * detected_sysv4 (struct super_block *sb, struct buffer_head *bh)
     /* [previous][next][first][last][top][bottom][index][help] */
 200 {
 201         struct sysv4_super_block * sbd;
 202 
 203         if (sb->sv_block_size == BLOCK_SIZE)
 204                 sbd = (struct sysv4_super_block *) (bh->b_data + BLOCK_SIZE/2);
 205         else {
 206                 sbd = (struct sysv4_super_block *) bh->b_data;
 207                 /* sanity check */
 208                 if (sbd->s_magic != 0xfd187e20)
 209                         return NULL;
 210                 if (sbd->s_time < 315532800)
 211                         return NULL;
 212         }
 213 
 214         sb->sv_convert = 0;
 215         sb->sv_kludge_symlinks = 0; /* ?? */
 216         sb->sv_truncate = 1;
 217         sb->sv_link_max = SYSV_LINK_MAX;
 218         sb->sv_fic_size = SYSV_NICINOD;
 219         sb->sv_flc_size = SYSV_NICFREE;
 220         sb->sv_bh1 = bh;
 221         sb->sv_bh2 = bh;
 222         sb->sv_sbd1 = (char *) sbd;
 223         sb->sv_sbd2 = (char *) sbd;
 224         sb->sv_sb_fic_count = &sbd->s_ninode;
 225         sb->sv_sb_fic_inodes = &sbd->s_inode[0];
 226         sb->sv_sb_total_free_inodes = &sbd->s_tinode;
 227         sb->sv_sb_flc_count = &sbd->s_nfree;
 228         sb->sv_sb_flc_blocks = &sbd->s_free[0];
 229         sb->sv_sb_total_free_blocks = &sbd->s_tfree;
 230         sb->sv_sb_time = &sbd->s_time;
 231         sb->sv_sb_state = &sbd->s_state;
 232         sb->sv_block_base = 0;
 233         sb->sv_firstinodezone = 2;
 234         sb->sv_firstdatazone = sbd->s_isize;
 235         sb->sv_nzones = sbd->s_fsize;
 236         sb->sv_ndatazones = sb->sv_nzones - sb->sv_firstdatazone;
 237         return sb;
 238 }
 239 
 240 static const char* detect_sysv2 (struct super_block *sb, struct buffer_head *bh)
     /* [previous][next][first][last][top][bottom][index][help] */
 241 {
 242         struct sysv2_super_block * sbd;
 243 
 244         sbd = (struct sysv2_super_block *) (bh->b_data + BLOCK_SIZE/2);
 245         if (sbd->s_magic != 0xfd187e20)
 246                 return NULL;
 247         if (sbd->s_time < 315532800) /* this is likely to happen on SystemV4 FS */
 248                 return NULL;
 249         switch (sbd->s_type) {
 250                 case 1: detected_bs512(sb); break;
 251                 case 2: detected_bs1024(sb); break;
 252                 default: return NULL;
 253         }
 254         sb->sv_type = FSTYPE_SYSV2;
 255         return "SystemV Release 2";
 256 }
 257 static struct super_block * detected_sysv2 (struct super_block *sb, struct buffer_head *bh)
     /* [previous][next][first][last][top][bottom][index][help] */
 258 {
 259         struct sysv2_super_block * sbd;
 260 
 261         if (sb->sv_block_size == BLOCK_SIZE)
 262                 sbd = (struct sysv2_super_block *) (bh->b_data + BLOCK_SIZE/2);
 263         else {
 264                 sbd = (struct sysv2_super_block *) bh->b_data;
 265                 /* sanity check */
 266                 if (sbd->s_magic != 0xfd187e20)
 267                         return NULL;
 268                 if (sbd->s_time < 315532800)
 269                         return NULL;
 270         }
 271 
 272         sb->sv_convert = 0;
 273         sb->sv_kludge_symlinks = 0; /* ?? */
 274         sb->sv_truncate = 1;
 275         sb->sv_link_max = SYSV_LINK_MAX;
 276         sb->sv_fic_size = SYSV_NICINOD;
 277         sb->sv_flc_size = SYSV_NICFREE;
 278         sb->sv_bh1 = bh;
 279         sb->sv_bh2 = bh;
 280         sb->sv_sbd1 = (char *) sbd;
 281         sb->sv_sbd2 = (char *) sbd;
 282         sb->sv_sb_fic_count = &sbd->s_ninode;
 283         sb->sv_sb_fic_inodes = &sbd->s_inode[0];
 284         sb->sv_sb_total_free_inodes = &sbd->s_tinode;
 285         sb->sv_sb_flc_count = &sbd->s_nfree;
 286         sb->sv_sb_flc_blocks = &sbd->s_free[0];
 287         sb->sv_sb_total_free_blocks = &sbd->s_tfree;
 288         sb->sv_sb_time = &sbd->s_time;
 289         sb->sv_sb_state = &sbd->s_state;
 290         sb->sv_block_base = 0;
 291         sb->sv_firstinodezone = 2;
 292         sb->sv_firstdatazone = sbd->s_isize;
 293         sb->sv_nzones = sbd->s_fsize;
 294         sb->sv_ndatazones = sb->sv_nzones - sb->sv_firstdatazone;
 295         return sb;
 296 }
 297 
 298 static const char* detect_coherent (struct super_block *sb, struct buffer_head *bh)
     /* [previous][next][first][last][top][bottom][index][help] */
 299 {
 300         struct coh_super_block * sbd;
 301 
 302         sbd = (struct coh_super_block *) (bh->b_data + BLOCK_SIZE/2);
 303         if ((memcmp(sbd->s_fname,"noname",6) && memcmp(sbd->s_fname,"xxxxx ",6))
 304             || (memcmp(sbd->s_fpack,"nopack",6) && memcmp(sbd->s_fpack,"xxxxx\n",6)))
 305                 return NULL;
 306         detected_bs512(sb);
 307         sb->sv_type = FSTYPE_COH;
 308         return "Coherent";
 309 }
 310 static struct super_block * detected_coherent (struct super_block *sb, struct buffer_head *bh)
     /* [previous][next][first][last][top][bottom][index][help] */
 311 {
 312         struct coh_super_block * sbd;
 313 
 314         sbd = (struct coh_super_block *) bh->b_data;
 315         /* sanity check */
 316         if ((memcmp(sbd->s_fname,"noname",6) && memcmp(sbd->s_fname,"xxxxx ",6))
 317             || (memcmp(sbd->s_fpack,"nopack",6) && memcmp(sbd->s_fpack,"xxxxx\n",6)))
 318                 return NULL;
 319 
 320         sb->sv_convert = 1;
 321         sb->sv_kludge_symlinks = 1;
 322         sb->sv_truncate = 1;
 323         sb->sv_link_max = COH_LINK_MAX;
 324         sb->sv_fic_size = COH_NICINOD;
 325         sb->sv_flc_size = COH_NICFREE;
 326         sb->sv_bh1 = bh;
 327         sb->sv_bh2 = bh;
 328         sb->sv_sbd1 = (char *) sbd;
 329         sb->sv_sbd2 = (char *) sbd;
 330         sb->sv_sb_fic_count = &sbd->s_ninode;
 331         sb->sv_sb_fic_inodes = &sbd->s_inode[0];
 332         sb->sv_sb_total_free_inodes = &sbd->s_tinode;
 333         sb->sv_sb_flc_count = &sbd->s_nfree;
 334         sb->sv_sb_flc_blocks = &sbd->s_free[0];
 335         sb->sv_sb_total_free_blocks = &sbd->s_tfree;
 336         sb->sv_sb_time = &sbd->s_time;
 337         sb->sv_sb_state = &sbd->s_state;
 338         sb->sv_block_base = 0;
 339         sb->sv_firstinodezone = 2;
 340         sb->sv_firstdatazone = sbd->s_isize;
 341         sb->sv_nzones = from_coh_ulong(sbd->s_fsize);
 342         sb->sv_ndatazones = sb->sv_nzones - sb->sv_firstdatazone;
 343         return sb;
 344 }
 345 
 346 struct super_block *sysv_read_super(struct super_block *sb,void *data, 
     /* [previous][next][first][last][top][bottom][index][help] */
 347                                      int silent)
 348 {
 349         struct buffer_head *bh;
 350         const char *found;
 351         int dev = sb->s_dev;
 352 
 353         if (1024 != sizeof (struct xenix_super_block))
 354                 panic("Xenix FS: bad super-block size");
 355         if ((512 != sizeof (struct sysv4_super_block))
 356             || (512 != sizeof (struct sysv2_super_block)))
 357                 panic("SystemV FS: bad super-block size");
 358         if (500 != sizeof (struct coh_super_block))
 359                 panic("Coherent FS: bad super-block size");
 360         if (64 != sizeof (struct sysv_inode))
 361                 panic("sysv fs: bad i-node size");
 362         MOD_INC_USE_COUNT;
 363         lock_super(sb);
 364         set_blocksize(dev,BLOCK_SIZE);
 365 
 366         /* Try to read Xenix superblock */
 367         if ((bh = bread(dev, 1, BLOCK_SIZE)) != NULL) {
 368                 if ((found = detect_xenix(sb,bh)) != NULL)
 369                         goto ok;
 370                 brelse(bh);
 371         }
 372         if ((bh = bread(dev, 0, BLOCK_SIZE)) != NULL) {
 373                 /* Try to recognize SystemV superblock */
 374                 if ((found = detect_sysv4(sb,bh)) != NULL)
 375                         goto ok;
 376                 if ((found = detect_sysv2(sb,bh)) != NULL)
 377                         goto ok;
 378                 /* Try to recognize Coherent superblock */
 379                 if ((found = detect_coherent(sb,bh)) != NULL)
 380                         goto ok;
 381                 brelse(bh);
 382         }
 383         /* Try to recognize SystemV superblock */
 384         /* Offset by 1 track, i.e. most probably 9, 15, or 18 kilobytes. */
 385         {       static int offsets[] = { 9, 15, 18, };
 386                 int i;
 387                 for (i = 0; i < sizeof(offsets)/sizeof(offsets[0]); i++)
 388                         if ((bh = bread(dev, offsets[i], BLOCK_SIZE)) != NULL) {
 389                                 /* Try to recognize SystemV superblock */
 390                                 if ((found = detect_sysv4(sb,bh)) != NULL) {
 391                                         sb->sv_block_base = offsets[i] << sb->sv_block_size_ratio_bits;
 392                                         goto ok;
 393                                 }
 394                                 if ((found = detect_sysv2(sb,bh)) != NULL) {
 395                                         sb->sv_block_base = offsets[i] << sb->sv_block_size_ratio_bits;
 396                                         goto ok;
 397                                 }
 398                                 brelse(bh);
 399                         }
 400         }
 401         sb->s_dev=0;
 402         unlock_super(sb);
 403         if (!silent)
 404                 printk("VFS: unable to read Xenix/SystemV/Coherent superblock on device %d/%d\n",MAJOR(dev),MINOR(dev));
 405         failed:
 406         MOD_DEC_USE_COUNT;
 407         return NULL;
 408 
 409         ok:
 410         if (sb->sv_block_size == BLOCK_SIZE) {
 411                 switch (sb->sv_type) {
 412                         case FSTYPE_XENIX:
 413                                 if (!detected_xenix(sb,bh,bh))
 414                                         goto bad_superblock;
 415                                 break;
 416                         case FSTYPE_SYSV4:
 417                                 if (!detected_sysv4(sb,bh))
 418                                         goto bad_superblock;
 419                                 break;
 420                         case FSTYPE_SYSV2:
 421                                 if (!detected_sysv2(sb,bh))
 422                                         goto bad_superblock;
 423                                 break;
 424                         default:
 425                         bad_superblock:
 426                                 brelse(bh);
 427                                 sb->s_dev = 0;
 428                                 unlock_super(sb);
 429                                 printk("SysV FS: cannot read superblock in 1024 byte mode\n");
 430                                 goto failed;
 431                 }
 432         } else {
 433                 /* Switch to another block size. Unfortunately, we have to
 434                    release the 1 KB block bh and read it in two parts again. */
 435                 struct buffer_head *bh1, *bh2;
 436                 unsigned long blocknr = bh->b_blocknr << sb->sv_block_size_ratio_bits;
 437 
 438                 brelse(bh);
 439                 set_blocksize(dev,sb->sv_block_size);
 440                 bh1 = NULL; bh2 = NULL;
 441                 switch (sb->sv_type) {
 442                         case FSTYPE_XENIX:
 443                                 if ((bh1 = bread(dev, blocknr, sb->sv_block_size)) == NULL)
 444                                         goto bad_superblock2;
 445                                 if ((bh2 = bread(dev, blocknr+1, sb->sv_block_size)) == NULL)
 446                                         goto bad_superblock2;
 447                                 if (!detected_xenix(sb,bh1,bh2))
 448                                         goto bad_superblock2;
 449                                 break;
 450                         case FSTYPE_SYSV4:
 451                                 if ((bh2 = bread(dev, blocknr+1, sb->sv_block_size)) == NULL)
 452                                         goto bad_superblock2;
 453                                 if (!detected_sysv4(sb,bh2))
 454                                         goto bad_superblock2;
 455                                 break;
 456                         case FSTYPE_SYSV2:
 457                                 if ((bh2 = bread(dev, blocknr+1, sb->sv_block_size)) == NULL)
 458                                         goto bad_superblock2;
 459                                 if (!detected_sysv2(sb,bh2))
 460                                         goto bad_superblock2;
 461                                 break;
 462                         case FSTYPE_COH:
 463                                 if ((bh2 = bread(dev, blocknr+1, sb->sv_block_size)) == NULL)
 464                                         goto bad_superblock2;
 465                                 if (!detected_coherent(sb,bh2))
 466                                         goto bad_superblock2;
 467                                 break;
 468                         default:
 469                         bad_superblock2:
 470                                 brelse(bh1);
 471                                 brelse(bh2);
 472                                 set_blocksize(sb->s_dev,BLOCK_SIZE);
 473                                 sb->s_dev = 0;
 474                                 unlock_super(sb);
 475                                 printk("SysV FS: cannot read superblock in 512 byte mode\n");
 476                                 goto failed;
 477                 }
 478         }
 479         sb->sv_ninodes = (sb->sv_firstdatazone - sb->sv_firstinodezone) << sb->sv_inodes_per_block_bits;
 480         if (!silent)
 481                 printk("VFS: Found a %s FS (block size = %d) on device %d/%d\n",found,sb->sv_block_size,MAJOR(dev),MINOR(dev));
 482         sb->s_magic = SYSV_MAGIC_BASE + sb->sv_type;
 483         /* The buffer code now supports block size 512 as well as 1024. */
 484         sb->s_blocksize = sb->sv_block_size;
 485         sb->s_blocksize_bits = sb->sv_block_size_bits;
 486         /* set up enough so that it can read an inode */
 487         sb->s_dev = dev;
 488         sb->s_op = &sysv_sops;
 489         sb->s_mounted = iget(sb,SYSV_ROOT_INO);
 490         unlock_super(sb);
 491         if (!sb->s_mounted) {
 492                 printk("SysV FS: get root inode failed\n");
 493                 sysv_put_super(sb);
 494                 return NULL;
 495         }
 496         sb->s_dirt = 1;
 497         /* brelse(bh);  resp.  brelse(bh1); brelse(bh2);
 498            occurs when the disk is unmounted. */
 499         return sb;
 500 }
 501 
 502 /* This is only called on sync() and umount(), when s_dirt=1. */
 503 void sysv_write_super (struct super_block *sb)
     /* [previous][next][first][last][top][bottom][index][help] */
 504 {
 505         lock_super(sb);
 506         if (sb->sv_bh1->b_dirt || sb->sv_bh2->b_dirt) {
 507                 /* If we are going to write out the super block,
 508                    then attach current time stamp.
 509                    But if the filesystem was marked clean, keep it clean. */
 510                 unsigned long time = CURRENT_TIME;
 511                 unsigned long old_time = *sb->sv_sb_time;
 512                 if (sb->sv_convert)
 513                         old_time = from_coh_ulong(old_time);
 514                 switch (sb->sv_type) {
 515                         case FSTYPE_SYSV4:
 516                                 if (*sb->sv_sb_state == 0x7c269d38 - old_time)
 517                                         *sb->sv_sb_state = 0x7c269d38 - time;
 518                         default:
 519                                 break;
 520                 }
 521                 if (sb->sv_convert)
 522                         time = to_coh_ulong(time);
 523                 *sb->sv_sb_time = time;
 524                 mark_buffer_dirty(sb->sv_bh2, 1);
 525         }
 526         sb->s_dirt = 0;
 527         unlock_super(sb);
 528 }
 529 
 530 void sysv_put_super(struct super_block *sb)
     /* [previous][next][first][last][top][bottom][index][help] */
 531 {
 532         /* we can assume sysv_write_super() has already been called */
 533         lock_super(sb);
 534         brelse(sb->sv_bh1);
 535         if (sb->sv_bh1 != sb->sv_bh2) brelse(sb->sv_bh2);
 536         /* switch back to default block size */
 537         if (sb->s_blocksize != BLOCK_SIZE)
 538                 set_blocksize(sb->s_dev,BLOCK_SIZE);
 539         sb->s_dev = 0;
 540         unlock_super(sb);
 541         MOD_DEC_USE_COUNT;
 542 }
 543 
 544 void sysv_statfs(struct super_block *sb, struct statfs *buf)
     /* [previous][next][first][last][top][bottom][index][help] */
 545 {
 546         long tmp;
 547 
 548         put_fs_long(sb->s_magic, &buf->f_type);         /* type of filesystem */
 549         put_fs_long(sb->sv_block_size, &buf->f_bsize);  /* block size */
 550         put_fs_long(sb->sv_ndatazones, &buf->f_blocks); /* total data blocks in file system */
 551         tmp = sysv_count_free_blocks(sb);
 552         put_fs_long(tmp, &buf->f_bfree);                /* free blocks in fs */
 553         put_fs_long(tmp, &buf->f_bavail);               /* free blocks available to non-superuser */
 554         put_fs_long(sb->sv_ninodes, &buf->f_files);     /* total file nodes in file system */
 555         put_fs_long(sysv_count_free_inodes(sb), &buf->f_ffree); /* free file nodes in fs */
 556         put_fs_long(SYSV_NAMELEN, &buf->f_namelen);
 557         /* Don't know what value to put in buf->f_fsid */       /* file system id */
 558 }
 559 
 560 
 561 /* bmap support for running executables and shared libraries. */
 562 
 563 static inline int inode_bmap(struct super_block * sb, struct inode * inode, int nr)
     /* [previous][next][first][last][top][bottom][index][help] */
 564 {
 565         int tmp = inode->u.sysv_i.i_data[nr];
 566         if (!tmp)
 567                 return 0;
 568         return tmp + sb->sv_block_base;
 569 }
 570 
 571 static int block_bmap(struct super_block * sb, struct buffer_head * bh, int nr, int convert)
     /* [previous][next][first][last][top][bottom][index][help] */
 572 {
 573         int tmp;
 574 
 575         if (!bh)
 576                 return 0;
 577         tmp = ((sysv_zone_t *) bh->b_data) [nr];
 578         if (convert)
 579                 tmp = from_coh_ulong(tmp);
 580         brelse(bh);
 581         if (!tmp)
 582                 return 0;
 583         return tmp + sb->sv_block_base;
 584 }
 585 
 586 int sysv_bmap(struct inode * inode,int block_nr)
     /* [previous][next][first][last][top][bottom][index][help] */
 587 {
 588         unsigned int block = block_nr;
 589         struct super_block * sb = inode->i_sb;
 590         int convert;
 591         int i;
 592         struct buffer_head * bh;
 593 
 594         if (block < 10)
 595                 return inode_bmap(sb,inode,block);
 596         block -= 10;
 597         convert = sb->sv_convert;
 598         if (block < sb->sv_ind_per_block) {
 599                 i = inode_bmap(sb,inode,10);
 600                 if (!i)
 601                         return 0;
 602                 bh = bread(inode->i_dev,i,sb->sv_block_size);
 603                 return block_bmap(sb, bh, block, convert);
 604         }
 605         block -= sb->sv_ind_per_block;
 606         if (block < sb->sv_ind_per_block_2) {
 607                 i = inode_bmap(sb,inode,11);
 608                 if (!i)
 609                         return 0;
 610                 bh = bread(inode->i_dev,i,sb->sv_block_size);
 611                 i = block_bmap(sb, bh, block >> sb->sv_ind_per_block_bits, convert);
 612                 if (!i)
 613                         return 0;
 614                 bh = bread(inode->i_dev,i,sb->sv_block_size);
 615                 return block_bmap(sb, bh, block & sb->sv_ind_per_block_1, convert);
 616         }
 617         block -= sb->sv_ind_per_block_2;
 618         if (block < sb->sv_ind_per_block_3) {
 619                 i = inode_bmap(sb,inode,12);
 620                 if (!i)
 621                         return 0;
 622                 bh = bread(inode->i_dev,i,sb->sv_block_size);
 623                 i = block_bmap(sb, bh, block >> sb->sv_ind_per_block_2_bits, convert);
 624                 if (!i)
 625                         return 0;
 626                 bh = bread(inode->i_dev,i,sb->sv_block_size);
 627                 i = block_bmap(sb, bh, (block >> sb->sv_ind_per_block_bits) & sb->sv_ind_per_block_1,convert);
 628                 if (!i)
 629                         return 0;
 630                 bh = bread(inode->i_dev,i,sb->sv_block_size);
 631                 return block_bmap(sb, bh, block & sb->sv_ind_per_block_1, convert);
 632         }
 633         if ((int)block<0) {
 634                 printk("sysv_bmap: block<0");
 635                 return 0;
 636         }
 637         printk("sysv_bmap: block>big");
 638         return 0;
 639 }
 640 
 641 /* End of bmap support. */
 642 
 643 
 644 /* Access selected blocks of regular files (or directories) */
 645 
 646 static struct buffer_head * inode_getblk(struct inode * inode, int nr, int create)
     /* [previous][next][first][last][top][bottom][index][help] */
 647 {
 648         struct super_block *sb;
 649         unsigned long tmp;
 650         unsigned long *p;
 651         struct buffer_head * result;
 652 
 653         sb = inode->i_sb;
 654         p = inode->u.sysv_i.i_data + nr;
 655 repeat:
 656         tmp = *p;
 657         if (tmp) {
 658                 result = sv_getblk(sb, inode->i_dev, tmp);
 659                 if (tmp == *p)
 660                         return result;
 661                 brelse(result);
 662                 goto repeat;
 663         }
 664         if (!create)
 665                 return NULL;
 666         tmp = sysv_new_block(sb);
 667         if (!tmp)
 668                 return NULL;
 669         result = sv_getblk(sb, inode->i_dev, tmp);
 670         if (*p) {
 671                 sysv_free_block(sb,tmp);
 672                 brelse(result);
 673                 goto repeat;
 674         }
 675         *p = tmp;
 676         inode->i_ctime = CURRENT_TIME;
 677         inode->i_dirt = 1;
 678         return result;
 679 }
 680 
 681 static struct buffer_head * block_getblk(struct inode * inode, 
     /* [previous][next][first][last][top][bottom][index][help] */
 682         struct buffer_head * bh, int nr, int create)
 683 {
 684         struct super_block *sb;
 685         unsigned long tmp, block;
 686         sysv_zone_t *p;
 687         struct buffer_head * result;
 688 
 689         if (!bh)
 690                 return NULL;
 691         if (!bh->b_uptodate) {
 692                 ll_rw_block(READ, 1, &bh);
 693                 wait_on_buffer(bh);
 694                 if (!bh->b_uptodate) {
 695                         brelse(bh);
 696                         return NULL;
 697                 }
 698         }
 699         sb = inode->i_sb;
 700         p = nr + (sysv_zone_t *) bh->b_data;
 701 repeat:
 702         block = tmp = *p;
 703         if (sb->sv_convert)
 704                 block = from_coh_ulong(block);
 705         if (tmp) {
 706                 result = sv_getblk(sb, bh->b_dev, block);
 707                 if (tmp == *p) {
 708                         brelse(bh);
 709                         return result;
 710                 }
 711                 brelse(result);
 712                 goto repeat;
 713         }
 714         if (!create) {
 715                 brelse(bh);
 716                 return NULL;
 717         }
 718         block = sysv_new_block(sb);
 719         if (!block) {
 720                 brelse(bh);
 721                 return NULL;
 722         }
 723         result = sv_getblk(sb, bh->b_dev, block);
 724         if (*p) {
 725                 sysv_free_block(sb,block);
 726                 brelse(result);
 727                 goto repeat;
 728         }
 729         *p = (sb->sv_convert ? to_coh_ulong(block) : block);
 730         mark_buffer_dirty(bh, 1);
 731         brelse(bh);
 732         return result;
 733 }
 734 
 735 struct buffer_head * sysv_getblk(struct inode * inode, unsigned int block, int create)
     /* [previous][next][first][last][top][bottom][index][help] */
 736 {
 737         struct super_block * sb = inode->i_sb;
 738         struct buffer_head * bh;
 739 
 740         if (block < 10)
 741                 return inode_getblk(inode,block,create);
 742         block -= 10;
 743         if (block < sb->sv_ind_per_block) {
 744                 bh = inode_getblk(inode,10,create);
 745                 return block_getblk(inode, bh, block, create);
 746         }
 747         block -= sb->sv_ind_per_block;
 748         if (block < sb->sv_ind_per_block_2) {
 749                 bh = inode_getblk(inode,11,create);
 750                 bh = block_getblk(inode, bh, block >> sb->sv_ind_per_block_bits, create);
 751                 return block_getblk(inode, bh, block & sb->sv_ind_per_block_1, create);
 752         }
 753         block -= sb->sv_ind_per_block_2;
 754         if (block < sb->sv_ind_per_block_3) {
 755                 bh = inode_getblk(inode,12,create);
 756                 bh = block_getblk(inode, bh, block >> sb->sv_ind_per_block_2_bits, create);
 757                 bh = block_getblk(inode, bh, (block >> sb->sv_ind_per_block_bits) & sb->sv_ind_per_block_1, create);
 758                 return block_getblk(inode, bh, block & sb->sv_ind_per_block_1, create);
 759         }
 760         if ((int)block<0) {
 761                 printk("sysv_getblk: block<0");
 762                 return NULL;
 763         }
 764         printk("sysv_getblk: block>big");
 765         return NULL;
 766 }
 767 
 768 struct buffer_head * sysv_file_bread(struct inode * inode, int block, int create)
     /* [previous][next][first][last][top][bottom][index][help] */
 769 {
 770         struct buffer_head * bh;
 771 
 772         bh = sysv_getblk(inode,block,create);
 773         if (!bh || bh->b_uptodate)
 774                 return bh;
 775         ll_rw_block(READ, 1, &bh);
 776         wait_on_buffer(bh);
 777         if (bh->b_uptodate)
 778                 return bh;
 779         brelse(bh);
 780         return NULL;
 781 }
 782 
 783 
 784 static inline unsigned long read3byte (char * p)
     /* [previous][next][first][last][top][bottom][index][help] */
 785 {
 786         return (unsigned long)(*(unsigned short *)p)
 787              | (unsigned long)(*(unsigned char *)(p+2)) << 16;
 788 }
 789 
 790 static inline void write3byte (char * p, unsigned long val)
     /* [previous][next][first][last][top][bottom][index][help] */
 791 {
 792         *(unsigned short *)p = (unsigned short) val;
 793         *(unsigned char *)(p+2) = val >> 16;
 794 }
 795 
 796 static inline unsigned long coh_read3byte (char * p)
     /* [previous][next][first][last][top][bottom][index][help] */
 797 {
 798         return (unsigned long)(*(unsigned char *)p) << 16
 799              | (unsigned long)(*(unsigned short *)(p+1));
 800 }
 801 
 802 static inline void coh_write3byte (char * p, unsigned long val)
     /* [previous][next][first][last][top][bottom][index][help] */
 803 {
 804         *(unsigned char *)p = val >> 16;
 805         *(unsigned short *)(p+1) = (unsigned short) val;
 806 }
 807 
 808 void sysv_read_inode(struct inode * inode)
     /* [previous][next][first][last][top][bottom][index][help] */
 809 {
 810         struct super_block * sb = inode->i_sb;
 811         struct buffer_head * bh;
 812         struct sysv_inode * raw_inode;
 813         unsigned int block, ino;
 814         umode_t mode;
 815 
 816         ino = inode->i_ino;
 817         inode->i_op = NULL;
 818         inode->i_mode = 0;
 819         if (!ino || ino > sb->sv_ninodes) {
 820                 printk("Bad inode number on dev 0x%04x: %d is out of range\n",
 821                         inode->i_dev, ino);
 822                 return;
 823         }
 824         block = sb->sv_firstinodezone + ((ino-1) >> sb->sv_inodes_per_block_bits);
 825         if (!(bh = sv_bread(sb,inode->i_dev,block))) {
 826                 printk("Major problem: unable to read inode from dev 0x%04x\n",
 827                         inode->i_dev);
 828                 return;
 829         }
 830         raw_inode = (struct sysv_inode *) bh->b_data + ((ino-1) & sb->sv_inodes_per_block_1);
 831         mode = raw_inode->i_mode;
 832         if (sb->sv_kludge_symlinks)
 833                 mode = from_coh_imode(mode);
 834         /* SystemV FS: kludge permissions if ino==SYSV_ROOT_INO ?? */
 835         inode->i_mode = mode;
 836         inode->i_uid = raw_inode->i_uid;
 837         inode->i_gid = raw_inode->i_gid;
 838         inode->i_nlink = raw_inode->i_nlink;
 839         if (sb->sv_convert) {
 840                 inode->i_size = from_coh_ulong(raw_inode->i_size);
 841                 inode->i_atime = from_coh_ulong(raw_inode->i_atime);
 842                 inode->i_mtime = from_coh_ulong(raw_inode->i_mtime);
 843                 inode->i_ctime = from_coh_ulong(raw_inode->i_ctime);
 844         } else {
 845                 inode->i_size = raw_inode->i_size;
 846                 inode->i_atime = raw_inode->i_atime;
 847                 inode->i_mtime = raw_inode->i_mtime;
 848                 inode->i_ctime = raw_inode->i_ctime;
 849         }
 850         inode->i_blocks = inode->i_blksize = 0;
 851         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
 852                 inode->i_rdev = raw_inode->i_a.i_rdev;
 853         else
 854         if (sb->sv_convert)
 855                 for (block = 0; block < 10+1+1+1; block++)
 856                         inode->u.sysv_i.i_data[block] =
 857                                 coh_read3byte(&raw_inode->i_a.i_addb[3*block]);
 858         else
 859                 for (block = 0; block < 10+1+1+1; block++)
 860                         inode->u.sysv_i.i_data[block] =
 861                                 read3byte(&raw_inode->i_a.i_addb[3*block]);
 862         brelse(bh);
 863         if (S_ISREG(inode->i_mode))
 864                 inode->i_op = &sysv_file_inode_operations;
 865         else if (S_ISDIR(inode->i_mode))
 866                 inode->i_op = &sysv_dir_inode_operations;
 867         else if (S_ISLNK(inode->i_mode))
 868                 inode->i_op = &sysv_symlink_inode_operations;
 869         else if (S_ISCHR(inode->i_mode))
 870                 inode->i_op = &chrdev_inode_operations;
 871         else if (S_ISBLK(inode->i_mode))
 872                 inode->i_op = &blkdev_inode_operations;
 873         else if (S_ISFIFO(inode->i_mode))
 874                 init_fifo(inode);
 875 }
 876 
 877 /* To avoid inconsistencies between inodes in memory and inodes on disk. */
 878 extern int sysv_notify_change(struct inode *inode, struct iattr *attr)
     /* [previous][next][first][last][top][bottom][index][help] */
 879 {
 880         int error;
 881 
 882         if ((error = inode_change_ok(inode, attr)) != 0)
 883                 return error;
 884 
 885         if (attr->ia_valid & ATTR_MODE)
 886                 if (inode->i_sb->sv_kludge_symlinks)
 887                         if (attr->ia_mode == COH_KLUDGE_SYMLINK_MODE)
 888                                 attr->ia_mode = COH_KLUDGE_NOT_SYMLINK;
 889 
 890         inode_setattr(inode, attr);
 891 
 892         return 0;
 893 }
 894 
 895 static struct buffer_head * sysv_update_inode(struct inode * inode)
     /* [previous][next][first][last][top][bottom][index][help] */
 896 {
 897         struct super_block * sb = inode->i_sb;
 898         struct buffer_head * bh;
 899         struct sysv_inode * raw_inode;
 900         unsigned int ino, block;
 901         umode_t mode;
 902 
 903         ino = inode->i_ino;
 904         if (!ino || ino > sb->sv_ninodes) {
 905                 printk("Bad inode number on dev 0x%04x: %d is out of range\n",
 906                         inode->i_dev, ino);
 907                 inode->i_dirt = 0;
 908                 return 0;
 909         }
 910         block = sb->sv_firstinodezone + ((ino-1) >> sb->sv_inodes_per_block_bits);
 911         if (!(bh = sv_bread(sb,inode->i_dev,block))) {
 912                 printk("unable to read i-node block\n");
 913                 inode->i_dirt = 0;
 914                 return 0;
 915         }
 916         raw_inode = (struct sysv_inode *) bh->b_data + ((ino-1) & sb->sv_inodes_per_block_1);
 917         mode = inode->i_mode;
 918         if (sb->sv_kludge_symlinks)
 919                 mode = to_coh_imode(mode);
 920         raw_inode->i_mode = mode;
 921         raw_inode->i_uid = inode->i_uid;
 922         raw_inode->i_gid = inode->i_gid;
 923         raw_inode->i_nlink = inode->i_nlink;
 924         if (sb->sv_convert) {
 925                 raw_inode->i_size = to_coh_ulong(inode->i_size);
 926                 raw_inode->i_atime = to_coh_ulong(inode->i_atime);
 927                 raw_inode->i_mtime = to_coh_ulong(inode->i_mtime);
 928                 raw_inode->i_ctime = to_coh_ulong(inode->i_ctime);
 929         } else {
 930                 raw_inode->i_size = inode->i_size;
 931                 raw_inode->i_atime = inode->i_atime;
 932                 raw_inode->i_mtime = inode->i_mtime;
 933                 raw_inode->i_ctime = inode->i_ctime;
 934         }
 935         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
 936                 raw_inode->i_a.i_rdev = inode->i_rdev; /* write 2 or 3 bytes ?? */
 937         else
 938         if (sb->sv_convert)
 939                 for (block = 0; block < 10+1+1+1; block++)
 940                         coh_write3byte(&raw_inode->i_a.i_addb[3*block],inode->u.sysv_i.i_data[block]);
 941         else
 942                 for (block = 0; block < 10+1+1+1; block++)
 943                         write3byte(&raw_inode->i_a.i_addb[3*block],inode->u.sysv_i.i_data[block]);
 944         inode->i_dirt=0;
 945         mark_buffer_dirty(bh, 1);
 946         return bh;
 947 }
 948 
 949 void sysv_write_inode(struct inode * inode)
     /* [previous][next][first][last][top][bottom][index][help] */
 950 {
 951         struct buffer_head *bh;
 952         bh = sysv_update_inode(inode);
 953         brelse(bh);
 954 }
 955 
 956 int sysv_sync_inode(struct inode * inode)
     /* [previous][next][first][last][top][bottom][index][help] */
 957 {
 958         int err = 0;
 959         struct buffer_head *bh;
 960 
 961         bh = sysv_update_inode(inode);
 962         if (bh && bh->b_dirt) {
 963                 ll_rw_block(WRITE, 1, &bh);
 964                 wait_on_buffer(bh);
 965                 if (bh->b_req && !bh->b_uptodate)
 966                 {
 967                         printk ("IO error syncing sysv inode [%04x:%08lx]\n",
 968                                 inode->i_dev, inode->i_ino);
 969                         err = -1;
 970                 }
 971         }
 972         else if (!bh)
 973                 err = -1;
 974         brelse (bh);
 975         return err;
 976 }
 977 
 978 #ifdef MODULE
 979 
 980 /* Every kernel module contains stuff like this. */
 981 
 982 char kernel_version[] = UTS_RELEASE;
 983 
 984 static struct file_system_type sysv_fs_type[3] = {
 985         {sysv_read_super, "xenix", 1, NULL},
 986         {sysv_read_super, "sysv", 1, NULL},
 987         {sysv_read_super, "coherent", 1, NULL}
 988 };
 989 
 990 int init_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 991 {
 992         int i;
 993 
 994         for (i = 0; i < 3; i++)
 995                 register_filesystem(&sysv_fs_type[i]);
 996 
 997         return 0;
 998 }
 999 
1000 void cleanup_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
1001 {
1002         int i;
1003 
1004         if (MOD_IN_USE) {
1005                 printk("SysV FS cannot be removed, currently in use\n");
1006                 return;
1007         }
1008 
1009         for (i = 0; i < 3; i++)
1010                 unregister_filesystem(&sysv_fs_type[i]);
1011 }
1012 
1013 #endif

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