Blame SOURCES/ntfs-3g-big-sectors.patch

446720
--- libntfs-3g/bootsect.c.ref	2017-03-23 10:42:44.000000000 +0100
446720
+++ libntfs-3g/bootsect.c	2018-05-07 09:11:13.004710800 +0200
446720
@@ -38,6 +38,7 @@ 
446720
 #include <errno.h>
446720
 #endif
446720
 
446720
+#include "param.h"
446720
 #include "compat.h"
446720
 #include "bootsect.h"
446720
 #include "debug.h"
446720
@@ -61,6 +62,7 @@ 
446720
 {
446720
 	u32 i;
446720
 	BOOL ret = FALSE;
446720
+	u16 sectors_per_cluster;
446720
 
446720
 	ntfs_log_debug("Beginning bootsector check.\n");
446720
 
446720
@@ -83,15 +85,27 @@ 
446720
 	case 1: case 2: case 4: case 8: case 16: case 32: case 64: case 128:
446720
 		break;
446720
 	default:
446720
-		ntfs_log_error("Unexpected sectors per cluster value (%d).\n",
446720
-			       b->bpb.sectors_per_cluster);
446720
-		goto not_ntfs;
446720
+		if ((b->bpb.sectors_per_cluster < 240)
446720
+		    || (b->bpb.sectors_per_cluster > 249)) {
446720
+			if (b->bpb.sectors_per_cluster > 128)
446720
+				ntfs_log_error("Unexpected sectors"
446720
+					" per cluster value (code 0x%x)\n",
446720
+					b->bpb.sectors_per_cluster);
446720
+			else
446720
+				ntfs_log_error("Unexpected sectors"
446720
+					" per cluster value (%d).\n",
446720
+					b->bpb.sectors_per_cluster);
446720
+			goto not_ntfs;
446720
+		}
446720
 	}
446720
 
446720
 	ntfs_log_debug("Checking cluster size.\n");
