2007-12-21 11:41:23 +00:00
|
|
|
/* ntfscomp.c - compression support for the NTFS filesystem */
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2007 Free Software Foundation, Inc.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <grub/file.h>
|
|
|
|
#include <grub/mm.h>
|
|
|
|
#include <grub/misc.h>
|
|
|
|
#include <grub/disk.h>
|
|
|
|
#include <grub/dl.h>
|
|
|
|
#include <grub/ntfs.h>
|
|
|
|
|
2011-04-11 21:01:51 +00:00
|
|
|
GRUB_MOD_LICENSE ("GPLv3+");
|
|
|
|
|
2007-12-21 11:41:23 +00:00
|
|
|
static grub_err_t
|
|
|
|
decomp_nextvcn (struct grub_ntfs_comp *cc)
|
|
|
|
{
|
|
|
|
if (cc->comp_head >= cc->comp_tail)
|
2009-12-24 22:53:05 +00:00
|
|
|
return grub_error (GRUB_ERR_BAD_FS, "compression block overflown");
|
2007-12-21 11:41:23 +00:00
|
|
|
if (grub_disk_read
|
|
|
|
(cc->disk,
|
2012-05-15 15:09:14 +00:00
|
|
|
(cc->comp_table[cc->comp_head].next_lcn -
|
2013-01-05 16:36:04 +00:00
|
|
|
(cc->comp_table[cc->comp_head].next_vcn - cc->cbuf_vcn)) << cc->log_spc,
|
|
|
|
0,
|
|
|
|
1 << (cc->log_spc + GRUB_NTFS_BLK_SHR), cc->cbuf))
|
2007-12-21 11:41:23 +00:00
|
|
|
return grub_errno;
|
|
|
|
cc->cbuf_vcn++;
|
2012-05-15 15:09:14 +00:00
|
|
|
if ((cc->cbuf_vcn >= cc->comp_table[cc->comp_head].next_vcn))
|
2007-12-21 11:41:23 +00:00
|
|
|
cc->comp_head++;
|
|
|
|
cc->cbuf_ofs = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static grub_err_t
|
2013-01-11 06:41:05 +00:00
|
|
|
decomp_getch (struct grub_ntfs_comp *cc, grub_uint8_t *res)
|
2007-12-21 11:41:23 +00:00
|
|
|
{
|
2013-01-05 16:36:04 +00:00
|
|
|
if (cc->cbuf_ofs >= (1U << (cc->log_spc + GRUB_NTFS_BLK_SHR)))
|
2007-12-21 11:41:23 +00:00
|
|
|
{
|
|
|
|
if (decomp_nextvcn (cc))
|
|
|
|
return grub_errno;
|
|
|
|
}
|
2013-01-11 06:41:05 +00:00
|
|
|
*res = cc->cbuf[cc->cbuf_ofs++];
|
2007-12-21 11:41:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static grub_err_t
|
|
|
|
decomp_get16 (struct grub_ntfs_comp *cc, grub_uint16_t * res)
|
|
|
|
{
|
2013-01-11 06:41:05 +00:00
|
|
|
grub_uint8_t c1 = 0, c2 = 0;
|
2007-12-21 11:41:23 +00:00
|
|
|
|
|
|
|
if ((decomp_getch (cc, &c1)) || (decomp_getch (cc, &c2)))
|
|
|
|
return grub_errno;
|
|
|
|
*res = ((grub_uint16_t) c2) * 256 + ((grub_uint16_t) c1);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Decompress a block (4096 bytes) */
|
|
|
|
static grub_err_t
|
2013-01-11 06:41:05 +00:00
|
|
|
decomp_block (struct grub_ntfs_comp *cc, grub_uint8_t *dest)
|
2007-12-21 11:41:23 +00:00
|
|
|
{
|
|
|
|
grub_uint16_t flg, cnt;
|
|
|
|
|
|
|
|
if (decomp_get16 (cc, &flg))
|
|
|
|
return grub_errno;
|
|
|
|
cnt = (flg & 0xFFF) + 1;
|
|
|
|
|
|
|
|
if (dest)
|
|
|
|
{
|
|
|
|
if (flg & 0x8000)
|
|
|
|
{
|
2013-01-11 06:41:05 +00:00
|
|
|
grub_uint8_t tag;
|
2007-12-21 11:41:23 +00:00
|
|
|
grub_uint32_t bits, copied;
|
|
|
|
|
|
|
|
bits = copied = tag = 0;
|
|
|
|
while (cnt > 0)
|
|
|
|
{
|
2011-10-27 00:59:45 +00:00
|
|
|
if (copied > GRUB_NTFS_COM_LEN)
|
2007-12-21 11:41:23 +00:00
|
|
|
return grub_error (GRUB_ERR_BAD_FS,
|
2009-12-24 22:53:05 +00:00
|
|
|
"compression block too large");
|
2007-12-21 11:41:23 +00:00
|
|
|
|
|
|
|
if (!bits)
|
|
|
|
{
|
|
|
|
if (decomp_getch (cc, &tag))
|
|
|
|
return grub_errno;
|
|
|
|
|
|
|
|
bits = 8;
|
|
|
|
cnt--;
|
|
|
|
if (cnt <= 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (tag & 1)
|
|
|
|
{
|
|
|
|
grub_uint32_t i, len, delta, code, lmask, dshift;
|
2016-02-17 16:56:41 +00:00
|
|
|
grub_uint16_t word = 0;
|
2007-12-21 11:41:23 +00:00
|
|
|
|
|
|
|
if (decomp_get16 (cc, &word))
|
|
|
|
return grub_errno;
|
|
|
|
|
|
|
|
code = word;
|
|
|
|
cnt -= 2;
|
|
|
|
|
|
|
|
if (!copied)
|
|
|
|
{
|
2009-12-24 22:53:05 +00:00
|
|
|
grub_error (GRUB_ERR_BAD_FS, "nontext window empty");
|
2007-12-21 11:41:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = copied - 1, lmask = 0xFFF, dshift = 12; i >= 0x10;
|
|
|
|
i >>= 1)
|
|
|
|
{
|
|
|
|
lmask >>= 1;
|
|
|
|
dshift--;
|
|
|
|
}
|
|
|
|
|
|
|
|
delta = code >> dshift;
|
|
|
|
len = (code & lmask) + 3;
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
dest[copied] = dest[copied - delta - 1];
|
|
|
|
copied++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-01-11 06:41:05 +00:00
|
|
|
grub_uint8_t ch = 0;
|
2007-12-21 11:41:23 +00:00
|
|
|
|
|
|
|
if (decomp_getch (cc, &ch))
|
|
|
|
return grub_errno;
|
|
|
|
dest[copied++] = ch;
|
|
|
|
cnt--;
|
|
|
|
}
|
|
|
|
tag >>= 1;
|
|
|
|
bits--;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-10-27 00:59:45 +00:00
|
|
|
if (cnt != GRUB_NTFS_COM_LEN)
|
2007-12-21 11:41:23 +00:00
|
|
|
return grub_error (GRUB_ERR_BAD_FS,
|
2009-12-24 22:53:05 +00:00
|
|
|
"invalid compression block size");
|
2007-12-21 11:41:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (cnt > 0)
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
|
2013-01-05 16:36:04 +00:00
|
|
|
n = (1 << (cc->log_spc + GRUB_NTFS_BLK_SHR)) - cc->cbuf_ofs;
|
2007-12-21 11:41:23 +00:00
|
|
|
if (n > cnt)
|
|
|
|
n = cnt;
|
|
|
|
if ((dest) && (n))
|
|
|
|
{
|
2009-06-18 13:51:06 +00:00
|
|
|
grub_memcpy (dest, &cc->cbuf[cc->cbuf_ofs], n);
|
2007-12-21 11:41:23 +00:00
|
|
|
dest += n;
|
|
|
|
}
|
|
|
|
cnt -= n;
|
|
|
|
cc->cbuf_ofs += n;
|
|
|
|
if ((cnt) && (decomp_nextvcn (cc)))
|
|
|
|
return grub_errno;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static grub_err_t
|
2013-01-11 06:41:05 +00:00
|
|
|
read_block (struct grub_ntfs_rlst *ctx, grub_uint8_t *buf, grub_size_t num)
|
2007-12-21 11:41:23 +00:00
|
|
|
{
|
2013-01-05 16:36:04 +00:00
|
|
|
int log_cpb = GRUB_NTFS_LOG_COM_SEC - ctx->comp.log_spc;
|
2007-12-21 11:41:23 +00:00
|
|
|
|
|
|
|
while (num)
|
|
|
|
{
|
2012-05-04 15:37:17 +00:00
|
|
|
grub_size_t nn;
|
2007-12-21 11:41:23 +00:00
|
|
|
|
|
|
|
if ((ctx->target_vcn & 0xF) == 0)
|
|
|
|
{
|
|
|
|
|
2012-05-04 15:37:17 +00:00
|
|
|
if (ctx->comp.comp_head != ctx->comp.comp_tail
|
|
|
|
&& !(ctx->flags & GRUB_NTFS_RF_BLNK))
|
2009-12-24 22:53:05 +00:00
|
|
|
return grub_error (GRUB_ERR_BAD_FS, "invalid compression block");
|
2007-12-21 11:41:23 +00:00
|
|
|
ctx->comp.comp_head = ctx->comp.comp_tail = 0;
|
|
|
|
ctx->comp.cbuf_vcn = ctx->target_vcn;
|
2013-01-05 16:36:04 +00:00
|
|
|
ctx->comp.cbuf_ofs = (1 << (ctx->comp.log_spc + GRUB_NTFS_BLK_SHR));
|
2007-12-21 11:41:23 +00:00
|
|
|
if (ctx->target_vcn >= ctx->next_vcn)
|
|
|
|
{
|
|
|
|
if (grub_ntfs_read_run_list (ctx))
|
|
|
|
return grub_errno;
|
|
|
|
}
|
|
|
|
while (ctx->target_vcn + 16 > ctx->next_vcn)
|
|
|
|
{
|
2011-10-27 00:59:45 +00:00
|
|
|
if (ctx->flags & GRUB_NTFS_RF_BLNK)
|
2007-12-21 11:41:23 +00:00
|
|
|
break;
|
2012-05-15 15:09:14 +00:00
|
|
|
ctx->comp.comp_table[ctx->comp.comp_tail].next_vcn = ctx->next_vcn;
|
|
|
|
ctx->comp.comp_table[ctx->comp.comp_tail].next_lcn =
|
2007-12-21 11:41:23 +00:00
|
|
|
ctx->curr_lcn + ctx->next_vcn - ctx->curr_vcn;
|
|
|
|
ctx->comp.comp_tail++;
|
|
|
|
if (grub_ntfs_read_run_list (ctx))
|
|
|
|
return grub_errno;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-05 16:36:04 +00:00
|
|
|
nn = (16 - (unsigned) (ctx->target_vcn & 0xF)) >> log_cpb;
|
2007-12-21 11:41:23 +00:00
|
|
|
if (nn > num)
|
|
|
|
nn = num;
|
|
|
|
num -= nn;
|
|
|
|
|
2011-10-27 00:59:45 +00:00
|
|
|
if (ctx->flags & GRUB_NTFS_RF_BLNK)
|
2007-12-21 11:41:23 +00:00
|
|
|
{
|
2013-01-05 16:36:04 +00:00
|
|
|
ctx->target_vcn += nn << log_cpb;
|
2007-12-21 11:41:23 +00:00
|
|
|
if (ctx->comp.comp_tail == 0)
|
|
|
|
{
|
|
|
|
if (buf)
|
|
|
|
{
|
2011-10-27 00:59:45 +00:00
|
|
|
grub_memset (buf, 0, nn * GRUB_NTFS_COM_LEN);
|
|
|
|
buf += nn * GRUB_NTFS_COM_LEN;
|
2013-11-02 15:30:53 +00:00
|
|
|
if (grub_file_progress_hook && ctx->file)
|
|
|
|
grub_file_progress_hook (0, 0, nn * GRUB_NTFS_COM_LEN,
|
|
|
|
ctx->file);
|
2007-12-21 11:41:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while (nn)
|
|
|
|
{
|
|
|
|
if (decomp_block (&ctx->comp, buf))
|
|
|
|
return grub_errno;
|
|
|
|
if (buf)
|
2011-10-27 00:59:45 +00:00
|
|
|
buf += GRUB_NTFS_COM_LEN;
|
2013-11-02 15:30:53 +00:00
|
|
|
if (grub_file_progress_hook && ctx->file)
|
|
|
|
grub_file_progress_hook (0, 0, GRUB_NTFS_COM_LEN,
|
|
|
|
ctx->file);
|
2007-12-21 11:41:23 +00:00
|
|
|
nn--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-01-05 16:36:04 +00:00
|
|
|
nn <<= log_cpb;
|
2007-12-21 11:41:23 +00:00
|
|
|
while ((ctx->comp.comp_head < ctx->comp.comp_tail) && (nn))
|
|
|
|
{
|
2012-05-04 15:37:17 +00:00
|
|
|
grub_disk_addr_t tt;
|
2007-12-21 11:41:23 +00:00
|
|
|
|
|
|
|
tt =
|
2012-05-15 15:09:14 +00:00
|
|
|
ctx->comp.comp_table[ctx->comp.comp_head].next_vcn -
|
2007-12-21 11:41:23 +00:00
|
|
|
ctx->target_vcn;
|
|
|
|
if (tt > nn)
|
|
|
|
tt = nn;
|
|
|
|
ctx->target_vcn += tt;
|
|
|
|
if (buf)
|
|
|
|
{
|
|
|
|
if (grub_disk_read
|
|
|
|
(ctx->comp.disk,
|
2012-05-15 15:09:14 +00:00
|
|
|
(ctx->comp.comp_table[ctx->comp.comp_head].next_lcn -
|
|
|
|
(ctx->comp.comp_table[ctx->comp.comp_head].next_vcn -
|
2013-01-05 16:36:04 +00:00
|
|
|
ctx->target_vcn)) << ctx->comp.log_spc, 0,
|
|
|
|
tt << (ctx->comp.log_spc + GRUB_NTFS_BLK_SHR), buf))
|
2007-12-21 11:41:23 +00:00
|
|
|
return grub_errno;
|
2013-11-02 15:30:53 +00:00
|
|
|
if (grub_file_progress_hook && ctx->file)
|
|
|
|
grub_file_progress_hook (0, 0,
|
|
|
|
tt << (ctx->comp.log_spc
|
|
|
|
+ GRUB_NTFS_BLK_SHR),
|
|
|
|
ctx->file);
|
2013-01-05 16:36:04 +00:00
|
|
|
buf += tt << (ctx->comp.log_spc + GRUB_NTFS_BLK_SHR);
|
2007-12-21 11:41:23 +00:00
|
|
|
}
|
|
|
|
nn -= tt;
|
|
|
|
if (ctx->target_vcn >=
|
2012-05-15 15:09:14 +00:00
|
|
|
ctx->comp.comp_table[ctx->comp.comp_head].next_vcn)
|
2007-12-21 11:41:23 +00:00
|
|
|
ctx->comp.comp_head++;
|
|
|
|
}
|
|
|
|
if (nn)
|
|
|
|
{
|
|
|
|
if (buf)
|
|
|
|
{
|
|
|
|
if (grub_disk_read
|
|
|
|
(ctx->comp.disk,
|
|
|
|
(ctx->target_vcn - ctx->curr_vcn +
|
2013-01-05 16:36:04 +00:00
|
|
|
ctx->curr_lcn) << ctx->comp.log_spc, 0,
|
|
|
|
nn << (ctx->comp.log_spc + GRUB_NTFS_BLK_SHR), buf))
|
2007-12-21 11:41:23 +00:00
|
|
|
return grub_errno;
|
2013-01-05 16:36:04 +00:00
|
|
|
buf += nn << (ctx->comp.log_spc + GRUB_NTFS_BLK_SHR);
|
2013-11-02 15:30:53 +00:00
|
|
|
if (grub_file_progress_hook && ctx->file)
|
|
|
|
grub_file_progress_hook (0, 0,
|
|
|
|
nn << (ctx->comp.log_spc
|
|
|
|
+ GRUB_NTFS_BLK_SHR),
|
|
|
|
ctx->file);
|
2007-12-21 11:41:23 +00:00
|
|
|
}
|
|
|
|
ctx->target_vcn += nn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static grub_err_t
|
2013-10-21 00:48:19 +00:00
|
|
|
ntfscomp (grub_uint8_t *dest, grub_disk_addr_t ofs,
|
|
|
|
grub_size_t len, struct grub_ntfs_rlst *ctx)
|
2007-12-21 11:41:23 +00:00
|
|
|
{
|
|
|
|
grub_err_t ret;
|
2013-10-21 00:48:19 +00:00
|
|
|
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);
|
2013-11-02 15:30:53 +00:00
|
|
|
if (grub_file_progress_hook && ctx->file)
|
|
|
|
grub_file_progress_hook (0, 0, n, ctx->file);
|
2013-10-21 00:48:19 +00:00
|
|
|
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;
|
|
|
|
}
|
2007-12-21 11:41:23 +00:00
|
|
|
|
|
|
|
ctx->comp.comp_head = ctx->comp.comp_tail = 0;
|
2013-01-05 16:36:04 +00:00
|
|
|
ctx->comp.cbuf = grub_malloc (1 << (ctx->comp.log_spc + GRUB_NTFS_BLK_SHR));
|
2007-12-21 11:41:23 +00:00
|
|
|
if (!ctx->comp.cbuf)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
//ctx->comp.disk->read_hook = read_hook;
|
2013-02-27 16:19:15 +00:00
|
|
|
//ctx->comp.disk->read_hook_data = read_hook_data;
|
2007-12-21 11:41:23 +00:00
|
|
|
|
|
|
|
if ((vcn > ctx->target_vcn) &&
|
|
|
|
(read_block
|
2013-01-05 16:36:04 +00:00
|
|
|
(ctx, NULL, (vcn - ctx->target_vcn) >> (GRUB_NTFS_LOG_COM_SEC - ctx->comp.log_spc))))
|
2007-12-21 11:41:23 +00:00
|
|
|
{
|
|
|
|
ret = grub_errno;
|
|
|
|
goto quit;
|
|
|
|
}
|
|
|
|
|
2011-10-27 00:59:45 +00:00
|
|
|
if (ofs % GRUB_NTFS_COM_LEN)
|
2007-12-21 11:41:23 +00:00
|
|
|
{
|
|
|
|
grub_uint32_t t, n, o;
|
2013-11-02 15:30:53 +00:00
|
|
|
void *file = ctx->file;
|
|
|
|
|
|
|
|
ctx->file = 0;
|
2007-12-21 11:41:23 +00:00
|
|
|
|
2013-01-05 16:36:04 +00:00
|
|
|
t = ctx->target_vcn << (ctx->comp.log_spc + GRUB_NTFS_BLK_SHR);
|
2013-10-21 00:48:19 +00:00
|
|
|
if (read_block (ctx, ctx->attr->sbuf, 1))
|
2007-12-21 11:41:23 +00:00
|
|
|
{
|
|
|
|
ret = grub_errno;
|
|
|
|
goto quit;
|
|
|
|
}
|
|
|
|
|
2013-11-02 15:30:53 +00:00
|
|
|
ctx->file = file;
|
|
|
|
|
2013-10-21 00:48:19 +00:00
|
|
|
ctx->attr->save_pos = t;
|
2007-12-21 11:41:23 +00:00
|
|
|
|
2011-10-27 00:59:45 +00:00
|
|
|
o = ofs % GRUB_NTFS_COM_LEN;
|
|
|
|
n = GRUB_NTFS_COM_LEN - o;
|
2007-12-21 11:41:23 +00:00
|
|
|
if (n > len)
|
|
|
|
n = len;
|
2013-10-21 00:48:19 +00:00
|
|
|
grub_memcpy (dest, &ctx->attr->sbuf[o], n);
|
2013-11-02 15:30:53 +00:00
|
|
|
if (grub_file_progress_hook && ctx->file)
|
|
|
|
grub_file_progress_hook (0, 0, n, ctx->file);
|
2007-12-21 11:41:23 +00:00
|
|
|
if (n == len)
|
|
|
|
goto quit;
|
|
|
|
dest += n;
|
|
|
|
len -= n;
|
|
|
|
}
|
|
|
|
|
2011-10-27 00:59:45 +00:00
|
|
|
if (read_block (ctx, dest, len / GRUB_NTFS_COM_LEN))
|
2007-12-21 11:41:23 +00:00
|
|
|
{
|
|
|
|
ret = grub_errno;
|
|
|
|
goto quit;
|
|
|
|
}
|
|
|
|
|
2011-10-27 00:59:45 +00:00
|
|
|
dest += (len / GRUB_NTFS_COM_LEN) * GRUB_NTFS_COM_LEN;
|
|
|
|
len = len % GRUB_NTFS_COM_LEN;
|
2007-12-21 11:41:23 +00:00
|
|
|
if (len)
|
|
|
|
{
|
|
|
|
grub_uint32_t t;
|
2013-11-02 15:30:53 +00:00
|
|
|
void *file = ctx->file;
|
2007-12-21 11:41:23 +00:00
|
|
|
|
2013-11-02 15:30:53 +00:00
|
|
|
ctx->file = 0;
|
2013-01-05 16:36:04 +00:00
|
|
|
t = ctx->target_vcn << (ctx->comp.log_spc + GRUB_NTFS_BLK_SHR);
|
2013-10-21 00:48:19 +00:00
|
|
|
if (read_block (ctx, ctx->attr->sbuf, 1))
|
2007-12-21 11:41:23 +00:00
|
|
|
{
|
|
|
|
ret = grub_errno;
|
|
|
|
goto quit;
|
|
|
|
}
|
|
|
|
|
2013-10-21 00:48:19 +00:00
|
|
|
ctx->attr->save_pos = t;
|
2007-12-21 11:41:23 +00:00
|
|
|
|
2013-10-21 00:48:19 +00:00
|
|
|
grub_memcpy (dest, ctx->attr->sbuf, len);
|
2013-11-02 15:30:53 +00:00
|
|
|
if (grub_file_progress_hook && file)
|
|
|
|
grub_file_progress_hook (0, 0, len, file);
|
2007-12-21 11:41:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
quit:
|
|
|
|
//ctx->comp.disk->read_hook = 0;
|
|
|
|
if (ctx->comp.cbuf)
|
|
|
|
grub_free (ctx->comp.cbuf);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
GRUB_MOD_INIT (ntfscomp)
|
|
|
|
{
|
|
|
|
grub_ntfscomp_func = ntfscomp;
|
|
|
|
}
|
|
|
|
|
|
|
|
GRUB_MOD_FINI (ntfscomp)
|
|
|
|
{
|
|
|
|
grub_ntfscomp_func = NULL;
|
|
|
|
}
|