]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
Merge branch 'maint' into next
authorTheodore Ts'o <tytso@mit.edu>
Wed, 5 Jul 2017 03:53:11 +0000 (23:53 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Wed, 5 Jul 2017 03:53:11 +0000 (23:53 -0400)
16 files changed:
e2fsck/jfs_user.h
e2fsck/pass1.c
e2fsck/recovery.c
e2fsck/revoke.c
lib/ext2fs/block.c
lib/ext2fs/getsize.c
lib/ext2fs/inode.c
lib/support/mkquota.c
lib/support/quotaio.c
misc/e4defrag.c
misc/filefrag.c
tests/j_recover_csum3_64bit/expect.1 [new file with mode: 0644]
tests/j_recover_csum3_64bit/expect.2 [new file with mode: 0644]
tests/j_recover_csum3_64bit/image.bz2 [new file with mode: 0644]
tests/j_recover_csum3_64bit/name [new file with mode: 0644]
tests/j_recover_csum3_64bit/script [new file with mode: 0755]

index 75877f33dfce964817ddeb3a199eb7fb8f05742f..d30b728d1e8525210964d377f8612ee0abe6348c 100644 (file)
@@ -137,6 +137,32 @@ _INLINE_ void do_cache_destroy(lkmem_cache_t *cache)
        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
 
index 422a3d69911191421771730b80ff8d8a182aeeff..0670cae6910bcf1c0dd87f19a646ab5665a7e091 100644 (file)
@@ -449,7 +449,7 @@ fix:
 }
 
 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;
 }
 
@@ -3094,7 +3094,7 @@ static void check_blocks(e2fsck_t ctx, struct problem_context *pctx,
        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;
index abf12c71ef2e65045442157656896a8a6ab32b63..4c457b39359811fac2ead35d28589fa1df7f8c80 100644 (file)
@@ -124,6 +124,27 @@ failed:
 
 #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
@@ -215,10 +236,10 @@ static int count_tags(journal_t *journal, struct buffer_head *bh)
 
                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;
        }
 
@@ -338,18 +359,6 @@ int journal_skip_recovery(journal_t *journal)
        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)
 {
@@ -424,9 +433,9 @@ static int jbd2_block_tag_csum_verify(journal_t *j, 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,
@@ -574,7 +583,7 @@ 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);
index 0543099725af45c898c3c53a6356ac7edc152778..64b897a7a4171ae12d983bcf484b42809435e18b 100644 (file)
@@ -134,12 +134,8 @@ static void flush_descriptor(journal_t *, struct buffer_head *, int, int);
 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,
index 601129d48e9cd2238f64685e6b89d8d23873d9ac..06eed6e0301c3a44f928018c98ff1052da876990 100644 (file)
@@ -251,7 +251,7 @@ static int block_iterate_tind(blk_t *tind_block, blk_t ref_block,
        }
        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) ||
index 89c33d4cdcdc1675bfe248d66377cf810a5cd06d..f3839ba3a011fd2bd3cf740d4d45abef9d82c8f0 100644 (file)
@@ -71,8 +71,8 @@
 #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;
@@ -272,6 +272,8 @@ out:
        return rc;
 }
 
+#endif /* WIN32 */
+
 errcode_t ext2fs_get_device_size(const char *file, int blocksize,
                                 blk_t *retblocks)
 {
@@ -287,8 +289,6 @@ errcode_t ext2fs_get_device_size(const char *file, int blocksize,
        return 0;
 }
 
-#endif /* WIN32 */
-
 #ifdef DEBUG
 int main(int argc, char **argv)
 {
index ba7ad2c9c4d46ac91abe0483d074600db1bb1e90..8dc9ac0d9e71ed1f734de02eb81b034239e07124 100644 (file)
@@ -630,7 +630,8 @@ errcode_t ext2fs_get_next_inode_full(ext2_inode_scan scan, ext2_ino_t *ino,
         * 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);
index 1bb43a71cfac2dfe75d706bd6bb1fa76a7a12fb9..11a878e7f1315785e42f9262381d90913db60f51 100644 (file)
@@ -50,7 +50,7 @@ static void print_dquot(const char *desc, struct dquot *dq)
 {
        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,
@@ -523,7 +523,7 @@ static int scan_dquots_callback(struct dquot *dquot, void *cb_data)
            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,
index befa832951a2bbdc3f6c3893cc0f3223838081fa..240eab3d63ea234ac3c273c64c7c963e078a0dce 100644 (file)
@@ -230,9 +230,9 @@ errcode_t quota_file_open(quota_ctx_t qctx, struct quota_handle *h,
                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));
@@ -366,7 +366,7 @@ errcode_t quota_file_create(struct quota_handle *h, ext2_filsys fs,
        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);
index 84501d17a8401be5ad620c5b4a09a1fc1682b284..5fa85b66c529922f6e036ac3e226c38d4bd6ed6b 100644 (file)
@@ -1675,6 +1675,7 @@ int main(int argc, char *argv[])
        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];
@@ -1818,7 +1819,6 @@ int main(int argc, char *argv[])
                }
 
                switch (arg_type) {
-                       int mount_dir_len = 0;
 
                case DIRNAME:
                        if (!(mode_flag & STATISTIC))
@@ -1830,11 +1830,11 @@ int main(int argc, char *argv[])
                        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,
@@ -1848,7 +1848,7 @@ int main(int argc, char *argv[])
                                        continue;
                                }
 
-                               /* "e4defrag mount_piont_dir/else_dir" */
+                               /* "e4defrag mount_point_dir/else_dir" */
                                memset(lost_found_dir, 0, PATH_MAX + 1);
                        }
                case DEVNAME:
index 1a185124509b741ecb3c8ba641b2c4b37564e786..9c57ab930ac1856a38b0452032e54aacd89cf32b 100644 (file)
@@ -588,7 +588,7 @@ int main(int argc, char**argv)
        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)
diff --git a/tests/j_recover_csum3_64bit/expect.1 b/tests/j_recover_csum3_64bit/expect.1
new file mode 100644 (file)
index 0000000..6aed56a
--- /dev/null
@@ -0,0 +1,16 @@
+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
diff --git a/tests/j_recover_csum3_64bit/expect.2 b/tests/j_recover_csum3_64bit/expect.2
new file mode 100644 (file)
index 0000000..b7a14da
--- /dev/null
@@ -0,0 +1,7 @@
+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
diff --git a/tests/j_recover_csum3_64bit/image.bz2 b/tests/j_recover_csum3_64bit/image.bz2
new file mode 100644 (file)
index 0000000..13b2956
Binary files /dev/null and b/tests/j_recover_csum3_64bit/image.bz2 differ
diff --git a/tests/j_recover_csum3_64bit/name b/tests/j_recover_csum3_64bit/name
new file mode 100644 (file)
index 0000000..8f91d97
--- /dev/null
@@ -0,0 +1 @@
+recover 64-bit journal checksum v3
diff --git a/tests/j_recover_csum3_64bit/script b/tests/j_recover_csum3_64bit/script
new file mode 100755 (executable)
index 0000000..4b0ec48
--- /dev/null
@@ -0,0 +1,31 @@
+#!/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