X-Git-Url: http://git.jankratochvil.net/?p=ntfsprogs.git;a=blobdiff_plain;f=ntfsprogs%2Futils.c;fp=ntfsprogs%2Futils.c;h=294e9e18bf3dccf07e9ff8e2ca4fb927777e2420;hp=b554e0c82b9702c8cf9bceea438379ddee0919f9;hb=2d83206a84e25bff80568704ebb0aca2b4323b9c;hpb=4abffda2cd1cad459fc0a61d79e8cd234e207b17 diff --git a/ntfsprogs/utils.c b/ntfsprogs/utils.c index b554e0c..294e9e1 100644 --- a/ntfsprogs/utils.c +++ b/ntfsprogs/utils.c @@ -395,6 +395,7 @@ int utils_inode_get_name (ntfs_inode *inode, char *buffer, int bufsize) ntfs_volume *vol; ntfs_attr_search_ctx *ctx; ATTR_RECORD *rec; + ATTR_RECORD *oldrec; FILE_NAME_ATTR *attr; int name_space; MFT_REF parent = FILE_root; @@ -420,11 +421,15 @@ int utils_inode_get_name (ntfs_inode *inode, char *buffer, int bufsize) //printf ("i = %d, inode = %p (%lld)\n", i, inode, inode->mft_no); name_space = 4; + oldrec = NULL; while ((rec = find_attribute (AT_FILE_NAME, ctx))) { + if (rec == oldrec) + break; + oldrec = rec; /* We know this will always be resident. */ attr = (FILE_NAME_ATTR *) ((char *) rec + le16_to_cpu (rec->value_offset)); - if (attr->file_name_type >= name_space) { //XXX find the ... + if (attr->file_name_type > name_space) { //XXX find the ... continue; } @@ -502,8 +507,8 @@ int utils_inode_get_name (ntfs_inode *inode, char *buffer, int bufsize) */ int utils_attr_get_name (ntfs_volume *vol, ATTR_RECORD *attr, char *buffer, int bufsize) { - int len, namelen, offset = 0; - char *name = NULL; + int len, namelen; + char *name; ATTR_DEF *attrdef; // flags: attr, name, or both @@ -512,6 +517,7 @@ int utils_attr_get_name (ntfs_volume *vol, ATTR_RECORD *attr, char *buffer, int attrdef = ntfs_attr_find_in_attrdef (vol, attr->type); if (attrdef) { + name = NULL; namelen = ntfs_ucsnlen (attrdef->name, sizeof (attrdef->name)); if (ntfs_ucstombs (attrdef->name, namelen, &name, namelen) < 0) { Eprintf ("Couldn't translate attribute type to current locale.\n"); @@ -529,24 +535,27 @@ int utils_attr_get_name (ntfs_volume *vol, ATTR_RECORD *attr, char *buffer, int return 0; } - offset += len; - if (!attr->name_length) { return 0; } + buffer += len; + bufsize -= len; + + name = NULL; namelen = attr->name_length; if (ntfs_ucstombs ((uchar_t *)((char *)attr + attr->name_offset), namelen, &name, namelen) < 0) { Eprintf ("Couldn't translate attribute name to current locale.\n"); // ? + len = snprintf (buffer, bufsize, ""); return 0; } - len = snprintf (buffer + offset, bufsize - offset, "(%s)", name); + len = snprintf (buffer, bufsize, "(%s)", name); free (name); - if ((len + offset) >= bufsize) { + if (len >= bufsize) { Eprintf ("Attribute name was truncated.\n"); return 0; }