Class: Yast::StorageUpdateClass

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

Instance Method Summary (collapse)

Instance Method Details

- (Object) main



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

def main

  textdomain "storage"


  Yast.import "Arch"
  Yast.import "AsciiFile"
  Yast.import "FileSystems"
  Yast.import "Partitions"
  Yast.import "Storage"


  # flag indicates calling StorageUpdate::Update()
  @called_update = false
end

- (Object) Update(oldv, newv)

Updates fstab on disk

Structure:

version 

Parameters:

  • map

    old version

  • map

    new version



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
# File '../../src/modules/StorageUpdate.rb', line 608

def Update(oldv, newv)
  oldv = deep_copy(oldv)
  newv = deep_copy(newv)
  if !@called_update
    Builtins.y2milestone("Update old:%1 new:%2", oldv, newv)

    # Enterprise products do not have minor release number
    # map enterprise releases to corresponding code bases of SL
    sles_major_to_minor = { 8 => 2, 9 => 1, 10 => 1 }
    if Builtins.haskey(oldv, "major") && !Builtins.haskey(oldv, "minor")
      Ops.set(
        oldv,
        "minor",
        Ops.get_integer(
          sles_major_to_minor,
          Ops.get_integer(oldv, "major", 0),
          0
        )
      )
      Builtins.y2milestone("Update old:%1", oldv)
    end
    if Builtins.haskey(newv, "major") && !Builtins.haskey(newv, "minor")
      Ops.set(
        newv,
        "minor",
        Ops.get_integer(
          sles_major_to_minor,
          Ops.get_integer(newv, "major", 0),
          0
        )
      )
      Builtins.y2milestone("Update new:%1", newv)
    end
    if !Builtins.haskey(oldv, "major") || !Builtins.haskey(newv, "major")
      Builtins.y2error("Missing key major or minor")
    end

    if Ops.less_or_equal(Ops.get_integer(oldv, "major", 0), 9)
      UpdateFstabSysfs()
    end
    if Ops.less_than(Ops.get_integer(oldv, "major", 0), 9)
      UpdateFstabUsbdevfs()
    end
    UpdateFstabPersistentNames() if Ops.get_integer(oldv, "major", 0) == 9

    if Ops.less_or_equal(Ops.get_integer(oldv, "major", 0), 10)
      UpdateFstabHotplugOption()
    end

    # remove EVMS
    # FIXME add appropriate condition if needed (does not seem so)
    UpdateFstabEvms2Lvm()

    dm = Storage.BuildDiskmap(oldv)
    if Ops.greater_than(Builtins.size(dm), 0)
      UpdateFstabDiskmap(dm)
      UpdateMdadm()
    end
    if Ops.less_than(Ops.get_integer(oldv, "major", 0), 9) ||
        Ops.get_integer(oldv, "major", 0) == 9 &&
          Ops.less_or_equal(Ops.get_integer(oldv, "minor", 0), 2)
      UpdateCryptoType()
    end
    if Ops.less_than(Ops.get_integer(oldv, "major", 0), 10) ||
        Ops.get_integer(oldv, "major", 0) == 10 &&
          Ops.get_integer(oldv, "minor", 0) == 0
      of = "/etc/udev/rules.d/20-cdrom.rules"
      Builtins.y2milestone("removing obsolete %1", of)
      SCR.Execute(path(".target.remove"), of)
      of = "/etc/udev/rules.d/55-cdrom.rules"
      Builtins.y2milestone("removing obsolete %1", of)
      SCR.Execute(path(".target.remove"), of)
    end
    if Ops.less_than(Ops.get_integer(oldv, "major", 0), 10) ||
        Ops.get_integer(oldv, "major", 0) == 10 &&
          Ops.less_or_equal(Ops.get_integer(oldv, "minor", 0), 2)
      of = "/etc/udev/rules.d/65-cdrom.rules"
      Builtins.y2milestone("removing obsolete %1", of)
      SCR.Execute(path(".target.remove"), of)
    end
    if Ops.less_than(Ops.get_integer(oldv, "major", 0), 10) ||
        Ops.get_integer(oldv, "major", 0) == 10 &&
          Ops.get_integer(oldv, "minor", 0) == 0
      UpdateFstabSubfs()
    end
    if Ops.less_than(Ops.get_integer(oldv, "major", 0), 9) ||
        Ops.get_integer(oldv, "major", 0) == 9 &&
          Ops.get_integer(oldv, "minor", 0) == 0
      UpdateFstabIseriesVd() if Arch.board_iseries
      cmd = "cd / && /sbin/insserv -r /etc/init.d/boot.evms"
      Builtins.y2milestone("Update cmd %1", cmd)
      bo = Convert.to_map(SCR.Execute(path(".target.bash_output"), cmd))
      Builtins.y2milestone("Update bo %1", bo)
    end
    if Ops.less_than(Ops.get_integer(oldv, "major", 0), 10) ||
        Ops.get_integer(oldv, "major", 0) == 10 &&
          Ops.less_or_equal(Ops.get_integer(oldv, "minor", 0), 2)
      cmd = "cd / && /sbin/insserv /etc/init.d/boot.crypto"
      bo = Convert.to_map(SCR.Execute(path(".target.bash_output"), cmd))
      Builtins.y2milestone("Update bo %1", bo)

      cmd = "cd / && /sbin/insserv /etc/init.d/boot.crypto-early"
      bo = Convert.to_map(SCR.Execute(path(".target.bash_output"), cmd))
      Builtins.y2milestone("Update bo %1", bo)
    end
    if Ops.less_than(Ops.get_integer(oldv, "major", 0), 11) ||
        Ops.get_integer(oldv, "major", 0) == 11 &&
          Ops.less_or_equal(Ops.get_integer(oldv, "minor", 0), 2)
      UpdateFstabCryptNofail()
    end
    # 	    if( oldv["major"]:0<=11 || (oldv["major"]:0==12 && oldv["minor"]:0<=1))
    # 		UpdateFstabWindowsMounts();
    if Ops.less_than(Ops.get_integer(oldv, "major", 0), 13)
      UpdateFstabRemoveSystemdMps()
    end
    # set flag -> it indicates that Update was already called
    @called_update = true
  else
    Builtins.y2milestone("Skip calling Update() -> It was already called")
  end

  nil
