fstests: Replace all __[u]intNN_t types with standard [u]intNN_t
[xfstests-dev.git] / src / loggen.c
index ca3c1ac9a95861bde72c6c06db5eb05a39478cb8..ed1ebbccc8baa0f8c84f8806225fd2ce4f3ae796 100644 (file)
@@ -1,33 +1,19 @@
 /*
- * Copyright (c) 2000-2003 Silicon Graphics, Inc.  All Rights Reserved.
+ * Copyright (c) 2000-2003 Silicon Graphics, Inc.
+ * All Rights Reserved.
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
+ * 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.
+ * 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.
  *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like.  Any license provided herein, whether implied or
- * otherwise, applies only to this software file.  Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc., 59
- * Temple Place - Suite 330, Boston MA 02111-1307, USA.
- *
- * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
- * Mountain View, CA  94043, or:
- *
- * http://www.sgi.com
- *
- * For further information regarding this notice, see:
- *
- * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
+ * 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
  */
  
 /*
  *                                                  - dxm 29/09/00
  */
 
+#include <config.h>
+
 #include <xfs/libxfs.h>
+#ifdef HAVE_XFS_XFS_LOG_FORMAT_H
+#include <xfs/xfs_log_format.h>
+#define XFS_TRANS_MAGIC        XFS_TRANS_HEADER_MAGIC
+#else /* HAVE_XFS_XFS_LOG_FORMAT_H */
 #include <xfs/xfs_log.h>
 #include <xfs/xfs_log_priv.h>
+#endif /* HAVE_XFS_XFS_LOG_FORMAT_H */
+
+#ifndef ASSIGN_ANY_LSN_DISK
+#define ASSIGN_ANY_LSN_DISK(lsn,cycle,block)  \
+    { \
+       INT_SET(((uint *)&(lsn))[0], ARCH_CONVERT, (cycle)); \
+       INT_SET(((uint *)&(lsn))[1], ARCH_CONVERT, (block)); \
+    }
+#endif
 
 void
 usage(void)
@@ -118,9 +119,9 @@ loggen_unmount(int count)
     xlog_op_header_t        *op;
     /* the data section must be 32 bit size aligned */
     struct {
-        __uint16_t magic;
-        __uint16_t pad1;
-        __uint32_t pad2; /* may as well make it 64 bits */
+        uint16_t magic;
+        uint16_t pad1;
+        uint32_t pad2; /* may as well make it 64 bits */
     } magic = { XLOG_UNMOUNT_TYPE, 0, 0 };
     
     if (!count) count=1;
@@ -136,35 +137,33 @@ loggen_unmount(int count)
      * way things end up on disk.
      */
 
-    INT_SET(head->h_magicno,        ARCH_CONVERT, XLOG_HEADER_MAGIC_NUM);
-    INT_SET(head->h_cycle,          ARCH_CONVERT, param_cycle);
-    INT_SET(head->h_version,        ARCH_CONVERT, 1);
-    INT_SET(head->h_len,            ARCH_CONVERT, 20);
-    INT_SET(head->h_chksum,         ARCH_CONVERT, 0);
-    INT_SET(head->h_prev_block,     ARCH_CONVERT, -1);
-    INT_SET(head->h_num_logops,     ARCH_CONVERT, 1);
-    INT_SET(head->h_cycle_data[0],  ARCH_CONVERT, 0xb0c0d0d0);
-    INT_SET(head->h_fmt,            ARCH_CONVERT, param_fmt);
-    
-    ASSIGN_ANY_LSN(head->h_tail_lsn,    
-            param_tail_cycle, param_tail_block, ARCH_CONVERT);
+    head->h_magicno = cpu_to_be32(XLOG_HEADER_MAGIC_NUM);
+    head->h_cycle = cpu_to_be32(param_cycle);
+    head->h_version = cpu_to_be32(1);
+    head->h_len = cpu_to_be32(20);
+    head->h_prev_block = cpu_to_be32(-1);
+    head->h_num_logops = cpu_to_be32(1);
+    head->h_cycle_data[0] = cpu_to_be32(0xb0c0d0d0);
+    head->h_fmt = cpu_to_be32(param_fmt);
+
+    head->h_tail_lsn = cpu_to_be64(xlog_assign_lsn(param_tail_cycle,
+                                                       param_tail_block));
 
     memcpy(head->h_fs_uuid,  param_uuid, sizeof(uuid_t));
 
     /* now a log unmount op */
