Пример #1
0
int32 read_super( int device )
{
    int32 rc;

    rc = ujfs_get_superblk( device, &sb, TRUE );
    if( rc != 0 ) {
	printf("Failed reading primary superblock, will try secondary.\n");

	rc = ujfs_get_superblk( device, &sb, FALSE );
	if( rc != 0 ) {
	    printf("Failed reading secondary superblock.\n");
	    return(rc);
	}
    }

    rc = ujfs_validate_super( &sb );

    if( rc != 0 ) {
	printf("Not a recognized XJFS filesystem.\n");
    }
    return(rc);
}
Пример #2
0
/*
 * NAME: ujfs_init_superblock
 *
 * FUNCTION: Initialize primary and secondary aggregate superblock and write to
 *      disk
 *
 * PRE CONDITIONS:
 *
 * POST CONDITIONS:
 *
 * PARAMETERS:
 *      aggr_superblock         - structure to be filled in with superblock
 *                                information.
 *      dev_ptr                 - open port for device to write superblock to
 *      volume_label            - Volume label for superblock
 *      number_of_blocks        - Number of blocks for aggregate
 *      compress                - Whether this is a compressed aggregate
 *      fs_block_size           - block size for aggregate
 *      phys_block_size         - physical block size for device
 *      type_jfs                - JFS type to create; s_flag field of superblock
 *      secondary_ait_address   - block offset of first extent of secondary
 *                                aggregate inode table
 *      secondary_ait_length    - number of blocks of first extent of secondary
 *                                aggregate inode table
 *      fsck_svclog_length      - number of blocks of fsck_wspace_length is
 *                                intended for the fsck service log.
 *      ag_size                 - AG size
 *      fsck_wspace_address     - block offset of start of fsck working space
 *      fsck_wspace_length      - number of blocks of fsck working space
 *      logloc                  - block offset of start of log in aggr.
 *      logsize                 - number of blocks of log in aggr.
 *      secondary_aim_address   - block offset of first extent of secondary
 *                                aggregate inode map
 *      secondary_aim_length    - number of blocks of first extent of secondary
 *                                aggregate inode map
 *
 * RETURNS:
 *      0: success
 *      Any other return value indicates failure
 */
int32 ujfs_init_superblock( struct superblock   *aggr_superblock,
                            HFILE               dev_ptr,
                            char                *volume_label,
                            int64               number_of_blocks,
                            uint32              compress,
                            int32               fs_block_size,
                            int32               phys_block_size,
                            uint32              type_jfs,
                            int64               secondary_ait_address,
                            int32               secondary_ait_length,
                            int32               ag_size,
                            int64               fsck_wspace_address,
                            int32               fsck_wspace_length,
                            int32               fsck_svclog_length,
                            int64               logloc,
                            int32               logsize,
                            int64               secondary_aim_address,
                            int32               secondary_aim_length )
{
    int32       rc;

    /*
     * Initialize all of the fields of the superblock
     */
    strncpy(aggr_superblock->s_magic, JFS_MAGIC, strlen(JFS_MAGIC));
    aggr_superblock->s_version = JFS_VERSION;
    aggr_superblock->s_logdev = 0;
    aggr_superblock->s_logserial = 0;
    aggr_superblock->s_size = (number_of_blocks * fs_block_size) /
                              phys_block_size;
    aggr_superblock->s_bsize = fs_block_size;
    aggr_superblock->s_l2bsize = log2shift( aggr_superblock->s_bsize );
    aggr_superblock->s_l2bfactor = log2shift( aggr_superblock->s_bsize /
                                              phys_block_size );
    aggr_superblock->s_pbsize = phys_block_size;
    aggr_superblock->s_l2pbsize = log2shift( aggr_superblock->s_pbsize );
    aggr_superblock->s_agsize = ag_size;
    aggr_superblock->s_flag = type_jfs;
    aggr_superblock->s_compress = compress;
    aggr_superblock->s_state = FM_CLEAN;
    strncpy(aggr_superblock->s_fpack, volume_label, LV_NAME_SIZE );

    PXDaddress( &(aggr_superblock->s_ait2), secondary_ait_address );
    PXDlength( &(aggr_superblock->s_ait2), secondary_ait_length );

    PXDaddress( &(aggr_superblock->s_aim2), secondary_aim_address );
    PXDlength( &(aggr_superblock->s_aim2), secondary_aim_length );

    PXDaddress( &(aggr_superblock->s_fsckpxd), fsck_wspace_address );
    PXDlength( &(aggr_superblock->s_fsckpxd), fsck_wspace_length );
    aggr_superblock->s_fscklog = 0;
    aggr_superblock->s_fsckloglen = fsck_svclog_length;

    PXDaddress( &(aggr_superblock->s_logpxd), logloc );
    PXDlength( &(aggr_superblock->s_logpxd), logsize );

#ifdef	_JFS_DFS_LFS
    aggr_superblock->s_attach = 0;
    aggr_superblock->totalUsable = (aggr_superblock->s_size
                                        << aggr_superblock->s_l2pbsize) >> 10;
    aggr_superblock->minFree = 0;
    aggr_superblock->realFree = 0;
#endif	/* _JFS_DFS_LFS */
    aggr_superblock->s_time.tv_sec = (uint32) time( NULL );

    /*
     * Write both the primary and secondary superblocks to disk if valid
     */
    rc = ujfs_validate_super( aggr_superblock );
    if( rc != 0 ) {
        return rc;
    }
    rc = ujfs_put_superblk( dev_ptr, aggr_superblock, 1 );
    if( rc != 0 ) return rc;

    rc = ujfs_put_superblk( dev_ptr, aggr_superblock, 0 );

    return( rc );
}