Whamcloud - gitweb
Fix compile error and warnings for old gcc versions
[tools/e2fsprogs.git] / debugfs / set_fields.c
index 365a8dc..e1e23a5 100644 (file)
@@ -40,6 +40,7 @@
 #include "debugfs.h"
 #include "uuid/uuid.h"
 #include "e2p/e2p.h"
+#include "support/quotaio.h"
 
 static struct ext2_super_block set_sb;
 static struct ext2_inode_large set_inode;
@@ -74,6 +75,11 @@ static errcode_t parse_gd_csum(struct field_set_info *info, char *field, char *a
 static errcode_t parse_mmp_clear(struct field_set_info *info, char *field,
                                 char *arg);
 
+#if __GNUC_PREREQ (4, 6)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
+#endif
+
 static struct field_set_info super_fields[] = {
        { "inodes_count", &set_sb.s_inodes_count, NULL, 4, parse_uint },
        { "blocks_count", &set_sb.s_blocks_count, &set_sb.s_blocks_count_hi,
@@ -149,6 +155,7 @@ static struct field_set_info super_fields[] = {
        { "mount_opts",  &set_sb.s_mount_opts, NULL, 64, parse_string },
        { "usr_quota_inum", &set_sb.s_usr_quota_inum, NULL, 4, parse_uint },
        { "grp_quota_inum", &set_sb.s_grp_quota_inum, NULL, 4, parse_uint },
+       { "prj_quota_inum", &set_sb.s_prj_quota_inum, NULL, 4, parse_uint },
        { "overhead_blocks", &set_sb.s_overhead_blocks, NULL, 4, parse_uint },
        { "backup_bgs", &set_sb.s_backup_bgs[0], NULL, 4, parse_uint,
          FLAG_ARRAY, 2 },
@@ -170,6 +177,7 @@ static struct field_set_info super_fields[] = {
          FLAG_ARRAY, 4 },
        { "encrypt_pw_salt", &set_sb.s_encrypt_pw_salt, NULL, 16, parse_uuid },
        { "lpf_ino", &set_sb.s_lpf_ino, NULL, 4, parse_uint },
+       { "checksum_seed", &set_sb.s_checksum_seed, NULL, 4, parse_uint },
        { 0, 0, 0, 0 }
 };
 
@@ -178,10 +186,14 @@ static struct field_set_info inode_fields[] = {
        { "uid", &set_inode.i_uid, &set_inode.osd2.linux2.l_i_uid_high,
                2, parse_uint },
        { "size", &set_inode.i_size, &set_inode.i_size_high, 4, parse_uint },
-       { "atime", &set_inode.i_atime, NULL, 4, parse_time },
-       { "ctime", &set_inode.i_ctime, NULL, 4, parse_time },
-       { "mtime", &set_inode.i_mtime, NULL, 4, parse_time },
-       { "dtime", &set_inode.i_dtime, NULL, 4, parse_time },
+       { "atime", &set_inode.i_atime, &set_inode.i_atime_extra,
+               4, parse_time },
+       { "ctime", &set_inode.i_ctime, &set_inode.i_ctime_extra,
+               4, parse_time },
+       { "mtime", &set_inode.i_mtime, &set_inode.i_mtime_extra,
+               4, parse_time },
+       { "dtime", &set_inode.i_dtime, NULL,
+               4, parse_time },
        { "gid", &set_inode.i_gid, &set_inode.osd2.linux2.l_i_gid_high,
                2, parse_uint },
        { "links_count", &set_inode.i_links_count, NULL, 2, parse_uint },
@@ -202,7 +214,6 @@ static struct field_set_info inode_fields[] = {
        /* Special case: i_file_acl_high is 2 bytes */
        { "file_acl", &set_inode.i_file_acl, 
                &set_inode.osd2.linux2.l_i_file_acl_high, 6, parse_uint },
-       { "dir_acl", &set_inode.i_dir_acl, NULL, 4, parse_uint, FLAG_ALIAS },
        { "faddr", &set_inode.i_faddr, NULL, 4, parse_uint },
        { "frag", &set_inode.osd2.hurd2.h_i_frag, NULL, 1, parse_uint, FLAG_ALIAS },
        { "fsize", &set_inode.osd2.hurd2.h_i_fsize, NULL, 1, parse_uint },
@@ -213,14 +224,16 @@ static struct field_set_info inode_fields[] = {
        { "extra_isize", &set_inode.i_extra_isize, NULL,
                2, parse_uint },
        { "ctime_extra", &set_inode.i_ctime_extra, NULL,
-               4, parse_uint },
+               4, parse_uint, FLAG_ALIAS },
        { "mtime_extra", &set_inode.i_mtime_extra, NULL,
-               4, parse_uint },
+               4, parse_uint, FLAG_ALIAS  },
        { "atime_extra", &set_inode.i_atime_extra, NULL,
-               4, parse_uint },
-       { "crtime", &set_inode.i_crtime, NULL, 4, parse_uint },
+               4, parse_uint, FLAG_ALIAS },
+       { "crtime", &set_inode.i_crtime, &set_inode.i_crtime_extra,
+               4, parse_time },
        { "crtime_extra", &set_inode.i_crtime_extra, NULL,
-               4, parse_uint },
+               4, parse_uint, FLAG_ALIAS },
+       { "projid", &set_inode.i_projid, NULL, 4, parse_uint },
        { "bmap", NULL, NULL, 4, parse_bmap, FLAG_ARRAY },
        { 0, 0, 0, 0 }
 };
@@ -278,9 +291,13 @@ static struct field_set_info mmp_fields[] = {
        { "checksum", &set_mmp.mmp_checksum, NULL, 4, parse_uint },
        { 0, 0, 0, 0 }
 };
+#if __GNUC_PREREQ (4, 6)
+#pragma GCC diagnostic pop
+#endif
 
 #ifdef UNITTEST
 
+
 static void do_verify_field_set_info(struct field_set_info *fields,
                const void *data, size_t size)
 {
@@ -416,7 +433,7 @@ static struct field_set_info *find_field(struct field_set_info *fields,
 
 /*
  * Note: info->size == 6 is special; this means a base size 4 bytes,
- * and secondiory (high) size of 2 bytes.  This is needed for the
+ * and secondary (high) size of 2 bytes.  This is needed for the
  * special case of i_blocks_high and i_file_acl_high.
  */
 static errcode_t parse_uint(struct field_set_info *info, char *field,
@@ -482,7 +499,7 @@ static errcode_t parse_uint(struct field_set_info *info, char *field,
        }
        if (!field2)
                return 0;
-       n = num >> (size*8);
+       n = (size == 8) ? 0 : (num >> (size*8));
        u.ptr8 = (__u8 *) field2;
        if (info->size == 6)
                size = 2;
@@ -550,21 +567,30 @@ static errcode_t parse_string(struct field_set_info *info,
 }
 
 static errcode_t parse_time(struct field_set_info *info,
-                           char *field EXT2FS_ATTR((unused)), char *arg)
+                           char *field, char *arg)
 {
-       time_t          t;
-       __u32           *ptr32;
+       __s64           t;
+       __u32           t_low, t_high;
+       __u32           *ptr_low, *ptr_high;
+
+       if (check_suffix(field))
+               return parse_uint(info, field, arg);
 
-       ptr32 = (__u32 *) info->ptr;
+       ptr_low  = (__u32 *) info->ptr;
+       ptr_high = (__u32 *) info->ptr2;
 
        t = string_to_time(arg);
 
-       if (t == ((time_t) -1)) {
+       if (t == -1) {
                fprintf(stderr, "Couldn't parse '%s' for field %s.\n",
                        arg, info->name);
                return EINVAL;
        }
-       *ptr32 = t;
+       t_low = (__u32) t;
+       t_high = ((t - (__s32)t) >> 32) & EXT4_EPOCH_MASK;
+       *ptr_low = t_low;
+       if (ptr_high)
+               *ptr_high = (*ptr_high & ~EXT4_EPOCH_MASK) | t_high;
        return 0;
 }
 
@@ -629,18 +655,13 @@ static errcode_t parse_bmap(struct field_set_info *info,
 static errcode_t parse_gd_csum(struct field_set_info *info, char *field,
                               char *arg)
 {
+       __u16 *checksum = info->ptr;
 
        if (strcmp(arg, "calc") == 0) {
-               ext2fs_group_desc_csum_set(current_fs, set_bg);
-               memcpy(&set_gd, ext2fs_group_desc(current_fs,
-                                       current_fs->group_desc,
-                                       set_bg),
-                       sizeof(set_gd));
-               printf("Checksum set to 0x%04x\n",
-                      ext2fs_bg_checksum(current_fs, set_bg));
+               *checksum = ext2fs_group_desc_csum(current_fs, set_bg);
+               printf("Checksum set to 0x%04x\n", *checksum);
                return 0;
        }
-
        return parse_uint(info, field, arg);
 }
 
@@ -770,7 +791,7 @@ void do_set_inode(int argc, char *argv[])
 void do_set_block_group_descriptor(int argc, char *argv[])
 {
        const char *usage = "<bg number> <field> <value>\n"
-               "\t\"set_block_group_descriptor -l\" will list the names of "
+               "\t\"set_block_group -l\" will list the names of "
                "the fields in a block group descriptor\n\twhich can be set.";
        struct field_set_info   *table;
        struct field_set_info   *ss;
@@ -801,7 +822,7 @@ void do_set_block_group_descriptor(int argc, char *argv[])
                return;
        }
 
-       if (common_args_process(argc, argv, 4, 4, "set_block_group_descriptor",
+       if (common_args_process(argc, argv, 4, 4, "set_block_group",
                                usage, CHECK_FS_RW))
                return;
 
@@ -844,9 +865,9 @@ static errcode_t parse_mmp_clear(struct field_set_info *info,
        return 1; /* we don't need the MMP block written again */
 }
 
+#ifdef CONFIG_MMP
 void do_set_mmp_value(int argc, char *argv[])
 {
-#ifdef CONFIG_MMP
        const char *usage = "<field> <value>\n"
                "\t\"set_mmp_value -l\" will list the names of "
                "MMP fields\n\twhich can be set.";
@@ -901,9 +922,13 @@ void do_set_mmp_value(int argc, char *argv[])
                                 &set_mmp);
                *mmp_s = set_mmp;
        }
+}
 #else
+void do_set_mmp_value(int argc EXT2FS_ATTR((unused)),
+                     char *argv[] EXT2FS_ATTR((unused)))
+{
        fprintf(stdout, "MMP is unsupported, please recompile with "
                        "--enable-mmp\n");
-#endif
 }
+#endif