]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blobdiff - libxfs/libxfs_priv.h
libfrog: move crc32c.h to libfrog/
[thirdparty/xfsprogs-dev.git] / libxfs / libxfs_priv.h
index 9829bc88c92abd0456d362dccd2cef008d46dc36..96d74bfa3798af97c9058b583c9e19b4ebf7b2f2 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 "cache.h"
 #include "bitops.h"
 #include "kmem.h"
-#include "radix-tree.h"
+#include "libfrog/radix-tree.h"
 #include "atomic.h"
 
 #include "xfs_types.h"
 #include "xfs_arch.h"
 
 #include "xfs_fs.h"
+#include "libfrog/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);
+/* Zones used in libxfs allocations that aren't in shared header files */
+extern kmem_zone_t *xfs_buf_item_zone;
+extern kmem_zone_t *xfs_ili_zone;
+extern kmem_zone_t *xfs_buf_zone;
+extern kmem_zone_t *xfs_inode_zone;
+extern kmem_zone_t *xfs_trans_zone;
 
-#define crc32(c,p,l)   crc32_le((c),(unsigned char const *)(p),(l))
+/* CRC stuff, buffer API dependent on it */
 #define crc32c(c,p,l)  crc32c_le((c),(unsigned char const *)(p),(l))
 
 #include "xfs_cksum.h"
@@ -112,14 +104,6 @@ extern char    *progname;
  */
 #define PTR_FMT "%p"
 
-/* XXX: need to push these out to make LIBXFS_ATTR defines */
-#define ATTR_ROOT                      0x0002
-#define ATTR_SECURE                    0x0008
-#define ATTR_CREATE                    0x0010
-#define ATTR_REPLACE                   0x0020
-#define ATTR_KERNOTIME                 0
-#define ATTR_KERNOVAL                  0
-
 #define XFS_IGET_CREATE                        0x1
 #define XFS_IGET_UNTRUSTED             0x2
 
@@ -128,18 +112,24 @@ 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_hex_dump(d,n)              ((void) 0)
+#define xfs_stack_trace()              ((void) 0)
+
 
 #define xfs_force_shutdown(d,n)                ((void) 0)
+#define xfs_mod_delalloc(a,b)          ((void) 0)
 
 /* stop unused var warnings by assigning mp to itself */
 
-#define xfs_corruption_error(fu,e,l,mp,fi,ln,fa)       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,l,mp,m) do { \
+#define XFS_CORRUPTION_ERROR(e, lvl, mp, buf, bufsize) do { \
        (mp) = (mp); \
        cmn_err(CE_ALERT, "%s: XFS_CORRUPTION_ERROR", (e));  \
 } while (0)
@@ -197,8 +187,6 @@ enum ce { CE_DEBUG, CE_CONT, CE_NOTE, CE_WARN, CE_ALERT, CE_PANIC };
 #endif
 
 /* miscellaneous kernel routines not in user space */
-#define down_read(a)           ((void) 0)
-#define up_read(a)             ((void) 0)
 #define spin_lock_init(a)      ((void) 0)
 #define spin_lock(a)           ((void) 0)
 #define spin_unlock(a)         ((void) 0)
@@ -207,14 +195,18 @@ enum ce { CE_DEBUG, CE_CONT, CE_NOTE, CE_WARN, CE_ALERT, CE_PANIC };
 #define rcu_read_lock()                ((void) 0)
 #define rcu_read_unlock()      ((void) 0)
 /* Need to be able to handle this bare or in control flow */
