2007-03-19 Yoshinori K. Okuji <okuji@enbug.org>

* fs/ext2.c (EXT2_GOOD_OLD_REVISION): New macro.
    (EXT2_GOOD_OLD_INODE_SIZE): Likewise.
    (EXT2_REVISION): Likewise.
    (EXT2_INODE_SIZE): Likewise.
    (struct grub_ext2_block_group): Added a missing member
    "used_dirs".
    (grub_ext2_read_inode): Divide by the inode size in a superblock
    instead of 128 to obtain INODES_PER_BLOCK.
    Use the macro EXT2_INODE_SIZE instead of directly using
    SBLOCK->INODE_SIZE.
This commit is contained in:
okuji 2007-03-19 00:04:29 +00:00
parent d70af616c2
commit 6795c4e10b
3 changed files with 56 additions and 26 deletions

View file

@ -1,3 +1,16 @@
2007-03-19 Yoshinori K. Okuji <okuji@enbug.org>
* fs/ext2.c (EXT2_GOOD_OLD_REVISION): New macro.
(EXT2_GOOD_OLD_INODE_SIZE): Likewise.
(EXT2_REVISION): Likewise.
(EXT2_INODE_SIZE): Likewise.
(struct grub_ext2_block_group): Added a missing member
"used_dirs".
(grub_ext2_read_inode): Divide by the inode size in a superblock
instead of 128 to obtain INODES_PER_BLOCK.
Use the macro EXT2_INODE_SIZE instead of directly using
SBLOCK->INODE_SIZE.
2007-03-18 Yoshinori K. Okuji <okuji@enbug.org>
* fs/ext2.c (grub_ext2_read_inode): Use the inode size in a

View file

@ -1,7 +1,7 @@
/* ext2.c - Second Extended filesystem */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
* Copyright (C) 2003,2004,2005,2007 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -27,6 +27,10 @@
/* Maximum nesting of symlinks, used to prevent a loop. */
#define EXT2_MAX_SYMLINKCNT 8
/* The good old revision and the default inode size. */
#define EXT2_GOOD_OLD_REVISION 0
#define EXT2_GOOD_OLD_INODE_SIZE 128
/* Filetype used in directory entry. */
#define FILETYPE_UNKNOWN 0
#define FILETYPE_REG 1
@ -59,6 +63,15 @@
/* The size of an ext2 block in bytes. */
#define EXT2_BLOCK_SIZE(data) (1 << LOG2_BLOCK_SIZE (data))
/* The revision level. */
#define EXT2_REVISION(data) grub_le_to_cpu32 (data->sblock.revision_level)
/* The inode size. */
#define EXT2_INODE_SIZE(data) \
(EXT2_REVISION (data) == EXT2_GOOD_OLD_REVISION \
? EXT2_GOOD_OLD_INODE_SIZE \
: grub_le_to_cpu16 (data->sblock.inode_size))
/* The ext2 superblock. */
struct grub_ext2_sblock
{
@ -107,6 +120,7 @@ struct grub_ext2_block_group
grub_uint32_t inode_table_id;
grub_uint16_t free_blocks;
grub_uint16_t free_inodes;
grub_uint16_t used_dirs;
grub_uint16_t pad;
grub_uint32_t reserved[3];
};
@ -173,7 +187,9 @@ struct grub_ext2_data
#ifndef GRUB_UTIL
static grub_dl_t my_mod;
#endif
/* Read into BLKGRP the blockgroup descriptor of blockgroup GROUP of
the mounted filesystem DATA. */
inline static grub_err_t
@ -279,12 +295,13 @@ grub_ext2_read_inode (struct grub_ext2_data *data,
/* It is easier to calculate if the first inode is 0. */
ino--;
grub_ext2_blockgroup (data, ino / grub_le_to_cpu32 (sblock->inodes_per_group),
grub_ext2_blockgroup (data,
ino / grub_le_to_cpu32 (sblock->inodes_per_group),
&blkgrp);
if (grub_errno)
return grub_errno;
inodes_per_block = EXT2_BLOCK_SIZE (data) / 128;
inodes_per_block = EXT2_BLOCK_SIZE (data) / EXT2_INODE_SIZE (data);
blkno = (ino % grub_le_to_cpu32 (sblock->inodes_per_group))
/ inodes_per_block;
blkoff = (ino % grub_le_to_cpu32 (sblock->inodes_per_group))
@ -294,7 +311,7 @@ grub_ext2_read_inode (struct grub_ext2_data *data,
if (grub_disk_read (data->disk,
((grub_le_to_cpu32 (blkgrp.inode_table_id) + blkno)
<< LOG2_EXT2_BLOCK_SIZE (data)),
grub_le_to_cpu16 (sblock->inode_size) * blkoff,
EXT2_INODE_SIZE (data) * blkoff,
sizeof (struct grub_ext2_inode), (char *) inode))
return grub_errno;
@ -441,7 +458,8 @@ grub_ext2_iterate_dir (grub_fshelp_node_t dir,
{
/* The filetype can not be read from the dirent, read
the inode to get more information. */
grub_ext2_read_inode (diro->data, grub_le_to_cpu32 (dirent.inode),
grub_ext2_read_inode (diro->data,
grub_le_to_cpu32 (dirent.inode),
&fdiro->inode);
if (grub_errno)
{
@ -536,8 +554,7 @@ grub_ext2_close (grub_file_t file)
static grub_ssize_t
grub_ext2_read (grub_file_t file, char *buf, grub_size_t len)
{
struct grub_ext2_data *data =
(struct grub_ext2_data *) file->data;
struct grub_ext2_data *data = (struct grub_ext2_data *) file->data;
return grub_ext2_read_file (&data->diropen, file->read_hook,
file->offset, len, buf);

View file

@ -148,7 +148,8 @@ grub_fshelp_find_file (const char *path, grub_fshelp_node_t rootnode,
{
free_node (currnode);
free_node (oldnode);
return grub_error (GRUB_ERR_SYMLINK_LOOP, "too deep nesting of symlinks");
return grub_error (GRUB_ERR_SYMLINK_LOOP,
"too deep nesting of symlinks");
}
symlink = read_symlink (currnode);
@ -232,12 +233,11 @@ grub_fshelp_read_file (grub_disk_t disk, grub_fshelp_node_t node,
int blockcnt;
int blocksize = 1 << (log2blocksize + GRUB_DISK_SECTOR_BITS);
/* Adjust len so it we can't read past the end of the file. */
/* Adjust LEN so it we can't read past the end of the file. */
if (len > filesize)
len = filesize;
blockcnt = ((len + pos)
+ blocksize - 1) / blocksize;
blockcnt = ((len + pos) + blocksize - 1) / blocksize;
for (i = pos / blocksize; i < blockcnt; i++)
{