17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  *  GRUB  --  GRand Unified Bootloader
37c478bd9Sstevel@tonic-gate  *  Copyright (C) 1999, 2001, 2003  Free Software Foundation, Inc.
47c478bd9Sstevel@tonic-gate  *
57c478bd9Sstevel@tonic-gate  *  This program is free software; you can redistribute it and/or modify
67c478bd9Sstevel@tonic-gate  *  it under the terms of the GNU General Public License as published by
77c478bd9Sstevel@tonic-gate  *  the Free Software Foundation; either version 2 of the License, or
87c478bd9Sstevel@tonic-gate  *  (at your option) any later version.
97c478bd9Sstevel@tonic-gate  *
107c478bd9Sstevel@tonic-gate  *  This program is distributed in the hope that it will be useful,
117c478bd9Sstevel@tonic-gate  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
127c478bd9Sstevel@tonic-gate  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
137c478bd9Sstevel@tonic-gate  *  GNU General Public License for more details.
147c478bd9Sstevel@tonic-gate  *
157c478bd9Sstevel@tonic-gate  *  You should have received a copy of the GNU General Public License
167c478bd9Sstevel@tonic-gate  *  along with this program; if not, write to the Free Software
177c478bd9Sstevel@tonic-gate  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
187c478bd9Sstevel@tonic-gate  */
207c478bd9Sstevel@tonic-gate #ifdef FSYS_EXT2FS
227c478bd9Sstevel@tonic-gate #include "shared.h"
237c478bd9Sstevel@tonic-gate #include "filesys.h"
257c478bd9Sstevel@tonic-gate static int mapblock1, mapblock2;
277c478bd9Sstevel@tonic-gate /* sizes are always in bytes, BLOCK values are always in DEV_BSIZE (sectors) */
287c478bd9Sstevel@tonic-gate #define DEV_BSIZE 512
307c478bd9Sstevel@tonic-gate /* include/linux/fs.h */
317c478bd9Sstevel@tonic-gate #define BLOCK_SIZE 1024		/* initial block size for superblock read */
327c478bd9Sstevel@tonic-gate /* made up, defaults to 1 but can be passed via mount_opts */
337c478bd9Sstevel@tonic-gate #define WHICH_SUPER 1
347c478bd9Sstevel@tonic-gate /* kind of from fs/ext2/super.c */
357c478bd9Sstevel@tonic-gate #define SBLOCK (WHICH_SUPER * BLOCK_SIZE / DEV_BSIZE)	/* = 2 */
377c478bd9Sstevel@tonic-gate /* include/asm-i386/types.h */
387c478bd9Sstevel@tonic-gate typedef __signed__ char __s8;
397c478bd9Sstevel@tonic-gate typedef unsigned char __u8;
407c478bd9Sstevel@tonic-gate typedef __signed__ short __s16;
417c478bd9Sstevel@tonic-gate typedef unsigned short __u16;
427c478bd9Sstevel@tonic-gate typedef __signed__ int __s32;
437c478bd9Sstevel@tonic-gate typedef unsigned int __u32;
457c478bd9Sstevel@tonic-gate /*
467c478bd9Sstevel@tonic-gate  * Constants relative to the data blocks, from ext2_fs.h
477c478bd9Sstevel@tonic-gate  */
487c478bd9Sstevel@tonic-gate #define EXT2_NDIR_BLOCKS                12
497c478bd9Sstevel@tonic-gate #define EXT2_IND_BLOCK                  EXT2_NDIR_BLOCKS
507c478bd9Sstevel@tonic-gate #define EXT2_DIND_BLOCK                 (EXT2_IND_BLOCK + 1)
517c478bd9Sstevel@tonic-gate #define EXT2_TIND_BLOCK                 (EXT2_DIND_BLOCK + 1)
527c478bd9Sstevel@tonic-gate #define EXT2_N_BLOCKS                   (EXT2_TIND_BLOCK + 1)
547c478bd9Sstevel@tonic-gate /* include/linux/ext2_fs.h */
557c478bd9Sstevel@tonic-gate struct ext2_super_block
567c478bd9Sstevel@tonic-gate   {
577c478bd9Sstevel@tonic-gate     __u32 s_inodes_count;	/* Inodes count */
587c478bd9Sstevel@tonic-gate     __u32 s_blocks_count;	/* Blocks count */
597c478bd9Sstevel@tonic-gate     __u32 s_r_blocks_count;	/* Reserved blocks count */
607c478bd9Sstevel@tonic-gate     __u32 s_free_blocks_count;	/* Free blocks count */
617c478bd9Sstevel@tonic-gate     __u32 s_free_inodes_count;	/* Free inodes count */
627c478bd9Sstevel@tonic-gate     __u32 s_first_data_block;	/* First Data Block */
637c478bd9Sstevel@tonic-gate     __u32 s_log_block_size;	/* Block size */
647c478bd9Sstevel@tonic-gate     __s32 s_log_frag_size;	/* Fragment size */
657c478bd9Sstevel@tonic-gate     __u32 s_blocks_per_group;	/* # Blocks per group */
667c478bd9Sstevel@tonic-gate     __u32 s_frags_per_group;	/* # Fragments per group */
677c478bd9Sstevel@tonic-gate     __u32 s_inodes_per_group;	/* # Inodes per group */
687c478bd9Sstevel@tonic-gate     __u32 s_mtime;		/* Mount time */
697c478bd9Sstevel@tonic-gate     __u32 s_wtime;		/* Write time */
707c478bd9Sstevel@tonic-gate     __u16 s_mnt_count;		/* Mount count */
717c478bd9Sstevel@tonic-gate     __s16 s_max_mnt_count;	/* Maximal mount count */
727c478bd9Sstevel@tonic-gate     __u16 s_magic;		/* Magic signature */
737c478bd9Sstevel@tonic-gate     __u16 s_state;		/* File system state */
747c478bd9Sstevel@tonic-gate     __u16 s_errors;		/* Behaviour when detecting errors */
757c478bd9Sstevel@tonic-gate     __u16 s_pad;
767c478bd9Sstevel@tonic-gate     __u32 s_lastcheck;		/* time of last check */
777c478bd9Sstevel@tonic-gate     __u32 s_checkinterval;	/* max. time between checks */
787c478bd9Sstevel@tonic-gate     __u32 s_creator_os;		/* OS */
797c478bd9Sstevel@tonic-gate     __u32 s_rev_level;		/* Revision level */
807c478bd9Sstevel@tonic-gate     __u16 s_def_resuid;		/* Default uid for reserved blocks */
817c478bd9Sstevel@tonic-gate     __u16 s_def_resgid;		/* Default gid for reserved blocks */
82*1b8adde7SWilliam Kucharski    /*
83*1b8adde7SWilliam Kucharski     * These fields are for EXT2_DYNAMIC_REV superblocks only.
84*1b8adde7SWilliam Kucharski     *
85*1b8adde7SWilliam Kucharski     * Note: the difference between the compatible feature set and
86*1b8adde7SWilliam Kucharski     * the incompatible feature set is that if there is a bit set
87*1b8adde7SWilliam Kucharski     * in the incompatible feature set that the kernel doesn't
88*1b8adde7SWilliam Kucharski     * know about, it should refuse to mount the filesystem.
89*1b8adde7SWilliam Kucharski     *
90*1b8adde7SWilliam Kucharski     * e2fsck's requirements are more strict; if it doesn't know
91*1b8adde7SWilliam Kucharski     * about a feature in either the compatible or incompatible
92*1b8adde7SWilliam Kucharski     * feature set, it must abort and not try to meddle with
93*1b8adde7SWilliam Kucharski     * things it doesn't understand...
94*1b8adde7SWilliam Kucharski     */
95*1b8adde7SWilliam Kucharski    __u32 s_first_ino;		/* First non-reserved inode */
96*1b8adde7SWilliam Kucharski    __u16 s_inode_size;		/* size of inode structure */
97*1b8adde7SWilliam Kucharski    __u16 s_block_group_nr;	/* block group # of this superblock */
98*1b8adde7SWilliam Kucharski    __u32 s_feature_compat;	/* compatible feature set */
99*1b8adde7SWilliam Kucharski    __u32 s_feature_incompat;	/* incompatible feature set */
100*1b8adde7SWilliam Kucharski    __u32 s_feature_ro_compat;	/* readonly-compatible feature set */
101*1b8adde7SWilliam Kucharski    __u8  s_uuid[16];		/* 128-bit uuid for volume */
102*1b8adde7SWilliam Kucharski    char  s_volume_name[16];	/* volume name */
103*1b8adde7SWilliam Kucharski    char  s_last_mounted[64];	/* directory where last mounted */
104*1b8adde7SWilliam Kucharski    __u32 s_algorithm_usage_bitmap; /* For compression */
105*1b8adde7SWilliam Kucharski    /*