Class: Yast::StorageFieldsClass

Inherits:
Module
  • Object
show all
Defined in:
../../src/modules/StorageFields.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) AlwaysHideDisk(target_map, disk)



1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
# File '../../src/modules/StorageFields.rb', line 1060

def AlwaysHideDisk(target_map, disk)
  target_map = deep_copy(target_map)
  disk = deep_copy(disk)
  real_disk = Storage.IsPartitionable(disk)
  type = Ops.get_symbol(disk, "type", :CT_UNKNOWN)

  return true if type == :CT_DISK && !real_disk

  if !Builtins.contains(
      [:CT_DISK, :CT_DMRAID, :CT_DMMULTIPATH, :CT_MDPART, :CT_LVM],
      type
    )
    return true
  end

  false
end

- (Object) AlwaysHidePartition(target_map, disk, partition)



1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
# File '../../src/modules/StorageFields.rb', line 1079

def AlwaysHidePartition(target_map, disk, partition)
  target_map = deep_copy(target_map)
  disk = deep_copy(disk)
  partition = deep_copy(partition)
  if Ops.get_integer(partition, "fsid", 0) == Partitions.fsid_mac_hidden
    return true
  end

  false
end

- (Object) BooleanToHumanString(value)



83
84
85
86
87
88
89
90
91
# File '../../src/modules/StorageFields.rb', line 83

def BooleanToHumanString(value)
  if value
    # human text for Boolean value
    return _("Yes")
  else
    # human text for Boolean value
    return _("No")
  end
end

- (Object) Helptext(field, style)



215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
# File '../../src/modules/StorageFields.rb', line 215

