Skip to content

Commit

Permalink
Fix 32-bit build and test failures
Browse files Browse the repository at this point in the history
Commit ca8bc92 ("Add post-2038 timestamp support to e2fsprogs")
was never built or tested on a 32-bit.  It introduced some build
problems when time_t is a 32-bit integer, and it exposed some test
bugs.  Fix them.

Fixes: ca8bc92 ("Add post-2038 timestamp support to e2fsprogs")
Signed-off-by: Theodore Ts'o <[email protected]>
  • Loading branch information
tytso committed Apr 18, 2024
1 parent b53ce78 commit 5b599a3
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 11 deletions.
16 changes: 15 additions & 1 deletion lib/ext2fs/ext2fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -581,13 +581,19 @@ typedef struct ext2_struct_inode_scan *ext2_inode_scan;

static inline __u32 __encode_extra_time(time_t seconds, __u32 nsec)
{
__u32 extra = ((seconds - (__s32)seconds) >> 32) & EXT4_EPOCH_MASK;
__u32 extra = 0;

#if (SIZEOF_TIME_T > 4)
extra = ((seconds - (__s32)seconds) >> 32) & EXT4_EPOCH_MASK;
#endif
return extra | (nsec << EXT4_EPOCH_BITS);
}
static inline time_t __decode_extra_sec(time_t seconds, __u32 extra)
{
#if (SIZEOF_TIME_T > 4)
if (extra & EXT4_EPOCH_MASK)
seconds += ((time_t)(extra & EXT4_EPOCH_MASK) << 32);
#endif
return seconds;
}
static inline __u32 __decode_extra_nsec(__u32 extra)
Expand Down Expand Up @@ -620,11 +626,19 @@ do { \
static inline void __sb_set_tstamp(__u32 *lo, __u8 *hi, time_t seconds)
{
*lo = seconds & 0xffffffff;
#if (SIZEOF_TIME_T > 4)
*hi = seconds >> 32;
#else
*hi = 0;
#endif
}
static inline time_t __sb_get_tstamp(__u32 *lo, __u8 *hi)
{
#if (SIZEOF_TIME_T == 4)
return *lo;
#else
return ((time_t)(*hi) << 32) | *lo;
#endif
}
#define ext2fs_set_tstamp(sb, field, seconds) \
__sb_set_tstamp(&(sb)->field, &(sb)->field ## _hi, seconds)
Expand Down
4 changes: 2 additions & 2 deletions tests/f_desc_size_bad/script
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ touch $TMPFILE
$MKE2FS -F -o Linux -O 64bit,extents -N 32 -b 1024 -g 512 -E desc_size=128 $TMPFILE 2048 > $test_name.log 2>&1
$DEBUGFS -R "ssv desc_size 129" -w $TMPFILE >> $test_name.log 2>&1

E2FSCK_TIME=200704102100
export E2FSCK_TIME
#E2FSCK_TIME=1176238800
#export E2FSCK_TIME

. $cmd_dir/run_e2fsck

Expand Down
2 changes: 1 addition & 1 deletion tests/f_dup4/script
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ set_inode_field /dir3/foe block[0] 34
q
EOF

E2FSCK_TIME=200704102100
E2FSCK_TIME=1176238800
export E2FSCK_TIME

. $cmd_dir/run_e2fsck
Expand Down
10 changes: 5 additions & 5 deletions tests/f_itable_collision/expect.1
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ Clear inode? yes
Restarting e2fsck from the beginning...
Pass 1: Checking inodes, blocks, and sizes
Inode 12 block 37 conflicts with critical metadata, skipping block checks.
Illegal block number passed to ext2fs_test_block_bitmap #4294967294 for in-use block map
Illegal block number passed to ext2fs_mark_block_bitmap #4294967294 for in-use block map
Illegal block number passed to ext2fs_test_block_bitmap #2147483646 for in-use block map
Illegal block number passed to ext2fs_mark_block_bitmap #2147483646 for in-use block map
Illegal block number passed to ext2fs_test_block_bitmap #268435455 for in-use block map
Illegal block number passed to ext2fs_mark_block_bitmap #268435455 for in-use block map

Running additional passes to resolve blocks claimed by more than one inode...
Pass 1B: Rescanning for multiply-claimed blocks
Illegal block number passed to ext2fs_test_block_bitmap #4294967294 for multiply claimed block map
Illegal block number passed to ext2fs_test_block_bitmap #2147483646 for multiply claimed block map
Illegal block number passed to ext2fs_test_block_bitmap #268435455 for multiply claimed block map
Multiply-claimed block(s) in inode 12: 37
Pass 1C: Scanning directories for inodes with multiply-claimed blocks
Expand All @@ -46,15 +46,15 @@ File /a (inode #12, mod time Fri Jun 27 18:34:44 2014)
<filesystem metadata>
Clone multiply-claimed blocks? yes

Illegal block number passed to ext2fs_test_block_bitmap #4294967294 for multiply claimed block map
Illegal block number passed to ext2fs_test_block_bitmap #2147483646 for multiply claimed block map
Illegal block number passed to ext2fs_test_block_bitmap #268435455 for multiply claimed block map
Pass 2: Checking directory structure
Setting filetype for entry 'bad1' in / (2) to 1.
Setting filetype for entry 'bad2' in / (2) to 1.
Restarting e2fsck from the beginning...
Pass 1: Checking inodes, blocks, and sizes
Inode 12 has an invalid extent
(logical block 0, invalid physical block 4294967294, len 1)
(logical block 0, invalid physical block 2147483646, len 1)
Clear? yes

Inode 12 has an invalid extent
Expand Down
2 changes: 1 addition & 1 deletion tests/f_itable_collision/script
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

FSCK_OPT=-fy
IMAGE=$test_dir/image.gz
E2FSCK_TIME=4294967294
E2FSCK_TIME=2147483646
export E2FSCK_TIME

gzip -d < $IMAGE > $TMPFILE
Expand Down
2 changes: 1 addition & 1 deletion tests/f_uninit_last_uninit/script
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ set_bg 1 checksum calc
q
EOF

E2FSCK_TIME=200704102100
E2FSCK_TIME=1176238800
export E2FSCK_TIME

. $cmd_dir/run_e2fsck
Expand Down

0 comments on commit 5b599a3

Please sign in to comment.