end

- (Object) UpdateCryptoType



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
# File '../../src/modules/StorageUpdate.rb', line 418

def UpdateCryptoType
  Builtins.y2milestone("UpdateCryptoType")
  tabpath = Storage.PathToDestdir("/etc/fstab")
  fstab = Partitions.GetFstab(tabpath)
  line = 0
  pos = 0
  searchstr = "encryption=twofish256"
  while Ops.less_or_equal(line, AsciiFile.NumLines(fstab))
    l = (
      fstab_ref = arg_ref(fstab);
      _GetLine_result = AsciiFile.GetLine(fstab_ref, line);
      fstab = fstab_ref.value;
      _GetLine_result
    )
    pos = Builtins.search(Ops.get_string(l, ["fields", 3], ""), searchstr)
    if pos != nil
      new = Builtins.substring(Ops.get_string(l, ["fields", 3], ""), 0, pos)
      new = Ops.add(new, "encryption=twofishSL92")
      new = Ops.add(
        new,
        Builtins.substring(
          Ops.get_string(l, ["fields", 3], ""),
          Ops.add(pos, Builtins.size(searchstr))
        )
      )
      Builtins.y2milestone("new options line in %1 is %2", l, new)
      fstab_ref = arg_ref(fstab)
      AsciiFile.ChangeLineField(fstab_ref, line, 3, new)
      fstab = fstab_ref.value
    end
    line = Ops.add(line, 1)
  end
  fstab_ref = arg_ref(fstab)
  AsciiFile.RewriteFile(fstab_ref, tabpath)
  fstab = fstab_ref.value
  tabpath = Storage.PathToDestdir("/etc/cryptotab")
  crtab = Partitions.GetCrypto(tabpath)
  line = 0
  while Ops.less_or_equal(line, AsciiFile.NumLines(crtab))
    l = (
      crtab_ref = arg_ref(crtab);
      _GetLine_result = AsciiFile.GetLine(crtab_ref, line);
      crtab = crtab_ref.value;
      _GetLine_result
    )
    if Ops.get_string(l, ["fields", 4], "") == "twofish256"
      Builtins.y2milestone("set twofishSL92 in line %1", l)
      crtab_ref = arg_ref(crtab)
      AsciiFile.ChangeLineField(crtab_ref, line, 4, "twofishSL92")
      crtab = crtab_ref.value
    end
    line = Ops.add(line, 1)
  end
  crtab_ref = arg_ref(crtab)
  AsciiFile.RewriteFile(crtab_ref, tabpath)
  crtab = crtab_ref.value

  nil