def Helptext(field, style)
  ret = "<p>"

  case field
    when :bios_id
      # helptext for table column and overview entry
      ret = Ops.add(
        ret,
        _(
          "<b>BIOS ID</b> shows the BIOS ID of the hard\ndisk. This field can be empty."
        )
      )
    when :bus
      # helptext for table column and overview entry
      ret = Ops.add(
        ret,
        _(
          "<b>Bus</b> shows how the device is connected to\nthe system. This field can be empty, e.g. for multipath disks."
        )
      )
    when :chunk_size
      # helptext for table column and overview entry
      ret = Ops.add(
        ret,
        _("<b>Chunk Size</b> shows the chunk size for RAID\ndevices.")
      )
    when :cyl_size
      # helptext for table column and overview entry
      ret = Ops.add(
        ret,
        _(
          "<b>Cylinder Size</b> shows the size of the\ncylinders of the hard disk."
        )
      )
    when :sector_size
      # helptext for table column and overview entry
      ret = Ops.add(
        ret,
        _(
          "<b>Sector Size</b> shows the size of the\nsectors of the hard disk."
        )
      )
    when :device
      # helptext for table column and overview entry
      ret = Ops.add(
        ret,
        _("<b>Device</b> shows the kernel name of the\ndevice.")
      )
    when :disk_label
      # helptext for table column and overview entry
      ret = Ops.add(
        ret,
        _(
          "<b>Disk Label</b> shows the partition table\ntype of the disk, e.g <tt>MSDOS</tt> or <tt>GPT</tt>."
        )
      )
    when :encrypted
      # helptext for table column and overview entry
      ret = Ops.add(
        ret,
        _("<b>Encrypted</b> shows whether the device is\nencrypted.")
      )
    when :end_cyl
      # helptext for table column and overview entry
      ret = Ops.add(
        ret,
        _("<b>End Cylinder</b> shows the end cylinder of\nthe partition.")
      )
    when :fc_fcp_lun
      # helptext for table column and overview entry
      ret = Ops.add(
        ret,
        _(
          "<b>LUN</b> shows the Logical Unit Number for\nFibre Channel disks."
        )
      )
    when :fc_port_id
      # helptext for table column and overview entry
      ret = Ops.add(
        ret,
        _("<b>Port ID</b> shows the port id for Fibre\nChannel disks.")
      )
    when :fc_wwpn
      # helptext for table column and overview entry
      ret = Ops.add(
        ret,
        _(
          "<b>WWPN</b> shows the World Wide Port Name for\nFibre Channel disks."
        )
      )
    when :file_path
      # helptext for table column and overview entry
      ret = Ops.add(
        ret,
        _(
          "<b>File Path</b> shows the path of the file for\nan encrypted loop device."
        )
      )
    when :format
      # helptext for table column and overview entry
      ret = Ops.add(
        ret,
        _(
          "<b>Format</b> shows some flags: <tt>F</tt>\nmeans the device is selected to be formatted."
        )
      )
    when :fs_id
      # helptext for table column and overview entry
      ret = Ops.add(ret, _("<b>FS ID</b> shows the file system id."))
    when :fs_type
      # helptext for table column and overview entry
      ret = Ops.add(ret, _("<b>FS Type</b> shows the file system type."))
    when :label
      # helptext for table column and overview entry
      ret = Ops.add(
        ret,
        _("<b>Label</b> shows the label of the file\nsystem.")
      )
    when :lvm_metadata
      # helptext for table column and overview entry
      ret = Ops.add(
        ret,
        _("<b>Metadata</b> shows the LVM metadata type for\nvolume groups.")
      )
    when :model
      # helptext for table column and overview entry
      ret = Ops.add(ret, _("<b>Model</b> shows the device model."))
    when :mount_by
      # helptext for table column and overview entry
      ret = Ops.add(
        ret,
        _(
          "<b>Mount by</b> indicates how the file system\n" +
            "is mounted: (Kernel) by kernel name, (Label) by file system label, (UUID) by\n" +
            "file system UUID, (ID) by device ID, and (Path) by device path.\n"
        )
      )
      if Mode.normal
        # helptext for table column and overview entry
        ret = Ops.add(
          Ops.add(ret, " "),
          _(
            "A question mark (?) indicates that\n" +
              "the file system is not listed in <tt>/etc/fstab</tt>. It is either mounted\n" +
              "manually or by some automount system. When changing settings for this volume\n" +
              "YaST will not update <tt>/etc/fstab</tt>.\n"
          )
        )
      end
    when :mount_point
      # helptext for table column and overview entry
      ret = Ops.add(
        ret,
        _("<b>Mount Point</b> shows where the file system\nis mounted.")
      )
      if Mode.normal
        # helptext for table column and overview entry
        ret = Ops.add(
          Ops.add(ret, " "),
          _(
            "An asterisk (*) after the mount point\n" +
              "indicates a file system that is currently not mounted (for example, because it\n" +
              "has the <tt>noauto</tt> option set in <tt>/etc/fstab</tt>)."
          )
        )
      end
    when :num_cyl
      # helptext for table column and overview entry
      ret = Ops.add(
        ret,
        _(
          "<b>Number of Cylinders</b> shows how many\ncylinders the hard disk has."
        )
      )
    when :parity_algorithm
      # helptext for table column and overview entry
      ret = Ops.add(
        ret,
        _(
          "<b>Parity Algorithm</b> shows the parity\nalgorithm for RAID devices with RAID type 5, 6 or 10."
        )
      )
    when :pe_size
      # helptext for table column and overview entry
      ret = Ops.add(
        ret,
        _(
          "<b>PE Size</b> shows the physical extent size\nfor LVM volume groups."
        )
      )
    when :raid_version
      # helptext for table column and overview entry
      ret = Ops.add(ret, _("<b>RAID Version</b> shows the RAID version."))
    when :raid_type
      # helptext for table column and overview entry
      ret = Ops.add(
        ret,
        _(
          "<b>RAID Type</b> shows the RAID type, also\ncalled RAID level, for RAID devices."
        )
      )
    when :size
      # helptext for table column and overview entry
      ret = Ops.add(ret, _("<b>Size</b> shows the size of the device."))
    when :start_cyl
      # helptext for table column and overview entry
      ret = Ops.add(
        ret,
        _(
          "<b>Start Cylinder</b> shows the start cylinder\nof the partition."
        )
      )
    when :stripes
      # helptext for table column and overview entry
      ret = Ops.add(
        ret,
        _(
          "<b>Stripes</b> shows the stripe number for LVM\nlogical volumes and, if greater than one, the stripe size  in parenthesis.\n"
        )
      )
    when :type
      # helptext for table column and overview entry
      ret = Ops.add(
        ret,
        _("<b>Type</b> gives a general overview about the\ndevice type.")
      )
    when :udev_id
      # helptext for table column and overview entry
      ret = Ops.add(
        ret,
        _(
          "<b>Device ID</b> shows the persistent device\nIDs. This field can be empty.\n"
        )
      )
    when :udev_path
      # helptext for table column and overview entry
      ret = Ops.add(
        ret,
        _(
          "<b>Device Path</b> shows the persistent device\npath. This field can be empty."
        )
      )
    when :used_by
      # helptext for table column and overview entry
      ret = Ops.add(
        ret,
        _(
          "<b>Used By</b> shows if a device is used by\ne.g. RAID or LVM. If not, this column is empty.\n"
        )
      )
    when :uuid
      # helptext for table column and overview entry
      ret = Ops.add(
        ret,
        _(
          "<b>UUID</b> shows the Universally Unique\nIdentifier of the file system."
        )
      )
    when :vendor
      # helptext for table column and overview entry
      ret = Ops.add(ret, _("<b>Vendor</b> shows the device vendor."))
    else
      Builtins.y2error("unknown field %1", field)
      ret = Ops.add(ret, "error")
  end

  ret = Ops.add(ret, "</p>")

  ret
end

- (Object) IterateTargetMap(target_map, callback)

Call callback for every disk of target_map in a well defined sorted order.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File '../../src/modules/StorageFields.rb', line 51

def IterateTargetMap(target_map, callback)

  disk_order = {
    :CT_DMRAID      => 0,
    :CT_DMMULTIPATH => 1,
    :CT_MDPART      => 2,
    :CT_DISK        => 3,
    :CT_MD          => 4,
    :CT_LOOP        => 5,
    :CT_LVM         => 6,
    :CT_DM          => 7,
    :CT_NFS         => 8,
    :CT_BTRFS       => 9,
    :CT_TMPFS       => 10
  }

  keys = target_map.keys()

  keys.sort! do |a, b|
    oa = disk_order.fetch(target_map.fetch(a).fetch("type", :CT_UNKNOWN))
    ob = disk_order.fetch(target_map.fetch(b).fetch("type", :CT_UNKNOWN))
    oa == ob ? a <=> b : oa <=> ob
  end

  keys.each do |dev|
    disk = target_map.fetch(dev)
    callback.call(target_map, disk)
  end

