* grub-core/fs/ntfs.c (read_data): Move code for compressed data to ...

* grub-core/fs/ntfscomp.c (ntfscomp): ... here.
This commit is contained in:
Vladimir 'phcoder' Serbinenko 2013-10-21 02:48:19 +02:00
parent 2cc679adae
commit 63efa602ff
4 changed files with 67 additions and 68 deletions

View file

@ -1,3 +1,8 @@
2013-10-21 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/fs/ntfs.c (read_data): Move code for compressed data to ...
* grub-core/fs/ntfscomp.c (ntfscomp): ... here.
2013-10-20 Vladimir Serbinenko <phcoder@gmail.com> 2013-10-20 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/kern/disk.c (grub_disk_write): Use malloc/free instead of * grub-core/kern/disk.c (grub_disk_write): Use malloc/free instead of

View file

@ -373,7 +373,6 @@ read_data (struct grub_ntfs_attr *at, grub_uint8_t *pa, grub_uint8_t *dest,
grub_disk_addr_t ofs, grub_size_t len, int cached, grub_disk_addr_t ofs, grub_size_t len, int cached,
grub_disk_read_hook_t read_hook, void *read_hook_data) grub_disk_read_hook_t read_hook, void *read_hook_data)
{ {
grub_disk_addr_t vcn;
struct grub_ntfs_rlst cc, *ctx; struct grub_ntfs_rlst cc, *ctx;
if (len == 0) if (len == 0)
@ -393,52 +392,23 @@ read_data (struct grub_ntfs_attr *at, grub_uint8_t *pa, grub_uint8_t *dest,
return 0; return 0;
} }
if (u16at (pa, 0xC) & GRUB_NTFS_FLAG_COMPRESSED)
ctx->flags |= GRUB_NTFS_RF_COMP;
else
ctx->flags &= ~GRUB_NTFS_RF_COMP;
ctx->cur_run = pa + u16at (pa, 0x20); ctx->cur_run = pa + u16at (pa, 0x20);
if (ctx->flags & GRUB_NTFS_RF_COMP) ctx->next_vcn = u32at (pa, 0x10);
ctx->curr_lcn = 0;
if ((pa[0xC] & GRUB_NTFS_FLAG_COMPRESSED)
&& !(at->flags & GRUB_NTFS_AF_GPOS))
{ {
if (!cached) if (!cached)
return grub_error (GRUB_ERR_BAD_FS, "attribute can\'t be compressed"); return grub_error (GRUB_ERR_BAD_FS, "attribute can\'t be compressed");
if (at->sbuf) return (grub_ntfscomp_func) ? grub_ntfscomp_func (dest, ofs, len, ctx)
{ : grub_error (GRUB_ERR_BAD_FS, N_("module `%s' isn't loaded"),
if ((ofs & (~(GRUB_NTFS_COM_LEN - 1))) == at->save_pos) "ntfscomp");
{
grub_disk_addr_t n;
n = GRUB_NTFS_COM_LEN - (ofs - at->save_pos);
if (n > len)
n = len;
grub_memcpy (dest, at->sbuf + ofs - at->save_pos, n);
if (n == len)
return 0;
dest += n;
len -= n;
ofs += n;
}
}
else
{
at->sbuf = grub_malloc (GRUB_NTFS_COM_LEN);
if (at->sbuf == NULL)
return grub_errno;
at->save_pos = 1;
}
vcn = ctx->target_vcn = (ofs >> GRUB_NTFS_COM_LOG_LEN) * (GRUB_NTFS_COM_SEC >> ctx->comp.log_spc);
ctx->target_vcn &= ~0xFULL;
} }
else
vcn = ctx->target_vcn = ofs >> (GRUB_NTFS_BLK_SHR + ctx->comp.log_spc);
ctx->next_vcn = u32at (pa, 0x10); ctx->target_vcn = ofs >> (GRUB_NTFS_BLK_SHR + ctx->comp.log_spc);
ctx->curr_lcn = 0;
while (ctx->next_vcn <= ctx->target_vcn) while (ctx->next_vcn <= ctx->target_vcn)
{ {
if (grub_ntfs_read_run_list (ctx)) if (grub_ntfs_read_run_list (ctx))
@ -467,20 +437,12 @@ read_data (struct grub_ntfs_attr *at, grub_uint8_t *pa, grub_uint8_t *dest,
return 0; return 0;
} }
if (!(ctx->flags & GRUB_NTFS_RF_COMP)) grub_fshelp_read_file (ctx->comp.disk, (grub_fshelp_node_t) ctx,
{ read_hook, read_hook_data, ofs, len,
grub_fshelp_read_file (ctx->comp.disk, (grub_fshelp_node_t) ctx, (char *) dest,
read_hook, read_hook_data, ofs, len, grub_ntfs_read_block, ofs + len,
(char *) dest, ctx->comp.log_spc, 0);
grub_ntfs_read_block, ofs + len, return grub_errno;
ctx->comp.log_spc, 0);
return grub_errno;
}
return (grub_ntfscomp_func) ? grub_ntfscomp_func (at, dest, ofs, len, ctx,
vcn) :
grub_error (GRUB_ERR_BAD_FS, N_("module `%s' isn't loaded"),
"ntfscomp");
} }
static grub_err_t static grub_err_t

View file

