branch update for ntfsprogs_200309071734
authorshort <>
Mon, 15 Sep 2003 19:51:31 +0000 (19:51 +0000)
committershort <>
Mon, 15 Sep 2003 19:51:31 +0000 (19:51 +0000)
ChangeLog
configure.ac
libntfs/attrib.c
libntfs/dir.c
ntfsprogs/Makefile.am
ntfsprogs/ntfscluster.c
ntfsprogs/ntfsundelete.8.in
ntfsprogs/ntfsundelete.c
ntfsprogs/utils.c
orig-ntfsprogs-200307311516.tar.bz2 [deleted file]
orig-ntfsprogs-200309071734.tar.bz2 [new file with mode: 0644]

index bf24856..f9ffafe 100644 (file)
--- 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):
index d88c228..3bc29e8 100644 (file)
@@ -1,5 +1,5 @@
 AC_PREREQ(2.57)
-AC_INIT(ntfsprogs, 200307311516, linux-ntfs-dev@lists.sourceforge.net)
+AC_INIT(ntfsprogs, 200309071734, linux-ntfs-dev@lists.sourceforge.net)
 AC_CANONICAL_TARGET([])
 AC_CONFIG_SRCDIR([config.h.in])
 AM_CONFIG_HEADER([config.h])
@@ -148,6 +148,7 @@ AC_CONFIG_FILES([
        ntfsprogs/ntfsprogs.8
        ntfsprogs/ntfsresize.8
        ntfsprogs/ntfsundelete.8
+       ntfsprogs/ntfscluster.8
        ntfsprogs.spec
 ])
 AC_OUTPUT
index d8cc670..c80ddfa 100644 (file)
@@ -382,8 +382,6 @@ err_out:
  */
 void ntfs_attr_close(ntfs_attr *na)
 {
-       if (!na)
-               return;
        if (NAttrNonResident(na) && na->rl)
                free(na->rl);
        /* Don't release if using an internal constant. */
@@ -2460,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
index 443322b..9abb792 100644 (file)
@@ -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;
 }
index 4d4a291..75c48e3 100644 (file)
@@ -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)
index 8dd4d92..a80206a 100644 (file)
@@ -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;
        }
 
index 8a53365..bb08b8f 100644 (file)
@@ -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
index 6df3c60..dfcd2ea 100644 (file)
@@ -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");
index b554e0c..294e9e1 100644 (file)
@@ -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");
                // <UNKNOWN>?
+               len = snprintf (buffer, bufsize, "<UNKNOWN>");
                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;
        }
diff --git a/orig-ntfsprogs-200307311516.tar.bz2 b/orig-ntfsprogs-200307311516.tar.bz2
deleted file mode 100644 (file)
index f965e5b..0000000
Binary files a/orig-ntfsprogs-200307311516.tar.bz2 and /dev/null differ
diff --git a/orig-ntfsprogs-200309071734.tar.bz2 b/orig-ntfsprogs-200309071734.tar.bz2
new file mode 100644 (file)
index 0000000..3d4ebe7
Binary files /dev/null and b/orig-ntfsprogs-200309071734.tar.bz2 differ