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
@@ -523,7 +523,7 @@ void do_one_corruption_in_one_block(reiserfs_filsys_t *fs,
|
||||
"not so many unfm ptrs in it\n");
|
||||
return;
|
||||
}
|
||||
d32_put((__u32 *) ih_item_body(bh, ih), pos_in_item,
|
||||
d32_put((__le32 *) ih_item_body(bh, ih), pos_in_item,
|
||||
get_sb_block_count(fs->fs_ondisk_sb) + 100);
|
||||
break;
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ static void print_disk_tree(reiserfs_filsys_t *fs, unsigned long block_nr)
|
||||
count = leaf_item_number_estimate(bh);
|
||||
for (i = 0; i < count; i++, ih++) {
|
||||
if (is_indirect_ih(ih)) {
|
||||
__u32 *ind_item = (__u32 *) ih_item_body(bh, ih);
|
||||
__le32 *ind_item = (__le32 *) ih_item_body(bh, ih);
|
||||
|
||||
for (j = 0; j < (int)I_UNFM_NUM(ih); j++) {
|
||||
if (d32_get(ind_item, j)) {
|
||||
@@ -571,11 +571,11 @@ static void callback_badblock_print(reiserfs_filsys_t *fs,
|
||||
{
|
||||
struct item_head *tmp_ih;
|
||||
FILE *fd = (FILE *) data;
|
||||
__u32 *ind_item;
|
||||
__le32 *ind_item;
|
||||
__u32 i;
|
||||
|
||||
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++)
|
||||
fprintf(fd, "%u\n", d32_get(ind_item, i));
|
||||
|
||||
@@ -134,21 +134,21 @@ struct packed_dir_entry {
|
||||
|
||||
#define fread_le16(pv)\
|
||||
{\
|
||||
__u16 tmp; \
|
||||
__le16 tmp; \
|
||||
fread16(&tmp); \
|
||||
*pv = le16_to_cpu(tmp); \
|
||||
}
|
||||
|
||||
#define fread_le32(pv)\
|
||||
{\
|
||||
__u32 tmp; \
|
||||
__le32 tmp; \
|
||||
fread32(&tmp); \
|
||||
*pv = le32_to_cpu(tmp); \
|
||||
}
|
||||
|
||||
#define fread_le64(pv)\
|
||||
{\
|
||||
__u64 tmp; \
|
||||
__le64 tmp; \
|
||||
fread64(&tmp); \
|
||||
*pv = le64_to_cpu(tmp); \
|
||||
}
|
||||
@@ -160,19 +160,19 @@ struct packed_dir_entry {
|
||||
|
||||
#define fwrite_le16(pv)\
|
||||
{\
|
||||
__u16 tmp = cpu_to_le16(*(pv));\
|
||||
__le16 tmp = cpu_to_le16(*(pv));\
|
||||
fwrite16(&tmp);\
|
||||
}
|
||||
|
||||
#define fwrite_le32(pv)\
|
||||
{\
|
||||
__u32 tmp = cpu_to_le32(*(pv));\
|
||||
__le32 tmp = cpu_to_le32(*(pv));\
|
||||
fwrite32(&tmp);\
|
||||
}
|
||||
|
||||
#define fwrite_le64(pv)\
|
||||
{\
|
||||
__u64 tmp = cpu_to_le64(*(pv));\
|
||||
__le64 tmp = cpu_to_le64(*(pv));\
|
||||
fwrite64(&tmp);\
|
||||
}
|
||||
|
||||
|
||||
@@ -100,14 +100,14 @@ static void pack_direct(struct packed_item *pi, struct buffer_head *bh,
|
||||
|
||||
if (get_pi_mask(pi) & SAFE_LINK)
|
||||
set_key_dirid(&ih->ih_key,
|
||||
d32_get((__u32 *) ih_item_body(bh, ih), 0));
|
||||
d32_get((__le32 *) ih_item_body(bh, ih), 0));
|
||||
|
||||
/* send key components which are to be sent */
|
||||
pack_ih(pi, ih);
|
||||
}
|
||||
|
||||
/* if there is at least one extent longer than 2 - it is worth packing */
|
||||
static int should_pack_indirect(__u32 * ind_item, int unfm_num)
|
||||
static int should_pack_indirect(__le32 * ind_item, int unfm_num)
|
||||
{
|
||||
int i, len;
|
||||
|
||||
@@ -132,13 +132,13 @@ static void pack_indirect(struct packed_item *pi, struct buffer_head *bh,
|
||||
struct item_head *ih)
|
||||
{
|
||||
unsigned int i;
|
||||
__u32 *ind_item;
|
||||
__le32 *ind_item;
|
||||
__u16 len;
|
||||
|
||||
if (get_ih_entry_count(ih))
|
||||
set_pi_mask(pi, get_pi_mask(pi) | IH_FREE_SPACE);
|
||||
|
||||
ind_item = (__u32 *) ih_item_body(bh, ih);
|
||||
ind_item = (__le32 *) ih_item_body(bh, ih);
|
||||
if (!should_pack_indirect(ind_item, I_UNFM_NUM(ih)))
|
||||
set_pi_mask(pi, get_pi_mask(pi) | WHOLE_INDIRECT);
|
||||
|
||||
@@ -275,8 +275,8 @@ static void pack_stat_data(struct packed_item *pi, struct buffer_head *bh,
|
||||
*/
|
||||
struct stat_data *sd;
|
||||
/* these will maintain disk-order values */
|
||||
__u16 nlink16;
|
||||
__u32 nlink32, size32;
|
||||
__le16 nlink16;
|
||||
__le32 nlink32, size32;
|
||||
__u64 size64;
|
||||
|
||||
sd = (struct stat_data *)ih_item_body(bh, ih);
|
||||
|
||||
@@ -81,7 +81,7 @@ void do_recover(reiserfs_filsys_t fs)
|
||||
|
||||
ih = item_head(bh, 0);
|
||||
for (i = 0; i < node_item_number(bh); i++, ih++) {
|
||||
__u32 *indirect;
|
||||
__le32 *indirect;
|
||||
struct buffer_head *tmp_bh;
|
||||
|
||||
if (!is_indirect_ih(ih)
|
||||
@@ -385,7 +385,7 @@ static void recover_items(FILE * fp, reiserfs_filsys_t *fs, FILE * target_file)
|
||||
} else if (is_indirect_ih(ih)) {
|
||||
for (j = 0; j < I_UNFM_NUM(ih); j++) {
|
||||
unfm_ptr =
|
||||
d32_get((__u32 *) ih_item_body(bh, ih), j);
|
||||
d32_get((__le32 *) ih_item_body(bh, ih), j);
|
||||
if (!unfm_ptr) {
|
||||
fseek(target_file, fs->fs_blocksize,
|
||||
SEEK_CUR);
|
||||
|
||||
@@ -220,7 +220,7 @@ static void unpack_stat_data(struct packed_item *pi, struct buffer_head *bh,
|
||||
static void unpack_indirect(struct packed_item *pi, struct buffer_head *bh,
|
||||
struct item_head *ih)
|
||||
{
|
||||
__u32 *ind_item, *end;
|
||||
__le32 *ind_item, *end;
|
||||
int i;
|
||||
__u16 v16;
|
||||
|
||||
@@ -229,7 +229,7 @@ static void unpack_indirect(struct packed_item *pi, struct buffer_head *bh,
|
||||
set_ih_entry_count(ih, 0);
|
||||
}
|
||||
|
||||
ind_item = (__u32 *) ih_item_body(bh, ih);
|
||||
ind_item = (__le32 *) ih_item_body(bh, ih);
|
||||
|
||||
if (get_pi_mask(pi) & SAFE_LINK) {
|
||||
d32_put(ind_item, 0, get_key_dirid(&ih->ih_key));
|
||||
@@ -263,7 +263,7 @@ static void unpack_indirect(struct packed_item *pi, struct buffer_head *bh,
|
||||
static void unpack_direct(struct packed_item *pi, struct buffer_head *bh,
|
||||
struct item_head *ih)
|
||||
{
|
||||
__u32 *d_item = (__u32 *) ih_item_body(bh, ih);
|
||||
__le32 *d_item = (__le32 *) ih_item_body(bh, ih);
|
||||
|
||||
if (!(get_pi_mask(pi) & IH_FREE_SPACE))
|
||||
/* ih_free_space was not packed - set default */
|
||||
@@ -285,8 +285,8 @@ static void unpack_leaf(int dev, hashf_t hash_func, __u16 blocksize)
|
||||
struct packed_item pi;
|
||||
struct item_head *ih;
|
||||
int i;
|
||||
__u16 v16;
|
||||
__u32 v32;
|
||||
__le16 v16;
|
||||
__le32 v32;
|
||||
|
||||
/* block number */
|
||||
fread_le32(&v32);
|
||||
@@ -489,7 +489,7 @@ void unpack_partition(int fd, int jfd)
|
||||
{
|
||||
__u32 magic32;
|
||||
long position;
|
||||
__u16 magic16;
|
||||
__le16 magic16;
|
||||
__u16 blocksize;
|
||||
int dev = fd;
|
||||
|
||||
|
||||
Reference in new issue
Block a user