[prev in list] [next in list] [prev in thread] [next in thread] 

List:       linux-ntfs-cvs
Subject:    [Linux-NTFS-cvs] CVS: ntfs-driver-tng/linux/fs/ntfs attrib.c,1.49,1.50
From:       Anton Altaparmakov <antona () users ! sourceforge ! net>
Date:       2002-01-28 6:54:08
[Download RAW message or body]


Changes by: antona

Update of /cvsroot/linux-ntfs/ntfs-driver-tng/linux/fs/ntfs
In directory usw-pr-cvs1:/tmp/cvs-serv3302

Modified Files:
	attrib.c 
Log Message:
1st file of the massive update.


Index: attrib.c
===================================================================
RCS file: /cvsroot/linux-ntfs/ntfs-driver-tng/linux/fs/ntfs/attrib.c,v
retrieving revision 1.49
retrieving revision 1.50
diff -U2 -r1.49 -r1.50
--- attrib.c	2002/01/27 07:25:07	1.49
+++ attrib.c	2002/01/28 06:54:05	1.50
@@ -42,5 +42,4 @@
 }
 
-
 /**
  * ntfs_rl_realloc - Reallocate memory for run_lists
@@ -82,4 +81,13 @@
 
 /**
+ * rl_mm (run_list *base, int dst, int src, int size)
+ */
+static inline void rl_mm (run_list *base, int dst, int src, int size)
+{
+	if ((dst != src) && (size > 0))
+		memmove (base+dst, base+src, size * sizeof (run_list));
+}
+
+/**
  * ntfs_rl_merge - Join together two run_lists
  * @one:  The first run_list and destination
@@ -187,4 +195,9 @@
 		return res;
 
+	if ((nsize - left + disc - hole) != 0)
+		rl_mm (res, loc + nsize - left + disc - hole,
+			    loc,
+			    osize - loc);
+
 	rl_mm (res, loc + nsize - left + disc - hole, loc, osize - loc);
 	rl_mc (res, loc + disc - hole, new, left, nsize - left);
@@ -309,7 +322,6 @@
 }
 
-
 /**
- * merge_run_lists - Merge two run_lists into one
+ * merge_run_lists - merge two run_lists into one
  * @drl:  The original run_list.
  * @srl:  The new run_list to be merge into @drl.
@@ -386,5 +398,15 @@
 	while (srl[si].length && srl[si].lcn < (LCN)LCN_HOLE)
 		si++;
-	/* can this happen for drl? */
+	/*
+	 * Can this happen for drl? - Not initially, but it will be possible in
+	 * the future, as I plan to cut down on the amount of work done by read
+	 * inode and one optimization would be not to bother reading in the
+	 * run list at all, i.e. the first read of the file will cause it to
+	 * be read but if that first read occurs somewhere into the file, the
+	 * first mapped part of the run list might well not be the first
+	 * extent of the attribute in which case exactly this code triggers. It
+	 * is a different question whether the current code would actually cope
+	 * with this... (AIA)
+	 */
 	while (drl[di].length && drl[di].lcn < (LCN)LCN_HOLE)
 		di++;
@@ -436,4 +458,7 @@
 	int ss = sfinal - sstart + 1;
 
+	// FIXME: This looks dodgy... drl[dins].lcn might well be LCN_ENOENT
+	// at end of file. Is just the comment wrong? (AIA)
+	// TODO: I am here (AIA)
 	start  = ((drl[dins].lcn == LCN_RL_NOT_MAPPED) ||    /* End of file   */
 		  (drl[dins].vcn == srl[sstart].vcn));	     /* Start of hole */
@@ -474,5 +499,4 @@
 }
 
-
 /**
  * decompress_mapping_pairs - convert mapping pairs array to run list
@@ -985,6 +1009,7 @@
  * in there and return it.
  *
- * NOTE: ctx->vfs_ino must be the base inode on first call. On subsequent calls
- * it can be any extended inode, too (ctx->base_vfs_ino is then the base inode).
+ * NOTE: ctx->ntfs_ino must be the base inode on first call. On subsequent
+ * calls it can be any extended inode, too (ctx->base_ntfs_ino is then the
+ * base inode).
  *
  * TODO: Flesh out the above description for this important function...
@@ -995,5 +1020,5 @@
 		attr_search_context *ctx)
 {
-	ntfs_inode *base_ntfs_ino, *ntfs_ino;
+	ntfs_inode *base_ni, *ni;
 	ntfs_volume *vol;
 	ATTR_LIST_ENTRY *al_entry, *next_al_entry;
@@ -1003,18 +1028,17 @@
 	u32 al_name_len;
 
-	ntfs_debug("Entering for inode 0x%lx, type 0x%x.\n",
-			ctx->vfs_ino->i_ino, type);
-	ntfs_ino = NTFS_I(ctx->vfs_ino);
-	if (!ctx->base_vfs_ino) {
+	ni = ctx->ntfs_ino;
+	base_ni = ctx->base_ntfs_ino;
+	ntfs_debug("Entering for inode 0x%Lx, type 0x%x.\n", ni->mft_no, type);
+	if (!base_ni) {
 		/* First call happens with the base mft record. */