446720
-	i = (u32)le16_to_cpu(b->bpb.bytes_per_sector) * 
446720
-		b->bpb.sectors_per_cluster;
446720
-	if (i > 65536) {
446720
+	if (b->bpb.sectors_per_cluster > 128)
446720
+		sectors_per_cluster = 1 << (256 - b->bpb.sectors_per_cluster);
446720
+	else
446720
+		sectors_per_cluster = b->bpb.sectors_per_cluster;
446720
+	i = (u32)le16_to_cpu(b->bpb.bytes_per_sector) * sectors_per_cluster;
446720
+	if (i > NTFS_MAX_CLUSTER_SIZE) {
446720
 		ntfs_log_error("Unexpected cluster size (%d).\n", i);
446720
 		goto not_ntfs;
446720
 	}
446720
@@ -171,7 +185,7 @@ 
446720
 int ntfs_boot_sector_parse(ntfs_volume *vol, const NTFS_BOOT_SECTOR *bs)
446720
 {
446720
 	s64 sectors;
446720
-	u8  sectors_per_cluster;
446720
+	u16  sectors_per_cluster;
446720
 	s8  c;
446720
 
446720
 	/* We return -1 with errno = EINVAL on error. */
446720
@@ -186,7 +200,10 @@ 
446720
 	 * below or equal the number_of_clusters) really belong in the
446720
 	 * ntfs_boot_sector_is_ntfs but in this way we can just do this once.
446720
 	 */
446720
-	sectors_per_cluster = bs->bpb.sectors_per_cluster;
446720
+	if (bs->bpb.sectors_per_cluster > 128)
446720
+		sectors_per_cluster = 1 << (256 - bs->bpb.sectors_per_cluster);
446720
+	else
446720
+		sectors_per_cluster = bs->bpb.sectors_per_cluster;
446720
 	ntfs_log_debug("SectorsPerCluster = 0x%x\n", sectors_per_cluster);
446720
 	if (sectors_per_cluster & (sectors_per_cluster - 1)) {
446720
 		ntfs_log_error("sectors_per_cluster (%d) is not a power of 2."
446720
--- ntfsprogs/mkntfs.8.in.ref	2017-03-23 10:42:44.000000000 +0100
446720
+++ ntfsprogs/mkntfs.8.in	2018-05-07 09:11:13.014132400 +0200
446720
@@ -132,7 +132,7 @@ 
446720
 .TP
446720
 \fB\-c\fR, \fB\-\-cluster\-size\fR BYTES
446720
 Specify the size of clusters in bytes. Valid cluster size values are powers of
446720
-two, with at least 256, and at most 65536 bytes per cluster. If omitted,
446720
+two, with at least 256, and at most 2097152 bytes (2MB) per cluster. If omitted,
446720
 .B mkntfs
446720
 uses 4096 bytes as the default cluster size.
446720
 .sp
446720
--- ntfsprogs/mkntfs.c.ref	2017-03-23 10:42:44.000000000 +0100
446720
+++ ntfsprogs/mkntfs.c	2018-05-07 09:11:13.035522300 +0200
446720
@@ -6,7 +6,7 @@ 
446720
  * Copyright (c) 2002-2006 Szabolcs Szakacsits
446720
  * Copyright (c) 2005      Erik Sornes
446720
  * Copyright (c) 2007      Yura Pakhuchiy
446720
- * Copyright (c) 2010-2014 Jean-Pierre Andre
446720
+ * Copyright (c) 2010-2018 Jean-Pierre Andre
446720
  *
446720
  * This utility will create an NTFS 1.2 or 3.1 volume on a user
446720
  * specified (block) device.
446720
@@ -119,6 +119,7 @@ 
446720
 #	endif
446720
 #endif
446720
 
446720
+#include "param.h"
446720
 #include "security.h"
446720
 #include "types.h"
446720
 #include "attrib.h"
446720
@@ -287,7 +288,7 @@ 
446720
 	ntfs_log_info("Copyright (c) 2002-2006 Szabolcs Szakacsits\n");
446720
 	ntfs_log_info("Copyright (c) 2005      Erik Sornes\n");
446720
 	ntfs_log_info("Copyright (c) 2007      Yura Pakhuchiy\n");
446720
-	ntfs_log_info("Copyright (c) 2010-2014 Jean-Pierre Andre\n");
446720
+	ntfs_log_info("Copyright (c) 2010-2018 Jean-Pierre Andre\n");
446720
 	ntfs_log_info("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home);
446720
 }
446720
 
446720
@@ -3719,11 +3720,11 @@ 
446720
 		/*
446720
 		 * For huge volumes, grow the cluster size until the number of
446720
 		 * clusters fits into 32 bits or the cluster size exceeds the
446720
-		 * maximum limit of 64kiB.
446720
+		 * maximum limit of NTFS_MAX_CLUSTER_SIZE.
446720
 		 */
446720
 		while (volume_size >> (ffs(vol->cluster_size) - 1 + 32)) {
446720
 			vol->cluster_size <<= 1;
446720
-			if (vol->cluster_size > 65535) {
446720
+			if (vol->cluster_size >= NTFS_MAX_CLUSTER_SIZE) {
446720
 				ntfs_log_error("Device is too large to hold an "
446720
 						"NTFS volume (maximum size is "
446720
 						"256TiB).\n");
446720
@@ -3744,15 +3745,18 @@ 
446720
 				"to, or larger than, the sector size.\n");
446720
 		return FALSE;
446720
 	}
446720
-	if (vol->cluster_size > 128 * (u32)opts.sector_size) {
446720
+		/* Before Windows 10 Creators, the limit was 128 */
446720
+	if (vol->cluster_size > 4096 * (u32)opts.sector_size) {
446720
 		ntfs_log_error("The cluster size is invalid.  It cannot be "
446720
-				"more that 128 times the size of the sector "
446720
+				"more that 4096 times the size of the sector "
446720
 				"size.\n");
446720
 		return FALSE;
446720
 	}
446720
-	if (vol->cluster_size > 65536) {
446720
+	if (vol->cluster_size > NTFS_MAX_CLUSTER_SIZE) {
446720
 		ntfs_log_error("The cluster size is invalid.  The maximum "
446720
-			"cluster size is 65536 bytes (64kiB).\n");
446720
+			"cluster size is %lu bytes (%lukiB).\n",
446720
+			(unsigned long)NTFS_MAX_CLUSTER_SIZE,
446720
+			(unsigned long)(NTFS_MAX_CLUSTER_SIZE >> 10));
446720
 		return FALSE;
446720
 	}
446720
 	vol->cluster_size_bits = ffs(vol->cluster_size) - 1;
446720
@@ -4387,6 +4391,7 @@ 
446720
 	u8 *sd;
446720
 	FILE_ATTR_FLAGS extend_flags;
446720
 	VOLUME_FLAGS volume_flags = const_cpu_to_le16(0);
446720
+	int sectors_per_cluster;
446720
 	int nr_sysfiles;
446720
 	int buf_sds_first_size;
446720
 	char *buf_sds;
446720
@@ -4639,8 +4644,11 @@ 
446720
 	 * already inserted, so no need to worry about these things.
446720
 	 */
446720
 	bs->bpb.bytes_per_sector = cpu_to_le16(opts.sector_size);
446720
-	bs->bpb.sectors_per_cluster = (u8)(g_vol->cluster_size /
446720
-			opts.sector_size);
446720
+	sectors_per_cluster = g_vol->cluster_size / opts.sector_size;
446720
+	if (sectors_per_cluster > 128)
446720
+		bs->bpb.sectors_per_cluster = 257 - ffs(sectors_per_cluster);
446720
+	else
446720
+		bs->bpb.sectors_per_cluster = sectors_per_cluster;
446720
 	bs->bpb.media_type = 0xf8; /* hard disk */
446720
 	bs->bpb.sectors_per_track = cpu_to_le16(opts.sectors_per_track);
446720
 	ntfs_log_debug("sectors per track = %ld (0x%lx)\n",
446720
--- ntfsprogs/ntfsclone.c.ref	2017-03-23 10:42:44.000000000 +0100
446720
+++ ntfsprogs/ntfsclone.c	2018-05-07 09:11:38.245007100 +0200
446720
@@ -3,7 +3,7 @@ 
446720
  *
446720
  * Copyright (c) 2003-2006 Szabolcs Szakacsits
446720
  * Copyright (c) 2004-2006 Anton Altaparmakov
446720
- * Copyright (c) 2010-2016 Jean-Pierre Andre
446720
+ * Copyright (c) 2010-2018 Jean-Pierre Andre
446720
  * Special image format support copyright (c) 2004 Per Olofsson
446720
  *
446720
  * Clone NTFS data and/or metadata to a sparse file, image, device or stdout.
446720
@@ -71,6 +71,7 @@ 
446720
  */
446720
 #define NTFS_DO_NOT_CHECK_ENDIANS
446720
 
446720
+#include "param.h"
446720
 #include "debug.h"
446720
 #include "types.h"
446720
 #include "support.h"
446720
@@ -270,7 +271,6 @@ 
446720
 
446720
 #define LAST_METADATA_INODE	11
446720
 
446720
-#define NTFS_MAX_CLUSTER_SIZE	65536
446720
 #define NTFS_SECTOR_SIZE	  512
446720
 
446720
 #define rounded_up_division(a, b) (((a) + (b - 1)) / (b))
446720
@@ -393,7 +393,7 @@ 
446720
 		   "Efficiently clone, image, restore or rescue an NTFS Volume.\n\n"
446720
 		   "Copyright (c) 2003-2006 Szabolcs Szakacsits\n"
446720
 		   "Copyright (c) 2004-2006 Anton Altaparmakov\n"
446720
-		   "Copyright (c) 2010-2016 Jean-Pierre Andre\n\n");
446720
+		   "Copyright (c) 2010-2018 Jean-Pierre Andre\n\n");
446720
 	fprintf(stderr, "%s\n%s%s", ntfs_gpl, ntfs_bugs, ntfs_home);
446720
 	exit(0);
446720
 }
446720
@@ -756,7 +756,7 @@ 
446720
 
446720
 static void copy_cluster(int rescue, u64 rescue_lcn, u64 lcn)
446720
 {
446720
-	char buff[NTFS_MAX_CLUSTER_SIZE]; /* overflow checked at mount time */
446720
+	char *buff;
446720
 	/* vol is NULL if opt.restore_image is set */
446720
 	s32 csize = le32_to_cpu(image_hdr.cluster_size);
446720
 	BOOL backup_bootsector;
446720
@@ -783,6 +783,10 @@ 
446720
 		}
446720
 	}
446720
 
446720
+	buff = (char*)ntfs_malloc(csize);
446720
+	if (!buff)
446720
+		err_exit("Not enough memory");
446720
+
446720
 // need reading when not about to write ?
446720
 	if (read_all(fd, buff, csize) == -1) {
446720
 
446720
@@ -858,6 +862,7 @@ 
446720
 		perr_printf("Write failed");
446720
 #endif
446720
 	}
446720
+	free(buff);
446720
 }
446720
 
446720
 static s64 lseek_out(int fd, s64 pos, int mode)
446720
@@ -995,7 +1000,11 @@ 
446720
 				 struct progress_bar *progress, u64 *p_counter)
