On Tue, Oct 20, 2015 at 01:28:23PM +0300, Maxim Perevedentsev wrote:
 On 10/19/2015 07:45 PM, Pino Toscano wrote:
 >On Monday 19 October 2015 17:05:02 Maxim Perevedentsev wrote:
 >
 >>+  const char *size_pattern = "You might resize at ",
 >>+             *full_pattern = "Volume is full",
 >>+             *cluster_size_pattern = "Cluster size",
 >>+             *volume_size_pattern = "Current volume size:";
 >>+  int is_full = 0;
 >>+  int32_t cluster_size = 0;
 >>+
 >>+  /* FS may be marked for check, so force ntfsresize */
 >>+  r = command (&out, &err, str_ntfsresize, "--info",
"-ff", device, NULL);
 >>+
 >>+  lines = split_lines (out);
 >>+  if (lines == NULL)
 >>+    return -1;
 >>+
 >>+  if (verbose) {
 >>+    for (i = 0; lines[i] != NULL; ++i)
 >>+      fprintf (stderr, "ntfs_min_size: lines[%zu] =
\"%s\"\n", i, lines[i]);
 >>+  }
 >>+
 >>+  if (r == -1) {
 >>+    /* If volume is full, ntfsresize returns error. */
 >>+    for (i = 0; lines[i] != NULL; ++i) {
 >>+      if (strstr (lines[i], full_pattern))
 >Better use STRPREFIX here, which is what we use all around libguestfs.
 This is not at the beginning of line.
 >
 >>+        is_full = 1;
 >>+      else if ((p = strstr (lines[i], cluster_size_pattern))) {
 >>+        if (sscanf (p + strlen(cluster_size_pattern),
 >>+                    "%*[ ]:%" SCNd32, &cluster_size) != 1) {
 >>+          reply_with_error("Cannot parse cluster size");
 >>+          return -1;
 >>+        }
 >>+      }
 >>+      else if ((p = strstr (lines[i], volume_size_pattern))) {
 >>+        if (sscanf (p + strlen(volume_size_pattern),
 >>+                    "%" SCNd64, &volume_size) != 1) {
 >>+          reply_with_error("Cannot parse volume size");
 >>+          return -1;
 >>+        }
 >It sounds like these scans of the lines could be done using the
 >analyze_line helper in btrfs.c (which would need to be moved as common
 >code in guestfd.c). This way, the parsing of numbers could use
 >xstrtoul/xstrtoull (see btrfs.c:do_btrfs_subvolume_list) instead of
 >sscanf. 
Although I think sscanf is fine, and certainly easier to use.
Rich.
-- 
Richard Jones, Virtualization Group, Red Hat 
http://people.redhat.com/~rjones
Read my programming and virtualization blog: 
http://rwmj.wordpress.com
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine.  Supports Linux and Windows.
http://people.redhat.com/~rjones/virt-df/