-    INT_SET(op->oh_tid,             ARCH_CONVERT, param_cycle);
-    INT_SET(op->oh_len,             ARCH_CONVERT, sizeof(magic));
-    INT_SET(op->oh_clientid,        ARCH_CONVERT, XFS_LOG);
-    INT_SET(op->oh_flags,           ARCH_CONVERT, XLOG_UNMOUNT_TRANS);
-    INT_SET(op->oh_res2,            ARCH_CONVERT, 0);
+    op->oh_tid = cpu_to_be32(param_cycle);
+    op->oh_len = cpu_to_be32(sizeof(magic));
+    op->oh_clientid = XFS_LOG;
+    op->oh_flags = XLOG_UNMOUNT_TRANS;
+    op->oh_res2 = cpu_to_be16(0);
 
     /* and the data for this op */
 
     memcpy(op+1, &magic, sizeof(magic));
     
     while (count--) {
-        ASSIGN_ANY_LSN(head->h_lsn,         
-                param_cycle, param_block++, ARCH_CONVERT);
+       head->h_lsn = cpu_to_be64(xlog_assign_lsn(param_cycle, param_block++));
         
         loggen_write();
     }
@@ -176,6 +175,7 @@ loggen_empty(int count)
     xlog_rec_header_t       *head;
     xlog_op_header_t        *op1, *op2, *op3, *op4, *op5;
     xfs_trans_header_t      *trans;
+    xfs_buf_log_format_t    blfs;
     xfs_buf_log_format_t    *blf;
     int                     *data;
     char                    *p;
@@ -201,72 +201,76 @@ loggen_empty(int count)
      * way things end up on disk.
      */
 