@ -289,10 +289,46 @@ read_block (struct grub_ntfs_rlst *ctx, grub_uint8_t *buf, grub_size_t num)
} }
static grub_err_t static grub_err_t
ntfscomp (struct grub_ntfs_attr *at, grub_uint8_t *dest, grub_disk_addr_t ofs, ntfscomp (grub_uint8_t *dest, grub_disk_addr_t ofs,
grub_size_t len, struct grub_ntfs_rlst *ctx, grub_disk_addr_t vcn) grub_size_t len, struct grub_ntfs_rlst *ctx)
{ {
grub_err_t ret; grub_err_t ret;
grub_disk_addr_t vcn;
if (ctx->attr->sbuf)
{
if ((ofs & (~(GRUB_NTFS_COM_LEN - 1))) == ctx->attr->save_pos)
{
grub_disk_addr_t n;
n = GRUB_NTFS_COM_LEN - (ofs - ctx->attr->save_pos);
if (n > len)
n = len;
grub_memcpy (dest, ctx->attr->sbuf + ofs - ctx->attr->save_pos, n);
if (n == len)
return 0;
dest += n;
len -= n;
ofs += n;
}
}
else
{
ctx->attr->sbuf = grub_malloc (GRUB_NTFS_COM_LEN);
if (ctx->attr->sbuf == NULL)
return grub_errno;
ctx->attr->save_pos = 1;
}
vcn = ctx->target_vcn = (ofs >> GRUB_NTFS_COM_LOG_LEN) * (GRUB_NTFS_COM_SEC >> ctx->comp.log_spc);
ctx->target_vcn &= ~0xFULL;
while (ctx->next_vcn <= ctx->target_vcn)
{
if (grub_ntfs_read_run_list (ctx))
return grub_errno;
}
ctx->comp.comp_head = ctx->comp.comp_tail = 0; ctx->comp.comp_head = ctx->comp.comp_tail = 0;
ctx->comp.cbuf = grub_malloc (1 << (ctx->comp.log_spc + GRUB_NTFS_BLK_SHR)); ctx->comp.cbuf = grub_malloc (1 << (ctx->comp.log_spc + GRUB_NTFS_BLK_SHR));
@ -317,19 +353,19 @@ ntfscomp (struct grub_ntfs_attr *at, grub_uint8_t *dest, grub_disk_addr_t ofs,
grub_uint32_t t, n, o; grub_uint32_t t, n, o;
t = ctx->target_vcn << (ctx->comp.log_spc + GRUB_NTFS_BLK_SHR); t = ctx->target_vcn << (ctx->comp.log_spc + GRUB_NTFS_BLK_SHR);
if (read_block (ctx, at->sbuf, 1)) if (read_block (ctx, ctx->attr->sbuf, 1))
{ {
ret = grub_errno; ret = grub_errno;
goto quit; goto quit;
} }
at->save_pos = t; ctx->attr->save_pos = t;
o = ofs % GRUB_NTFS_COM_LEN; o = ofs % GRUB_NTFS_COM_LEN;
n = GRUB_NTFS_COM_LEN - o; n = GRUB_NTFS_COM_LEN - o;
if (n > len) if (n > len)
n = len; n = len;
grub_memcpy (dest, &at->sbuf[o], n); grub_memcpy (dest, &ctx->attr->sbuf[o], n);
if (n == len) if (n == len)
goto quit; goto quit;
dest += n; dest += n;
@ -349,15 +385,15 @@ ntfscomp (struct grub_ntfs_attr *at, grub_uint8_t *dest, grub_disk_addr_t ofs,
grub_uint32_t t; grub_uint32_t t;
t = ctx->target_vcn << (ctx->comp.log_spc + GRUB_NTFS_BLK_SHR); t = ctx->target_vcn << (ctx->comp.log_spc + GRUB_NTFS_BLK_SHR);
if (read_block (ctx, at->sbuf, 1)) if (read_block (ctx, ctx->attr->sbuf, 1))
{ {
ret = grub_errno; ret = grub_errno;
goto quit; goto quit;
} }
at->save_pos = t; ctx->attr->save_pos = t;
grub_memcpy (dest, at->sbuf, len); grub_memcpy (dest, ctx->attr->sbuf, len);
} }
quit: quit:

View file

@ -98,9 +98,7 @@ enum
enum enum
{ {
GRUB_NTFS_RF_COMP = 1, GRUB_NTFS_RF_BLNK = 1
GRUB_NTFS_RF_CBLK = 2,
GRUB_NTFS_RF_BLNK = 4
}; };
struct grub_ntfs_bpb struct grub_ntfs_bpb
@ -187,12 +185,10 @@ struct grub_ntfs_rlst
struct grub_ntfs_comp comp; struct grub_ntfs_comp comp;
}; };
typedef grub_err_t (*grub_ntfscomp_func_t) (struct grub_ntfs_attr * at, typedef grub_err_t (*grub_ntfscomp_func_t) (grub_uint8_t *dest,
grub_uint8_t *dest,
grub_disk_addr_t ofs, grub_disk_addr_t ofs,
grub_size_t len, grub_size_t len,
struct grub_ntfs_rlst * ctx, struct grub_ntfs_rlst * ctx);
grub_disk_addr_t vcn);
extern grub_ntfscomp_func_t grub_ntfscomp_func; extern grub_ntfscomp_func_t grub_ntfscomp_func;