How to get current time & date for timestamps for DOS-FS files

How to get current time & date for timestamps for DOS-FS files

Post by Manfred Fisch » Wed, 01 Mar 2000 04:00:00



I'm working with a MV2700 PowerPC board with a DOS FS on a harddisk.
Is there a possibilty to get current time and date as timestamp for
new created or changed files.

Is there a special mechanism to apply a timestamp automatically on
files.

 
 
 

How to get current time & date for timestamps for DOS-FS files

Post by Harvey Taylo » Wed, 01 Mar 2000 04:00:00



> I'm working with a MV2700 PowerPC board with a DOS FS on a harddisk.
> Is there a possibilty to get current time and date as timestamp for
> new created or changed files.

> Is there a special mechanism to apply a timestamp automatically on
> files.

        Yes look at the dosFsLib docs.  The function is called
        dosFsDateTimeInstall().

        It requires a handler function which typically looks like:

STATUS DateTimeFunc(DOS_DATE_TIME * pDosDateTime)
{
        time_t tNow = time(NULL);
        struct tm* t = localtime(&tNow);

        pDosDateTime->dosdt_year   = t->tm_year ;
        pDosDateTime->dosdt_year += ( (t->tm_year > 70) ? 1900 : 2000);
        pDosDateTime->dosdt_month  = t->tm_mon + 1  ; /* Map 0..11 to 1..12 */
        pDosDateTime->dosdt_day    = t->tm_mday ;
        pDosDateTime->dosdt_hour   = t->tm_hour ;
        pDosDateTime->dosdt_minute = t->tm_min  ;
        pDosDateTime->dosdt_second = t->tm_sec  ;

        return( OK ) ;          

Quote:}

        You should probably add error handling to taste.
        Oh and of cousre you must have done a clock_settime() to
        make this work.

<l8r>
-het

---
"Assembly of Japanese bicycle require great peace of mind."
        - Instruction manual mentioned by R. Pirsig



 
 
 

How to get current time & date for timestamps for DOS-FS files

Post by Zakelij » Sat, 04 Mar 2000 04:00:00


Harvey.

In the message below u mention that u should use clock_settime() to set the
system time.
That's all nice etc. but where can i get for example the time from the bios.

What i like to do:
- having a standalone (PCPEntium boarded) VXWorks machine which could
autoboot without interference from the outside.

(or rather if i tried to do a reboot i would want to move to the location of
the machine to reset the time and date).

Do u   (or anyone else) knows how to set the time on such a standalone
system.

thx.. Leendert Biemans



> > I'm working with a MV2700 PowerPC board with a DOS FS on a harddisk.
> > Is there a possibilty to get current time and date as timestamp for
> > new created or changed files.

> > Is there a special mechanism to apply a timestamp automatically on
> > files.

> Yes look at the dosFsLib docs.  The function is called
> dosFsDateTimeInstall().

> It requires a handler function which typically looks like:

> STATUS DateTimeFunc(DOS_DATE_TIME * pDosDateTime)
> {
> time_t tNow = time(NULL);
> struct tm* t = localtime(&tNow);

> pDosDateTime->dosdt_year   = t->tm_year ;
> pDosDateTime->dosdt_year += ( (t->tm_year > 70) ? 1900 : 2000);
> pDosDateTime->dosdt_month  = t->tm_mon + 1  ; /* Map 0..11 to 1..12 */
> pDosDateTime->dosdt_day    = t->tm_mday ;
> pDosDateTime->dosdt_hour   = t->tm_hour ;
> pDosDateTime->dosdt_minute = t->tm_min  ;
> pDosDateTime->dosdt_second = t->tm_sec  ;

> return( OK ) ;
> }

> You should probably add error handling to taste.
> Oh and of cousre you must have done a clock_settime() to
> make this work.

> <l8r>
> -het

> ---
> "Assembly of Japanese bicycle require great peace of mind."
> - Instruction manual mentioned by R. Pirsig



 
 
 

How to get current time & date for timestamps for DOS-FS files

Post by Harvey Taylo » Sat, 04 Mar 2000 04:00:00



> In the message below u mention that u should use clock_settime() to set the
> system time.
> That's all nice etc. but where can i get for example the time from the bios.

