Ejemplo n.º 1
0
int reiserfs_global_version_in_proc( char *buffer, char **start, off_t offset,
				     int count, int *eof, void *data )
{
	int len = 0;
    
	len += sprintf( &buffer[ len ], "%s [%s]\n", 
			reiserfs_get_version_string(),
#if defined( CONFIG_REISERFS_FS_MODULE )
			"as module"
#else
			"built into kernel"
#endif
			);
	return reiserfs_proc_tail( len, buffer, start, offset, count, eof );
}
Ejemplo n.º 2
0
//
// a portion of this function, particularly the VFS interface portion,
// was derived from minix or ext2's analog and evolved as the
// prototype did. You should be able to tell which portion by looking
// at the ext2 code and comparing. It's subfunctions contain no code
// used as a template unless they are so labeled.
//
static struct super_block * reiserfs_read_super (struct super_block * s, void * data, int silent)
{
    int size;
    struct inode *root_inode;
    kdev_t dev = s->s_dev;
    int j;
    extern int *blksize_size[];
    struct reiserfs_transaction_handle th ;
    int old_format = 0;
    unsigned long blocks;
    int jinit_done = 0 ;
    struct reiserfs_iget4_args args ;
    int old_magic;
    struct reiserfs_super_block * rs;


    memset (&s->u.reiserfs_sb, 0, sizeof (struct reiserfs_sb_info));

    if (parse_options ((char *) data, &(s->u.reiserfs_sb.s_mount_opt), &blocks) == 0) {
	return NULL;
    }

    if (blocks) {
  	printk("reserfs: resize option for remount only\n");
	return NULL;
    }	

    if (blksize_size[MAJOR(dev)] && blksize_size[MAJOR(dev)][MINOR(dev)] != 0) {
	/* as blocksize is set for partition we use it */
	size = blksize_size[MAJOR(dev)][MINOR(dev)];
    } else {
	size = BLOCK_SIZE;
	set_blocksize (s->s_dev, BLOCK_SIZE);
    }

    /* read block (64-th 1k block), which can contain reiserfs super block */
    if (read_super_block (s, size, REISERFS_DISK_OFFSET_IN_BYTES)) {
	// try old format (undistributed bitmap, super block in 8-th 1k block of a device)
	if (read_super_block (s, size, REISERFS_OLD_DISK_OFFSET_IN_BYTES)) 
	    goto error;
	else
	    old_format = 1;
    }

    rs = SB_DISK_SUPER_BLOCK (s);

    s->u.reiserfs_sb.s_mount_state = SB_REISERFS_STATE(s);
    s->u.reiserfs_sb.s_mount_state = REISERFS_VALID_FS ;

    if (old_format ? read_old_bitmaps(s) : read_bitmaps(s)) { 
	printk ("reiserfs_read_super: unable to read bitmap\n");
	goto error;
    }
#ifdef CONFIG_REISERFS_CHECK
    printk("reiserfs:warning: CONFIG_REISERFS_CHECK is set ON\n");
    printk("reiserfs:warning: - it is slow mode for debugging.\n");
#endif

    // set_device_ro(s->s_dev, 1) ;
    if (journal_init(s)) {
	printk("reiserfs_read_super: unable to initialize journal space\n") ;
	goto error ;
    } else {
	jinit_done = 1 ; /* once this is set, journal_release must be called
			 ** if we error out of the mount 
			 */
    }
    if (reread_meta_blocks(s)) {
	printk("reiserfs_read_super: unable to reread meta blocks after journal init\n") ;
	goto error ;
    }

    if (replay_only (s))
	goto error;

    if (is_read_only(s->s_dev) && !(s->s_flags & MS_RDONLY)) {
        printk("clm-7000: Detected readonly device, marking FS readonly\n") ;
	s->s_flags |= MS_RDONLY ;
    }
    args.objectid = REISERFS_ROOT_PARENT_OBJECTID ;
    root_inode = iget4 (s, REISERFS_ROOT_OBJECTID, 0, (void *)(&args));
    if (!root_inode) {
	printk ("reiserfs_read_super: get root inode failed\n");
	goto error;
    }

    s->s_root = d_alloc_root(root_inode);  
    if (!s->s_root) {
	iput(root_inode);
	goto error;
    }

    // define and initialize hash function
    s->u.reiserfs_sb.s_hash_function = hash_function (s);
    if (s->u.reiserfs_sb.s_hash_function == NULL) {
      dput(s->s_root) ;
      s->s_root = NULL ;
      goto error ;
    }