-static inline bool WARN_ON_ONCE(bool expr) {
+static inline bool WARN_ON(bool expr) {
        return (expr);
 }
 
+#define WARN_ON_ONCE(e)                        WARN_ON(e)
 #define percpu_counter_read(x)         (*x)
 #define percpu_counter_read_positive(x)        ((*x) > 0 ? (*x) : 0)
 #define percpu_counter_sum(x)          (*x)
 
+#define READ_ONCE(x)                   (x)
+#define WRITE_ONCE(x, val)             ((x) = (val))
+
 /*
  * prandom_u32 is used for di_gen inode allocation, it must be zero for libxfs
  * or all sorts of badness can occur!
@@ -263,6 +255,13 @@ div_u64_rem(uint64_t dividend, uint32_t divisor, uint32_t *remainder)
 #define max_t(type,x,y) \
        ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
 
+/**
+ * swap - swap values of @a and @b
+ * @a: first value
+ * @b: second value
+ */
+#define swap(a, b) \
+       do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0)
 
 #define __round_mask(x, y) ((__typeof__(x))((y)-1))
 #define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
@@ -383,7 +382,7 @@ roundup_64(uint64_t x, uint32_t y)
 #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_buf_get(devp,blkno,len)    (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)
@@ -391,8 +390,7 @@ roundup_64(uint64_t x, uint32_t y)
 
 #define XBRW_READ                      LIBXFS_BREAD
 #define XBRW_WRITE                     LIBXFS_BWRITE
-#define xfs_buf_iomove(bp,off,len,data,f)      libxfs_iomove(bp,off,len,data,f)
-#define xfs_buf_zero(bp,off,len)       libxfs_iomove(bp,off,len,0,LIBXFS_BZERO)
+#define xfs_buf_zero(bp,off,len)     libxfs_iomove(bp,off,len,NULL,LIBXFS_BZERO)
 
 /* mount stuff */
 #define XFS_MOUNT_32BITINODES          LIBXFS_MOUNT_32BITINODES
@@ -403,7 +401,7 @@ roundup_64(uint64_t x, uint32_t y)
 #define XFS_MOUNT_IKEEP                        0       /* ignored in userspace */
 #define XFS_MOUNT_SWALLOC              0       /* ignored in userspace */
 #define XFS_MOUNT_RDONLY               0       /* ignored in userspace */
-
+#define XFS_MOUNT_BAD_SUMMARY          0       /* ignored in userspace */
 
 #define xfs_trans_set_sync(tp)         ((void) 0)
 #define        xfs_trans_agblocks_delta(tp, d)
@@ -424,15 +422,9 @@ 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)
-#define xfs_ilock_nowait(ip,mode)                      ((void) 0)
-#define xfs_ilock_demote(ip,mode)                      ((void) 0)
 #define xfs_ilock_data_map_shared(ip)                  (0)
 #define xfs_ilock_attr_map_shared(ip)                  (0)
 #define xfs_iunlock(ip,mode)                           ({      \
@@ -465,9 +457,6 @@ roundup_64(uint64_t x, uint32_t y)
 #define xfs_filestream_lookup_ag(ip)           (0)
 #define xfs_filestream_new_ag(ip,ag)           (0)
 
-#define xfs_log_force(mp,flags)                        ((void) 0)
-#define XFS_LOG_SYNC                           1
-
 /* quota bits */
 #define xfs_trans_mod_dquot_byino(t,i,f,d)             ((void) 0)
 #define xfs_trans_reserve_quota_nblks(t,i,b,n,f)       (0)
@@ -566,7 +555,10 @@ typedef int (*xfs_rtalloc_query_range_fn)(
 int libxfs_zero_extent(struct xfs_inode *ip, xfs_fsblock_t start_fsb,
                         xfs_off_t count_fsb);
 
+
 bool xfs_log_check_lsn(struct xfs_mount *, xfs_lsn_t);
+void xfs_log_item_init(struct xfs_mount *, struct xfs_log_item *, int);
+#define xfs_log_in_recovery(mp)        (false)
 
 /* xfs_icache.c */
 #define xfs_inode_set_cowblocks_tag(ip)        do { } while (0)
@@ -579,6 +571,8 @@ 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)
@@ -607,5 +601,68 @@ static inline int test_bit(int nr, const volatile unsigned long *addr)
        return *p & mask;
 }
 
