* include/grub/ntfs.h: Add GRUB_NTFS_ prefix. All users updated.

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2011-10-27 02:59:45 +02:00
parent 3be82e10a9
commit 91c3fdde0d
4 changed files with 181 additions and 156 deletions

View file

@ -1,3 +1,7 @@
2011-10-26 Vladimir Serbinenko <phcoder@gmail.com>
* include/grub/ntfs.h: Add GRUB_NTFS_ prefix. All users updated.
2011-10-26 Vladimir Serbinenko <phcoder@gmail.com> 2011-10-26 Vladimir Serbinenko <phcoder@gmail.com>
fstest xnu_uuid subcommand. fstest xnu_uuid subcommand.

View file

@ -17,6 +17,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#define grub_fshelp_node grub_ntfs_file
#include <grub/file.h> #include <grub/file.h>
#include <grub/mm.h> #include <grub/mm.h>
#include <grub/misc.h> #include <grub/misc.h>
@ -30,7 +32,19 @@ GRUB_MOD_LICENSE ("GPLv3+");
static grub_dl_t my_mod; static grub_dl_t my_mod;
ntfscomp_func_t grub_ntfscomp_func; #define grub_fshelp_node grub_ntfs_file
#define valueat(buf,ofs,type) *((type*)(((char*)buf)+ofs))
#define u16at(buf,ofs) grub_le_to_cpu16(valueat(buf,ofs,grub_uint16_t))
#define u32at(buf,ofs) grub_le_to_cpu32(valueat(buf,ofs,grub_uint32_t))
#define u64at(buf,ofs) grub_le_to_cpu64(valueat(buf,ofs,grub_uint64_t))
#define v16at(buf,ofs) valueat(buf,ofs,grub_uint16_t)
#define v32at(buf,ofs) valueat(buf,ofs,grub_uint32_t)
#define v64at(buf,ofs) valueat(buf,ofs,grub_uint64_t)
grub_ntfscomp_func_t grub_ntfscomp_func;
static grub_err_t static grub_err_t
fixup (struct grub_ntfs_data *data, char *buf, int len, char *magic) fixup (struct grub_ntfs_data *data, char *buf, int len, char *magic)
@ -87,7 +101,7 @@ static void
init_attr (struct grub_ntfs_attr *at, struct grub_ntfs_file *mft) init_attr (struct grub_ntfs_attr *at, struct grub_ntfs_file *mft)
{ {
at->mft = mft; at->mft = mft;
at->flags = (mft == &mft->data->mmft) ? AF_MMFT : 0; at->flags = (mft == &mft->data->mmft) ? GRUB_NTFS_AF_MMFT : 0;
at->attr_nxt = mft->buf + u16at (mft->buf, 0x14); at->attr_nxt = mft->buf + u16at (mft->buf, 0x14);
at->attr_end = at->emft_buf = at->edat_buf = at->sbuf = NULL; at->attr_end = at->emft_buf = at->edat_buf = at->sbuf = NULL;
} }
@ -103,7 +117,7 @@ free_attr (struct grub_ntfs_attr *at)
static char * static char *
find_attr (struct grub_ntfs_attr *at, unsigned char attr) find_attr (struct grub_ntfs_attr *at, unsigned char attr)
{ {
if (at->flags & AF_ALST) if (at->flags & GRUB_NTFS_AF_ALST)
{ {
retry: retry:
while (at->attr_nxt < at->attr_end) while (at->attr_nxt < at->attr_end)
@ -114,7 +128,7 @@ find_attr (struct grub_ntfs_attr *at, unsigned char attr)
{ {
char *new_pos; char *new_pos;
if (at->flags & AF_MMFT) if (at->flags & GRUB_NTFS_AF_MMFT)
{ {
if ((grub_disk_read if ((grub_disk_read
(at->mft->data->disk, v32at (at->attr_cur, 0x10), 0, (at->mft->data->disk, v32at (at->attr_cur, 0x10), 0,
@ -160,7 +174,7 @@ find_attr (struct grub_ntfs_attr *at, unsigned char attr)
while ((unsigned char) *at->attr_cur != 0xFF) while ((unsigned char) *at->attr_cur != 0xFF)
{ {
at->attr_nxt += u16at (at->attr_cur, 4); at->attr_nxt += u16at (at->attr_cur, 4);
if ((unsigned char) *at->attr_cur == AT_ATTRIBUTE_LIST) if ((unsigned char) *at->attr_cur == GRUB_NTFS_AT_ATTRIBUTE_LIST)
at->attr_end = at->attr_cur; at->attr_end = at->attr_cur;
if (((unsigned char) *at->attr_cur == attr) || (attr == 0)) if (((unsigned char) *at->attr_cur == attr) || (attr == 0))
return at->attr_cur; return at->attr_cur;
@ -170,7 +184,7 @@ find_attr (struct grub_ntfs_attr *at, unsigned char attr)
{ {
char *pa; char *pa;
at->emft_buf = grub_malloc (at->mft->data->mft_size << BLK_SHR); at->emft_buf = grub_malloc (at->mft->data->mft_size << GRUB_NTFS_BLK_SHR);
if (at->emft_buf == NULL) if (at->emft_buf == NULL)
return NULL; return NULL;
@ -199,7 +213,7 @@ find_attr (struct grub_ntfs_attr *at, unsigned char attr)
at->attr_nxt = at->attr_end + u16at (pa, 0x14); at->attr_nxt = at->attr_end + u16at (pa, 0x14);
at->attr_end = at->attr_end + u32at (pa, 4); at->attr_end = at->attr_end + u32at (pa, 4);
} }
at->flags |= AF_ALST; at->flags |= GRUB_NTFS_AF_ALST;
while (at->attr_nxt < at->attr_end) while (at->attr_nxt < at->attr_end)
{ {
if (((unsigned char) *at->attr_nxt == attr) || (attr == 0)) if (((unsigned char) *at->attr_nxt == attr) || (attr == 0))
@ -209,9 +223,9 @@ find_attr (struct grub_ntfs_attr *at, unsigned char attr)
if (at->attr_nxt >= at->attr_end) if (at->attr_nxt >= at->attr_end)
return NULL; return NULL;
if ((at->flags & AF_MMFT) && (attr == AT_DATA)) if ((at->flags & GRUB_NTFS_AF_MMFT) && (attr == GRUB_NTFS_AT_DATA))
{ {
at->flags |= AF_GPOS; at->flags |= GRUB_NTFS_AF_GPOS;
at->attr_cur = at->attr_nxt; at->attr_cur = at->attr_nxt;
pa = at->attr_cur; pa = at->attr_cur;
v32at (pa, 0x10) = at->mft->data->mft_start; v32at (pa, 0x10) = at->mft->data->mft_start;
@ -223,13 +237,13 @@ find_attr (struct grub_ntfs_attr *at, unsigned char attr)
break; break;
if (read_attr if (read_attr
(at, pa + 0x10, (at, pa + 0x10,
u32at (pa, 0x10) * (at->mft->data->mft_size << BLK_SHR), u32at (pa, 0x10) * (at->mft->data->mft_size << GRUB_NTFS_BLK_SHR),
at->mft->data->mft_size << BLK_SHR, 0, 0)) at->mft->data->mft_size << GRUB_NTFS_BLK_SHR, 0, 0))
return NULL; return NULL;
pa += u16at (pa, 4); pa += u16at (pa, 4);
} }
at->attr_nxt = at->attr_cur; at->attr_nxt = at->attr_cur;
at->flags &= ~AF_GPOS; at->flags &= ~GRUB_NTFS_AF_GPOS;
} }
goto retry; goto retry;
} }
@ -245,13 +259,13 @@ locate_attr (struct grub_ntfs_attr *at, struct grub_ntfs_file *mft,
init_attr (at, mft); init_attr (at, mft);
if ((pa = find_attr (at, attr)) == NULL) if ((pa = find_attr (at, attr)) == NULL)
return NULL; return NULL;
if ((at->flags & AF_ALST) == 0) if ((at->flags & GRUB_NTFS_AF_ALST) == 0)
{ {
while (1) while (1)
{ {
if ((pa = find_attr (at, attr)) == NULL) if ((pa = find_attr (at, attr)) == NULL)
break; break;
if (at->flags & AF_ALST) if (at->flags & GRUB_NTFS_AF_ALST)
return pa; return pa;
} }
grub_errno = GRUB_ERR_NONE; grub_errno = GRUB_ERR_NONE;
@ -296,7 +310,7 @@ retry:
c2 = ((unsigned char) (*run) >> 4); c2 = ((unsigned char) (*run) >> 4);
if (!c1) if (!c1)
{ {
if ((ctx->attr) && (ctx->attr->flags & AF_ALST)) if ((ctx->attr) && (ctx->attr->flags & GRUB_NTFS_AF_ALST))
{ {
void NESTED_FUNC_ATTR (*save_hook) (grub_disk_addr_t sector, void NESTED_FUNC_ATTR (*save_hook) (grub_disk_addr_t sector,
unsigned offset, unsigned offset,
@ -325,9 +339,9 @@ retry:
run = read_run_data (run, c2, &val, 1); /* offset to previous LCN */ run = read_run_data (run, c2, &val, 1); /* offset to previous LCN */
ctx->curr_lcn += val; ctx->curr_lcn += val;
if (val == 0) if (val == 0)
ctx->flags |= RF_BLNK; ctx->flags |= GRUB_NTFS_RF_BLNK;
else else
ctx->flags &= ~RF_BLNK; ctx->flags &= ~GRUB_NTFS_RF_BLNK;
ctx->cur_run = run; ctx->cur_run = run;
return 0; return 0;
} }
@ -345,7 +359,7 @@ grub_ntfs_read_block (grub_fshelp_node_t node, grub_disk_addr_t block)
return ctx->curr_lcn; return ctx->curr_lcn;
} }
else else
return (ctx->flags & RF_BLNK) ? 0 : (block - return (ctx->flags & GRUB_NTFS_RF_BLNK) ? 0 : (block -
ctx->curr_vcn + ctx->curr_lcn); ctx->curr_vcn + ctx->curr_lcn);
} }
@ -376,24 +390,24 @@ read_data (struct grub_ntfs_attr *at, char *pa, char *dest,
return 0; return 0;
} }
if (u16at (pa, 0xC) & FLAG_COMPRESSED) if (u16at (pa, 0xC) & GRUB_NTFS_FLAG_COMPRESSED)
ctx->flags |= RF_COMP; ctx->flags |= GRUB_NTFS_RF_COMP;
else else
ctx->flags &= ~RF_COMP; ctx->flags &= ~GRUB_NTFS_RF_COMP;
ctx->cur_run = pa + u16at (pa, 0x20); ctx->cur_run = pa + u16at (pa, 0x20);
if (ctx->flags & RF_COMP) if (ctx->flags & GRUB_NTFS_RF_COMP)
{ {
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) if (at->sbuf)
{ {
if ((ofs & (~(COM_LEN - 1))) == at->save_pos) if ((ofs & (~(GRUB_NTFS_COM_LEN - 1))) == at->save_pos)
{ {
grub_disk_addr_t n; grub_disk_addr_t n;
n = COM_LEN - (ofs - at->save_pos); n = GRUB_NTFS_COM_LEN - (ofs - at->save_pos);
if (n > len) if (n > len)
n = len; n = len;
@ -408,17 +422,17 @@ read_data (struct grub_ntfs_attr *at, char *pa, char *dest,
} }
else else
{ {
at->sbuf = grub_malloc (COM_LEN); at->sbuf = grub_malloc (GRUB_NTFS_COM_LEN);
if (at->sbuf == NULL) if (at->sbuf == NULL)
return grub_errno; return grub_errno;
at->save_pos = 1; at->save_pos = 1;
} }
vcn = ctx->target_vcn = (ofs >> COM_LOG_LEN) * (COM_SEC / ctx->comp.spc); vcn = ctx->target_vcn = (ofs >> GRUB_NTFS_COM_LOG_LEN) * (GRUB_NTFS_COM_SEC / ctx->comp.spc);
ctx->target_vcn &= ~0xF; ctx->target_vcn &= ~0xF;
} }
else else
vcn = ctx->target_vcn = grub_divmod64 (ofs >> BLK_SHR, ctx->comp.spc, 0); vcn = ctx->target_vcn = grub_divmod64 (ofs >> GRUB_NTFS_BLK_SHR, ctx->comp.spc, 0);
ctx->next_vcn = u32at (pa, 0x10); ctx->next_vcn = u32at (pa, 0x10);
ctx->curr_lcn = 0; ctx->curr_lcn = 0;
@ -428,12 +442,12 @@ read_data (struct grub_ntfs_attr *at, char *pa, char *dest,
return grub_errno; return grub_errno;
} }
if (at->flags & AF_GPOS) if (at->flags & GRUB_NTFS_AF_GPOS)
{ {
grub_disk_addr_t st0, st1; grub_disk_addr_t st0, st1;
grub_uint64_t m; grub_uint64_t m;
grub_divmod64 (ofs >> BLK_SHR, ctx->comp.spc, &m); grub_divmod64 (ofs >> GRUB_NTFS_BLK_SHR, ctx->comp.spc, &m);
st0 = st0 =
(ctx->target_vcn - ctx->curr_vcn + ctx->curr_lcn) * ctx->comp.spc + m; (ctx->target_vcn - ctx->curr_vcn + ctx->curr_lcn) * ctx->comp.spc + m;
@ -450,7 +464,7 @@ read_data (struct grub_ntfs_attr *at, char *pa, char *dest,
return 0; return 0;
} }
if (!(ctx->flags & RF_COMP)) if (!(ctx->flags & GRUB_NTFS_RF_COMP))
{ {
unsigned int pow; unsigned int pow;
@ -481,12 +495,12 @@ read_attr (struct grub_ntfs_attr *at, char *dest, grub_disk_addr_t ofs,
save_cur = at->attr_cur; save_cur = at->attr_cur;
at->attr_nxt = at->attr_cur; at->attr_nxt = at->attr_cur;
attr = (unsigned char) *at->attr_nxt; attr = (unsigned char) *at->attr_nxt;
if (at->flags & AF_ALST) if (at->flags & GRUB_NTFS_AF_ALST)
{ {
char *pa; char *pa;
grub_disk_addr_t vcn; grub_disk_addr_t vcn;
vcn = grub_divmod64 (ofs, at->mft->data->spc << BLK_SHR, 0); vcn = grub_divmod64 (ofs, at->mft->data->spc << GRUB_NTFS_BLK_SHR, 0);
pa = at->attr_nxt + u16at (at->attr_nxt, 4); pa = at->attr_nxt + u16at (at->attr_nxt, 4);
while (pa < at->attr_end) while (pa < at->attr_end)
{ {
@ -513,8 +527,8 @@ static grub_err_t
read_mft (struct grub_ntfs_data *data, char *buf, grub_uint32_t mftno) read_mft (struct grub_ntfs_data *data, char *buf, grub_uint32_t mftno)
{ {
if (read_attr if (read_attr
(&data->mmft.attr, buf, mftno * ((grub_disk_addr_t) data->mft_size << BLK_SHR), (&data->mmft.attr, buf, mftno * ((grub_disk_addr_t) data->mft_size << GRUB_NTFS_BLK_SHR),
data->mft_size << BLK_SHR, 0, 0)) data->mft_size << GRUB_NTFS_BLK_SHR, 0, 0))
return grub_error (GRUB_ERR_BAD_FS, "read MFT 0x%X fails", mftno); return grub_error (GRUB_ERR_BAD_FS, "read MFT 0x%X fails", mftno);
return fixup (data, buf, data->mft_size, "FILE"); return fixup (data, buf, data->mft_size, "FILE");
} }
@ -526,7 +540,7 @@ init_file (struct grub_ntfs_file *mft, grub_uint32_t mftno)
mft->inode_read = 1; mft->inode_read = 1;
mft->buf = grub_malloc (mft->data->mft_size << BLK_SHR); mft->buf = grub_malloc (mft->data->mft_size << GRUB_NTFS_BLK_SHR);
if (mft->buf == NULL) if (mft->buf == NULL)
return grub_errno; return grub_errno;
@ -541,7 +555,7 @@ init_file (struct grub_ntfs_file *mft, grub_uint32_t mftno)
{ {
char *pa; char *pa;
pa = locate_attr (&mft->attr, mft, AT_DATA); pa = locate_attr (&mft->attr, mft, GRUB_NTFS_AT_DATA);
if (pa == NULL) if (pa == NULL)
return grub_error (GRUB_ERR_BAD_FS, "no $DATA in MFT 0x%X", mftno); return grub_error (GRUB_ERR_BAD_FS, "no $DATA in MFT 0x%X", mftno);
@ -550,7 +564,7 @@ init_file (struct grub_ntfs_file *mft, grub_uint32_t mftno)
else else
mft->size = u64at (pa, 0x30); mft->size = u64at (pa, 0x30);
if ((mft->attr.flags & AF_ALST) == 0) if ((mft->attr.flags & GRUB_NTFS_AF_ALST) == 0)
mft->attr.attr_end = 0; /* Don't jump to attribute list */ mft->attr.attr_end = 0; /* Don't jump to attribute list */
} }
else else
@ -603,7 +617,7 @@ list_file (struct grub_ntfs_file *diro, char *pos,
} }
type = type =
(u32at (pos, 0x48) & ATTR_DIRECTORY) ? GRUB_FSHELP_DIR : (u32at (pos, 0x48) & GRUB_NTFS_ATTR_DIRECTORY) ? GRUB_FSHELP_DIR :
GRUB_FSHELP_REG; GRUB_FSHELP_REG;
fdiro = grub_zalloc (sizeof (struct grub_ntfs_file)); fdiro = grub_zalloc (sizeof (struct grub_ntfs_file));
@ -668,7 +682,7 @@ grub_ntfs_iterate_dir (grub_fshelp_node_t dir,
init_attr (at, mft); init_attr (at, mft);
while (1) while (1)
{ {
if ((cur_pos = find_attr (at, AT_INDEX_ROOT)) == NULL) if ((cur_pos = find_attr (at, GRUB_NTFS_AT_INDEX_ROOT)) == NULL)
{ {
grub_error (GRUB_ERR_BAD_FS, "no $INDEX_ROOT"); grub_error (GRUB_ERR_BAD_FS, "no $INDEX_ROOT");
goto done; goto done;
@ -694,7 +708,7 @@ grub_ntfs_iterate_dir (grub_fshelp_node_t dir,
bitmap_len = 0; bitmap_len = 0;
free_attr (at); free_attr (at);
init_attr (at, mft); init_attr (at, mft);
while ((cur_pos = find_attr (at, AT_BITMAP)) != NULL) while ((cur_pos = find_attr (at, GRUB_NTFS_AT_BITMAP)) != NULL)
{ {
int ofs; int ofs;
@ -735,7 +749,7 @@ grub_ntfs_iterate_dir (grub_fshelp_node_t dir,
} }
free_attr (at); free_attr (at);
cur_pos = locate_attr (at, mft, AT_INDEX_ALLOCATION); cur_pos = locate_attr (at, mft, GRUB_NTFS_AT_INDEX_ALLOCATION);
while (cur_pos != NULL) while (cur_pos != NULL)
{ {
/* Non-resident, Namelen=4, Offset=0x40, Flags=0, Name="$I30" */ /* Non-resident, Namelen=4, Offset=0x40, Flags=0, Name="$I30" */
@ -743,7 +757,7 @@ grub_ntfs_iterate_dir (grub_fshelp_node_t dir,
(u32at (cur_pos, 0x40) == 0x490024) && (u32at (cur_pos, 0x40) == 0x490024) &&
(u32at (cur_pos, 0x44) == 0x300033)) (u32at (cur_pos, 0x44) == 0x300033))
break; break;
cur_pos = find_attr (at, AT_INDEX_ALLOCATION); cur_pos = find_attr (at, GRUB_NTFS_AT_INDEX_ALLOCATION);
} }
if ((!cur_pos) && (bitmap)) if ((!cur_pos) && (bitmap))
@ -756,7 +770,7 @@ grub_ntfs_iterate_dir (grub_fshelp_node_t dir,
{ {
grub_disk_addr_t v, i; grub_disk_addr_t v, i;
indx = grub_malloc (mft->data->idx_size << BLK_SHR); indx = grub_malloc (mft->data->idx_size << GRUB_NTFS_BLK_SHR);
if (indx == NULL) if (indx == NULL)
goto done; goto done;
@ -766,8 +780,8 @@ grub_ntfs_iterate_dir (grub_fshelp_node_t dir,
if (*bitmap & v) if (*bitmap & v)
{ {
if ((read_attr if ((read_attr
(at, indx, i * (mft->data->idx_size << BLK_SHR), (at, indx, i * (mft->data->idx_size << GRUB_NTFS_BLK_SHR),
(mft->data->idx_size << BLK_SHR), 0, 0)) (mft->data->idx_size << GRUB_NTFS_BLK_SHR), 0, 0))
|| (fixup (mft->data, indx, mft->data->idx_size, "INDX"))) || (fixup (mft->data, indx, mft->data->idx_size, "INDX")))
goto done; goto done;
ret = list_file (mft, &indx[0x18 + u16at (indx, 0x18)], hook); ret = list_file (mft, &indx[0x18 + u16at (indx, 0x18)], hook);
@ -814,32 +828,32 @@ grub_ntfs_mount (grub_disk_t disk)
goto fail; goto fail;
data->blocksize = grub_le_to_cpu16 (bpb.bytes_per_sector); data->blocksize = grub_le_to_cpu16 (bpb.bytes_per_sector);
data->spc = bpb.sectors_per_cluster * (data->blocksize >> BLK_SHR); data->spc = bpb.sectors_per_cluster * (data->blocksize >> GRUB_NTFS_BLK_SHR);
if (bpb.clusters_per_mft > 0) if (bpb.clusters_per_mft > 0)
data->mft_size = data->spc * bpb.clusters_per_mft; data->mft_size = data->spc * bpb.clusters_per_mft;
else else
data->mft_size = 1 << (-bpb.clusters_per_mft - BLK_SHR); data->mft_size = 1 << (-bpb.clusters_per_mft - GRUB_NTFS_BLK_SHR);
if (bpb.clusters_per_index > 0) if (bpb.clusters_per_index > 0)
data->idx_size = data->spc * bpb.clusters_per_index; data->idx_size = data->spc * bpb.clusters_per_index;
else else
data->idx_size = 1 << (-bpb.clusters_per_index - BLK_SHR); data->idx_size = 1 << (-bpb.clusters_per_index - GRUB_NTFS_BLK_SHR);
data->mft_start = grub_le_to_cpu64 (bpb.mft_lcn) * data->spc; data->mft_start = grub_le_to_cpu64 (bpb.mft_lcn) * data->spc;
if ((data->mft_size > MAX_MFT) || (data->idx_size > MAX_IDX)) if ((data->mft_size > GRUB_NTFS_MAX_MFT) || (data->idx_size > GRUB_NTFS_MAX_IDX))
goto fail; goto fail;
data->mmft.data = data; data->mmft.data = data;
data->cmft.data = data; data->cmft.data = data;
data->mmft.buf = grub_malloc (data->mft_size << BLK_SHR); data->mmft.buf = grub_malloc (data->mft_size << GRUB_NTFS_BLK_SHR);
if (!data->mmft.buf) if (!data->mmft.buf)
goto fail; goto fail;
if (grub_disk_read if (grub_disk_read
(disk, data->mft_start, 0, data->mft_size << BLK_SHR, data->mmft.buf)) (disk, data->mft_start, 0, data->mft_size << GRUB_NTFS_BLK_SHR, data->mmft.buf))
goto fail; goto fail;
data->uuid = grub_le_to_cpu64 (bpb.num_serial); data->uuid = grub_le_to_cpu64 (bpb.num_serial);
@ -847,10 +861,10 @@ grub_ntfs_mount (grub_disk_t disk)
if (fixup (data, data->mmft.buf, data->mft_size, "FILE")) if (fixup (data, data->mmft.buf, data->mft_size, "FILE"))
goto fail; goto fail;
if (!locate_attr (&data->mmft.attr, &data->mmft, AT_DATA)) if (!locate_attr (&data->mmft.attr, &data->mmft, GRUB_NTFS_AT_DATA))
goto fail; goto fail;
if (init_file (&data->cmft, FILE_ROOT)) if (init_file (&data->cmft, GRUB_NTFS_FILE_ROOT))
goto fail; goto fail;
return data; return data;
@ -1030,7 +1044,7 @@ grub_ntfs_label (grub_device_t device, char **label)
if (!mft->inode_read) if (!mft->inode_read)
{ {
mft->buf = grub_malloc (mft->data->mft_size << BLK_SHR); mft->buf = grub_malloc (mft->data->mft_size << GRUB_NTFS_BLK_SHR);
if (mft->buf == NULL) if (mft->buf == NULL)
goto fail; goto fail;
@ -1039,7 +1053,7 @@ grub_ntfs_label (grub_device_t device, char **label)
} }
init_attr (&mft->attr, mft); init_attr (&mft->attr, mft);
pa = find_attr (&mft->attr, AT_VOLUME_NAME); pa = find_attr (&mft->attr, GRUB_NTFS_AT_VOLUME_NAME);
if ((pa) && (pa[8] == 0) && (u32at (pa, 0x10))) if ((pa) && (pa[8] == 0) && (u32at (pa, 0x10)))
{ {
char *buf; char *buf;

View file

@ -21,7 +21,6 @@
#include <grub/misc.h> #include <grub/misc.h>
#include <grub/disk.h> #include <grub/disk.h>
#include <grub/dl.h> #include <grub/dl.h>
#include <grub/fshelp.h>
#include <grub/ntfs.h> #include <grub/ntfs.h>
GRUB_MOD_LICENSE ("GPLv3+"); GRUB_MOD_LICENSE ("GPLv3+");
@ -35,7 +34,7 @@ decomp_nextvcn (struct grub_ntfs_comp *cc)
(cc->disk, (cc->disk,
(cc->comp_table[cc->comp_head][1] - (cc->comp_table[cc->comp_head][1] -
(cc->comp_table[cc->comp_head][0] - cc->cbuf_vcn)) * cc->spc, 0, (cc->comp_table[cc->comp_head][0] - cc->cbuf_vcn)) * cc->spc, 0,
cc->spc << BLK_SHR, cc->cbuf)) cc->spc << GRUB_NTFS_BLK_SHR, cc->cbuf))
return grub_errno; return grub_errno;
cc->cbuf_vcn++; cc->cbuf_vcn++;
if ((cc->cbuf_vcn >= cc->comp_table[cc->comp_head][0])) if ((cc->cbuf_vcn >= cc->comp_table[cc->comp_head][0]))
@ -47,7 +46,7 @@ decomp_nextvcn (struct grub_ntfs_comp *cc)
static grub_err_t static grub_err_t
decomp_getch (struct grub_ntfs_comp *cc, unsigned char *res) decomp_getch (struct grub_ntfs_comp *cc, unsigned char *res)
{ {
if (cc->cbuf_ofs >= (cc->spc << BLK_SHR)) if (cc->cbuf_ofs >= (cc->spc << GRUB_NTFS_BLK_SHR))
{ {
if (decomp_nextvcn (cc)) if (decomp_nextvcn (cc))
return grub_errno; return grub_errno;
@ -87,7 +86,7 @@ decomp_block (struct grub_ntfs_comp *cc, char *dest)
bits = copied = tag = 0; bits = copied = tag = 0;
while (cnt > 0) while (cnt > 0)
{ {
if (copied > COM_LEN) if (copied > GRUB_NTFS_COM_LEN)
return grub_error (GRUB_ERR_BAD_FS, return grub_error (GRUB_ERR_BAD_FS,
"compression block too large"); "compression block too large");
@ -150,7 +149,7 @@ decomp_block (struct grub_ntfs_comp *cc, char *dest)
} }
else else
{ {
if (cnt != COM_LEN) if (cnt != GRUB_NTFS_COM_LEN)
return grub_error (GRUB_ERR_BAD_FS, return grub_error (GRUB_ERR_BAD_FS,
"invalid compression block size"); "invalid compression block size");
} }
@ -160,7 +159,7 @@ decomp_block (struct grub_ntfs_comp *cc, char *dest)
{ {
int n; int n;
n = (cc->spc << BLK_SHR) - cc->cbuf_ofs; n = (cc->spc << GRUB_NTFS_BLK_SHR) - cc->cbuf_ofs;
if (n > cnt) if (n > cnt)
n = cnt; n = cnt;
if ((dest) && (n)) if ((dest) && (n))
@ -179,7 +178,7 @@ decomp_block (struct grub_ntfs_comp *cc, char *dest)
static grub_err_t static grub_err_t
read_block (struct grub_ntfs_rlst *ctx, char *buf, int num) read_block (struct grub_ntfs_rlst *ctx, char *buf, int num)
{ {
int cpb = COM_SEC / ctx->comp.spc; int cpb = GRUB_NTFS_COM_SEC / ctx->comp.spc;
while (num) while (num)
{ {
@ -192,7 +191,7 @@ read_block (struct grub_ntfs_rlst *ctx, char *buf, int num)
return grub_error (GRUB_ERR_BAD_FS, "invalid compression block"); return grub_error (GRUB_ERR_BAD_FS, "invalid compression block");
ctx->comp.comp_head = ctx->comp.comp_tail = 0; ctx->comp.comp_head = ctx->comp.comp_tail = 0;
ctx->comp.cbuf_vcn = ctx->target_vcn; ctx->comp.cbuf_vcn = ctx->target_vcn;
ctx->comp.cbuf_ofs = (ctx->comp.spc << BLK_SHR); ctx->comp.cbuf_ofs = (ctx->comp.spc << GRUB_NTFS_BLK_SHR);
if (ctx->target_vcn >= ctx->next_vcn) if (ctx->target_vcn >= ctx->next_vcn)
{ {
if (grub_ntfs_read_run_list (ctx)) if (grub_ntfs_read_run_list (ctx))
@ -200,7 +199,7 @@ read_block (struct grub_ntfs_rlst *ctx, char *buf, int num)
} }
while (ctx->target_vcn + 16 > ctx->next_vcn) while (ctx->target_vcn + 16 > ctx->next_vcn)
{ {
if (ctx->flags & RF_BLNK) if (ctx->flags & GRUB_NTFS_RF_BLNK)
break; break;
ctx->comp.comp_table[ctx->comp.comp_tail][0] = ctx->next_vcn; ctx->comp.comp_table[ctx->comp.comp_tail][0] = ctx->next_vcn;
ctx->comp.comp_table[ctx->comp.comp_tail][1] = ctx->comp.comp_table[ctx->comp.comp_tail][1] =
@ -216,15 +215,15 @@ read_block (struct grub_ntfs_rlst *ctx, char *buf, int num)
nn = num; nn = num;
num -= nn; num -= nn;
if (ctx->flags & RF_BLNK) if (ctx->flags & GRUB_NTFS_RF_BLNK)
{ {
ctx->target_vcn += nn * cpb; ctx->target_vcn += nn * cpb;
if (ctx->comp.comp_tail == 0) if (ctx->comp.comp_tail == 0)
{ {
if (buf) if (buf)
{ {
grub_memset (buf, 0, nn * COM_LEN); grub_memset (buf, 0, nn * GRUB_NTFS_COM_LEN);
buf += nn * COM_LEN; buf += nn * GRUB_NTFS_COM_LEN;
} }
} }
else else
@ -234,7 +233,7 @@ read_block (struct grub_ntfs_rlst *ctx, char *buf, int num)
if (decomp_block (&ctx->comp, buf)) if (decomp_block (&ctx->comp, buf))
return grub_errno; return grub_errno;
if (buf) if (buf)
buf += COM_LEN; buf += GRUB_NTFS_COM_LEN;
nn--; nn--;
} }
} }
@ -259,9 +258,9 @@ read_block (struct grub_ntfs_rlst *ctx, char *buf, int num)
(ctx->comp.comp_table[ctx->comp.comp_head][1] - (ctx->comp.comp_table[ctx->comp.comp_head][1] -
(ctx->comp.comp_table[ctx->comp.comp_head][0] - (ctx->comp.comp_table[ctx->comp.comp_head][0] -
ctx->target_vcn)) * ctx->comp.spc, 0, ctx->target_vcn)) * ctx->comp.spc, 0,
tt * (ctx->comp.spc << BLK_SHR), buf)) tt * (ctx->comp.spc << GRUB_NTFS_BLK_SHR), buf))
return grub_errno; return grub_errno;
buf += tt * (ctx->comp.spc << BLK_SHR); buf += tt * (ctx->comp.spc << GRUB_NTFS_BLK_SHR);
} }
nn -= tt; nn -= tt;
if (ctx->target_vcn >= if (ctx->target_vcn >=
@ -276,9 +275,9 @@ read_block (struct grub_ntfs_rlst *ctx, char *buf, int num)
(ctx->comp.disk, (ctx->comp.disk,
(ctx->target_vcn - ctx->curr_vcn + (ctx->target_vcn - ctx->curr_vcn +
ctx->curr_lcn) * ctx->comp.spc, 0, ctx->curr_lcn) * ctx->comp.spc, 0,
nn * (ctx->comp.spc << BLK_SHR), buf)) nn * (ctx->comp.spc << GRUB_NTFS_BLK_SHR), buf))
return grub_errno; return grub_errno;
buf += nn * (ctx->comp.spc << BLK_SHR); buf += nn * (ctx->comp.spc << GRUB_NTFS_BLK_SHR);
} }
ctx->target_vcn += nn; ctx->target_vcn += nn;
} }
@ -294,7 +293,7 @@ ntfscomp (struct grub_ntfs_attr *at, char *dest, grub_uint32_t ofs,
grub_err_t ret; grub_err_t ret;
ctx->comp.comp_head = ctx->comp.comp_tail = 0; ctx->comp.comp_head = ctx->comp.comp_tail = 0;
ctx->comp.cbuf = grub_malloc ((ctx->comp.spc) << BLK_SHR); ctx->comp.cbuf = grub_malloc ((ctx->comp.spc) << GRUB_NTFS_BLK_SHR);
if (!ctx->comp.cbuf) if (!ctx->comp.cbuf)
return 0; return 0;
@ -304,17 +303,17 @@ ntfscomp (struct grub_ntfs_attr *at, char *dest, grub_uint32_t ofs,
if ((vcn > ctx->target_vcn) && if ((vcn > ctx->target_vcn) &&
(read_block (read_block
(ctx, NULL, ((vcn - ctx->target_vcn) * ctx->comp.spc) / COM_SEC))) (ctx, NULL, ((vcn - ctx->target_vcn) * ctx->comp.spc) / GRUB_NTFS_COM_SEC)))
{ {
ret = grub_errno; ret = grub_errno;
goto quit; goto quit;
} }
if (ofs % COM_LEN) if (ofs % GRUB_NTFS_COM_LEN)
{ {
grub_uint32_t t, n, o; grub_uint32_t t, n, o;
t = ctx->target_vcn * (ctx->comp.spc << BLK_SHR); t = ctx->target_vcn * (ctx->comp.spc << GRUB_NTFS_BLK_SHR);
if (read_block (ctx, at->sbuf, 1)) if (read_block (ctx, at->sbuf, 1))
{ {
ret = grub_errno; ret = grub_errno;
@ -323,8 +322,8 @@ ntfscomp (struct grub_ntfs_attr *at, char *dest, grub_uint32_t ofs,
at->save_pos = t; at->save_pos = t;
o = ofs % COM_LEN; o = ofs % GRUB_NTFS_COM_LEN;
n = 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, &at->sbuf[o], n);
@ -334,19 +333,19 @@ ntfscomp (struct grub_ntfs_attr *at, char *dest, grub_uint32_t ofs,
len -= n; len -= n;
} }
if (read_block (ctx, dest, len / COM_LEN)) if (read_block (ctx, dest, len / GRUB_NTFS_COM_LEN))
{ {
ret = grub_errno; ret = grub_errno;
goto quit; goto quit;
} }
dest += (len / COM_LEN) * COM_LEN; dest += (len / GRUB_NTFS_COM_LEN) * GRUB_NTFS_COM_LEN;
len = len % COM_LEN; len = len % GRUB_NTFS_COM_LEN;
if (len) if (len)
{ {
grub_uint32_t t; grub_uint32_t t;
t = ctx->target_vcn * (ctx->comp.spc << BLK_SHR); t = ctx->target_vcn * (ctx->comp.spc << GRUB_NTFS_BLK_SHR);
if (read_block (ctx, at->sbuf, 1)) if (read_block (ctx, at->sbuf, 1))
{ {
ret = grub_errno; ret = grub_errno;

View file

@ -20,79 +20,87 @@
#ifndef GRUB_NTFS_H #ifndef GRUB_NTFS_H
#define GRUB_NTFS_H 1 #define GRUB_NTFS_H 1
#define FILE_MFT 0 enum
#define FILE_MFTMIRR 1 {
#define FILE_LOGFILE 2 GRUB_NTFS_FILE_MFT = 0,
#define FILE_VOLUME 3 GRUB_NTFS_FILE_MFTMIRR = 1,
#define FILE_ATTRDEF 4 GRUB_NTFS_FILE_LOGFILE = 2,
#define FILE_ROOT 5 GRUB_NTFS_FILE_VOLUME = 3,
#define FILE_BITMAP 6 GRUB_NTFS_FILE_ATTRDEF = 4,
#define FILE_BOOT 7 GRUB_NTFS_FILE_ROOT = 5,
#define FILE_BADCLUS 8 GRUB_NTFS_FILE_BITMAP = 6,
#define FILE_QUOTA 9 GRUB_NTFS_FILE_BOOT = 7,
#define FILE_UPCASE 10 GRUB_NTFS_FILE_BADCLUS = 8,
GRUB_NTFS_FILE_QUOTA = 9,
GRUB_NTFS_FILE_UPCASE = 10,
};
#define AT_STANDARD_INFORMATION 0x10 enum
#define AT_ATTRIBUTE_LIST 0x20 {
#define AT_FILENAME 0x30 GRUB_NTFS_AT_STANDARD_INFORMATION = 0x10,
#define AT_OBJECT_ID 0x40 GRUB_NTFS_AT_ATTRIBUTE_LIST = 0x20,
#define AT_SECURITY_DESCRIPTOR 0x50 GRUB_NTFS_AT_FILENAME = 0x30,
#define AT_VOLUME_NAME 0x60 GRUB_NTFS_AT_OBJECT_ID = 0x40,
#define AT_VOLUME_INFORMATION 0x70 GRUB_NTFS_AT_SECURITY_DESCRIPTOR = 0x50,
#define AT_DATA 0x80 GRUB_NTFS_AT_VOLUME_NAME = 0x60,
#define AT_INDEX_ROOT 0x90 GRUB_NTFS_AT_VOLUME_INFORMATION = 0x70,
#define AT_INDEX_ALLOCATION 0xA0 GRUB_NTFS_AT_DATA = 0x80,
#define AT_BITMAP 0xB0 GRUB_NTFS_AT_INDEX_ROOT = 0x90,
#define AT_SYMLINK 0xC0 GRUB_NTFS_AT_INDEX_ALLOCATION = 0xA0,
#define AT_EA_INFORMATION 0xD0 GRUB_NTFS_AT_BITMAP = 0xB0,
#define AT_EA 0xE0 GRUB_NTFS_AT_SYMLINK = 0xC0,
GRUB_NTFS_AT_EA_INFORMATION = 0xD0,
GRUB_NTFS_AT_EA = 0xE0,
};
#define ATTR_READ_ONLY 0x1 enum
#define ATTR_HIDDEN 0x2 {
#define ATTR_SYSTEM 0x4 GRUB_NTFS_ATTR_READ_ONLY = 0x1,
#define ATTR_ARCHIVE 0x20 GRUB_NTFS_ATTR_HIDDEN = 0x2,
#define ATTR_DEVICE 0x40 GRUB_NTFS_ATTR_SYSTEM = 0x4,
#define ATTR_NORMAL 0x80 GRUB_NTFS_ATTR_ARCHIVE = 0x20,
#define ATTR_TEMPORARY 0x100 GRUB_NTFS_ATTR_DEVICE = 0x40,
#define ATTR_SPARSE 0x200 GRUB_NTFS_ATTR_NORMAL = 0x80,
#define ATTR_REPARSE 0x400 GRUB_NTFS_ATTR_TEMPORARY = 0x100,
#define ATTR_COMPRESSED 0x800 GRUB_NTFS_ATTR_SPARSE = 0x200,
#define ATTR_OFFLINE 0x1000 GRUB_NTFS_ATTR_REPARSE = 0x400,
#define ATTR_NOT_INDEXED 0x2000 GRUB_NTFS_ATTR_COMPRESSED = 0x800,
#define ATTR_ENCRYPTED 0x4000 GRUB_NTFS_ATTR_OFFLINE = 0x1000,
#define ATTR_DIRECTORY 0x10000000 GRUB_NTFS_ATTR_NOT_INDEXED = 0x2000,
#define ATTR_INDEX_VIEW 0x20000000 GRUB_NTFS_ATTR_ENCRYPTED = 0x4000,
GRUB_NTFS_ATTR_DIRECTORY = 0x10000000,
GRUB_NTFS_ATTR_INDEX_VIEW = 0x20000000
};
#define FLAG_COMPRESSED 1 enum
#define FLAG_ENCRYPTED 0x4000 {
#define FLAG_SPARSE 0x8000 GRUB_NTFS_FLAG_COMPRESSED = 1,
GRUB_NTFS_FLAG_ENCRYPTED = 0x4000,
GRUB_NTFS_FLAG_SPARSE = 0x8000
};
#define BLK_SHR GRUB_DISK_SECTOR_BITS #define GRUB_NTFS_BLK_SHR GRUB_DISK_SECTOR_BITS
#define MAX_MFT (1024 >> BLK_SHR) #define GRUB_NTFS_MAX_MFT (1024 >> GRUB_NTFS_BLK_SHR)
#define MAX_IDX (16384 >> BLK_SHR) #define GRUB_NTFS_MAX_IDX (16384 >> GRUB_NTFS_BLK_SHR)
#define COM_LEN 4096 #define GRUB_NTFS_COM_LEN 4096
#define COM_LOG_LEN 12 #define GRUB_NTFS_COM_LOG_LEN 12
#define COM_SEC (COM_LEN >> BLK_SHR) #define GRUB_NTFS_COM_SEC (GRUB_NTFS_COM_LEN >> GRUB_NTFS_BLK_SHR)
#define AF_ALST 1 enum
#define AF_MMFT 2 {
#define AF_GPOS 4 GRUB_NTFS_AF_ALST = 1,
GRUB_NTFS_AF_MMFT = 2,
GRUB_NTFS_AF_GPOS = 4,
};
#define RF_COMP 1 enum
#define RF_CBLK 2 {
#define RF_BLNK 4 GRUB_NTFS_RF_COMP = 1,
GRUB_NTFS_RF_CBLK = 2,
#define valueat(buf,ofs,type) *((type*)(((char*)buf)+ofs)) GRUB_NTFS_RF_BLNK = 4
};
#define u16at(buf,ofs) grub_le_to_cpu16(valueat(buf,ofs,grub_uint16_t))
#define u32at(buf,ofs) grub_le_to_cpu32(valueat(buf,ofs,grub_uint32_t))
#define u64at(buf,ofs) grub_le_to_cpu64(valueat(buf,ofs,grub_uint64_t))
#define v16at(buf,ofs) valueat(buf,ofs,grub_uint16_t)
#define v32at(buf,ofs) valueat(buf,ofs,grub_uint32_t)
#define v64at(buf,ofs) valueat(buf,ofs,grub_uint64_t)
struct grub_ntfs_bpb struct grub_ntfs_bpb
{ {
@ -120,8 +128,6 @@ struct grub_ntfs_bpb
grub_uint32_t checksum; grub_uint32_t checksum;
} __attribute__ ((packed)); } __attribute__ ((packed));
#define grub_ntfs_file grub_fshelp_node
struct grub_ntfs_attr struct grub_ntfs_attr
{ {
int flags; int flags;
@ -132,7 +138,7 @@ struct grub_ntfs_attr
struct grub_ntfs_file *mft; struct grub_ntfs_file *mft;
}; };
struct grub_fshelp_node struct grub_ntfs_file
{ {
struct grub_ntfs_data *data; struct grub_ntfs_data *data;
char *buf; char *buf;
@ -174,13 +180,15 @@ struct grub_ntfs_rlst
struct grub_ntfs_comp comp; struct grub_ntfs_comp comp;
}; };
typedef grub_err_t (*ntfscomp_func_t) (struct grub_ntfs_attr * at, char *dest, typedef grub_err_t (*grub_ntfscomp_func_t) (struct grub_ntfs_attr * at,
grub_uint32_t ofs, grub_uint32_t len, char *dest,
grub_uint32_t ofs,
grub_uint32_t len,
struct grub_ntfs_rlst * ctx, struct grub_ntfs_rlst * ctx,
grub_uint32_t vcn); grub_uint32_t vcn);
extern ntfscomp_func_t EXPORT_VAR (grub_ntfscomp_func); extern grub_ntfscomp_func_t grub_ntfscomp_func;
grub_err_t EXPORT_FUNC(grub_ntfs_read_run_list) (struct grub_ntfs_rlst *ctx); grub_err_t grub_ntfs_read_run_list (struct grub_ntfs_rlst *ctx);
#endif /* ! GRUB_NTFS_H */ #endif /* ! GRUB_NTFS_H */