From 2d83206a84e25bff80568704ebb0aca2b4323b9c Mon Sep 17 00:00:00 2001 From: short <> Date: Mon, 15 Sep 2003 19:43:11 +0000 Subject: [PATCH] http://linux-ntfs.sourceforge.net/snapshots/ntfsprogs-200309071734.tar.bz2 --- ChangeLog | 4 ++ configure | 6 +- configure.ac | 3 +- libntfs/attrib.c | 3 + libntfs/dir.c | 13 +++- ntfsprogs/Makefile.am | 10 +-- ntfsprogs/Makefile.in | 24 ++++---- ntfsprogs/ntfscluster.8.in | 144 ++++++++++++++++++++++++++++++++++++++++++++ ntfsprogs/ntfscluster.c | 95 ++++++++++++++++++++++++++--- ntfsprogs/ntfsundelete.8.in | 4 ++ ntfsprogs/ntfsundelete.c | 9 ++- ntfsprogs/utils.c | 23 ++++--- 12 files changed, 295 insertions(+), 43 deletions(-) create mode 100644 ntfsprogs/ntfscluster.8.in diff --git a/ChangeLog b/ChangeLog index bf24856..f9ffafe 100644 --- a/ChangeLog +++ b/ChangeLog @@ -9,6 +9,10 @@ xx/xx/2003 - 1.7.2-WIP - Work in progress. - Update for newer autoconf/automake. - Abstract low level device operations (include/device,h and libntfs/device.c) and adapt utilities to changes. + - Fix bugs in dir.c::ntfs_readdir() where we try to close ia_na when + it is NULL. + - Return errno ENOTDIR from dir.c::ntfs_readdir() when called with a + file inode. 13/02/2003 - 1.7.1 - Urgent bug fixes. - Urgent bug fixes in ntfsresize (Szabolcs Szakacsits): diff --git a/configure b/configure index 2659b20..997ac6c 100755 --- a/configure +++ b/configure @@ -8731,11 +8731,10 @@ fi - for ac_header in fcntl.h libintl.h limits.h locale.h mntent.h stddef.h \ stdint.h stdlib.h stdio.h stdarg.h string.h strings.h errno.h time.h \ sys/ioctl.h sys/mount.h unistd.h utime.h wchar.h getopt.h sys/stat.h \ - sys/types.h linux/types.h asm/byteorder.h linux/major.h linux/fd.h + sys/types.h asm/byteorder.h linux/major.h linux/fd.h do as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh` if eval "test \"\${$as_ac_Header+set}\" = set"; then @@ -11027,7 +11026,7 @@ done # Makefiles to be created by configure. - ac_config_files="$ac_config_files Makefile doc/Makefile include/Makefile libntfs/Makefile ntfsprogs/Makefile ntfsprogs/mkntfs.8 ntfsprogs/ntfsfix.8 ntfsprogs/ntfsinfo.8 ntfsprogs/ntfslabel.8 ntfsprogs/ntfsprogs.8 ntfsprogs/ntfsresize.8 ntfsprogs/ntfsundelete.8 ntfsprogs.spec" + ac_config_files="$ac_config_files Makefile doc/Makefile include/Makefile libntfs/Makefile ntfsprogs/Makefile ntfsprogs/mkntfs.8 ntfsprogs/ntfsfix.8 ntfsprogs/ntfsinfo.8 ntfsprogs/ntfslabel.8 ntfsprogs/ntfsprogs.8 ntfsprogs/ntfsresize.8 ntfsprogs/ntfsundelete.8 ntfsprogs/ntfscluster.8 ntfsprogs.spec" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure @@ -11610,6 +11609,7 @@ do "ntfsprogs/ntfsprogs.8" ) CONFIG_FILES="$CONFIG_FILES ntfsprogs/ntfsprogs.8" ;; "ntfsprogs/ntfsresize.8" ) CONFIG_FILES="$CONFIG_FILES ntfsprogs/ntfsresize.8" ;; "ntfsprogs/ntfsundelete.8" ) CONFIG_FILES="$CONFIG_FILES ntfsprogs/ntfsundelete.8" ;; + "ntfsprogs/ntfscluster.8" ) CONFIG_FILES="$CONFIG_FILES ntfsprogs/ntfscluster.8" ;; "ntfsprogs.spec" ) CONFIG_FILES="$CONFIG_FILES ntfsprogs.spec" ;; "depfiles" ) CONFIG_COMMANDS="$CONFIG_COMMANDS depfiles" ;; "config.h" ) CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;; diff --git a/configure.ac b/configure.ac index cfb90dd..4440142 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ AC_PREREQ(2.57) -AC_INIT(ntfsprogs, 1.7.2-WIP-200307311516, linux-ntfs-dev@lists.sourceforge.net) +AC_INIT(ntfsprogs, 1.7.2-WIP, linux-ntfs-dev@lists.sourceforge.net) AC_CANONICAL_TARGET([]) AC_CONFIG_SRCDIR([config.h.in]) AM_CONFIG_HEADER([config.h]) @@ -146,6 +146,7 @@ AC_CONFIG_FILES([ ntfsprogs/ntfsprogs.8 ntfsprogs/ntfsresize.8 ntfsprogs/ntfsundelete.8 + ntfsprogs/ntfscluster.8 ntfsprogs.spec ]) AC_OUTPUT diff --git a/libntfs/attrib.c b/libntfs/attrib.c index b04bb38..c80ddfa 100644 --- a/libntfs/attrib.c +++ b/libntfs/attrib.c @@ -2458,6 +2458,9 @@ put_err_out: return -1; } +/** + * ntfs_attr_make_resident - + */ static int ntfs_attr_make_resident(ntfs_attr *na, ntfs_attr_search_ctx *ctx) { // FIXME: For now we cheat and assume there is no attribute list diff --git a/libntfs/dir.c b/libntfs/dir.c index 443322b..9abb792 100644 --- a/libntfs/dir.c +++ b/libntfs/dir.c @@ -1,7 +1,7 @@ /* * dir.c - Directory handling code. Part of the Linux-NTFS project. * - * Copyright (c) 2002 Anton Altaparmakov + * Copyright (c) 2002-2003 Anton Altaparmakov * * This program/include file is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as published @@ -612,6 +612,11 @@ int ntfs_readdir(ntfs_inode *dir_ni, s64 *pos, return -1; } + if (!(dir_ni->mrec->flags & MFT_RECORD_IS_DIRECTORY)) { + errno = ENOTDIR; + return -1; + } + vol = dir_ni->vol; Dprintf("Entering for inode 0x%Lx, *pos 0x%Lx.\n", @@ -898,7 +903,8 @@ EOD: done: if (bmp_na) ntfs_attr_close(bmp_na); - ntfs_attr_close(ia_na); + if (ia_na) + ntfs_attr_close(ia_na); #ifdef DEBUG if (!rc) Dprintf("EOD, *pos 0x%Lx, returning 0.\n", (long long)*pos); @@ -916,7 +922,8 @@ err_out: ntfs_attr_put_search_ctx(ctx); if (bmp_na) ntfs_attr_close(bmp_na); - ntfs_attr_close(ia_na); + if (ia_na) + ntfs_attr_close(ia_na); errno = eo; return -1; } diff --git a/ntfsprogs/Makefile.am b/ntfsprogs/Makefile.am index 4d4a291..75c48e3 100644 --- a/ntfsprogs/Makefile.am +++ b/ntfsprogs/Makefile.am @@ -25,12 +25,12 @@ endif # Workaround to make REALLYSTATIC work with automake 1.5. LINK=$(STATIC_LINK) $(LIBTOOL_LINK) -bin_PROGRAMS = ntfsfix ntfsinfo +bin_PROGRAMS = ntfsfix ntfsinfo ntfscluster sbin_PROGRAMS = mkntfs ntfslabel ntfsundelete ntfsresize -EXTRA_PROGRAMS = ntfsdump_logfile dumplog ntfswipe ntfstruncate ntfscluster +EXTRA_PROGRAMS = ntfsdump_logfile dumplog ntfswipe ntfstruncate man_MANS = mkntfs.8 ntfsfix.8 ntfslabel.8 ntfsinfo.8 \ - ntfsundelete.8 ntfsresize.8 ntfsprogs.8 + ntfsundelete.8 ntfsresize.8 ntfscluster.8 ntfsprogs.8 EXTRA_MANS = CLEANFILES = $(EXTRA_PROGRAMS) @@ -64,12 +64,12 @@ ntfsresize_SOURCES = ntfsresize.c utils.c utils.h ntfsresize_LDADD = $(AM_LIBS) ntfsresize_LDFLAGS = $(AM_LFLAGS) -# We don't distribute these - ntfscluster_SOURCES = ntfscluster.c ntfscluster.h utils.c utils.h ntfscluster_LDADD = $(AM_LIBS) ntfscluster_LDFLAGS = $(AM_LFLAGS) +# We don't distribute these + ntfstruncate_SOURCES = attrdef.c ntfstruncate.c utils.c utils.h ntfstruncate_LDADD = $(AM_LIBS) ntfstruncate_LDFLAGS = $(AM_LFLAGS) diff --git a/ntfsprogs/Makefile.in b/ntfsprogs/Makefile.in index b9f6355..b67879f 100644 --- a/ntfsprogs/Makefile.in +++ b/ntfsprogs/Makefile.in @@ -111,12 +111,12 @@ install_sh = @install_sh@ # Workaround to make REALLYSTATIC work with automake 1.5. LINK = $(STATIC_LINK) $(LIBTOOL_LINK) -bin_PROGRAMS = ntfsfix ntfsinfo +bin_PROGRAMS = ntfsfix ntfsinfo ntfscluster sbin_PROGRAMS = mkntfs ntfslabel ntfsundelete ntfsresize -EXTRA_PROGRAMS = ntfsdump_logfile dumplog ntfswipe ntfstruncate ntfscluster +EXTRA_PROGRAMS = ntfsdump_logfile dumplog ntfswipe ntfstruncate man_MANS = mkntfs.8 ntfsfix.8 ntfslabel.8 ntfsinfo.8 \ - ntfsundelete.8 ntfsresize.8 ntfsprogs.8 + ntfsundelete.8 ntfsresize.8 ntfscluster.8 ntfsprogs.8 EXTRA_MANS = @@ -151,12 +151,12 @@ ntfsresize_SOURCES = ntfsresize.c utils.c utils.h ntfsresize_LDADD = $(AM_LIBS) ntfsresize_LDFLAGS = $(AM_LFLAGS) - -# We don't distribute these ntfscluster_SOURCES = ntfscluster.c ntfscluster.h utils.c utils.h ntfscluster_LDADD = $(AM_LIBS) ntfscluster_LDFLAGS = $(AM_LFLAGS) + +# We don't distribute these ntfstruncate_SOURCES = attrdef.c ntfstruncate.c utils.c utils.h ntfstruncate_LDADD = $(AM_LIBS) ntfstruncate_LDFLAGS = $(AM_LFLAGS) @@ -176,10 +176,10 @@ subdir = ntfsprogs mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs CONFIG_HEADER = $(top_builddir)/config.h CONFIG_CLEAN_FILES = mkntfs.8 ntfsfix.8 ntfsinfo.8 ntfslabel.8 \ - ntfsprogs.8 ntfsresize.8 ntfsundelete.8 + ntfsprogs.8 ntfsresize.8 ntfsundelete.8 ntfscluster.8 EXTRA_PROGRAMS = ntfsdump_logfile$(EXEEXT) dumplog$(EXEEXT) \ - ntfswipe$(EXEEXT) ntfstruncate$(EXEEXT) ntfscluster$(EXEEXT) -bin_PROGRAMS = ntfsfix$(EXEEXT) ntfsinfo$(EXEEXT) + ntfswipe$(EXEEXT) ntfstruncate$(EXEEXT) +bin_PROGRAMS = ntfsfix$(EXEEXT) ntfsinfo$(EXEEXT) ntfscluster$(EXEEXT) sbin_PROGRAMS = mkntfs$(EXEEXT) ntfslabel$(EXEEXT) ntfsundelete$(EXEEXT) \ ntfsresize$(EXEEXT) PROGRAMS = $(bin_PROGRAMS) $(sbin_PROGRAMS) @@ -281,9 +281,9 @@ DIST_SOURCES = $(dumplog_SOURCES) $(mkntfs_SOURCES) \ NROFF = nroff MANS = $(man_MANS) -DIST_COMMON = Makefile.am Makefile.in mkntfs.8.in ntfsfix.8.in \ - ntfsinfo.8.in ntfslabel.8.in ntfsprogs.8.in ntfsresize.8.in \ - ntfsundelete.8.in +DIST_COMMON = Makefile.am Makefile.in mkntfs.8.in ntfscluster.8.in \ + ntfsfix.8.in ntfsinfo.8.in ntfslabel.8.in ntfsprogs.8.in \ + ntfsresize.8.in ntfsundelete.8.in SOURCES = $(dumplog_SOURCES) $(mkntfs_SOURCES) $(ntfscluster_SOURCES) $(ntfsdump_logfile_SOURCES) $(ntfsfix_SOURCES) $(ntfsinfo_SOURCES) $(ntfslabel_SOURCES) $(ntfsresize_SOURCES) $(ntfstruncate_SOURCES) $(ntfsundelete_SOURCES) $(ntfswipe_SOURCES) all: all-am @@ -309,6 +309,8 @@ ntfsresize.8: $(top_builddir)/config.status ntfsresize.8.in cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ ntfsundelete.8: $(top_builddir)/config.status ntfsundelete.8.in cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ +ntfscluster.8: $(top_builddir)/config.status ntfscluster.8.in + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ binPROGRAMS_INSTALL = $(INSTALL_PROGRAM) install-binPROGRAMS: $(bin_PROGRAMS) @$(NORMAL_INSTALL) diff --git a/ntfsprogs/ntfscluster.8.in b/ntfsprogs/ntfscluster.8.in new file mode 100644 index 0000000..2dbd91a --- /dev/null +++ b/ntfsprogs/ntfscluster.8.in @@ -0,0 +1,144 @@ +.\" Copyright (c) 2003 Richard Russon. All Rights Reserved. +.\" This file may be copied under the terms of the GNU Public License. +.\" +.TH NTFSCLUSTER 8 "September 2003" "Linux\-NTFS version @VERSION@" +.SH NAME +ntfscluster \- identify files in a specified region of an NTFS volume. +.SH SYNOPSIS +.B ntfscluster +[ +.I options +] +.B device +.SH DESCRIPTION +.B ntfscluster +has three modes of operation: +.IR info , +.I sector +and +.IR cluster . +.SS Info +.PP +The default mode, +.I info +is currently not implemented. It will display general infomation about the NTFS +volume when it is working. +.SS Sector +.PP +The +.I sector +mode will display a list of files that have data in the specified range of +sectors. +.SS Cluster +The +.I cluster +mode will display a list of files that have data in the specified range of +clusters. When the cluster size is one sector, this will be equivalent to the +.I sector +mode of operation. +.SH OPTIONS +Below is a summary of all the options that +.B ntfscluster +accepts. All options have two equivalent names. The short name is preceded by +.BR \- +and the long name is preceded by +.BR \-\- . +Any single letter options, that don't take an argument, can be combined into a +single command, e.g. +.BR \-fv +is equivalent to +.BR "\-f \-v" . +Long named options can be abbreviated to any unique prefix of their name. +.TP +.BI "\-c " range +.br +.ns +.TP +.BI "\-\-cluster " range +Any files whose data is in this range of clusters will be displayed. +.TP +.B \-f +.br +.ns +.TP +.B \-\-force +This will override some sensible defaults, such as not working with a mounted +volume. Use this option with caution. +.TP +.B \-\-help +Show a list of options with a brief description of each one. +.TP +.B \-i +.br +.ns +.TP +.B \-\-info +This option is not yet implemented. +.TP +.BI \-q +.br +.ns +.TP +.BI \-\-quiet +Reduce the amount of output to a minimum. Naturally, it doesn't make sense to +combine this option with +.TP +.B \-s +.br +.ns +.TP +.B \-\-sector +Any files whose data is in this range of sectors will be displayed. +.TP +.B \-v +.br +.ns +.TP +.B \-\-verbose +Increase the amount of output that +.B ntfscluster +prints. +.TP +.B \-V +.br +.ns +.TP +.B \-\-version +Show the version number, copyright and license +.BR ntfscluster . +.SH EXAMPLES +Get some information about the volume /dev/hda1. +.RS +.sp +.B ntfscluster /dev/hda1 +.sp +.RE +Look for files in the first 500 clusters of /dev/hda1. +.RS +.sp +.B ntfscluster -c 0-500 /dev/hda1 +.sp +.SH BUGS +The +.I info +mode isn't implemented yet. This program is quite limited, but it has no known +bugs. If you find one, please send an email to +.nh + +.hy +.SH AUTHOR +.B ntfscluster +was written by Richard Russon (FlatCap) +.br +If you find this tool useful, make FlatCap happy and send him an email. +.SH AVAILABILITY +.B ntfscluster +is part of the linux\-ntfs package and is available from +.br +.nh +http://linux\-ntfs.sourceforge.net/downloads.html +.hy +.SH SEE ALSO +.BR ntfsinfo (8), +.BR ntfsprogs (8) + diff --git a/ntfsprogs/ntfscluster.c b/ntfsprogs/ntfscluster.c index 8dd4d92..a80206a 100644 --- a/ntfsprogs/ntfscluster.c +++ b/ntfsprogs/ntfscluster.c @@ -67,7 +67,7 @@ void version (void) void usage (void) { printf ("\nUsage: %s [options] device\n" - " -i --info Print information about the volume\n" + " -i --info Print information about the volume (default)\n" " -c range --cluster range Look for objects in this range of clusters\n" " -s range --sector range Look for objects in this range of sectors\n" /* " -l --last Find the last file on the volume\n" */ @@ -204,7 +204,8 @@ int parse_options (int argc, char **argv) } if (opts.action == act_error) { - Eprintf ("You may only specify one action: --info, --cluster, --sector or --last.\n"); + //Eprintf ("You may only specify one action: --info, --cluster, --sector or --last.\n"); + Eprintf ("You may only specify one action: --info, --cluster or --sector.\n"); err++; } else if (opts.range_begin > opts.range_end) { Eprintf ("The range must be in ascending order.\n"); @@ -220,6 +221,79 @@ int parse_options (int argc, char **argv) return (!err && !help && !ver); } + +/** + * free_space - Calculate the amount of space which isn't in use + */ +u64 free_space (ntfs_volume *vol) +{ + return 0; +} + +/** + * user_space - Calculate the amount of space of the user's files + */ +u64 user_space (ntfs_volume *vol) +{ + return 0; +} + +/** + * meta_space - Calculate the amount of space used by the filesystem structures + */ +u64 meta_space (ntfs_volume *vol) +{ + return 0; +} + +/** + * info - Display information about the volume + */ +int info (ntfs_volume *vol) +{ + u64 a, b, c, d, e, f, g, h, i, j, k, l, m, n; + int cps; + u64 fs, us, ms; + + cps = vol->cluster_size_bits - vol->sector_size_bits; + fs = free_space (vol); + ms = meta_space (vol); + us = user_space (vol); + + a = vol->sector_size; + b = vol->cluster_size; + c = 1 << cps; + d = vol->nr_clusters >> cps; + e = vol->nr_clusters; + f = fs / a; + g = fs / b; + h = fs * 100 / a / d; + i = us / a; + j = us / b; + k = us * 100 / a / d; + l = ms / a; + m = ms / b; + n = ms * 100 / a / d; + + printf ("bytes per sector : %lld\n", a); + printf ("bytes per cluster : %lld\n", b); + printf ("sectors per cluster : %lld\n", c); + printf ("sectors per volume : %lld\n", d); + printf ("clusters per volume : %lld\n", e); + printf ("sectors of free space : %lld\n", f); + printf ("clusters of free space : %lld\n", g); + printf ("percentage free space : %lld\n", h); + printf ("sectors of user data : %lld\n", i); + printf ("clusters of user data : %lld\n", j); + printf ("percentage user data : %lld\n", k); + printf ("sectors of metadata : %lld\n", l); + printf ("clusters of metadata : %lld\n", m); + printf ("percentage metadata : %lld\n", n); + + return 0; +} + + /** * cluster_find */ @@ -247,10 +321,11 @@ int cluster_find (ntfs_volume *vol, LCN s_begin, LCN s_end) if (!in_use) { if (s_begin == s_end) - printf ("clusters isn't in use\n"); + printf ("cluster isn't in use\n"); else printf ("clusters aren't in use\n"); - return 0; + result = 0; + goto free; } // first, is the cluster in use in $Bitmap? @@ -260,7 +335,7 @@ int cluster_find (ntfs_volume *vol, LCN s_begin, LCN s_end) ntfs_attr_search_ctx *ctx; if (!utils_mftrec_in_use (vol, i)) { - //printf ("%d skipped\n", i); + //printf ("%lld skipped\n", i); continue; } @@ -325,9 +400,8 @@ int cluster_find (ntfs_volume *vol, LCN s_begin, LCN s_end) printf ("inode %lld %s", i, buffer); utils_attr_get_name (vol, ctx->attr, buffer, sizeof (buffer)); printf ("%c%s\n", PATH_SEP, buffer); - //printf ("\n"); } - break; + break; // XXX if verbose, we should list all matching runs } } @@ -343,6 +417,7 @@ free: return result; } + /** * main - Begin here * @@ -372,8 +447,8 @@ int main (int argc, char *argv[]) else Qprintf ("Searching for sector range %lld-%lld\n", opts.range_begin, opts.range_end); /* Convert to clusters */ - opts.range_begin <<= (vol->cluster_size_bits - vol->sector_size_bits); - opts.range_end <<= (vol->cluster_size_bits - vol->sector_size_bits); + opts.range_begin >>= (vol->cluster_size_bits - vol->sector_size_bits); + opts.range_end >>= (vol->cluster_size_bits - vol->sector_size_bits); result = cluster_find (vol, opts.range_begin, opts.range_end); break; case act_cluster: @@ -390,7 +465,7 @@ int main (int argc, char *argv[]) */ case act_info: default: - printf ("Info\n"); + info (vol); break; } diff --git a/ntfsprogs/ntfsundelete.8.in b/ntfsprogs/ntfsundelete.8.in index 8a53365..bb08b8f 100644 --- a/ntfsprogs/ntfsundelete.8.in +++ b/ntfsprogs/ntfsundelete.8.in @@ -274,6 +274,10 @@ Recover the file with this inode number. This option can be combined with .BR \-\-destination , and .BR \-\-byte . +.sp +When the file is recovered it will be given its original name, unless the +.B "\-\-output" +option is used. .TP .B \-v .br diff --git a/ntfsprogs/ntfsundelete.c b/ntfsprogs/ntfsundelete.c index 6df3c60..dfcd2ea 100644 --- a/ntfsprogs/ntfsundelete.c +++ b/ntfsprogs/ntfsundelete.c @@ -489,6 +489,9 @@ int parse_options (int argc, char *argv[]) } } + if (opts.fillbyte == -1) + opts.fillbyte = 0; + if (ver) version(); if (help || err) @@ -947,9 +950,9 @@ void dump_record (struct ufile *file) if (f->flags & FILE_ATTR_REPARSE_POINT) Qprintf ("Reparse "); if (f->flags & FILE_ATTR_COMPRESSED) Qprintf ("Compressed "); if (f->flags & FILE_ATTR_ENCRYPTED) Qprintf ("Encrypted "); - if (!(f->flags & (FILE_ATTR_SYSTEM || FILE_ATTR_DIRECTORY || - FILE_ATTR_SPARSE_FILE || FILE_ATTR_REPARSE_POINT || - FILE_ATTR_COMPRESSED || FILE_ATTR_ENCRYPTED))) { + if (!(f->flags & (FILE_ATTR_SYSTEM | FILE_ATTR_DIRECTORY | + FILE_ATTR_SPARSE_FILE | FILE_ATTR_REPARSE_POINT | + FILE_ATTR_COMPRESSED | FILE_ATTR_ENCRYPTED))) { Qprintf (NONE); } Qprintf ("\n"); 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; } -- 1.8.3.1