~hamo/ubuntu/precise/grub2/grub2.hi_res

« back to all changes in this revision

Viewing changes to disk/lvm.c

Tags: upstream-1.98+20100705
ImportĀ upstreamĀ versionĀ 1.98+20100705

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
}
47
47
 
48
48
static int
 
49
grub_lvm_checkvalue (char **p, char *str, char *tmpl)
 
50
{
 
51
  int tmpllen = grub_strlen (tmpl);
 
52
  *p = grub_strstr (*p, str);
 
53
  if (! *p)
 
54
    return 0;
 
55
  *p += grub_strlen (str);
 
56
  if (**p != '"')
 
57
    return 0;
 
58
  return (grub_memcmp (*p + 1, tmpl, tmpllen) == 0 && (*p)[tmpllen + 1] == '"');
 
59
}
 
60
 
 
61
static int
 
62
grub_lvm_check_flag (char *p, char *str, char *flag)
 
63
{
 
64
  int len_str = grub_strlen (str), len_flag = grub_strlen (flag);
 
65
  while (1)
 
66
    {
 
67
      char *q;
 
68
      p = grub_strstr (p, str);
 
69
      if (! p)
 
70
        return 0;
 
71
      p += len_str;
 
72
      if (grub_memcmp (p, " = [", sizeof (" = [") - 1) != 0)
 
73
        continue;
 
74
      q = p + sizeof (" = [") - 1;
 
75
      while (1)
 
76
        {
 
77
          while (grub_isspace (*q))
 
78
            q++;
 
79
          if (*q != '"')
 
80
            return 0;
 
81
          q++;
 
82
          if (grub_memcmp (q, flag, len_flag) == 0 && q[len_flag] == '"')
 
83
            return 1;
 
84
          while (*q != '"')
 
85
            q++;
 
86
          q++;
 
87
          if (*q == ']')
 
88
            return 0;
 
89
          q++;
 
90
        }
 
91
    }
 
92
}
 
93
 
 
94
static int
49
95
grub_lvm_iterate (int (*hook) (const char *name))
50
96
{
51
97
  struct grub_lvm_vg *vg;
421
467
          while (1)
422
468
            {
423
469
              int s;
 
470
              int skip_lv = 0;
424
471
              struct grub_lvm_lv *lv;
425
472
              struct grub_lvm_segment *seg;
426
473
 
445
492
 
446
493
              lv->size = 0;
447
494
 
 
495
              if (!grub_lvm_check_flag (p, "status", "VISIBLE"))
 
496
                {
 
497
                  skip_lv = 1;
 
498
                  goto lv_parsed;
 
499
                }
 
500
 
448
501
              lv->segment_count = grub_lvm_getvalue (&p, "segment_count = ");
449
502
              if (p == NULL)
450
503
                goto lvs_fail;
465
518
                  seg->extent_count = grub_lvm_getvalue (&p, "extent_count = ");
466
519
                  if (p == NULL)
467
520
                    goto lvs_segment_fail;
 
521
 
 
522
                  if (grub_lvm_checkvalue (&p, "type = ", "snapshot"))
 
523
                    {
 
524
                      /* Found a snapshot, give up and move on. */
 
525
                      skip_lv = 1;
 
526
                      break;
 
527
                    }
 
528
 
468
529
                  seg->stripe_count = grub_lvm_getvalue (&p, "stripe_count = ");
469
530
                  if (p == NULL)
470
531
                    goto lvs_segment_fail;
531
592
                  goto fail4;
532
593
                }
533
594
 
 
595
            lv_parsed:
534
596
              if (p != NULL)
535
597
                p = grub_strchr (p, '}');
536
598
              if (p == NULL)
537
599
                goto lvs_fail;
538
600
              p += 3;
539
601
 
 
602
              if (skip_lv)
 
603
                {
 
604
                  grub_free (lv->name);
 
605
                  grub_free (lv);
 
606
                  continue;
 
607
                }
 
608
 
540
609
              lv->number = lv_count++;
541
610
              lv->vg = vg;
542
611
              lv->next = vg->lvs;