Compare commits

...

1 Commits

Author SHA1 Message Date
Vladimir Serbinenko
8e2fb1e3ce More efficient retrieval of file size 2013-10-27 17:24:35 +01:00
27 changed files with 55 additions and 34 deletions

View 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"));

View 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);
}

View 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)

View 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);
}

View 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)];

View 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);

View 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;
}

View 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);

View 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);

View 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);
}

View 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);

View 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);
}

View 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;
}

View 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;

View 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);

View 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);
}

View 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);
}

View 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);
}

View 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);

View 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);
}

View 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;

View 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);

View 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);

View 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);

View 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",

View 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);

View 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,