end

- (Object) main



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File '../../src/modules/StorageFields.rb', line 30

def main
  Yast.import "UI"


  textdomain "storage"


  Yast.import "Storage"
  Yast.import "StorageIcons"
  Yast.import "FileSystems"
  Yast.import "Partitions"
  Yast.import "Directory"
  Yast.import "Mode"
  Yast.import "HTML"
  Yast.import "Integer"
  Yast.import "String"
  Yast.import "Region"
end

- (Object) MakeSubInfo(disk, part, field, style)



487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
# File '../../src/modules/StorageFields.rb', line 487

def MakeSubInfo(disk, part, field, style)
  disk = deep_copy(disk)
  part = deep_copy(part)
  data = part == nil ? disk : part
  type = part == nil ?
    Ops.get_symbol(disk, "type", :primary) :
    Ops.get_symbol(part, "type", :CT_DISK)

  device = Ops.get_string(data, "device", "")

  case field
    when :device
      value = device
      if style == :table
        return value
      else
        # row label, %1 is replace by device name
        return Builtins.sformat(_("Device: %1"), String.EscapeTags(value))
      end
    when :size
      value = Storage.KByteToHumanString(Ops.get_integer(data, "size_k", 0))
      if style == :table
        return value
      else
        # row label, %1 is replace by size
        return Builtins.sformat(_("Size: %1"), value)
      end
    when :type
      value = ""

      if part == nil
        disk_device = Ops.get_string(disk, "device", "")
        vendor = Ops.get_string(disk, "vendor", "")
        model = Ops.get_string(disk, "model", "")

        if model != "" && vendor != ""
          value = Ops.add(Ops.add(vendor, "-"), model)
        else
          value = Ops.add(vendor, model)
        end

        if value == ""
          if Ops.get_string(disk, "bus", "") == "RAID"
            value = Ops.add("RAID ", disk_device)
          elsif Ops.get_symbol(disk, "type", :CT_UNKNOWN) == :CT_LVM
            value = Ops.add(
              "LVM" + (Ops.get_boolean(disk, "lvm2", false) ? "2 " : " "),
              Ops.get_string(disk, "name", "")
            )
          elsif Ops.get_symbol(disk, "type", :CT_UNKNOWN) == :CT_DMRAID
            value = Ops.add("DM RAID ", Ops.get_string(disk, "name", ""))
          elsif Ops.get_symbol(disk, "type", :CT_UNKNOWN) == :CT_DMMULTIPATH
            value = Ops.add(
              "DM Multipath ",
              Ops.get_string(disk, "name", "")
            )
          elsif Ops.get_symbol(disk, "type", :CT_UNKNOWN) == :CT_MDPART
            value = Ops.add("MD RAID ", Ops.get_string(disk, "name", ""))
          else
            # label text
            vendor = Builtins.sformat(
              _("DISK %1"),
              Builtins.substring(disk_device, 5)
            )
          end
        end
      else
        value = Ops.get_string(part, "fstype", "")
      end
      if style == :table
        return term(
          :cell,
          term(
            :icon,
            Ops.add(
              Ops.add(Directory.icondir, "22x22/apps/"),
              StorageIcons.IconMap(type)
            )
          ),
          value
        )
      else
        # row label
        return Builtins.sformat(_("Type: %1"), String.EscapeTags(value))
      end
    when :format
      value = ""
      if part == nil
        if Ops.get_boolean(disk, "dasdfmt", false)
          value = Ops.add(value, "X")
        end
      else
        if Ops.get_boolean(part, "format", false)
          value = Ops.add(value, "F")
        end
      end
      if style == :table
        return value
      else
        # row label
        return Builtins.sformat(_("Format: %1"), value)
      end
    when :encrypted
      value = Ops.get_symbol(data, "enc_type", :none) != :none
      if style == :table
        if value
          if Ops.get_boolean(UI.GetDisplayInfo, "HasIconSupport", false)
            return term(
              :cell,
              term(
                :icon,
                Ops.add(
                  Ops.add(Directory.icondir, "22x22/apps/"),
                  StorageIcons.encrypted_icon
                )
              ),
              ""
            )
          else
            return "E"
          end
        else
          return ""
        end
      else
        # row label, %1 is replace by "Yes" or "No"
        return Builtins.sformat(
          _("Encrypted: %1"),
          BooleanToHumanString(value)
        )
      end
    when :fs_type
      value = FileSystems.GetName(
        Ops.get_symbol(data, "used_fs", :unknown),
        ""
      )
      if style == :table
        return value
      else
        # row label, %1 is replace by file system name e.g. "Ext3"
        return Builtins.sformat(_("File System: %1"), value)
      end
    when :mount_point
      value = Ops.get_string(data, "mount", "")

      if Mode.normal
        if Ops.get_boolean(data, "inactive", false)
          value = Ops.add(value, " *")
        end
      end

      if style == :table
        return value
      else
        # row label, %1 is replace by mount point e.g. "/mnt"
        return Builtins.sformat(
          _("Mount Point: %1"),
          String.EscapeTags(value)
        )
      end
    when :mount_by
      value = ""

      if Ops.get_string(data, "mount", "") != ""
        tmp = {
          :device => "Kernel",
          :uuid   => "UUID",
          :label  => "Label",
          :id     => "ID",
          :path   => "Path"
        }
        mount_by = Ops.get_symbol(data, "mountby", :device)
        value = Ops.get_string(tmp, mount_by, "")
      end

      if Mode.normal
        tmp = false
        if (
            tmp_ref = arg_ref(tmp);
            _GetIgnoreFstab_result = Storage.GetIgnoreFstab(device, tmp_ref);
            tmp = tmp_ref.value;
            _GetIgnoreFstab_result
          ) && tmp
          value = "?"
        end
      end

      if style == :table
        return value
      else
        # row label, %1 is replace by mount by method
        return Builtins.sformat(_("Mount by: %1"), value)
      end
    when :used_by
      if style == :table
        return UsedByString(Ops.get_map(data, ["used_by", 0], {}))
      else
        n = Builtins.size(Ops.get_list(data, "used_by", []))
        return Builtins.mergestring(
          Builtins.maplist(Integer.Range(n == 0 ? 1 : n)) do |i|
            Builtins.sformat(
              _("Used by %1: %2"),
              Ops.add(i, 1),
              String.EscapeTags(
                UsedByString(Ops.get_map(data, ["used_by", i], {}))
              )
            )
          end,
          HTML.Newline
        )
      end
    when :uuid
      value = Ops.get_string(data, "uuid", "")
      if style == :table
        return value
      else
        # row label, %1 is replace by file system uuid
        return Builtins.sformat(_("UUID: %1"), value)
      end
    when :label
      value = part == nil ? "" : Ops.get_string(data, "label", "")
      if style == :table
        return value
      else
        # row label, %1 is replace by file system label
        return Builtins.sformat(_("Label: %1"), String.EscapeTags(value))
      end
    when :udev_path
      value = Ops.get_string(data, "udev_path", "")
      if style == :table
        return value
      else
        # row label, %1 is replace by udev device path
        return Builtins.sformat(_("Device Path: %1"), value)
      end
    when :udev_id
      if style == :table
        return Ops.get_string(data, ["udev_id", 0], "")
      else
        n = Builtins.size(Ops.get_list(data, "udev_id", []))
        return Builtins.mergestring(
          Builtins.maplist(Integer.Range(n == 0 ? 1 : n)) do |i|
            Builtins.sformat(
              _("Device ID %1: %2"),
              Ops.add(i, 1),
              Ops.get_string(data, ["udev_id", i], "")
            )
          end,
          HTML.Newline
        )
      end
    when :bios_id
      value = Ops.get_string(data, "bios_id", "")
      if style == :table
        return value
      else
        # row label, %1 is replace by bios id
        return Builtins.sformat(_("BIOS ID: %1"), value)
      end
    when :disk_label
      value = part == nil ?
        Builtins.toupper(Ops.get_string(data, "label", "")) :
        ""
      if style == :table
        return value
      else
        # row label, %1 is replace by disk label e.g. "MSDOS" or "GPT"
        return Builtins.sformat(_("Disk Label: %1"), value)
      end
    when :vendor
      value = Ops.get_string(data, "vendor", "")
      if style == :table
        return value
      else
        # row label, %1 is replace by vendor name
        return Builtins.sformat(_("Vendor: %1"), String.EscapeTags(value))
      end
    when :model
      value = Ops.get_string(data, "model", "")
      if style == :table
        return value
      else
        # row label, %1 is replace by model string
        return Builtins.sformat(_("Model: %1"), String.EscapeTags(value))
      end
    when :bus
      names = {
        :sbp   => "Firewire",
        :ata   => "ATA",
        :fc    => "Fibre Channel",
        :iscsi => "iSCSI",
        :sas   => "SAS",
        :sata  => "SATA",
        :spi   => "SCSI",
        :usb   => "USB",
        :fcoe  => "FCoE"
      }
      value = Ops.get(
        names,
        Ops.get_symbol(data, "transport", :unknown),
        ""
      )
      if style == :table
        return value
      else
        # row label, %1 is replace by bus name e.g. "SCSI"
        return Builtins.sformat(_("Bus: %1"), value)
      end
    when :lvm_metadata
      value = ""
      if Ops.get_symbol(disk, "type", :CT_UNKNOWN) == :CT_LVM && part == nil
        value = Ops.get_boolean(disk, "lvm2", true) ? "LVM2" : "LVM1"
      end
      if style == :table
        return value
      else
        # row label, %1 is replace by metadata version string
        return Builtins.sformat(_("Metadata: %1"), value)
      end
    when :pe_size
      value = ""
      if Ops.get_symbol(disk, "type", :CT_UNKNOWN) == :CT_LVM && part == nil
        value = Storage.ByteToHumanStringOmitZeroes(
          Ops.get_integer(disk, "pesize", 0)
        )
      end
      if style == :table
        return value
      else
        # row label, %1 is replace by size
        return Builtins.sformat(_("PE Size: %1"), value)
      end
    when :stripes
      value = ""
      if Ops.get_symbol(disk, "type", :CT_UNKNOWN) == :CT_LVM && part != nil
        stripes = Ops.get_integer(data, "stripes", 1)
        stripesize = Ops.get_integer(data, "stripesize", 0)
        if stripes == 1
          value = Builtins.sformat("%1", stripes)
        else
          value = Builtins.sformat(
            "%1 (%2)",
            stripes,
            Storage.KByteToHumanStringOmitZeroes(stripesize)
          )
        end
      end
      if style == :table
        return value
      else
        # row label, %1 is replace by integer
        return Builtins.sformat(_("Stripes: %1"), value)
      end
    when :raid_version
      value = Ops.get_string(data, "sb_ver", "")
      if style == :table
        return value
      else
        # row label, %1 is replace by raid version e.g. "1.00"
        return Builtins.sformat(_("RAID Version: %1"), value)
      end
    when :raid_type
      value = Builtins.toupper(Ops.get_string(data, "raid_type", ""))
      if style == :table
        return value
      else
        # row label, %1 is replace by raid type e.g. "RAID1"
        return Builtins.sformat(_("RAID Type: %1"), value)
      end
    when :chunk_size
      value = ""
      if Ops.get_string(data, "raid_type", "") == "raid0" ||
          Storage.HasRaidParity(Ops.get_string(data, "raid_type", ""))
        chunksize = Ops.get_integer(data, "chunk_size", 0)
        value = Storage.KByteToHumanStringOmitZeroes(chunksize)
      end
      if style == :table
        return value
      else
        # row label, %1 is replace by size
        return Builtins.sformat(_("Chunk Size: %1"), value)
      end
    when :parity_algorithm
      value = ""
      if Storage.HasRaidParity(Ops.get_string(data, "raid_type", ""))
        value = Ops.get_string(data, "parity_algorithm", "")
        value = Builtins.mergestring(Builtins.splitstring(value, "_"), "-")
      end
      if style == :table
        return value
      else
        # row label, %1 is replace by algorithm name
        return Builtins.sformat(_("Parity Algorithm: %1"), value)
      end
    when :num_cyl
      value = ""
      if part == nil && Storage.IsPartitionable(disk)
        value = Builtins.tostring(Ops.get_integer(disk, "cyl_count", 0))
      end
      if style == :table
        return value
      else
        # row label, %1 is replace by integer
        return Builtins.sformat(_("Number of Cylinders: %1"), value)
      end
    when :cyl_size
      value = ""
      if part == nil && Storage.IsPartitionable(disk)
        value = Storage.ByteToHumanString(
          Ops.get_integer(disk, "cyl_size", 0)
        )
      end
      if style == :table
        return value
      else
        # row label, %1 is replace by size
        return Builtins.sformat(_("Cylinder Size: %1"), value)
      end
    when :start_cyl
      value = ""
      if Storage.IsPartitionable(disk)
        if part == nil
          value = Builtins.tostring(0)
        else
          value = Builtins.tostring(
            Region.Start(Ops.get_list(part, "region", []))
          )
        end
      end
      if style == :table
        return value
      else
        # row label, %1 is replace by integer
        return Builtins.sformat(_("Start Cylinder: %1"), value)
      end
    when :end_cyl
      value = ""
      if Storage.IsPartitionable(disk)
        if part == nil
          value = Builtins.tostring(
            Ops.subtract(Ops.get_integer(disk, "cyl_count", 0), 1)
          )
        else
          value = Builtins.tostring(
            Region.End(Ops.get_list(part, "region", []))
          )
        end
      end
      if style == :table
        return value
      else
        # row label, %1 is replace by integer
        return Builtins.sformat(_("End Cylinder: %1"), value)
      end
    when :sector_size
      value = ""
      if part == nil && Storage.IsPartitionable(disk)
        value = Storage.ByteToHumanStringOmitZeroes(
          Ops.get_integer(disk, "sector_size", 0)
        )
      end
      if style == :table
        return value
      else
        # row label, %1 is replace by size
        return Builtins.sformat(_("Sector Size: %1"), value)
      end
    when :fs_id
      fs_id = Ops.get_integer(data, "fsid", 0)
      value = Ops.add(
        Ops.add(Partitions.ToHexString(fs_id), " "),
        Partitions.FsIdToString(fs_id)
      )
      if style == :table
        return value
      else
        # row label, %1 is replace by file system id
        return Builtins.sformat(_("FS ID: %1"), value)
      end
    when :file_path
      value = Ops.get_string(data, "fpath", "")
      if style == :table
        return value
      else
        # row label, %1 is replace by file path e.g. "/data/secret"
        return Builtins.sformat(
          _("File Path: %1"),
          String.EscapeTags(value)
        )
      end
    when :fc_wwpn
      value = ""
      if Builtins.haskey(Ops.get_map(data, "fc", {}), "wwpn")
        value = Ops.add(
          "0x",
          Builtins.toupper(
            Builtins.substring(
              Builtins.tohexstring(
                Ops.get_integer(data, ["fc", "wwpn"], 0),
                16
              ),
              2
            )
          )
        )
      end
      if style == :table
        return value
      else
        # row label, %1 is replace by wwpn
        return Builtins.sformat(_("WWPN: %1"), value)
      end
    when :fc_fcp_lun
      value = ""
      if Builtins.haskey(Ops.get_map(data, "fc", {}), "fcp_lun")
        value = Builtins.tostring(
          Ops.get_integer(data, ["fc", "fcp_lun"], 0)
        )
      end
      if style == :table
        return value
      else
        # row label, %1 is replace by lun
        return Builtins.sformat(_("LUN: %1"), value)
      end
    when :fc_port_id
      value = ""
      if Builtins.haskey(Ops.get_map(data, "fc", {}), "port_id")
        value = Ops.add(
          "0x",
          Builtins.toupper(
            Builtins.substring(
              Builtins.tohexstring(
                Ops.get_integer(data, ["fc", "port_id"], 0),
                6
              ),
              2
            )
          )
        )
      end
      if style == :table
        return value
      else
        # row label, %1 is replace by port id
        return Builtins.sformat(_("Port ID: %1"), value)
      end
    else
      Builtins.y2error("unknown field %1", field)
      return "error"
  end
