RAMDISK与文件系统

来源:互联网 发布:淘宝苹果电池哪家靠谱 编辑:程序博客网 时间:2024/05/16 00:50

本样例要与之前的一篇RAMDISK文章一起学习:

ram_ext3.h


#ifndef __RAM_EXT3_H__

#define __RAM_EXT3_H__


/*
 * Structure of the super block
 */
struct ext3_super_block {
/*00*/ __le32 s_inodes_count; /* Inodes count */
__le32 s_blocks_count; /* Blocks count */
__le32 s_r_blocks_count; /* Reserved blocks count */
__le32 s_free_blocks_count; /* Free blocks count */
/*10*/ __le32 s_free_inodes_count; /* Free inodes count */
__le32 s_first_data_block; /* First Data Block */
__le32 s_log_block_size; /* Block size */
__le32 s_log_frag_size; /* Fragment size */
/*20*/ __le32 s_blocks_per_group; /* # Blocks per group */
__le32 s_frags_per_group; /* # Fragments per group */
__le32 s_inodes_per_group; /* # Inodes per group */
__le32 s_mtime; /* Mount time */
/*30*/ __le32 s_wtime; /* Write time */
__le16 s_mnt_count; /* Mount count */
__le16 s_max_mnt_count; /* Maximal mount count */
__le16 s_magic; /* Magic signature */
__le16 s_state; /* File system state */
__le16 s_errors; /* Behaviour when detecting errors */
__le16 s_minor_rev_level; /* minor revision level */
/*40*/ __le32 s_lastcheck; /* time of last check */
__le32 s_checkinterval; /* max. time between checks */
__le32 s_creator_os; /* OS */
__le32 s_rev_level; /* Revision level */
/*50*/ __le16 s_def_resuid; /* Default uid for reserved blocks */
__le16 s_def_resgid; /* Default gid for reserved blocks */
/*
* These fields are for EXT3_DYNAMIC_REV superblocks only.
*
* Note: the difference between the compatible feature set and
* the incompatible feature set is that if there is a bit set
* in the incompatible feature set that the kernel doesn't
* know about, it should refuse to mount the filesystem.
*
* e2fsck's requirements are more strict; if it doesn't know
* about a feature in either the compatible or incompatible
* feature set, it must abort and not try to meddle with
* things it doesn't understand...
*/
__le32 s_first_ino; /* First non-reserved inode */
__le16   s_inode_size;/* size of inode structure */
__le16 s_block_group_nr; /* block group # of this superblock */
__le32 s_feature_compat; /* compatible feature set */
/*60*/ __le32 s_feature_incompat; /* incompatible feature set */
__le32 s_feature_ro_compat; /* readonly-compatible feature set */
/*68*/ __u8 s_uuid[16]; /* 128-bit uuid for volume */
/*78*/ char s_volume_name[16]; /* volume name */
/*88*/ char s_last_mounted[64]; /* directory where last mounted */
/*C8*/ __le32 s_algorithm_usage_bitmap; /* For compression */
/*
* Performance hints.  Directory preallocation should only
* happen if the EXT3_FEATURE_COMPAT_DIR_PREALLOC flag is on.
*/
__u8 s_prealloc_blocks;/* Nr of blocks to try to preallocate*/
__u8 s_prealloc_dir_blocks;/* Nr to preallocate for dirs */
__le16 s_reserved_gdt_blocks; /* Per group desc for online growth */
/*
* Journaling support valid if EXT3_FEATURE_COMPAT_HAS_JOURNAL set.
*/
/*D0*/ __u8 s_journal_uuid[16]; /* uuid of journal superblock */
/*E0*/ __le32 s_journal_inum; /* inode number of journal file */
__le32 s_journal_dev; /* device number of journal file */
__le32 s_last_orphan; /* start of list of inodes to delete */
__le32 s_hash_seed[4]; /* HTREE hash seed */
__u8 s_def_hash_version;/* Default hash version to use */
__u8 s_reserved_char_pad;
__u16 s_reserved_word_pad;
__le32 s_default_mount_opts;
__le32 s_first_meta_bg; /* First metablock block group */
__le32 s_mkfs_time; /* When the filesystem was created */
__le32 s_jnl_blocks[17]; /* Backup of the journal inode */
/* 64bit support valid if EXT4_FEATURE_COMPAT_64BIT */
/*150*/ __le32s_blocks_count_hi; /* Blocks count */
__le32 s_r_blocks_count_hi; /* Reserved blocks count */
__le32 s_free_blocks_count_hi; /* Free blocks count */
__le16 s_min_extra_isize; /* All inodes have at least # bytes */
__le16 s_want_extra_isize; /* New inodes should reserve # bytes */
__le32 s_flags; /* Miscellaneous flags */
__le16  s_raid_stride;/* RAID stride */
__le16  s_mmp_interval;         /* # seconds to wait in MMP checking */
__le64  s_mmp_block;            /* Block for multi-mount protection */
__le32  s_raid_stripe_width;    /* blocks on all data disks (N*stride)*/
__u8 s_log_groups_per_flex;  /* FLEX_BG group size */
__u8 s_reserved_char_pad2;
__le16  s_reserved_pad;
__u32   s_reserved[162];        /* Padding to the end of the block */
};


#endif


ram_ext3.c

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/magic.h>


#include "ram_ext3.h"


extern char *sdisk[2];
static int __init ramext3_init(void)
{
    //EXT3_SUPER_MAGIC = 0xEF53
    struct ext3_super_block *sb;
    unsigned long tmp = (unsigned long)sdisk[0];
    tmp += 1024;
    
    sb = (struct ext3_super_block *)tmp;
    //printk("sdisk = %p\n", sdisk[0]);
    printk("s_magic = 0x%X, s_inodes=%d, s_blocks=%d\n", sb->s_magic, sb->s_inodes_count, sb->s_blocks_count); 
    printk("s_blocks_per_group = %d, s_log_frag_size=%d, s_inodes_per_group=%d\n", sb->s_blocks_per_group, sb->s_log_frag_size, sb->s_inodes_per_group);
    return 0;
}


static void __exit ramext3_exit(void)
{
     
}


module_init(ramext3_init);
module_exit(ramext3_exit);


MODULE_AUTHOR("dennis chen @AMDLinuxFGL");
MODULE_DESCRIPTION("The EXT3 file system demo");
MODULE_LICENSE("GPL");

原创粉丝点击