]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
More efficient retrieval of file size phcoder/filesize
authorVladimir Serbinenko <phcoder@gmail.com>
Sun, 27 Oct 2013 16:24:35 +0000 (17:24 +0100)
committerVladimir Serbinenko <phcoder@gmail.com>
Sun, 27 Oct 2013 16:24:35 +0000 (17:24 +0100)
27 files changed:
grub-core/commands/ls.c
grub-core/fs/affs.c
grub-core/fs/archelp.c
grub-core/fs/bfs.c
grub-core/fs/btrfs.c
grub-core/fs/cbfs.c
grub-core/fs/cpio_common.c
grub-core/fs/ext2.c
grub-core/fs/fat.c
grub-core/fs/hfs.c
grub-core/fs/hfsplus.c
grub-core/fs/iso9660.c
grub-core/fs/jfs.c
grub-core/fs/minix.c
grub-core/fs/nilfs2.c
grub-core/fs/ntfs.c
grub-core/fs/reiserfs.c
grub-core/fs/romfs.c
grub-core/fs/sfs.c
grub-core/fs/squash4.c
grub-core/fs/tar.c
grub-core/fs/udf.c
grub-core/fs/ufs.c
grub-core/fs/xfs.c
grub-core/fs/zfs/zfs.c
include/grub/archelp.h
include/grub/fs.h

index 0eaf836527944ba69d499050ad080f919d3e57ef..6ba85f462aee95b8219abdd54af78b2594a9ce8f 100644 (file)
@@ -116,35 +116,11 @@ print_files_long (const char *filename, const struct grub_dirhook_info *info,
 
   if (! info->dir)
     {
-      grub_file_t file;
-      char *pathname;
-
-      if (ctx->dirname[grub_strlen (ctx->dirname) - 1] == '/')
-       pathname = grub_xasprintf ("%s%s", ctx->dirname, filename);
-      else
-       pathname = grub_xasprintf ("%s/%s", ctx->dirname, filename);
-
-      if (!pathname)
-       return 1;
-
-      /* XXX: For ext2fs symlinks are detected as files while they
-        should be reported as directories.  */
-      grub_file_filter_disable_compression ();
-      file = grub_file_open (pathname);
-      if (! file)
-       {
-         grub_errno = 0;
-         grub_free (pathname);
-         return 0;
-       }
-
       if (! ctx->human)
-       grub_printf ("%-12llu", (unsigned long long) file->size);
+       grub_printf ("%-12llu", (unsigned long long) info->size);
       else
-       grub_printf ("%-12s", grub_get_human_size (file->size,
-                                                  GRUB_HUMAN_SIZE_SHORT));
-      grub_file_close (file);
-      grub_free (pathname);
+       grub_printf ("%-12s", grub_get_human_size (info->size,
+                                                  GRUB_HUMAN_SIZE_SHORT));    
     }
   else
     grub_printf ("%-12s", _("DIR"));
index 15f7d9dc6f6a9f712c45d3a48d19864a88dc6fb5..15e64d26b38ece3eea71bf72c2e096d50238da11 100644 (file)
@@ -565,6 +565,7 @@ grub_affs_dir_iter (const char *filename, enum grub_fshelp_filetype filetype,
   info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR);
   info.mtimeset = 1;
   info.mtime = aftime2ctime (&node->di.mtime);
+  info.size = grub_be_to_cpu32 (node->di.size);
   grub_free (node);
   return ctx->hook (filename, &info, ctx->hook_data);
 }
index 4a7ace117857f4078137605615e98a22766a4578..73a05b2b4a72b1ae433ae3fae25dabe00c880562 100644 (file)
@@ -155,9 +155,10 @@ grub_archelp_dir (struct grub_archelp_data *data,
     {
       grub_int32_t mtime;
       grub_uint32_t mode;
+      grub_uint64_t size;
       grub_err_t err;
 
-      if (arcops->find_file (data, &name, &mtime, &mode))
+      if (arcops->find_file (data, &name, &mtime, &mode, &size))
        goto fail;
 
       if (mode == GRUB_ARCHELP_ATTR_END)
@@ -189,6 +190,7 @@ grub_archelp_dir (struct grub_archelp_data *data,
                  info.mtime = mtime;
                  info.mtimeset = 1;
                }
+             info.size = size;
              if (hook (n, &info, hook_data))
                {
                  grub_free (name);
@@ -248,8 +250,9 @@ grub_archelp_open (struct grub_archelp_data *data,
     {
       grub_uint32_t mode;
       int restart;
+      grub_uint64_t size;
       
-      if (arcops->find_file (data, &fn, NULL, &mode))
+      if (arcops->find_file (data, &fn, NULL, &mode, &size))
        goto fail;
 
       if (mode == GRUB_ARCHELP_ATTR_END)
index 36b01efc86cd07fc791e90c0312f0648453b366b..22acd50a038ca32d8fe8a53b2480195145ee8081 100644 (file)
@@ -889,6 +889,7 @@ grub_bfs_dir_iter (const char *name, grub_uint64_t value,
   info.mtime = grub_bfs_to_cpu64 (ino.mtime) >> 16;
 #endif
   info.dir = ((grub_bfs_to_cpu32 (ino.mode) & ATTR_TYPE) == ATTR_DIR);
+  info.size = grub_bfs_to_cpu64 (ino.size);
   return ctx->hook (name, &info, ctx->hook_data);
 }
 
index 196f3017c744c385d35cfef370b101b4b7cf4f60..ee0c8fde6a73e1d197c312ca2d5710d240207599 100644 (file)
@@ -1580,6 +1580,7 @@ grub_btrfs_dir (grub_device_t device, const char *path,
          else
            {
              info.mtime = grub_le_to_cpu64 (inode.mtime.sec);
+             info.size = grub_le_to_cpu64 (inode.size);
              info.mtimeset = 1;
            }
          c = cdirel->name[grub_le_to_cpu16 (cdirel->n)];
index c79ec433a95acafe75517b8da284aa09388eafea..efc29d5680f3b3a31af8decbcb64e89c31d2fb27 100644 (file)
@@ -44,7 +44,8 @@ struct grub_archelp_data
 static grub_err_t
 grub_cbfs_find_file (struct grub_archelp_data *data, char **name,
                     grub_int32_t *mtime,
-                    grub_uint32_t *mode)
+                    grub_uint32_t *mode,
+                    grub_uint64_t *size)
 {
   grub_size_t offset;
   for (;;
@@ -71,6 +72,7 @@ grub_cbfs_find_file (struct grub_archelp_data *data, char **name,
          return GRUB_ERR_NONE;
        }
       data->size = grub_be_to_cpu32 (hd.len);
+      *size = grub_be_to_cpu32 (hd.len);
       (void) mtime;
       offset = grub_be_to_cpu32 (hd.offset);
 
index b0ae9f445cc6b91d4b5f4bc373fd8e7a8c94914b..eedc18ef61a9210dc834760ede28a511b0f9071a 100644 (file)
@@ -38,7 +38,8 @@ struct grub_archelp_data
 
 static grub_err_t
 grub_cpio_find_file (struct grub_archelp_data *data, char **name,
-                    grub_int32_t *mtime, grub_uint32_t *mode)
+                    grub_int32_t *mtime, grub_uint32_t *mode,
+                    grub_uint64_t *size)
 {
   struct head hd;
   grub_size_t namesize;
@@ -86,6 +87,7 @@ grub_cpio_find_file (struct grub_archelp_data *data, char **name,
 
   data->dofs = data->hofs + ALIGN_CPIO (sizeof (hd) + namesize);
   data->next_hofs = data->dofs + ALIGN_CPIO (data->size);
+  *size = data->size;
   return GRUB_ERR_NONE;
 }
 
index 46fb76f55b12d0080333c9af3505d989b615cd5b..7107ef77d10b5b25c1536794e510e8d484cdeedc 100644 (file)
@@ -884,6 +884,8 @@ grub_ext2_dir_iter (const char *filename, enum grub_fshelp_filetype filetype,
     {
       info.mtimeset = 1;
       info.mtime = grub_le_to_cpu32 (node->inode.mtime);
+      info.size = grub_le_to_cpu32 (node->inode.size);
+      info.size |= ((grub_off_t) grub_le_to_cpu32 (node->inode.size_high)) << 32;
     }
 
   info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR);
index e84f6c6722c04ea26ee3bd4b1fbc7d332c7a1381..49c4ba11b205ed7fa704a910df9138ab0f5c1361 100644 (file)
@@ -938,6 +938,8 @@ grub_fat_find_dir (grub_disk_t disk, struct grub_fat_data *data,
 #endif
          data->cur_cluster_num = ~0U;
 
+         info.size = data->file_size;
+
          if (call_hook)
            hook (ctxt.filename, &info, hook_data);
 
index 25414a5c5ba787f3205082b46be074064f5e44c2..c16d7101a48aceaa5dd52e40ddfe53a0b6b52b94 100644 (file)
@@ -1237,6 +1237,7 @@ grub_hfs_dir_hook (struct grub_hfs_record *rec, void *hook_arg)
       info.dir = 0;
       info.mtimeset = 1;
       info.mtime = grub_be_to_cpu32 (frec->mtime) - 2082844800;
+      info.size = grub_be_to_cpu32 (frec->size);
       return ctx->hook (fname, &info, ctx->hook_data);
     }
 
index 7905624508a903b38f8c52bd3e3965091b79ca90..a2110ef90f0d27cc33a614a828edb8d25c275226 100644 (file)
@@ -917,6 +917,7 @@ grub_hfsplus_dir_iter (const char *filename,
   info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR);
   info.mtimeset = 1;
   info.mtime = node->mtime;
+  info.size = node->size;
   info.case_insensitive = !! (filetype & GRUB_FSHELP_CASE_INSENSITIVE);
   grub_free (node);
   return ctx->hook (filename, &info, ctx->hook_data);
index 69e61ca023145ce491caa90ebaf0068e4b962168..9240a4db9ec5e4e2c5740b742eb66c1990673dbc 100644 (file)
@@ -861,7 +861,7 @@ grub_iso9660_dir_iter (const char *filename,
   grub_memset (&info, 0, sizeof (info));
   info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR);
   info.mtimeset = !!iso9660_to_unixtime2 (&node->dirents[0].mtime, &info.mtime);
-
+  info.size = get_node_size (node);
   grub_free (node);
   return ctx->hook (filename, &info, ctx->hook_data);
 }
index 26d77164716b76c1f3723fa3e016e7daf45c3b98..af457442f11f260facfc7793873206f6b62ece5e 100644 (file)
@@ -778,6 +778,7 @@ grub_jfs_dir (grub_device_t device, const char *path,
                  & GRUB_JFS_FILETYPE_MASK) == GRUB_JFS_FILETYPE_DIR;
       info.mtimeset = 1;
       info.mtime = grub_le_to_cpu32 (inode.mtime.sec);
+      info.size = grub_le_to_cpu64 (inode.size);
       if (hook (diro->name, &info, hook_data))
        goto fail;
     }
index 98e1b71ec3976468b81839d53914a9260c36eba6..30a02a88a7a3be53771493a70316fcdb39a6d468 100644 (file)
@@ -576,6 +576,7 @@ grub_minix_dir (grub_device_t device, const char *path,
                   & GRUB_MINIX_IFDIR) == GRUB_MINIX_IFDIR);
       info.mtimeset = 1;
       info.mtime = grub_minix_to_cpu32 (data->inode.mtime);
+      info.size = GRUB_MINIX_INODE_SIZE (data);
 
       if (hook (filename, &info, hook_data) ? 1 : 0)
        break;
index 1318f214076d941525a475d678847ba49a4d42d9..0332992d5288d8ade9058a83d487230c02039d80 100644 (file)
@@ -1066,6 +1066,7 @@ grub_nilfs2_dir_iter (const char *filename, enum grub_fshelp_filetype filetype,
     {
       info.mtimeset = 1;
       info.mtime = grub_le_to_cpu64 (node->inode.i_mtime);
+      info.size = grub_le_to_cpu64 (node->inode.i_size);
     }
 
   info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR);
index a0ae44200afc017a18c338fd9430cf205050c7a4..fd1ae54f6ce6bc2b3f344136eebd9fb52254e1c6 100644 (file)
@@ -981,10 +981,13 @@ grub_ntfs_dir_iter (const char *filename, enum grub_fshelp_filetype filetype,
 
   grub_memset (&info, 0, sizeof (info));
   info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR);
+  init_file (node, node->ino);
   info.mtimeset = 1;
   info.mtime = grub_divmod64 (node->mtime, 10000000, 0) 
     - 86400ULL * 365 * (1970 - 1601)
     - 86400ULL * ((1970 - 1601) / 4) + 86400ULL * ((1970 - 1601) / 100);
+  info.mtime = node->size;
+  free_file (node);
   grub_free (node);
   return ctx->hook (filename, &info, ctx->hook_data);
 }
index eaa7adead6b05d55e365be924eb538a80df268e4..0ff3d33c2444ce6aa3186756db2a0379d558916a 100644 (file)
@@ -1271,6 +1271,7 @@ grub_reiserfs_dir_iter (const char *filename,
   info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR);
   info.mtimeset = 1;
   info.mtime = node->mtime;
+  info.size = node->size;
   grub_free (node);
   return ctx->hook (filename, &info, ctx->hook_data);
 }
index 2e35444085fd968c5259436db530159f2ccd60db..4d2d9fd151391d403a91187ba46a411e73d67f14 100644 (file)
@@ -331,6 +331,7 @@ grub_romfs_dir_iter (const char *filename, enum grub_fshelp_filetype filetype,
   grub_memset (&info, 0, sizeof (info));
 
   info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR);
+  info.size = grub_be_to_cpu32 (node->file.size);
   grub_free (node);
   return ctx->hook (filename, &info, ctx->hook_data);
 }
index e7d2f72f3eef167f841643d5d903a41fb4d07d80..9780b42c6759337d3887fa6c0f533133941b4db9 100644 (file)
@@ -671,6 +671,7 @@ grub_sfs_dir_iter (const char *filename, enum grub_fshelp_filetype filetype,
   info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR);
   info.mtime = node->mtime + 8 * 365 * 86400 + 86400 * 2;
   info.mtimeset = 1;
+  info.size = node->size;
   grub_free (node->cache);
   grub_free (node);
   return ctx->hook (filename, &info, ctx->hook_data);
index cb3cc3a6eab480a58898d0992d9663517ab932aa..0cda4f611ab163cf8bd28d19a1f22bf4ed1643a2 100644 (file)
@@ -656,6 +656,15 @@ grub_squash_dir_iter (const char *filename, enum grub_fshelp_filetype filetype,
   info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR);
   info.mtimeset = 1;
   info.mtime = grub_le_to_cpu32 (node->ino.mtime);
+  switch (node->ino.type)
+    {
+    case grub_cpu_to_le16_compile_time (SQUASH_TYPE_LONG_REGULAR):
+      info.size = grub_le_to_cpu64 (node->ino.long_file.size);
+      break;
+    case grub_cpu_to_le16_compile_time (SQUASH_TYPE_REGULAR):
+      info.size = grub_le_to_cpu32 (node->ino.file.size);
+      break;
+    }
   grub_free (node);
   return ctx->hook (filename, &info, ctx->hook_data);
 }