end

- (Object) Overview(fields, target_map, device)



1399
1400
1401
1402
1403
1404
1405
# File '../../src/modules/StorageFields.rb', line 1399

def Overview(fields, target_map, device)
  fields = deep_copy(fields)
  target_map = deep_copy(target_map)
  contents = OverviewContents(fields, target_map, device)

  RichText(Id(:text), Opt(:hstretch, :vstretch), contents)
end

- (Object) OverviewContents(fields, target_map, device)

The device must be the device entry in the target-map, e.g. “/dev/sda1”, not something like “LABEL=test”.



1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
# File '../../src/modules/StorageFields.rb', line 1316

def OverviewContents(fields, target_map, device)
  fields = deep_copy(fields)
  target_map = deep_copy(target_map)
  disk = Ops.get(target_map, device)
  part = nil

  Builtins.foreach(target_map) do |s, d|
    part = Builtins.find(Ops.get_list(d, "partitions", [])) do |p|
      Ops.get_string(p, "device", "") == device
    end
    if part != nil
      disk = deep_copy(d)
      raise Break
    end
  end if disk == nil

  splitfields = lambda do |fields2|
    fields2 = deep_copy(fields2)
    ret = []

    tmp = []
    Builtins.foreach(fields2) do |field|
      if Builtins.substring(Builtins.tostring(field), 0, 8) == "`heading"
        if Ops.greater_than(Builtins.size(tmp), 1)
          ret = Builtins.add(ret, tmp)
        end
        tmp = [field]
      else
        tmp = Builtins.add(tmp, field)
      end
    end
    ret = Builtins.add(ret, tmp) if Ops.greater_than(Builtins.size(tmp), 1)

    deep_copy(ret)
  end

  _Heading = lambda do |field|
    case field
      when :heading_device
        # heading
        return _("Device:")
      when :heading_filesystem
        # heading
        return _("File System:")
      when :heading_hd
        # heading
        return _("Hard Disk:")
      when :heading_fc
        # heading
        return _("Fibre Channel:")
      when :heading_lvm
        # heading
        return _("LVM:")
      when :heading_md
        # heading
        return _("RAID:")
      else
        Builtins.y2error("unknown field %1", field)
        return "error"
    end
  end

  _List = lambda do |fields2|
    fields2 = deep_copy(fields2)
    Builtins.maplist(fields2) do |field|
      Convert.to_string(MakeSubInfo(disk, part, field, :overview))
    end
  end

  content = Builtins.mergestring(
    Builtins.maplist(splitfields.call(fields)) do |subfields|
      Ops.add(
        HTML.Heading(_Heading.call(Ops.get(subfields, 0, :none))),
        HTML.List(_List.call(Builtins.sublist(subfields, 1)))
      )
    end,
    ""
  )

  content
