linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Anton Altaparmakov <aia21@cam.ac.uk>
To: Linus Torvalds <torvalds@osdl.org>
Cc: viro@parcelfarce.linux.theplanet.co.uk,
	Andrew Morton <akpm@osdl.org>,
	linux-kernel@vger.kernel.org,
	linux-ntfs-dev@lists.sourceforge.net
Subject: [PATCH 5/10] Re: [2.6-BK-URL] NTFS: 2.1.19 sparse annotation, cleanups and a bugfix
Date: Fri, 24 Sep 2004 17:13:36 +0100 (BST)	[thread overview]
Message-ID: <Pine.LNX.4.60.0409241713220.19983@hermes-1.csi.cam.ac.uk> (raw)
In-Reply-To: <Pine.LNX.4.60.0409241713070.19983@hermes-1.csi.cam.ac.uk>

This is patch 5/10 in the series.  It contains the following ChangeSet:

<aia21@cantab.net> (04/09/23 1.1952)
   NTFS: - Update ->truncate (fs/ntfs/inode.c::ntfs_truncate()) to check if the
           inode size has changed and to only output an error if so.
         - Rename fs/ntfs/attrib.h::attribute_value_length() to ntfs_attr_size().
   
   Signed-off-by: Anton Altaparmakov <aia21@cantab.net>

Best regards,

	Anton
-- 
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @)
Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK
Linux NTFS maintainer / IRC: #ntfs on irc.freenode.net
WWW: http://linux-ntfs.sf.net/, http://www-stu.christs.cam.ac.uk/~aia21/

===================================================================

diff -Nru a/fs/ntfs/ChangeLog b/fs/ntfs/ChangeLog
--- a/fs/ntfs/ChangeLog	2004-09-24 17:06:16 +01:00
+++ b/fs/ntfs/ChangeLog	2004-09-24 17:06:16 +01:00
@@ -31,6 +31,9 @@
 	- Get rid of the ugly transparent union in fs/ntfs/dir.c::ntfs_readdir()
 	  and ntfs_filldir() as per suggestion from Al Viro.
 	- Change '\0' and L'\0' to simply 0 as per advice from Linus Torvalds.
+	- Update ->truncate (fs/ntfs/inode.c::ntfs_truncate()) to check if the
+	  inode size has changed and to only output an error if so.
+	- Rename fs/ntfs/attrib.h::attribute_value_length() to ntfs_attr_size().
 
 2.1.18 - Fix scheduling latencies at mount time as well as an endianness bug.
 
diff -Nru a/fs/ntfs/attrib.h b/fs/ntfs/attrib.h
--- a/fs/ntfs/attrib.h	2004-09-24 17:06:16 +01:00
+++ b/fs/ntfs/attrib.h	2004-09-24 17:06:16 +01:00
@@ -89,7 +89,7 @@
 extern int load_attribute_list(ntfs_volume *vol, runlist *rl, u8 *al_start,
 		const s64 size, const s64 initialized_size);
 
-static inline s64 attribute_value_length(const ATTR_RECORD *a)
+static inline s64 ntfs_attr_size(const ATTR_RECORD *a)
 {
 	if (!a->non_resident)
 		return (s64)le32_to_cpu(a->data.resident.value_length);
diff -Nru a/fs/ntfs/inode.c b/fs/ntfs/inode.c
--- a/fs/ntfs/inode.c	2004-09-24 17:06:16 +01:00
+++ b/fs/ntfs/inode.c	2004-09-24 17:06:16 +01:00
@@ -680,7 +680,7 @@
 			goto unm_err_out;
 		}
 		/* Now allocate memory for the attribute list. */