end

- (Object) UpdateFstabCryptNofail



478
479
480
481
482
483
484
485
486
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
# File '../../src/modules/StorageUpdate.rb', line 478

def UpdateFstabCryptNofail
  Builtins.y2milestone("UpdateFstabCryptNofail called")
  tabpath = Storage.PathToDestdir("/etc/fstab")
  fstab = Partitions.GetFstab(tabpath)
  line = 0
  update = false
  while Ops.less_or_equal(line, AsciiFile.NumLines(fstab))
    l = (
      fstab_ref = arg_ref(fstab);
      _GetLine_result = AsciiFile.GetLine(fstab_ref, line);
      fstab = fstab_ref.value;
      _GetLine_result
    )
    if Builtins.search(
        Ops.get_string(l, ["fields", 0], ""),
        "/dev/mapper/cr_"
      ) == 0
      ls = Builtins.splitstring(Ops.get_string(l, ["fields", 3], ""), ",")
      ls = Builtins.filter(ls) { |s| s != "noauto" }
      if Builtins.size(Builtins.filter(ls) { |s| s == "nofail" }) == 0
        ls = Builtins.add(ls, "nofail")
        fstab_ref = arg_ref(fstab)
        AsciiFile.ChangeLineField(
          fstab_ref,
          line,
          3,
          Builtins.mergestring(ls, ",")
        )
        fstab = fstab_ref.value
        update = true
      end
    end
    line = Ops.add(line, 1)
  end
  if update
    fstab_ref = arg_ref(fstab)
    AsciiFile.RewriteFile(fstab_ref, tabpath)
    fstab = fstab_ref.value
  end

  nil
end

- (Object) UpdateFstabDiskmap(diskmap)



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
# File '../../src/modules/StorageUpdate.rb', line 282

def UpdateFstabDiskmap(diskmap)
  diskmap = deep_copy(diskmap)
  Builtins.y2milestone("UpdateFstabDiskmap map %1", diskmap)
  tabpath = Storage.PathToDestdir("/etc/fstab")
  fstab = Partitions.GetFstab(tabpath)
  line = 0
  n = ""
  while Ops.less_or_equal(line, AsciiFile.NumLines(fstab))
    l = (
      fstab_ref = arg_ref(fstab);
      _GetLine_result = AsciiFile.GetLine(fstab_ref, line);
      fstab = fstab_ref.value;
      _GetLine_result
    )
    n = Storage.HdDiskMap(Ops.get_string(l, ["fields", 0], ""), diskmap)
    if n != Ops.get_string(l, ["fields", 0], "")
      fstab_ref = arg_ref(fstab)
      AsciiFile.ChangeLineField(fstab_ref, line, 0, n)
      fstab = fstab_ref.value
    end
    line = Ops.add(line, 1)
  end
  fstab_ref = arg_ref(fstab)
  AsciiFile.RewriteFile(fstab_ref, tabpath)
  fstab = fstab_ref.value
  tabpath = Storage.PathToDestdir("/etc/cryptotab")
  crtab = Partitions.GetCrypto(tabpath)
  line = 0
  while Ops.less_or_equal(line, AsciiFile.NumLines(crtab))
    l = (
      crtab_ref = arg_ref(crtab);
      _GetLine_result = AsciiFile.GetLine(crtab_ref, line);
      crtab = crtab_ref.value;
      _GetLine_result
    )
    n = Storage.HdDiskMap(Ops.get_string(l, ["fields", 1], ""), diskmap)
    if n != Ops.get_string(l, ["fields", 1], "")
      crtab_ref = arg_ref(crtab)
      AsciiFile.ChangeLineField(crtab_ref, line, 1, n)
      crtab = crtab_ref.value
    end
    line = Ops.add(line, 1)
  end
  crtab_ref = arg_ref(crtab)
  AsciiFile.RewriteFile(crtab_ref, tabpath)
  crtab = crtab_ref.value

  nil
