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
+4
-3
@@ -388,7 +388,8 @@ static int bad_direct_item(reiserfs_filsys_t *fs,
|
||||
}
|
||||
|
||||
inline void handle_one_pointer(reiserfs_filsys_t *fs,
|
||||
struct buffer_head *bh, __u32 * item, int offset)
|
||||
struct buffer_head *bh, __le32 * item,
|
||||
int offset)
|
||||
{
|
||||
if (fsck_mode(fs) == FSCK_FIX_FIXABLE) {
|
||||
fsck_log(" - zeroed");
|
||||
@@ -403,7 +404,7 @@ static int bad_badblocks_item(reiserfs_filsys_t *fs, struct buffer_head *bh,
|
||||
struct item_head *ih)
|
||||
{
|
||||
__u32 i;
|
||||
__u32 *ind = (__u32 *) ih_item_body(bh, ih);
|
||||
__le32 *ind = (__le32 *) ih_item_body(bh, ih);
|
||||
|
||||
if (get_ih_item_len(ih) % 4) {
|
||||
fsck_log("%s: block %lu: item (%H) has bad length\n",
|
||||
@@ -477,7 +478,7 @@ static int bad_badblocks_item(reiserfs_filsys_t *fs, struct buffer_head *bh,
|
||||
static int bad_indirect_item(reiserfs_filsys_t *fs, struct buffer_head *bh,
|
||||
struct item_head *ih)
|
||||
{
|
||||
__u32 *ind = (__u32 *) ih_item_body(bh, ih);
|
||||
__le32 *ind = (__le32 *) ih_item_body(bh, ih);
|
||||
unsigned int i;
|
||||
|
||||
if (get_ih_item_len(ih) % 4) {
|
||||
|
||||
@@ -1331,10 +1331,6 @@ int main(int argc, char *argv[])
|
||||
screen_savebuffer = getmem(screen_width + 1);
|
||||
memset(screen_savebuffer, 0, screen_savebuffer_len + 1);
|
||||
|
||||
lost_found_dir_key.k2_dir_id =
|
||||
cpu_to_le32(lost_found_dir_key.k2_dir_id);
|
||||
lost_found_dir_key.k2_objectid =
|
||||
cpu_to_le32(lost_found_dir_key.k2_objectid);
|
||||
/* this is only needed (and works) when running under 2.4 on regular files */
|
||||
if (setrlimit(RLIMIT_FSIZE, &rlim) == -1) {
|
||||
reiserfs_warning(stderr,
|
||||
|
||||
+3
-3
@@ -676,7 +676,7 @@ static void pass0_correct_leaf(reiserfs_filsys_t *fs, struct buffer_head *bh)
|
||||
int file_format = KEY_FORMAT_UNDEFINED;
|
||||
struct item_head *ih;
|
||||
|
||||
__u32 *ind_item;
|
||||
__le32 *ind_item;
|
||||
__u64 fs_size;
|
||||
__u64 offset;
|
||||
int symlnk = 0;
|
||||
@@ -1607,7 +1607,7 @@ start_again:
|
||||
}
|
||||
}
|
||||
*/
|
||||
ind_item = (__u32 *) ih_item_body(bh, ih);
|
||||
ind_item = (__le32 *) ih_item_body(bh, ih);
|
||||
for (j = 0; j < (int)I_UNFM_NUM(ih); j++) {
|
||||
unfm_ptr = d32_get(ind_item, j);
|
||||
if (!unfm_ptr)
|
||||
@@ -1766,7 +1766,7 @@ static int is_bad_indirect(struct item_head *ih, char *item, int dev,
|
||||
blocks = get_sb_block_count(fs->fs_ondisk_sb);
|
||||
|
||||
for (i = 0; i < I_UNFM_NUM(ih); i++) {
|
||||
__u32 *ind = (__u32 *) item;
|
||||
__le32 *ind = (__le32 *) item;
|
||||
|
||||
if (d32_get(ind, i) >= blocks) {
|
||||
bad++;
|
||||
|
||||
+4
-4
@@ -94,11 +94,11 @@ static char *still_bad_unfm_ptr_to_string(int val)
|
||||
static void indirect_in_tree(struct buffer_head *bh, struct item_head *ih)
|
||||
{
|
||||
unsigned int i;
|
||||
__u32 *unp;
|
||||
__le32 *unp;
|
||||
__u32 unfm_ptr;
|
||||
int ret;
|
||||
|
||||
unp = (__u32 *) ih_item_body(bh, ih);
|
||||
unp = (__le32 *) ih_item_body(bh, ih);
|
||||
|
||||
for (i = 0; i < I_UNFM_NUM(ih); i++) {
|
||||
unfm_ptr = d32_get(unp, i);
|
||||
@@ -344,7 +344,7 @@ static void pass1_correct_leaf(reiserfs_filsys_t *fs, struct buffer_head *bh)
|
||||
{
|
||||
unsigned int i, j;
|
||||
struct item_head *ih;
|
||||
__u32 *ind_item;
|
||||
__le32 *ind_item;
|
||||
__u32 unfm_ptr;
|
||||
int dirty = 0;
|
||||
|
||||
@@ -423,7 +423,7 @@ static void pass1_correct_leaf(reiserfs_filsys_t *fs, struct buffer_head *bh)
|
||||
continue;
|
||||
|
||||
/* correct indirect items */
|
||||
ind_item = (__u32 *) ih_item_body(bh, ih);
|
||||
ind_item = (__le32 *) ih_item_body(bh, ih);
|
||||
|
||||
for (j = 0; j < I_UNFM_NUM(ih); j++) {
|
||||
unfm_ptr = d32_get(ind_item, j);
|
||||
|
||||
@@ -753,7 +753,7 @@ static int check_semantic_pass(struct reiserfs_key *key,
|
||||
static int check_safe_links(void)
|
||||
{
|
||||
struct reiserfs_path safe_link_path, path;
|
||||
struct reiserfs_key safe_link_key = { -1, 0, {{0, 0}} };
|
||||
struct reiserfs_key safe_link_key = { cpu_to_le32(-1), 0, {{0, 0}} };
|
||||
struct reiserfs_key key = { 0, 0, {{0, 0}} };
|
||||
struct reiserfs_key *rkey;
|
||||
struct item_head *tmp_ih;
|
||||
@@ -784,7 +784,7 @@ static int check_safe_links(void)
|
||||
get_ih_item_len(tmp_ih));
|
||||
|
||||
set_key_dirid(&key,
|
||||
d32_get((__u32 *) tp_item_body(&safe_link_path), 0));
|
||||
d32_get((__le32 *) tp_item_body(&safe_link_path), 0));
|
||||
set_key_objectid(&key, get_key_objectid(&tmp_ih->ih_key));
|
||||
if ((rkey = reiserfs_next_key(&safe_link_path)) == NULL)
|
||||
set_key_dirid(&safe_link_key, 0);
|
||||
@@ -803,7 +803,7 @@ static int check_safe_links(void)
|
||||
("Invalid safe link %k: cannot find the pointed object (%K) - "
|
||||
"safe link was deleted\n", &tmp_ih->ih_key,
|
||||
&key);
|
||||
d32_put((__u32 *) tp_item_body(&safe_link_path), 0,
|
||||
d32_put((__le32 *) tp_item_body(&safe_link_path), 0,
|
||||
0);
|
||||
pathrelse(&path);
|
||||
reiserfsck_delete_item(&safe_link_path, 0);
|
||||
@@ -825,7 +825,7 @@ static int check_safe_links(void)
|
||||
("Invalid 'truncate' safe link %k, cannot happen for "
|
||||
"a directory (%K) - safe link was deleted\n",
|
||||
&tmp_ih->ih_key, &key);
|
||||
d32_put((__u32 *)
|
||||
d32_put((__le32 *)
|
||||
tp_item_body(&safe_link_path), 0,
|
||||
0);
|
||||
pathrelse(&path);
|
||||
|
||||
+1
-1
@@ -540,7 +540,7 @@ void rebuild_sb(reiserfs_filsys_t *fs, char *filename, struct fsck_data *data)
|
||||
"generated (%U)\n", sb->s_uuid);
|
||||
}
|
||||
#endif
|
||||
if (sb->s_flags != 0 && sb->s_flags != 1) {
|
||||
if (sb->s_flags != 0 && sb->s_flags != cpu_to_le32(1)) {
|
||||
fsck_log
|
||||
("rebuild-sb: super block flags found (%u), zeroed\n",
|
||||
sb->s_flags);
|
||||
|
||||
+20
-20
@@ -57,7 +57,7 @@ static unsigned long indirect_to_direct(struct reiserfs_path *path, __u64 len,
|
||||
TYPE_DIRECT);
|
||||
|
||||
// we do not know what length this item should be
|
||||
unfm_ptr = d32_get((__u32 *) tp_item_body(path), I_UNFM_NUM(ih) - 1);
|
||||
unfm_ptr = d32_get((__le32 *) tp_item_body(path), I_UNFM_NUM(ih) - 1);
|
||||
if (unfm_ptr && (unfm_bh = bread(bh->b_dev, unfm_ptr, bh->b_size))) {
|
||||
/* we can read the block */
|
||||
buf = unfm_bh->b_data;
|
||||
@@ -375,8 +375,8 @@ int are_file_items_correct(struct item_head *sd_ih, void *sd, __u64 * size,
|
||||
else
|
||||
for (i = 0; i < I_UNFM_NUM(ih);
|
||||
i++) {
|
||||
__u32 *ind =
|
||||
(__u32 *)
|
||||
__le32 *ind =
|
||||
(__le32 *)
|
||||
tp_item_body(&path);
|
||||
|
||||
if (d32_get(ind, i) !=
|
||||
@@ -413,8 +413,8 @@ int are_file_items_correct(struct item_head *sd_ih, void *sd, __u64 * size,
|
||||
FIXABLE);
|
||||
pathrelse(&path);
|
||||
} else {
|
||||
__u32 *ind =
|
||||
(__u32 *) tp_item_body(&path);
|
||||
__le32 *ind =
|
||||
(__le32 *) tp_item_body(&path);
|
||||
/* DEBUG message.
|
||||
fsck_log ("are_file_items_correct: The indirect item is converted back to direct %K\n", &ih->ih_key);
|
||||
*/
|
||||
@@ -647,8 +647,8 @@ static int create_first_item_of_file(struct item_head *ih, char *item,
|
||||
struct reiserfs_path *path,
|
||||
int was_in_tree)
|
||||
{
|
||||
__u32 unfm_ptr;
|
||||
__u32 *ni = 0;
|
||||
__le32 unfm_ptr;
|
||||
__le32 *ni = 0;
|
||||
struct buffer_head *unbh;
|
||||
struct item_head indih;
|
||||
unsigned int i;
|
||||
@@ -743,7 +743,7 @@ static unsigned long block_to_start(struct reiserfs_path *path)
|
||||
return bh->b_blocknr;
|
||||
|
||||
ih--;
|
||||
blk = d32_get((__u32 *) ih_item_body(bh, ih), I_UNFM_NUM(ih) - 1);
|
||||
blk = d32_get((__le32 *) ih_item_body(bh, ih), I_UNFM_NUM(ih) - 1);
|
||||
return (blk ? blk : bh->b_blocknr);
|
||||
}
|
||||
|
||||
@@ -752,7 +752,7 @@ static void direct2indirect2(unsigned long unfm, struct reiserfs_path *path)
|
||||
struct item_head *ih;
|
||||
struct reiserfs_key key;
|
||||
struct buffer_head *unbh;
|
||||
__u32 ni;
|
||||
__le32 ni;
|
||||
int copied = 0;
|
||||
int file_format;
|
||||
|
||||
@@ -856,7 +856,7 @@ static int append_to_unformatted_node(struct item_head *comingih,
|
||||
int zero_number;
|
||||
|
||||
bh = PATH_PLAST_BUFFER(path);
|
||||
unfm_ptr = d32_get((__u32 *) ih_item_body(bh, ih), I_UNFM_NUM(ih) - 1);
|
||||
unfm_ptr = d32_get((__le32 *) ih_item_body(bh, ih), I_UNFM_NUM(ih) - 1);
|
||||
|
||||
/* append to free space of the last unformatted node of indirect item ih */
|
||||
free_space =
|
||||
@@ -896,7 +896,7 @@ static int append_to_unformatted_node(struct item_head *comingih,
|
||||
/*if (unfm_ptr == 0 || unfm_ptr >= SB_BLOCK_COUNT (fs)) { */
|
||||
unbh = reiserfsck_get_new_buffer(bh->b_blocknr);
|
||||
memset(unbh->b_data, 0, unbh->b_size);
|
||||
d32_put((__u32 *) ih_item_body(bh, ih), I_UNFM_NUM(ih) - 1,
|
||||
d32_put((__le32 *) ih_item_body(bh, ih), I_UNFM_NUM(ih) - 1,
|
||||
unbh->b_blocknr);
|
||||
/*mark_block_unformatted (unbh->b_blocknr); */
|
||||
mark_buffer_dirty(bh);
|
||||
@@ -924,7 +924,7 @@ static int append_to_unformatted_node(struct item_head *comingih,
|
||||
int reiserfsck_append_file(struct item_head *comingih, char *item, int pos,
|
||||
struct reiserfs_path *path, int was_in_tree)
|
||||
{
|
||||
__u32 *ni;
|
||||
__le32 *ni;
|
||||
struct buffer_head *unbh;
|
||||
int retval;
|
||||
struct item_head *ih = tp_item_head(path);
|
||||
@@ -1023,7 +1023,7 @@ long long int must_there_be_a_hole(struct item_head *comingih,
|
||||
int reiserfs_append_zero_unfm_ptr(struct reiserfs_path *path,
|
||||
long long int p_count)
|
||||
{
|
||||
__u32 *ni;
|
||||
__le32 *ni;
|
||||
long long int count;
|
||||
|
||||
if (is_direct_ih(tp_item_head(path)))
|
||||
@@ -1057,7 +1057,7 @@ static int overwrite_by_direct_item(struct item_head *comingih, char *item,
|
||||
bh = PATH_PLAST_BUFFER(path);
|
||||
ih = tp_item_head(path);
|
||||
|
||||
unfm_ptr = d32_get((__u32 *) ih_item_body(bh, ih), path->pos_in_item);
|
||||
unfm_ptr = d32_get((__le32 *) ih_item_body(bh, ih), path->pos_in_item);
|
||||
unbh = 0;
|
||||
|
||||
if (unfm_ptr != 0 && unfm_ptr < get_sb_block_count(fs->fs_ondisk_sb)) {
|
||||
@@ -1070,7 +1070,7 @@ static int overwrite_by_direct_item(struct item_head *comingih, char *item,
|
||||
if (unfm_ptr == 0 || unfm_ptr >= get_sb_block_count(fs->fs_ondisk_sb)) {
|
||||
if ((unbh = reiserfsck_get_new_buffer(bh->b_blocknr)) != NULL) {
|
||||
memset(unbh->b_data, 0, unbh->b_size);
|
||||
d32_put((__u32 *) ih_item_body(bh, ih), path->pos_in_item,
|
||||
d32_put((__le32 *) ih_item_body(bh, ih), path->pos_in_item,
|
||||
unbh->b_blocknr);
|
||||
mark_buffer_dirty(bh);
|
||||
} else {
|
||||
@@ -1151,17 +1151,17 @@ void overwrite_unfm_by_unfm(unsigned long unfm_in_tree,
|
||||
|
||||
/* put unformatted node pointers from incoming item over the in-tree ones */
|
||||
static int overwrite_by_indirect_item(struct item_head *comingih,
|
||||
__u32 * coming_item,
|
||||
__le32 * coming_item,
|
||||
struct reiserfs_path *path,
|
||||
int *pos_in_coming_item)
|
||||
{
|
||||
struct buffer_head *bh = PATH_PLAST_BUFFER(path);
|
||||
struct item_head *ih = tp_item_head(path);
|
||||
int written;
|
||||
__u32 *item_in_tree;
|
||||
__le32 *item_in_tree;
|
||||
int src_unfm_ptrs, dest_unfm_ptrs, to_copy, i, dirty = 0;
|
||||
|
||||
item_in_tree = (__u32 *) ih_item_body(bh, ih) + path->pos_in_item;
|
||||
item_in_tree = (__le32 *) ih_item_body(bh, ih) + path->pos_in_item;
|
||||
coming_item += *pos_in_coming_item;
|
||||
|
||||
dest_unfm_ptrs = I_UNFM_NUM(ih) - path->pos_in_item;
|
||||
@@ -1224,7 +1224,7 @@ static int reiserfsck_overwrite_file(struct item_head *comingih, char *item,
|
||||
" be overwritten by indirect item %k",
|
||||
&ih->ih_key, &comingih->ih_key);
|
||||
/* use pointer from coming indirect item */
|
||||
unfm_ptr = d32_get((__u32 *) item, *pos_in_coming_item);
|
||||
unfm_ptr = d32_get((__le32 *) item, *pos_in_coming_item);
|
||||
if (!was_in_tree) {
|
||||
if (still_bad_unfm_ptr_2(unfm_ptr))
|
||||
die("reiserfsck_overwrite_file: The pointer to the unformatted block (%u)" " points to the bad area.", unfm_ptr);
|
||||
@@ -1242,7 +1242,7 @@ static int reiserfsck_overwrite_file(struct item_head *comingih, char *item,
|
||||
" %k cannot not be in the tree yet", &ih->ih_key,
|
||||
&comingih->ih_key);
|
||||
written =
|
||||
overwrite_by_indirect_item(comingih, (__u32 *) item, path,
|
||||
overwrite_by_indirect_item(comingih, (__le32 *) item, path,
|
||||
pos_in_coming_item);
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -213,10 +213,10 @@ void id_map_flush(struct id_map *map, reiserfs_filsys_t *fs)
|
||||
{
|
||||
int size, max, i;
|
||||
__u32 id, prev_id;
|
||||
__u32 *sb_objectid_map;
|
||||
__le32 *sb_objectid_map;
|
||||
|
||||
size = reiserfs_super_block_size(fs->fs_ondisk_sb);
|
||||
sb_objectid_map = (__u32 *) ((char *)(fs->fs_ondisk_sb) + size);
|
||||
sb_objectid_map = (__le32 *) ((char *)(fs->fs_ondisk_sb) + size);
|
||||
|
||||
max = ((fs->fs_blocksize - size) >> 3 << 1);
|
||||
set_sb_oid_maxsize(fs->fs_ondisk_sb, max);
|
||||
@@ -286,10 +286,10 @@ void id_map_flush(struct id_map *map, reiserfs_filsys_t *fs)
|
||||
void fetch_objectid_map (struct id_map * map, reiserfs_filsys_t *fs)
|
||||
{
|
||||
int sb_size;
|
||||
__u32 * sb_objectid_map;
|
||||
__le32 * sb_objectid_map;
|
||||
|
||||
sb_size = reiserfs_super_block_size (fs->fs_ondisk_sb);
|
||||
sb_objectid_map = (__u32 *)((char *)(fs->fs_ondisk_sb) + sb_size);
|
||||
sb_objectid_map = (__le32 *)((char *)(fs->fs_ondisk_sb) + sb_size);
|
||||
|
||||
if (map->m_page_count != 1)
|
||||
die ("fetch_objectid_map: can not fetch long map");
|
||||
|
||||
+2
-2
@@ -40,7 +40,7 @@ void reiserfsck_insert_item(struct reiserfs_path *path, struct item_head *ih,
|
||||
|
||||
static void free_unformatted_nodes(struct item_head *ih, struct buffer_head *bh)
|
||||
{
|
||||
__u32 *punfm = (__u32 *) ih_item_body(bh, ih);
|
||||
__le32 *punfm = (__le32 *) ih_item_body(bh, ih);
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < I_UNFM_NUM(ih); i++) {
|
||||
@@ -90,7 +90,7 @@ void reiserfsck_cut_from_item(struct reiserfs_path *path, int cut_size)
|
||||
if (is_indirect_ih(ih = tp_item_head(path))) {
|
||||
struct buffer_head *bh = PATH_PLAST_BUFFER(path);
|
||||
__u32 unfm_ptr =
|
||||
d32_get((__u32 *) ih_item_body(bh, ih), I_UNFM_NUM(ih) - 1);
|
||||
d32_get((__le32 *)ih_item_body(bh, ih), I_UNFM_NUM(ih) - 1);
|
||||
if (unfm_ptr != 0) {
|
||||
struct buffer_head *to_be_forgotten;
|
||||
|
||||
|
||||
Reference in new issue
Block a user