end

- (Object) OverviewHelptext(fields)



1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
# File '../../src/modules/StorageFields.rb', line 1408

def OverviewHelptext(fields)
  fields = deep_copy(fields)
  fields = Builtins.filter(fields) do |field|
    Builtins.substring(Builtins.tostring(field), 0, 8) != "`heading"
  end

  initial = _("<p>The overview contains:</p>")

  helptext = Builtins::List.reduce(initial, fields) do |tmp, field|
    Ops.add(tmp, Helptext(field, :overview))
  end

  helptext
end

- (Object) PredicateAll(disk, partition)

Predicate function for Table and TableContents.



1092
1093
1094
1095
1096
# File '../../src/modules/StorageFields.rb', line 1092

def PredicateAll(disk, partition)
  disk = deep_copy(disk)
  partition = deep_copy(partition)
  :showandfollow
end

- (Object) PredicateBtrfs(disk, partition)

Predicate function for Table and TableContents.



1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
# File '../../src/modules/StorageFields.rb', line 1202

def PredicateBtrfs(disk, partition)
  disk = deep_copy(disk)
  partition = deep_copy(partition)
  if partition == nil
    return :follow
  else
    if Ops.get_symbol(partition, "used_fs", :unknown) == :btrfs &&
        !Storage.IsUsedBy(partition) &&
        (Ops.get_symbol(partition, ["used_by", 0, "type"], :UB_NONE) == :UB_BTRFS ||
          Builtins.search(Ops.get_string(partition, "device", ""), "UUID=") == 0)
      return :show
    else
      return :ignore
    end
  end
