Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * Copyright (c) 2000-2005 Silicon Graphics, Inc.
0004  * All Rights Reserved.
0005  */
0006 #ifndef __XFS_LINUX__
0007 #define __XFS_LINUX__
0008 
0009 #include <linux/types.h>
0010 #include <linux/uuid.h>
0011 
0012 /*
0013  * Kernel specific type declarations for XFS
0014  */
0015 
0016 typedef __s64           xfs_off_t;  /* <file offset> type */
0017 typedef unsigned long long  xfs_ino_t;  /* <inode> type */
0018 typedef __s64           xfs_daddr_t;    /* <disk address> type */
0019 typedef __u32           xfs_dev_t;
0020 typedef __u32           xfs_nlink_t;
0021 
0022 #include "xfs_types.h"
0023 
0024 #include "kmem.h"
0025 #include "mrlock.h"
0026 
0027 #include <linux/semaphore.h>
0028 #include <linux/mm.h>
0029 #include <linux/sched/mm.h>
0030 #include <linux/kernel.h>
0031 #include <linux/blkdev.h>
0032 #include <linux/slab.h>
0033 #include <linux/crc32c.h>
0034 #include <linux/module.h>
0035 #include <linux/mutex.h>
0036 #include <linux/file.h>
0037 #include <linux/swap.h>
0038 #include <linux/errno.h>
0039 #include <linux/sched/signal.h>
0040 #include <linux/bitops.h>
0041 #include <linux/major.h>
0042 #include <linux/pagemap.h>
0043 #include <linux/vfs.h>
0044 #include <linux/seq_file.h>
0045 #include <linux/init.h>
0046 #include <linux/list.h>
0047 #include <linux/proc_fs.h>
0048 #include <linux/sort.h>
0049 #include <linux/cpu.h>
0050 #include <linux/notifier.h>
0051 #include <linux/delay.h>
0052 #include <linux/log2.h>
0053 #include <linux/spinlock.h>
0054 #include <linux/random.h>
0055 #include <linux/ctype.h>
0056 #include <linux/writeback.h>
0057 #include <linux/capability.h>
0058 #include <linux/kthread.h>
0059 #include <linux/freezer.h>
0060 #include <linux/list_sort.h>
0061 #include <linux/ratelimit.h>
0062 #include <linux/rhashtable.h>
0063 #include <linux/xattr.h>
0064 #include <linux/mnt_idmapping.h>
0065 
0066 #include <asm/page.h>
0067 #include <asm/div64.h>
0068 #include <asm/param.h>
0069 #include <linux/uaccess.h>
0070 #include <asm/byteorder.h>
0071 #include <asm/unaligned.h>
0072 
0073 #include "xfs_fs.h"
0074 #include "xfs_stats.h"
0075 #include "xfs_sysctl.h"
0076 #include "xfs_iops.h"
0077 #include "xfs_aops.h"
0078 #include "xfs_super.h"
0079 #include "xfs_cksum.h"
0080 #include "xfs_buf.h"
0081 #include "xfs_message.h"
0082 
0083 #ifdef __BIG_ENDIAN
0084 #define XFS_NATIVE_HOST 1
0085 #else
0086 #undef XFS_NATIVE_HOST
0087 #endif
0088 
0089 #define irix_sgid_inherit   xfs_params.sgid_inherit.val
0090 #define irix_symlink_mode   xfs_params.symlink_mode.val
0091 #define xfs_panic_mask      xfs_params.panic_mask.val
0092 #define xfs_error_level     xfs_params.error_level.val
0093 #define xfs_syncd_centisecs xfs_params.syncd_timer.val
0094 #define xfs_stats_clear     xfs_params.stats_clear.val
0095 #define xfs_inherit_sync    xfs_params.inherit_sync.val
0096 #define xfs_inherit_nodump  xfs_params.inherit_nodump.val
0097 #define xfs_inherit_noatime xfs_params.inherit_noatim.val
0098 #define xfs_inherit_nosymlinks  xfs_params.inherit_nosym.val
0099 #define xfs_rotorstep       xfs_params.rotorstep.val
0100 #define xfs_inherit_nodefrag    xfs_params.inherit_nodfrg.val
0101 #define xfs_fstrm_centisecs xfs_params.fstrm_timer.val
0102 #define xfs_blockgc_secs    xfs_params.blockgc_timer.val
0103 
0104 #define current_cpu()       (raw_smp_processor_id())
0105 #define current_set_flags_nested(sp, f)     \
0106         (*(sp) = current->flags, current->flags |= (f))
0107 #define current_restore_flags_nested(sp, f) \
0108         (current->flags = ((current->flags & ~(f)) | (*(sp) & (f))))
0109 
0110 #define NBBY        8       /* number of bits per byte */
0111 
0112 /*
0113  * Size of block device i/o is parameterized here.
0114  * Currently the system supports page-sized i/o.
0115  */
0116 #define BLKDEV_IOSHIFT      PAGE_SHIFT
0117 #define BLKDEV_IOSIZE       (1<<BLKDEV_IOSHIFT)
0118 /* number of BB's per block device block */
0119 #define BLKDEV_BB       BTOBB(BLKDEV_IOSIZE)
0120 
0121 #define ENOATTR     ENODATA     /* Attribute not found */
0122 #define EWRONGFS    EINVAL      /* Mount with wrong filesystem type */
0123 #define EFSCORRUPTED    EUCLEAN     /* Filesystem is corrupted */
0124 #define EFSBADCRC   EBADMSG     /* Bad CRC detected */
0125 
0126 #define __return_address __builtin_return_address(0)
0127 
0128 /*
0129  * Return the address of a label.  Use barrier() so that the optimizer
0130  * won't reorder code to refactor the error jumpouts into a single
0131  * return, which throws off the reported address.
0132  */
0133 #define __this_address  ({ __label__ __here; __here: barrier(); &&__here; })
0134 
0135 #define XFS_PROJID_DEFAULT  0
0136 
0137 #define howmany(x, y)   (((x)+((y)-1))/(y))
0138 
0139 static inline void delay(long ticks)
0140 {
0141     schedule_timeout_uninterruptible(ticks);
0142 }
0143 
0144 /*
0145  * XFS wrapper structure for sysfs support. It depends on external data
0146  * structures and is embedded in various internal data structures to implement
0147  * the XFS sysfs object heirarchy. Define it here for broad access throughout
0148  * the codebase.
0149  */
0150 struct xfs_kobj {
0151     struct kobject      kobject;
0152     struct completion   complete;
0153 };
0154 
0155 struct xstats {
0156     struct xfsstats __percpu    *xs_stats;
0157     struct xfs_kobj         xs_kobj;
0158 };
0159 
0160 extern struct xstats xfsstats;
0161 
0162 static inline dev_t xfs_to_linux_dev_t(xfs_dev_t dev)
0163 {
0164     return MKDEV(sysv_major(dev) & 0x1ff, sysv_minor(dev));
0165 }
0166 
0167 static inline xfs_dev_t linux_to_xfs_dev_t(dev_t dev)
0168 {
0169     return sysv_encode_dev(dev);
0170 }
0171 
0172 /*
0173  * Various platform dependent calls that don't fit anywhere else
0174  */
0175 #define xfs_sort(a,n,s,fn)  sort(a,n,s,fn,NULL)
0176 #define xfs_stack_trace()   dump_stack()
0177 
0178 static inline uint64_t rounddown_64(uint64_t x, uint32_t y)
0179 {
0180     do_div(x, y);
0181     return x * y;
0182 }
0183 
0184 static inline uint64_t roundup_64(uint64_t x, uint32_t y)
0185 {
0186     x += y - 1;
0187     do_div(x, y);
0188     return x * y;
0189 }
0190 
0191 static inline uint64_t howmany_64(uint64_t x, uint32_t y)
0192 {
0193     x += y - 1;
0194     do_div(x, y);
0195     return x;
0196 }
0197 
0198 int xfs_rw_bdev(struct block_device *bdev, sector_t sector, unsigned int count,
0199         char *data, enum req_op op);
0200 
0201 #define ASSERT_ALWAYS(expr) \
0202     (likely(expr) ? (void)0 : assfail(NULL, #expr, __FILE__, __LINE__))
0203 
0204 #ifdef DEBUG
0205 #define ASSERT(expr)    \
0206     (likely(expr) ? (void)0 : assfail(NULL, #expr, __FILE__, __LINE__))
0207 
0208 #else   /* !DEBUG */
0209 
0210 #ifdef XFS_WARN
0211 
0212 #define ASSERT(expr)    \
0213     (likely(expr) ? (void)0 : asswarn(NULL, #expr, __FILE__, __LINE__))
0214 
0215 #else   /* !DEBUG && !XFS_WARN */
0216 
0217 #define ASSERT(expr)        ((void)0)
0218 
0219 #endif /* XFS_WARN */
0220 #endif /* DEBUG */
0221 
0222 #define XFS_IS_CORRUPT(mp, expr)    \
0223     (unlikely(expr) ? xfs_corruption_error(#expr, XFS_ERRLEVEL_LOW, (mp), \
0224                            NULL, 0, __FILE__, __LINE__, \
0225                            __this_address), \
0226               true : false)
0227 
0228 #define STATIC static noinline
0229 
0230 #ifdef CONFIG_XFS_RT
0231 
0232 /*
0233  * make sure we ignore the inode flag if the filesystem doesn't have a
0234  * configured realtime device.
0235  */
0236 #define XFS_IS_REALTIME_INODE(ip)           \
0237     (((ip)->i_diflags & XFS_DIFLAG_REALTIME) && \
0238      (ip)->i_mount->m_rtdev_targp)
0239 #define XFS_IS_REALTIME_MOUNT(mp) ((mp)->m_rtdev_targp ? 1 : 0)
0240 #else
0241 #define XFS_IS_REALTIME_INODE(ip) (0)
0242 #define XFS_IS_REALTIME_MOUNT(mp) (0)
0243 #endif
0244 
0245 /*
0246  * Starting in Linux 4.15, the %p (raw pointer value) printk modifier
0247  * prints a hashed version of the pointer to avoid leaking kernel
0248  * pointers into dmesg.  If we're trying to debug the kernel we want the
0249  * raw values, so override this behavior as best we can.
0250  */
0251 #ifdef DEBUG
0252 # define PTR_FMT "%px"
0253 #else
0254 # define PTR_FMT "%p"
0255 #endif
0256 
0257 #endif /* __XFS_LINUX__ */