提交 ac8ba50f 编写于 作者: C Christoph Hellwig

xfs: kill struct xfs_dir2_sf

The list field of it is never cactually used, so all uses can simply be
replaced with the xfs_dir2_sf_hdr_t type that it has as first member.
Signed-off-by: NChristoph Hellwig <hch@lst.de>
Reviewed-by: NAlex Elder <aelder@sgi.com>
Reviewed-by: NDave Chinner <dchinner@redhat.com>
上级 8bc38787
......@@ -122,15 +122,15 @@ int
xfs_dir_isempty(
xfs_inode_t *dp)
{
xfs_dir2_sf_t *sfp;
xfs_dir2_sf_hdr_t *sfp;
ASSERT((dp->i_d.di_mode & S_IFMT) == S_IFDIR);
if (dp->i_d.di_size == 0) /* might happen during shutdown. */
return 1;
if (dp->i_d.di_size > XFS_IFORK_DSIZE(dp))
return 0;
sfp = (xfs_dir2_sf_t *)dp->i_df.if_u1.if_data;
return !sfp->hdr.count;
sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data;
return !sfp->count;
}
/*
......
......@@ -1028,8 +1028,6 @@ xfs_dir2_sf_to_block(
xfs_dir2_leaf_entry_t *blp; /* block leaf entries */
xfs_dabuf_t *bp; /* block buffer */
xfs_dir2_block_tail_t *btp; /* block tail pointer */
char *buf; /* sf buffer */
int buf_len;
xfs_dir2_data_entry_t *dep; /* data entry pointer */
xfs_inode_t *dp; /* incore directory inode */
int dummy; /* trash */
......@@ -1043,7 +1041,8 @@ xfs_dir2_sf_to_block(
int newoffset; /* offset from current entry */
int offset; /* target block offset */
xfs_dir2_sf_entry_t *sfep; /* sf entry pointer */
xfs_dir2_sf_t *sfp; /* shortform structure */
xfs_dir2_sf_hdr_t *oldsfp; /* old shortform header */
xfs_dir2_sf_hdr_t *sfp; /* shortform header */
__be16 *tagp; /* end of data entry */
xfs_trans_t *tp; /* transaction pointer */
struct xfs_name name;
......@@ -1061,32 +1060,30 @@ xfs_dir2_sf_to_block(
ASSERT(XFS_FORCED_SHUTDOWN(mp));
return XFS_ERROR(EIO);
}
oldsfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data;
ASSERT(dp->i_df.if_bytes == dp->i_d.di_size);
ASSERT(dp->i_df.if_u1.if_data != NULL);
sfp = (xfs_dir2_sf_t *)dp->i_df.if_u1.if_data;
ASSERT(dp->i_d.di_size >= xfs_dir2_sf_hdr_size(sfp->hdr.i8count));
ASSERT(dp->i_d.di_size >= xfs_dir2_sf_hdr_size(oldsfp->i8count));
/*
* Copy the directory into the stack buffer.
* Copy the directory into a temporary buffer.
* Then pitch the incore inode data so we can make extents.
*/
sfp = kmem_alloc(dp->i_df.if_bytes, KM_SLEEP);
memcpy(sfp, oldsfp, dp->i_df.if_bytes);
buf_len = dp->i_df.if_bytes;
buf = kmem_alloc(buf_len, KM_SLEEP);
memcpy(buf, sfp, buf_len);
xfs_idata_realloc(dp, -buf_len, XFS_DATA_FORK);
xfs_idata_realloc(dp, -dp->i_df.if_bytes, XFS_DATA_FORK);
dp->i_d.di_size = 0;
xfs_trans_log_inode(tp, dp, XFS_ILOG_CORE);
/*
* Reset pointer - old sfp is gone.
*/
sfp = (xfs_dir2_sf_t *)buf;
/*
* Add block 0 to the inode.
*/
error = xfs_dir2_grow_inode(args, XFS_DIR2_DATA_SPACE, &blkno);
if (error) {
kmem_free(buf);
kmem_free(sfp);
return error;
}
/*
......@@ -1094,7 +1091,7 @@ xfs_dir2_sf_to_block(
*/
error = xfs_dir2_data_init(args, blkno, &bp);
if (error) {
kmem_free(buf);
kmem_free(sfp);
return error;
}
block = bp->data;
......@@ -1103,7 +1100,7 @@ xfs_dir2_sf_to_block(
* Compute size of block "tail" area.
*/
i = (uint)sizeof(*btp) +
(sfp->hdr.count + 2) * (uint)sizeof(xfs_dir2_leaf_entry_t);
(sfp->count + 2) * (uint)sizeof(xfs_dir2_leaf_entry_t);
/*
* The whole thing is initialized to free by the init routine.
* Say we're using the leaf and tail area.
......@@ -1117,7 +1114,7 @@ xfs_dir2_sf_to_block(
* Fill in the tail.
*/
btp = xfs_dir2_block_tail_p(mp, block);
btp->count = cpu_to_be32(sfp->hdr.count + 2); /* ., .. */
btp->count = cpu_to_be32(sfp->count + 2); /* ., .. */
btp->stale = 0;
blp = xfs_dir2_block_leaf_p(btp);
endoffset = (uint)((char *)blp - (char *)block);
......@@ -1159,7 +1156,8 @@ xfs_dir2_sf_to_block(
/*
* Loop over existing entries, stuff them in.
*/
if ((i = 0) == sfp->hdr.count)
i = 0;
if (!sfp->count)
sfep = NULL;
else
sfep = xfs_dir2_sf_firstentry(sfp);
......@@ -1208,13 +1206,13 @@ xfs_dir2_sf_to_block(
blp[2 + i].address = cpu_to_be32(xfs_dir2_byte_to_dataptr(mp,
(char *)dep - (char *)block));
offset = (int)((char *)(tagp + 1) - (char *)block);
if (++i == sfp->hdr.count)
if (++i == sfp->count)
sfep = NULL;
else
sfep = xfs_dir2_sf_nextentry(sfp, sfep);
}
/* Done with the temporary buffer */
kmem_free(buf);
kmem_free(sfp);
/*
* Sort the leaf entries by hash value.
*/
......
此差异已折叠。
......@@ -21,8 +21,12 @@
/*
* Directory layout when stored internal to an inode.
*
* Small directories are packed as tightly as possible so as to
* fit into the literal area of the inode.
* Small directories are packed as tightly as possible so as to fit into the
* literal area of the inode. They consist of a single xfs_dir2_sf_hdr header
* followed by zero or more xfs_dir2_sf_entry structures. Due the different
* inode number storage size and the variable length name field in
* the xfs_dir2_sf_entry all these structure are variable length, and the
* accessors in this file should be used to iterate over them.
*/
struct uio;
......@@ -61,9 +65,9 @@ typedef struct { __uint8_t i[2]; } __arch_pack xfs_dir2_sf_off_t;
* The parent directory has a dedicated field, and the self-pointer must
* be calculated on the fly.
*
* Entries are packed toward the top as tightly as possible. The header
* and the elements must be memcpy'd out into a work area to get correct
* alignment for the inode number fields.
* Entries are packed toward the top as tightly as possible, and thus may
* be misaligned. Care needs to be taken to access them through special
* helpers or copy them into aligned variables first.
*/
typedef struct xfs_dir2_sf_hdr {
__uint8_t count; /* count of entries */
......@@ -78,11 +82,6 @@ typedef struct xfs_dir2_sf_entry {
xfs_dir2_inou_t inumber; /* inode number, var. offset */
} __arch_pack xfs_dir2_sf_entry_t;
typedef struct xfs_dir2_sf {
xfs_dir2_sf_hdr_t hdr; /* shortform header */
xfs_dir2_sf_entry_t list[1]; /* shortform entries */
} xfs_dir2_sf_t;
static inline int xfs_dir2_sf_hdr_size(int i8count)
{
return ((uint)sizeof(xfs_dir2_sf_hdr_t) - \
......@@ -102,39 +101,41 @@ xfs_dir2_sf_put_offset(xfs_dir2_sf_entry_t *sfep, xfs_dir2_data_aoff_t off)
INT_SET_UNALIGNED_16_BE(&(sfep)->offset.i, off);
}
static inline int xfs_dir2_sf_entsize_byname(xfs_dir2_sf_t *sfp, int len)
static inline int xfs_dir2_sf_entsize_byname(xfs_dir2_sf_hdr_t *sfp, int len)
{
return ((uint)sizeof(xfs_dir2_sf_entry_t) - 1 + (len) - \
((sfp)->hdr.i8count == 0) * \
((sfp)->i8count == 0) * \
((uint)sizeof(xfs_dir2_ino8_t) - (uint)sizeof(xfs_dir2_ino4_t)));
}
static inline int
xfs_dir2_sf_entsize_byentry(xfs_dir2_sf_t *sfp, xfs_dir2_sf_entry_t *sfep)
xfs_dir2_sf_entsize_byentry(xfs_dir2_sf_hdr_t *sfp, xfs_dir2_sf_entry_t *sfep)
{
return ((uint)sizeof(xfs_dir2_sf_entry_t) - 1 + (sfep)->namelen - \
((sfp)->hdr.i8count == 0) * \
((sfp)->i8count == 0) * \
((uint)sizeof(xfs_dir2_ino8_t) - (uint)sizeof(xfs_dir2_ino4_t)));
}
static inline xfs_dir2_sf_entry_t *xfs_dir2_sf_firstentry(xfs_dir2_sf_t *sfp)
static inline struct xfs_dir2_sf_entry *
xfs_dir2_sf_firstentry(struct xfs_dir2_sf_hdr *hdr)
{
return ((xfs_dir2_sf_entry_t *) \
((char *)(sfp) + xfs_dir2_sf_hdr_size(sfp->hdr.i8count)));
return (struct xfs_dir2_sf_entry *)
((char *)hdr + xfs_dir2_sf_hdr_size(hdr->i8count));
}
static inline xfs_dir2_sf_entry_t *
xfs_dir2_sf_nextentry(xfs_dir2_sf_t *sfp, xfs_dir2_sf_entry_t *sfep)
static inline struct xfs_dir2_sf_entry *
xfs_dir2_sf_nextentry(struct xfs_dir2_sf_hdr *hdr,
struct xfs_dir2_sf_entry *sfep)
{
return ((xfs_dir2_sf_entry_t *) \
((char *)(sfep) + xfs_dir2_sf_entsize_byentry(sfp,sfep)));
return (struct xfs_dir2_sf_entry *)
((char *)sfep + xfs_dir2_sf_entsize_byentry(hdr, sfep));
}
/*
* Functions.
*/
extern xfs_ino_t xfs_dir2_sf_get_parent_ino(struct xfs_dir2_sf *sfp);
extern xfs_ino_t xfs_dir2_sfe_get_ino(struct xfs_dir2_sf *sfp,
extern xfs_ino_t xfs_dir2_sf_get_parent_ino(struct xfs_dir2_sf_hdr *sfp);
extern xfs_ino_t xfs_dir2_sfe_get_ino(struct xfs_dir2_sf_hdr *sfp,
struct xfs_dir2_sf_entry *sfep);
extern int xfs_dir2_block_sfsize(struct xfs_inode *dp,
struct xfs_dir2_block *block,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册