aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLiu Aleaxander <Aleaxander@gmail.com>2009-05-12 12:01:20 +0800
committerLiu Aleaxander <Aleaxander@gmail.com>2009-05-12 12:01:20 +0800
commit1e7425a956fa1681c86aee6044d4dcc46abd9121 (patch)
tree7a5ccc5ff537bc75c2474e176f38a22bb4f7330b
parent0d701f8a814792f5db473d417648c2e5a9f6a20c (diff)
downloaddevel-1e7425a956fa1681c86aee6044d4dcc46abd9121.tar.gz
devel-1e7425a956fa1681c86aee6044d4dcc46abd9121.tar.xz
devel-1e7425a956fa1681c86aee6044d4dcc46abd9121.zip
add get_group_desc and read_inode function
Make the get_group_desc function and read_inode function from open_inode. This makes the open_inode function much easier.
-rwxr-xr-xa.outbin26239 -> 27316 bytes
-rw-r--r--extlinux.c91
2 files changed, 72 insertions, 19 deletions
diff --git a/a.out b/a.out
index db21112..da1dda9 100755
--- a/a.out
+++ b/a.out
Binary files differ
diff --git a/extlinux.c b/extlinux.c
index b1e108c..d2b22bc 100644
--- a/extlinux.c
+++ b/extlinux.c
@@ -88,6 +88,7 @@ struct open_file_t Files[MAX_OPEN];
__u32 ClustBytesShift, ClustSize, ClustShift;
__u32 SecPerClust, ClustMask;
__u32 PtrsPerBlock1, PtrsPerBlock2, PtrsPerBlock3;
+__u32 DescPerBlock, InodePerBlock;
/* a static value, which is the boot/extlinux's inode number */
__u32 CurrentDir = 13;
@@ -203,6 +204,71 @@ void getonesec_ext(char *buf, int sector)
+
+/**
+ * get_group_desc:
+ *
+ * get the group's descriptor of group_num
+ *
+ * @param: group_num, the group number;
+ *
+ * @return: the pointer of the group's descriptor
+ *
+ */
+struct ext2_group_desc *get_group_desc(__u32 group_num)
+{
+ __u32 block_num;
+ __u32 offset;
+ struct ext2_group_desc *desc;
+ struct cache_struct *cs;
+
+ block_num = group_num / DescPerBlock;
+ offset = group_num % DescPerBlock;
+
+ block_num += sb.s_first_data_block + 1;
+ cs = get_cache_block(block_num);
+
+ desc = (struct ext2_group_desc *)cs->data + offset;
+
+ return desc;
+}
+
+
+/**
+ * read_inode:
+ *
+ * read the right inode structure to _dst_.
+ *
+ * @param: inode_offset, the inode offset within a group;
+ * @prarm: dst, wher we will store the inode structure;
+ * @param: desc, the pointer to the group's descriptor
+ * @param: block, a pointer, used for retruning the block number for file structure
+ * @param: offset, same as block
+ *
+ */
+void read_inode(__u32 inode_offset,
+ struct ext2_inode *dst, struct ext2_group_desc *desc,
+ __u32 *block, __u32 *offset)
+{
+ struct cache_struct *cs;
+ struct ext2_inode *inode;
+
+ *block = inode_offset / InodePerBlock + desc->bg_inode_table;
+ *offset = inode_offset % InodePerBlock;
+
+ cs = get_cache_block(*block);
+ inode = (struct ext2_inode *)cs->data + *offset;
+ memcpy(dst, inode, EXT2_GOOD_OLD_INODE_SIZE);
+
+ /* for file structure */
+ *offset = (inode_offset * sb.s_inode_size) % ClustSize;
+}
+
+
+
+
+
+
/**
* open_inode:
*
@@ -232,27 +298,12 @@ struct open_file_t * open_inode(unsigned int inr, __u32 *file_len)
inr --;
inode_group = inr / sb.s_inodes_per_group;
- inode_offset = inr % sb.s_inodes_per_group;
-
- /* get bytes offset in desc table */
- inode_group <<= ext2_group_desc_lg2size;
- block_num = inode_group / ClustSize;
- block_off = inode_group % ClustSize;
- /* finally we get the real block number where the desc stores */
- block_num += sb.s_first_data_block + 1;
- cs = get_cache_block(block_num);
- /* got the group desc */
- desc = (struct ext2_group_desc *)(cs->data + block_off);
-
-
- /* get the inode bytes offset in the inode table */
- inode_offset *= sb.s_inode_size;
- block_num = (inode_offset / ClustSize) + (desc->bg_inode_table);
- block_off = inode_offset % ClustSize;
+ /* get the group desc */
+ desc = get_group_desc(inode_group);
- cs = get_cache_block(block_num);
- memcpy(&ThisInode, cs->data + block_off, EXT2_GOOD_OLD_INODE_SIZE);
+ inode_offset = inr % sb.s_inodes_per_group;
+ read_inode(inode_offset, &ThisInode, desc, &block_num, &block_off);
/* Finally, we need to convet it to sector for now */
file->file_in_sec = (block_num<<ClustShift) + (block_off>>SECTOR_SHIFT);
@@ -700,6 +751,8 @@ void init_fs(struct ext2_super_block *sb)
ClustShift = ClustBytesShift - SECTOR_SHIFT;
blk_size = ClustSize;
+ DescPerBlock = blk_size / ( 1 << ext2_group_desc_lg2size);
+ InodePerBlock = blk_size / EXT2_GOOD_OLD_INODE_SIZE;
SecPerClust = ClustSize >> SECTOR_SHIFT;
ClustMask = SecPerClust - 1;