diff --git a/db/Image.pm.in b/db/Image.pm.in index ca6938d31c979b10e4fe8f7938fe4f7a0705aa2f..2def9f6332ce6c7585aadca354ed48b85060a531 100644 --- a/db/Image.pm.in +++ b/db/Image.pm.in @@ -205,6 +205,38 @@ sub ActiveImages($) return \@result; } +# +# Return a list of all images of the given format for the given pid. +# If format is NULL, return all formats. If pid is NULL, return for all pids. +# List is names of the form "pid/imagename". +# +sub ListAll($$$) +{ + my ($class, $format, $pid); + my @result = (); + + my $clause = ""; + if (defined($format) && $format =~ /^([-\w]+)$/) { + $clause .= ($clause ? " and" : "where"); + $clause .= " format='$1'"; + } + if (defined($pid) && $pid =~ /^([-\w]+)$/) { + $clause .= ($clause ? " and" : "where"); + $clause .= " pid='$1'"; + } + + my $query_result = + DBQueryWarn("select pid,imagename from images $clause ". + "order by pid,imagename"); + if ($query_result) { + while (my ($pid,$name) = $query_result->fetchrow_array()) { + push(@result, "$pid/$name"); + } + } + + return @result; +} + # # Refresh a class instance by reloading from the DB. # @@ -829,6 +861,31 @@ sub UnLockTables($) return 0; } +# +# Return updated time for image as a UNIX timestamp via the passed ref. +# Return 0 on success, non-zero otherwise. +# +sub GetUpdate($$) +{ + my ($self,$stampp) = @_; + + # Must be a real reference. + return -1 + if (! ref($self)); + + my $imageid = $self->imageid(); + + my $result = DBQueryWarn("select UNIX_TIMESTAMP(updated) from images ". + "where imageid='$imageid'"); + if ($result && $result->numrows) { + my ($stamp) = $result->fetchrow_array(); + $$stampp = $stamp; + return 0; + } + + return -1; +} + # # Mark the update time in the record, # @@ -893,6 +950,29 @@ sub SetHash($$) return 0; } +# +# Set the sector range of an image. +# +sub SetRange($$$;$) +{ + my ($self,$start,$end,$ssize) = @_; + + # Must be a real reference. + return -1 + if (! ref($self)); + + my $imageid = $self->imageid(); + $ssize = 512 + if (!defined($ssize)); + + return -1 + if (! DBQueryWarn("update images set ". + " lba_low=$start,lba_high=$end,lba_size=$ssize ". + "where imageid='$imageid'")); + + return 0; +} + # # Lock and Unlock # diff --git a/sql/database-create.sql b/sql/database-create.sql index ef5d07369c3db95e6f32382605a1e375d39fb927..2a439594844a46ab6ea03faef7f77fcc6ddc5869 100644 --- a/sql/database-create.sql +++ b/sql/database-create.sql @@ -1926,6 +1926,9 @@ CREATE TABLE `images` ( `auth_key` varchar(512) default NULL, `decryption_key` varchar(256) default NULL, `hash` varchar(64) default NULL, + `lba_low` bigint(20) unsigned NOT NULL default '0', + `lba_high` bigint(20) unsigned NOT NULL default '0', + `lba_size` int(10) unsigned NOT NULL default '512', `locked` datetime default NULL, `locker_pid` int(11) default '0', `metadata_url` tinytext, diff --git a/sql/database-fill.sql b/sql/database-fill.sql index 63efe1d25f6811537ee9ebd18ae8723d05941315..01482a84557f7a8430a9825e67af63d41fd8aa74 100644 --- a/sql/database-fill.sql +++ b/sql/database-fill.sql @@ -1057,6 +1057,9 @@ REPLACE INTO table_regex VALUES ('images','max_concurrent','text','redirect','de REPLACE INTO table_regex VALUES ('images','reboot_waittime','text','redirect','default:int',0,0,NULL); REPLACE INTO table_regex VALUES ('images','format','text','regex','^[-\\w]+$',1,8,NULL); REPLACE INTO table_regex VALUES ('images','hash','text','regex','^[\\w]+$',16,64,NULL); +REPLACE INTO `table_regex` VALUES ('images','lba_low','int','redirect','default:bigint',0,0,NULL); +REPLACE INTO `table_regex` VALUES ('images','lba_high','int','redirect','default:bigint',0,0,NULL); +REPLACE INTO `table_regex` VALUES ('images','lba_size','int','redirect','default:int',0,0,NULL); REPLACE INTO table_regex VALUES ('node_types','new_type','text','redirect','default:tinytext',0,0,NULL); REPLACE INTO table_regex VALUES ('node_types','node_type','text','regex','^[-\\w]+$',1,30,NULL); REPLACE INTO table_regex VALUES ('node_types','class','text','regex','^[\\w]+$',1,30,NULL); @@ -1268,7 +1271,7 @@ REPLACE INTO table_regex VALUES ('default','boolean','int','regex','^(0|1)$',0,1 REPLACE INTO table_regex VALUES ('default','tinyuint','int','regex','^[\\d]+$',0,255,'Default regex for tiny int fields. Allow any standard ascii integer, but no binary data'); REPLACE INTO table_regex VALUES ('default','int','int','regex','^[\\d]+$',-2147483648,2147483647,'Default regex for int fields. Allow any standard ascii integer, but no binary data'); REPLACE INTO table_regex VALUES ('default','float','float','regex','^[+-]?\\ *(\\d+(\\.\\d*)?|\\.\\d+)([eE][+-]?\\d+)?$',-2147483648,2147483647,'Default regex for float fields. Allow any digits and the decimal point'); - +REPLACE INTO table_regex VALUES ('default','bigint','int','regex','^[\\d]+$',0,0,'Allow any ascii 64-bit integer'); REPLACE INTO table_regex VALUES ('default','tinytext_utf8','text','regex','^(?:[\\x20-\\x7E]|[\\xC2-\\xDF][\\x80-\\xBF]|\\xE0[\\xA0-\\xBF][\\x80-\\xBF]|[\\xE1-\\xEC\\xEE\\xEF][\\x80-\\xBF]{2}|\\xED[\\x80-\\x9F][\\x80-\\xBF])*$',0,256,'adopted from http://www.w3.org/International/questions/qa-forms-utf-8.en.php'); REPLACE INTO table_regex VALUES ('default','text_utf8','text','regex','^(?:[\\x20-\\x7E]|[\\xC2-\\xDF][\\x80-\\xBF]|\\xE0[\\xA0-\\xBF][\\x80-\\xBF]|[\\xE1-\\xEC\\xEE\\xEF][\\x80-\\xBF]{2}|\\xED[\\x80-\\x9F][\\x80-\\xBF])*$',0,65535,'adopted from http://www.w3.org/International/questions/qa-forms-utf-8.en.php'); REPLACE INTO table_regex VALUES ('default','fulltext_utf8','text','regex','^(?:[\\x09\\x0A\\x0D\\x20-\\x7E]|[\\xC2-\\xDF][\\x80-\\xBF]|\\xE0[\\xA0-\\xBF][\\x80-\\xBF]|[\\xE1-\\xEC\\xEE\\xEF][\\x80-\\xBF]{2}|\\xED[\\x80-\\x9F][\\x80-\\xBF])*$',0,65535,'adopted from http://www.w3.org/International/questions/qa-forms-utf-8.en.php'); diff --git a/sql/updates/4/390 b/sql/updates/4/390 new file mode 100644 index 0000000000000000000000000000000000000000..511d6b93700114d413eb97a8e026306a1a3f0ceb --- /dev/null +++ b/sql/updates/4/390 @@ -0,0 +1,47 @@ +# +# Image state info for tracking uncompressed size of image. +# +use strict; +use libdb; + +sub DoUpdate($$$) +{ + my ($dbhandle, $dbname, $version) = @_; + + if (!DBSlotExists("images", "lba_low")) { + DBQueryFatal("ALTER TABLE images ADD ". + "`lba_low` bigint unsigned NOT NULL default '0'". + " AFTER hash"); + DBQueryFatal("ALTER TABLE images ADD ". + "`lba_high` bigint unsigned NOT NULL default '0'". + " AFTER lba_low"); + DBQueryFatal("ALTER TABLE images ADD ". + "`lba_size` int(10) unsigned NOT NULL default '512' ". + " AFTER lba_high"); + + # + # Since these are the first "bigint" types in the DB, add a regex + # for them. + # XXX cannot set min/max since the table_regex columns for those + # are type "int"! + # + DBQueryFatal("REPLACE INTO table_regex VALUES ". + "('default','bigint','int','regex',". + "'^[\\\\d]+\$',0,0,'Allow any ascii 64-bit integer')"); + + DBQueryFatal("REPLACE INTO table_regex VALUES ". + "('images','lba_low','int','redirect',". + "'default:bigint',0,0,NULL)"); + DBQueryFatal("REPLACE INTO table_regex VALUES ". + "('images','lba_high','int','redirect',". + "'default:bigint',0,0,NULL)"); + DBQueryFatal("REPLACE INTO table_regex VALUES ". + "('images','lba_size','int','redirect',". + "'default:int',0,0,NULL)"); + } + return 0; +} + +# Local Variables: +# mode:perl +# End: