1  /* PR rtl-optimization/45593 */
       2  /* Testcase by Arnaud Lacombe <lacombar@gmail.com> */
       3  
       4  typedef unsigned int __u32;
       5  typedef __u32 __be32;
       6  static inline __attribute__((always_inline)) int __attribute__((__cold__)) printk(const char *s, ...) { return 0; }
       7  typedef struct journal_s journal_t;
       8  typedef struct journal_header_s
       9  {
      10   __be32 h_magic;
      11   __be32 h_blocktype;
      12   __be32 h_sequence;
      13  } journal_header_t;
      14  typedef struct journal_superblock_s
      15  {
      16   journal_header_t s_header;
      17   __be32 s_blocksize;
      18   __be32 s_maxlen;
      19  } journal_superblock_t;
      20  struct journal_s
      21  {
      22   struct buffer_head *j_sb_buffer;
      23   journal_superblock_t *j_superblock;
      24   int j_format_version;
      25   int j_blocksize;
      26   unsigned int j_maxlen;
      27  };
      28  static void journal_fail_superblock (journal_t *journal)
      29  {
      30   journal->j_sb_buffer = ((void *)0);
      31  }
      32  static int journal_get_superblock(journal_t *journal)
      33  {
      34   struct buffer_head *bh;
      35   journal_superblock_t *sb;
      36   int err = -100;
      37   bh = journal->j_sb_buffer;
      38   if (!buffer_uptodate(bh)) {
      39    if (!buffer_uptodate(bh)) {
      40     printk ("JBD: IO error reading journal superblock\n");
      41     goto out;
      42    }
      43   }
      44   err = -101;
      45   if (sb->s_header.h_magic != (( __be32)(__u32)(0)) ||
      46       sb->s_blocksize != (( __be32)(__u32)(journal->j_blocksize))) {
      47    printk("JBD: no valid journal superblock found\n");
      48    goto out;
      49   }
      50   switch((( __u32)(__be32)(sb->s_header.h_blocktype))) {
      51   case 0:
      52   case 1:
      53    break;
      54   default:
      55    goto out;
      56   }
      57   if ((( __u32)(__be32)(sb->s_maxlen)) < journal->j_maxlen)
      58    journal->j_maxlen = (( __u32)(__be32)(sb->s_maxlen));
      59   else if ((( __u32)(__be32)(sb->s_maxlen)) > journal->j_maxlen) {
      60    printk ("JBD: journal file too short\n");
      61    goto out;
      62   }
      63   return 0;
      64  out:
      65   journal_fail_superblock(journal);
      66   return err;
      67  }
      68  static int load_superblock(journal_t *journal)
      69  {
      70   journal_get_superblock(journal);
      71   return 0;
      72  }
      73  int jbd2_journal_update_format (journal_t *journal)
      74  {
      75   journal_get_superblock(journal);
      76   return 0;
      77  }
      78  int jbd2_journal_wipe(journal_t *journal, int write)
      79  {
      80   load_superblock(journal);
      81   return 0;
      82  }