Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 18 Mar 2010 11:08:54 GMT
From:      Samuel Martin Moro <faust64@gmail.com>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   ports/144852: ntfsprogs - mkntfs
Message-ID:  <201003181108.o2IB8s4q067255@www.freebsd.org>
Resent-Message-ID: <201003181110.o2IBA4Dd040318@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         144852
>Category:       ports
>Synopsis:       ntfsprogs - mkntfs
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          update
>Submitter-Id:   current-users
>Arrival-Date:   Thu Mar 18 11:10:04 UTC 2010
>Closed-Date:
>Last-Modified:
>Originator:     Samuel Martin Moro
>Release:        7.2 RELEASE
>Organization:
CamTrace
>Environment:
>Description:
mkntfs do not work, whatever FreeBSD version.
badly ported from Linux, it wants block devices, and infinite loop when forcing on character device (if using libublio).
also, the libntfs uses bad defines to get disk geometry.

>How-To-Repeat:
mkntfs /dev/ad0s1
> not block device
mkntfs /dev/ad0s1
> infinite loop
also, warning about bad geometry (and using pointless default values)
>Fix:
I made these two patches (for libntfs, and mkntfs)

Also:
with the patch mkntfs, I correct the infinite loop using libublio.
The problem is that ublio reads out of disk, because of UBLIO_BLOCK_SIZE defined to 262144. When reading on a entire drive, there's no problem, but when working on parts, ublio returns a negative value, not handled by mkntfs.
but, my patch only avoid the infinite loop. the problem is still that mkntfs failed writing the end boot sector. user would have to chkdsk under windows to repair its partition.
I think a way to avoid that may be, for example, UBLIO_BLOCK_SIZE=`expr 63 '*' 255` mkntfs $dev.
Anyway, without libublio support, the partition is just fine.

There's still a thing I didn't fixed: when chkdsk on 'correct' partition, it says that the $UpCase file is invalid.
Indeed, a few differences.
I'll make an other patch to get rid of it (it's at my office, I don't work every day)


Patch attached with submission follows:

faust@alpha ~> cat patch-libntfs-device_2.c
--- libntfs/device.c	2010-03-16 16:20:38.000000000 +0100
+++ libntfs/device.c	2010-03-16 17:18:31.000000000 +0100
@@ -641,8 +641,8 @@
  *
  * The following error codes are defined:
  *	EINVAL		Input parameter error
- *	EOPNOTSUPP	System does not support HDIO_GETGEO ioctl
- *	ENOTTY		@dev is a file or a device not supporting HDIO_GETGEO
+ *	EOPNOTSUPP	System does not support DIOCGFWSECTORS ioctl
+ *	ENOTTY		@dev is a file or a device not supporting DIOCGFWSECTORS
  */
 s64 ntfs_device_partition_start_sector_get(struct ntfs_device *dev)
 {
@@ -650,13 +650,13 @@
 		errno = EINVAL;
 		return -1;
 	}
