Skip to content

Commit

Permalink
Make the shifted start_sector is the mount partition identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
AhmedKamal1432 committed Aug 22, 2015
1 parent 1c7ed57 commit d493779
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions app/controllers/disk_wizard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ def process_disk
# send start sector as to be able to know which partition to mount
device = Device.find_with_unallocated(user_selections['disk'])
@selected_disk = (device.partitions.select{|part| part.identifier == user_selections['identifier'] }).first
end_sector = @selected_disk.end_sector
start_sector = @selected_disk.start_sector
end

para = {path: path, label: label, end_sector: end_sector}
para = {path: path, label: label, start_sector: start_sector}
job_name = :mount_job
jobs_queue.enqueue({job_name: job_name, job_para: para})
end
Expand Down
7 changes: 4 additions & 3 deletions app/models/device.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def full_format fstype, label = nil

def create_partition(size = nil, type = Partition.PartitionType[:TYPE_PRIMARY])
# Shift start sector if it is on the patition table size
new_start_sector = [self.megabyte_to_sectors(PARTITION_TABLE_SIZE_MB), size[:start_sector].to_i].max
new_start_sector = self.shift_start_sector(size[:start_sector])
raise "cannot create a partition with negative size" if size[:end_sector].to_i < new_start_sector

old_partitions = Device.find(self.path).partitions
Expand Down Expand Up @@ -137,10 +137,11 @@ def mount_job params_hash
Device.progress = 60
kname = @kname
DebugLogger.info "|#{self.class.name}|>|#{__method__}|:New partition Label #{params_hash[:label]}"
unless params_hash[:end_sector].blank?
unless params_hash[:start_sector].blank?
# mount new partition
device = Device.find_with_unallocated "/dev/#{self.kname}"
new_partition = device.partitions.select{|part| part.end_sector.to_i == params_hash[:end_sector].to_i}.first
new_start_sector = self.shift_start_sector(params_hash[:start_sector])
new_partition = device.partitions.select{|part| part.start_sector.to_i == new_start_sector.to_i}.first
else
new_partition = self.partitions.last
end
Expand Down
10 changes: 7 additions & 3 deletions lib/modules/operation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ module Operation
GPT_EDGE = 2 * TERA_BYTE

# Consider this space as small space
SMALL_UNALLOCATED_PARTITION = 3 * MEGA_BYTE
SMALL_UNALLOCATED_PARTITION = 2 * MEGA_BYTE

# the space in MB that we let it to the partition table
PARTITION_TABLE_SIZE_MB = 2
PARTITION_TABLE_SIZE_MB = 1

DRIVE_MOUNT_ROOT = "/var/hda/files/drives"

Expand Down Expand Up @@ -136,6 +136,11 @@ def path
return DiskUtils.get_path self
end

# Shift start sector if it is on the patition table size
def shift_start_sector start_sector
[self.megabyte_to_sectors(PARTITION_TABLE_SIZE_MB), start_sector.to_i].max
end

# Reload the device/partition attribute from system.
def reload
dev_path = "/dev/#{self.kname}"
Expand Down Expand Up @@ -179,6 +184,5 @@ def find node
def is_small_unallocated_partition partition
return (partition.free_space and partition.size < SMALL_UNALLOCATED_PARTITION)
end

end
end

0 comments on commit d493779

Please sign in to comment.