end

- (Object) UpdateFstabEvms2Lvm



212
213
214
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
# File '../../src/modules/StorageUpdate.rb', line 212

def UpdateFstabEvms2Lvm
  Builtins.y2milestone("UpdateFstabEvms2Lvm migrating EVMS to LVM")
  tabpath = Storage.PathToDestdir("/etc/fstab")
  fstab = Partitions.GetFstab(tabpath)
  line = 0
  n = ""
  while Ops.less_or_equal(line, AsciiFile.NumLines(fstab))
    l = (
      fstab_ref = arg_ref(fstab);
      _GetLine_result = AsciiFile.GetLine(fstab_ref, line);
      fstab = fstab_ref.value;
      _GetLine_result
    )
    n = Ops.get_string(l, ["fields", 0], "")
    if Builtins.substring(n, 0, 15) == "/dev/evms/lvm2/"
      n = Ops.add("/dev/", Builtins.substring(n, 15))
      fstab_ref = arg_ref(fstab)
      AsciiFile.ChangeLineField(fstab_ref, line, 0, n)
      fstab = fstab_ref.value
    end
    line = Ops.add(line, 1)
  end
  fstab_ref = arg_ref(fstab)
  AsciiFile.RewriteFile(fstab_ref, tabpath)
  fstab = fstab_ref.value

  nil
end

- (Object) UpdateFstabHotplugOption



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
# File '../../src/modules/StorageUpdate.rb', line 145

def UpdateFstabHotplugOption
  Builtins.y2milestone("UpdateFstabHotplugOption")
  tabpath = Storage.PathToDestdir("/etc/fstab")
  fstab = Partitions.GetFstab(tabpath)
  line = 0
  n = ""
  while Ops.less_or_equal(line, AsciiFile.NumLines(fstab))
    l = (
      fstab_ref = arg_ref(fstab);
      _GetLine_result = AsciiFile.GetLine(fstab_ref, line);
      fstab = fstab_ref.value;
      _GetLine_result
    )
    options = Ops.get_string(l, ["fields", 3], "")
    if Builtins.regexpmatch(options, "^(.*,)?hotplug(,.*)?$")
      options = Builtins.regexpsub(
        options,
        "^(.*,)?hotplug(,.*)?$",
        "\\1nofail\\2"
      )
      fstab_ref = arg_ref(fstab)
      AsciiFile.ChangeLineField(fstab_ref, line, 3, options)
      fstab = fstab_ref.value
    end
    line = Ops.add(line, 1)
  end
  fstab_ref = arg_ref(fstab)
  AsciiFile.RewriteFile(fstab_ref, tabpath)
  fstab = fstab_ref.value

  nil
end

- (Object) UpdateFstabIseriesVd



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
# File '../../src/modules/StorageUpdate.rb', line 368

def UpdateFstabIseriesVd
  Builtins.y2milestone("UpdateFstabIseriesVd updating hdx to iseries/vdx")
  tabpath = Storage.PathToDestdir("/etc/fstab")
  fstab = Partitions.GetFstab(tabpath)
  line = 0
  n = ""
  while Ops.less_or_equal(line, AsciiFile.NumLines(fstab))
    l = (
      fstab_ref = arg_ref(fstab);
      _GetLine_result = AsciiFile.GetLine(fstab_ref, line);
      fstab = fstab_ref.value;
      _GetLine_result
    )
    n = Storage.HdToIseries(Ops.get_string(l, ["fields", 0], ""))
    if n != Ops.get_string(l, ["fields", 0], "")
      fstab_ref = arg_ref(fstab)
      AsciiFile.ChangeLineField(fstab_ref, line, 0, n)
      fstab = fstab_ref.value
    end
    line = Ops.add(line, 1)
  end
  fstab_ref = arg_ref(fstab)
  AsciiFile.RewriteFile(fstab_ref, tabpath)
  fstab = fstab_ref.value
  tabpath = Storage.PathToDestdir("/etc/cryptotab")
  crtab = Partitions.GetCrypto(tabpath)
  line = 0
  while Ops.less_or_equal(line, AsciiFile.NumLines(crtab))
    l = (
      crtab_ref = arg_ref(crtab);
      _GetLine_result = AsciiFile.GetLine(crtab_ref, line);
      crtab = crtab_ref.value;
      _GetLine_result
    )
    n = Storage.HdToIseries(Ops.get_string(l, ["fields", 1], ""))
    if n != Ops.get_string(l, ["fields", 1], "")
      crtab_ref = arg_ref(crtab)
      AsciiFile.ChangeLineField(crtab_ref, line, 1, n)
      crtab = crtab_ref.value
    end
    line = Ops.add(line, 1)
  end
  crtab_ref = arg_ref(crtab)
  AsciiFile.RewriteFile(crtab_ref, tabpath)
  crtab = crtab_ref.value

  nil
end

- (Object) UpdateFstabPersistentNames



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
# File '../../src/modules/StorageUpdate.rb', line 179

def UpdateFstabPersistentNames
  Builtins.y2milestone(
    "UpdateFstabPersistentDevNames updating to SLES10 names"
  )
  tabpath = Storage.PathToDestdir("/etc/fstab")
  fstab = Partitions.GetFstab(tabpath)
  line = 0
  n = ""
  while Ops.less_or_equal(line, AsciiFile.NumLines(fstab))
    l = (
      fstab_ref = arg_ref(fstab);
      _GetLine_result = AsciiFile.GetLine(fstab_ref, line);
      fstab = fstab_ref.value;
      _GetLine_result
    )
    n = Storage.SLES9PersistentDevNames(
      Ops.get_string(l, ["fields", 0], "")
    )
    if n != Ops.get_string(l, ["fields", 0], "")
      fstab_ref = arg_ref(fstab)
      AsciiFile.ChangeLineField(fstab_ref, line, 0, n)
      fstab = fstab_ref.value
    end
    line = Ops.add(line, 1)
  end
  fstab_ref = arg_ref(fstab)
  AsciiFile.RewriteFile(fstab_ref, tabpath)
  fstab = fstab_ref.value

  nil
end

- (Object) UpdateFstabRemoveSystemdMps



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
# File '../../src/modules/StorageUpdate.rb', line 556

def UpdateFstabRemoveSystemdMps
  Builtins.y2milestone("UpdateFstabRemoveSystemdMps called")
  tabpath = Storage.PathToDestdir("/etc/fstab")
  fstab = Partitions.GetFstab(tabpath)
  rem_lines = []
  rem_dirs = [
    "/proc",
    "/sys",
    "/sys/kernel/debug",
    "/dev/pts",
    "/proc/bus/usb"
  ]
  line = 0
  while Ops.less_or_equal(line, AsciiFile.NumLines(fstab))
    l = (
      fstab_ref = arg_ref(fstab);
      _GetLine_result = AsciiFile.GetLine(fstab_ref, line);
      fstab = fstab_ref.value;
      _GetLine_result
    )
    if Builtins.contains(rem_dirs, Ops.get_string(l, ["fields", 1], ""))
      rem_lines = Builtins.add(rem_lines, line)
    end
    line = Ops.add(line, 1)
  end
  if Ops.greater_than(Builtins.size(rem_lines), 0)
    rem_lines = Builtins.sort(rem_lines)
    Builtins.y2milestone("UpdateFstabRemoveSystemdMps %1", rem_lines)
    fstab_ref = arg_ref(fstab)
    AsciiFile.RemoveLines(fstab_ref, rem_lines)
    fstab = fstab_ref.value
    fstab_ref = arg_ref(fstab)
    AsciiFile.RewriteFile(fstab_ref, tabpath)
    fstab = fstab_ref.value
  end

  nil
end

- (Object) UpdateFstabSubfs



46
47
48
49
50
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File '../../src/modules/StorageUpdate.rb', line 46