Hi  Leendert,
        I am not familiar with the MV2700 PowerPC, but it depends upon
        your particular RTC chip.  If it uses something different, you
        will have to write some RTC reading code yourself (or bug the
        MV2700 supplier).  If it looks like a generic PC, you can use
        Linux source (or something like snippets.org).  
        I'm sorry but I don't happen to have a sample to hand.

        Anybody?
<cordially>
-het

> What i like to do:
> - having a standalone (PCPEntium boarded) VXWorks machine which could
> autoboot without interference from the outside.

> (or rather if i tried to do a reboot i would want to move to the location of
> the machine to reset the time and date).

> Do u   (or anyone else) knows how to set the time on such a standalone
> system.

> thx.. Leendert Biemans




> > > I'm working with a MV2700 PowerPC board with a DOS FS on a harddisk.
> > > Is there a possibilty to get current time and date as timestamp for
> > > new created or changed files.

> > > Is there a special mechanism to apply a timestamp automatically on
> > > files.

> > Yes look at the dosFsLib docs.  The function is called
> > dosFsDateTimeInstall().

> > It requires a handler function which typically looks like:

> > STATUS DateTimeFunc(DOS_DATE_TIME * pDosDateTime)
> > {
> > time_t tNow = time(NULL);
> > struct tm* t = localtime(&tNow);

> > pDosDateTime->dosdt_year   = t->tm_year ;
> > pDosDateTime->dosdt_year += ( (t->tm_year > 70) ? 1900 : 2000);
> > pDosDateTime->dosdt_month  = t->tm_mon + 1  ; /* Map 0..11 to 1..12 */
> > pDosDateTime->dosdt_day    = t->tm_mday ;
> > pDosDateTime->dosdt_hour   = t->tm_hour ;
> > pDosDateTime->dosdt_minute = t->tm_min  ;
> > pDosDateTime->dosdt_second = t->tm_sec  ;

> > return( OK ) ;
> > }

> > You should probably add error handling to taste.
> > Oh and of cousre you must have done a clock_settime() to
> > make this work.

> > <l8r>
> > -het

> > ---
> > "Assembly of Japanese bicycle require great peace of mind."
> > - Instruction manual mentioned by R. Pirsig



--

---
"Assembly of Japanese bicycle require great peace of mind."
        - Instruction manual mentioned by R. Pirsig


 
 
 

How to get current time & date for timestamps for DOS-FS files

Post by Manfred Fisch » Wed, 08 Mar 2000 04:00:00


Thanks Harvey & Leendert

Quote:

> Yes look at the dosFsLib docs.  The function is called
> dosFsDateTimeInstall().

> It requires a handler function which typically looks like:

> STATUS DateTimeFunc(DOS_DATE_TIME * pDosDateTime)
> {
> time_t tNow = time(NULL);
> struct tm* t = localtime(&tNow);

> pDosDateTime->dosdt_year   = t->tm_year ;
> pDosDateTime->dosdt_year += ( (t->tm_year > 70) ? 1900 : 2000);
> pDosDateTime->dosdt_month  = t->tm_mon + 1  ; /* Map 0..11 to 1..12 */
> pDosDateTime->dosdt_day    = t->tm_mday ;
> pDosDateTime->dosdt_hour   = t->tm_hour ;
> pDosDateTime->dosdt_minute = t->tm_min  ;
> pDosDateTime->dosdt_second = t->tm_sec  ;

> return( OK ) ;
> }

For the MV2700 PowerPC a solution for getting the current time & date
will be:

int getRTC(void)
{
  struct tm currentTime;
  struct timespec ansiTime;

  /* read real time clock from nvram: */
  currentTime.tm_year = BCDToInt(sysNvRead((ULONG) 0x1FFF));
  currentTime.tm_year += (currentTime.tm_year < 70 ? 100 : 0);
  currentTime.tm_mon = BCDToInt(sysNvRead((ULONG) 0x1FFE)) - 1;
  currentTime.tm_mday = BCDToInt(sysNvRead((ULONG) 0x1FFD));
  currentTime.tm_hour = BCDToInt(sysNvRead((ULONG) 0x1FFB));
  currentTime.tm_min = BCDToInt(sysNvRead((ULONG) 0x1FFA));
  currentTime.tm_sec = BCDToInt(sysNvRead((ULONG) 0x1FF9));
  currentTime.tm_isdst = 0;

  /* convert in calendar time */
  if ((ansiTime.tv_sec = mktime(&currentTime)) == ERROR)
    return(ERROR);
  ansiTime.tv_nsec = 0;

  /* set software clock */
  clock_settime(CLOCK_REALTIME, &ansiTime);

  return(OK);

Quote:}

