Module: Yast::PartitioningAutoPartFunctionsInclude

Defined in:
../../src/include/partitioning/auto_part_functions.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) can_create_logical(partitions, first_logical_nr, max_logical)

Check whether three logical partitions can be created without running past the kernel limit for the number of partitions



156
157
158
159
160
161
162
163
164
165
166
# File '../../src/include/partitioning/auto_part_functions.rb', line 156

def can_create_logical(partitions, first_logical_nr, max_logical)
  partitions = deep_copy(partitions)
  logicals = Builtins.filter(partitions) do |pentry|
    Ops.get_symbol(pentry, "type", :unknown) == :logical
  end
  num_logical = Builtins.size(logicals)
  Ops.less_or_equal(
    Ops.add(Ops.add(first_logical_nr, num_logical), 2),
    max_logical
  )
end

- (Object) can_resize(partitions)

Check whether the partition list has a resizable partition as the highest partition. Input: List of partition maps Return: resizeable partition map or $[] if none found



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
# File '../../src/include/partitioning/auto_part_functions.rb', line 219

def can_resize(partitions)
  partitions = deep_copy(partitions)
  last_used_partition = {}

  if !Arch.i386
    Builtins.y2warning("Wrong architecture - can't resize partitions")
    return {} # for now
  end

  # Filter out empty space that might exist behind valid partitions.
  # This space would be there as a pseudo partition of type `free.
  #
  partitions_local = Builtins.filter(partitions) do |pentry|
    Ops.get_symbol(pentry, "type", :dummy) != :free
  end

  last_used_partition = get_last_used_partition(partitions_local)

  return {} if last_used_partition == {} # no last resizeable partition found

  # Check for supported filesystem types.
  #
  if is_fat_partition(last_used_partition)
    return deep_copy(last_used_partition)
  else
    return {}
  end
end

- (Object) check_win_nt_system(disk)

Check whether the partition list has a resizable partition as the highest partition. Input: map of data containing the disk Return: true if there is NT on the system, otherwise false



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
# File '../../src/include/partitioning/auto_part_functions.rb', line 274

def check_win_nt_system(disk)
  disk = deep_copy(disk)
  is_nt = false
  go_on = true
  local_ret = 0
  local_err = false
  partitions = []
  partitions_local = []
  fat_partition = ""

  partitions = Ops.get_list(disk, "partitions", [])
  if !is_nt && !local_err && go_on
    # First check if there are any NTFS partitions on the system
    #
    partitions_local = Builtins.filter(partitions) do |pentry|
      is_ntfs_partition(pentry)
    end

    is_nt = true if Builtins.size(partitions_local) != 0 # is NT system
  end

  if !is_nt && !local_err && go_on
    # Then look for specific files on all FAT partitions
    #
    partitions_local = Builtins.filter(partitions) do |pentry|
      is_fat_partition(pentry)
    end

    go_on = false if Builtins.size(partitions_local) == 0 # not an NT system
  end

  # If there are FAT partitions mount them and check specific files
  #
  if !is_nt && !local_err && go_on
    Builtins.foreach(partitions_local) do |pentry|
      # Now we are looping over all partitions for the current device.
      # get some special values from the partition entry.
      if !is_nt && !local_err && go_on
        # build devicename.
        fat_partition = Ops.get_string(pentry, "device", "")

        # mount the partition
        local_ret = Convert.to_integer(
          SCR.Execute(
            path(".target.bash"),
            Ops.add(Ops.add("/bin/mount ", fat_partition), " /mnt")
          )
        )

        if local_ret != 0
          Builtins.y2error(
            "FAT partition <%1> could not be mounted. Canceled",
            fat_partition
          )
          local_err = true
        end
      end
      if !is_nt && !local_err && go_on
        if file_exist("/mnt/winnt/system32/ntoskrnl.exe") ||
            file_exist("/mnt/winnt/system32/dllcache")
          Builtins.y2error(
            "Current Windows device <%1> is NT or 2000. Canceled",
            fat_partition
          )
          is_nt = true
        end
      end
      # unmount the partition if was mounted
      if !local_err
        SCR.Execute(
          path(".target.bash"),
          Ops.add("/bin/umount ", fat_partition)
        )
      end
    end # loop over all partitions
  end

  return 2 if local_err
  if is_nt
    return 1
  else
    return 0
  end