-		ni->attr_list_size = (u32)attribute_value_length(ctx->attr);
+		ni->attr_list_size = (u32)ntfs_attr_size(ctx->attr);
 		ni->attr_list = ntfs_malloc_nofs(ni->attr_list_size);
 		if (!ni->attr_list) {
 			ntfs_error(vi->i_sb, "Not enough memory to allocate "
@@ -1794,7 +1794,7 @@
 			goto put_err_out;
 		}
 		/* Now allocate memory for the attribute list. */
-		ni->attr_list_size = (u32)attribute_value_length(ctx->attr);
+		ni->attr_list_size = (u32)ntfs_attr_size(ctx->attr);
 		ni->attr_list = ntfs_malloc_nofs(ni->attr_list_size);
 		if (!ni->attr_list) {
 			ntfs_error(sb, "Not enough memory to allocate buffer "
@@ -2284,12 +2284,38 @@
  */
 void ntfs_truncate(struct inode *vi)
 {
-	// TODO: Implement...
-	ntfs_warning(vi->i_sb, "Eeek: i_size may have changed!  If you see "
-			"this right after a message from "
-			"ntfs_prepare_{,nonresident_}write() then just ignore "
-			"it.  Otherwise it is bad news.");
-	// TODO: reset i_size now!
+	ntfs_inode *ni = NTFS_I(vi);
+	ntfs_attr_search_ctx *ctx;
+	MFT_RECORD *m;
+
+	m = map_mft_record(ni);
+	if (IS_ERR(m)) {
+		ntfs_error(vi->i_sb, "Failed to map mft record for inode 0x%lx "
+				"(error code %ld).", vi->i_ino, PTR_ERR(m));
+		if (PTR_ERR(m) != ENOMEM)
+			make_bad_inode(vi);
+		return;
+	}
+	ctx = ntfs_attr_get_search_ctx(ni, m);
+	if (unlikely(!ctx)) {
+		ntfs_error(vi->i_sb, "Failed to allocate a search context: "
+				"Not enough memory");
+		// FIXME: We can't report an error code upstream.  So what do
+		// we do?!?  make_bad_inode() seems a bit harsh...
+		unmap_mft_record(ni);
+		goto out;
+	}
+	/* If the size has not changed there is nothing to do. */
+	if (ntfs_attr_size(ctx->attr) == i_size_read(vi))
+		goto out;
+	// TODO: Implement the truncate...
+	ntfs_error(vi->i_sb, "Inode size has changed but this is not "
+			"implemented yet.  Resetting inode size to old value. "
+			" This is most likely a bug in the ntfs driver!");
+	i_size_write(vi, ntfs_attr_size(ctx->attr)); 
+out:
+	ntfs_attr_put_search_ctx(ctx);
+	unmap_mft_record(ni);
 	return;
 }
 

  reply	other threads:[~2004-09-24 16:18 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-09-24 16:11 [2.6-BK-URL] NTFS: 2.1.19 sparse annotation, cleanups and a bugfix Anton Altaparmakov
2004-09-24 16:12 ` [PATCH 1/10] " Anton Altaparmakov
2004-09-24 16:12   ` [PATCH 2/10] " Anton Altaparmakov
2004-09-24 16:13     ` [PATCH 3/10] " Anton Altaparmakov
2004-09-24 16:13       ` [PATCH 4/10] " Anton Altaparmakov
2004-09-24 16:13         ` Anton Altaparmakov [this message]
2004-09-24 16:13           ` [PATCH 6/10] " Anton Altaparmakov
2004-09-24 16:14             ` [PATCH 7/10] " Anton Altaparmakov
2004-09-24 16:14               ` [PATCH 8/10] " Anton Altaparmakov
2004-09-24 16:15                 ` [PATCH 9/10] " Anton Altaparmakov
2004-09-24 16:15                   ` [PATCH 10/10] " Anton Altaparmakov
2004-09-24 16:30                 ` [PATCH 8/10] " Linus Torvalds
2004-09-24 20:02                   ` Anton Altaparmakov
2004-09-25  2:46                     ` Linus Torvalds
2004-09-25  7:25                       ` viro
2004-09-25 15:43                         ` Linus Torvalds
2004-09-26  7:48                           ` Anton Altaparmakov
2004-09-26 16:39                             ` Linus Torvalds
2004-09-26  7:47                       ` Anton Altaparmakov
2004-09-26  7:51                         ` Anton Altaparmakov
2004-09-25  6:38               ` [PATCH 7/10] " viro
2004-09-25 23:31                 ` Anton Altaparmakov
2004-09-25  6:35             ` [PATCH 6/10] " viro
2004-09-25 23:09               ` Anton Altaparmakov
2004-09-26  0:10                 ` Anton Altaparmakov
2004-09-25  6:32         ` [PATCH 4/10] " viro
2004-09-26  0:06           ` Anton Altaparmakov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.60.0409241713220.19983@hermes-1.csi.cam.ac.uk \
    --to=aia21@cam.ac.uk \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-ntfs-dev@lists.sourceforge.net \
    --cc=torvalds@osdl.org \
    --cc=viro@parcelfarce.linux.theplanet.co.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).