package partition_table; # $Id: partition_table.pm 268438 2010-05-10 14:25:50Z pterjan $ use diagnostics; use strict; use common; use fs::type; use partition_table::raw; use detect_devices; use log; sub hd2minimal_part { my ($hd) = @_; { rootDevice => $hd->{device}, if_($hd->{usb_media_type}, is_removable => 1), }; } #- works for both hard disk drives and partitions ;p sub description { my ($hd) = @_; my $win = $hd->{device_windobe}; sprintf "%s%s (%s)", $hd->{device}, $win && " [$win:]", join(', ', grep { $_ } formatXiB($hd->{totalsectors} || $hd->{size}, 512), $hd->{info}, $hd->{mntpoint}, $hd->{fs_type}); } #- align partition start to the next MB boundary sub align_to_MB_boundaries { my ($part) = @_; my $end = $part->{start} + $part->{size}; $part->{start} = round_up($part->{start}, MB(1)); $part->{size} = $end - $part->{start}; } sub adjustStartAndEnd { my ($hd, $part) = @_; # always align partition start to MB boundaries # (this accounts for devices with non-512 physical sector sizes): align_to_MB_boundaries($part); $hd->adjustStart($part); $hd->adjustEnd($part); } sub verifyNotOverlap { my ($a, $b) = @_; $a->{start} + $a->{size} <= $b->{start} || $b->{start} + $b->{size} <= $a->{start}; } sub verifyInside { my ($a, $b) = @_; $b->{start} <= $a->{start} && $a->{start} + $a->{size} <= $b->{start} + $b->{size}; } sub verifyParts_ { foreach my $i (@_) { foreach (@_) { next if !$i || !$_ || $i == $_ || isWholedisk($i) || isExtended($i); #- avoid testing twice for simplicity :-) if (isWholedisk($_)) { verifyInside($i, $_) or cdie sprintf("partition sector #$i->{start} (%s) is not inside whole disk (%s)!", formatXiB($i->{size}, 512), formatXiB($_->{size}, 512)); } elsif (isExtended($_)) { verifyNotOverlap($i, $_) or log::l(sprintf("warning partition sector #$i->{start} (%s) is overlapping with extended partition!", formatXiB($i->{size}, 512))); #- only warning for this one is acceptable } else { verifyNotOverlap($i, $_) or cdie sprintf("partitions sector #$i->{start} (%s) and sector #$_->{start} (%s) are overlapping!", formatXiB($i->{size}, 512), formatXiB($_->{size}, 512)); } } } } sub verifyParts { my ($hd) = @_; verifyParts_(get_normal_parts($hd)); } sub verifyPrimary { my ($pt) = @_; $_->{start} > 0 || arch() =~ /^sparc/ || die "partition must NOT start at sector 0" foreach @{$pt->{normal}}; verifyParts_(@{$pt->{normal}}, $pt->{extended}); } sub compute_device_name { my ($part, $hd) = @_; $part->{device} = _compute_device_name($hd, $part->{part_number}); } sub _compute_device_name { my ($hd, $nb) = @_; my $prefix = $hd->{prefix} || devices::prefix_for_dev($hd->{device}); $prefix . $nb; } sub assign_device_numbers { my ($hd) = @_; my $i = 1; my $start = 1; #- on PPC we need to assign device numbers to the holes too - big FUN! #- not if it's an IBM machine using a DOS partition table though if (arch() =~ /ppc/ && detect_devices::get_mac_model() !~ /^IBM/) { #- first sort the normal parts $hd->{primary}{normal} = [ sort { $a->{start} <=> $b->{start} } @{$hd->{primary}{normal}} ]; #- now loop through them, assigning partition numbers - reserve one for the holes foreach (@{$hd->{primary}{normal}}) { if ($_->{start} > $start) { log::l("PPC: found a hole on $hd->{device} before $_->{start}, skipping device..."); $i++; } $_->{part_number} = $i; compute_device_name($_, $hd); $start = $_->{start} + $_->{size}; $i++; } } else { foreach (@{$hd->{primary}{raw}}) { $_->{part_number} = $i; compute_device_name($_, $hd); $i++; } foreach (map { $_->{normal} } @{$hd->{extended} || []}) { my $dev = _compute_device_name($hd, $i); my $renumbered = $_->{device} && $dev ne $_->{device}; if ($renumbered) { require fs::mount; eval { fs::mount::umount_part($_) }; #- at least try to umount it will_tell_kernel($hd, del => $_, 'delay_del'); push @{$hd->{partitionsRenumbered}}, [ $_->{device}, $dev ]; } $_->{part_number} = $i; compute_device_name($_, $hd); if ($renumbered) { will_tell_kernel($hd, add => $_, 'delay_add'); } $i++; } } #- try to figure what the windobe drive letter could be! # #- first verify there's at least one primary dos partition, otherwise it #- means it is a secondary disk and all will be false :( #- my ($c, @others) = grep { isFat_or_NTFS($_) } @{$hd->{primary}{normal}}; $i = ord 'C';<?php /** * Adjust username_clean column. * * You should make a backup from your users table in case something goes wrong */ die("Please read the first lines of this script for instructions on how to enable it"); set_time_limit(0); define('IN_PHPBB', true); $phpbb_root_path = './../'; $phpEx = substr(strrchr(__FILE__, '.'), 1); include($phpbb_root_path . 'common.'.$phpEx); // Start session management $user->session_begin(); $auth->acl($user->data); $user->setup(); $echos = 0; $sql = 'SELECT user_id, username FROM ' . USERS_TABLE; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $sql = 'UPDATE ' . USERS_TABLE . " SET username_clean = '" . $db->sql_escape(utf8_clean_string($row['username'])) . "' WHERE user_id = " . $row['user_id']; $db->sql_query($sql); if ($echos > 200) { echo '<br />' . "\n"; $echos = 0; } echo '.'; $echos++; flush(); } $db->sql_freeresult($result); echo 'FINISHED'; // Done $db->sql_close(); ?>