    rs = SB_DISK_SUPER_BLOCK (s);
    old_magic = strncmp (rs->s_magic,  REISER2FS_SUPER_MAGIC_STRING,
                           strlen ( REISER2FS_SUPER_MAGIC_STRING));
    if (!old_magic)
	set_bit(REISERFS_3_6, &(s->u.reiserfs_sb.s_properties));
    else
	set_bit(REISERFS_3_5, &(s->u.reiserfs_sb.s_properties));

    if (!(s->s_flags & MS_RDONLY)) {

	journal_begin(&th, s, 1) ;
	reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1) ;

        set_sb_state( rs, REISERFS_ERROR_FS );

        if ( old_magic ) {
	    // filesystem created under 3.5.x found
	    if (convert_reiserfs (s)) {
		reiserfs_warning("reiserfs: converting 3.5.x filesystem to the new format\n") ;
		// after this 3.5.x will not be able to mount this partition
		memcpy (rs->s_magic, REISER2FS_SUPER_MAGIC_STRING, 
			sizeof (REISER2FS_SUPER_MAGIC_STRING));

		reiserfs_convert_objectid_map_v1(s) ;
		set_bit(REISERFS_3_6, &(s->u.reiserfs_sb.s_properties));
		clear_bit(REISERFS_3_5, &(s->u.reiserfs_sb.s_properties));
	    } else {
		reiserfs_warning("reiserfs: using 3.5.x disk format\n") ;
	    }
	}

	journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB (s));
	journal_end(&th, s, 1) ;
	
	/* look for files which were to be removed in previous session */
	finish_unfinished (s);

	s->s_dirt = 0;
    } else {
	if ( old_magic ) {
	    reiserfs_warning("reiserfs: using 3.5.x disk format\n") ;
	}
    }
    // mark hash in super block: it could be unset. overwrite should be ok
    set_sb_hash_function_code( rs, function2code(s->u.reiserfs_sb.s_hash_function ) );

    handle_attrs( s );

    reiserfs_proc_info_init( s );
    reiserfs_proc_register( s, "version", reiserfs_version_in_proc );
    reiserfs_proc_register( s, "super", reiserfs_super_in_proc );
    reiserfs_proc_register( s, "per-level", reiserfs_per_level_in_proc );
    reiserfs_proc_register( s, "bitmap", reiserfs_bitmap_in_proc );
    reiserfs_proc_register( s, "on-disk-super", reiserfs_on_disk_super_in_proc );
    reiserfs_proc_register( s, "oidmap", reiserfs_oidmap_in_proc );
    reiserfs_proc_register( s, "journal", reiserfs_journal_in_proc );
    init_waitqueue_head (&(s->u.reiserfs_sb.s_wait));

    printk("%s\n", reiserfs_get_version_string()) ;
    return s;

 error:
    if (jinit_done) { /* kill the commit thread, free journal ram */
	journal_release_error(NULL, s) ;
    }
    if (SB_DISK_SUPER_BLOCK (s)) {
	for (j = 0; j < SB_BMAP_NR (s); j ++) {
	    if (SB_AP_BITMAP (s))
		brelse (SB_AP_BITMAP (s)[j]);
	}
	if (SB_AP_BITMAP (s))
	    reiserfs_kfree (SB_AP_BITMAP (s), sizeof (struct buffer_head *) * SB_BMAP_NR (s), s);
    }
    if (SB_BUFFER_WITH_SB (s))
	brelse(SB_BUFFER_WITH_SB (s));

    return NULL;
}
Ejemplo n.º 3
0
struct super_block * reiserfs_read_super (struct super_block * s, void * data, int silent)
{
  int size;
  struct inode *root_inode;
  kdev_t dev = s->s_dev;
  int j;
  extern int *blksize_size[];
  struct reiserfs_transaction_handle th ;
  int old_format = 0;
  unsigned long blocks;
  int jinit_done = 0 ;

  memset (&s->u.reiserfs_sb, 0, sizeof (struct reiserfs_sb_info));

  if (parse_options ((char *) data, &(s->u.reiserfs_sb.s_mount_opt), &blocks) == 0) {
    s->s_dev = 0;
    return NULL;
  }

  if (blocks) {
  	printk("reserfs: resize option for remount only\n");
	return NULL;
  }	

  MOD_INC_USE_COUNT;
  lock_super (s);

