ntfs3g-2017.3.23-big-sectors.patch 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. --- a/libntfs-3g/bootsect.c.ref 2017-03-23 10:42:44.000000000 +0100
  2. +++ b/libntfs-3g/bootsect.c 2018-05-07 09:11:13.004710800 +0200
  3. @@ -38,6 +38,7 @@
  4. #include <errno.h>
  5. #endif
  6. +#include "param.h"
  7. #include "compat.h"
  8. #include "bootsect.h"
  9. #include "debug.h"
  10. @@ -61,6 +62,7 @@
  11. {
  12. u32 i;
  13. BOOL ret = FALSE;
  14. + u16 sectors_per_cluster;
  15. ntfs_log_debug("Beginning bootsector check.\n");
  16. @@ -83,15 +85,27 @@
  17. case 1: case 2: case 4: case 8: case 16: case 32: case 64: case 128:
  18. break;
  19. default:
  20. - ntfs_log_error("Unexpected sectors per cluster value (%d).\n",
  21. - b->bpb.sectors_per_cluster);
  22. - goto not_ntfs;
  23. + if ((b->bpb.sectors_per_cluster < 240)
  24. + || (b->bpb.sectors_per_cluster > 249)) {
  25. + if (b->bpb.sectors_per_cluster > 128)
  26. + ntfs_log_error("Unexpected sectors"
  27. + " per cluster value (code 0x%x)\n",
  28. + b->bpb.sectors_per_cluster);
  29. + else
  30. + ntfs_log_error("Unexpected sectors"
  31. + " per cluster value (%d).\n",
  32. + b->bpb.sectors_per_cluster);
  33. + goto not_ntfs;
  34. + }
  35. }
  36. ntfs_log_debug("Checking cluster size.\n");
  37. - i = (u32)le16_to_cpu(b->bpb.bytes_per_sector) *
  38. - b->bpb.sectors_per_cluster;
  39. - if (i > 65536) {
  40. + if (b->bpb.sectors_per_cluster > 128)
  41. + sectors_per_cluster = 1 << (256 - b->bpb.sectors_per_cluster);
  42. + else
  43. + sectors_per_cluster = b->bpb.sectors_per_cluster;
  44. + i = (u32)le16_to_cpu(b->bpb.bytes_per_sector) * sectors_per_cluster;
  45. + if (i > NTFS_MAX_CLUSTER_SIZE) {
  46. ntfs_log_error("Unexpected cluster size (%d).\n", i);
  47. goto not_ntfs;
  48. }
  49. @@ -171,7 +185,7 @@
  50. int ntfs_boot_sector_parse(ntfs_volume *vol, const NTFS_BOOT_SECTOR *bs)
  51. {
  52. s64 sectors;
  53. - u8 sectors_per_cluster;
  54. + u16 sectors_per_cluster;
  55. s8 c;
  56. /* We return -1 with errno = EINVAL on error. */
  57. @@ -186,7 +200,10 @@
  58. * below or equal the number_of_clusters) really belong in the
  59. * ntfs_boot_sector_is_ntfs but in this way we can just do this once.
  60. */
  61. - sectors_per_cluster = bs->bpb.sectors_per_cluster;
  62. + if (bs->bpb.sectors_per_cluster > 128)
  63. + sectors_per_cluster = 1 << (256 - bs->bpb.sectors_per_cluster);
  64. + else
  65. + sectors_per_cluster = bs->bpb.sectors_per_cluster;
  66. ntfs_log_debug("SectorsPerCluster = 0x%x\n", sectors_per_cluster);
  67. if (sectors_per_cluster & (sectors_per_cluster - 1)) {
  68. ntfs_log_error("sectors_per_cluster (%d) is not a power of 2."
  69. --- a/ntfsprogs/mkntfs.8.in.ref 2017-03-23 10:42:44.000000000 +0100
  70. +++ b/ntfsprogs/mkntfs.8.in 2018-05-07 09:11:13.014132400 +0200
  71. @@ -132,7 +132,7 @@
  72. .TP
  73. \fB\-c\fR, \fB\-\-cluster\-size\fR BYTES
  74. Specify the size of clusters in bytes. Valid cluster size values are powers of
  75. -two, with at least 256, and at most 65536 bytes per cluster. If omitted,
  76. +two, with at least 256, and at most 2097152 bytes (2MB) per cluster. If omitted,
  77. .B mkntfs
  78. uses 4096 bytes as the default cluster size.
  79. .sp
  80. --- a/ntfsprogs/mkntfs.c.ref 2017-03-23 10:42:44.000000000 +0100
  81. +++ b/ntfsprogs/mkntfs.c 2018-05-07 09:11:13.035522300 +0200
  82. @@ -6,7 +6,7 @@
  83. * Copyright (c) 2002-2006 Szabolcs Szakacsits
  84. * Copyright (c) 2005 Erik Sornes
  85. * Copyright (c) 2007 Yura Pakhuchiy
  86. - * Copyright (c) 2010-2014 Jean-Pierre Andre
  87. + * Copyright (c) 2010-2018 Jean-Pierre Andre
  88. *
  89. * This utility will create an NTFS 1.2 or 3.1 volume on a user
  90. * specified (block) device.
  91. @@ -119,6 +119,7 @@
  92. # endif
  93. #endif
  94. +#include "param.h"
  95. #include "security.h"
  96. #include "types.h"
  97. #include "attrib.h"
  98. @@ -287,7 +288,7 @@
  99. ntfs_log_info("Copyright (c) 2002-2006 Szabolcs Szakacsits\n");
  100. ntfs_log_info("Copyright (c) 2005 Erik Sornes\n");
  101. ntfs_log_info("Copyright (c) 2007 Yura Pakhuchiy\n");
  102. - ntfs_log_info("Copyright (c) 2010-2014 Jean-Pierre Andre\n");
  103. + ntfs_log_info("Copyright (c) 2010-2018 Jean-Pierre Andre\n");
  104. ntfs_log_info("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home);
  105. }
  106. @@ -3719,11 +3720,11 @@
  107. /*
  108. * For huge volumes, grow the cluster size until the number of
  109. * clusters fits into 32 bits or the cluster size exceeds the
  110. - * maximum limit of 64kiB.
  111. + * maximum limit of NTFS_MAX_CLUSTER_SIZE.
  112. */
  113. while (volume_size >> (ffs(vol->cluster_size) - 1 + 32)) {
  114. vol->cluster_size <<= 1;
  115. - if (vol->cluster_size > 65535) {
  116. + if (vol->cluster_size >= NTFS_MAX_CLUSTER_SIZE) {
  117. ntfs_log_error("Device is too large to hold an "
  118. "NTFS volume (maximum size is "
  119. "256TiB).\n");
  120. @@ -3744,15 +3745,18 @@
  121. "to, or larger than, the sector size.\n");
  122. return FALSE;
  123. }
  124. - if (vol->cluster_size > 128 * (u32)opts.sector_size) {
  125. + /* Before Windows 10 Creators, the limit was 128 */
  126. + if (vol->cluster_size > 4096 * (u32)opts.sector_size) {
  127. ntfs_log_error("The cluster size is invalid. It cannot be "
  128. - "more that 128 times the size of the sector "
  129. + "more that 4096 times the size of the sector "
  130. "size.\n");
  131. return FALSE;
  132. }
  133. - if (vol->cluster_size > 65536) {
  134. + if (vol->cluster_size > NTFS_MAX_CLUSTER_SIZE) {
  135. ntfs_log_error("The cluster size is invalid. The maximum "
  136. - "cluster size is 65536 bytes (64kiB).\n");
  137. + "cluster size is %lu bytes (%lukiB).\n",
  138. + (unsigned long)NTFS_MAX_CLUSTER_SIZE,
  139. + (unsigned long)(NTFS_MAX_CLUSTER_SIZE >> 10));
  140. return FALSE;
  141. }
  142. vol->cluster_size_bits = ffs(vol->cluster_size) - 1;
  143. @@ -4387,6 +4391,7 @@
  144. u8 *sd;
  145. FILE_ATTR_FLAGS extend_flags;
  146. VOLUME_FLAGS volume_flags = const_cpu_to_le16(0);
  147. + int sectors_per_cluster;
  148. int nr_sysfiles;
  149. int buf_sds_first_size;
  150. char *buf_sds;
  151. @@ -4639,8 +4644,11 @@
  152. * already inserted, so no need to worry about these things.
  153. */
  154. bs->bpb.bytes_per_sector = cpu_to_le16(opts.sector_size);
  155. - bs->bpb.sectors_per_cluster = (u8)(g_vol->cluster_size /
  156. - opts.sector_size);
  157. + sectors_per_cluster = g_vol->cluster_size / opts.sector_size;
  158. + if (sectors_per_cluster > 128)
  159. + bs->bpb.sectors_per_cluster = 257 - ffs(sectors_per_cluster);
  160. + else
  161. + bs->bpb.sectors_per_cluster = sectors_per_cluster;
  162. bs->bpb.media_type = 0xf8; /* hard disk */
  163. bs->bpb.sectors_per_track = cpu_to_le16(opts.sectors_per_track);
  164. ntfs_log_debug("sectors per track = %ld (0x%lx)\n",
  165. --- a/ntfsprogs/ntfsclone.c.ref 2017-03-23 10:42:44.000000000 +0100
  166. +++ b/ntfsprogs/ntfsclone.c 2018-05-07 09:11:38.245007100 +0200
  167. @@ -3,7 +3,7 @@
  168. *
  169. * Copyright (c) 2003-2006 Szabolcs Szakacsits
  170. * Copyright (c) 2004-2006 Anton Altaparmakov
  171. - * Copyright (c) 2010-2016 Jean-Pierre Andre
  172. + * Copyright (c) 2010-2018 Jean-Pierre Andre
  173. * Special image format support copyright (c) 2004 Per Olofsson
  174. *
  175. * Clone NTFS data and/or metadata to a sparse file, image, device or stdout.
  176. @@ -71,6 +71,7 @@
  177. */
  178. #define NTFS_DO_NOT_CHECK_ENDIANS
  179. +#include "param.h"
  180. #include "debug.h"
  181. #include "types.h"
  182. #include "support.h"
  183. @@ -270,7 +271,6 @@
  184. #define LAST_METADATA_INODE 11
  185. -#define NTFS_MAX_CLUSTER_SIZE 65536
  186. #define NTFS_SECTOR_SIZE 512
  187. #define rounded_up_division(a, b) (((a) + (b - 1)) / (b))
  188. @@ -393,7 +393,7 @@
  189. "Efficiently clone, image, restore or rescue an NTFS Volume.\n\n"
  190. "Copyright (c) 2003-2006 Szabolcs Szakacsits\n"
  191. "Copyright (c) 2004-2006 Anton Altaparmakov\n"
  192. - "Copyright (c) 2010-2016 Jean-Pierre Andre\n\n");
  193. + "Copyright (c) 2010-2018 Jean-Pierre Andre\n\n");
  194. fprintf(stderr, "%s\n%s%s", ntfs_gpl, ntfs_bugs, ntfs_home);
  195. exit(0);
  196. }
  197. @@ -756,7 +756,7 @@
  198. static void copy_cluster(int rescue, u64 rescue_lcn, u64 lcn)
  199. {
  200. - char buff[NTFS_MAX_CLUSTER_SIZE]; /* overflow checked at mount time */
  201. + char *buff;
  202. /* vol is NULL if opt.restore_image is set */
  203. s32 csize = le32_to_cpu(image_hdr.cluster_size);
  204. BOOL backup_bootsector;
  205. @@ -783,6 +783,10 @@
  206. }
  207. }
  208. + buff = (char*)ntfs_malloc(csize);
  209. + if (!buff)
  210. + err_exit("Not enough memory");
  211. +
  212. // need reading when not about to write ?
  213. if (read_all(fd, buff, csize) == -1) {
  214. @@ -858,6 +862,7 @@
  215. perr_printf("Write failed");
  216. #endif
  217. }
  218. + free(buff);
  219. }
  220. static s64 lseek_out(int fd, s64 pos, int mode)
  221. @@ -995,7 +1000,11 @@
  222. struct progress_bar *progress, u64 *p_counter)
  223. {
  224. s64 i;
  225. - char buff[NTFS_MAX_CLUSTER_SIZE];
  226. + char *buff;
  227. +
  228. + buff = (char*)ntfs_malloc(csize);
  229. + if (!buff)
  230. + err_exit("Not enough memory");
  231. memset(buff, 0, csize);
  232. @@ -1004,6 +1013,7 @@
  233. perr_exit("write_all");
  234. progress_update(progress, ++(*p_counter));
  235. }
  236. + free(buff);
  237. }
  238. static void restore_image(void)
  239. @@ -1492,7 +1502,7 @@
  240. static void copy_wipe_mft(ntfs_walk_clusters_ctx *image, runlist *rl)
  241. {
  242. - char buff[NTFS_MAX_CLUSTER_SIZE]; /* overflow checked at mount time */
  243. + char *buff;
  244. void *fd;
  245. s64 mft_no;
  246. u32 mft_record_size;
  247. @@ -1522,6 +1532,10 @@
  248. clusters_per_set = mft_record_size/csize;
  249. records_per_set = 1;
  250. }
  251. + buff = (char*)ntfs_malloc(mft_record_size);
  252. + if (!buff)
  253. + err_exit("Not enough memory");
  254. +
  255. mft_no = 0;
  256. ri = rj = 0;
  257. wi = wj = 0;
  258. @@ -1554,6 +1568,7 @@
  259. }
  260. }
  261. image->current_lcn = current_lcn;
  262. + free(buff);
  263. }
  264. /*
  265. @@ -1566,7 +1581,7 @@
  266. static void copy_wipe_i30(ntfs_walk_clusters_ctx *image, runlist *rl)
  267. {
  268. - char buff[NTFS_MAX_CLUSTER_SIZE]; /* overflow checked at mount time */
  269. + char *buff;
  270. void *fd;
  271. u32 indx_record_size;
  272. u32 csize;
  273. @@ -1595,6 +1610,10 @@
  274. clusters_per_set = indx_record_size/csize;
  275. records_per_set = 1;
  276. }
  277. + buff = (char*)ntfs_malloc(indx_record_size);
  278. + if (!buff)
  279. + err_exit("Not enough memory");
  280. +
  281. ri = rj = 0;
  282. wi = wj = 0;
  283. if (rl[ri].length)
  284. @@ -1627,6 +1646,7 @@
  285. }
  286. }
  287. image->current_lcn = current_lcn;
  288. + free(buff);
  289. }
  290. static void dump_clusters(ntfs_walk_clusters_ctx *image, runlist *rl)
  291. --- a/ntfsprogs/ntfsresize.c.ref 2017-03-23 10:42:44.000000000 +0100
  292. +++ b/ntfsprogs/ntfsresize.c 2018-05-07 09:11:13.076883400 +0200
  293. @@ -59,6 +59,7 @@
  294. #include <fcntl.h>
  295. #endif
  296. +#include "param.h"
  297. #include "debug.h"
  298. #include "types.h"
  299. #include "support.h"
  300. @@ -243,8 +244,6 @@
  301. #define DIRTY_INODE (1)
  302. #define DIRTY_ATTRIB (2)
  303. -#define NTFS_MAX_CLUSTER_SIZE (65536)
  304. -
  305. static s64 rounded_up_division(s64 numer, s64 denom)
  306. {
  307. return (numer + (denom - 1)) / denom;
  308. @@ -404,7 +403,7 @@
  309. printf("Copyright (c) 2002-2005 Anton Altaparmakov\n");
  310. printf("Copyright (c) 2002-2003 Richard Russon\n");
  311. printf("Copyright (c) 2007 Yura Pakhuchiy\n");
  312. - printf("Copyright (c) 2011-2016 Jean-Pierre Andre\n");
  313. + printf("Copyright (c) 2011-2018 Jean-Pierre Andre\n");
  314. printf("\n%s\n%s%s", ntfs_gpl, ntfs_bugs, ntfs_home);
  315. }
  316. @@ -1849,9 +1848,13 @@
  317. static void copy_clusters(ntfs_resize_t *resize, s64 dest, s64 src, s64 len)
  318. {
  319. s64 i;
  320. - char buff[NTFS_MAX_CLUSTER_SIZE]; /* overflow checked at mount time */
  321. + char *buff;
  322. ntfs_volume *vol = resize->vol;
  323. + buff = (char*)ntfs_malloc(vol->cluster_size);
  324. + if (!buff)
  325. + perr_exit("ntfs_malloc");
  326. +
  327. for (i = 0; i < len; i++) {
  328. lseek_to_cluster(vol, src + i);
  329. @@ -1875,6 +1878,7 @@
  330. resize->relocations++;
  331. progress_update(&resize->progress, resize->relocations);
  332. }
  333. + free(buff);
  334. }
  335. static void relocate_clusters(ntfs_resize_t *r, runlist *dest_rl, s64 src_lcn)
  336. --- a/include/ntfs-3g/param.h.ref 2017-03-23 10:42:44.000000000 +0100
  337. +++ b/include/ntfs-3g/param.h 2018-05-07 09:11:13.088302600 +0200
  338. @@ -40,6 +40,13 @@
  339. };
  340. /*
  341. + * Parameters for formatting
  342. + */
  343. +
  344. + /* Up to Windows 10, the cluster size was limited to 64K */
  345. +#define NTFS_MAX_CLUSTER_SIZE 2097152 /* Windows 10 Creators allows 2MB */
  346. +
  347. +/*
  348. * Parameters for compression
  349. */