end

- (Object) PredicateDevice(disk, partition, devices)

Predicate function for Table and TableContents.



1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
# File '../../src/modules/StorageFields.rb', line 1137

def PredicateDevice(disk, partition, devices)
  disk = deep_copy(disk)
  partition = deep_copy(partition)
  devices = deep_copy(devices)
  if partition == nil
    if Builtins.contains(devices, Ops.get_string(disk, "device", ""))
      return :showandfollow
    else
      return :follow
    end
  else
    if Builtins.contains(devices, Ops.get_string(partition, "device", ""))
      return :show
    else
      return :ignore
    end
  end
end

- (Object) PredicateDiskDevice(disk, partition, disk_devices)

Predicate function for Table and TableContents.



1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
# File '../../src/modules/StorageFields.rb', line 1120

def PredicateDiskDevice(disk, partition, disk_devices)
  disk = deep_copy(disk)
  partition = deep_copy(partition)
  disk_devices = deep_copy(disk_devices)
  if partition == nil
    if Builtins.contains(disk_devices, Ops.get_string(disk, "device", ""))
      return :follow
    else
      return :ignore
    end
  else
    return :show
  end
end

- (Object) PredicateDiskType(disk, partition, disk_types)

Predicate function for Table and TableContents.



1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
# File '../../src/modules/StorageFields.rb', line 1100