  if (blksize_size[MAJOR(dev)] && blksize_size[MAJOR(dev)][MINOR(dev)] != 0) {
    /* as blocksize is set for partition we use it */
    size = blksize_size[MAJOR(dev)][MINOR(dev)];
  } else {
    size = BLOCK_SIZE;
    set_blocksize (s->s_dev, BLOCK_SIZE);
  }

  /* read block, containing reiserfs super block (it is stored at REISERFS_FIRST_BLOCK-th 1K block) */
  if (read_super_block (s, size)) {
	  if(read_old_super_block(s,size)) 
		  goto error;
	  else
		  old_format = 1;
  }

  s->u.reiserfs_sb.s_mount_state = le16_to_cpu (SB_DISK_SUPER_BLOCK (s)->s_state); /* journal victim */
  s->u.reiserfs_sb.s_mount_state = REISERFS_VALID_FS ;

  /* reiserfs can not be mounted when it propably contains errors */
#if 0 /* journal victim */
  if (le16_to_cpu (SB_DISK_SUPER_BLOCK (s)->s_state) != REISERFS_VALID_FS) {
    printk ("reiserfs_read_super:  mounting unchecked fs, run reiserfsck first\n");
    goto error;
  }
#endif
  if (old_format ? read_old_bitmaps(s) : read_bitmaps(s)) { 
	  printk ("reiserfs_read_super: unable to read bitmap\n");
	  goto error;
  }

  if (journal_init(s)) {
    printk("reiserfs_read_super: unable to initialize journal space\n") ;
    goto error ;
  } else {
    jinit_done = 1 ; /* once this is set, journal_release must be called
                     ** if we error out of the mount 
		     */
  }
  if (reread_meta_blocks(s)) {
    printk("reiserfs_read_super: unable to reread meta blocks after journal init\n") ;
    goto error ;
  }

  if (replay_only (s))
    goto error;

  /*s->s_op = &reiserfs_sops;*/
   
  /* get root directory inode */
  store_key (s, &root_key);
  root_inode = iget (s, root_key.k_objectid);
  forget_key (s, &root_key);
  if (!root_inode) {
    printk ("reiserfs_read_super: get root inode failed\n");
    goto error;
  }

  s->s_root = d_alloc_root(root_inode, NULL);  
  if (!s->s_root) {
    iput(root_inode);
    goto error;
  }

  if (!(s->s_flags & MS_RDONLY)) {
    SB_DISK_SUPER_BLOCK (s)->s_state = cpu_to_le16 (REISERFS_ERROR_FS);
    /* mark_buffer_dirty (SB_BUFFER_WITH_SB (s), 1); */
    journal_begin(&th, s, 1) ;
    journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB (s));
    journal_end(&th, s, 1) ;
    s->s_dirt = 0;
  }

  /*s->u.reiserfs_sb.unpreserve = dont_preserve (s) ? 0 : unpreserve;*/
  /* we have to do this to make journal writes work correctly */
  SB_BUFFER_WITH_SB(s)->b_end_io = reiserfs_end_buffer_io_sync ;

  unlock_super (s);
  print_credits() ;
  printk("%s\n", reiserfs_get_version_string()) ;
  return s;

 error:
  if (jinit_done) { /* kill the commit thread, free journal ram */
    journal_release_error(NULL, s) ;
  }
  if (SB_DISK_SUPER_BLOCK (s)) {
    for (j = 0; j < le16_to_cpu (SB_DISK_SUPER_BLOCK (s)->s_bmap_nr); j ++) {
      if (SB_AP_BITMAP (s))
	brelse (SB_AP_BITMAP (s)[j]);
      /* if (SB_AP_CAUTIOUS_BITMAP (s))
	brelse (SB_AP_CAUTIOUS_BITMAP (s)[j]); */
    }
    if (SB_AP_BITMAP (s))
      reiserfs_kfree (SB_AP_BITMAP (s), sizeof (struct buffer_head *) * SB_BMAP_NR (s), s);
    /* if (SB_AP_CAUTIOUS_BITMAP (s))
      reiserfs_kfree (SB_AP_CAUTIOUS_BITMAP (s), sizeof (struct buffer_head *) * SB_BMAP_NR (s), s); */
  }
  if (SB_BUFFER_WITH_SB (s))
    brelse(SB_BUFFER_WITH_SB (s));
  s->s_dev = 0;
  unlock_super(s);
  MOD_DEC_USE_COUNT;

  return NULL;
}