-		ctx->base_vfs_ino = ctx->vfs_ino;
+		base_ni = ctx->base_ntfs_ino = ctx->ntfs_ino;
 		ctx->base_mrec = ctx->mrec;
 	}
-	if (ctx->vfs_ino == ctx->base_vfs_ino)
+	if (ni == base_ni)
 		ctx->base_attr = ctx->attr;
-	vol = NTFS_SB(ctx->base_vfs_ino->i_sb);
-	base_ntfs_ino = NTFS_I(ctx->base_vfs_ino);
-	al_start = base_ntfs_ino->attr_list;
-	al_end = al_start + base_ntfs_ino->attr_list_size;
+	vol = base_ni->vol;
+	al_start = base_ni->attr_list;
+	al_end = al_start + base_ni->attr_list_size;
 	if (!ctx->al_entry)
 		ctx->al_entry = (ATTR_LIST_ENTRY*)al_start;
@@ -1031,5 +1055,5 @@
 	for (;; al_entry = next_al_entry) {
 		/* Out of bounds check. */
-		if ((u8*)al_entry < base_ntfs_ino->attr_list ||
+		if ((u8*)al_entry < base_ni->attr_list ||
 				(u8*)al_entry > al_end)
 			break;	/* Inode is corrupt. */
@@ -1112,54 +1136,26 @@
 						vol->upcase_len))
 			continue;
