dvhtool's calculates free space in vh incorrectly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The way dvhtool calculates the free space in the vh is bogus. Since this
number is too small dvhtool may write past the end of the vh. Attached
patch fixes this. Can I get the dvhtool cvs commit messages from
somewhere?
 -- Guido

--- dvhtool-1.0.1.orig/dvhlib.c
+++ dvhtool-1.0.1/dvhlib.c
@@ -325,8 +327,10 @@
 	if (res == -1)
 		die("Couldn't stat source file");
 
-	/* XXX pad to blocksize? */
-	size = vh->vh_pt[8].pt_nblks * blksize - istat.st_size;
+	/* calculate free blocks in vh */
+	size = vh->vh_pt[8].pt_nblks				/* total vh size */
+		- ( vh->vh_pt[8].pt_firstlbn + 4 )		/* reserved area */
+		- (( istat.st_size + blksize - 1 ) / blksize );	/* pad to blocksize */
 	/*
 	 * Are we replacing an existing file, check for enough space and free
 	 * entry in volume header
@@ -336,16 +340,15 @@
 			/* It's an existing file, delete it.  */
 			memset(vd->vd_name, 0, VDNAMESIZE);
 			vd->vd_nbytes = 0;
-			break;
 		}
 		if ( vd->vd_nbytes ) {
-			size -= vd->vd_nbytes;
+			size -= (vd->vd_nbytes + blksize - 1 ) / blksize; /* pad to blocksize */
 			num++;
 		}
 		vd++;
 	}
 
-	if ( num == NVDIR ) 
+	if ( num == NVDIR )
 		die("No more free entries in volume header");
 	if ( size <= 0 )
 		die("Not enough space left in volume header");
@@ -403,7 +406,7 @@
 				die("Short write");
 			}
 		}
-		dest += (vd->vd_nbytes + 511) / 512;	/* XXX Blocksize  */
+		dest += (vd->vd_nbytes + blksize - 1) / blksize;
 		vd++;
 	}
 

[Index of Archives]     [Linux MIPS Home]     [LKML Archive]     [Linux ARM Kernel]     [Linux ARM]     [Linux]     [Git]     [Yosemite News]     [Linux SCSI]     [Linux Hams]

  Powered by Linux