-    INT_SET(head->h_magicno,        ARCH_CONVERT, XLOG_HEADER_MAGIC_NUM);
-    INT_SET(head->h_cycle,          ARCH_CONVERT, param_cycle);
-    INT_SET(head->h_version,        ARCH_CONVERT, 1);
-    INT_SET(head->h_len,            ARCH_CONVERT, 5*sizeof(xlog_op_header_t) +
+    head->h_magicno        = cpu_to_be32(XLOG_HEADER_MAGIC_NUM);
+    head->h_cycle          = cpu_to_be32(param_cycle);
+    head->h_version        = cpu_to_be32(1);
+    head->h_len            = cpu_to_be32(5*sizeof(xlog_op_header_t) +
                                                     sizeof(xfs_trans_header_t)+
                                                     sizeof(xfs_buf_log_format_t)+
                                                     sizeof(int));
-    INT_SET(head->h_chksum,         ARCH_CONVERT, 0);
-    INT_SET(head->h_prev_block,     ARCH_CONVERT, -1);
-    INT_SET(head->h_num_logops,     ARCH_CONVERT, 5);
-    INT_SET(head->h_cycle_data[0],  ARCH_CONVERT, 0xb0c0d0d0);
-    INT_SET(head->h_fmt,            ARCH_CONVERT, param_fmt);
+    head->h_prev_block     = cpu_to_be32(-1);
+    head->h_num_logops     = cpu_to_be32(5);
+    head->h_cycle_data[0]  = cpu_to_be32(0xb0c0d0d0);
+    head->h_fmt            = cpu_to_be32(param_fmt);
     
-    ASSIGN_ANY_LSN(head->h_tail_lsn,    
-            param_tail_cycle, param_tail_block, ARCH_CONVERT);
+    head->h_tail_lsn = cpu_to_be64(xlog_assign_lsn(param_tail_cycle,
+                                                       param_tail_block));
 
-    memcpy(head->h_fs_uuid,  param_uuid, sizeof(uuid_t));
+    memcpy(head->h_fs_uuid, param_uuid, sizeof(uuid_t));
 
     /* start */
-    INT_SET(op1->oh_tid,            ARCH_CONVERT, 1);
-    INT_SET(op1->oh_len,            ARCH_CONVERT, 0);
-    INT_SET(op1->oh_clientid,       ARCH_CONVERT, XFS_TRANSACTION);
-    INT_SET(op1->oh_flags,          ARCH_CONVERT, XLOG_START_TRANS);
-    INT_SET(op1->oh_res2,           ARCH_CONVERT, 0);
+    op1->oh_tid            = cpu_to_be32(1);
+    op1->oh_len            = cpu_to_be32(0);
+    op1->oh_clientid       = XFS_TRANSACTION;
+    op1->oh_flags          = XLOG_START_TRANS;
+    op1->oh_res2           = cpu_to_be16(0);
     /* dummy */
-    INT_SET(op2->oh_tid,            ARCH_CONVERT, 0xb0c0d0d0);
-    INT_SET(op2->oh_len,            ARCH_CONVERT, sizeof(xfs_trans_header_t));
-    INT_SET(op2->oh_clientid,       ARCH_CONVERT, XFS_TRANSACTION);
-    INT_SET(op2->oh_flags,          ARCH_CONVERT, 0);
-    INT_SET(op2->oh_res2,           ARCH_CONVERT, 0);
+    op2->oh_tid            = cpu_to_be32(0xb0c0d0d0);
+    op2->oh_len            = cpu_to_be32(sizeof(xfs_trans_header_t));
+    op2->oh_clientid       = XFS_TRANSACTION;
+    op2->oh_flags          = 0;
+    op2->oh_res2           = cpu_to_be16(0);
     /* dummy transaction - this stuff doesn't get endian converted */
     trans->th_magic     = XFS_TRANS_MAGIC;
     trans->th_type      = XFS_TRANS_DUMMY1;
     trans->th_tid       = 0;
     trans->th_num_items = 1;
     /* buffer */
-    INT_SET(op3->oh_tid,            ARCH_CONVERT, 0xb0c0d0d0);
-    INT_SET(op3->oh_len,            ARCH_CONVERT, sizeof(xfs_buf_log_format_t));
-    INT_SET(op3->oh_clientid,       ARCH_CONVERT, XFS_TRANSACTION);
-    INT_SET(op3->oh_flags,          ARCH_CONVERT, 0);
-    INT_SET(op3->oh_res2,           ARCH_CONVERT, 0);
+    op3->oh_tid            = cpu_to_be32(0xb0c0d0d0);
+    op3->oh_len            = cpu_to_be32(sizeof(xfs_buf_log_format_t));
+    op3->oh_clientid       = XFS_TRANSACTION;
+    op3->oh_flags          = 0;
+    op3->oh_res2           = cpu_to_be16(0);
     /* an empty buffer too */
-    blf->blf_type       = XFS_LI_BUF;
-    blf->blf_size       = 2;
-    blf->blf_flags      = XFS_BLI_CANCEL;
-    blf->blf_blkno      = 1;
-    blf->blf_map_size   = 1;
-    blf->blf_data_map[0]= 0;
+    blfs.blf_type       = XFS_LI_BUF;
+    blfs.blf_size       = 2;
+#ifdef XFS_BLF_CANCEL
+    blfs.blf_flags      = XFS_BLF_CANCEL;
+#else
+    blfs.blf_flags      = XFS_BLI_CANCEL;
+#endif
+    blfs.blf_len        = 0;
+    blfs.blf_blkno      = 1;
+    blfs.blf_map_size   = 1;
+    blfs.blf_data_map[0]= 0;
+    memcpy(blf, &blfs, sizeof(blfs));
     /* commit */
-    INT_SET(op4->oh_tid,            ARCH_CONVERT, 0xb0c0d0d0);
-    INT_SET(op4->oh_len,            ARCH_CONVERT, sizeof(int));
-    INT_SET(op4->oh_clientid,       ARCH_CONVERT, XFS_TRANSACTION);
-    INT_SET(op4->oh_flags,          ARCH_CONVERT, 0);
-    INT_SET(op4->oh_res2,           ARCH_CONVERT, 0);
+    op4->oh_tid            = cpu_to_be32(0xb0c0d0d0);
+    op4->oh_len            = cpu_to_be32(sizeof(int));
+    op4->oh_clientid       = XFS_TRANSACTION;
+    op4->oh_flags          = 0;
+    op4->oh_res2           = cpu_to_be16(0);
     /* and the data */
     *data=*(int*)(char*)"FISH"; /* this won't get written (I hope) */
     /* commit */
-    INT_SET(op5->oh_tid,            ARCH_CONVERT, 0xb0c0d0d0);
-    INT_SET(op5->oh_len,            ARCH_CONVERT, 0);
-    INT_SET(op5->oh_clientid,       ARCH_CONVERT, XFS_TRANSACTION);
-    INT_SET(op5->oh_flags,          ARCH_CONVERT, XLOG_COMMIT_TRANS);
-    INT_SET(op5->oh_res2,           ARCH_CONVERT, 0);
+    op5->oh_tid            = cpu_to_be32(0xb0c0d0d0);
+    op5->oh_len            = cpu_to_be32(0);
+    op5->oh_clientid       = XFS_TRANSACTION;
+    op5->oh_flags          = XLOG_COMMIT_TRANS;
+    op5->oh_res2           = cpu_to_be16(0);
 
     while (count--) {
-        ASSIGN_ANY_LSN(head->h_lsn,         
-                param_cycle, param_block++, ARCH_CONVERT);
+        head->h_lsn = cpu_to_be64(xlog_assign_lsn(param_cycle, param_block++));
         
         loggen_write();
     }