+/* Sets and returns original value of the bit */
+static inline int test_and_set_bit(int nr, volatile unsigned long *addr)
+{
+       if (test_bit(nr, addr))
+               return 1;
+       set_bit(nr, addr);
+       return 0;
+}
+
+/* Keep static checkers quiet about nonstatic functions by exporting */
+int xfs_inode_hasattr(struct xfs_inode *ip);
+int xfs_attr_get_ilocked(struct xfs_inode *ip, struct xfs_da_args *args);
+int xfs_attr_get(struct xfs_inode *ip, const unsigned char *name,
+                unsigned char *value, int *valuelenp, int flags);
+int xfs_attr_set(struct xfs_inode *dp, const unsigned char *name,
+                 unsigned char *value, int valuelen, int flags);
+int xfs_attr_remove(struct xfs_inode *dp, const unsigned char *name, int flags);
+
+int xfs_rtbuf_get(struct xfs_mount *mp, struct xfs_trans *tp,
+                 xfs_rtblock_t block, int issum, struct xfs_buf **bpp);
+int xfs_rtcheck_range(struct xfs_mount *mp, struct xfs_trans *tp,
+                     xfs_rtblock_t start, xfs_extlen_t len, int val,
+                     xfs_rtblock_t *new, int *stat);
+int xfs_rtfind_back(struct xfs_mount *mp, struct xfs_trans *tp,
+                   xfs_rtblock_t start, xfs_rtblock_t limit,
+                   xfs_rtblock_t *rtblock);
+int xfs_rtfind_forw(struct xfs_mount *mp, struct xfs_trans *tp,
+                   xfs_rtblock_t start, xfs_rtblock_t limit,
+                   xfs_rtblock_t *rtblock);
+int xfs_rtmodify_range(struct xfs_mount *mp, struct xfs_trans *tp,
+                      xfs_rtblock_t start, xfs_extlen_t len, int val);
+int xfs_rtmodify_summary_int(struct xfs_mount *mp, struct xfs_trans *tp,
+                            int log, xfs_rtblock_t bbno, int delta,
+                            xfs_buf_t **rbpp, xfs_fsblock_t *rsb,
+                            xfs_suminfo_t *sum);
+int xfs_rtmodify_summary(struct xfs_mount *mp, struct xfs_trans *tp, int log,
+                        xfs_rtblock_t bbno, int delta, xfs_buf_t **rbpp,
+                        xfs_fsblock_t *rsb);
+int xfs_rtfree_range(struct xfs_mount *mp, struct xfs_trans *tp,
+                    xfs_rtblock_t start, xfs_extlen_t len,
+                    struct xfs_buf **rbpp, xfs_fsblock_t *rsb);
+int xfs_rtalloc_query_range(struct xfs_trans *tp,
+                           struct xfs_rtalloc_rec *low_rec,
+                           struct xfs_rtalloc_rec *high_rec,
+                           xfs_rtalloc_query_range_fn fn,
+                           void *priv);
+int xfs_rtalloc_query_all(struct xfs_trans *tp,
+                         xfs_rtalloc_query_range_fn fn,
+                         void *priv);
+bool xfs_verify_rtbno(struct xfs_mount *mp, xfs_rtblock_t rtbno);
+int xfs_rtalloc_extent_is_free(struct xfs_mount *mp, struct xfs_trans *tp,
+                              xfs_rtblock_t start, xfs_extlen_t len,
+                              bool *is_free);
+/* xfs_bmap_util.h */
+struct xfs_bmalloca;
+int xfs_bmap_extsize_align(struct xfs_mount *mp, struct xfs_bmbt_irec *gotp,
+                          struct xfs_bmbt_irec *prevp, xfs_extlen_t extsz,
+                          int rt, int eof, int delay, int convert,
+                          xfs_fileoff_t *offp, xfs_extlen_t *lenp);
+void xfs_bmap_adjacent(struct xfs_bmalloca *ap);
+int xfs_bmap_last_extent(struct xfs_trans *tp, struct xfs_inode *ip,
+                        int whichfork, struct xfs_bmbt_irec *rec,
+                        int *is_empty);
 
 #endif /* __LIBXFS_INTERNAL_XFS_H__ */