Whamcloud - gitweb
libext2fs: use strcpy()/strcat() instead of sprintf() in bmap functions
[tools/e2fsprogs.git] / lib / ext2fs / csum.c
index b301749..9fa3f24 100644 (file)
@@ -5,11 +5,12 @@
  * Copyright (C) 2006, 2007 by Andreas Dilger <adilger@clusterfs.com>
  *
  * %Begin-Header%
- * This file may be redistributed under the terms of the GNU Public
- * License.
+ * This file may be redistributed under the terms of the GNU Library
+ * General Public License, version 2.
  * %End-Header%
  */
 
+#include "config.h"
 #if HAVE_SYS_TYPES_H
 #include <sys/types.h>
 #endif
@@ -29,7 +30,7 @@
 #define STATIC static
 #endif
 
-STATIC __u16 ext2fs_group_desc_csum(ext2_filsys fs, dgrp_t group)
+__u16 ext2fs_group_desc_csum(ext2_filsys fs, dgrp_t group)
 {
        __u16 crc = 0;
        struct ext2_group_desc *desc;
@@ -46,7 +47,7 @@ STATIC __u16 ext2fs_group_desc_csum(ext2_filsys fs, dgrp_t group)
        desc = ext2fs_group_desc(fs, fs->group_desc, group);
 
        if (fs->super->s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_GDT_CSUM) {
-               int offset = offsetof(struct ext2_group_desc, bg_checksum);
+               size_t offset = offsetof(struct ext2_group_desc, bg_checksum);
 
 #ifdef WORDS_BIGENDIAN
                struct ext4_group_desc swabdesc;
@@ -127,10 +128,10 @@ errcode_t ext2fs_set_gdt_csum(ext2_filsys fs)
                return 0;
 
        for (i = 0; i < fs->group_desc_count; i++) {
-               unsigned int old_csum = ext2fs_bg_checksum(fs, i);
-               int old_unused = ext2fs_bg_itable_unused(fs, i);
-               unsigned int old_flags = ext2fs_bg_flags(fs, i);
-               int old_free_inodes_count = ext2fs_bg_free_inodes_count(fs, i);
+               __u32 old_csum = ext2fs_bg_checksum(fs, i);
+               __u32 old_unused = ext2fs_bg_itable_unused(fs, i);
+               __u32 old_flags = ext2fs_bg_flags(fs, i);
+               __u32 old_free_inodes_count = ext2fs_bg_free_inodes_count(fs, i);
 
                if (old_free_inodes_count == sb->s_inodes_per_group) {
                        ext2fs_bg_flags_set(fs, i, EXT2_BG_INODE_UNINIT);
@@ -159,6 +160,8 @@ errcode_t ext2fs_set_gdt_csum(ext2_filsys fs)
 }
 
 #ifdef DEBUG
+#include "e2p/e2p.h"
+
 void print_csum(const char *msg, ext2_filsys fs, dgrp_t group)
 {
        __u16 crc1, crc2, crc3;
@@ -195,9 +198,9 @@ void print_csum(const char *msg, ext2_filsys fs, dgrp_t group)
        if (offset < size)
                crc3 = ext2fs_crc16(crc3, (char *)desc + offset, size - offset);
 
-       printf("%s: UUID %016Lx%016Lx(%04x), grp %u(%04x): %04x=%04x\n",
-              msg, *(long long *)&sb->s_uuid, *(long long *)&sb->s_uuid[8],
-              crc1, group, crc2, crc3, ext2fs_group_desc_csum(fs, group));
+       printf("%s: UUID %s(%04x), grp %u(%04x): %04x=%04x\n",
+              msg, e2p_uuid2str(sb->s_uuid), crc1, group, crc2, crc3,
+              ext2fs_group_desc_csum(fs, group));
 }
 
 unsigned char sb_uuid[16] = { 0x4f, 0x25, 0xe8, 0xcf, 0xe7, 0x97, 0x48, 0x23,