]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blobdiff - libxfs/libxfs_priv.h
libfrog: move crc32c code out of libxfs
[thirdparty/xfsprogs-dev.git] / libxfs / libxfs_priv.h
index 130f6ed2bbbec9baa5407703ca5987a2ac157395..2f2ca06f1bb18a4712b95975cd24b7c40755852d 100644 (file)
@@ -1,19 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * Copyright (c) 2000-2005 Silicon Graphics, Inc.
  * All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write the Free Software Foundation,
- * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
 /*
 #include "xfs_arch.h"
 
 #include "xfs_fs.h"
+#include "crc32c.h"
 
 /* CRC stuff, buffer API dependent on it */
-extern uint32_t crc32_le(uint32_t crc, unsigned char const *p, size_t len);
-extern uint32_t crc32c_le(uint32_t crc, unsigned char const *p, size_t len);
-
-#define crc32(c,p,l)   crc32_le((c),(unsigned char const *)(p),(l))
 #define crc32c(c,p,l)  crc32c_le((c),(unsigned char const *)(p),(l))
 
 #include "xfs_cksum.h"
@@ -102,6 +87,16 @@ extern char    *progname;
 
 #define STATIC                         static
 
+/*
+ * Starting in Linux 4.15, the %p (raw pointer value) printk modifier
+ * prints a hashed version of the pointer to avoid leaking kernel
+ * pointers into dmesg.  If we're trying to debug the kernel we want the
+ * raw values, so override this behavior as best we can.
+ *
+ * In userspace we don't have this problem.
+ */
+#define PTR_FMT "%p"
+
 /* XXX: need to push these out to make LIBXFS_ATTR defines */
 #define ATTR_ROOT                      0x0002
 #define ATTR_SECURE                    0x0008
@@ -118,12 +113,22 @@ enum ce { CE_DEBUG, CE_CONT, CE_NOTE, CE_WARN, CE_ALERT, CE_PANIC };
 
 #define xfs_notice(mp,fmt,args...)             cmn_err(CE_NOTE,fmt, ## args)
 #define xfs_warn(mp,fmt,args...)               cmn_err(CE_WARN,fmt, ## args)
+#define xfs_err(mp,fmt,args...)                        cmn_err(CE_ALERT,fmt, ## args)
+#define xfs_alert(mp,fmt,args...)              cmn_err(CE_ALERT,fmt, ## args)
+#define xfs_alert_tag(mp,tag,fmt,args...)      cmn_err(CE_ALERT,fmt, ## args)
+
 #define xfs_hex_dump(d,n)              ((void) 0)
 
 #define xfs_force_shutdown(d,n)                ((void) 0)
 
 /* stop unused var warnings by assigning mp to itself */
-#define XFS_CORRUPTION_ERROR(e,l,mp,m) do { \
+
+#define xfs_corruption_error(e,l,mp,b,sz,fi,ln,fa)     do { \
+       (mp) = (mp); \
+       cmn_err(CE_ALERT, "%s: XFS_CORRUPTION_ERROR", (e));  \
+} while (0)
+
+#define XFS_CORRUPTION_ERROR(e, lvl, mp, buf, bufsize) do { \
        (mp) = (mp); \
        cmn_err(CE_ALERT, "%s: XFS_CORRUPTION_ERROR", (e));  \
 } while (0)
@@ -180,8 +185,6 @@ enum ce { CE_DEBUG, CE_CONT, CE_NOTE, CE_WARN, CE_ALERT, CE_PANIC };
 # define barrier() __memory_barrier()
 #endif
 
-#define XFS_DQUOT_CLUSTER_SIZE_FSB (xfs_filblks_t)1
-
 /* miscellaneous kernel routines not in user space */
 #define down_read(a)           ((void) 0)
 #define up_read(a)             ((void) 0)
@@ -209,6 +212,11 @@ static inline bool WARN_ON_ONCE(bool expr) {
 
 #define PAGE_SIZE              getpagesize()
 
+#define inode_peek_iversion(inode)     (inode)->i_version
+#define inode_set_iversion_queried(inode, version) do { \
+       (inode)->i_version = (version); \
+} while (0)
+
 static inline int __do_div(unsigned long long *n, unsigned base)
 {
        int __res;
@@ -221,6 +229,24 @@ static inline int __do_div(unsigned long long *n, unsigned base)
 #define do_mod(a, b)           ((a) % (b))
 #define rol32(x,y)             (((x) << (y)) | ((x) >> (32 - (y))))
 
+/**
+ * div_u64_rem - unsigned 64bit divide with 32bit divisor with remainder
+ * @dividend: unsigned 64bit dividend
+ * @divisor: unsigned 32bit divisor
+ * @remainder: pointer to unsigned 32bit remainder
+ *
+ * Return: sets ``*remainder``, then returns dividend / divisor
+ *
+ * This is commonly provided by 32bit archs to provide an optimized 64bit
+ * divide.
+ */
+static inline uint64_t
+div_u64_rem(uint64_t dividend, uint32_t divisor, uint32_t *remainder)
+{
+       *remainder = dividend % divisor;
+       return dividend / divisor;
+}
+
 #define min_t(type,x,y) \
        ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
 #define max_t(type,x,y) \
@@ -336,17 +362,21 @@ roundup_64(uint64_t x, uint32_t y)
 #define XFS_BUF_SET_BDSTRAT_FUNC(a,b)  ((void) 0)
 
 /* avoid gcc warning */
-#define xfs_incore(bt,blkno,len,lockit)        ({              \
+#define xfs_buf_incore(bt,blkno,len,lockit) ({         \
        typeof(blkno) __foo = (blkno);                  \
        typeof(len) __bar = (len);                      \
        (blkno) = __foo;                                \
        (len) = __bar; /* no set-but-unused warning */  \
        NULL;                                           \
 })
