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