debuggers.hg
annotate xen/common/time.c @ 22855:1d1eec7e1fb4
xl: Perform minimal validation of virtual disk file while parsing config file
This patch performs some very basic validation on the virtual disk
file passed through the config file. This validation ensures that we
don't go too far with the initialization like spawn qemu and more
while there could be some potentially fundamental issues.
[ Patch fixed up to work with PHYSTYPE_EMPTY 22808:6ec61438713a -iwj ]
Signed-off-by: Kamala Narasimhan <kamala.narasimhan@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
This patch performs some very basic validation on the virtual disk
file passed through the config file. This validation ensures that we
don't go too far with the initialization like spawn qemu and more
while there could be some potentially fundamental issues.
[ Patch fixed up to work with PHYSTYPE_EMPTY 22808:6ec61438713a -iwj ]
Signed-off-by: Kamala Narasimhan <kamala.narasimhan@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
author | Kamala Narasimhan <kamala.narasimhan@gmail.com> |
---|---|
date | Tue Jan 25 18:09:49 2011 +0000 (2011-01-25) |
parents | 459f35d8cac4 |
children |
rev | line source |
---|---|
kfraser@11855 | 1 /****************************************************************************** |
kfraser@11855 | 2 * time.c |
kfraser@11855 | 3 * |
kfraser@11855 | 4 * This program is free software; you can redistribute it and/or modify |
kfraser@11855 | 5 * it under the terms of the GNU General Public License as published by |
kfraser@11855 | 6 * the Free Software Foundation; either version 2 of the License, or |
kfraser@11855 | 7 * (at your option) any later version. |
kfraser@11855 | 8 * |
kfraser@11855 | 9 * This program is distributed in the hope that it will be useful, |
kfraser@11855 | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
kfraser@11855 | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
kfraser@11855 | 12 * GNU General Public License for more details. |
kfraser@11855 | 13 * |
kfraser@11855 | 14 * You should have received a copy of the GNU General Public License |
kfraser@11855 | 15 * along with this program; if not, write to the Free Software |
kfraser@11855 | 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
kfraser@11855 | 17 */ |
kfraser@11855 | 18 |
kfraser@11855 | 19 #include <xen/config.h> |
kfraser@11855 | 20 #include <xen/time.h> |
kfraser@11855 | 21 |
kfraser@11855 | 22 /* Nonzero if YEAR is a leap year (every 4 years, |
kfraser@11855 | 23 except every 100th isn't, and every 400th is). */ |
kfraser@11855 | 24 #define __isleap(year) \ |
kfraser@11855 | 25 ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0)) |
kfraser@11855 | 26 |
kfraser@11855 | 27 /* How many days are in each month. */ |
kfraser@11855 | 28 const unsigned short int __mon_lengths[2][12] = { |
kfraser@11855 | 29 /* Normal years. */ |
kfraser@11855 | 30 {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, |
kfraser@11855 | 31 /* Leap years. */ |
kfraser@11855 | 32 {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} |
kfraser@11855 | 33 }; |
kfraser@11855 | 34 |
kfraser@11855 | 35 #define SECS_PER_HOUR (60 * 60) |
kfraser@11855 | 36 #define SECS_PER_DAY (SECS_PER_HOUR * 24) |
kfraser@11855 | 37 |
kfraser@11855 | 38 struct tm gmtime(unsigned long t) |
kfraser@11855 | 39 { |
kfraser@11855 | 40 struct tm tbuf; |
kfraser@11855 | 41 long days, rem; |
kfraser@11855 | 42 int y; |
kfraser@13158 | 43 const unsigned short int *ip; |
kfraser@11855 | 44 |
keir@21498 | 45 y = 1970; |
keir@21498 | 46 #ifdef __x86_64__ |
keir@21498 | 47 /* Allow the concept of time before 1970. 64-bit only; for 32-bit |
keir@21498 | 48 * time after 2038 seems more important than time before 1970. */ |
keir@21498 | 49 while ( t & (1UL<<39) ) |
keir@21498 | 50 { |
keir@21498 | 51 y -= 400; |
keir@21498 | 52 t += ((unsigned long)(365 * 303 + 366 * 97)) * SECS_PER_DAY; |
keir@21498 | 53 } |
keir@21498 | 54 t &= (1UL << 40) - 1; |
keir@21498 | 55 #endif |
keir@21498 | 56 |
kfraser@11855 | 57 days = t / SECS_PER_DAY; |
kfraser@11855 | 58 rem = t % SECS_PER_DAY; |
kfraser@11855 | 59 |
kfraser@11855 | 60 tbuf.tm_hour = rem / SECS_PER_HOUR; |
kfraser@11855 | 61 rem %= SECS_PER_HOUR; |
kfraser@11855 | 62 tbuf.tm_min = rem / 60; |
kfraser@11855 | 63 tbuf.tm_sec = rem % 60; |
kfraser@11855 | 64 /* January 1, 1970 was a Thursday. */ |
kfraser@11855 | 65 tbuf.tm_wday = (4 + days) % 7; |
kfraser@11855 | 66 if ( tbuf.tm_wday < 0 ) |
kfraser@11855 | 67 tbuf.tm_wday += 7; |
kfraser@11855 | 68 while ( days >= (rem = __isleap(y) ? 366 : 365) ) |
kfraser@11855 | 69 { |
kfraser@11855 | 70 ++y; |
kfraser@11855 | 71 days -= rem; |
kfraser@11855 | 72 } |
kfraser@11855 | 73 while ( days < 0 ) |
kfraser@11855 | 74 { |
kfraser@11855 | 75 --y; |
kfraser@11855 | 76 days += __isleap(y) ? 366 : 365; |
kfraser@11855 | 77 } |
kfraser@11855 | 78 tbuf.tm_year = y - 1900; |
kfraser@11855 | 79 tbuf.tm_yday = days; |
kfraser@13158 | 80 ip = (const unsigned short int *)__mon_lengths[__isleap(y)]; |
kfraser@11855 | 81 for ( y = 0; days >= ip[y]; ++y ) |
kfraser@11855 | 82 days -= ip[y]; |
kfraser@11855 | 83 tbuf.tm_mon = y; |
kfraser@11855 | 84 tbuf.tm_mday = days + 1; |
kfraser@11855 | 85 tbuf.tm_isdst = -1; |
kfraser@11855 | 86 |
kfraser@11855 | 87 return tbuf; |
kfraser@11855 | 88 } |