end

- (Object) compute_max_partitions(disk)

The maximum partition number the kernel can handle for the target disk, count from 0 on, return the maximal allowed value for a partition number



102
103
104
105
106
107
108
109
110
111
112
113
# File '../../src/include/partitioning/auto_part_functions.rb', line 102

def compute_max_partitions(disk)
  disk = deep_copy(disk)
  ret = Ops.subtract(Ops.get_integer(disk, "max_primary", 4), 1)
  if Ops.get_string(disk, "label", "") == "msdos"
    if Ops.get_string(disk, "bus", "") == "IDE"
      ret = 63
    else
      ret = 15
    end
  end
  ret
end

- (Object) contains_extended(partitions)

Return true if an extended partition exists



118
119
120
121
122
123
124
125
# File '../../src/include/partitioning/auto_part_functions.rb', line 118

def contains_extended(partitions)
  partitions = deep_copy(partitions)
  ret = Builtins.find(partitions) do |p|
    Ops.get_symbol(p, "type", :unknown) == :extended &&
      !Ops.get_boolean(p, "delete", false)
  end != nil
  ret
end

- (Object) end_of_region(region)

Return the end of the region, ie. start of the next region



78
79
80
81
# File '../../src/include/partitioning/auto_part_functions.rb', line 78

def end_of_region(region)
  region = deep_copy(region)
  Ops.add(Ops.get(region, 0, 0), Ops.get(region, 1, 0))
end

- (Object) extended_region(partitions)

Return the region of the extended partition



139
140
141
142
143
144
145
146
147
148
# File '../../src/include/partitioning/auto_part_functions.rb', line 139

def extended_region(partitions)
  partitions = deep_copy(partitions)
  ret = [0, 0]
  Builtins.foreach(partitions) do |pentry|
    if Ops.get_symbol(pentry, "type", :unknown) == :extended
      ret = Ops.get_list(pentry, "region", [])
    end
  end
  deep_copy(ret)
end

- (Object) file_exist(file_path)

Check if the given file does exist. Input: File to be checked incl. path as string, e.g. “/usr/lib/YaST2/clients/installation.ycp” This may also point to a directory. Return: true if found, false if not.



254
255
256
257
258
259
260
261
262
263
264
265
266
# File '../../src/include/partitioning/auto_part_functions.rb', line 254

def file_exist(file_path)
  file_found = Ops.greater_or_equal(
    Convert.to_integer(SCR.Read(path(".target.size"), file_path)),
    0
  )
  Builtins.y2milestone(
    "file %1 found %2 ret:%3",
    file_path,
    file_found,
    SCR.Read(path(".target.size"), file_path)
  )
  file_found
end

- (Object) get_last_used_partition(partitions)

Get the partition map with the highest minor number out of the given partition list Input: List of partition maps. Return: Partition map if found or $[] if not.



197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File '../../src/include/partitioning/auto_part_functions.rb', line 197

def get_last_used_partition(partitions)
  partitions = deep_copy(partitions)
  last_partition = {}
  minor = -1

  Builtins.y2milestone("get_last_used_partition p:%1", partitions)

  Builtins.foreach(partitions) do |partition|
    if Ops.greater_than(Ops.get_integer(partition, "nr", -1), minor)
      minor = Ops.get_integer(partition, "nr", -1)
      last_partition = deep_copy(partition)
    end
  end
  Builtins.y2milestone("get_last_used_partition ret %1", last_partition)
  deep_copy(last_partition)
end

- (Object) ignored_partition(disk, part)



127
128
129
130
131
132
133
134
135
# File '../../src/include/partitioning/auto_part_functions.rb', line 127