index 85382974ce26af27b155c719edab009af0b350bd..e63e3c01c49b8f0e25bde2eefa2b9421837eb95d 100644 (file)
@@ -72,7 +72,8 @@ struct grub_archelp_data
 static grub_err_t
 grub_cpio_find_file (struct grub_archelp_data *data, char **name,
                     grub_int32_t *mtime,
-                    grub_uint32_t *mode)
+                    grub_uint32_t *mode,
+                    grub_uint64_t *size)
 {
   struct head hd;
   int reread = 0, have_longname = 0, have_longlink = 0;
@@ -200,6 +201,7 @@ grub_cpio_find_file (struct grub_archelp_data *data, char **name,
          grub_memcpy (data->linkname, hd.linkname, sizeof (hd.linkname));
          data->linkname[100] = 0;
        }
+      *size = data->size;
       return GRUB_ERR_NONE;
     }
   return GRUB_ERR_NONE;
index 60ce928306093d32b2857a53e4356132fc4dd55f..c80bd587fb1bbcba21b8025cfe0e0068abc558b8 100644 (file)
@@ -1072,6 +1072,7 @@ grub_udf_dir_iter (const char *filename, enum grub_fshelp_filetype filetype,
       info.mtimeset = !!grub_datetime2unixtime (&datetime, &info.mtime);
 
       info.mtime -= 60 * tz;
+      info.size = U64 (node->block.fe.file_size);
     }
   grub_free (node);
   return ctx->hook (filename, &info, ctx->hook_data);