+#define xfs_buf_get_uncached(t,n,f)     \
+       libxfs_getbufr((t), XFS_BUF_DADDR_NULL, (n));
 #define xfs_buf_relse(bp)              libxfs_putbuf(bp)
 #define xfs_buf_get(devp,blkno,len,f)  (libxfs_getbuf((devp), (blkno), (len)))
 #define xfs_bwrite(bp)                 libxfs_writebuf((bp), 0)
 #define xfs_buf_delwri_queue(bp, bl)   libxfs_writebuf((bp), 0)
+#define xfs_buf_delwri_submit(bl)      (0)
+#define xfs_buf_oneshot(bp)            ((void) 0)
 
 #define XBRW_READ                      LIBXFS_BREAD
 #define XBRW_WRITE                     LIBXFS_BWRITE
@@ -383,10 +413,6 @@ roundup_64(uint64_t x, uint32_t y)
 })
 #define xfs_buf_readahead_map(a,b,c,ops)       ((void) 0)      /* no readahead */
 
-#define xfs_warn(mp,fmt,args...)               cmn_err(CE_WARN,fmt, ## args)
-#define xfs_alert(mp,fmt,args...)              cmn_err(CE_ALERT,fmt, ## args)
-#define xfs_alert_tag(mp,tag,fmt,args...)      cmn_err(CE_ALERT,fmt, ## args)
-
 #define xfs_sort                                       qsort
 
 #define xfs_ilock(ip,mode)                             ((void) 0)
@@ -400,6 +426,9 @@ roundup_64(uint64_t x, uint32_t y)
 })
 
 /* space allocation */
+#define XFS_EXTENT_BUSY_DISCARDED      0x01    /* undergoing a discard op. */
+#define XFS_EXTENT_BUSY_SKIP_DISCARD   0x02    /* do not discard */
+
 #define xfs_extent_busy_reuse(mp,ag,bno,len,user)      ((void) 0)
 /* avoid unused variable warning */
 #define xfs_extent_busy_insert(tp,ag,bno,len,flags)({  \
@@ -428,7 +457,7 @@ roundup_64(uint64_t x, uint32_t y)
 #define xfs_trans_mod_dquot_byino(t,i,f,d)             ((void) 0)
 #define xfs_trans_reserve_quota_nblks(t,i,b,n,f)       (0)
 #define xfs_trans_unreserve_quota_nblks(t,i,b,n,f)     ((void) 0)
-#define xfs_qm_dqattach(i,f)                           (0)
+#define xfs_qm_dqattach(i)                             (0)
 
 #define uuid_copy(s,d)         platform_uuid_copy((s),(d))
 #define uuid_equal(s,d)                (platform_uuid_compare((s),(d)) == 0)
@@ -494,15 +523,24 @@ int  libxfs_mod_incore_sb(struct xfs_mount *, int, int64_t, int);
 #define xfs_reinit_percpu_counters(mp)
 
 void xfs_trans_mod_sb(struct xfs_trans *, uint, long);
-void xfs_verifier_error(struct xfs_buf *bp, int error, xfs_failaddr_t failaddr);
+
+void xfs_verifier_error(struct xfs_buf *bp, int error,
+                       xfs_failaddr_t failaddr);
+void xfs_inode_verifier_error(struct xfs_inode *ip, int error,
+                       const char *name, void *buf, size_t bufsz,
+                       xfs_failaddr_t failaddr);
+
+#define xfs_buf_verifier_error(bp,e,n,bu,bus,fa) \
+       xfs_verifier_error(bp, e, fa)
 
 /* XXX: this is clearly a bug - a shared header needs to export this */
 /* xfs_rtalloc.c */
 int libxfs_rtfree_extent(struct xfs_trans *, xfs_rtblock_t, xfs_extlen_t);
+bool libxfs_verify_rtbno(struct xfs_mount *mp, xfs_rtblock_t rtbno);
 
 struct xfs_rtalloc_rec {
-       xfs_rtblock_t           ar_startblock;
-       xfs_rtblock_t           ar_blockcount;
+       xfs_rtblock_t           ar_startext;
+       xfs_rtblock_t           ar_extcount;
 };
 
 typedef int (*xfs_rtalloc_query_range_fn)(
@@ -526,5 +564,35 @@ bool xfs_log_check_lsn(struct xfs_mount *, xfs_lsn_t);
 
 typedef unsigned char u8;
 unsigned int hweight8(unsigned int w);
+unsigned int hweight32(unsigned int w);
+unsigned int hweight64(__u64 w);
+
+#define BIT_MASK(nr)   (1UL << ((nr) % BITS_PER_LONG))
+#define BIT_WORD(nr)   ((nr) / BITS_PER_LONG)
+
+static inline void set_bit(int nr, volatile unsigned long *addr)
+{
+       unsigned long mask = BIT_MASK(nr);
+       unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
+
+       *p  |= mask;
+}
+
+static inline void clear_bit(int nr, volatile unsigned long *addr)
+{
+       unsigned long mask = BIT_MASK(nr);
+       unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
+
+       *p &= ~mask;
+}
+
+static inline int test_bit(int nr, const volatile unsigned long *addr)
+{
+       unsigned long mask = BIT_MASK(nr);
+       unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
+
+       return *p & mask;
+}
+
 
 #endif /* __LIBXFS_INTERNAL_XFS_H__ */