446720
 {
446720
 	s64 i;
446720
-	char buff[NTFS_MAX_CLUSTER_SIZE];
446720
+	char *buff;
446720
+
446720
+	buff = (char*)ntfs_malloc(csize);
446720
+	if (!buff)
446720
+		err_exit("Not enough memory");
446720
 
446720
 	memset(buff, 0, csize);
446720
 
446720
@@ -1004,6 +1013,7 @@ 
446720
 			perr_exit("write_all");
446720
 		progress_update(progress, ++(*p_counter));
446720
 	}
446720
+	free(buff);
446720
 }
446720
 
446720
 static void restore_image(void)
446720
@@ -1492,7 +1502,7 @@ 
446720
 
446720
 static void copy_wipe_mft(ntfs_walk_clusters_ctx *image, runlist *rl)
446720
 {
446720
-	char buff[NTFS_MAX_CLUSTER_SIZE]; /* overflow checked at mount time */
446720
+	char *buff;
446720
 	void *fd;
446720
 	s64 mft_no;
446720
 	u32 mft_record_size;
446720
@@ -1522,6 +1532,10 @@ 
446720
 		clusters_per_set = mft_record_size/csize;
446720
 		records_per_set = 1;
446720
 	}
446720
+	buff = (char*)ntfs_malloc(mft_record_size);
446720
+	if (!buff)
446720
+		err_exit("Not enough memory");
446720
+
446720
 	mft_no = 0;
