超级块的定义

超级块,文件系统的心脏。
  如果说inode块是Unix操作系统中文件的核心,那么超级块就是文件系统的心脏。启动Unix操作系统后,发现某个文件系统无法使用,很有 可能就是超级块出现了问题。为什么这个超级块有这么大的作用呢?主要是因为在超级块中保存了全局文件信息,如硬盘已用空间、数据块可用空间、inode结 点信息等等。做一个形象的比喻,这个超级块就好像是企业的资产负债表,一个文件系统中有哪些资源都记录在这个表中。
  当操作系统启动后,系统内核会把超级块中的内容复制到内存中,并周期性的利用内存里的最新内容去更新硬盘上的超级块中的内容。由于这个更新存在 一个时间差,为此内存中的超级块信息与硬盘中的超级块信息往往只有在开机与关机的某个特定时刻是同步的;而在其他时间都是不同步的。假设当操作系统意外当 机或者因为断电而造成的意外事故时,内存中的超级块信息没有及时保存到硬盘中,此时文件系统的完整性就会受到破坏。轻者导致刚建立的丢失,重则的话会导致 文件系统瘫痪。遇到这种情况时,系统工程师往往需要利用系统提供的sync命令在系统出现故障的那一刻把内存里的内容复制到磁盘上。这个过程往往操作系统 会自动完成,这也正是因为为什么Unix操作系统要比Windows操作系统稳定的一个重要原因。当操作系统重新启动的过程中,系统内核会对两者进行比 较,根据他们之间的差异,给文件系统打上干净或者脏的标签。这个信息也是存储在文件系统的超级块中。
  可见超级块如果发生损坏的话,对于文件系统的破坏性非常的大。轻者的话导致某个文件系统无法挂载,重则的话导致整个操作系统崩溃。在Unix操 作系统中,除了可以利用sync命令来保证硬盘上的内容决不会比内存里的内容更新之外,还提供了一个很有利的措施来保证其的安全性。其实,这个技术很早就 有,只是一开始并没有用在超级块的管理中。这个技术就是跟磁盘阵列类似。操作系统会将多个超级块内容保存到硬盘中的不同区域。当其中一个超级块出现问题 时,操作系统会自动采用另外一个超级块。等到系统运行正常后,系统内容就会把可用的超级块去替换那个故障的超级块。为此除非所有的超级块都损坏了,否则的 话,只要有一个超级块是可用的,那么文件系统与操作系统就可以正常挂载与启动。这种安全机制在很大程度上提高了超级块的安全性,系统了Unix操作系统的 稳定性。现在大部分的Unix操作系统(包括Linux操作系统)已经实现了类似的安全机制。

转载于:https://www.cnblogs.com/betterquan/p/11369364.html

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
磁盘的超级是一个重要的数据结构,它记录了文件系统的基本信息,包括文件系统的大小、大小、inode 数量、数量等信息。在 ext2、ext3、ext4 等文件系统中,超级的结构体定义如下: ``` struct ext2_super_block { __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 */ __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 */ __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 */ __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 */ __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 */ __le16 s_def_resuid; /* Default uid for reserved blocks */ __le16 s_def_resgid; /* Default gid for reserved blocks */ /* * These fields are for EXT2_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 */ __le32 s_feature_incompat; /* incompatible feature set */ __le32 s_feature_ro_compat; /* readonly-compatible feature set */ __u8 s_uuid[16]; /* 128-bit uuid for volume */ char s_volume_name[16]; /* volume name */ char s_last_mounted[64]; /* directory where last mounted */ __le32 s_algorithm_usage_bitmap; /* For compression */ /* * Performance hints. Directory preallocation should only * happen if the EXT2_COMPAT_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 */ __u16 s_padding1; /* * Journaling support valid if EXT3_FEATURE_COMPAT_HAS_JOURNAL set. */ __u8 s_journal_uuid[16]; /* uuid of journal superblock */ __u32 s_journal_inum; /* inode number of journal file */ __u32 s_journal_dev; /* device number of journal file */ __u32 s_last_orphan; /* start of list of inodes to delete */ __u32 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 */ __u32 s_reserved[190]; /* Padding to the end of the block */ }; ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值