2007-08-03 07:44:01 +00:00
|
|
|
/* ntfs.c - NTFS filesystem */
|
|
|
|
/*
|
|
|
|
* GRUB -- GRand Unified Bootloader
|
2010-01-03 22:05:07 +00:00
|
|
|
* Copyright (C) 2007,2008,2009 Free Software Foundation, Inc.
|
2007-08-03 07:44:01 +00:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2011-10-27 00:59:45 +00:00
|
|
|
#define grub_fshelp_node grub_ntfs_file
|
|
|
|
|
2007-08-03 07:44:01 +00:00
|
|
|
#include <grub/file.h>
|
|
|
|
#include <grub/mm.h>
|
|
|
|
#include <grub/misc.h>
|
|
|
|
#include <grub/disk.h>
|
|
|
|
#include <grub/dl.h>
|
|
|
|
#include <grub/fshelp.h>
|
2007-12-21 11:41:23 +00:00
|
|
|
#include <grub/ntfs.h>
|
2009-11-09 17:43:53 +00:00
|
|
|
#include <grub/charset.h>
|
2007-08-03 07:44:01 +00:00
|
|
|
|
2011-04-11 21:01:51 +00:00
|
|
|
GRUB_MOD_LICENSE ("GPLv3+");
|
|
|
|
|
2007-08-03 07:44:01 +00:00
|
|
|
static grub_dl_t my_mod;
|
|
|
|
|
2011-10-27 00:59:45 +00:00
|
|
|
#define grub_fshelp_node grub_ntfs_file
|
|
|
|
|
2011-12-13 13:17:24 +00:00
|
|
|
static inline grub_uint16_t
|
|
|
|
u16at (void *ptr, grub_size_t ofs)
|
|
|
|
{
|
|
|
|
return grub_le_to_cpu16 (grub_get_unaligned16 ((char *) ptr + ofs));
|
|
|
|
}
|
2011-10-27 00:59:45 +00:00
|
|
|
|
2011-12-13 13:17:24 +00:00
|
|
|
static inline grub_uint32_t
|
|
|
|
u32at (void *ptr, grub_size_t ofs)
|
|
|
|
{
|
|
|
|
return grub_le_to_cpu32 (grub_get_unaligned32 ((char *) ptr + ofs));
|
|
|
|
}
|
2011-10-27 00:59:45 +00:00
|
|
|
|
2011-12-13 13:17:24 +00:00
|
|
|
static inline grub_uint64_t
|
|
|
|
u64at (void *ptr, grub_size_t ofs)
|
|
|
|
{
|
|
|
|
return grub_le_to_cpu64 (grub_get_unaligned64 ((char *) ptr + ofs));
|
|
|
|
}
|
2011-10-27 00:59:45 +00:00
|
|
|
|
|
|
|
grub_ntfscomp_func_t grub_ntfscomp_func;
|
2007-12-21 11:41:23 +00:00
|
|
|
|
2007-08-03 07:44:01 +00:00
|
|
|
static grub_err_t
|
2013-01-11 06:41:05 +00:00
|
|
|
fixup (grub_uint8_t *buf, grub_size_t len, const grub_uint8_t *magic)
|
2007-08-03 07:44:01 +00:00
|
|
|
{
|
2013-01-11 06:41:05 +00:00
|
|
|
grub_uint16_t ss;
|
|
|
|
grub_uint8_t *pu;
|
2007-12-21 11:41:23 +00:00
|
|
|
grub_uint16_t us;
|
2007-08-03 07:44:01 +00:00
|
|
|
|
2012-01-20 14:01:35 +00:00
|
|
|
COMPILE_TIME_ASSERT ((1 << GRUB_NTFS_BLK_SHR) == GRUB_DISK_SECTOR_SIZE);
|
|
|
|
|
2007-08-03 07:44:01 +00:00
|
|
|
if (grub_memcmp (buf, magic, 4))
|
|
|
|
return grub_error (GRUB_ERR_BAD_FS, "%s label not found", magic);
|
|
|
|
|
|
|
|
ss = u16at (buf, 6) - 1;
|
2012-01-20 14:01:35 +00:00
|
|
|
if (ss != len)
|
|
|
|
return grub_error (GRUB_ERR_BAD_FS, "size not match");
|
2007-08-03 07:44:01 +00:00
|
|
|
pu = buf + u16at (buf, 4);
|
|
|
|
us = u16at (pu, 0);
|
|
|
|
buf -= 2;
|
|
|
|
while (ss > 0)
|
|
|
|
{
|
2012-01-20 14:01:35 +00:00
|
|
|
buf += GRUB_DISK_SECTOR_SIZE;
|
2007-08-03 07:44:01 +00:00
|
|
|
pu += 2;
|
|
|
|
if (u16at (buf, 0) != us)
|
2009-12-24 22:53:05 +00:00
|
|
|
return grub_error (GRUB_ERR_BAD_FS, "fixup signature not match");
|
2011-12-13 13:17:24 +00:00
|
|
|
buf[0] = pu[0];
|
|
|
|
buf[1] = pu[1];
|
2007-08-03 07:44:01 +00:00
|
|
|
ss--;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-11 06:41:05 +00:00
|
|
|
static grub_err_t read_mft (struct grub_ntfs_data *data, grub_uint8_t *buf,
|
2013-10-21 10:58:38 +00:00
|
|
|
grub_uint64_t mftno);
|
2013-01-11 06:41:05 +00:00
|
|
|
static grub_err_t read_attr (struct grub_ntfs_attr *at, grub_uint8_t *dest,
|
2009-12-10 13:45:00 +00:00
|
|
|
grub_disk_addr_t ofs, grub_size_t len,
|
2007-08-03 07:44:01 +00:00
|
|
|
int cached,
|
2013-02-27 16:19:15 +00:00
|
|
|
grub_disk_read_hook_t read_hook,
|
|
|
|
void *read_hook_data);
|
2007-08-03 07:44:01 +00:00
|
|
|
|
2013-01-11 06:41:05 +00:00
|
|
|
static grub_err_t read_data (struct grub_ntfs_attr *at, grub_uint8_t *pa,
|
|
|
|
grub_uint8_t *dest,
|
2009-12-10 13:45:00 +00:00
|
|
|
grub_disk_addr_t ofs, grub_size_t len,
|
2007-08-03 07:44:01 +00:00
|
|
|
int cached,
|
2013-02-27 16:19:15 +00:00
|
|
|
grub_disk_read_hook_t read_hook,
|
|
|
|
void *read_hook_data);
|
2007-08-03 07:44:01 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
init_attr (struct grub_ntfs_attr *at, struct grub_ntfs_file *mft)
|
|
|
|
{
|
|
|
|
at->mft = mft;
|
2011-10-27 00:59:45 +00:00
|
|
|
at->flags = (mft == &mft->data->mmft) ? GRUB_NTFS_AF_MMFT : 0;
|
2007-08-03 07:44:01 +00:00
|
|
|
at->attr_nxt = mft->buf + u16at (mft->buf, 0x14);
|
|
|
|
at->attr_end = at->emft_buf = at->edat_buf = at->sbuf = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_attr (struct grub_ntfs_attr *at)
|
|
|
|
{
|
|
|
|
grub_free (at->emft_buf);
|
|
|
|
grub_free (at->edat_buf);
|
|
|
|
grub_free (at->sbuf);
|
|
|
|
}
|
|
|
|
|
2013-01-11 06:41:05 +00:00
|
|
|
static grub_uint8_t *
|
|
|
|
find_attr (struct grub_ntfs_attr *at, grub_uint8_t attr)
|
2007-08-03 07:44:01 +00:00
|
|
|
{
|
2011-10-27 00:59:45 +00:00
|
|
|
if (at->flags & GRUB_NTFS_AF_ALST)
|
2007-08-03 07:44:01 +00:00
|
|
|
{
|
|
|
|
retry:
|
|
|
|
while (at->attr_nxt < at->attr_end)
|
|
|
|
{
|
|
|
|
at->attr_cur = at->attr_nxt;
|
|
|
|
at->attr_nxt += u16at (at->attr_cur, 4);
|
2013-01-11 06:41:05 +00:00
|
|
|
if ((*at->attr_cur == attr) || (attr == 0))
|
2007-08-03 07:44:01 +00:00
|
|
|
{
|
2013-01-11 06:41:05 +00:00
|
|
|
grub_uint8_t *new_pos;
|
2007-08-03 07:44:01 +00:00
|
|
|
|
2011-10-27 00:59:45 +00:00
|
|
|
if (at->flags & GRUB_NTFS_AF_MMFT)
|
2007-08-03 07:44:01 +00:00
|
|
|
{
|
|
|
|
if ((grub_disk_read
|
2011-12-13 13:17:24 +00:00
|
|
|
(at->mft->data->disk, u32at (at->attr_cur, 0x10), 0,
|
2007-08-03 07:44:01 +00:00
|
|
|
512, at->emft_buf))
|
|
|
|
||
|
|
|
|
(grub_disk_read
|
2011-12-13 13:17:24 +00:00
|
|
|
(at->mft->data->disk, u32at (at->attr_cur, 0x14), 0,
|
2007-08-03 07:44:01 +00:00
|
|
|
512, at->emft_buf + 512)))
|
|
|
|
return NULL;
|
|
|
|
|
2013-01-11 06:41:05 +00:00
|
|
|
if (fixup (at->emft_buf, at->mft->data->mft_size,
|
|
|
|
(const grub_uint8_t *) "FILE"))
|
2007-08-03 07:44:01 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (read_mft (at->mft->data, at->emft_buf,
|
|
|
|
u32at (at->attr_cur, 0x10)))
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
new_pos = &at->emft_buf[u16at (at->emft_buf, 0x14)];
|
2013-01-11 06:41:05 +00:00
|
|
|
while (*new_pos != 0xFF)
|
2007-08-03 07:44:01 +00:00
|
|
|
{
|
2013-01-11 06:41:05 +00:00
|
|
|
if ((*new_pos == *at->attr_cur)
|
2007-08-03 07:44:01 +00:00
|
|
|
&& (u16at (new_pos, 0xE) == u16at (at->attr_cur, 0x18)))
|
|
|
|
{
|
|
|
|
return new_pos;
|
|
|
|
}
|
|
|
|
new_pos += u16at (new_pos, 4);
|
|
|
|
}
|
|
|
|
grub_error (GRUB_ERR_BAD_FS,
|
2009-12-24 22:53:05 +00:00
|
|
|
"can\'t find 0x%X in attribute list",
|
2007-08-03 07:44:01 +00:00
|
|
|
(unsigned char) *at->attr_cur);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
at->attr_cur = at->attr_nxt;
|
2013-01-11 06:41:05 +00:00
|
|
|
while (*at->attr_cur != 0xFF)
|
2007-08-03 07:44:01 +00:00
|
|
|
{
|
|
|
|
at->attr_nxt += u16at (at->attr_cur, 4);
|
2013-01-11 06:41:05 +00:00
|
|
|
if (*at->attr_cur == GRUB_NTFS_AT_ATTRIBUTE_LIST)
|
2007-08-03 07:44:01 +00:00
|
|
|
at->attr_end = at->attr_cur;
|
2013-01-11 06:41:05 +00:00
|
|
|
if ((*at->attr_cur == attr) || (attr == 0))
|
2007-08-03 07:44:01 +00:00
|
|
|
return at->attr_cur;
|
|
|
|
at->attr_cur = at->attr_nxt;
|
|
|
|
}
|
|
|
|
if (at->attr_end)
|
|
|
|
{
|
2013-01-11 06:41:05 +00:00
|
|
|
grub_uint8_t *pa;
|
2007-08-03 07:44:01 +00:00
|
|
|
|
2011-10-27 00:59:45 +00:00
|
|
|
at->emft_buf = grub_malloc (at->mft->data->mft_size << GRUB_NTFS_BLK_SHR);
|
2007-08-03 07:44:01 +00:00
|
|
|
if (at->emft_buf == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
pa = at->attr_end;
|
|
|
|
if (pa[8])
|
|
|
|
{
|
2013-01-11 06:41:05 +00:00
|
|
|
grub_uint32_t n;
|
2008-03-31 12:00:48 +00:00
|
|
|
|
|
|
|
n = ((u32at (pa, 0x30) + GRUB_DISK_SECTOR_SIZE - 1)
|
|
|
|
& (~(GRUB_DISK_SECTOR_SIZE - 1)));
|
2007-08-03 07:44:01 +00:00
|
|
|
at->attr_cur = at->attr_end;
|
2008-03-31 12:00:48 +00:00
|
|
|
at->edat_buf = grub_malloc (n);
|
2007-08-03 07:44:01 +00:00
|
|
|
if (!at->edat_buf)
|
|
|
|
return NULL;
|
2013-02-27 16:19:15 +00:00
|
|
|
if (read_data (at, pa, at->edat_buf, 0, n, 0, 0, 0))
|
2007-08-03 07:44:01 +00:00
|
|
|
{
|
|
|
|
grub_error (GRUB_ERR_BAD_FS,
|
2009-12-24 22:53:05 +00:00
|
|
|
"fail to read non-resident attribute list");
|
2007-08-03 07:44:01 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
at->attr_nxt = at->edat_buf;
|
|
|
|
at->attr_end = at->edat_buf + u32at (pa, 0x30);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
at->attr_nxt = at->attr_end + u16at (pa, 0x14);
|
|
|
|
at->attr_end = at->attr_end + u32at (pa, 4);
|
|
|
|
}
|
2011-10-27 00:59:45 +00:00
|
|
|
at->flags |= GRUB_NTFS_AF_ALST;
|
2007-08-03 07:44:01 +00:00
|
|
|
while (at->attr_nxt < at->attr_end)
|
|
|
|
{
|
2013-01-11 06:41:05 +00:00
|
|
|
if ((*at->attr_nxt == attr) || (attr == 0))
|
2007-08-03 07:44:01 +00:00
|
|
|
break;
|
|
|
|
at->attr_nxt += u16at (at->attr_nxt, 4);
|
|
|
|
}
|
|
|
|
if (at->attr_nxt >= at->attr_end)
|
|
|
|
return NULL;
|
|
|
|
|
2011-10-27 00:59:45 +00:00
|
|
|
if ((at->flags & GRUB_NTFS_AF_MMFT) && (attr == GRUB_NTFS_AT_DATA))
|
2007-08-03 07:44:01 +00:00
|
|
|
{
|
2011-10-27 00:59:45 +00:00
|
|
|
at->flags |= GRUB_NTFS_AF_GPOS;
|
2007-08-03 07:44:01 +00:00
|
|
|
at->attr_cur = at->attr_nxt;
|
|
|
|
pa = at->attr_cur;
|
2011-12-13 13:17:24 +00:00
|
|
|
grub_set_unaligned32 ((char *) pa + 0x10,
|
|
|
|
grub_cpu_to_le32 (at->mft->data->mft_start));
|
|
|
|
grub_set_unaligned32 ((char *) pa + 0x14,
|
|
|
|
grub_cpu_to_le32 (at->mft->data->mft_start
|
|
|
|
+ 1));
|
2007-08-03 07:44:01 +00:00
|
|
|
pa = at->attr_nxt + u16at (pa, 4);
|
|
|
|
while (pa < at->attr_end)
|
|
|
|
{
|
2013-01-11 06:41:05 +00:00
|
|
|
if (*pa != attr)
|
2007-08-03 07:44:01 +00:00
|
|
|
break;
|
|
|
|
if (read_attr
|
|
|
|
(at, pa + 0x10,
|
2011-10-27 00:59:45 +00:00
|
|
|
u32at (pa, 0x10) * (at->mft->data->mft_size << GRUB_NTFS_BLK_SHR),
|
2013-02-27 16:19:15 +00:00
|
|
|
at->mft->data->mft_size << GRUB_NTFS_BLK_SHR, 0, 0, 0))
|
2007-08-03 07:44:01 +00:00
|
|
|
return NULL;
|
|
|
|
pa += u16at (pa, 4);
|
|
|
|
}
|
|
|
|
at->attr_nxt = at->attr_cur;
|
2011-10-27 00:59:45 +00:00
|
|
|
at->flags &= ~GRUB_NTFS_AF_GPOS;
|
2007-08-03 07:44:01 +00:00
|
|
|
}
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-01-11 06:41:05 +00:00
|
|
|
static grub_uint8_t *
|
2007-08-03 07:44:01 +00:00
|
|
|
locate_attr (struct grub_ntfs_attr *at, struct grub_ntfs_file *mft,
|
2013-01-11 06:41:05 +00:00
|
|
|
grub_uint8_t attr)
|
2007-08-03 07:44:01 +00:00
|
|
|
{
|
2013-01-11 06:41:05 +00:00
|
|
|
grub_uint8_t *pa;
|
2007-08-03 07:44:01 +00:00
|
|
|
|
|
|
|
init_attr (at, mft);
|
2012-02-12 17:47:46 +00:00
|
|
|
pa = find_attr (at, attr);
|
|
|
|
if (pa == NULL)
|
2007-08-03 07:44:01 +00:00
|
|
|
return NULL;
|
2011-10-27 00:59:45 +00:00
|
|
|
if ((at->flags & GRUB_NTFS_AF_ALST) == 0)
|
2007-08-03 07:44:01 +00:00
|
|
|
{
|
|
|
|
while (1)
|
|
|
|
{
|
2012-02-12 17:47:46 +00:00
|
|
|
pa = find_attr (at, attr);
|
|
|
|
if (pa == NULL)
|
2007-08-03 07:44:01 +00:00
|
|
|
break;
|
2011-10-27 00:59:45 +00:00
|
|
|
if (at->flags & GRUB_NTFS_AF_ALST)
|
2007-08-03 07:44:01 +00:00
|
|
|
return pa;
|
|
|
|
}
|
|
|
|
grub_errno = GRUB_ERR_NONE;
|
|
|
|
free_attr (at);
|
|
|
|
init_attr (at, mft);
|
|
|
|
pa = find_attr (at, attr);
|
|
|
|
}
|
|
|
|
return pa;
|
|
|
|
}
|
|
|
|
|
2013-10-21 02:05:23 +00:00
|
|
|
static grub_disk_addr_t
|
|
|
|
read_run_data (const grub_uint8_t *run, int nn, int sig)
|
2007-08-03 07:44:01 +00:00
|
|
|
{
|
2013-10-21 02:05:23 +00:00
|
|
|
grub_uint64_t r = 0;
|
2007-08-03 07:44:01 +00:00
|
|
|
|
2013-10-21 02:05:23 +00:00
|
|
|
if (sig && nn && (run[nn - 1] & 0x80))
|
|
|
|
r = -1;
|
2007-08-03 07:44:01 +00:00
|
|
|
|
2013-10-21 02:05:23 +00:00
|
|
|
grub_memcpy (&r, run, nn);
|
2007-08-03 07:44:01 +00:00
|
|
|
|
2013-10-21 02:05:23 +00:00
|
|
|
return grub_le_to_cpu64 (r);
|
2007-08-03 07:44:01 +00:00
|
|
|
}
|
|
|
|
|
2007-12-21 11:41:23 +00:00
|
|
|
grub_err_t
|
|
|
|
grub_ntfs_read_run_list (struct grub_ntfs_rlst * ctx)
|
2007-08-03 07:44:01 +00:00
|
|
|
{
|
2013-01-11 06:41:05 +00:00
|
|
|
grub_uint8_t c1, c2;
|
2009-12-10 13:45:00 +00:00
|
|
|
grub_disk_addr_t val;
|
2013-01-11 06:41:05 +00:00
|
|
|
grub_uint8_t *run;
|
2007-08-03 07:44:01 +00:00
|
|
|
|
|
|
|
run = ctx->cur_run;
|
|
|
|
retry:
|
2013-10-21 02:05:23 +00:00
|
|
|
c1 = ((*run) & 0x7);
|
|
|
|
c2 = ((*run) >> 4) & 0x7;
|
|
|
|
run++;
|
2007-08-03 07:44:01 +00:00
|
|
|
if (!c1)
|
|
|
|
{
|
2011-10-27 00:59:45 +00:00
|
|
|
if ((ctx->attr) && (ctx->attr->flags & GRUB_NTFS_AF_ALST))
|
2007-08-03 07:44:01 +00:00
|
|
|
{
|
2013-02-27 16:19:15 +00:00
|
|
|
grub_disk_read_hook_t save_hook;
|
2007-08-03 07:44:01 +00:00
|
|
|
|
|
|
|
save_hook = ctx->comp.disk->read_hook;
|
|
|
|
ctx->comp.disk->read_hook = 0;
|
2013-01-11 06:41:05 +00:00
|
|
|
run = find_attr (ctx->attr, *ctx->attr->attr_cur);
|
2007-08-03 07:44:01 +00:00
|
|
|
ctx->comp.disk->read_hook = save_hook;
|
|
|
|
if (run)
|
|
|
|
{
|
|
|
|
if (run[8] == 0)
|
|
|
|
return grub_error (GRUB_ERR_BAD_FS,
|
|
|
|
"$DATA should be non-resident");
|
|
|
|
|
|
|
|
run += u16at (run, 0x20);
|
|
|
|
ctx->curr_lcn = 0;
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
}
|
2009-12-24 22:53:05 +00:00
|
|
|
return grub_error (GRUB_ERR_BAD_FS, "run list overflown");
|
2007-08-03 07:44:01 +00:00
|
|
|
}
|
|
|
|
ctx->curr_vcn = ctx->next_vcn;
|
2013-10-21 02:05:23 +00:00
|
|
|
ctx->next_vcn += read_run_data (run, c1, 0); /* length of current VCN */
|
|
|
|
run += c1;
|
|
|
|
val = read_run_data (run, c2, 1); /* offset to previous LCN */
|
|
|
|
run += c2;
|
2007-08-03 07:44:01 +00:00
|
|
|
ctx->curr_lcn += val;
|
|
|
|
if (val == 0)
|
2011-10-27 00:59:45 +00:00
|
|
|
ctx->flags |= GRUB_NTFS_RF_BLNK;
|
2007-08-03 07:44:01 +00:00
|
|
|
else
|
2011-10-27 00:59:45 +00:00
|
|
|
ctx->flags &= ~GRUB_NTFS_RF_BLNK;
|
2007-08-03 07:44:01 +00:00
|
|
|
ctx->cur_run = run;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-20 05:00:53 +00:00
|
|
|
static grub_disk_addr_t
|
|
|
|
grub_ntfs_read_block (grub_fshelp_node_t node, grub_disk_addr_t block)
|
2007-08-03 07:44:01 +00:00
|
|
|
{
|
|
|
|
struct grub_ntfs_rlst *ctx;
|
|
|
|
|
|
|
|
ctx = (struct grub_ntfs_rlst *) node;
|
2009-12-10 13:45:00 +00:00
|
|
|
if (block >= ctx->next_vcn)
|
2007-08-03 07:44:01 +00:00
|
|
|
{
|
2007-12-21 11:41:23 +00:00
|
|
|
if (grub_ntfs_read_run_list (ctx))
|
2007-08-03 07:44:01 +00:00
|
|
|
return -1;
|
|
|
|
return ctx->curr_lcn;
|
|
|
|
}
|
|
|
|
else
|
2011-10-27 00:59:45 +00:00
|
|
|
return (ctx->flags & GRUB_NTFS_RF_BLNK) ? 0 : (block -
|
2007-08-03 07:44:01 +00:00
|
|
|
ctx->curr_vcn + ctx->curr_lcn);
|
|
|
|
}
|
|
|
|
|
|
|
|
static grub_err_t
|
2013-01-11 06:41:05 +00:00
|
|
|
read_data (struct grub_ntfs_attr *at, grub_uint8_t *pa, grub_uint8_t *dest,
|
2009-12-10 13:45:00 +00:00
|
|
|
grub_disk_addr_t ofs, grub_size_t len, int cached,
|
2013-02-27 16:19:15 +00:00
|
|
|
grub_disk_read_hook_t read_hook, void *read_hook_data)
|
2007-08-03 07:44:01 +00:00
|
|
|
{
|
|
|
|
struct grub_ntfs_rlst cc, *ctx;
|
|
|
|
|
|
|
|
if (len == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
grub_memset (&cc, 0, sizeof (cc));
|
|
|
|
ctx = &cc;
|
|
|
|
ctx->attr = at;
|
2013-01-05 16:36:04 +00:00
|
|
|
ctx->comp.log_spc = at->mft->data->log_spc;
|
2007-08-03 07:44:01 +00:00
|
|
|
ctx->comp.disk = at->mft->data->disk;
|
|
|
|
|
|
|
|
if (pa[8] == 0)
|
|
|
|
{
|
|
|
|
if (ofs + len > u32at (pa, 0x10))
|
2009-12-24 22:53:05 +00:00
|
|
|
return grub_error (GRUB_ERR_BAD_FS, "read out of range");
|
2007-08-03 07:44:01 +00:00
|
|
|
grub_memcpy (dest, pa + u32at (pa, 0x14) + ofs, len);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->cur_run = pa + u16at (pa, 0x20);
|
|
|
|
|
2013-10-21 00:48:19 +00:00
|
|
|
ctx->next_vcn = u32at (pa, 0x10);
|
|
|
|
ctx->curr_lcn = 0;
|
|
|
|
|
|
|
|
if ((pa[0xC] & GRUB_NTFS_FLAG_COMPRESSED)
|
|
|
|
&& !(at->flags & GRUB_NTFS_AF_GPOS))
|
2007-08-03 07:44:01 +00:00
|
|
|
{
|
|
|
|
if (!cached)
|
2009-12-24 22:53:05 +00:00
|
|
|
return grub_error (GRUB_ERR_BAD_FS, "attribute can\'t be compressed");
|
2007-08-03 07:44:01 +00:00
|
|
|
|
2013-10-21 00:48:19 +00:00
|
|
|
return (grub_ntfscomp_func) ? grub_ntfscomp_func (dest, ofs, len, ctx)
|
|
|
|
: grub_error (GRUB_ERR_BAD_FS, N_("module `%s' isn't loaded"),
|
|
|
|
"ntfscomp");
|
2007-08-03 07:44:01 +00:00
|
|
|
}
|
|
|
|
|
2013-10-21 00:48:19 +00:00
|
|
|
ctx->target_vcn = ofs >> (GRUB_NTFS_BLK_SHR + ctx->comp.log_spc);
|
2007-08-03 07:44:01 +00:00
|
|
|
while (ctx->next_vcn <= ctx->target_vcn)
|
|
|
|
{
|
2007-12-21 11:41:23 +00:00
|
|
|
if (grub_ntfs_read_run_list (ctx))
|
2007-08-03 07:44:01 +00:00
|
|
|
return grub_errno;
|
|
|
|
}
|
|
|
|
|
2011-10-27 00:59:45 +00:00
|
|
|
if (at->flags & GRUB_NTFS_AF_GPOS)
|
2007-08-03 07:44:01 +00:00
|
|
|
{
|
2009-12-10 13:45:00 +00:00
|
|
|
grub_disk_addr_t st0, st1;
|
2011-05-18 13:35:19 +00:00
|
|
|
grub_uint64_t m;
|
2009-12-10 13:45:00 +00:00
|
|
|
|
2013-01-05 16:36:04 +00:00
|
|
|
m = (ofs >> GRUB_NTFS_BLK_SHR) & ((1 << ctx->comp.log_spc) - 1);
|
2007-08-03 07:44:01 +00:00
|
|
|
|
|
|
|
st0 =
|
2013-01-05 16:36:04 +00:00
|
|
|
((ctx->target_vcn - ctx->curr_vcn + ctx->curr_lcn) << ctx->comp.log_spc) + m;
|
2007-08-03 07:44:01 +00:00
|
|
|
st1 = st0 + 1;
|
|
|
|
if (st1 ==
|
2013-01-05 16:36:04 +00:00
|
|
|
(ctx->next_vcn - ctx->curr_vcn + ctx->curr_lcn) << ctx->comp.log_spc)
|
2007-08-03 07:44:01 +00:00
|
|
|
{
|
2007-12-21 11:41:23 +00:00
|
|
|
if (grub_ntfs_read_run_list (ctx))
|
2007-08-03 07:44:01 +00:00
|
|
|
return grub_errno;
|
2013-01-05 16:36:04 +00:00
|
|
|
st1 = ctx->curr_lcn << ctx->comp.log_spc;
|
2007-08-03 07:44:01 +00:00
|
|
|
}
|
2011-12-13 13:17:24 +00:00
|
|
|
grub_set_unaligned32 (dest, grub_cpu_to_le32 (st0));
|
|
|
|
grub_set_unaligned32 (dest + 4, grub_cpu_to_le32 (st1));
|
2007-08-03 07:44:01 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-10-21 00:48:19 +00:00
|
|
|
grub_fshelp_read_file (ctx->comp.disk, (grub_fshelp_node_t) ctx,
|
|
|
|
read_hook, read_hook_data, ofs, len,
|
|
|
|
(char *) dest,
|
|
|
|
grub_ntfs_read_block, ofs + len,
|
|
|
|
ctx->comp.log_spc, 0);
|
|
|
|
return grub_errno;
|
2007-08-03 07:44:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static grub_err_t
|
2013-01-11 06:41:05 +00:00
|
|
|
read_attr (struct grub_ntfs_attr *at, grub_uint8_t *dest, grub_disk_addr_t ofs,
|
2009-12-10 13:45:00 +00:00
|
|
|
grub_size_t len, int cached,
|
2013-02-27 16:19:15 +00:00
|
|
|
grub_disk_read_hook_t read_hook, void *read_hook_data)
|
2007-08-03 07:44:01 +00:00
|
|
|
{
|
2013-01-11 06:41:05 +00:00
|
|
|
grub_uint8_t *save_cur;
|
|
|
|
grub_uint8_t attr;
|
|
|
|
grub_uint8_t *pp;
|
2007-08-03 07:44:01 +00:00
|
|
|
grub_err_t ret;
|
|
|
|
|
|
|
|
save_cur = at->attr_cur;
|
|
|
|
at->attr_nxt = at->attr_cur;
|
2013-01-11 06:41:05 +00:00
|
|
|
attr = *at->attr_nxt;
|
2011-10-27 00:59:45 +00:00
|
|
|
if (at->flags & GRUB_NTFS_AF_ALST)
|
2007-08-03 07:44:01 +00:00
|
|
|
{
|
2013-01-11 06:41:05 +00:00
|
|
|
grub_uint8_t *pa;
|
2009-12-10 13:45:00 +00:00
|
|
|
grub_disk_addr_t vcn;
|
2007-08-03 07:44:01 +00:00
|
|
|
|
2012-05-15 15:17:06 +00:00
|
|
|
/* If compression is possible make sure that we include possible
|
|
|
|
compressed block size. */
|
2013-01-05 16:36:04 +00:00
|
|
|
if (GRUB_NTFS_LOG_COM_SEC >= at->mft->data->log_spc)
|
2012-05-15 15:17:06 +00:00
|
|
|
vcn = ((ofs >> GRUB_NTFS_COM_LOG_LEN)
|
2013-01-05 16:36:04 +00:00
|
|
|
<< (GRUB_NTFS_LOG_COM_SEC - at->mft->data->log_spc)) & ~0xFULL;
|
2012-05-15 15:17:06 +00:00
|
|
|
else
|
2013-01-05 16:36:04 +00:00
|
|
|
vcn = ofs >> (at->mft->data->log_spc + GRUB_NTFS_BLK_SHR);
|
2007-08-03 07:44:01 +00:00
|
|
|
pa = at->attr_nxt + u16at (at->attr_nxt, 4);
|
|
|
|
while (pa < at->attr_end)
|
|
|
|
{
|
2013-01-11 06:41:05 +00:00
|
|
|
if (*pa != attr)
|
2007-08-03 07:44:01 +00:00
|
|
|
break;
|
|
|
|
if (u32at (pa, 8) > vcn)
|
|
|
|
break;
|
|
|
|
at->attr_nxt = pa;
|
|
|
|
pa += u16at (pa, 4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pp = find_attr (at, attr);
|
|
|
|
if (pp)
|
2013-02-27 16:19:15 +00:00
|
|
|
ret = read_data (at, pp, dest, ofs, len, cached,
|
|
|
|
read_hook, read_hook_data);
|
2007-08-03 07:44:01 +00:00
|
|
|
else
|
|
|
|
ret =
|
|
|
|
(grub_errno) ? grub_errno : grub_error (GRUB_ERR_BAD_FS,
|
2009-12-24 22:53:05 +00:00
|
|
|
"attribute not found");
|
2007-08-03 07:44:01 +00:00
|
|
|
at->attr_cur = save_cur;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static grub_err_t
|
2013-10-21 10:58:38 +00:00
|
|
|
read_mft (struct grub_ntfs_data *data, grub_uint8_t *buf, grub_uint64_t mftno)
|
2007-08-03 07:44:01 +00:00
|
|
|
{
|
|
|
|
if (read_attr
|
2011-10-27 00:59:45 +00:00
|
|
|
(&data->mmft.attr, buf, mftno * ((grub_disk_addr_t) data->mft_size << GRUB_NTFS_BLK_SHR),
|
2013-02-27 16:19:15 +00:00
|
|
|
data->mft_size << GRUB_NTFS_BLK_SHR, 0, 0, 0))
|
2013-10-21 10:58:38 +00:00
|
|
|
return grub_error (GRUB_ERR_BAD_FS, "read MFT 0x%llx fails", (unsigned long long) mftno);
|
2013-01-11 06:41:05 +00:00
|
|
|
return fixup (buf, data->mft_size, (const grub_uint8_t *) "FILE");
|
2007-08-03 07:44:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static grub_err_t
|
2013-10-21 10:58:38 +00:00
|
|
|
init_file (struct grub_ntfs_file *mft, grub_uint64_t mftno)
|
2007-08-03 07:44:01 +00:00
|
|
|
{
|
|
|
|
unsigned short flag;
|
|
|
|
|
|
|
|
mft->inode_read = 1;
|
|
|
|
|
2011-10-27 00:59:45 +00:00
|
|
|
mft->buf = grub_malloc (mft->data->mft_size << GRUB_NTFS_BLK_SHR);
|
2007-08-03 07:44:01 +00:00
|
|
|
if (mft->buf == NULL)
|
|
|
|
return grub_errno;
|
|
|
|
|
|
|
|
if (read_mft (mft->data, mft->buf, mftno))
|
|
|
|
return grub_errno;
|
|
|
|
|
|
|
|
flag = u16at (mft->buf, 0x16);
|
|
|
|
if ((flag & 1) == 0)
|
2013-10-21 10:58:38 +00:00
|
|
|
return grub_error (GRUB_ERR_BAD_FS, "MFT 0x%llx is not in use",
|
|
|
|
(unsigned long long) mftno);
|
2007-08-03 07:44:01 +00:00
|
|
|
|
|
|
|
if ((flag & 2) == 0)
|
|
|
|
{
|
2013-01-11 06:41:05 +00:00
|
|
|
grub_uint8_t *pa;
|
2007-08-03 07:44:01 +00:00
|
|
|
|
2011-10-27 00:59:45 +00:00
|
|
|
pa = locate_attr (&mft->attr, mft, GRUB_NTFS_AT_DATA);
|
2007-08-03 07:44:01 +00:00
|
|
|
if (pa == NULL)
|
2013-10-21 10:58:38 +00:00
|
|
|
return grub_error (GRUB_ERR_BAD_FS, "no $DATA in MFT 0x%llx",
|
|
|
|
(unsigned long long) mftno);
|
2007-08-03 07:44:01 +00:00
|
|
|
|
|
|
|
if (!pa[8])
|
|
|
|
mft->size = u32at (pa, 0x10);
|
|
|
|
else
|
2009-09-11 14:26:12 +00:00
|
|
|
mft->size = u64at (pa, 0x30);
|
2007-08-03 07:44:01 +00:00
|
|
|
|
2011-10-27 00:59:45 +00:00
|
|
|
if ((mft->attr.flags & GRUB_NTFS_AF_ALST) == 0)
|
2007-08-03 07:44:01 +00:00
|
|
|
mft->attr.attr_end = 0; /* Don't jump to attribute list */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
init_attr (&mft->attr, mft);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_file (struct grub_ntfs_file *mft)
|
|
|
|
{
|
|
|
|
free_attr (&mft->attr);
|
|
|
|
grub_free (mft->buf);
|
|
|
|
}
|
|
|
|
|
2013-10-21 11:04:41 +00:00
|
|
|
static char *
|
|
|
|
get_utf8 (grub_uint8_t *in, grub_size_t len)
|
|
|
|
{
|
|
|
|
grub_uint8_t *buf;
|
|
|
|
grub_uint16_t *tmp;
|
|
|
|
grub_size_t i;
|
|
|
|
|
|
|
|
buf = grub_malloc (len * GRUB_MAX_UTF8_PER_UTF16 + 1);
|
|
|
|
tmp = grub_malloc (len * sizeof (tmp[0]));
|
|
|
|
if (!buf || !tmp)
|
|
|
|
{
|
|
|
|
grub_free (buf);
|
|
|
|
grub_free (tmp);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
tmp[i] = grub_le_to_cpu16 (grub_get_unaligned16 (in + 2 * i));
|
|
|
|
*grub_utf16_to_utf8 (buf, tmp, len) = '\0';
|
|
|
|
grub_free (tmp);
|
|
|
|
return (char *) buf;
|
|
|
|
}
|
|
|
|
|
2007-08-03 07:44:01 +00:00
|
|
|
static int
|
2013-01-11 06:41:05 +00:00
|
|
|
list_file (struct grub_ntfs_file *diro, grub_uint8_t *pos,
|
2013-01-21 01:33:46 +00:00
|
|
|
grub_fshelp_iterate_dir_hook_t hook, void *hook_data)
|
2007-08-03 07:44:01 +00:00
|
|
|
{
|
2013-01-11 06:41:05 +00:00
|
|
|
grub_uint8_t *np;
|
2007-08-03 07:44:01 +00:00
|
|
|
int ns;
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
2013-01-11 06:41:05 +00:00
|
|
|
grub_uint8_t namespace;
|
|
|
|
char *ustr;
|
2008-09-05 15:48:37 +00:00
|
|
|
|
2007-08-03 07:44:01 +00:00
|
|
|
if (pos[0xC] & 2) /* end signature */
|
|
|
|
break;
|
|
|
|
|
2008-09-05 15:48:37 +00:00
|
|
|
np = pos + 0x50;
|
2013-01-11 06:41:05 +00:00
|
|
|
ns = *(np++);
|
2008-09-05 15:48:37 +00:00
|
|
|
namespace = *(np++);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ignore files in DOS namespace, as they will reappear as Win32
|
|
|
|
* names.
|
|
|
|
*/
|
|
|
|
if ((ns) && (namespace != 2))
|
2007-08-03 07:44:01 +00:00
|
|
|
{
|
|
|
|
enum grub_fshelp_filetype type;
|
|
|
|
struct grub_ntfs_file *fdiro;
|
2011-10-27 01:04:27 +00:00
|
|
|
grub_uint32_t attr;
|
2007-08-03 07:44:01 +00:00
|
|
|
|
2011-10-27 01:04:27 +00:00
|
|
|
attr = u32at (pos, 0x48);
|
|
|
|
if (attr & GRUB_NTFS_ATTR_REPARSE)
|
|
|
|
type = GRUB_FSHELP_SYMLINK;
|
|
|
|
else if (attr & GRUB_NTFS_ATTR_DIRECTORY)
|
|
|
|
type = GRUB_FSHELP_DIR;
|
|
|
|
else
|
|
|
|
type = GRUB_FSHELP_REG;
|
2007-08-03 07:44:01 +00:00
|
|
|
|
2009-07-16 22:14:09 +00:00
|
|
|
fdiro = grub_zalloc (sizeof (struct grub_ntfs_file));
|
2007-08-03 07:44:01 +00:00
|
|
|
if (!fdiro)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fdiro->data = diro->data;
|
2013-10-21 10:58:38 +00:00
|
|
|
fdiro->ino = u64at (pos, 0) & 0xffffffffffffULL;
|
2012-05-26 23:00:46 +00:00
|
|
|
fdiro->mtime = u64at (pos, 0x20);
|
2007-08-03 07:44:01 +00:00
|
|
|
|
2013-10-21 11:04:41 +00:00
|
|
|
ustr = get_utf8 (np, ns);
|
2007-08-03 07:44:01 +00:00
|
|
|
if (ustr == NULL)
|
|
|
|
return 0;
|
2008-09-05 15:48:37 +00:00
|
|
|
if (namespace)
|
|
|
|
type |= GRUB_FSHELP_CASE_INSENSITIVE;
|
|
|
|
|
2013-01-21 01:33:46 +00:00
|
|
|
if (hook (ustr, type, fdiro, hook_data))
|
2007-08-03 07:44:01 +00:00
|
|
|
{
|
|
|
|
grub_free (ustr);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
grub_free (ustr);
|
|
|
|
}
|
|
|
|
pos += u16at (pos, 8);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-10-27 01:04:27 +00:00
|
|
|
struct symlink_descriptor
|
|
|
|
{
|
|
|
|
grub_uint32_t type;
|
|
|
|
grub_uint32_t total_len;
|
|
|
|
grub_uint16_t off1;
|
|
|
|
grub_uint16_t len1;
|
|
|
|
grub_uint16_t off2;
|
|
|
|
grub_uint16_t len2;
|
|
|
|
} __attribute__ ((packed));
|
|
|
|
|
|
|
|
static char *
|
|
|
|
grub_ntfs_read_symlink (grub_fshelp_node_t node)
|
|
|
|
{
|
|
|
|
struct grub_ntfs_file *mft;
|
|
|
|
struct symlink_descriptor symdesc;
|
|
|
|
grub_err_t err;
|
2013-10-21 11:04:41 +00:00
|
|
|
grub_uint8_t *buf16;
|
2011-10-27 01:04:27 +00:00
|
|
|
char *buf, *end;
|
|
|
|
grub_size_t len;
|
2013-01-11 06:41:05 +00:00
|
|
|
grub_uint8_t *pa;
|
2011-10-27 01:04:27 +00:00
|
|
|
grub_size_t off;
|
|
|
|
|
|
|
|
mft = (struct grub_ntfs_file *) node;
|
|
|
|
|
|
|
|
mft->buf = grub_malloc (mft->data->mft_size << GRUB_NTFS_BLK_SHR);
|
|
|
|
if (mft->buf == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (read_mft (mft->data, mft->buf, mft->ino))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
pa = locate_attr (&mft->attr, mft, GRUB_NTFS_AT_SYMLINK);
|
|
|
|
if (pa == NULL)
|
|
|
|
{
|
2013-10-21 11:04:41 +00:00
|
|
|
grub_error (GRUB_ERR_BAD_FS, "no $SYMLINK in MFT 0x%llx",
|
|
|
|
(unsigned long long) mft->ino);
|
2011-10-27 01:04:27 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-01-11 06:41:05 +00:00
|
|
|
err = read_attr (&mft->attr, (grub_uint8_t *) &symdesc, 0,
|
2013-02-27 16:19:15 +00:00
|
|
|
sizeof (struct symlink_descriptor), 1, 0, 0);
|
2011-10-27 01:04:27 +00:00
|
|
|
if (err)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
switch (grub_cpu_to_le32 (symdesc.type))
|
|
|
|
{
|
|
|
|
case 0xa000000c:
|
2011-11-11 16:18:34 +00:00
|
|
|
off = (sizeof (struct symlink_descriptor) + 4
|
|
|
|
+ grub_cpu_to_le32 (symdesc.off1));
|
2011-10-27 01:04:27 +00:00
|
|
|
len = grub_cpu_to_le32 (symdesc.len1);
|
|
|
|
break;
|
|
|
|
case 0xa0000003:
|
2011-11-11 16:18:34 +00:00
|
|
|
off = (sizeof (struct symlink_descriptor)
|
|
|
|
+ grub_cpu_to_le32 (symdesc.off1));
|
2011-10-27 01:04:27 +00:00
|
|
|
len = grub_cpu_to_le32 (symdesc.len1);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
grub_error (GRUB_ERR_BAD_FS, "symlink type invalid (%x)",
|
|
|
|
grub_cpu_to_le32 (symdesc.type));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf16 = grub_malloc (len);
|
|
|
|
if (!buf16)
|
|
|
|
return NULL;
|
|
|
|
|
2013-10-21 11:04:41 +00:00
|
|
|
err = read_attr (&mft->attr, buf16, off, len, 1, 0, 0);
|
2011-10-27 01:04:27 +00:00
|
|
|
if (err)
|
|
|
|
return NULL;
|
|
|
|
|
2013-10-21 11:04:41 +00:00
|
|
|
buf = get_utf8 (buf16, len / 2);
|
2011-10-27 01:04:27 +00:00
|
|
|
if (!buf)
|
|
|
|
{
|
|
|
|
grub_free (buf16);
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-10-21 11:04:41 +00:00
|
|
|
grub_free (buf16);
|
2011-10-27 01:04:27 +00:00
|
|
|
|
2013-10-21 11:04:41 +00:00
|
|
|
for (end = buf; *end; end++)
|
|
|
|
if (*end == '\\')
|
|
|
|
*end = '/';
|
2011-10-27 01:04:27 +00:00
|
|
|
|
|
|
|
/* Split the sequence to avoid GCC thinking that this is a trigraph. */
|
|
|
|
if (grub_memcmp (buf, "/?" "?/", 4) == 0 && buf[5] == ':' && buf[6] == '/'
|
|
|
|
&& grub_isalpha (buf[4]))
|
|
|
|
{
|
|
|
|
grub_memmove (buf, buf + 6, end - buf + 1 - 6);
|
|
|
|
end -= 6;
|
|
|
|
}
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2007-08-03 07:44:01 +00:00
|
|
|
static int
|
|
|
|
grub_ntfs_iterate_dir (grub_fshelp_node_t dir,
|
2013-01-21 01:33:46 +00:00
|
|
|
grub_fshelp_iterate_dir_hook_t hook, void *hook_data)
|
2007-08-03 07:44:01 +00:00
|
|
|
{
|
2013-01-11 06:41:05 +00:00
|
|
|
grub_uint8_t *bitmap;
|
2007-08-03 07:44:01 +00:00
|
|
|
struct grub_ntfs_attr attr, *at;
|
2013-01-11 06:41:05 +00:00
|
|
|
grub_uint8_t *cur_pos, *indx, *bmp;
|
2009-12-10 13:45:00 +00:00
|
|
|
int ret = 0;
|
|
|
|
grub_size_t bitmap_len;
|
2007-08-03 07:44:01 +00:00
|
|
|
struct grub_ntfs_file *mft;
|
|
|
|
|
|
|
|
mft = (struct grub_ntfs_file *) dir;
|
|
|
|
|
|
|
|
if (!mft->inode_read)
|
|
|
|
{
|
|
|
|
if (init_file (mft, mft->ino))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
indx = NULL;
|
|
|
|
bmp = NULL;
|
|
|
|
|
|
|
|
at = &attr;
|
|
|
|
init_attr (at, mft);
|
|
|
|
while (1)
|
|
|
|
{
|
2012-02-12 17:47:46 +00:00
|
|
|
cur_pos = find_attr (at, GRUB_NTFS_AT_INDEX_ROOT);
|
|
|
|
if (cur_pos == NULL)
|
2007-08-03 07:44:01 +00:00
|
|
|
{
|
2009-12-24 22:53:05 +00:00
|
|
|
grub_error (GRUB_ERR_BAD_FS, "no $INDEX_ROOT");
|
2007-08-03 07:44:01 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Resident, Namelen=4, Offset=0x18, Flags=0x00, Name="$I30" */
|
|
|
|
if ((u32at (cur_pos, 8) != 0x180400) ||
|
|
|
|
(u32at (cur_pos, 0x18) != 0x490024) ||
|
|
|
|
(u32at (cur_pos, 0x1C) != 0x300033))
|
|
|
|
continue;
|
|
|
|
cur_pos += u16at (cur_pos, 0x14);
|
|
|
|
if (*cur_pos != 0x30) /* Not filename index */
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
cur_pos += 0x10; /* Skip index root */
|
2013-01-21 01:33:46 +00:00
|
|
|
ret = list_file (mft, cur_pos + u16at (cur_pos, 0), hook, hook_data);
|
2007-08-03 07:44:01 +00:00
|
|
|
if (ret)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
bitmap = NULL;
|
|
|
|
bitmap_len = 0;
|
|
|
|
free_attr (at);
|
|
|
|
init_attr (at, mft);
|
2011-10-27 00:59:45 +00:00
|
|
|
while ((cur_pos = find_attr (at, GRUB_NTFS_AT_BITMAP)) != NULL)
|
2007-08-03 07:44:01 +00:00
|
|
|
{
|
|
|
|
int ofs;
|
|
|
|
|
2013-01-11 06:41:05 +00:00
|
|
|
ofs = cur_pos[0xA];
|
2007-08-03 07:44:01 +00:00
|
|
|
/* Namelen=4, Name="$I30" */
|
|
|
|
if ((cur_pos[9] == 4) &&
|
|
|
|
(u32at (cur_pos, ofs) == 0x490024) &&
|
|
|
|
(u32at (cur_pos, ofs + 4) == 0x300033))
|
|
|
|
{
|
2008-09-22 04:18:57 +00:00
|
|
|
int is_resident = (cur_pos[8] == 0);
|
|
|
|
|
|
|
|
bitmap_len = ((is_resident) ? u32at (cur_pos, 0x10) :
|
2008-09-28 03:35:49 +00:00
|
|
|
u32at (cur_pos, 0x28));
|
2007-08-03 07:44:01 +00:00
|
|
|
|
2008-09-22 04:18:57 +00:00
|
|
|
bmp = grub_malloc (bitmap_len);
|
|
|
|
if (bmp == NULL)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
if (is_resident)
|
2007-08-03 07:44:01 +00:00
|
|
|
{
|
2013-01-11 06:41:05 +00:00
|
|
|
grub_memcpy (bmp, cur_pos + u16at (cur_pos, 0x14),
|
2008-09-22 04:18:57 +00:00
|
|
|
bitmap_len);
|
2007-08-03 07:44:01 +00:00
|
|
|
}
|
2008-09-22 04:18:57 +00:00
|
|
|
else
|
|
|
|
{
|
2013-02-27 16:19:15 +00:00
|
|
|
if (read_data (at, cur_pos, bmp, 0, bitmap_len, 0, 0, 0))
|
2008-09-22 04:18:57 +00:00
|
|
|
{
|
|
|
|
grub_error (GRUB_ERR_BAD_FS,
|
2009-12-24 22:53:05 +00:00
|
|
|
"fails to read non-resident $BITMAP");
|
2008-09-22 04:18:57 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
bitmap_len = u32at (cur_pos, 0x30);
|
|
|
|
}
|
|
|
|
|
2013-01-11 06:41:05 +00:00
|
|
|
bitmap = bmp;
|
2007-08-03 07:44:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free_attr (at);
|
2011-10-27 00:59:45 +00:00
|
|
|
cur_pos = locate_attr (at, mft, GRUB_NTFS_AT_INDEX_ALLOCATION);
|
2007-08-03 07:44:01 +00:00
|
|
|
while (cur_pos != NULL)
|
|
|
|
{
|
|
|
|
/* Non-resident, Namelen=4, Offset=0x40, Flags=0, Name="$I30" */
|
|
|
|
if ((u32at (cur_pos, 8) == 0x400401) &&
|
|
|
|
(u32at (cur_pos, 0x40) == 0x490024) &&
|
|
|
|
(u32at (cur_pos, 0x44) == 0x300033))
|
|
|
|
break;
|
2011-10-27 00:59:45 +00:00
|
|
|
cur_pos = find_attr (at, GRUB_NTFS_AT_INDEX_ALLOCATION);
|
2007-08-03 07:44:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((!cur_pos) && (bitmap))
|
|
|
|
{
|
|
|
|
grub_error (GRUB_ERR_BAD_FS, "$BITMAP without $INDEX_ALLOCATION");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bitmap)
|
|
|
|
{
|
2013-10-21 01:23:57 +00:00
|
|
|
grub_disk_addr_t i;
|
|
|
|
grub_uint8_t v;
|
2007-08-03 07:44:01 +00:00
|
|
|
|
2011-10-27 00:59:45 +00:00
|
|
|
indx = grub_malloc (mft->data->idx_size << GRUB_NTFS_BLK_SHR);
|
2007-08-03 07:44:01 +00:00
|
|
|
if (indx == NULL)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
v = 1;
|
2009-12-10 13:45:00 +00:00
|
|
|
for (i = 0; i < (grub_disk_addr_t)bitmap_len * 8; i++)
|
2007-08-03 07:44:01 +00:00
|
|
|
{
|
|
|
|
if (*bitmap & v)
|
|
|
|
{
|
|
|
|
if ((read_attr
|
2011-10-27 00:59:45 +00:00
|
|
|
(at, indx, i * (mft->data->idx_size << GRUB_NTFS_BLK_SHR),
|
2013-02-27 16:19:15 +00:00
|
|
|
(mft->data->idx_size << GRUB_NTFS_BLK_SHR), 0, 0, 0))
|
2013-01-11 06:41:05 +00:00
|
|
|
|| (fixup (indx, mft->data->idx_size,
|
|
|
|
(const grub_uint8_t *) "INDX")))
|
2007-08-03 07:44:01 +00:00
|
|
|
goto done;
|
2013-01-21 01:33:46 +00:00
|
|
|
ret = list_file (mft, &indx[0x18 + u16at (indx, 0x18)],
|
|
|
|
hook, hook_data);
|
2007-08-03 07:44:01 +00:00
|
|
|
if (ret)
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
v <<= 1;
|
2013-10-21 01:23:57 +00:00
|
|
|
if (!v)
|
2007-08-03 07:44:01 +00:00
|
|
|
{
|
|
|
|
v = 1;
|
|
|
|
bitmap++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
free_attr (at);
|
|
|
|
grub_free (indx);
|
|
|
|
grub_free (bmp);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct grub_ntfs_data *
|
|
|
|
grub_ntfs_mount (grub_disk_t disk)
|
|
|
|
{
|
|
|
|
struct grub_ntfs_bpb bpb;
|
|
|
|
struct grub_ntfs_data *data = 0;
|
2013-01-05 16:36:04 +00:00
|
|
|
grub_uint32_t spc;
|
2007-08-03 07:44:01 +00:00
|
|
|
|
|
|
|
if (!disk)
|
|
|
|
goto fail;
|
|
|
|
|
2009-07-16 22:14:09 +00:00
|
|
|
data = (struct grub_ntfs_data *) grub_zalloc (sizeof (*data));
|
2007-08-03 07:44:01 +00:00
|
|
|
if (!data)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
data->disk = disk;
|
|
|
|
|
|
|
|
/* Read the BPB. */
|
2009-05-13 18:58:38 +00:00
|
|
|
if (grub_disk_read (disk, 0, 0, sizeof (bpb), &bpb))
|
2007-08-03 07:44:01 +00:00
|
|
|
goto fail;
|
|
|
|
|
2012-05-12 11:31:05 +00:00
|
|
|
if (grub_memcmp ((char *) &bpb.oem_name, "NTFS", 4) != 0
|
|
|
|
|| bpb.sectors_per_cluster == 0
|
|
|
|
|| (bpb.sectors_per_cluster & (bpb.sectors_per_cluster - 1)) != 0
|
|
|
|
|| bpb.bytes_per_sector == 0
|
|
|
|
|| (bpb.bytes_per_sector & (bpb.bytes_per_sector - 1)) != 0)
|
2007-08-03 07:44:01 +00:00
|
|
|
goto fail;
|
|
|
|
|
2013-01-05 16:36:04 +00:00
|
|
|
spc = (((grub_uint32_t) bpb.sectors_per_cluster
|
|
|
|
* (grub_uint32_t) grub_le_to_cpu16 (bpb.bytes_per_sector))
|
|
|
|
>> GRUB_NTFS_BLK_SHR);
|
2013-10-21 11:14:38 +00:00
|
|
|
if (spc == 0)
|
2012-05-12 11:31:05 +00:00
|
|
|
goto fail;
|
2007-08-03 07:44:01 +00:00
|
|
|
|
2013-01-05 16:36:04 +00:00
|
|
|
for (data->log_spc = 0; (1U << data->log_spc) < spc; data->log_spc++);
|
|
|
|
|
2007-08-03 07:44:01 +00:00
|
|
|
if (bpb.clusters_per_mft > 0)
|
2013-01-11 06:41:05 +00:00
|
|
|
data->mft_size = ((grub_disk_addr_t) bpb.clusters_per_mft) << data->log_spc;
|
2007-08-03 07:44:01 +00:00
|
|
|
else
|
2013-01-11 06:41:05 +00:00
|
|
|
data->mft_size = 1ULL << (-bpb.clusters_per_mft - GRUB_NTFS_BLK_SHR);
|
2007-08-03 07:44:01 +00:00
|
|
|
|
|
|
|
if (bpb.clusters_per_index > 0)
|
2013-01-11 06:41:05 +00:00
|
|
|
data->idx_size = (((grub_disk_addr_t) bpb.clusters_per_index)
|
|
|
|
<< data->log_spc);
|
2007-08-03 07:44:01 +00:00
|
|
|
else
|
2013-01-11 06:41:05 +00:00
|
|
|
data->idx_size = 1ULL << (-bpb.clusters_per_index - GRUB_NTFS_BLK_SHR);
|
2007-08-03 07:44:01 +00:00
|
|
|
|
2013-01-05 16:36:04 +00:00
|
|
|
data->mft_start = grub_le_to_cpu64 (bpb.mft_lcn) << data->log_spc;
|
2007-08-03 07:44:01 +00:00
|
|
|
|
2011-10-27 00:59:45 +00:00
|
|
|
if ((data->mft_size > GRUB_NTFS_MAX_MFT) || (data->idx_size > GRUB_NTFS_MAX_IDX))
|
2007-08-03 07:44:01 +00:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
data->mmft.data = data;
|
|
|
|
data->cmft.data = data;
|
|
|
|
|
2011-10-27 00:59:45 +00:00
|
|
|
data->mmft.buf = grub_malloc (data->mft_size << GRUB_NTFS_BLK_SHR);
|
2007-08-03 07:44:01 +00:00
|
|
|
if (!data->mmft.buf)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (grub_disk_read
|
2011-10-27 00:59:45 +00:00
|
|
|
(disk, data->mft_start, 0, data->mft_size << GRUB_NTFS_BLK_SHR, data->mmft.buf))
|
2007-08-03 07:44:01 +00:00
|
|
|
goto fail;
|
|
|
|
|
2008-06-08 19:18:58 +00:00
|
|
|
data->uuid = grub_le_to_cpu64 (bpb.num_serial);
|
|
|
|
|
2013-01-11 06:41:05 +00:00
|
|
|
if (fixup (data->mmft.buf, data->mft_size, (const grub_uint8_t *) "FILE"))
|
2007-08-03 07:44:01 +00:00
|
|
|
goto fail;
|
|
|
|
|
2011-10-27 00:59:45 +00:00
|
|
|
if (!locate_attr (&data->mmft.attr, &data->mmft, GRUB_NTFS_AT_DATA))
|
2007-08-03 07:44:01 +00:00
|
|
|
goto fail;
|
|
|
|
|
2011-10-27 00:59:45 +00:00
|
|
|
if (init_file (&data->cmft, GRUB_NTFS_FILE_ROOT))
|
2007-08-03 07:44:01 +00:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
return data;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
grub_error (GRUB_ERR_BAD_FS, "not an ntfs filesystem");
|
|
|
|
|
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
free_file (&data->mmft);
|
|
|
|
free_file (&data->cmft);
|
2008-08-21 13:30:32 +00:00
|
|
|
grub_free (data);
|
2007-08-03 07:44:01 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-21 01:33:46 +00:00
|
|
|
/* Context for grub_ntfs_dir. */
|
|
|
|
struct grub_ntfs_dir_ctx
|
|
|
|
{
|
|
|
|
grub_fs_dir_hook_t hook;
|
|
|
|
void *hook_data;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Helper for grub_ntfs_dir. */
|
|
|
|
static int
|
|
|
|
grub_ntfs_dir_iter (const char *filename, enum grub_fshelp_filetype filetype,
|
|
|
|
grub_fshelp_node_t node, void *data)
|
|
|
|
{
|
|
|
|
struct grub_ntfs_dir_ctx *ctx = data;
|
|
|
|
struct grub_dirhook_info info;
|
|
|
|
|
|
|
|
grub_memset (&info, 0, sizeof (info));
|
|
|
|
info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR);
|
|
|
|
info.mtimeset = 1;
|
|
|
|
info.mtime = grub_divmod64 (node->mtime, 10000000, 0)
|
|
|
|
- 86400ULL * 365 * (1970 - 1601)
|
|
|
|
- 86400ULL * ((1970 - 1601) / 4) + 86400ULL * ((1970 - 1601) / 100);
|
|
|
|
grub_free (node);
|
|
|
|
return ctx->hook (filename, &info, ctx->hook_data);
|
|
|
|
}
|
|
|
|
|
2007-08-03 07:44:01 +00:00
|
|
|
static grub_err_t
|
|
|
|
grub_ntfs_dir (grub_device_t device, const char *path,
|
2013-01-21 01:33:46 +00:00
|
|
|
grub_fs_dir_hook_t hook, void *hook_data)
|
2007-08-03 07:44:01 +00:00
|
|
|
{
|
2013-01-21 01:33:46 +00:00
|
|
|
struct grub_ntfs_dir_ctx ctx = { hook, hook_data };
|
2007-08-03 07:44:01 +00:00
|
|
|
struct grub_ntfs_data *data = 0;
|
|
|
|
struct grub_fshelp_node *fdiro = 0;
|
|
|
|
|
|
|
|
grub_dl_ref (my_mod);
|
|
|
|
|
|
|
|
data = grub_ntfs_mount (device->disk);
|
|
|
|
if (!data)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
grub_fshelp_find_file (path, &data->cmft, &fdiro, grub_ntfs_iterate_dir,
|
2011-10-27 01:04:27 +00:00
|
|
|
grub_ntfs_read_symlink, GRUB_FSHELP_DIR);
|
2007-08-03 07:44:01 +00:00
|
|
|
|
|
|
|
if (grub_errno)
|
|
|
|
goto fail;
|
|
|
|
|
2013-01-21 01:33:46 +00:00
|
|
|
grub_ntfs_iterate_dir (fdiro, grub_ntfs_dir_iter, &ctx);
|
2007-08-03 07:44:01 +00:00
|
|
|
|
|
|
|
fail:
|
|
|
|
if ((fdiro) && (fdiro != &data->cmft))
|
|
|
|
{
|
|
|
|
free_file (fdiro);
|
|
|
|
grub_free (fdiro);
|
|
|
|
}
|
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
free_file (&data->mmft);
|
|
|
|
free_file (&data->cmft);
|
|
|
|
grub_free (data);
|
|
|
|
}
|
|
|
|
|
|
|
|
grub_dl_unref (my_mod);
|
|
|
|
|
|
|
|
return grub_errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
static grub_err_t
|
|
|
|
grub_ntfs_open (grub_file_t file, const char *name)
|
|
|
|
{
|
|
|
|
struct grub_ntfs_data *data = 0;
|
|
|
|
struct grub_fshelp_node *mft = 0;
|
|
|
|
|
|
|
|
grub_dl_ref (my_mod);
|
|
|
|
|
|
|
|
data = grub_ntfs_mount (file->device->disk);
|
|
|
|
if (!data)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
grub_fshelp_find_file (name, &data->cmft, &mft, grub_ntfs_iterate_dir,
|
2011-10-27 01:04:27 +00:00
|
|
|
grub_ntfs_read_symlink, GRUB_FSHELP_REG);
|
2007-08-03 07:44:01 +00:00
|
|
|
|
|
|
|
if (grub_errno)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (mft != &data->cmft)
|
|
|
|
{
|
|
|
|
free_file (&data->cmft);
|
|
|
|
grub_memcpy (&data->cmft, mft, sizeof (*mft));
|
|
|
|
grub_free (mft);
|
|
|
|
if (!data->cmft.inode_read)
|
|
|
|
{
|
|
|
|
if (init_file (&data->cmft, data->cmft.ino))
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
file->size = data->cmft.size;
|
|
|
|
file->data = data;
|
|
|
|
file->offset = 0;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
free_file (&data->mmft);
|
|
|
|
free_file (&data->cmft);
|
|
|
|
grub_free (data);
|
|
|
|
}
|
|
|
|
|
|
|
|
grub_dl_unref (my_mod);
|
|
|
|
|
|
|
|
return grub_errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
static grub_ssize_t
|
|
|
|
grub_ntfs_read (grub_file_t file, char *buf, grub_size_t len)
|
|
|
|
{
|
|
|
|
struct grub_ntfs_file *mft;
|
|
|
|
|
|
|
|
mft = &((struct grub_ntfs_data *) file->data)->cmft;
|
|
|
|
if (file->read_hook)
|
|
|
|
mft->attr.save_pos = 1;
|
|
|
|
|
2013-01-11 06:41:05 +00:00
|
|
|
read_attr (&mft->attr, (grub_uint8_t *) buf, file->offset, len, 1,
|
2013-02-27 16:19:15 +00:00
|
|
|
file->read_hook, file->read_hook_data);
|
2012-05-04 15:37:17 +00:00
|
|
|
return (grub_errno) ? -1 : (grub_ssize_t) len;
|
2007-08-03 07:44:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static grub_err_t
|
|
|
|
grub_ntfs_close (grub_file_t file)
|
|
|
|
{
|
|
|
|
struct grub_ntfs_data *data;
|
|
|
|
|
|
|
|
data = file->data;
|
|
|
|
|
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
free_file (&data->mmft);
|
|
|
|
free_file (&data->cmft);
|
|
|
|
grub_free (data);
|
|
|
|
}
|
|
|
|
|
|
|
|
grub_dl_unref (my_mod);
|
|
|
|
|
|
|
|
return grub_errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
static grub_err_t
|
|
|
|
grub_ntfs_label (grub_device_t device, char **label)
|
|
|
|
{
|
|
|
|
struct grub_ntfs_data *data = 0;
|
|
|
|
struct grub_fshelp_node *mft = 0;
|
2013-01-11 06:41:05 +00:00
|
|
|
grub_uint8_t *pa;
|
2007-08-03 07:44:01 +00:00
|
|
|
|
|
|
|
grub_dl_ref (my_mod);
|
|
|
|
|
|
|
|
*label = 0;
|
|
|
|
|
|
|
|
data = grub_ntfs_mount (device->disk);
|
|
|
|
if (!data)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
grub_fshelp_find_file ("/$Volume", &data->cmft, &mft, grub_ntfs_iterate_dir,
|
|
|
|
0, GRUB_FSHELP_REG);
|
|
|
|
|
|
|
|
if (grub_errno)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (!mft->inode_read)
|
|
|
|
{
|
2011-10-27 00:59:45 +00:00
|
|
|
mft->buf = grub_malloc (mft->data->mft_size << GRUB_NTFS_BLK_SHR);
|
2007-08-03 07:44:01 +00:00
|
|
|
if (mft->buf == NULL)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (read_mft (mft->data, mft->buf, mft->ino))
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
init_attr (&mft->attr, mft);
|
2011-10-27 00:59:45 +00:00
|
|
|
pa = find_attr (&mft->attr, GRUB_NTFS_AT_VOLUME_NAME);
|
2007-08-03 07:44:01 +00:00
|
|
|
if ((pa) && (pa[8] == 0) && (u32at (pa, 0x10)))
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
|
|
|
|
len = u32at (pa, 0x10) / 2;
|
|
|
|
pa += u16at (pa, 0x14);
|
2013-10-21 11:04:41 +00:00
|
|
|
*label = get_utf8 (pa, len);
|
2007-08-03 07:44:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fail:
|
|
|
|
if ((mft) && (mft != &data->cmft))
|
|
|
|
{
|
|
|
|
free_file (mft);
|
|
|
|
grub_free (mft);
|
|
|
|
}
|
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
free_file (&data->mmft);
|
|
|
|
free_file (&data->cmft);
|
|
|
|
grub_free (data);
|
|
|
|
}
|
|
|
|
|
|
|
|
grub_dl_unref (my_mod);
|
|
|
|
|
|
|
|
return grub_errno;
|
|
|
|
}
|
|
|
|
|
2008-06-08 19:18:58 +00:00
|
|
|
static grub_err_t
|
|
|
|
grub_ntfs_uuid (grub_device_t device, char **uuid)
|
|
|
|
{
|
|
|
|
struct grub_ntfs_data *data;
|
|
|
|
grub_disk_t disk = device->disk;
|
|
|
|
|
|
|
|
grub_dl_ref (my_mod);
|
|
|
|
|
|
|
|
data = grub_ntfs_mount (disk);
|
|
|
|
if (data)
|
|
|
|
{
|
2010-11-06 20:54:24 +00:00
|
|
|
char *ptr;
|
2010-01-20 08:12:47 +00:00
|
|
|
*uuid = grub_xasprintf ("%016llx", (unsigned long long) data->uuid);
|
2010-11-06 20:54:24 +00:00
|
|
|
if (*uuid)
|
|
|
|
for (ptr = *uuid; *ptr; ptr++)
|
|
|
|
*ptr = grub_toupper (*ptr);
|
2011-10-25 22:29:46 +00:00
|
|
|
free_file (&data->mmft);
|
|
|
|
free_file (&data->cmft);
|
|
|
|
grub_free (data);
|
2008-06-08 19:18:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
*uuid = NULL;
|
|
|
|
|
|
|
|
grub_dl_unref (my_mod);
|
|
|
|
|
|
|
|
return grub_errno;
|
|
|
|
}
|
|
|
|
|
2009-10-25 15:23:48 +00:00
|
|
|
static struct grub_fs grub_ntfs_fs =
|
|
|
|
{
|
|
|
|
.name = "ntfs",
|
|
|
|
.dir = grub_ntfs_dir,
|
|
|
|
.open = grub_ntfs_open,
|
|
|
|
.read = grub_ntfs_read,
|
|
|
|
.close = grub_ntfs_close,
|
|
|
|
.label = grub_ntfs_label,
|
|
|
|
.uuid = grub_ntfs_uuid,
|
|
|
|
#ifdef GRUB_UTIL
|
|
|
|
.reserved_first_sector = 1,
|
2012-02-27 20:36:58 +00:00
|
|
|
.blocklist_install = 1,
|
2009-10-25 15:23:48 +00:00
|
|
|
#endif
|
|
|
|
.next = 0
|
2007-08-03 07:44:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
GRUB_MOD_INIT (ntfs)
|
|
|
|
{
|
|
|
|
grub_fs_register (&grub_ntfs_fs);
|
|
|
|
my_mod = mod;
|
|
|
|
}
|
|
|
|
|
|
|
|
GRUB_MOD_FINI (ntfs)
|
|
|
|
{
|
|
|
|
grub_fs_unregister (&grub_ntfs_fs);
|
|
|
|
}
|