int BCDToInt(int BCD)
{
  return ((BCD >> 4) * 10) + (BCD & 0x0F);

Quote:}

But now I have a new problem: How to set the RTC in nvram?

vxWorks provides a sysNvWrite() function, but there is no example or
advice how to use this function! I tried to do this with the following
code but it does not work:

int setRTC(void)
{
  time_t ansiTime = time(NULL);
  struct tm *currentTime = localtime(&ansiTime);

  sysNvWrite((ULONG) 0x1FFF, (UCHAR)intToBCD(currentTime->tm_year %
100));
  sysNvWrite((ULONG) 0x1FFE, (UCHAR)intToBCD(currentTime->tm_mon+1));
  sysNvWrite((ULONG) 0x1FFD, (UCHAR)intToBCD(currentTime->tm_mday));
  sysNvWrite((ULONG) 0x1FFB, (UCHAR)intToBCD(currentTime->tm_hour));
  sysNvWrite((ULONG) 0x1FFA, (UCHAR)intToBCD(currentTime->tm_min));
  sysNvWrite((ULONG) 0x1FF9, (UCHAR)intToBCD(currentTime->tm_sec));

  return(OK);

Quote:}

int intToBCD(int n)
{
  if ((n > 99) || (n < 0))
    return(0);

  return ((n / 10) | (n % 10));

Quote:}

Where is my problem?

Manfred

 
 
 

How to get current time & date for timestamps for DOS-FS files

Post by Harvey Taylo » Wed, 08 Mar 2000 04:00:00



>[...]
> But now I have a new problem: How to set the RTC in nvram?
>[...]
>sysNvWrite((ULONG) 0x1FFF, (UCHAR)intToBCD(currentTime->tm_year % 100));

        There may be some bit you have to set somewhere before
        you can write.

        What hardware exactly is located at 0x01FFF?
        Is it NVRAM or is it an RTC?   NVRAM and RTC?
        Find out what kind of hardware it is.  Glomm on over to
        that manufacturer's web site.  Dig up the docs on
        that RTC.

<have fun>
-het

---
"Assembly of Japanese bicycle require great peace of mind."
        - Instruction manual mentioned by R. Pirsig


 
 
 

How to get current time & date for timestamps for DOS-FS files

Post by Charlie Grame » Wed, 22 Mar 2000 04:00:00


Manfred:

The RTC write enable bit is 0x80 at NVRAM location 0x1ff8.  Check out

    http://us.st.com/stonline/books/pdf/docs/7001.pdf

or, if the document name has changed, go to

    http://us/st/com

search for M48T59, and select the data sheet.

Charlie Grames
The Boeing Company


> Thanks Harvey & Leendert

> > Yes look at the dosFsLib docs.  The function is called
> > dosFsDateTimeInstall().

> > It requires a handler function which typically looks like:

> > STATUS DateTimeFunc(DOS_DATE_TIME * pDosDateTime)
> > {
> > time_t tNow = time(NULL);
> > struct tm* t = localtime(&tNow);

> > pDosDateTime->dosdt_year   = t->tm_year ;
> > pDosDateTime->dosdt_year += ( (t->tm_year > 70) ? 1900 : 2000);
> > pDosDateTime->dosdt_month  = t->tm_mon + 1  ; /* Map 0..11 to 1..12 */
> > pDosDateTime->dosdt_day    = t->tm_mday ;
> > pDosDateTime->dosdt_hour   = t->tm_hour ;
> > pDosDateTime->dosdt_minute = t->tm_min  ;
> > pDosDateTime->dosdt_second = t->tm_sec  ;

> > return( OK ) ;
> > }

> For the MV2700 PowerPC a solution for getting the current time & date
> will be:

> int getRTC(void)
> {
>   struct tm currentTime;
>   struct timespec ansiTime;

>   /* read real time clock from nvram: */
>   currentTime.tm_year = BCDToInt(sysNvRead((ULONG) 0x1FFF));
>   currentTime.tm_year += (currentTime.tm_year < 70 ? 100 : 0);
>   currentTime.tm_mon = BCDToInt(sysNvRead((ULONG) 0x1FFE)) - 1;
>   currentTime.tm_mday = BCDToInt(sysNvRead((ULONG) 0x1FFD));
>   currentTime.tm_hour = BCDToInt(sysNvRead((ULONG) 0x1FFB));
>   currentTime.tm_min = BCDToInt(sysNvRead((ULONG) 0x1FFA));
>   currentTime.tm_sec = BCDToInt(sysNvRead((ULONG) 0x1FF9));
>   currentTime.tm_isdst = 0;

>   /* convert in calendar time */
>   if ((ansiTime.tv_sec = mktime(&currentTime)) == ERROR)
>     return(ERROR);
>   ansiTime.tv_nsec = 0;

>   /* set software clock */
>   clock_settime(CLOCK_REALTIME, &ansiTime);

>   return(OK);
> }

> int BCDToInt(int BCD)
> {
>   return ((BCD >> 4) * 10) + (BCD & 0x0F);
> }

> But now I have a new problem: How to set the RTC in nvram?

> vxWorks provides a sysNvWrite() function, but there is no example or
> advice how to use this function! I tried to do this with the following
> code but it does not work:

> int setRTC(void)
> {
>   time_t ansiTime = time(NULL);
>   struct tm *currentTime = localtime(&ansiTime);

>   sysNvWrite((ULONG) 0x1FFF, (UCHAR)intToBCD(currentTime->tm_year %
> 100));
>   sysNvWrite((ULONG) 0x1FFE, (UCHAR)intToBCD(currentTime->tm_mon+1));
>   sysNvWrite((ULONG) 0x1FFD, (UCHAR)intToBCD(currentTime->tm_mday));
>   sysNvWrite((ULONG) 0x1FFB, (UCHAR)intToBCD(currentTime->tm_hour));
>   sysNvWrite((ULONG) 0x1FFA, (UCHAR)intToBCD(currentTime->tm_min));
>   sysNvWrite((ULONG) 0x1FF9, (UCHAR)intToBCD(currentTime->tm_sec));

>   return(OK);
> }

> int intToBCD(int n)
> {
>   if ((n > 99) || (n < 0))
>     return(0);

>   return ((n / 10) | (n % 10));
> }

> Where is my problem?

> Manfred

 
 
 

1. date&time vs timestamp question

I've been asked what the best way for storing dates&times in a postgresql database.

Anyone have a summary of the advantages/disadvantages of
   create table a (dat date, tim time, ...);
vs.
   create table b (dattim timestamp, ...);

The table will be kinda large, perhaps 10 million rows, and
many queries would be searching creating aggregate information
of events that happened on a particular day.  Perhaps
  select min(price),thing from table where dat='2002-01-01' group by thing;
will be a typical query.  Sometimes but rarely will aggregate queries want
sub-day resolution, but I need the time because the total order is important.

In my mind..

  Advantages for a separate date, time:
       * somewhat nicer query syntax...
           select whatever from a where dat='2003-01-01';
         vs
           select whatever from a where dattim>='2003-01-01' and dattim<'2003-01-02;
         or
           select whatever from a where date_trunc('day',dattim)='2003-01-01'

       * Could analyze generate have meaningful statistics
         with a separate date column for the optimizer?  For example, the
         most-common values in pg_stats is probably less useful for timestamps
         than dates.

  Advantages for a combined timestamp:
       * looks like a few bytes smaller.
       * slightly easier to isolate a specific event based on time.

Any other advantages/disadvantages/opinions welcome.

   Ron

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

2. Fax and V29

3. Using INDEX on date/time values // Re: how to select a time frame on timestamp rows.

4. This one can be checked out too.

5. Read, record (write to a db) and display current system time & date

6. NE2000 vs. NE2100

7. Implications of date/timestamp from multiple time zones

8. FS: Sparc 4s and Sparc 5s pretty cheap

9. Date and Time or Timestamp?

10. getting the current date

11. SELECT timestamp('2001-06-12'::date - '2000-06-12'::date)

12. Original Date & time in a zip file created with pkzip 2.04

13. Get a File's Date & Time stamp