446720
 	ri = rj = 0;
446720
 	wi = wj = 0;
446720
@@ -1554,6 +1568,7 @@ 
446720
 		}
446720
 	}
446720
 	image->current_lcn = current_lcn;
446720
+	free(buff);
446720
 }
446720
 
446720
 /*
446720
@@ -1566,7 +1581,7 @@ 
446720
 
446720
 static void copy_wipe_i30(ntfs_walk_clusters_ctx *image, runlist *rl)
446720
 {
446720
-	char buff[NTFS_MAX_CLUSTER_SIZE]; /* overflow checked at mount time */
446720
+	char *buff;
446720
 	void *fd;
446720
 	u32 indx_record_size;
446720
 	u32 csize;
446720
@@ -1595,6 +1610,10 @@ 
446720
 		clusters_per_set = indx_record_size/csize;
446720
 		records_per_set = 1;
446720
 	}
446720
+	buff = (char*)ntfs_malloc(indx_record_size);
446720
+	if (!buff)
446720
+		err_exit("Not enough memory");
446720
+
446720
 	ri = rj = 0;
446720
 	wi = wj = 0;
446720
 	if (rl[ri].length)
446720
@@ -1627,6 +1646,7 @@ 
446720
 		}
446720
 	}
446720
 	image->current_lcn = current_lcn;
