]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blobdiff - logprint/log_misc.c
xfsprogs: make static things static
[thirdparty/xfsprogs-dev.git] / logprint / log_misc.c
index 6dc0ed4b2e4c8e8332e842dbb2ece1f5bbce56e1..e2889f0fc93ce2cc5f38eb159f685e671f141d12 100644 (file)
@@ -1,19 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * Copyright (c) 2000-2003,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 "libxfs.h"
 #include "libxlog.h"
@@ -36,7 +24,7 @@ typedef struct xlog_split_item {
        int                     si_skip;
 } xlog_split_item_t;
 
-xlog_split_item_t *split_list = NULL;
+static xlog_split_item_t *split_list = NULL;
 
 void
 print_xlog_op_line(void)
@@ -45,7 +33,7 @@ print_xlog_op_line(void)
           "--------------------------------------\n");
 }      /* print_xlog_op_line */
 
-void
+static void
 print_xlog_xhdr_line(void)
 {
     printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
@@ -70,7 +58,7 @@ print_stars(void)
  * Given a pointer to a data segment, print out the data as if it were
  * a log operation header.
  */
-void
+static void
 xlog_print_op_header(xlog_op_header_t  *op_head,
                     int                i,
                     char               **ptr)
@@ -110,7 +98,7 @@ xlog_print_op_header(xlog_op_header_t        *op_head,
 }      /* xlog_print_op_header */
 
 
-void
+static void
 xlog_print_add_to_trans(xlog_tid_t     tid,
                        int             skip)
 {
@@ -127,7 +115,7 @@ xlog_print_add_to_trans(xlog_tid_t  tid,
 }      /* xlog_print_add_to_trans */
 
 
-int
+static int
 xlog_print_find_tid(xlog_tid_t tid, uint was_cont)
 {
     xlog_split_item_t *listp = split_list;
@@ -161,17 +149,17 @@ xlog_print_find_tid(xlog_tid_t tid, uint was_cont)
     return 1;
 }      /* xlog_print_find_tid */
 
-int
+static int
 xlog_print_trans_header(char **ptr, int len)
 {
     xfs_trans_header_t  *h;
     char               *cptr = *ptr;
-    __uint32_t          magic;
+    uint32_t          magic;
     char                *magic_c = (char *)&magic;
 
     *ptr += len;
 
-    magic=*(__uint32_t*)cptr; /* XXX be32_to_cpu soon */
+    magic = *(uint32_t *)cptr; /* XXX be32_to_cpu soon */
 
     if (len >= 4) {
 #if __BYTE_ORDER == __LITTLE_ENDIAN
@@ -193,7 +181,7 @@ xlog_print_trans_header(char **ptr, int len)
 }      /* xlog_print_trans_header */
 
 
-int
+static int
 xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops)
 {
     xfs_buf_log_format_t *f;
@@ -201,7 +189,7 @@ xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops)
     int                         num, skip;
     int                         super_block = 0;
     int                         bucket, col, buckets;
-    __int64_t           blkno;
+    int64_t                     blkno;
     xfs_buf_log_format_t lbuf;
     int                         size, blen, map_size, struct_size;
     __be64              x, y;
@@ -211,7 +199,7 @@ xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops)
      * memmove to ensure 8-byte alignment for the long longs in
      * buf_log_format_t structure
      */
-    memmove(&lbuf, *ptr, MIN(sizeof(xfs_buf_log_format_t), len));
+    memmove(&lbuf, *ptr, min(sizeof(xfs_buf_log_format_t), len));
     f = &lbuf;
     *ptr += len;
 
@@ -428,13 +416,13 @@ xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops)
 }      /* xlog_print_trans_buffer */
 
 