def ignored_partition(disk, part)
  disk = deep_copy(disk)
  part = deep_copy(part)
  # skip #3 on AlphaBSD and SparcBSD
  ret = Ops.get_string(disk, "label", "") == "bsd" ||
    Ops.get_string(disk, "label", "") == "sun"
  ret = Ops.get_integer(part, "nr", 0) == 3 if ret
  ret
end

- (Object) initialize_partitioning_auto_part_functions(include_target)



53
54
55
56
57
# File '../../src/include/partitioning/auto_part_functions.rb', line 53

def initialize_partitioning_auto_part_functions(include_target)
  Yast.import "Arch"

  textdomain "storage"
end

- (Object) is_fat_partition(partition)

Check if the given partition is a FAT partition Input: partition map to be checked (from targets) Return: true if partition is FAT, false otherwise



172
173
174
175
176
177
178
# File '../../src/include/partitioning/auto_part_functions.rb', line 172

def is_fat_partition(partition)
  partition = deep_copy(partition)
  Ops.get_integer(partition, "fsid", -1) == 6 ||
    Ops.get_integer(partition, "fsid", -1) == 11 ||
    Ops.get_integer(partition, "fsid", -1) == 12 ||
    Ops.get_integer(partition, "fsid", -1) == 14 # Win95 FAT16 LBA
end

- (Object) is_ntfs_partition(partition)

Check if the given partition is a NTFS partition Input: partition map to be checked (from targets) Return: true if partition is NTFS, false otherwise



185
186
187
188
189
190
# File '../../src/include/partitioning/auto_part_functions.rb', line 185

def is_ntfs_partition(partition)
  partition = deep_copy(partition)
  Ops.get_integer(partition, "fsid", -1) == 7 ||
    Ops.get_integer(partition, "fsid", -1) == 134 ||
    Ops.get_integer(partition, "fsid", -1) == 135 # NTFS-Datenträger
end

- (Object) num_primary(partitions)

Return the number of primary partitions



85
86
87
88
89
90
91
92
93
94
95
96
# File '../../src/include/partitioning/auto_part_functions.rb', line 85

def num_primary(partitions)
  partitions = deep_copy(partitions)
  n = 0

  Builtins.foreach(partitions) do |pentry|
    if Ops.get_symbol(pentry, "type", :unknown) == :primary
      n = Ops.add(n, 1)
    end
  end

  n
end

- (Object) size_of_region(region, bytes_per_unit)

Return the size of a disk region in bytes



64
65
66
67
# File '../../src/include/partitioning/auto_part_functions.rb', line 64

def size_of_region(region, bytes_per_unit)
  region = deep_copy(region)
  Ops.multiply(Ops.get(region, 1, 0), bytes_per_unit)
end

- (Object) start_of_region(region)

Return the start of the region.



71
72
73
74
# File '../../src/include/partitioning/auto_part_functions.rb', line 71

def start_of_region(region)
  region = deep_copy(region)
  Ops.get(region, 0, 0)
end

- (Object) unused_extended_region(partitions)

Find unused space at the end of the extended partition



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
# File '../../src/include/partitioning/auto_part_functions.rb', line 361

def unused_extended_region(partitions)
  partitions = deep_copy(partitions)
  extended = extended_region(partitions)
  logicals = Builtins.filter(partitions) do |pentry|
    Ops.get_symbol(pentry, "type", :unknown) == :logical
  end
  end_of_logicals = 0

  if Ops.greater_than(Builtins.size(logicals), 0)
    end_of_logicals = end_of_region(
      Ops.get_list(
        logicals,
        [Ops.subtract(Builtins.size(logicals), 1), "region"],
        []
      )
    )
  else
    end_of_logicals = start_of_region(extended)
  end

  if Ops.less_than(end_of_logicals, end_of_region(extended))
    return [
      end_of_logicals,
      Ops.subtract(end_of_region(extended), end_of_logicals)
    ]
  end
  [0, 0]
end