-#ifdef HDIO_GETGEO
-	{	struct hd_geometry geo;
+#ifdef DIOCGFWSECTORS
+	{	u_int	start_sector = 0;
 
-		if (!dev->d_ops->ioctl(dev, HDIO_GETGEO, &geo)) {
-			ntfs_log_debug("HDIO_GETGEO start_sect = %lu (0x%lx)\n",
-					geo.start, geo.start);
-			return geo.start;
+		if (!dev->d_ops->ioctl(dev, DIOCGFWSECTORS, &start_sector)) {
+			ntfs_log_debug("DIOCGFWSECTORS start_sect = %lu (0x%lx)\n",
+					start_sector, start_sector);
+			return start_sector;
 		}
 	}
 #else
@@ -674,8 +674,8 @@
  *
  * The following error codes are defined:
  *	EINVAL		Input parameter error
- *	EOPNOTSUPP	System does not support HDIO_GETGEO ioctl
- *	ENOTTY		@dev is a file or a device not supporting HDIO_GETGEO
+ *	EOPNOTSUPP	System does not support DIOCGFWHEADS ioctl
+ *	ENOTTY		@dev is a file or a device not supporting DIOCGFWHEADS
  */
 int ntfs_device_heads_get(struct ntfs_device *dev)
 {
@@ -683,14 +683,13 @@
 		errno = EINVAL;
 		return -1;
 	}
-#ifdef HDIO_GETGEO
-	{	struct hd_geometry geo;
+#ifdef DIOCGFWHEADS
+	{	u_int	heads;
 
-		if (!dev->d_ops->ioctl(dev, HDIO_GETGEO, &geo)) {
-			ntfs_log_debug("HDIO_GETGEO heads = %u (0x%x)\n",
-					(unsigned)geo.heads,
-					(unsigned)geo.heads);
-			return geo.heads;
+		if (!dev->d_ops->ioctl(dev, DIOCGFWHEADS, &heads)) {
+			ntfs_log_debug("DIOCGFWHEADS heads = %u (0x%x)\n",
+					heads, heads);
+			return heads;
 		}
 	}
 #else
@@ -708,8 +707,8 @@
  *
  * The following error codes are defined:
  *	EINVAL		Input parameter error
- *	EOPNOTSUPP	System does not support HDIO_GETGEO ioctl
- *	ENOTTY		@dev is a file or a device not supporting HDIO_GETGEO
+ *	EOPNOTSUPP	System does not support DIOCGFWSECTORS ioctl
+ *	ENOTTY		@dev is a file or a device not supporting DIOCGFWSECTORS
  */
 int ntfs_device_sectors_per_track_get(struct ntfs_device *dev)
 {
@@ -717,14 +716,13 @@
 		errno = EINVAL;
 		return -1;
 	}
-#ifdef HDIO_GETGEO
-	{	struct hd_geometry geo;
+#ifdef DIOCGFWSECTORS
+	{	u_int	sptrack;
 
-		if (!dev->d_ops->ioctl(dev, HDIO_GETGEO, &geo)) {
-			ntfs_log_debug("HDIO_GETGEO sectors_per_track = %u (0x%x)\n",
-					(unsigned)geo.sectors,
-					(unsigned)geo.sectors);
-			return geo.sectors;
+		if (!dev->d_ops->ioctl(dev, DIOCGFWSECTORS, &sptrack)) {
+			ntfs_log_debug("DIOCGFWSECTORS sectors_per_track = %u (0x%x)\n",
+					sptrack, sptrack);
+			return sptrack;
 		}
 	}
 #else
@@ -742,8 +740,8 @@
  *
  * The following error codes are defined:
  *	EINVAL		Input parameter error
- *	EOPNOTSUPP	System does not support BLKSSZGET ioctl
- *	ENOTTY		@dev is a file or a device not supporting BLKSSZGET
+ *	EOPNOTSUPP	System does not support DIOCGSECTORSIZE ioctl
+ *	ENOTTY		@dev is a file or a device not supporting DIOCGSECTORSIZE
  */
 int ntfs_device_sector_size_get(struct ntfs_device *dev)
 {
@@ -751,24 +749,7 @@
 		errno = EINVAL;
 		return -1;
 	}
-#ifdef BLKSSZGET
-	{
-		int sect_size = 0;
-
-		if (!dev->d_ops->ioctl(dev, BLKSSZGET, &sect_size)) {
-			ntfs_log_debug("BLKSSZGET sector size = %d bytes\n",
-					sect_size);
-			return sect_size;
-		}
-	}
-#elif defined(DIOCGSECTORSIZE)
-	/*
-	 * XXX On FreeBSD (where we have DIOCGSECTORSIZE) the low-level I/O
-	 * system already knows the sector size, and doing an ioctl is needless.
-	 * However, I don't know how to extract that information cleanly,
-	 * without letting a bunch of platform specific #ifdef-s to sneak in.
-	 * So now I rather just re-do the ioctl...
-	 */
+#ifdef	DIOCGSECTORSIZE
 	{
 		size_t sect_size = 0;
faust@alpha ~> cat patch-ntfsprogs-mkntfs.c
--- ntfsprogs/mkntfs.c	2007-09-19 18:51:09.000000000 +0200
+++ ntfsprogs/mkntfs.c	2010-03-16 17:26:42.000000000 +0100
@@ -552,12 +552,16 @@
 	total = 0LL;
 	retry = 0;
 	do {
-		bytes_written = dev->d_ops->write(dev, b, count);
+		bytes_written = (long long)dev->d_ops->write(dev, b, count);
 		if (bytes_written == -1LL) {
 			retry = errno;
 			ntfs_log_perror("Error writing to %s", dev->d_name);
 			errno = retry;
 			return bytes_written;
+	    	} else if (bytes_written < 0) {
+			errno = EINVAL;
+			ntfs_log_error("Failed to write to device %s.\n", dev->d_name);
+			return -1;
 		} else if (!bytes_written) {
 			retry++;
 		} else {
@@ -3072,8 +3076,8 @@
 		goto done;
 	}
 
-	if (!S_ISBLK(sbuf.st_mode)) {
-		ntfs_log_error("%s is not a block device.\n", vol->dev->d_name);
+	if (!S_ISCHR(sbuf.st_mode)) {
+		ntfs_log_error("%s is not a character device.\n", vol->dev->d_name);
 		if (!opts.force) {
 			ntfs_log_error("Refusing to make a filesystem here!\n");
 			goto done;


>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201003181108.o2IB8s4q067255>