index c9c2556d12926a3b4117c961649bb74cfbd498e5..fabed017e2b5b74267928430d7e01bd9625127bd 100644 (file)
@@ -711,6 +711,8 @@ grub_ufs_dir (grub_device_t device, const char *path,
 #endif
       info.mtimeset = 1;
 
+      info.size = grub_ufs_to_cpu64 (inode.size);
+
       if (hook (filename, &info, hook_data))
        {
          grub_free (filename);
index 7cd3e07bf7bad1a290a172d5c3576b11e8d7c048..b611e41cdd79c35a7b26e13a37bc3054e1509fe2 100644 (file)
@@ -732,6 +732,7 @@ grub_xfs_dir_iter (const char *filename, enum grub_fshelp_filetype filetype,
     {
       info.mtimeset = 1;
       info.mtime = grub_be_to_cpu32 (node->inode.mtime.sec);
+      info.size = grub_be_to_cpu64 (node->inode.size);
     }
   info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR);
   grub_free (node);
index 52314040f1deb9d7c688f2a88566ab37a2a698c7..06c6198e219c56ffcb06f5acbb8633ce363c4fd7 100644 (file)
@@ -3999,6 +3999,8 @@ iterate_zap (const char *name, grub_uint64_t val, struct grub_zfs_dir_ctx *ctx)
       info.mtimeset = 1;
       info.mtime = grub_zfs_to_cpu64 (grub_get_unaligned64 ((char *) sahdrp + hdrsize + SA_MTIME_OFFSET), dn.endian);
       info.case_insensitive = ctx->data->subvol.case_insensitive;
+      info.size = grub_zfs_to_cpu64 (grub_get_unaligned64 ((char *) sahdrp + hdrsize + SA_SIZE_OFFSET), dn.endian);
+
     }
   
   if (dn.dn.dn_bonustype == DMU_OT_ZNODE)
@@ -4006,6 +4008,7 @@ iterate_zap (const char *name, grub_uint64_t val, struct grub_zfs_dir_ctx *ctx)
       info.mtimeset = 1;
       info.mtime = grub_zfs_to_cpu64 (((znode_phys_t *) DN_BONUS (&dn.dn))->zp_mtime[0],
                                      dn.endian);
+      info.size = grub_zfs_to_cpu64 (((znode_phys_t *) DN_BONUS (&dn.dn))->zp_size, dn.endian);
     }
   info.dir = (dn.dn.dn_type == DMU_OT_DIRECTORY_CONTENTS);
   grub_dprintf ("zfs", "type=%d, name=%s\n", 
index 2611d7f45005efae5cc61a896b7506ca451062d9..7129ec561b6843ec68a00c3e2185ae477bfc2081 100644 (file)
@@ -40,7 +40,8 @@ struct grub_archelp_ops
   grub_err_t
   (*find_file) (struct grub_archelp_data *data, char **name,
                grub_int32_t *mtime,
-               grub_archelp_mode_t *mode);
+               grub_archelp_mode_t *mode,
+               grub_uint64_t *size);
 
   char *
   (*get_link_target) (struct grub_archelp_data *data);
index e4517972b8d2b95e9d02d125a94cf72d6555ed00..66d84cab4478cea5b2226f8997cabd3a01d1460f 100644 (file)
@@ -39,6 +39,7 @@ struct grub_dirhook_info
   unsigned mtimeset:1;
   unsigned case_insensitive:1;
   grub_int32_t mtime;
+  grub_off_t size;
 };
 
 typedef int (*grub_fs_dir_hook_t) (const char *filename,