aefd677.patch 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. diff --git a/src/plugins/fs/generic.c b/src/plugins/fs/generic.c
  2. index 4406d5c..075af7e 100644
  3. --- a/src/plugins/fs/generic.c
  4. +++ b/src/plugins/fs/generic.c
  5. @@ -229,7 +229,7 @@ const BDFSInfo fs_info[BD_FS_LAST_FS] = {
  6. .repair_util = "ntfsfix",
  7. .resize_util = "ntfsresize",
  8. .label_util = "ntfslabel",
  9. - .info_util = "ntfscluster",
  10. + .info_util = "ntfsinfo",
  11. .uuid_util = "ntfslabel" },
  12. /* F2FS */
  13. { .type = "f2fs",
  14. diff --git a/src/plugins/fs/ntfs.c b/src/plugins/fs/ntfs.c
  15. index 517d1cf..1aa503c 100644
  16. --- a/src/plugins/fs/ntfs.c
  17. +++ b/src/plugins/fs/ntfs.c
  18. @@ -20,6 +20,7 @@
  19. #include <blockdev/utils.h>
  20. #include <check_deps.h>
  21. #include <string.h>
  22. +#include <stdio.h>
  23. #include "ntfs.h"
  24. #include "fs.h"
  25. @@ -36,8 +37,8 @@ static GMutex deps_check_lock;
  26. #define DEPS_NTFSRESIZE_MASK (1 << DEPS_NTFSRESIZE)
  27. #define DEPS_NTFSLABEL 3
  28. #define DEPS_NTFSLABEL_MASK (1 << DEPS_NTFSLABEL)
  29. -#define DEPS_NTFSCLUSTER 4
  30. -#define DEPS_NTFSCLUSTER_MASK (1 << DEPS_NTFSCLUSTER)
  31. +#define DEPS_NTFSINFO 4
  32. +#define DEPS_NTFSINFO_MASK (1 << DEPS_NTFSINFO)
  33. #define DEPS_LAST 5
  34. @@ -46,7 +47,7 @@ static const UtilDep deps[DEPS_LAST] = {
  35. {"ntfsfix", NULL, NULL, NULL},
  36. {"ntfsresize", NULL, NULL, NULL},
  37. {"ntfslabel", NULL, NULL, NULL},
  38. - {"ntfscluster", NULL, NULL, NULL},
  39. + {"ntfsinfo", NULL, NULL, NULL},
  40. };
  41. static guint32 fs_mode_util[BD_FS_MODE_LAST+1] = {
  42. @@ -55,7 +56,7 @@ static guint32 fs_mode_util[BD_FS_MODE_LAST+1] = {
  43. DEPS_NTFSFIX_MASK, /* check */
  44. DEPS_NTFSFIX_MASK, /* repair */
  45. DEPS_NTFSLABEL_MASK, /* set-label */
  46. - DEPS_NTFSCLUSTER_MASK, /* query */
  47. + DEPS_NTFSINFO_MASK, /* query */
  48. DEPS_NTFSRESIZE_MASK, /* resize */
  49. DEPS_NTFSLABEL_MASK /* set-uuid */
  50. };
  51. @@ -356,7 +357,7 @@ gboolean bd_fs_ntfs_resize (const gchar *device, guint64 new_size, GError **erro
  52. * Tech category: %BD_FS_TECH_NTFS-%BD_FS_TECH_MODE_QUERY
  53. */
  54. BDFSNtfsInfo* bd_fs_ntfs_get_info (const gchar *device, GError **error) {
  55. - const gchar *args[3] = {"ntfscluster", device, NULL};
  56. + const gchar *args[4] = {"ntfsinfo", "-m", device, NULL};
  57. gboolean success = FALSE;
  58. gchar *output = NULL;
  59. BDFSNtfsInfo *ret = NULL;
  60. @@ -365,8 +366,9 @@ BDFSNtfsInfo* bd_fs_ntfs_get_info (const gchar *device, GError **error) {
  61. gchar *val_start = NULL;
  62. g_autofree gchar* mountpoint = NULL;
  63. GError *l_error = NULL;
  64. + size_t cluster_size = 0;
  65. - if (!check_deps (&avail_deps, DEPS_NTFSCLUSTER_MASK, deps, DEPS_LAST, &deps_check_lock, error))
  66. + if (!check_deps (&avail_deps, DEPS_NTFSINFO_MASK, deps, DEPS_LAST, &deps_check_lock, error))
  67. return NULL;
  68. mountpoint = bd_fs_get_mountpoint (device, &l_error);
  69. @@ -400,8 +402,9 @@ BDFSNtfsInfo* bd_fs_ntfs_get_info (const gchar *device, GError **error) {
  70. lines = g_strsplit (output, "\n", 0);
  71. g_free (output);
  72. line_p = lines;
  73. +
  74. /* find the beginning of the (data) section we are interested in */
  75. - while (line_p && *line_p && !g_str_has_prefix (*line_p, "bytes per volume"))
  76. + while (line_p && *line_p && !strstr (*line_p, "Cluster Size"))
  77. line_p++;
  78. if (!line_p || !(*line_p)) {
  79. g_set_error (error, BD_FS_ERROR, BD_FS_ERROR_PARSE, "Failed to parse NTFS file system information");
  80. @@ -410,12 +413,12 @@ BDFSNtfsInfo* bd_fs_ntfs_get_info (const gchar *device, GError **error) {
  81. return NULL;
  82. }
  83. - /* extract data from something like this: "bytes per volume : 998240256" */
  84. + /* extract data from something like this: "Cluster Size: 4096" */
  85. val_start = strchr (*line_p, ':');
  86. val_start++;
  87. - ret->size = g_ascii_strtoull (val_start, NULL, 0);
  88. + cluster_size = g_ascii_strtoull (val_start, NULL, 0);
  89. - while (line_p && *line_p && !g_str_has_prefix (*line_p, "bytes of free space"))
  90. + while (line_p && *line_p && !strstr (*line_p, "Volume Size in Clusters"))
  91. line_p++;
  92. if (!line_p || !(*line_p)) {
  93. g_set_error (error, BD_FS_ERROR, BD_FS_ERROR_PARSE, "Failed to parse NTFS file system information");
  94. @@ -424,10 +427,27 @@ BDFSNtfsInfo* bd_fs_ntfs_get_info (const gchar *device, GError **error) {
  95. return NULL;
  96. }
  97. - /* extract data from something like this: "bytes of free space : 992759808" */
  98. + /* extract data from something like this: "Volume Size in Clusters: 15314943" */
  99. val_start = strchr (*line_p, ':');
  100. val_start++;
  101. - ret->free_space = g_ascii_strtoull (val_start, NULL, 0);
  102. + ret->size = g_ascii_strtoull (val_start, NULL, 0) * cluster_size;
  103. +
  104. + while (line_p && *line_p && !strstr (*line_p, "Free Clusters"))
  105. + line_p++;
  106. + if (!line_p || !(*line_p)) {
  107. + g_set_error (error, BD_FS_ERROR, BD_FS_ERROR_PARSE, "Failed to parse NTFS file system information");
  108. + g_strfreev (lines);
  109. + bd_fs_ntfs_info_free (ret);
  110. + return NULL;
  111. + }
  112. +
  113. + /* extract data from something like this: "Free Clusters: 7812655 (51,0%)" */
  114. + val_start = strchr (*line_p, ':');
  115. + val_start++;
  116. + ret->free_space = g_ascii_strtoull (val_start, NULL, 0) * cluster_size;
  117. +
  118. + printf("size: %lu\n", ret->size);
  119. + printf("free_space: %lu\n", ret->free_space);
  120. g_strfreev (lines);
  121. diff --git a/tests/fs_tests/ntfs_test.py b/tests/fs_tests/ntfs_test.py
  122. index c04e39d..ff0fc31 100644
  123. --- a/tests/fs_tests/ntfs_test.py
  124. +++ b/tests/fs_tests/ntfs_test.py
  125. @@ -56,9 +56,9 @@ class NTFSTestAvailability(NTFSNoDevTestCase):
  126. with self.assertRaisesRegex(GLib.GError, "The 'ntfsfix' utility is not available"):
  127. BlockDev.fs_is_tech_avail(BlockDev.FSTech.NTFS, BlockDev.FSTechMode.REPAIR)
  128. - # now try without ntfscluster
  129. - with utils.fake_path(all_but="ntfscluster"):
  130. - with self.assertRaisesRegex(GLib.GError, "The 'ntfscluster' utility is not available"):
  131. + # now try without ntfsinfo
  132. + with utils.fake_path(all_but="ntfsinfo"):
  133. + with self.assertRaisesRegex(GLib.GError, "The 'ntfsinfo' utility is not available"):
  134. BlockDev.fs_is_tech_avail(BlockDev.FSTech.NTFS, BlockDev.FSTechMode.QUERY)
  135. # now try without ntfsresize
  136. diff --git a/tests/utils.py b/tests/utils.py
  137. index c498c10..ef21507 100644
  138. --- a/tests/utils.py
  139. +++ b/tests/utils.py
  140. @@ -81,7 +81,7 @@ ALL_UTILS = {"lvm", "btrfs", "mkswap", "swaplabel", "multipath", "mpathconf", "d
  141. "mke2fs", "e2fsck", "tune2fs", "dumpe2fs", "resize2fs",
  142. "mkfs.f2fs", "fsck.f2fs", "fsck.f2fs", "dump.f2fs", "resize.f2fs",
  143. "mkfs.nilfs2", "nilfs-tune", "nilfs-resize",
  144. - "mkntfs", "ntfsfix", "ntfsresize", "ntfslabel", "ntfscluster",
  145. + "mkntfs", "ntfsfix", "ntfsresize", "ntfslabel", "ntfsinfo",
  146. "mkfs.vfat", "fatlabel", "fsck.vfat", "vfat-resize",
  147. "mkfs.xfs", "xfs_db", "xfs_repair", "xfs_admin", "xfs_growfs"}