libxfs: make some dir2 definitions public
cover libxfs: make some dir2 definitions public
Hi folks,
These are a couple of patches that make some private dir2 functions public as they are used externally to libxfs in userspace. e.g. by xfs_repair to walk and rebuild directories. There will be more patches like this as I work through the process of synchronising libxfs in user and kernel space...
-Dave.
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH 1/2 xfs: move ftype conversion functions to libxfs
From: Dave Chinner <[email protected]>
These functions are needed in userspace for repair and mkfs to do the right thing. Move them to libxfs so they can be easily shared.
--- fs/xfs/libxfs/xfs_dir2.c | 16 ++++++++++++++++ fs/xfs/libxfs/xfs_dir2.h | 6 ++++++ fs/xfs/libxfs/xfs_dir2_priv.h | 6 ------ fs/xfs/xfs_dir2_readdir.c | 18 +----------------- fs/xfs/xfs_iops.c | 2 +- 5 files changed, 24 insertions(+), 24 deletions(-)
fs/xfs/libxfs/xfs_dir2.c +16 -0
@@ -34,6 +34,22 @@struct xfs_name xfs_name_dotdot = { (unsigned char *)".." ,2 ,XFS_DIR3_FT_DIR }; +/* +* @mode, if set, indicates that the type field needs to be set up. +* This uses the transformation from file mode to DT_* as defined in linux/fs.h +* for file type specification. This will be propagated into the directory +* structure if appropriate for the given operation and filesystem config. +*/ +const unsigned char xfs_mode_to_ftype[S_IFMT >>S_SHIFT ] = { + [0 ] =XFS_DIR3_FT_UNKNOWN , + [S_IFREG >>S_SHIFT ] =XFS_DIR3_FT_REG_FILE , + [S_IFDIR >>S_SHIFT ] =XFS_DIR3_FT_DIR , + [S_IFCHR >>S_SHIFT ] =XFS_DIR3_FT_CHRDEV , + [S_IFBLK >>S_SHIFT ] =XFS_DIR3_FT_BLKDEV , + [S_IFIFO >>S_SHIFT ] =XFS_DIR3_FT_FIFO , + [S_IFSOCK >>S_SHIFT ] =XFS_DIR3_FT_SOCK , + [S_IFLNK >>S_SHIFT ] =XFS_DIR3_FT_SYMLINK , +};/* * ASCII case-insensitive (ie. A-Z) support for directories that was
fs/xfs/libxfs/xfs_dir2.h +6 -0
@@ -32,6 +32,12 @@ struct xfs_dir2_data_unused;extern struct xfs_name xfs_name_dotdot;/* +* directory filetype conversion tables. +*/ +#define S_SHIFT 12 +extern const unsigned char xfs_mode_to_ftype[]; + +/* * directory operations vector for encode/decode routines */ struct xfs_dir_ops {
fs/xfs/libxfs/xfs_dir2_priv.h +0 -6
@@ -161,12 +161,6 @@ extern int xfs_dir2_grow_inode(struct xfs_da_args *args, int space,extern int xfs_dir_cilookup_result (struct xfs_da_args *args,const unsigned char *name,int len); -#define S_SHIFT 12 -extern const unsigned char xfs_mode_to_ftype[]; - -extern unsigned char xfs_dir3_get_dtype (struct xfs_mount *mp, -__uint8_t filetype); -/* xfs_dir2_block.c */ extern int xfs_dir3_block_read(struct xfs_trans *tp, struct xfs_inode *dp,
fs/xfs/xfs_dir2_readdir.c +1 -17
@@ -41,7 +41,7 @@ static unsigned char xfs_dir3_filetype_table[] = { DT_FIFO, DT_SOCK, DT_LNK, DT_WHT, }; -unsigned char +static unsigned char xfs_dir3_get_dtype (struct xfs_mount *mp,__uint8_t filetype)
@@ -54,22 +54,6 @@ xfs_dir3_get_dtype(return xfs_dir3_filetype_table[filetype]; } -/* -* @mode, if set, indicates that the type field needs to be set up. -* This uses the transformation from file mode to DT_* as defined in linux/fs.h -* for file type specification. This will be propagated into the directory -* structure if appropriate for the given operation and filesystem config. -*/ -const unsigned char xfs_mode_to_ftype[S_IFMT >>S_SHIFT ] = { - [0 ] =XFS_DIR3_FT_UNKNOWN , - [S_IFREG >>S_SHIFT ] =XFS_DIR3_FT_REG_FILE , - [S_IFDIR >>S_SHIFT ] =XFS_DIR3_FT_DIR , - [S_IFCHR >>S_SHIFT ] =XFS_DIR3_FT_CHRDEV , - [S_IFBLK >>S_SHIFT ] =XFS_DIR3_FT_BLKDEV , - [S_IFIFO >>S_SHIFT ] =XFS_DIR3_FT_FIFO , - [S_IFSOCK >>S_SHIFT ] =XFS_DIR3_FT_SOCK , - [S_IFLNK >>S_SHIFT ] =XFS_DIR3_FT_SYMLINK , -}; STATIC int xfs_dir2_sf_getdents(
fs/xfs/xfs_iops.c +1 -1
@@ -35,7 +35,7 @@#include "xfs_icache.h" #include "xfs_symlink.h" #include "xfs_da_btree.h" -#include "xfs_dir2_priv.h" +#include "xfs_dir2.h" #include "xfs_trans_space.h" #include <linux/capability.h>
Signature · 6 lines
2.0.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Re: [PATCH 1/2] xfs: move ftype conversion functions to libxfs
Looks good,
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH 2/2 xfs: move type conversion functions to xfs_dir.h
In reply to Dave ChinnerFrom: Dave Chinner <[email protected]>
These are currently considered private to libxfs, but they are widely used by the userspace code to decode, walk and check directory structures. Hence they really form part of the external API and as such need to bemoved to xfs_dir2.h.
--- fs/xfs/libxfs/xfs_dir2.h | 134 ++++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_dir2_priv.h | 134 ------------------------------------------ fs/xfs/xfs_export.c | 1 + fs/xfs/xfs_log_recover.c | 1 + fs/xfs/xfs_mount.c | 1 + 5 files changed, 137 insertions(+), 134 deletions(-)
fs/xfs/libxfs/xfs_dir2.h +134 -0
@@ -183,4 +183,138 @@ extern const struct xfs_buf_ops xfs_dir3_leaf1_buf_ops;extern const struct xfs_buf_ops xfs_dir3_free_buf_ops;extern const struct xfs_buf_ops xfs_dir3_data_buf_ops; +/* +* Directory offset/block conversion functions. +* +* DB blocks here are logical directory block numbers, not filesystem blocks. +*/ + +/* +* Convert dataptr to byte in file space +*/ +static inline xfs_dir2_off_t +xfs_dir2_dataptr_to_byte (xfs_dir2_dataptr_t dp) +{ +return (xfs_dir2_off_t )dp <<XFS_DIR2_DATA_ALIGN_LOG ; +} + +/* +* Convert byte in file space to dataptr. It had better be aligned. +*/ +static inline xfs_dir2_dataptr_t +xfs_dir2_byte_to_dataptr (xfs_dir2_off_t by) +{ +return (xfs_dir2_dataptr_t)(by >>XFS_DIR2_DATA_ALIGN_LOG ); +} + +/* +* Convert byte in space to (DB) block +*/ +static inline xfs_dir2_db_t +xfs_dir2_byte_to_db (struct xfs_da_geometry *geo,xfs_dir2_off_t by) +{ +return (xfs_dir2_db_t)(by >> geo->blklog); +} + +/* +* Convert dataptr to a block number +*/ +static inline xfs_dir2_db_t +xfs_dir2_dataptr_to_db (struct xfs_da_geometry *geo,xfs_dir2_dataptr_t dp) +{ +return xfs_dir2_byte_to_db (geo,xfs_dir2_dataptr_to_byte (dp)); +} + +/* +* Convert byte in space to offset in a block +*/ +static inline xfs_dir2_data_aoff_t +xfs_dir2_byte_to_off (struct xfs_da_geometry *geo,xfs_dir2_off_t by) +{ +return (xfs_dir2_data_aoff_t)(by & (geo->blksize -1 )); +} + +/* +* Convert dataptr to a byte offset in a block +*/ +static inline xfs_dir2_data_aoff_t +xfs_dir2_dataptr_to_off (struct xfs_da_geometry *geo,xfs_dir2_dataptr_t dp) +{ +return xfs_dir2_byte_to_off (geo,xfs_dir2_dataptr_to_byte (dp)); +} + +/* +* Convert block and offset to byte in space +*/ +static inline xfs_dir2_off_t +xfs_dir2_db_off_to_byte (struct xfs_da_geometry *geo,xfs_dir2_db_t db, +xfs_dir2_data_aoff_t o) +{ +return ((xfs_dir2_off_t )db << geo->blklog) + o; +} + +/* +* Convert block (DB) to block (dablk) +*/ +static inline xfs_dablk_t +xfs_dir2_db_to_da (struct xfs_da_geometry *geo,xfs_dir2_db_t db) +{ +return (xfs_dablk_t)(db << (geo->blklog - geo->fsblog)); +} + +/* +* Convert byte in space to (DA) block +*/ +static inline xfs_dablk_t +xfs_dir2_byte_to_da (struct xfs_da_geometry *geo,xfs_dir2_off_t by) +{ +return xfs_dir2_db_to_da (geo,xfs_dir2_byte_to_db (geo, by)); +} + +/* +* Convert block and offset to dataptr +*/ +static inline xfs_dir2_dataptr_t +xfs_dir2_db_off_to_dataptr (struct xfs_da_geometry *geo,xfs_dir2_db_t db, +xfs_dir2_data_aoff_t o) +{ +return xfs_dir2_byte_to_dataptr (xfs_dir2_db_off_to_byte (geo, db, o)); +} + +/* +* Convert block (dablk) to block (DB) +*/ +static inline xfs_dir2_db_t +xfs_dir2_da_to_db (struct xfs_da_geometry *geo,xfs_dablk_t da) +{ +return (xfs_dir2_db_t)(da >> (geo->blklog - geo->fsblog)); +} + +/* +* Convert block (dablk) to byte offset in space +*/ +static inline xfs_dir2_off_t +xfs_dir2_da_to_byte (struct xfs_da_geometry *geo,xfs_dablk_t da) +{ +return xfs_dir2_db_off_to_byte (geo,xfs_dir2_da_to_db (geo, da),0 ); +} + +/* +* Directory tail pointer accessor functions. Based on block geometry. +*/ +static inline struct xfs_dir2_block_tail * +xfs_dir2_block_tail_p (struct xfs_da_geometry *geo,struct xfs_dir2_data_hdr *hdr) +{ +return ((struct xfs_dir2_block_tail *) + ((char *)hdr + geo->blksize)) -1 ; +} + +static inline struct xfs_dir2_leaf_tail * +xfs_dir2_leaf_tail_p (struct xfs_da_geometry *geo,struct xfs_dir2_leaf *lp) +{ +return (struct xfs_dir2_leaf_tail *) + ((char *)lp + geo->blksize - +sizeof (struct xfs_dir2_leaf_tail )); +} +#endif /* __XFS_DIR2_H__ */
fs/xfs/libxfs/xfs_dir2_priv.h +0 -134
140 lines not on this page · raw message
fs/xfs/xfs_export.c +1 -0
@@ -21,6 +21,7 @@#include "xfs_trans_resv.h" #include "xfs_mount.h" #include "xfs_da_format.h" +#include "xfs_da_btree.h" #include "xfs_dir2.h" #include "xfs_export.h" #include "xfs_inode.h"
fs/xfs/xfs_log_recover.c +1 -0
@@ -25,6 +25,7 @@#include "xfs_sb.h" #include "xfs_mount.h" #include "xfs_da_format.h" +#include "xfs_da_btree.h" #include "xfs_inode.h" #include "xfs_trans.h" #include "xfs_log.h"
fs/xfs/xfs_mount.c +1 -0
@@ -25,6 +25,7 @@#include "xfs_sb.h" #include "xfs_mount.h" #include "xfs_da_format.h" +#include "xfs_da_btree.h" #include "xfs_inode.h" #include "xfs_dir2.h" #include "xfs_ialloc.h"
Signature · 6 lines
2.0.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Re: [PATCH 2/2] xfs: move type conversion functions to xfs_dir.h
Quoted 6 lines · Dave Chinner
From: Dave Chinner <[email protected]>
These are currently considered private to libxfs, but they are widely used by the userspace code to decode, walk and check directory structures. Hence they really form part of the external API and as such need to bemoved to
xfs_dir2.h.
Lokos good, but why do we need the additional includes in various files?
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Re: [PATCH 2/2] xfs: move type conversion functions to xfs_dir.h
Quoted 9 lines · Christoph Hellwig
Quoted 6 lines · Dave Chinner
From: Dave Chinner <[email protected]>
These are currently considered private to libxfs, but they are widely used by the userspace code to decode, walk and check directory structures. Hence they really form part of the external API and as such need to bemoved to
xfs_dir2.h.Lokos good, but why do we need the additional includes in various files?
Because the conversion functions have a dependency on the struct xfs_da_geometry definition in xfs_da_btree.h. xfs_dir2_priv.h had that dependency, but xfs_dir2.h didn't. Now the conversion functions have been moved, that dependency moves as well...
Quoted 1 line
Signed-off-by Christoph Hellwig <[email protected]>
Did you mean Reviewed-by? :)
Cheers,
Dave.
Signature · 7 lines
Dave Chinner [email protected] _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Re: [PATCH 2/2] xfs: move type conversion functions to xfs_dir.h
Quoted 3 lines · Dave Chinner
Quoted 1 line
Signed-off-by Christoph Hellwig <[email protected]>Did you mean Reviewed-by? :)
Yes.
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs