}
static grub_err_t
-grub_affs_mtime (grub_device_t device, grub_int32_t *t)
+grub_affs_mtime (grub_device_t device, grub_int64_t *t)
{
struct grub_affs_data *data;
grub_disk_t disk = device->disk;
/* Get mtime. */
static grub_err_t
-grub_ext2_mtime (grub_device_t device, grub_int32_t *tm)
+grub_ext2_mtime (grub_device_t device, grub_int64_t *tm)
{
struct grub_ext2_data *data;
grub_disk_t disk = device->disk;
* https://docs.microsoft.com/en-us/windows/win32/fileio/exfat-specification
*/
static int
-grub_exfat_timestamp (grub_uint32_t field, grub_uint8_t msec, grub_int32_t *nix) {
+grub_exfat_timestamp (grub_uint32_t field, grub_uint8_t msec, grub_int64_t *nix) {
struct grub_datetime datetime = {
.year = (field >> 25) + 1980,
.month = (field & 0x01E00000) >> 21,
* https://www.ecma-international.org/publications/files/ECMA-ST/Ecma-107.pdf
*/
static int
-grub_fat_timestamp (grub_uint16_t time, grub_uint16_t date, grub_int32_t *nix) {
+grub_fat_timestamp (grub_uint16_t time, grub_uint16_t date, grub_int64_t *nix) {
struct grub_datetime datetime = {
.year = (date >> 9) + 1980,
.month = (date & 0x01E0) >> 5,
}
static grub_err_t
-grub_hfs_mtime (grub_device_t device, grub_int32_t *tm)
+grub_hfs_mtime (grub_device_t device, grub_int64_t *tm)
{
struct grub_hfs_data *data;
/* Get mtime. */
static grub_err_t
-grub_hfsplus_mtime (grub_device_t device, grub_int32_t *tm)
+grub_hfsplus_mtime (grub_device_t device, grub_int64_t *tm)
{
struct grub_hfsplus_data *data;
grub_disk_t disk = device->disk;
\f
static grub_err_t
-iso9660_to_unixtime (const struct grub_iso9660_date *i, grub_int32_t *nix)
+iso9660_to_unixtime (const struct grub_iso9660_date *i, grub_int64_t *nix)
{
struct grub_datetime datetime;
}
static int
-iso9660_to_unixtime2 (const struct grub_iso9660_date2 *i, grub_int32_t *nix)
+iso9660_to_unixtime2 (const struct grub_iso9660_date2 *i, grub_int64_t *nix)
{
struct grub_datetime datetime;
/* Get writing time of filesystem. */
static grub_err_t
-grub_iso9660_mtime (grub_device_t device, grub_int32_t *timebuf)
+grub_iso9660_mtime (grub_device_t device, grub_int64_t *timebuf)
{
struct grub_iso9660_data *data;
grub_disk_t disk = device->disk;
/* Get mtime. */
static grub_err_t
-grub_nilfs2_mtime (grub_device_t device, grub_int32_t * tm)
+grub_nilfs2_mtime (grub_device_t device, grub_int64_t * tm)
{
struct grub_nilfs2_data *data;
grub_disk_t disk = device->disk;
}
static grub_err_t
-grub_squash_mtime (grub_device_t dev, grub_int32_t *tm)
+grub_squash_mtime (grub_device_t dev, grub_int64_t *tm)
{
struct grub_squash_data *data = 0;
/* Get mtime. */
static grub_err_t
-grub_ufs_mtime (grub_device_t device, grub_int32_t *tm)
+grub_ufs_mtime (grub_device_t device, grub_int64_t *tm)
{
struct grub_ufs_data *data = 0;
}
static grub_err_t
-zfs_mtime (grub_device_t device, grub_int32_t *mt)
+zfs_mtime (grub_device_t device, grub_int64_t *mt)
{
struct grub_zfs_data *data;
grub_zfs_endian_t ub_endian = GRUB_ZFS_UNKNOWN_ENDIAN;
#include <grub/datetime.h>
#include <grub/i18n.h>
+#include <grub/misc.h>
+#include <grub/mm.h>
static const char *const grub_weekday_names[] =
{
void
-grub_unixtime2datetime (grub_int32_t nix, struct grub_datetime *datetime)
+grub_unixtime2datetime (grub_int64_t nix, struct grub_datetime *datetime)
{
int i;
grub_uint8_t months[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
unsigned days;
/* Seconds into current day. */
unsigned secs_in_day;
+
/* Transform C divisions and modulos to mathematical ones */
if (nix < 0)
- days_epoch = -(((unsigned) (SECPERDAY-nix-1)) / SECPERDAY);
+ /*
+ * The result of division here shouldn't be larger than GRUB_INT_MAX.
+ * So, it's safe to store the result back in an int.
+ */
+ days_epoch = -(grub_divmod64 (((grub_int64_t) (SECPERDAY) - nix - 1), SECPERDAY, NULL));
else
- days_epoch = ((unsigned) nix) / SECPERDAY;
+ days_epoch = grub_divmod64 (nix, SECPERDAY, NULL);
+
secs_in_day = nix - days_epoch * SECPERDAY;
days = days_epoch + 69 * DAYSPERYEAR + 17;
grub_err_t err;
struct grub_net_bootp_packet *pack;
struct grub_datetime date;
- grub_int32_t t = 0;
+ grub_int64_t t = 0;
struct grub_net_buff *nb;
struct udphdr *udph;
grub_net_network_level_address_t target;
}
if (fs->fs_mtime)
{
- grub_int32_t tm;
+ grub_int64_t tm;
struct grub_datetime datetime;
(fs->fs_mtime) (dev, &tm);
if (grub_errno == GRUB_ERR_NONE)
sleep_test (void)
{
struct grub_datetime st, en;
- grub_int32_t stu = 0, enu = 0;
+ grub_int64_t stu = 0, enu = 0;
int is_delayok;
grub_test_assert (!grub_get_datetime (&st), "Couldn't retrieve start time");
grub_millisleep (10000);
if (enu - stu >= 15 && enu - stu <= 17)
is_delayok = 1;
#endif
- grub_test_assert (is_delayok, "Interval out of range: %d", enu-stu);
-
+ grub_test_assert (is_delayok, "Interval out of range: %" PRIdGRUB_INT64_T, enu - stu);
}
GRUB_FUNCTIONAL_TEST (sleep_test, sleep_test);
int grub_get_weekday (struct grub_datetime *datetime);
const char *grub_get_weekday_name (struct grub_datetime *datetime);
-void grub_unixtime2datetime (grub_int32_t nix,
+void grub_unixtime2datetime (grub_int64_t nix,
struct grub_datetime *datetime);
static inline int
-grub_datetime2unixtime (const struct grub_datetime *datetime, grub_int32_t *nix)
+grub_datetime2unixtime (const struct grub_datetime *datetime, grub_int64_t *nix)
{
grub_int32_t ret;
int y4, ay;
unsigned mtimeset:1;
unsigned case_insensitive:1;
unsigned inodeset:1;
- grub_int32_t mtime;
+ grub_int64_t mtime;
grub_uint64_t inode;
};
grub_err_t (*fs_uuid) (grub_device_t device, char **uuid);
/* Get writing time of filesystem. */
- grub_err_t (*fs_mtime) (grub_device_t device, grub_int32_t *timebuf);
+ grub_err_t (*fs_mtime) (grub_device_t device, grub_int64_t *timebuf);
#ifdef GRUB_UTIL
/* Determine sectors available for embedding. */