Skip to content

Commit

Permalink
Merge pull request #12 from AhmedKamal1432/amahi-8
Browse files Browse the repository at this point in the history
Hide mounted partitions
  • Loading branch information
cpg committed Aug 22, 2015
2 parents 1888b3a + d493779 commit 3148845
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
6 changes: 4 additions & 2 deletions app/controllers/disk_wizard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ def select_fs
else
@selected_disk = Device.find_with_unallocated(user_selections['path'])
end
@selected_disk = @selected_disk.exclude_mounted_partition
@selected_disk = @selected_disk.exclude_small_unallocated_space
end

# Expected key:values in @params:
Expand Down Expand Up @@ -149,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
21 changes: 18 additions & 3 deletions app/models/device.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@ def partition_count
return self.partitions.count
end

# Return new clone of the device without mounted partitions
def exclude_mounted_partition
new_device = self.clone
new_device.partitions = new_device.partitions.select{|part| part.mountpoint.blank?}
return new_device
end

# Return new clone of the device without small unallocated space
def exclude_small_unallocated_space
new_device = self.clone
new_device.partitions = new_device.partitions.reject{|part| Device.is_small_unallocated_partition(part)}
return new_device
end

# @return [boolean] check the value of the @rm and return a boolean, true if the device is a removable device else false
def removable?
return self.rm.eql? 1
Expand All @@ -81,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 @@ -123,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
14 changes: 13 additions & 1 deletion lib/modules/operation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ module Operation
# 2 Tera byte is the edge between MBR and GPT
GPT_EDGE = 2 * TERA_BYTE

# Consider this space as small space
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 @@ -133,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 @@ -172,5 +180,9 @@ def find node
return Device.new data_hash
end
end

def is_small_unallocated_partition partition
return (partition.free_space and partition.size < SMALL_UNALLOCATED_PARTITION)
end
end
end

0 comments on commit 3148845

Please sign in to comment.