446720
+	free(buff);
446720
 }
446720
 
446720
 static void dump_clusters(ntfs_walk_clusters_ctx *image, runlist *rl)
446720
--- ntfsprogs/ntfsresize.c.ref	2017-03-23 10:42:44.000000000 +0100
446720
+++ ntfsprogs/ntfsresize.c	2018-05-07 09:11:13.076883400 +0200
446720
@@ -59,6 +59,7 @@ 
446720
 #include <fcntl.h>
446720
 #endif
446720
 
446720
+#include "param.h"
446720
 #include "debug.h"
446720
 #include "types.h"
446720
 #include "support.h"
446720
@@ -243,8 +244,6 @@ 
446720
 #define DIRTY_INODE		(1)
446720
 #define DIRTY_ATTRIB		(2)
446720
 
446720
-#define NTFS_MAX_CLUSTER_SIZE	(65536)
446720
-
446720
 static s64 rounded_up_division(s64 numer, s64 denom)
446720
 {
446720
 	return (numer + (denom - 1)) / denom;
446720
@@ -404,7 +403,7 @@ 
446720
 	printf("Copyright (c) 2002-2005  Anton Altaparmakov\n");
446720
 	printf("Copyright (c) 2002-2003  Richard Russon\n");
446720
 	printf("Copyright (c) 2007       Yura Pakhuchiy\n");
446720
-	printf("Copyright (c) 2011-2016  Jean-Pierre Andre\n");
446720
+	printf("Copyright (c) 2011-2018  Jean-Pierre Andre\n");
446720
 	printf("\n%s\n%s%s", ntfs_gpl, ntfs_bugs, ntfs_home);
446720
 }
446720
 
446720
@@ -1849,9 +1848,13 @@ 
446720
 static void copy_clusters(ntfs_resize_t *resize, s64 dest, s64 src, s64 len)
446720
 {
446720
 	s64 i;
446720
-	char buff[NTFS_MAX_CLUSTER_SIZE]; /* overflow checked at mount time */
446720
+	char *buff;
446720
 	ntfs_volume *vol = resize->vol;
446720
 
446720
+	buff = (char*)ntfs_malloc(vol->cluster_size);
446720
+	if (!buff)
446720
+		perr_exit("ntfs_malloc");
446720
+
446720
 	for (i = 0; i < len; i++) {
446720
 
446720
 		lseek_to_cluster(vol, src + i);
446720
@@ -1875,6 +1878,7 @@ 
446720
 		resize->relocations++;
446720
 		progress_update(&resize->progress, resize->relocations);
446720
 	}
446720
+	free(buff);
446720
 }
446720
 
446720
 static void relocate_clusters(ntfs_resize_t *r, runlist *dest_rl, s64 src_lcn)
446720
--- include/ntfs-3g/param.h.ref	2017-03-23 10:42:44.000000000 +0100
446720
+++ include/ntfs-3g/param.h	2018-05-07 09:11:13.088302600 +0200
446720
@@ -40,6 +40,13 @@ 
446720
 };
446720
 
446720
 /*
446720
+ *		Parameters for formatting
446720
+ */
446720
+
446720
+		/* Up to Windows 10, the cluster size was limited to 64K */
446720
+#define NTFS_MAX_CLUSTER_SIZE 2097152 /* Windows 10 Creators allows 2MB */
446720
+
446720
+/*
446720
  *		Parameters for compression
446720
  */
446720