[syslinux:pathbased] fs: cleanups: use PVT() macro for all filesystems; iso9660 cleanups
syslinux-bot for H. Peter Anvin
hpa at zytor.com
Wed Feb 24 21:06:08 PST 2010
Commit-ID: e464516f5baa21981d8f0130e3589dffea201558
Gitweb: http://syslinux.zytor.com/commit/e464516f5baa21981d8f0130e3589dffea201558
Author: H. Peter Anvin <hpa at zytor.com>
AuthorDate: Wed, 24 Feb 2010 21:04:29 -0800
Committer: H. Peter Anvin <hpa at zytor.com>
CommitDate: Wed, 24 Feb 2010 21:04:29 -0800
fs: cleanups: use PVT() macro for all filesystems; iso9660 cleanups
Use a PVT() macro and a structure to access the private inode data for
all filesystems, instead of open-coding the type.
Use a packed structure for iso9660, instead of open-coding pointer
casts.
Signed-off-by: H. Peter Anvin <hpa at zytor.com>
---
core/fs/btrfs/btrfs.c | 8 ++++----
core/fs/btrfs/btrfs.h | 9 +++++++++
core/fs/ext2/bmap.c | 15 +++++++--------
core/fs/ext2/ext2.c | 12 ++++++------
core/fs/ext2/ext2_fs.h | 11 +++++++++++
core/fs/iso9660/iso9660.c | 20 +++++++++-----------
core/fs/iso9660/iso9660_fs.h | 39 ++++++++++++++++++++++++++-------------
7 files changed, 72 insertions(+), 42 deletions(-)
diff --git a/core/fs/btrfs/btrfs.c b/core/fs/btrfs/btrfs.c
index a602cd6..7e83adf 100644
--- a/core/fs/btrfs/btrfs.c
+++ b/core/fs/btrfs/btrfs.c
@@ -452,7 +452,7 @@ static struct inode *btrfs_iget_by_inr(struct fs_info *fs, u64 inr)
if (ret)
return NULL;
inode_item = *(struct btrfs_inode_item *)path.data;
- if (!(inode = alloc_inode(fs, inr, sizeof(u64))))
+ if (!(inode = alloc_inode(fs, inr, sizeof(struct btrfs_pvt_inode))))
return NULL;
inode->ino = inr;
inode->size = inode_item.size;
@@ -476,7 +476,7 @@ static struct inode *btrfs_iget_by_inr(struct fs_info *fs, u64 inr)
+ offsetof(struct btrfs_file_extent_item, disk_bytenr);
else
offset = extent_item.disk_bytenr;
- *(u64 *)inode->pvt = offset;
+ PVT(inode)->offset = offset;
}
return inode;
}
@@ -509,7 +509,7 @@ static struct inode *btrfs_iget(const char *name, struct inode *parent)
static int btrfs_readlink(struct inode *inode, char *buf)
{
- btrfs_read(buf, logical_physical(*(u64 *)inode->pvt), inode->size);
+ btrfs_read(buf, logical_physical(PVT(inode)->offset), inode->size);
buf[inode->size] = '\0';
return inode->size;
}
@@ -520,7 +520,7 @@ static uint32_t btrfs_getfssec(struct file *file, char *buf, int sectors,
struct inode *inode = file->inode;
struct disk *disk = fs->fs_dev->disk;
u32 sec_shift = fs->fs_dev->disk->sector_shift;
- u32 phy = logical_physical(*(u64 *)inode->pvt + file->offset);
+ u32 phy = logical_physical(PVT(inode)->offset + file->offset);
u32 sec = phy >> sec_shift;
u32 off = phy - (sec << sec_shift);
u32 remain = file->file_len - file->offset;
diff --git a/core/fs/btrfs/btrfs.h b/core/fs/btrfs/btrfs.h
index 6852227..aa1245b 100644
--- a/core/fs/btrfs/btrfs.h
+++ b/core/fs/btrfs/btrfs.h
@@ -280,4 +280,13 @@ struct btrfs_root_ref {
__le16 name_len;
} __attribute__ ((__packed__));
+/*
+ * btrfs private inode information
+ */
+struct btrfs_pvt_inode {
+ uint64_t offset;
+};
+
+#define PVT(i) ((struct btrfs_pvt_inode *)((i)->pvt))
+
#endif
diff --git a/core/fs/ext2/bmap.c b/core/fs/ext2/bmap.c
index e25759f..73473e2 100644
--- a/core/fs/ext2/bmap.c
+++ b/core/fs/ext2/bmap.c
@@ -49,8 +49,7 @@ static block_t bmap_extent(struct inode *inode, block_t block)
int i;
block_t start;
- leaf = ext4_find_leaf(fs, (const struct ext4_extent_header *)inode->pvt,
- block);
+ leaf = ext4_find_leaf(fs, &PVT(inode)->i_extent_hdr, block);
if (!leaf) {
printf("ERROR, extent leaf not found\n");
return 0;
@@ -113,24 +112,24 @@ static block_t bmap_traditional(struct inode *inode, block_t block)
/* direct blocks */
if (block < direct_blocks)
- return ((uint32_t *)inode->pvt)[block];
+ return PVT(inode)->i_block[block];
/* indirect blocks */
block -= direct_blocks;
if (block < indirect_blocks)
- return bmap_indirect(fs, ((uint32_t *)inode->pvt)[EXT2_IND_BLOCK],
+ return bmap_indirect(fs, PVT(inode)->i_block[EXT2_IND_BLOCK],
block, 1);
/* double indirect blocks */
block -= indirect_blocks;
if (block < double_blocks)
- return bmap_indirect(fs, ((uint32_t *)inode->pvt)[EXT2_DIND_BLOCK],
+ return bmap_indirect(fs, PVT(inode)->i_block[EXT2_DIND_BLOCK],
block, 2);
/* triple indirect block */
block -= double_blocks;
if (block < triple_blocks)
- return bmap_indirect(fs, ((uint32_t *)inode->pvt)[EXT2_TIND_BLOCK],
+ return bmap_indirect(fs, PVT(inode)->i_block[EXT2_TIND_BLOCK],
block, 3);
/* This can't happen... */
@@ -145,8 +144,8 @@ static block_t bmap_traditional(struct inode *inode, block_t block)
*
* @fs: the fs_info structure.
* @inode: the inode structure.
- * @block: the logical blcok needed to be maped.
- * @retrun: the physic block number.
+ * @block: the logical block to be mapped.
+ * @retrun: the physical block number.
*
*/
block_t ext2_bmap(struct inode *inode, block_t block)
diff --git a/core/fs/ext2/ext2.c b/core/fs/ext2/ext2.c
index 5e806ee..29d0371 100644
--- a/core/fs/ext2/ext2.c
+++ b/core/fs/ext2/ext2.c
@@ -254,7 +254,8 @@ static void fill_inode(struct inode *inode, const struct ext2_inode *e_inode)
inode->blocks = e_inode->i_blocks;
inode->flags = e_inode->i_flags;
inode->file_acl = e_inode->i_file_acl;
- memcpy(inode->pvt, e_inode->i_block, EXT2_N_BLOCKS * sizeof(uint32_t *));
+ memcpy(PVT(inode)->i_block, e_inode->i_block,
+ EXT2_N_BLOCKS * sizeof(uint32_t *));
}
static struct inode *ext2_iget_by_inr(struct fs_info *fs, uint32_t inr)
@@ -263,7 +264,7 @@ static struct inode *ext2_iget_by_inr(struct fs_info *fs, uint32_t inr)
struct inode *inode;
e_inode = ext2_get_inode(fs, inr);
- if (!(inode = alloc_inode(fs, inr, EXT2_N_BLOCKS*sizeof(uint32_t *))))
+ if (!(inode = alloc_inode(fs, inr, sizeof(struct ext2_pvt_inode))))
return NULL;
fill_inode(inode, e_inode);
@@ -327,11 +328,10 @@ int ext2_readlink(struct inode *inode, char *buf)
return -1; /* Error! */
fast_symlink = (inode->file_acl ? sec_per_block : 0) == inode->blocks;
- if (fast_symlink) {
- memcpy(buf, inode->pvt, inode->size);
- } else {
+ if (fast_symlink)
+ memcpy(buf, PVT(inode)->i_block, inode->size);
+ else
cache_get_file(inode, buf, inode->size);
- }
return inode->size;
}
diff --git a/core/fs/ext2/ext2_fs.h b/core/fs/ext2/ext2_fs.h
index 82f508f..8d27609 100644
--- a/core/fs/ext2/ext2_fs.h
+++ b/core/fs/ext2/ext2_fs.h
@@ -289,6 +289,17 @@ static inline struct ext2_sb_info *EXT2_SB(struct fs_info *fs)
#define EXT2_INODES_PER_BLOCK(fs) (EXT2_SB(fs)->s_inodes_per_block)
#define EXT2_DESC_PER_BLOCK(fs) (EXT2_SB(fs)->s_desc_per_block)
+/*
+ * ext2 private inode information
+ */
+struct ext2_pvt_inode {
+ union {
+ uint32_t i_block[EXT2_N_BLOCKS];
+ struct ext4_extent_header i_extent_hdr;
+ };
+};
+
+#define PVT(i) ((struct ext2_pvt_inode *)((i)->pvt))
/*
* functions
diff --git a/core/fs/iso9660/iso9660.c b/core/fs/iso9660/iso9660.c
index fa7fd2d..5640a16 100644
--- a/core/fs/iso9660/iso9660.c
+++ b/core/fs/iso9660/iso9660.c
@@ -19,10 +19,10 @@ static inline char iso_tolower(char c)
static struct inode *new_iso_inode(struct fs_info *fs)
{
- return alloc_inode(fs, 0, sizeof(uint32_t));
+ return alloc_inode(fs, 0, sizeof(struct iso9660_pvt_inode));
}
-static inline struct iso_sb_info * ISO_SB(struct fs_info *fs)
+static inline struct iso_sb_info *ISO_SB(struct fs_info *fs)
{
return fs->fs_info;
}
@@ -153,8 +153,7 @@ static uint32_t iso_getfssec(struct file *file, char *buf,
uint32_t bytes_left = file->inode->size - file->offset;
uint32_t blocks_left = (bytes_left + BLOCK_SIZE(file->fs) - 1)
>> file->fs->block_shift;
- block_t block = *(uint32_t *)file->inode->pvt
- + (file->offset >> fs->block_shift);
+ block_t block = PVT(file->inode)->lba + (file->offset >> fs->block_shift);
if (blocks > blocks_left)
blocks = blocks_left;
@@ -178,7 +177,7 @@ static const struct iso_dir_entry *
iso_find_entry(const char *dname, struct inode *inode)
{
struct fs_info *fs = inode->fs;
- block_t dir_block = *(uint32_t *)inode->pvt;
+ block_t dir_block = PVT(inode)->lba;
int i = 0, offset = 0;
const char *de_name;
int de_name_len, de_len;
@@ -237,8 +236,8 @@ static struct inode *iso_get_inode(struct fs_info *fs,
return NULL;
inode->mode = get_inode_mode(de->flags);
- inode->size = *(uint32_t *)de->size;
- *(uint32_t *)inode->pvt = *(uint32_t *)de->extent;
+ inode->size = de->size_le;
+ PVT(inode)->lba = de->extent_le;
inode->blocks = (inode->size + BLOCK_SIZE(fs) - 1)
>> fs->block_shift;
@@ -255,10 +254,9 @@ static struct inode *iso_iget_root(struct fs_info *fs)
return NULL;
inode->mode = I_DIR;
- inode->size = *(uint32_t *)root->size;
- *(uint32_t *)inode->pvt = *(uint32_t *)root->extent;
- inode->blocks = (inode->size + BLOCK_SIZE(fs) - 1)
- >> fs->block_shift;
+ inode->size = root->size_le;
+ PVT(inode)->lba = root->extent_le;
+ inode->blocks = (inode->size + BLOCK_SIZE(fs) - 1) >> BLOCK_SHIFT(fs);
return inode;
}
diff --git a/core/fs/iso9660/iso9660_fs.h b/core/fs/iso9660/iso9660_fs.h
index e77ae10..6e9d495 100644
--- a/core/fs/iso9660/iso9660_fs.h
+++ b/core/fs/iso9660/iso9660_fs.h
@@ -1,27 +1,40 @@
#ifndef ISO9660_FS_H
#define ISO9660_FS_H
+#include <klibc/compiler.h>
#include <stdint.h>
/* The root dir entry offset in the primary volume descriptor */
#define ROOT_DIR_OFFSET 156
struct iso_dir_entry {
- uint8_t length; /* 00 */
- uint8_t ext_attr_length; /* 01 */
- uint8_t extent[8]; /* 02 */
- uint8_t size[8]; /* 0a */
- uint8_t date[7]; /* 12 */
- uint8_t flags; /* 19 */
- uint8_t file_unit_size; /* 1a */
- uint8_t interleave; /* 1b */
- uint8_t volume_sequence_number[4]; /* 1c */
- uint8_t name_len; /* 20 */
- char name[0]; /* 21 */
-};
+ uint8_t length; /* 00 */
+ uint8_t ext_attr_length; /* 01 */
+ uint32_t extent_le; /* 02 */
+ uint32_t extent_be; /* 06 */
+ uint32_t size_le; /* 0a */
+ uint32_t size_be; /* 0e */
+ uint8_t date[7]; /* 12 */
+ uint8_t flags; /* 19 */
+ uint8_t file_unit_size; /* 1a */
+ uint8_t interleave; /* 1b */
+ uint16_t volume_sequence_number_le; /* 1c */
+ uint16_t volume_sequence_number_be; /* 1e */
+ uint8_t name_len; /* 20 */
+ char name[0]; /* 21 */
+} __packed;
struct iso_sb_info {
- struct iso_dir_entry root;
+ struct iso_dir_entry root;
+};
+
+/*
+ * iso9660 private inode information
+ */
+struct iso9660_pvt_inode {
+ uint32_t lba; /* Starting LBA of file data area*/
};
+#define PVT(i) ((struct iso9660_pvt_inode *)((i)->pvt))
+
#endif /* iso9660_fs.h */
More information about the Syslinux-commits
mailing list