-
Notifications
You must be signed in to change notification settings - Fork 728
Add support for gpart in BSD Fdisk
#2405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| # Iterate over disk devices | ||
| foreach my $dev (glob("/dev/ada[0-9]"), glob("/dev/ada[0-9][0-9]"), | ||
| glob("/dev/ad[0-9]"), glob("/dev/ad[0-9][0-9]"), | ||
| glob("/dev/nvd[0-9]"), glob("/dev/nvd[0-9][0-9]"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@karmantyu, I have modified it to nvd[0-9][0-9] for all three regexes because nvd[0-9]* is greedy and would even match nvd alone. Will this work for your case? If you are unsure, could you provide the list of devices?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
99 disk is plenty enough
| # Get size and slices | ||
| my $out; | ||
| my $sdev = 's'; | ||
| if (&has_command('gpart')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@karmantyu, I changed this part because we want to support older systems that still use fdisk.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've got the suggestion to implement:
# Add at the beginning of each CGI script
sub get_disk_manager {
my $has_gpart = &has_command("gpart");
return $has_gpart ? "gpart" : "fdisk";
}
# Example implementation for disk operations
sub handle_disk_operation {
my ($disk, $operation) = @_;
my $manager = &get_disk_manager();
if ($manager eq "gpart") {
# Modern gpart commands
return &execute_gpart_command($disk, $operation);
} else {
# Legacy fdisk commands
return &execute_fdisk_command($disk, $operation);
}
}
| $slice = { 'number' => $1, | ||
| 'device' => $dev."$sdev".$1, | ||
| 'index' => scalar(@{$disk->{'slices'}}) }; | ||
| if ($slice->{'device'} =~ /^\/dev\/([a-z]+)(\d+)[ps](\d+)/) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@karmantyu And, the same here, the regex will match both, old and new format.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A possible example for backward compat.
fdisk_compat_example.zip
| use WebminCore; | ||
| &init_config(); | ||
| &foreign_require("mount"); | ||
| &foreign_require("fdisk"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@karmantyu, I reverted back this change to use fdisk module, because using mount::device_status seems incorrect, simply because device_status sub isn't available in mount module.
| # Validate inputs, starting with slice number | ||
| my $part = { }; | ||
| $in{'letter'} =~ /^[a-d]$/i || &error($text{'npart_eletter'}); | ||
| $in{'letter'} =~ /^[a-z]$/i || &error($text{'npart_eletter'}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@karmantyu, can you explain this change?
| # Slice type | ||
| $part->{'type'} = $in{'type'}; | ||
| # Set partition properties | ||
| $part->{'label'} = $in{'label'} if ($in{'label'} =~ /^[a-zA-Z0-9._-]+$/); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@karmantyu, I have also changed the regex from /^[a-zA-Z0-9._-]*$/ to /^[a-zA-Z0-9._-]+$/ because we expect the label not to be empty.
|
|
||
| # Slice type | ||
| $slice->{'type'} = $in{'type'}; | ||
| $slice->{'label'} = $in{'label'} if ($in{'label'} =~ /^[a-zA-Z0-9._-]+$/); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@karmantyu, and the same here.
| if ($disk->{'model'}) { | ||
| push(@info, &text('disk_model', $disk->{'model'})); | ||
| } | ||
| push(@info, &text('disk_cylinders', $disk->{'cylinders'})); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@karmantyu, why deleting this line? Please remember we need to provide support for older versions!
| &ui_select("type", $part->{'type'}, | ||
| [ &list_partition_types() ], 1, 0, 1)); | ||
| print &ui_table_row($text{'part_label'}, | ||
| &ui_textbox("label", $part->{'label'}, 20)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@karmantyu, remember to maintain indent correctly! We use tabs with tab display size set to 8.
| [ sort { $a->[1] cmp $b->[1] } | ||
| map { [ $_, &fdisk::tag_name($_) ] } | ||
| &fdisk::list_tags() ])); | ||
| [ &list_partition_types() ])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@karmantyu, we need to main backward compatibility with older versions of BSD that don't have gpart available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I folder than FreeBSD 10.0. needed of course.
| $slice->{'active'} ? $text{'yes'} : | ||
| &ui_yesno_radio("active", $slice->{'active'})); | ||
| # Label field | ||
| print &ui_table_row($text{'slice_label'}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@karmantyu, where is the updated lang/en file? I couldn't find it in the initial archive, and all these new language strings are missing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry missed that. Maybe tomorrow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've let Sourcegraph cross-reference the language file with the changes. Need further testing.
| # Partition type selection | ||
| print &ui_table_row($text{'npart_type'}, | ||
| &ui_select("type", '4.2BSD', | ||
| &ui_select("type", 'freebsd-ufs', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@karmantyu, it has to be backward compatible with older versions of BSD.
| # Start and end blocks (defaults to last slice+1) | ||
| my ($start, $end) = (63, $disk->{'blocks'}); | ||
| foreach my $s (sort { $a->{'startblock'} cmp $b->{'startblock'} } | ||
| my ($start, $end) = (2048, $disk->{'blocks'}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@karmantyu, can you explain this change? Again, it has to be compatible with older versions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using newer disk drives, GPT is recommended which uses 2048 as start sector by default. For partitioning newer "Advanced Format 4K" disks.
| my ($start, $end) = (63, $disk->{'blocks'}); | ||
| foreach my $s (sort { $a->{'startblock'} cmp $b->{'startblock'} } | ||
| my ($start, $end) = (2048, $disk->{'blocks'}); | ||
| foreach my $s (sort { $a->{'startblock'} <=> $b->{'startblock'} } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@karmantyu, and why this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 MiB (2048 sector) alignment was introduced to Linux fdisk in util-linux-ng-2.17.1/fdisk/fdisk.c, function update_sector_offset(void), released on 2010-02-22. Windows Vista was released in 2006-11.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And more: In other words, the LBA sector number 63 corresponds to cylinder 0, head 1, sector 1 in the CHS format, which is the first sector you can use in the MBR format. However, the number 63 is not divisible by 8, which causes a problem with 4K drives, so some modern tools starts the first partition at 2048 which also provides future GPT compatibility.
|
Appreciate Your hard work. Sorry for the mistakes. |
|
New example bsdfdiksk-lib.pl now checking if the BSD is newer than ver. 10 and using gpart in case of new systems. Showing the partitions and slices nicely on FreeBSD 14.2 |
Hello Jamie,
As described in this comment, a user suggests that the changes made are tested and working correctly.
I have reviewed the changes and fixed a large number of broken indents, along with some logic that, from my perspective, was incorrect.
I will add comments along the way, inviting the original author, @karmantyu, to comment on them.