ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

stat() for ifs-files

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • stat() for ifs-files

    when using the stat() on an IFS-file we have 3 timestamp-values that can be used :
    - st_atime = last access time
    - st_mtime = last modified time
    - st_ctime = creation time

    those times should return us the number of seconds since 01.01.1970 00.00.00 in GMT

    the "atime" and "mtime "gives me correct values (1567543570)
    this converts correctly to Tuesday 3 September 2019 20:46:10

    but the "ctime" gives me a negative value (-2147483648) for the same file that has been created
    this converts to Friday 13 December 1901 20:45:52

    is there another logic to convert the ctime ? or is the ctime not reliable ?

    now we changed the code to use the "mtime" as a temporary solution
    but what if we really need to know the real creation date

    when checking the IFS-attributes the creation date is correct (in dutch) :

    Datum/tijd waarop gemaakt . . . . . . : 03/09/19 22:46:10
    Datum/tijdstip laatst geopend . . . . : 05/09/19 11:59:09
    Datum/tijdstip laatste wijziging . . . : 03/09/19 22:46:11
    Datum/tijdstip laatste kenmerkwijziging: 03/09/19 22:46:11

    thanks for any replies


  • #2
    I just checked the definition in the version of IFSIO_H from Scott Klement that I have.
    It is like this
    D st_ctime 10I 0

    This is a signed integer.
    My first thought was that it has to be an unsigned integer but it is not necessary here.
    -2147483648 has a hex representation of FFFF FFFF 8000 0000

    So no clues here.

    Try to check your definition of the data structure for the stat() api.

    Regards
    Peder

    Comment


    • #3
      i got my definition of those 3 time-definitions and the whol datastructure from the Scott-Klement-website too (https://www.scottklement.com/rpg/ifs_ebook/stat.html)
      so i'm using 3 variables defined as 10I 0 :

      PHP Code:
      D  statds         ds                   based(p_statds)
      D   st_mode                     10U 0                
      D   st_ino                      10U 0                
      D   st_nlink                     5U 0                
      D   st_pad                       2A                  
      D   st_uid                      10U 0                
      D   st_gid                      10U 0                
      D   st_size                     10I 0                
      D   st_atime                    10I 0                
      D   st_mtime                    10I 0                
      D   st_ctime                    10I 0                
      D   st_dev                      10U 0                
      D   st_blksize                  10U 0                
      D   st_allocsize                10U 0                
      D   st_objtype                  12A                  
      D   st_codepage                  5U 0                
      D   st_reserved1                62A                  
      D   st_ino_gen                  10U 0 

      Comment


      • #4
        Positions are the same as mine up till st_objtype
        In my definition the st_objtype is defined as a 11 character field followed by a 1 byte field called st_reserved3
        so it equals the size of 12 bytes for the st_objtype in your definition.

        Well, do you have the same problem with the other IFS files?
        Or is it just this file that gives you problems?

        Regards
        Peder

        Comment


        • #5
          i found a slightly different datastructure-description too yesterday in the Scott-Klement-documentation between
          https://www.scottklement.com/rpg/ifs_ebook/stat.html (the description i use with 12A)
          and
          https://www.scottklement.com/present...0the%20IFS.pdf (your description with 11A + 1byte)
          but i guess that won't make the difference here as the appear further on in the data-structure-description

          ----

          i just took another random file to do the test in a little test-program

          the (important) code from my test-program :

          PHP Code:
          h datedit(*dmydatfmt(*eurdecedit('0,')
          h actgrp(*new)                           
          h bnddir('STDFUNC')                      

           /
          copy src,ifsfpr

          d w_tmst_init     s               z   INZ
          (z'1970-01-01-00.00.00')
          d w_tmst_file     s               z                             
          d                                                               
          d full_b          s           1000A                             
          d mystat          s                   like
          (p_statds)            

           /
          free                                                   

            full_b 
          '/test/random.xml';                           

            if 
          ifs_stat(%trimr(full_b):%addr(mystat)) >= 0;        
              
          p_statds = %addr(mystat);                            

              
          w_tmst_file w_tmst_init + %seconds(st_atime);      
              
          z_text 'A ' + %char(w_tmst_file) +                 
                       
          '/' + %char(st_atime);                      
              
          write ltext;                                         

              
          w_tmst_file w_tmst_init + %seconds(st_mtime);      
              
          z_text 'M ' + %char(w_tmst_file) +                 
                       
          '/' + %char(st_mtime);                      
              
          write ltext;  

              
          w_tmst_file w_tmst_init + %seconds(st_ctime);
              
          z_text 'C ' + %char(w_tmst_file) +           
                       
          '/' + %char(st_ctime);                
              
          write ltext;                                   
            endif;                                           

            *
          inlr = *on;                                     
            return;                                          

           /
          end-free 

          in the included IFSFPR i have this :

          PHP Code:
          D ifs_stat        pr            10I 0 extproc('stat')      
          D  path                           *   value options(*string)
          D  buf                            *   value                

          D p_statds        s               
          *                  
          D  statds         ds                   based(p_statds)
          D   st_mode                     10U 0                
          D   st_ino                      10U 0                
          D   st_nlink                     5U 0                
          D   st_pad                       2A                  
          D   st_uid                      10U 0                
          D   st_gid                      10U 0                
          D   st_size                     10I 0                
          D   st_atime                    10I 0                
          D   st_mtime                    10I 0                
          D   st_ctime                    10I 0                
          D   st_dev                      10U 0                
          D   st_blksize                  10U 0
          D   st_allocsize                10U 0
          D   st_objtype                  12A  
          D   st_codepage                  5U 0
          D   st_reserved1                62A  
          D   st_ino_gen                  10U 0 

          the resulting output is this :
          PHP Code:
          A 2019-09-06-08.16.12.000000/1567757772
          M 2018
          -04-09-13.46.07.000000/1523281567
          C 1901
          -12-13-20.45.52.000000/-2147483648 
          so the result is the same for a random file too

          Comment


          • #6
            st_ctime is NOT the creation date... it is the "change date" and indicates the last time that someone changed the status of the file. (not to be confused with st_mtime which is the last time the data in the file was changed.)

            The stat() API does not return the creation date. If it is the creation date you are interested in, you will need to use the Qp0lGetAttr() API


            Comment


            • #7
              thanks for clearing that out scott
              the confusion (from my side) was because in windows the standard file attributes are creation / modification / access
              but ok ... an extra pair of glasses would have helped too

              i'll change my program by using Qp0lGetAttr()

              TICKET SOLVED

              Comment

              Working...
              X