def UpdateFstabSubfs
  Builtins.y2milestone(
    "UpdateFstabSubfs removing fstab entries for cdrom and floppy"
  )
  tabpath = Storage.PathToDestdir("/etc/fstab")
  fstab = Partitions.GetFstab(tabpath)
  line = 0
  rem_lines = []
  while Ops.less_or_equal(line, AsciiFile.NumLines(fstab))
    l = (
      fstab_ref = arg_ref(fstab);
      _GetLine_result = AsciiFile.GetLine(fstab_ref, line);
      fstab = fstab_ref.value;
      _GetLine_result
    )
    if Builtins.search(
        Ops.get_string(l, ["fields", 1], ""),
        "/media/floppy"
      ) == 0
      rem_lines = Builtins.add(rem_lines, line)
    elsif Builtins.search(
        Ops.get_string(l, ["fields", 1], ""),
        "/media/cdrom"
      ) == 0 ||
        Builtins.search(Ops.get_string(l, ["fields", 1], ""), "/media/dvd") == 0 ||
        Builtins.search(
          Ops.get_string(l, ["fields", 1], ""),
          "/media/cdrecorder"
        ) == 0 ||
        Builtins.search(
          Ops.get_string(l, ["fields", 1], ""),
          "/media/dvdrecorder"
        ) == 0 ||
        Builtins.search(Ops.get_string(l, ["fields", 1], ""), "/cdrom") == 0 ||
        Builtins.search(Ops.get_string(l, ["fields", 1], ""), "/dvd") == 0 ||
        Builtins.search(Ops.get_string(l, ["fields", 1], ""), "/cdrecorder") == 0 ||
        Builtins.search(
          Ops.get_string(l, ["fields", 1], ""),
          "/dvdrecorder"
        ) == 0
      rem_lines = Builtins.add(rem_lines, line)
    end
    line = Ops.add(line, 1)
  end
  Builtins.y2milestone("UpdateFstabSubfs %1", rem_lines)
  if Ops.greater_than(Builtins.size(rem_lines), 0)
    rem_lines = Builtins.sort(rem_lines)
    fstab_ref = arg_ref(fstab)
    AsciiFile.RemoveLines(fstab_ref, rem_lines)
    fstab = fstab_ref.value
  end
  fstab_ref = arg_ref(fstab)
  AsciiFile.RewriteFile(fstab_ref, tabpath)
  fstab = fstab_ref.value

  nil
end

- (Object) UpdateFstabSysfs



105
106
107
108
109
110
111
112
113
114
115
116
117
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
# File '../../src/modules/StorageUpdate.rb', line 105

def UpdateFstabSysfs
  Builtins.y2milestone("UpdateFstabSysfs called")
  tabpath = Storage.PathToDestdir("/etc/fstab")
  fstab = Partitions.GetFstab(tabpath)
  line = 0
  have_sysfs = false
  while !have_sysfs && Ops.less_or_equal(line, AsciiFile.NumLines(fstab))
    l = (
      fstab_ref = arg_ref(fstab);
      _GetLine_result = AsciiFile.GetLine(fstab_ref, line);
      fstab = fstab_ref.value;
      _GetLine_result
    )
    have_sysfs = Ops.get_string(l, ["fields", 1], "") == "/sys"
    line = Ops.add(line, 1)
  end
  if !have_sysfs
    entry = FileSystems.GetFstabDefaultMap("sys")
    fstlist = [
      Ops.get_string(entry, "spec", ""),
      Ops.get_string(entry, "mount", ""),
      Ops.get_string(entry, "vfstype", ""),
      Ops.get_string(entry, "mntops", ""),
      Builtins.sformat("%1", Ops.get_integer(entry, "freq", 0)),
      Builtins.sformat("%1", Ops.get_integer(entry, "passno", 0))
    ]
    Builtins.y2milestone("UpdateFstabSysfs entry %1", entry)
    Builtins.y2milestone("UpdateFstabSysfs fstlist %1", fstlist)
    fstab_ref = arg_ref(fstab)
    AsciiFile.AppendLine(fstab_ref, fstlist)
    fstab = fstab_ref.value
    fstab_ref = arg_ref(fstab)
    AsciiFile.RewriteFile(fstab_ref, tabpath)
    fstab = fstab_ref.value
  end

  nil
end

- (Object) UpdateFstabUsbdevfs



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
# File '../../src/modules/StorageUpdate.rb', line 333

