free(cache);
}
+/* generic hashing taken from the Linux kernel */
+#define GOLDEN_RATIO_32 0x61C88647
+#define GOLDEN_RATIO_64 0x61C8864680B583EBull
+
+_INLINE_ __u32 __hash_32(__u32 val)
+{
+ return val * GOLDEN_RATIO_32;
+}
+
+_INLINE_ __u32 hash_32(__u32 val, unsigned int bits)
+{
+ /* High bits are more random, so use them. */
+ return __hash_32(val) >> (32 - bits);
+}
+
+_INLINE_ __u32 hash_64(__u64 val, unsigned int bits)
+{
+ if (sizeof(long) >= 8) {
+ /* 64x64-bit multiply is efficient on all 64-bit processors */
+ return val * GOLDEN_RATIO_64 >> (64 - bits);
+ } else {
+ /* Hash 64 bits using only 32x32-bit multiply. */
+ return hash_32((__u32)val ^ __hash_32(val >> 32), bits);
+ }
+}
+
#undef _INLINE_
#endif
}
static int check_inode_extra_negative_epoch(__u32 xtime, __u32 extra) {
- return (xtime & (1 << 31)) != 0 &&
+ return (xtime & (1U << 31)) != 0 &&
(extra & EXT4_EPOCH_MASK) == EXT4_EPOCH_MASK;
}
pb.previous_block = 0;
pb.is_dir = LINUX_S_ISDIR(inode->i_mode);
pb.is_reg = LINUX_S_ISREG(inode->i_mode);
- pb.max_blocks = 1 << (31 - fs->super->s_log_block_size);
+ pb.max_blocks = 1U << (31 - fs->super->s_log_block_size);
pb.inode = inode;
pb.pctx = pctx;
pb.ctx = ctx;
#endif /* __KERNEL__ */
+static inline __u32 get_be32(__be32 *p)
+{
+ unsigned char *cp = (unsigned char *) p;
+ __u32 ret;
+
+ ret = *cp++;
+ ret = (ret << 8) + *cp++;
+ ret = (ret << 8) + *cp++;
+ ret = (ret << 8) + *cp++;
+ return ret;
+}
+
+static inline __u16 get_be16(__be16 *p)
+{
+ unsigned char *cp = (unsigned char *) p;
+ __u16 ret;
+
+ ret = *cp++;
+ ret = (ret << 8) + *cp++;
+ return ret;
+}
/*
* Read a block from the journal
nr++;
tagp += tag_bytes;
- if (!(tag->t_flags & ext2fs_cpu_to_be16(JFS_FLAG_SAME_UUID)))
+ if (!(get_be16(&tag->t_flags) & JFS_FLAG_SAME_UUID))
tagp += 16;
- if (tag->t_flags & ext2fs_cpu_to_be16(JFS_FLAG_LAST_TAG))
+ if (get_be16(&tag->t_flags) & JFS_FLAG_LAST_TAG)
break;
}
return err;
}
-static inline __u32 get_be32(__be32 *p)
-{
- unsigned char *cp = (unsigned char *) p;
- __u32 ret;
-
- ret = *cp++;
- ret = (ret << 8) + *cp++;
- ret = (ret << 8) + *cp++;
- ret = (ret << 8) + *cp++;
- return ret;
-}
-
static inline unsigned long long read_tag_block(journal_t *journal,
journal_block_tag_t *tag)
{
csum32 = jbd2_chksum(j, csum32, buf, j->j_blocksize);
if (jfs_has_feature_csum3(j))
- return tag3->t_checksum == ext2fs_cpu_to_be32(csum32);
+ return get_be32(&tag3->t_checksum) == csum32;
- return tag->t_checksum == ext2fs_cpu_to_be16(csum32);
+ return get_be16(&tag->t_checksum) == (csum32 & 0xFFFF);
}
static int do_one_pass(journal_t *journal,
unsigned long io_block;
tag = (journal_block_tag_t *) tagp;
- flags = ext2fs_be16_to_cpu(tag->t_flags);
+ flags = get_be16(&tag->t_flags);
io_block = next_log_block++;
wrap(journal, next_log_block);
static inline int hash(journal_t *journal, unsigned long long block)
{
struct jbd2_revoke_table_s *table = journal->j_revoke;
- int hash_shift = table->hash_shift;
- int hash = (int)block ^ (int)((block >> 31) >> 1);
- return ((hash << (hash_shift - 6)) ^
- (hash >> 13) ^
- (hash << (hash_shift - 12))) & (table->hash_size - 1);
+ return (hash_64(block, table->hash_shift));
}
static int insert_revoke_hash(journal_t *journal, unsigned long long blocknr,
}
check_for_ro_violation_return(ctx, ret);
if (!*tind_block || (ret & BLOCK_ABORT)) {
- ctx->bcount += limit*limit*limit;
+ ctx->bcount += ((unsigned long long) limit)*limit*limit;
return ret;
}
if (*tind_block >= ext2fs_blocks_count(ctx->fs->super) ||
#define HAVE_GET_FILE_SIZE_EX 1
#endif
-errcode_t ext2fs_get_device_size(const char *file, int blocksize,
- blk_t *retblocks)
+errcode_t ext2fs_get_device_size2(const char *file, int blocksize,
+ blk64_t *retblocks)
{
HANDLE dev;
PARTITION_INFORMATION pi;
return rc;
}
+#endif /* WIN32 */
+
errcode_t ext2fs_get_device_size(const char *file, int blocksize,
blk_t *retblocks)
{
return 0;
}
-#endif /* WIN32 */
-
#ifdef DEBUG
int main(int argc, char **argv)
{
* need to read in more blocks.
*/
if (scan->bytes_left < scan->inode_size) {
- memcpy(scan->temp_buffer, scan->ptr, scan->bytes_left);
+ if (scan->bytes_left)
+ memcpy(scan->temp_buffer, scan->ptr, scan->bytes_left);
extra_bytes = scan->bytes_left;
retval = get_next_blocks(scan);
{
if (desc)
fprintf(stderr, "%s: ", desc);
- fprintf(stderr, "%u %lld:%lld:%lld %lld:%lld:%lld\n",
+ fprintf(stderr, "%u %ld:%ld:%ld %ld:%ld:%ld\n",
dq->dq_id, dq->dq_dqb.dqb_curspace,
dq->dq_dqb.dqb_bsoftlimit, dq->dq_dqb.dqb_bhardlimit,
dq->dq_dqb.dqb_curinodes,
dq->dq_dqb.dqb_curinodes != dquot->dq_dqb.dqb_curinodes) {
scan_data->usage_is_inconsistent = 1;
fprintf(stderr, "[QUOTA WARNING] Usage inconsistent for ID %u:"
- "actual (%lld, %lld) != expected (%lld, %lld)\n",
+ "actual (%ld, %ld) != expected (%ld, %ld)\n",
dq->dq_id, dq->dq_dqb.dqb_curspace,
dq->dq_dqb.dqb_curinodes,
dquot->dq_dqb.dqb_curspace,
return err;
if (qf_ino == 0)
- qf_ino = *quota_sb_inump(fs->super, qtype)
+ qf_ino = *quota_sb_inump(fs->super, qtype);
- log_debug("Opening quota ino=%lu, type=%d", qf_ino, qtype);
+ log_debug("Opening quota ino=%u, type=%d", qf_ino, qtype);
err = ext2fs_file_open(fs, qf_ino, flags, &e2_file);
if (err) {
log_err("ext2fs_file_open failed: %s", error_message(err));
h->e2fs_write = quota_write_nomount;
h->e2fs_read = quota_read_nomount;
- log_debug("Creating quota ino=%lu, type=%d", qf_inum, type);
+ log_debug("Creating quota ino=%u, type=%d", qf_inum, qtype);
err = ext2fs_file_open(fs, qf_inum, h->qh_file_flags, &e2_file);
if (err) {
log_err("ext2fs_file_open failed: %ld", err);
int i, j, ret = 0;
int flags = FTW_PHYS | FTW_MOUNT;
int arg_type = -1;
+ int mount_dir_len = 0;
int success_flag = 0;
char dir_name[PATH_MAX + 1];
char dev_name[PATH_MAX + 1];
}
switch (arg_type) {
- int mount_dir_len = 0;
case DIRNAME:
if (!(mode_flag & STATISTIC))
strncat(lost_found_dir, "/lost+found",
PATH_MAX - strnlen(lost_found_dir, PATH_MAX));
- /* Not the case("e4defrag mount_piont_dir") */
+ /* Not the case("e4defrag mount_point_dir") */
if (dir_name[mount_dir_len] != '\0') {
/*
- * "e4defrag mount_piont_dir/lost+found"
- * or "e4defrag mount_piont_dir/lost+found/"
+ * "e4defrag mount_point_dir/lost+found"
+ * or "e4defrag mount_point_dir/lost+found/"
*/
if (strncmp(lost_found_dir, dir_name,
strnlen(lost_found_dir,
continue;
}
- /* "e4defrag mount_piont_dir/else_dir" */
+ /* "e4defrag mount_point_dir/else_dir" */
memset(lost_found_dir, 0, PATH_MAX + 1);
}
case DEVNAME:
if (optind == argc)
usage(argv[0]);
- for (cpp = argv + optind; *cpp != '\0'; cpp++) {
+ for (cpp = argv + optind; *cpp != NULL; cpp++) {
int rc2 = frag_report(*cpp);
if (rc2 < 0 && rc == 0)
--- /dev/null
+test_filesys: recovering journal
+Pass 1: Checking inodes, blocks, and sizes
+Pass 2: Checking directory structure
+Pass 3: Checking directory connectivity
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+Free blocks count wrong (121285, counted=121282).
+Fix? yes
+
+Free inodes count wrong (32757, counted=32754).
+Fix? yes
+
+
+test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
+test_filesys: 14/32768 files (0.0% non-contiguous), 9790/131072 blocks
+Exit status is 0
--- /dev/null
+Pass 1: Checking inodes, blocks, and sizes
+Pass 2: Checking directory structure
+Pass 3: Checking directory connectivity
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+test_filesys: 14/32768 files (0.0% non-contiguous), 9790/131072 blocks
+Exit status is 0
--- /dev/null
+recover 64-bit journal checksum v3
--- /dev/null
+#!/bin/bash
+
+FSCK_OPT=-fy
+IMAGE=$test_dir/image.bz2
+
+bzip2 -d < $IMAGE > $TMPFILE
+
+# Run fsck to fix things?
+EXP1=$test_dir/expect.1
+OUT1=$test_name.1.log
+rm -rf $test_name.failed $test_name.ok
+
+$FSCK $FSCK_OPT -N test_filesys $TMPFILE 2>&1 | head -n 1000 | tail -n +2 > $OUT1
+echo "Exit status is $?" >> $OUT1
+
+# Run a second time
+EXP2=$test_dir/expect.2
+OUT2=$test_name.2.log
+
+$FSCK $FSCK_OPT -N test_filesys $TMPFILE 2>&1 | head -n 1000 | tail -n +2 > $OUT2
+echo "Exit status is $?" >> $OUT2
+
+# Figure out what happened
+if cmp -s $EXP1 $OUT1 && cmp -s $EXP2 $OUT2; then
+ echo "$test_name: $test_description: ok"
+ touch $test_name.ok
+else
+ echo "$test_name: $test_description: failed"
+ diff -u $EXP1 $OUT1 >> $test_name.failed
+ diff -u $EXP2 $OUT2 >> $test_name.failed
+fi