From f75d0c5be5d35f5dd5299fa484ced6f842ff66dd Mon Sep 17 00:00:00 2001 From: "cantab.net!aia21" Date: Sun, 29 Dec 2002 12:17:35 +0000 Subject: [PATCH] Load the attribute definition table at mount time and free it at umount time. (Logical change 1.72) --- libntfs/volume.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/libntfs/volume.c b/libntfs/volume.c index 77cca83c..0ba13f39 100644 --- a/libntfs/volume.c +++ b/libntfs/volume.c @@ -79,6 +79,8 @@ static void __ntfs_volume_release(ntfs_volume *v) free(v->vol_name); if (v->upcase) free(v->upcase); + if (v->attrdef) + free(v->attrdef); free(v); } @@ -836,7 +838,50 @@ ntfs_volume *ntfs_mount(const char *name, unsigned long rwflag) if (ntfs_inode_close(ni)) Dperror("Failed to close inode, leaking memory"); - /* FIXME: Need to deal with FILE_AttrDef. (AIA) */ + /* Now load the attribute definitions from $AttrDef. */ + Dprintf("Loading $AttrDef... "); + ni = ntfs_inode_open(vol, FILE_AttrDef); + if (!ni) { + Dputs(FAILED); + Dperror("Failed to open inode"); + goto error_exit; + } + /* Get an ntfs attribute for $AttrDef/$DATA. */ + na = ntfs_attr_open(ni, AT_DATA, AT_UNNAMED, 0); + if (!na) { + Dputs(FAILED); + Dperror("Failed to open ntfs attribute"); + goto error_exit; + } + /* Check we don't overflow 32-bits. */ + if (na->data_size > 0xffffffffLL) { + Dputs(FAILED); + Dputs("Error: Attribute definition table is too big " + "(max 32-bit allowed)."); + errno = EINVAL; + goto error_exit; + } + vol->attrdef_len = na->data_size; + vol->attrdef = (ATTR_DEF*)malloc(na->data_size); + if (!vol->attrdef) { + Dputs(FAILED); + Dputs("Not enough memory to load $AttrDef."); + goto error_exit; + } + /* Read in the $DATA attribute value into the buffer. */ + l = ntfs_attr_pread(na, 0, na->data_size, vol->attrdef); + if (l != na->data_size) { + Dputs(FAILED); + Dputs("Amount of data read does not correspond to expected " + "length!"); + errno = EIO; + goto error_exit; + } + /* Done with the $AttrDef mft record. */ + Dputs(OK); + ntfs_attr_close(na); + if (ntfs_inode_close(ni)) + Dperror("Failed to close inode, leaking memory"); return vol; io_error_exit: