reiserfsprogs: annotate for endian safeness
By annotating structure members and other on-disk structures as little endian, we can catch bugs more easily. The code was already endian safe except for three minor spots: 1) The badblock list code was initializing its key in an endian-unsafe way. 2) Indirect block pointer sequence printing was treating cpu-order values as little endian. 3) reiserfsck was trying to do endian switching on the lost+found key, but it was before it was even initialized to anything, so we can just remove that completely. These issues were fixed as part of this commit. Signed-off-by: Jeff Mahoney <jeffm@suse.com>
This commit is contained in:
1 parent
767f7b85df
commit
81aeadf510
26 files changed
+241
-220
No files matched your search
@@ -495,7 +495,7 @@ static int is_bad_indirect(reiserfs_filsys_t *fs, struct item_head *ih,
|
||||
char *item, check_unfm_func_t check_unfm_func)
|
||||
{
|
||||
unsigned int i;
|
||||
__u32 *ind = (__u32 *) item;
|
||||
__le32 *ind = (__le32 *) item;
|
||||
|
||||
if (get_ih_item_len(ih) % UNFM_P_SIZE)
|
||||
return 1;
|
||||
@@ -1147,8 +1147,8 @@ void get_set_sd_field(int field, struct item_head *ih, void *sd,
|
||||
|
||||
static int comp_ids(const void *p1, const void *p2)
|
||||
{
|
||||
__u32 id1 = le32_to_cpu(*(__u32 *) p1);
|
||||
__u32 id2 = le32_to_cpu(*(__u32 *) p2);
|
||||
__u32 id1 = le32_to_cpu(*(__le32 *) p1);
|
||||
__u32 id2 = le32_to_cpu(*(__le32 *) p2);
|
||||
|
||||
if (id1 < id2)
|
||||
return -1;
|
||||
@@ -1161,14 +1161,14 @@ static int comp_ids(const void *p1, const void *p2)
|
||||
|
||||
int is_objectid_used(reiserfs_filsys_t *fs, __u32 objectid)
|
||||
{
|
||||
__u32 *objectid_map;
|
||||
__le32 *objectid_map;
|
||||
__u32 count = get_sb_oid_cursize(fs->fs_ondisk_sb);
|
||||
int ret;
|
||||
__u32 pos;
|
||||
__u32 le_id = cpu_to_le32(objectid);
|
||||
__le32 le_id = cpu_to_le32(objectid);
|
||||
|
||||
objectid_map =
|
||||
(__u32 *) ((char *)fs->fs_ondisk_sb +
|
||||
(__le32 *) ((char *)fs->fs_ondisk_sb +
|
||||
reiserfs_super_block_size(fs->fs_ondisk_sb));
|
||||
|
||||
ret =
|
||||
@@ -1186,7 +1186,7 @@ int is_objectid_used(reiserfs_filsys_t *fs, __u32 objectid)
|
||||
void mark_objectid_used(reiserfs_filsys_t *fs, __u32 objectid)
|
||||
{
|
||||
int i;
|
||||
__u32 *objectid_map;
|
||||
__le32 *objectid_map;
|
||||
int cursize;
|
||||
|
||||
if (is_objectid_used(fs, objectid)) {
|
||||
@@ -1194,7 +1194,7 @@ void mark_objectid_used(reiserfs_filsys_t *fs, __u32 objectid)
|
||||
}
|
||||
|
||||
objectid_map =
|
||||
(__u32 *) ((char *)fs->fs_ondisk_sb +
|
||||
(__le32 *) ((char *)fs->fs_ondisk_sb +
|
||||
reiserfs_super_block_size(fs->fs_ondisk_sb));
|
||||
cursize = get_sb_oid_cursize(fs->fs_ondisk_sb);
|
||||
|
||||
|
||||
+10
-9
@@ -333,14 +333,14 @@ static void start_new_sequence(__u32 * start, int *len, __u32 new)
|
||||
|
||||
static int sequence_finished(__u32 start, int *len, __u32 new)
|
||||
{
|
||||
if (le32_to_cpu(start) == INT_MAX)
|
||||
if (start == INT_MAX)
|
||||
return 1;
|
||||
|
||||
if (start == 0 && new == 0) {
|
||||
(*len)++;
|
||||
return 0;
|
||||
}
|
||||
if (start != 0 && (le32_to_cpu(start) + *len) == le32_to_cpu(new)) {
|
||||
if (start != 0 && (start + *len) == new) {
|
||||
(*len)++;
|
||||
return 0;
|
||||
}
|
||||
@@ -353,20 +353,21 @@ static void print_sequence(FILE * fp, __u32 start, int len)
|
||||
return;
|
||||
|
||||
if (len == 1)
|
||||
reiserfs_warning(fp, " %u", le32_to_cpu(start));
|
||||
reiserfs_warning(fp, " %u", start);
|
||||
else
|
||||
reiserfs_warning(fp, " %u(%d)", le32_to_cpu(start), len);
|
||||
reiserfs_warning(fp, " %u(%d)", start, len);
|
||||
}
|
||||
|
||||
void print_indirect_item(FILE * fp, struct buffer_head *bh, int item_num)
|
||||
{
|
||||
struct item_head *ih;
|
||||
unsigned int j;
|
||||
__u32 *unp, prev = INT_MAX;
|
||||
__le32 *unp;
|
||||
__u32 prev = INT_MAX;
|
||||
int num = 0;
|
||||
|
||||
ih = item_head(bh, item_num);
|
||||
unp = (__u32 *) ih_item_body(bh, ih);
|
||||
unp = (__le32 *) ih_item_body(bh, ih);
|
||||
|
||||
if (get_ih_item_len(ih) % UNFM_P_SIZE)
|
||||
reiserfs_warning(fp, "print_indirect_item: invalid item len");
|
||||
@@ -1016,13 +1017,13 @@ void print_objectid_map(FILE * fp, reiserfs_filsys_t *fs)
|
||||
{
|
||||
int i;
|
||||
struct reiserfs_super_block *sb;
|
||||
__u32 *omap;
|
||||
__le32 *omap;
|
||||
|
||||
sb = fs->fs_ondisk_sb;
|
||||
if (fs->fs_format == REISERFS_FORMAT_3_6)
|
||||
omap = (__u32 *) (sb + 1);
|
||||
omap = (__le32 *) (sb + 1);
|
||||
else if (fs->fs_format == REISERFS_FORMAT_3_5)
|
||||
omap = (__u32 *) ((struct reiserfs_super_block_v1 *)sb + 1);
|
||||
omap = (__le32 *) ((struct reiserfs_super_block_v1 *)sb + 1);
|
||||
else {
|
||||
reiserfs_warning(fp,
|
||||
"print_objectid_map: proper signature is not found\n");
|
||||
|
||||
@@ -13,7 +13,8 @@ struct reiserfs_key root_dir_key = { 0, 0, {{0, 0},} };
|
||||
struct reiserfs_key parent_root_dir_key = { 0, 0, {{0, 0},} };
|
||||
struct reiserfs_key lost_found_dir_key = { 0, 0, {{0, 0},} };
|
||||
static struct reiserfs_key badblock_key =
|
||||
{ BADBLOCK_DIRID, BADBLOCK_OBJID, {{0, 0},} };
|
||||
{ cpu_to_le32(BADBLOCK_DIRID), cpu_to_le32(BADBLOCK_OBJID),
|
||||
{{cpu_to_le32(0), cpu_to_le32(0)},} };
|
||||
|
||||
__u16 root_dir_format = 0;
|
||||
__u16 lost_found_dir_format = 0;
|
||||
@@ -597,7 +598,7 @@ static int comp_dir_entries(const void *p1, const void *p2)
|
||||
{
|
||||
__u32 off1, off2;
|
||||
|
||||
off1 = d32_get((__u32 *) p1, 0);
|
||||
off1 = d32_get((__le32 *) p1, 0);
|
||||
off2 = *(__u32 *) p2;
|
||||
|
||||
if (off1 < off2)
|
||||
@@ -1412,14 +1413,14 @@ void mark_badblock(reiserfs_filsys_t *fs,
|
||||
struct reiserfs_path *badblock_path, void *data)
|
||||
{
|
||||
struct item_head *tmp_ih;
|
||||
__u32 *ind_item;
|
||||
__le32 *ind_item;
|
||||
__u32 i;
|
||||
|
||||
if (!fs->fs_badblocks_bm)
|
||||
create_badblock_bitmap(fs, NULL);
|
||||
|
||||
tmp_ih = tp_item_head(badblock_path);
|
||||
ind_item = (__u32 *) tp_item_body(badblock_path);
|
||||
ind_item = (__le32 *) tp_item_body(badblock_path);
|
||||
|
||||
for (i = 0; i < I_UNFM_NUM(tmp_ih); i++) {
|
||||
reiserfs_bitmap_set_bit(fs->fs_badblocks_bm,
|
||||
@@ -1434,7 +1435,7 @@ void add_badblock_list(reiserfs_filsys_t *fs, int replace)
|
||||
struct tree_balance tb;
|
||||
struct reiserfs_path badblock_path;
|
||||
struct item_head badblock_ih;
|
||||
__u32 ni;
|
||||
__le32 ni;
|
||||
|
||||
__u64 offset;
|
||||
__u32 i, j;
|
||||
|
||||
@@ -53,8 +53,8 @@ inline int B_IS_IN_TREE(struct buffer_head *p_s_bh)
|
||||
int comp_short_keys(const void *k1, const void *k2)
|
||||
{
|
||||
int n_key_length = REISERFS_SHORT_KEY_LEN;
|
||||
__u32 *p_s_key1 = (__u32 *) k1;
|
||||
__u32 *p_s_key2 = (__u32 *) k2;
|
||||
__le32 *p_s_key1 = (__le32 *) k1;
|
||||
__le32 *p_s_key2 = (__le32 *) k2;
|
||||
__u32 u1, u2;
|
||||
|
||||
for (; n_key_length--; ++p_s_key1, ++p_s_key2) {
|
||||
@@ -173,11 +173,14 @@ int bin_search(void *p_v_key, /* Key to search for. */
|
||||
}
|
||||
|
||||
/* Minimal possible key. It is never in the tree. */
|
||||
const struct reiserfs_key MIN_KEY = { 0, 0, {{0, 0},} };
|
||||
const struct reiserfs_key MIN_KEY =
|
||||
{ cpu_to_le32(0), cpu_to_le32(0),
|
||||
{{cpu_to_le32(0), cpu_to_le32(0)},} };
|
||||
|
||||
/* Maximal possible key. It is never in the tree. */
|
||||
const struct reiserfs_key MAX_KEY =
|
||||
{ 0xffffffff, 0xffffffff, {{0xffffffff, 0xffffffff},} };
|
||||
{ cpu_to_le32(0xffffffff), cpu_to_le32(0xffffffff),
|
||||
{{cpu_to_le32(0xffffffff), cpu_to_le32(0xffffffff)},} };
|
||||
|
||||
/* Get delimiting key of the buffer by looking for it in the buffers in the
|
||||
path, starting from the bottom of the path, and going upwards. We must
|
||||
|
||||
Reference in new issue
Block a user