def PredicateDiskType(disk, partition, disk_types)
  disk = deep_copy(disk)
  partition = deep_copy(partition)
  disk_types = deep_copy(disk_types)
  if partition == nil
    if Builtins.contains(
        disk_types,
        Ops.get_symbol(disk, "type", :CT_UNKNOWN)
      )
      return :showandfollow
    else
      return :ignore
    end
  else
    return :show
  end
end

- (Object) PredicateMountpoint(disk, partition)

Predicate function for Table and TableContents.



1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
# File '../../src/modules/StorageFields.rb', line 1183

def PredicateMountpoint(disk, partition)
  disk = deep_copy(disk)
  partition = deep_copy(partition)
  if partition == nil
    if !Builtins.isempty(Ops.get_string(disk, "mount", ""))
      return :showandfollow
    else
      return :follow
    end
  else
    if !Builtins.isempty(Ops.get_string(partition, "mount", ""))
      return :show
    else
      return :ignore
    end
  end
end

- (Object) PredicateTmpfs(disk, partition)

Predicate function for Table and TableContents.



1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
# File '../../src/modules/StorageFields.rb', line 1220

def PredicateTmpfs(disk, partition)
  disk = deep_copy(disk)
  partition = deep_copy(partition)
  if partition == nil
    return :follow
  else
    if Ops.get_symbol(partition, "used_fs", :unknown) == :tmpfs
      return :show
    else
      return :ignore
    end
  end
end

- (Object) PredicateUsedByDevice(disk, partition, devices)

Predicate function for Table and TableContents.



1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
# File '../../src/modules/StorageFields.rb', line 1158

def PredicateUsedByDevice(disk, partition, devices)
  disk = deep_copy(disk)
  partition = deep_copy(partition)
  devices = deep_copy(devices)
  if partition == nil
    if Builtins.find(Ops.get_list(disk, "used_by", [])) do |used_by|
        Builtins.contains(devices, Ops.get_string(used_by, "device", ""))
      end != nil
      return :showandfollow
    else
      return :follow
    end
  else
    if Builtins.find(Ops.get_list(partition, "used_by", [])) do |used_by|
        Builtins.contains(devices, Ops.get_string(used_by, "device", ""))
      end != nil
      return :show
    else
      return :ignore
    end
  end
end

- (Object) Table(fields, target_map, predicate)



1287
1288
1289
1290
1291
1292
1293
1294
1295
# File '../../src/modules/StorageFields.rb', line 1287

def Table(fields, target_map, predicate)
  fields = deep_copy(fields)
  target_map = deep_copy(target_map)
  predicate = deep_copy(predicate)
  header = TableHeader(fields)
  content = TableContents(fields, target_map, predicate)

  term(:Table, Opt(:keepSorting), header, content)
end

- (Object) TableContents(fields, target_map, predicate)

The predicate function determines whether the disk/partition is included. The predicate function takes two arguments, disk and partition. For disks predicate is called with the partitions set to nil.

Possible return values for predicate: show,follow, showandfollow,ignore



1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
# File '../../src/modules/StorageFields.rb', line 1244

def TableContents(fields, target_map, predicate)
  fields = deep_copy(fields)
  target_map = deep_copy(target_map)
  predicate = deep_copy(predicate)
  contents = []

  callback = lambda do |target_map2, disk|
    target_map2 = deep_copy(target_map2)
    disk = deep_copy(disk)
    disk_predicate = predicate.call(disk, nil)

    if !AlwaysHideDisk(target_map2, disk) &&
        Builtins.contains([:show, :showandfollow], disk_predicate)
      row = TableRow(fields, disk, nil)
      contents = Builtins.add(contents, row)
    end

    if Builtins.contains([:follow, :showandfollow], disk_predicate)
      partitions = Ops.get_list(disk, "partitions", [])

      Builtins.foreach(partitions) do |partition|
        part_predicate = predicate.call(disk, partition)
        if !AlwaysHidePartition(target_map2, disk, partition) &&
            Builtins.contains([:show, :showandfollow], part_predicate)
          row = TableRow(fields, disk, partition)
          contents = Builtins.add(contents, row)
        end
      end
    end

    nil
  end

  IterateTargetMap(
    target_map,
    fun_ref(callback, "void (map <string, map>, map)")
  )

  deep_copy(contents)
