#!/bin/sh
# Creates ext2_meth.h
# I wrote this because the C preprocessor isn't powerful enough to do it.
# "Rerolling the loop" in this way should make it easier (?) and safer
# to edit.
#

SCRIPTNAME=ext2_meth.sh
DEST=ext2_meth.h

cat > "$DEST" <<EOT
/*
 * This file automatically generated by ${SCRIPTNAME}.
 * To make changes, either change ${SCRIPTNAME} and rerun it,
 * or make the changes to this file and delete ${SCRIPTNAME}.
 */

#include <ext2fs/ext2_fs.h>

extern unsigned meth_name2id(char const *);
extern char const *meth_id2name(unsigned);

/* 
 * The ext2fs library private definition of the ext2 compression method names,
 * so we don't have to depend on the kernel's definition of them.
 * The idea is to provide a consistent compilation environment.
 */

#define EXT2FS_LZV1_METH 0
#define EXT2FS_AUTO_METH 1
#define EXT2FS_DEFER_METH 2
#define EXT2FS_NONE_METH EXT2_DEFER_METH
#define EXT2FS_NEVER_METH 3
#define EXT2FS_BZIP2_METH 4
#define EXT2FS_LZRW3A_METH 8
#define EXT2FS_LZO1X_1_METH 0x0a
#define EXT2FS_GZIP_1_METH 0x10
#define EXT2FS_GZIP_2_METH 0x11
#define EXT2FS_GZIP_3_METH 0x12
#define EXT2FS_GZIP_4_METH 0x13
#define EXT2FS_GZIP_5_METH 0x14
#define EXT2FS_GZIP_6_METH 0x15
#define EXT2FS_GZIP_7_METH 0x16
#define EXT2FS_GZIP_8_METH 0x17
#define EXT2FS_GZIP_9_METH 0x18

/*
 * Check for incompatibilities. 
 */
EOT
for i in AUTO NEVER DEFER LZO1X_1 LZV1 LZRW3A BZIP2 \
  GZIP_1 GZIP_2 GZIP_3 GZIP_4 GZIP_5 GZIP_6 GZIP_7 GZIP_8 GZIP_9
do
cat >> "$DEST" <<EOT

#ifdef EXT2_${i}_METH
# if EXT2_${i}_METH != EXT2FS_${i}_METH
#  error "This kernel using a non-standard value of EXT2_${i}_METH"
# endif
#endif
EOT
done