-int
+static int
 xlog_print_trans_qoff(char **ptr, uint len)
 {
     xfs_qoff_logformat_t *f;
     xfs_qoff_logformat_t lbuf;
 
-    memmove(&lbuf, *ptr, MIN(sizeof(xfs_qoff_logformat_t), len));
+    memmove(&lbuf, *ptr, min(sizeof(xfs_qoff_logformat_t), len));
     f = &lbuf;
     *ptr += len;
     if (len >= sizeof(xfs_qoff_logformat_t)) {
@@ -447,7 +435,7 @@ xlog_print_trans_qoff(char **ptr, uint len)
 }      /* xlog_print_trans_qoff */
 
 
-void
+static void
 xlog_print_trans_inode_core(
        struct xfs_log_dinode   *ip)
 {
@@ -473,7 +461,7 @@ xlog_print_trans_inode_core(
     }
 }
 
-void
+static void
 xlog_print_dir2_sf(
        struct xlog     *log,
        xfs_dir2_sf_hdr_t *sfp,
@@ -508,38 +496,39 @@ xlog_print_dir2_sf(
        }
 }
 
-int
+static int
 xlog_print_trans_inode(
-       struct xlog     *log,
-       char            **ptr,
-       int             len,
-       int             *i,
-       int             num_ops,
-       int             continued)
+       struct xlog             *log,
+       char                    **ptr,
+       int                     len,
+       int                     *i,
+       int                     num_ops,
+       int                     continued)
 {
-    struct xfs_log_dinode dino;
-    xlog_op_header_t      *op_head;
-    xfs_inode_log_format_t dst_lbuf;
-    xfs_inode_log_format_64_t src_lbuf; /* buffer of biggest one */
-    xfs_inode_log_format_t *f;
-    int                           mode;
-    int                           size;
+    struct xfs_log_dinode      dino;
+    struct xlog_op_header      *op_head;
+    struct xfs_inode_log_format        dst_lbuf;
+    struct xfs_inode_log_format        src_lbuf;
+    struct xfs_inode_log_format *f;
+    int                                mode;
+    int                                size;
+    int                                skip_count;
 
     /*
      * print inode type header region
      *
      * memmove to ensure 8-byte alignment for the long longs in
-     * xfs_inode_log_format_t structure
+     * struct xfs_inode_log_format structure
      *
-     * len can be smaller than xfs_inode_log_format_32|64_t
+     * len can be smaller than struct xfs_inode_log_format
      * if format data is split over operations
      */
-    memmove(&src_lbuf, *ptr, MIN(sizeof(xfs_inode_log_format_64_t), len));
+    memmove(&src_lbuf, *ptr, min(sizeof(src_lbuf), len));
     (*i)++;                                    /* bump index */
     *ptr += len;
     if (!continued &&
-       (len == sizeof(xfs_inode_log_format_32_t) ||
-        len == sizeof(xfs_inode_log_format_64_t))) {
+       (len == sizeof(struct xfs_inode_log_format_32) ||
+        len == sizeof(struct xfs_inode_log_format))) {
        f = xfs_inode_item_format_convert((char*)&src_lbuf, len, &dst_lbuf);
        printf(_("INODE: "));
        printf(_("#regs: %d   ino: 0x%llx  flags: 0x%x   dsize: %d\n"),
@@ -549,21 +538,23 @@ xlog_print_trans_inode(
               (long long)f->ilf_blkno, f->ilf_len, f->ilf_boffset);
     } else {
        ASSERT(len >= 4);       /* must have at least 4 bytes if != 0 */
-       f = (xfs_inode_log_format_t *)&src_lbuf;
+       f = (struct xfs_inode_log_format *)&src_lbuf;
        printf(_("INODE: #regs: %d   Not printing rest of data\n"),
               f->ilf_size);
        return f->ilf_size;
     }
 
+    skip_count = f->ilf_size-1;
+
     if (*i >= num_ops)                 /* end of LR */
-           return f->ilf_size-1;
+           return skip_count;
 
     /* core inode comes 2nd */
     op_head = (xlog_op_header_t *)*ptr;
     xlog_print_op_header(op_head, *i, ptr);
 
     if (op_head->oh_flags & XLOG_CONTINUE_TRANS)  {
-       return f->ilf_size-1;
+        return skip_count;
     }
 
     memmove(&dino, *ptr, sizeof(dino));
@@ -571,13 +562,7 @@ xlog_print_trans_inode(
     size = (int)dino.di_size;
     xlog_print_trans_inode_core(&dino);
     *ptr += xfs_log_dinode_size(dino.di_version);
-
-    if (*i == num_ops-1 && f->ilf_size == 3)  {
-       return 1;
-    }
-
-    /* does anything come next */
-    op_head = (xlog_op_header_t *)*ptr;
+    skip_count--;
 
     switch (f->ilf_fields & (XFS_ILOG_DEV | XFS_ILOG_UUID)) {
     case XFS_ILOG_DEV:
@@ -595,7 +580,12 @@ xlog_print_trans_inode(
     ASSERT(f->ilf_size <= 4);
     ASSERT((f->ilf_size == 3) || (f->ilf_fields & XFS_ILOG_AFORK));
 
+    /* does anything come next */
+    op_head = (xlog_op_header_t *)*ptr;
+
     if (f->ilf_fields & XFS_ILOG_DFORK) {
+           if (*i == num_ops-1)
+               return skip_count;
            (*i)++;
            xlog_print_op_header(op_head, *i, ptr);
 
@@ -618,11 +608,14 @@ xlog_print_trans_inode(
 
            *ptr += be32_to_cpu(op_head->oh_len);
            if (op_head->oh_flags & XLOG_CONTINUE_TRANS)
-               return 1;
+               return skip_count;
            op_head = (xlog_op_header_t *)*ptr;
+           skip_count--;
     }
 
     if (f->ilf_fields & XFS_ILOG_AFORK) {
+           if (*i == num_ops-1)
+               return skip_count;
            (*i)++;
            xlog_print_op_header(op_head, *i, ptr);
 
@@ -644,14 +637,17 @@ xlog_print_trans_inode(
            }
            *ptr += be32_to_cpu(op_head->oh_len);
            if (op_head->oh_flags & XLOG_CONTINUE_TRANS)
-               return 1;
+               return skip_count;
+           skip_count--;
     }
 
+    ASSERT(skip_count == 0);
+
     return 0;
 }      /* xlog_print_trans_inode */
 
 
-int
+static int
 xlog_print_trans_dquot(char **ptr, int len, int *i, int num_ops)
 {
     xfs_dq_logformat_t *f;
@@ -666,7 +662,7 @@ xlog_print_trans_dquot(char **ptr, int len, int *i, int num_ops)
      * memmove to ensure 8-byte alignment for the long longs in
      * xfs_dq_logformat_t structure
      */
-    memmove(&lbuf, *ptr, MIN(sizeof(xfs_dq_logformat_t), len));
+    memmove(&lbuf, *ptr, min(sizeof(xfs_dq_logformat_t), len));
     f = &lbuf;
     (*i)++;                                    /* bump index */
     *ptr += len;
@@ -716,7 +712,7 @@ xlog_print_trans_icreate(
        struct xfs_icreate_log  icl_buf = {0};
        struct xfs_icreate_log  *icl;
 
-       memmove(&icl_buf, *ptr, MIN(sizeof(struct xfs_icreate_log), len));
+       memmove(&icl_buf, *ptr, min(sizeof(struct xfs_icreate_log), len));
        icl = &icl_buf;
        *ptr += len;
 
@@ -751,15 +747,15 @@ xlog_print_lseek(struct xlog *log, int fd, xfs_daddr_t blkno, int whence)
                offset = BBTOOFF64(blkno+log->l_logBBstart);
        else
                offset = BBTOOFF64(blkno);
-       if (lseek64(fd, offset, whence) < 0) {
-               fprintf(stderr, _("%s: lseek64 to %lld failed: %s\n"),
+       if (lseek(fd, offset, whence) < 0) {
+               fprintf(stderr, _("%s: lseek to %lld failed: %s\n"),
                        progname, (long long)offset, strerror(errno));
                exit(1);
        }
 }      /* xlog_print_lseek */
 
 
-void
+static void
 print_lsn(char         *string,
          __be64        *lsn)
 {
@@ -768,7 +764,7 @@ print_lsn(char              *string,
 }
 
 
-int
+static int
 xlog_print_record(
        struct xlog             *log,
        int                     fd,
@@ -1023,7 +1019,7 @@ xlog_print_record(
 }      /* xlog_print_record */
 
 
-int
+static int
 xlog_print_rec_head(xlog_rec_header_t *head, int *len, int bad_hdr_warn)
 {
     int i;
@@ -1065,7 +1061,7 @@ xlog_print_rec_head(xlog_rec_header_t *head, int *len, int bad_hdr_warn)
 
     if (print_overwrite) {
        printf(_("cycle num overwrites: "));
-       for (i=0; i< MIN(bbs, XLOG_HEADER_CYCLE_SIZE / BBSIZE); i++)
+       for (i=0; i< min(bbs, XLOG_HEADER_CYCLE_SIZE / BBSIZE); i++)
            printf("%d - 0x%x  ",
                    i,
                    be32_to_cpu(head->h_cycle_data[i]));
@@ -1097,7 +1093,7 @@ xlog_print_rec_head(xlog_rec_header_t *head, int *len, int bad_hdr_warn)
     return(be32_to_cpu(head->h_num_logops));
 }      /* xlog_print_rec_head */
 
-void
+static void
 xlog_print_rec_xhead(xlog_rec_ext_header_t *head, int coverage)
 {
     int i;
@@ -1137,7 +1133,7 @@ print_xlog_bad_header(xfs_daddr_t blkno, char *buf)
            xlog_exit("Bad log record header");
 }      /* print_xlog_bad_header */
 
-void
+static void
 print_xlog_bad_data(xfs_daddr_t blkno)
 {
        print_stars();
@@ -1469,48 +1465,32 @@ end:
 }
 
 /*
- * if necessary, convert an xfs_inode_log_format struct from 32bit or 64 bit versions
- * (which can have different field alignments) to the native version
+ * if necessary, convert an xfs_inode_log_format struct from the old 32bit version
+ * (which can have different field alignments) to the native 64 bit version
  */
-xfs_inode_log_format_t *
-xfs_inode_item_format_convert(char *src_buf, uint len, xfs_inode_log_format_t *in_f)
+struct xfs_inode_log_format *
+xfs_inode_item_format_convert(char *src_buf, uint len, struct xfs_inode_log_format *in_f)
 {
+       struct xfs_inode_log_format_32  *in_f32;
+
        /* if we have native format then just return buf without copying data */
-       if (len == sizeof(xfs_inode_log_format_t)) {
-               return (xfs_inode_log_format_t *)src_buf;
+       if (len == sizeof(struct xfs_inode_log_format)) {
+               return (struct xfs_inode_log_format *)src_buf;
        }
 
-       if (len == sizeof(xfs_inode_log_format_32_t)) {
-               xfs_inode_log_format_32_t *in_f32;
-
-               in_f32 = (xfs_inode_log_format_32_t *)src_buf;
-               in_f->ilf_type = in_f32->ilf_type;
-               in_f->ilf_size = in_f32->ilf_size;
-               in_f->ilf_fields = in_f32->ilf_fields;
-               in_f->ilf_asize = in_f32->ilf_asize;
-               in_f->ilf_dsize = in_f32->ilf_dsize;
-               in_f->ilf_ino = in_f32->ilf_ino;
-               /* copy biggest */
-               memcpy(&in_f->ilf_u.ilfu_uuid, &in_f32->ilf_u.ilfu_uuid, sizeof(uuid_t));
-               in_f->ilf_blkno = in_f32->ilf_blkno;
-               in_f->ilf_len = in_f32->ilf_len;
-               in_f->ilf_boffset = in_f32->ilf_boffset;
-       } else {
-               xfs_inode_log_format_64_t *in_f64;
-
-               ASSERT(len == sizeof(xfs_inode_log_format_64_t));
-               in_f64 = (xfs_inode_log_format_64_t *)src_buf;
-               in_f->ilf_type = in_f64->ilf_type;
-               in_f->ilf_size = in_f64->ilf_size;
-               in_f->ilf_fields = in_f64->ilf_fields;
-               in_f->ilf_asize = in_f64->ilf_asize;
-               in_f->ilf_dsize = in_f64->ilf_dsize;
-               in_f->ilf_ino = in_f64->ilf_ino;
-               /* copy biggest */
-               memcpy(&in_f->ilf_u.ilfu_uuid, &in_f64->ilf_u.ilfu_uuid, sizeof(uuid_t));
-               in_f->ilf_blkno = in_f64->ilf_blkno;
-               in_f->ilf_len = in_f64->ilf_len;
-               in_f->ilf_boffset = in_f64->ilf_boffset;
-       }
+       in_f32 = (struct xfs_inode_log_format_32 *)src_buf;
+       in_f->ilf_type = in_f32->ilf_type;
+       in_f->ilf_size = in_f32->ilf_size;
+       in_f->ilf_fields = in_f32->ilf_fields;
+       in_f->ilf_asize = in_f32->ilf_asize;
+       in_f->ilf_dsize = in_f32->ilf_dsize;
+       in_f->ilf_ino = in_f32->ilf_ino;
+       /* copy biggest field of ilf_u */
+       memcpy(&in_f->ilf_u.__pad, &in_f32->ilf_u.__pad,
+                                       sizeof(in_f->ilf_u.__pad));
+       in_f->ilf_blkno = in_f32->ilf_blkno;
+       in_f->ilf_len = in_f32->ilf_len;
+       in_f->ilf_boffset = in_f32->ilf_boffset;
+
        return in_f;
 }