end

- (Object) TableHeader(fields)



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File '../../src/modules/StorageFields.rb', line 118

def TableHeader(fields)
  fields = deep_copy(fields)
  header = Header()

  Builtins.foreach(fields) do |field|
    case field
      when :device
        # Column header
        header = Builtins.add(header, _("Device"))
      when :size
        # Column header
        header = Builtins.add(header, Right(_("Size")))
      when :type
        # Column header
        header = Builtins.add(header, _("Type"))
      when :format
        # Column header, abbreviation for "format" (to format a partition)
        header = Builtins.add(header, Center(_("F")))
      when :encrypted
        # Column header, , abbreviation for "encrypted" (an encrypted device)
        header = Builtins.add(header, Center(_("Enc")))
      when :fs_type
        # Column header, abbreviation for "Filesystem Type"
        header = Builtins.add(header, _("FS Type"))
      when :mount_point
        # Column header
        header = Builtins.add(header, _("Mount Point"))
      when :mount_by
        # Column header
        header = Builtins.add(header, _("Mount by"))
      when :used_by
        # Column header
        header = Builtins.add(header, _("Used by"))
      when :start_cyl
        # Column header
        header = Builtins.add(header, Right(_("Start")))
      when :end_cyl
        # Column header
        header = Builtins.add(header, Right(_("End")))
      when :fs_id
        # Column header
        header = Builtins.add(header, Right(_("FS ID")))
      when :uuid
        # Column header
        header = Builtins.add(header, _("UUID"))
      when :label
        # Column header
        header = Builtins.add(header, _("Label"))
      when :udev_path
        # Column header
        header = Builtins.add(header, _("Device Path"))
      when :udev_id
        # Column header
        header = Builtins.add(header, _("Device ID"))
      when :bios_id
        # Column header
        header = Builtins.add(header, _("BIOS ID"))
      when :disk_label
        # Column header
        header = Builtins.add(header, _("Disk Label"))
      when :lvm_metadata
        # Column header
        header = Builtins.add(header, _("Metadata"))
      when :pe_size
        # Column header, abbreviation for "Physical Extent"
        header = Builtins.add(header, _("PE Size"))
      when :stripes
        # Column header
        header = Builtins.add(header, _("Stripes"))
      when :raid_version
        # Column header
        header = Builtins.add(header, _("RAID Version"))
      when :raid_type
        # Column header
        header = Builtins.add(header, _("RAID Type"))
      when :chunk_size
        # Column header
        header = Builtins.add(header, _("Chunk Size"))
      when :parity_algorithm
        # Column header
        header = Builtins.add(header, _("Parity Algorithm"))
      when :vendor
        # Column header
        header = Builtins.add(header, _("Vendor"))
      when :model
        # Column header
        header = Builtins.add(header, _("Model"))
      else
        Builtins.y2error("unknown field %1", field)
        header = Builtins.add(header, "error")
    end
  end

  deep_copy(header)
end

- (Object) TableHelptext(fields)



1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
# File '../../src/modules/StorageFields.rb', line 1298

def TableHelptext(fields)
  fields = deep_copy(fields)
  fields = Builtins.filter(fields) do |field|
    Builtins.substring(Builtins.tostring(field), 0, 8) != "`heading"
  end

  initial = _("<p>The table contains:</p>")

  helptext = Builtins::List.reduce(initial, fields) do |tmp, field|
    Ops.add(tmp, Helptext(field, :table))
  end

  helptext
end

- (Object) TableRow(fields, disk, part)



1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
# File '../../src/modules/StorageFields.rb', line 1041

def TableRow(fields, disk, part)
  fields = deep_copy(fields)
  disk = deep_copy(disk)
  part = deep_copy(part)
  device = part == nil ?
    Ops.get_string(disk, "device", "") :
    Ops.get_string(part, "device", "")
  if Ops.get_symbol(disk, "type", :CT_UNKNOWN) == :CT_TMPFS
    device = Ops.add("tmpfs:", Ops.get_string(part, "mount", ""))
  end

  row = Builtins::List.reduce(Item(Id(device)), fields) do |tmp, field|
    Builtins.add(tmp, MakeSubInfo(disk, part, field, :table))
  end

  deep_copy(row)
end

- (Object) UsedByString(used_by)



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File '../../src/modules/StorageFields.rb', line 94

def UsedByString(used_by)
  used_by = deep_copy(used_by)
  type = Ops.get_symbol(used_by, "type", :UB_NONE)
  device = Ops.get_string(used_by, "device", "")

  case type
    when :UB_LVM
      return Ops.add("LVM ", device)
    when :UB_DM
      return Ops.add("DM ", device)
    when :UB_DMRAID
      return Ops.add("DM RAID ", device)
    when :UB_DMMULTIPATH
      return Ops.add("DM Multipath ", device)
    when :UB_MD, :UB_MDPART
      return Ops.add("MD RAID ", device)
    when :UB_BTRFS
      return Ops.add("BTRFS ", device)
    else
      return device
  end
end