-		if (MREF_LE(al_entry->mft_reference) == ctx->vfs_ino->i_ino) {
-			if (MSEQNO_LE(al_entry->mft_reference) !=
-					ctx->vfs_ino->i_generation) {
-				ntfs_error(ctx->vfs_ino->i_sb, "Found stale "
-						"mft reference in attribute "
-						"list!");
+		if (MREF_LE(al_entry->mft_reference) == ni->mft_no) {
+			if (MSEQNO_LE(al_entry->mft_reference) != ni->seq_no) {
+				ntfs_error(vol->sb, "Found stale mft "
+						"reference in attribute list!");
 				break;
 			}
 		} else { /* Mft references do not match. */
 			/* If there is a mapped record unmap it first. */
-			if (ctx->vfs_ino != ctx->base_vfs_ino) {
-				unmap_mft_record(READ, ctx->vfs_ino);
-			}
+			if (ni != base_ni)
+				unmap_extent_mft_record(ni);
 			/* Do we want the base record back? */
 			if (MREF_LE(al_entry->mft_reference) ==
-					ctx->base_vfs_ino->i_ino) {
-				ctx->vfs_ino = ctx->base_vfs_ino;
+					base_ni->mft_no) {
+				ni = ctx->ntfs_ino = base_ni;
 				ctx->mrec = ctx->base_mrec;
-			} else { /* We want an extent record. */
-			 	int i, have_it = 0;
-				struct inode **extent_inos = NULL;
-
-				/* Do we have the wanted extent inode yet? */
-				down(&base_ntfs_ino->extent_lock);
-				if (base_ntfs_ino->nr_extents > 0)
-					extent_inos =
-						base_ntfs_ino->extent_vfs_inos;
-				for (i = 0; i < base_ntfs_ino->nr_extents;
-						i++) {
-					if (MREF_LE(al_entry->mft_reference) !=
-							extent_inos[i]->i_ino)
-						continue;
-					have_it = 1;
-					ctx->vfs_ino = extent_inos[i];
-					break;
-				}
-				up(&base_ntfs_ino->extent_lock);
-				if (have_it)
-					ctx->mrec = map_mft_record(READ,
-							ctx->vfs_ino);
-				else
-					ctx->mrec =
-						iget_map_mft_record(READ,
-						ctx->base_vfs_ino->i_sb,
-						MREF_LE(
-						al_entry->mft_reference),
-						&ctx->vfs_ino);
+			} else {
+				/* We want an extent record. */
+				ctx->mrec = map_extent_mft_record(base_ni,
+						al_entry->mft_reference, &ni);
+				ctx->ntfs_ino = ni;
 				if (IS_ERR(ctx->mrec)) {
-					ntfs_error(ctx->vfs_ino->i_sb,
-							"Failed to map mft "
+					ntfs_error(vol->sb, "Failed to map mft "
 							"record, error code "
 							"%i.",
@@ -1229,9 +1225,9 @@
 		goto do_next_attr_loop;
 	}
-	ntfs_error(ctx->base_vfs_ino->i_sb, "Inode contains corrupt attribute "
-			"list attribute.\n");
-	if (ctx->vfs_ino != ctx->base_vfs_ino) {
-		unmap_mft_record(READ, ctx->vfs_ino);
-		ctx->vfs_ino = ctx->base_vfs_ino;
+	ntfs_error(base_ni->vol->sb, "Inode contains corrupt attribute list "
+			"attribute.\n");
+	if (ni != base_ni) {
+		unmap_extent_mft_record(ni);
+		ctx->ntfs_ino = base_ni;
 		ctx->mrec = ctx->base_mrec;
 		ctx->attr = ctx->base_attr;
@@ -1246,6 +1242,6 @@
 not_found:
 	/* Not found, cleanup current mapping if any and not the base. */
-	if (ctx->vfs_ino != ctx->base_vfs_ino)
-		unmap_mft_record(READ, ctx->vfs_ino);
+	if (ni != base_ni)
+		unmap_extent_mft_record(ni);
 	/*
 	 * Seek to the end of the base mft record, i.e. when we return false,
@@ -1257,5 +1253,5 @@
 	 * FIXME: Do we really want to do this here? Think about it... (AIA)
 	 */
-	ctx->vfs_ino = ctx->base_vfs_ino;
+	ctx->ntfs_ino = base_ni;
 	ctx->mrec = ctx->base_mrec;
 	ctx->attr = ctx->base_attr;
@@ -1271,5 +1267,5 @@
  */
 static inline void init_attr_search_ctx(attr_search_context *ctx,
-		struct inode *vfs_ino, MFT_RECORD *mrec)
+		ntfs_inode *ni, MFT_RECORD *mrec)
 {
 	ctx->mrec = mrec;
@@ -1277,7 +1273,7 @@
 	ctx->attr = (ATTR_RECORD*)((u8*)mrec + le16_to_cpu(mrec->attrs_offset));
 	ctx->is_first = TRUE;
-	ctx->vfs_ino = vfs_ino;
+	ctx->ntfs_ino = ni;
 	ctx->al_entry = NULL;
-	ctx->base_vfs_ino = NULL;
+	ctx->base_ntfs_ino = NULL;
 	ctx->base_mrec = NULL;
 	ctx->base_attr = NULL;
@@ -1287,5 +1283,5 @@
  * get_attr_search_ctx -
  */
-int get_attr_search_ctx(attr_search_context **ctx, struct inode *vfs_ino,
+int get_attr_search_ctx(attr_search_context **ctx, ntfs_inode *ni,
 		MFT_RECORD *mrec)
 {
@@ -1293,5 +1289,5 @@
 	if (unlikely(!*ctx))
 		return -ENOMEM;
-	init_attr_search_ctx(*ctx, vfs_ino, mrec);
+	init_attr_search_ctx(*ctx, ni, mrec);
 	return 0;
 }
@@ -1302,6 +1298,6 @@
 void put_attr_search_ctx(attr_search_context *ctx)
 {
-	if (ctx->base_vfs_ino && ctx->vfs_ino != ctx->base_vfs_ino)
-		unmap_mft_record(READ, ctx->vfs_ino);
+	if (ctx->base_ntfs_ino && ctx->ntfs_ino != ctx->base_ntfs_ino)
+		unmap_mft_record(READ, ctx->ntfs_ino);
 	kmem_cache_free(ntfs_attr_ctx_cache, ctx);
 	return;
@@ -1313,5 +1309,5 @@
 void reinit_attr_search_ctx(attr_search_context *ctx)
 {
-	if (likely(!ctx->base_vfs_ino)) {
+	if (likely(!ctx->base_ntfs_ino)) {
 		/* No attribute list. */
 		ctx->is_first = TRUE;
@@ -1321,7 +1317,7 @@
 		return;
 	} /* Attribute list. */
-	if (ctx->vfs_ino != ctx->base_vfs_ino)
-		unmap_mft_record(READ, ctx->vfs_ino);
-	init_attr_search_ctx(ctx, ctx->base_vfs_ino, ctx->base_mrec);
+	if (ctx->ntfs_ino != ctx->base_ntfs_ino)
+		unmap_mft_record(READ, ctx->ntfs_ino);
+	init_attr_search_ctx(ctx, ctx->base_ntfs_ino, ctx->base_mrec);
 	return;
 }
@@ -1330,5 +1326,5 @@
  * lookup_attr -
  *
- * Find an attribute in an inode. On first search ctx->vfs_ino must be the
+ * Find an attribute in an inode. On first search ctx->ntfs_ino must be the
  * base mft record and ctx must have been obtained from a call to
  * get_attr_search_ctx().
@@ -1348,15 +1344,14 @@
 		const u32 val_len, attr_search_context *ctx)
 {
-	struct inode *base_vfs_ino;
+	ntfs_inode *base_ni;
 
 	ntfs_debug("Entering.\n");
-	if (ctx->base_vfs_ino)
-		base_vfs_ino = ctx->base_vfs_ino;
+	if (ctx->base_ntfs_ino)
+		base_ni = ctx->base_ntfs_ino;
 	else
-		base_vfs_ino = ctx->vfs_ino;
+		base_ni = ctx->ntfs_ino;
 	/* Sanity check, just for debugging really. */
-	if (!base_vfs_ino)
-		BUG();
-	if (likely(!NInoAttrList(NTFS_I(base_vfs_ino))))
+	BUG_ON(!base_ni);
+	if (likely(!NInoAttrList(base_ni)))
 		return find_attr(type, name, name_len, ic, upcase, upcase_len,
 				val, val_len, ctx);


_______________________________________________
Linux-NTFS-cvs mailing list
Linux-NTFS-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-ntfs-cvs
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic