summaryrefslogtreecommitdiff
path: root/ext4_utils/ext4_utils.h
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2010-06-11 14:21:37 -0700
committerColin Cross <ccross@android.com>2010-06-16 13:12:01 -0700
commitec0a2e83dc66d67addeb90e83144187691852a3e (patch)
tree6702cdbbbd9b5d6d939b6d3abb3c2b8514146550 /ext4_utils/ext4_utils.h
parent545e6ca13f744650e4a62630f1b901c0840dcd43 (diff)
downloadextras-ec0a2e83dc66d67addeb90e83144187691852a3e.tar.gz
Initial commit of ext4_utils
Change-Id: I911d5b7fd7170ec81d544850717d8e69976e272b
Diffstat (limited to 'ext4_utils/ext4_utils.h')
-rw-r--r--ext4_utils/ext4_utils.h116
1 files changed, 116 insertions, 0 deletions
diff --git a/ext4_utils/ext4_utils.h b/ext4_utils/ext4_utils.h
new file mode 100644
index 00000000..40c0676b
--- /dev/null
+++ b/ext4_utils/ext4_utils.h
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _EXT4_UTILS_H_
+#define _EXT4_UTILS_H_
+
+#include <sys/types.h>
+#include <errno.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+extern int force;
+
+#define warn(fmt, args...) do { fprintf(stderr, "warning: %s: " fmt "\n", __func__, ## args); } while (0)
+#define error(fmt, args...) do { fprintf(stderr, "error: %s: " fmt "\n", __func__, ## args); if (!force) exit(EXIT_FAILURE); } while (0)
+#define error_errno(s) error(s ": %s", strerror(errno))
+#define critical_error(fmt, args...) do { fprintf(stderr, "critical error: %s: " fmt "\n", __func__, ## args); exit(EXIT_FAILURE); } while (0)
+#define critical_error_errno(s) critical_error(s ": %s", strerror(errno))
+
+#define EXT4_SUPER_MAGIC 0xEF53
+#define EXT4_JNL_BACKUP_BLOCKS 1
+
+#define min(a, b) ((a) < (b) ? (a) : (b))
+
+#define DIV_ROUND_UP(x, y) (((x) + (y) - 1)/(y))
+
+#define __le64 u64
+#define __le32 u32
+#define __le16 u16
+
+#define __be64 u64
+#define __be32 u32
+#define __be16 u16
+
+#define __u64 u64
+#define __u32 u32
+#define __u16 u16
+#define __u8 u8
+
+typedef unsigned long long u64;
+typedef unsigned int u32;
+typedef unsigned short int u16;
+typedef unsigned char u8;
+
+struct block_group_info;
+
+struct ext2_group_desc {
+ __le32 bg_block_bitmap;
+ __le32 bg_inode_bitmap;
+ __le32 bg_inode_table;
+ __le16 bg_free_blocks_count;
+ __le16 bg_free_inodes_count;
+ __le16 bg_used_dirs_count;
+ __le16 bg_pad;
+ __le32 bg_reserved[3];
+};
+
+struct fs_info {
+ u64 len;
+ u32 block_size;
+ u32 blocks_per_group;
+ u32 inodes_per_group;
+ u32 inode_size;
+ u32 inodes;
+ u32 journal_blocks;
+ u16 feat_ro_compat;
+ u16 feat_compat;
+ u16 feat_incompat;
+ const char *label;
+};
+
+struct fs_aux_info {
+ struct ext4_super_block *sb;
+ struct ext2_group_desc *bg_desc;
+ struct block_group_info *bgs;
+ u32 first_data_block;
+ u64 len_blocks;
+ u32 inode_table_blocks;
+ u32 groups;
+ u32 bg_desc_blocks;
+ u32 bg_desc_reserve_blocks;
+ u32 default_i_flags;
+ u32 blocks_per_ind;
+ u32 blocks_per_dind;
+ u32 blocks_per_tind;
+};
+
+extern struct fs_info info;
+extern struct fs_aux_info aux_info;
+
+static inline int log_2(int j)
+{
+ int i;
+
+ for (i = 0; j > 0; i++)
+ j >>= 1;
+
+ return i - 1;
+}
+
+#endif