Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
0004  * All Rights Reserved.
0005  */
0006 #ifndef __XFS_DIR2_H__
0007 #define __XFS_DIR2_H__
0008 
0009 #include "xfs_da_format.h"
0010 #include "xfs_da_btree.h"
0011 
0012 struct xfs_da_args;
0013 struct xfs_inode;
0014 struct xfs_mount;
0015 struct xfs_trans;
0016 struct xfs_dir2_sf_hdr;
0017 struct xfs_dir2_sf_entry;
0018 struct xfs_dir2_data_hdr;
0019 struct xfs_dir2_data_entry;
0020 struct xfs_dir2_data_unused;
0021 struct xfs_dir3_icfree_hdr;
0022 struct xfs_dir3_icleaf_hdr;
0023 
0024 extern const struct xfs_name    xfs_name_dotdot;
0025 
0026 /*
0027  * Convert inode mode to directory entry filetype
0028  */
0029 extern unsigned char xfs_mode_to_ftype(int mode);
0030 
0031 /*
0032  * Generic directory interface routines
0033  */
0034 extern void xfs_dir_startup(void);
0035 extern int xfs_da_mount(struct xfs_mount *mp);
0036 extern void xfs_da_unmount(struct xfs_mount *mp);
0037 
0038 extern int xfs_dir_isempty(struct xfs_inode *dp);
0039 extern int xfs_dir_init(struct xfs_trans *tp, struct xfs_inode *dp,
0040                 struct xfs_inode *pdp);
0041 extern int xfs_dir_createname(struct xfs_trans *tp, struct xfs_inode *dp,
0042                 const struct xfs_name *name, xfs_ino_t inum,
0043                 xfs_extlen_t tot);
0044 extern int xfs_dir_lookup(struct xfs_trans *tp, struct xfs_inode *dp,
0045                 const struct xfs_name *name, xfs_ino_t *inum,
0046                 struct xfs_name *ci_name);
0047 extern int xfs_dir_removename(struct xfs_trans *tp, struct xfs_inode *dp,
0048                 struct xfs_name *name, xfs_ino_t ino,
0049                 xfs_extlen_t tot);
0050 extern int xfs_dir_replace(struct xfs_trans *tp, struct xfs_inode *dp,
0051                 const struct xfs_name *name, xfs_ino_t inum,
0052                 xfs_extlen_t tot);
0053 extern int xfs_dir_canenter(struct xfs_trans *tp, struct xfs_inode *dp,
0054                 struct xfs_name *name);
0055 
0056 /*
0057  * Direct call from the bmap code, bypassing the generic directory layer.
0058  */
0059 extern int xfs_dir2_sf_to_block(struct xfs_da_args *args);
0060 
0061 /*
0062  * Interface routines used by userspace utilities
0063  */
0064 extern int xfs_dir2_isblock(struct xfs_da_args *args, int *r);
0065 extern int xfs_dir2_isleaf(struct xfs_da_args *args, int *r);
0066 extern int xfs_dir2_shrink_inode(struct xfs_da_args *args, xfs_dir2_db_t db,
0067                 struct xfs_buf *bp);
0068 
0069 extern void xfs_dir2_data_freescan(struct xfs_mount *mp,
0070         struct xfs_dir2_data_hdr *hdr, int *loghead);
0071 extern void xfs_dir2_data_log_entry(struct xfs_da_args *args,
0072         struct xfs_buf *bp, struct xfs_dir2_data_entry *dep);
0073 extern void xfs_dir2_data_log_header(struct xfs_da_args *args,
0074         struct xfs_buf *bp);
0075 extern void xfs_dir2_data_log_unused(struct xfs_da_args *args,
0076         struct xfs_buf *bp, struct xfs_dir2_data_unused *dup);
0077 extern void xfs_dir2_data_make_free(struct xfs_da_args *args,
0078         struct xfs_buf *bp, xfs_dir2_data_aoff_t offset,
0079         xfs_dir2_data_aoff_t len, int *needlogp, int *needscanp);
0080 extern int xfs_dir2_data_use_free(struct xfs_da_args *args,
0081         struct xfs_buf *bp, struct xfs_dir2_data_unused *dup,
0082         xfs_dir2_data_aoff_t offset, xfs_dir2_data_aoff_t len,
0083         int *needlogp, int *needscanp);
0084 
0085 extern struct xfs_dir2_data_free *xfs_dir2_data_freefind(
0086         struct xfs_dir2_data_hdr *hdr, struct xfs_dir2_data_free *bf,
0087         struct xfs_dir2_data_unused *dup);
0088 
0089 extern int xfs_dir_ino_validate(struct xfs_mount *mp, xfs_ino_t ino);
0090 
0091 extern const struct xfs_buf_ops xfs_dir3_block_buf_ops;
0092 extern const struct xfs_buf_ops xfs_dir3_leafn_buf_ops;
0093 extern const struct xfs_buf_ops xfs_dir3_leaf1_buf_ops;
0094 extern const struct xfs_buf_ops xfs_dir3_free_buf_ops;
0095 extern const struct xfs_buf_ops xfs_dir3_data_buf_ops;
0096 
0097 /*
0098  * Directory offset/block conversion functions.
0099  *
0100  * DB blocks here are logical directory block numbers, not filesystem blocks.
0101  */
0102 
0103 /*
0104  * Convert dataptr to byte in file space
0105  */
0106 static inline xfs_dir2_off_t
0107 xfs_dir2_dataptr_to_byte(xfs_dir2_dataptr_t dp)
0108 {
0109     return (xfs_dir2_off_t)dp << XFS_DIR2_DATA_ALIGN_LOG;
0110 }
0111 
0112 /*
0113  * Convert byte in file space to dataptr.  It had better be aligned.
0114  */
0115 static inline xfs_dir2_dataptr_t
0116 xfs_dir2_byte_to_dataptr(xfs_dir2_off_t by)
0117 {
0118     return (xfs_dir2_dataptr_t)(by >> XFS_DIR2_DATA_ALIGN_LOG);
0119 }
0120 
0121 /*
0122  * Convert byte in space to (DB) block
0123  */
0124 static inline xfs_dir2_db_t
0125 xfs_dir2_byte_to_db(struct xfs_da_geometry *geo, xfs_dir2_off_t by)
0126 {
0127     return (xfs_dir2_db_t)(by >> geo->blklog);
0128 }
0129 
0130 /*
0131  * Convert dataptr to a block number
0132  */
0133 static inline xfs_dir2_db_t
0134 xfs_dir2_dataptr_to_db(struct xfs_da_geometry *geo, xfs_dir2_dataptr_t dp)
0135 {
0136     return xfs_dir2_byte_to_db(geo, xfs_dir2_dataptr_to_byte(dp));
0137 }
0138 
0139 /*
0140  * Convert byte in space to offset in a block
0141  */
0142 static inline xfs_dir2_data_aoff_t
0143 xfs_dir2_byte_to_off(struct xfs_da_geometry *geo, xfs_dir2_off_t by)
0144 {
0145     return (xfs_dir2_data_aoff_t)(by & (geo->blksize - 1));
0146 }
0147 
0148 /*
0149  * Convert dataptr to a byte offset in a block
0150  */
0151 static inline xfs_dir2_data_aoff_t
0152 xfs_dir2_dataptr_to_off(struct xfs_da_geometry *geo, xfs_dir2_dataptr_t dp)
0153 {
0154     return xfs_dir2_byte_to_off(geo, xfs_dir2_dataptr_to_byte(dp));
0155 }
0156 
0157 /*
0158  * Convert block and offset to byte in space
0159  */
0160 static inline xfs_dir2_off_t
0161 xfs_dir2_db_off_to_byte(struct xfs_da_geometry *geo, xfs_dir2_db_t db,
0162             xfs_dir2_data_aoff_t o)
0163 {
0164     return ((xfs_dir2_off_t)db << geo->blklog) + o;
0165 }
0166 
0167 /*
0168  * Convert block (DB) to block (dablk)
0169  */
0170 static inline xfs_dablk_t
0171 xfs_dir2_db_to_da(struct xfs_da_geometry *geo, xfs_dir2_db_t db)
0172 {
0173     return (xfs_dablk_t)(db << (geo->blklog - geo->fsblog));
0174 }
0175 
0176 /*
0177  * Convert byte in space to (DA) block
0178  */
0179 static inline xfs_dablk_t
0180 xfs_dir2_byte_to_da(struct xfs_da_geometry *geo, xfs_dir2_off_t by)
0181 {
0182     return xfs_dir2_db_to_da(geo, xfs_dir2_byte_to_db(geo, by));
0183 }
0184 
0185 /*
0186  * Convert block and offset to dataptr
0187  */
0188 static inline xfs_dir2_dataptr_t
0189 xfs_dir2_db_off_to_dataptr(struct xfs_da_geometry *geo, xfs_dir2_db_t db,
0190                xfs_dir2_data_aoff_t o)
0191 {
0192     return xfs_dir2_byte_to_dataptr(xfs_dir2_db_off_to_byte(geo, db, o));
0193 }
0194 
0195 /*
0196  * Convert block (dablk) to block (DB)
0197  */
0198 static inline xfs_dir2_db_t
0199 xfs_dir2_da_to_db(struct xfs_da_geometry *geo, xfs_dablk_t da)
0200 {
0201     return (xfs_dir2_db_t)(da >> (geo->blklog - geo->fsblog));
0202 }
0203 
0204 /*
0205  * Convert block (dablk) to byte offset in space
0206  */
0207 static inline xfs_dir2_off_t
0208 xfs_dir2_da_to_byte(struct xfs_da_geometry *geo, xfs_dablk_t da)
0209 {
0210     return xfs_dir2_db_off_to_byte(geo, xfs_dir2_da_to_db(geo, da), 0);
0211 }
0212 
0213 /*
0214  * Directory tail pointer accessor functions. Based on block geometry.
0215  */
0216 static inline struct xfs_dir2_block_tail *
0217 xfs_dir2_block_tail_p(struct xfs_da_geometry *geo, struct xfs_dir2_data_hdr *hdr)
0218 {
0219     return ((struct xfs_dir2_block_tail *)
0220         ((char *)hdr + geo->blksize)) - 1;
0221 }
0222 
0223 static inline struct xfs_dir2_leaf_tail *
0224 xfs_dir2_leaf_tail_p(struct xfs_da_geometry *geo, struct xfs_dir2_leaf *lp)
0225 {
0226     return (struct xfs_dir2_leaf_tail *)
0227         ((char *)lp + geo->blksize -
0228           sizeof(struct xfs_dir2_leaf_tail));
0229 }
0230 
0231 /*
0232  * The Linux API doesn't pass down the total size of the buffer
0233  * we read into down to the filesystem.  With the filldir concept
0234  * it's not needed for correct information, but the XFS dir2 leaf
0235  * code wants an estimate of the buffer size to calculate it's
0236  * readahead window and size the buffers used for mapping to
0237  * physical blocks.
0238  *
0239  * Try to give it an estimate that's good enough, maybe at some
0240  * point we can change the ->readdir prototype to include the
0241  * buffer size.  For now we use the current glibc buffer size.
0242  * musl libc hardcodes 2k and dietlibc uses PAGE_SIZE.
0243  */
0244 #define XFS_READDIR_BUFSIZE (32768)
0245 
0246 unsigned char xfs_dir3_get_dtype(struct xfs_mount *mp, uint8_t filetype);
0247 unsigned int xfs_dir3_data_end_offset(struct xfs_da_geometry *geo,
0248         struct xfs_dir2_data_hdr *hdr);
0249 bool xfs_dir2_namecheck(const void *name, size_t length);
0250 
0251 #endif  /* __XFS_DIR2_H__ */