def UpdateFstabUsbdevfs
  Builtins.y2milestone("UpdateFstabUsbdevfs updating usbdevfs to usbfs")
  changed = false
  tabpath = Storage.PathToDestdir("/etc/fstab")
  fstab = Partitions.GetFstab(tabpath)
  line = 0
  while Ops.less_or_equal(line, AsciiFile.NumLines(fstab))
    l = (
      fstab_ref = arg_ref(fstab);
      _GetLine_result = AsciiFile.GetLine(fstab_ref, line);
      fstab = fstab_ref.value;
      _GetLine_result
    )
    if Ops.get_string(l, ["fields", 2], "") == "usbdevfs"
      fstab_ref = arg_ref(fstab)
      AsciiFile.ChangeLineField(fstab_ref, line, 2, "usbfs")
      fstab = fstab_ref.value
      fstab_ref = arg_ref(fstab)
      AsciiFile.ChangeLineField(fstab_ref, line, 0, "usbfs")
      fstab = fstab_ref.value
      changed = true
    end
    line = Ops.add(line, 1)
  end
  if changed
    Builtins.y2milestone("UpdateFstabUsbdevfs changed")
    fstab_ref = arg_ref(fstab)
    AsciiFile.RewriteFile(fstab_ref, tabpath)
    fstab = fstab_ref.value
  end

  nil
end

- (Object) UpdateFstabWindowsMounts



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
# File '../../src/modules/StorageUpdate.rb', line 521

def UpdateFstabWindowsMounts
  Builtins.y2milestone("UpdateFstabWindowsMounts called")
  tabpath = Storage.PathToDestdir("/etc/fstab")
  fstab = Partitions.GetFstab(tabpath)
  rem_lines = []
  line = 0
  while Ops.less_or_equal(line, AsciiFile.NumLines(fstab))
    l = (
      fstab_ref = arg_ref(fstab);
      _GetLine_result = AsciiFile.GetLine(fstab_ref, line);
      fstab = fstab_ref.value;
      _GetLine_result
    )
    if Builtins.search(Ops.get_string(l, ["fields", 1], ""), "/windows/") == 0 &&
        Builtins.size(Ops.get_string(l, ["fields", 1], "")) == 10 ||
        Builtins.search(Ops.get_string(l, ["fields", 1], ""), "/dos/") == 0 &&
          Builtins.size(Ops.get_string(l, ["fields", 1], "")) == 6
      rem_lines = Builtins.add(rem_lines, line)
    end
    line = Ops.add(line, 1)
  end
  if Ops.greater_than(Builtins.size(rem_lines), 0)
    rem_lines = Builtins.sort(rem_lines)
    Builtins.y2milestone("UpdateFstabWindowsMounts %1", rem_lines)
    fstab_ref = arg_ref(fstab)
    AsciiFile.RemoveLines(fstab_ref, rem_lines)
    fstab = fstab_ref.value
    fstab_ref = arg_ref(fstab)
    AsciiFile.RewriteFile(fstab_ref, tabpath)
    fstab = fstab_ref.value
  end

  nil
end

- (Object) UpdateMdadm



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
# File '../../src/modules/StorageUpdate.rb', line 242

def UpdateMdadm
  Builtins.y2milestone("UpdateMdadm")
  cpath = Storage.PathToDestdir("/etc/mdadm.conf")
  file = {}
  file_ref = arg_ref(file)
  AsciiFile.SetComment(file_ref, "^[ \t]*#")
  file = file_ref.value
  file_ref = arg_ref(file)
  AsciiFile.ReadFile(file_ref, cpath)
  file = file_ref.value
  line = 0
  changed = false
  while Ops.less_or_equal(line, AsciiFile.NumLines(file))
    if Builtins.search(
        Ops.get_string(file, ["l", line, "line"], ""),
        "DEVICE"
      ) != nil &&
        Builtins.search(
          Ops.get_string(file, ["l", line, "line"], ""),
          "/dev/"
        ) != nil
      changed = true
      Ops.set(file, ["l", line, "line"], "DEVICE partitions")
      Builtins.y2milestone(
        "UpdateMdadm %1",
        Ops.get_map(file, ["l", line], {})
      )
    end
    line = Ops.add(line, 1)
  end
  if changed
    file_ref = arg_ref(file)
    AsciiFile.RewriteFile(file_ref, cpath)
    file = file_ref.value
  end

  nil
end