• Subject: RE: Object/size listing on IFS
  • From: Scott Klement <klemscot@xxxxxxxxxxxx>
  • Date: Tue, 8 May 2001 11:26:55 -0500 (CDT)



On Tue, 8 May 2001, Haase, Justin C. wrote:

> I think an example program would be great.  We have directories many, many
> layers deep.  Damn Websphere anyway!  =)  We're talking 12, 13 layers.
> Thanks in advance for your help.
> 
> You could write a program that goes through all the objects in the IFS 
> and adds up their sizes, etc.   The trick is going to be figuring out
> how to store the pathname, since it can potentially be hundreds of bytes
> long...  :)  I don't know if that's a concern for you or not, though...
> 
> Do you need an example of how to do this?  (in RPG IV?)
> 

In comparison to the STRQSH method that Buck suggests, my way will
seem very complicated... :)   But, at least you won't have to try to
figure out how to parse the filenames from the output file.

Basically, I'm writing my own "ls" command :)

It may be worth your while to modify the code so that it skips 
'/qsys.lib/'  since you're probably already getting that information
elsewhere.

Here it is:

     D**********************************************************************
     D* File Information Structure (stat)
     D*
     D* struct stat {
     D*  mode_t         st_mode;       /* File mode                       */
     D*  ino_t          st_ino;        /* File serial number              */
     D*  nlink_t        st_nlink;      /* Number of links                 */
     D*  uid_t          st_uid;        /* User ID of the owner of file    */
     D*  gid_t          st_gid;        /* Group ID of the group of file   */
     D*  off_t          st_size;       /* For regular files, the file
     D*                                 * size in bytes                   */
     D*  time_t         st_atime;      /* Time of last access             */
     D*  time_t         st_mtime;      /* Time of last data modification  */
     D*  time_t         st_ctime;      /* Time of last file status change */
     D*  dev_t          st_dev;        /* ID of device containing file    */
     D*  size_t         st_blksize;    /* Size of a block of the file     */
     D*  unsigned long  st_allocsize;  /* Allocation size of the file     */
     D*  qp0l_objtype_t st_objtype;    /* AS/400 object type              */
     D*  unsigned short st_codepage;   /* Object data codepage            */
     D*  char           st_reserved1[66]; /* Reserved                     */
     D* };
     D*
     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_alctize                   10U 0
     D  st_objtype                   12A
     D  st_codepag                    5U 0
     D  st_resv11                    62A
     D  st_ino_gen_id                10U 0


     D**********************************************************************
     D*
     D* Directory Entry Structure (dirent)
     D*
     D* struct dirent {
     D*   char           d_reserved1[16];  /* Reserved                       */
     D*   unsigned int   d_reserved2;      /* Reserved                       */
     D*   ino_t          d_fileno;         /* The file number of the file    */
     D*   unsigned int   d_reclen;         /* Length of this directory entry
     D*                                     * in bytes                       */
     D*   int            d_reserved3;      /* Reserved                       */
     D*   char           d_reserved4[8];   /* Reserved                       */
     D*   qlg_nls_t      d_nlsinfo;        /* National Language Information
     D*                                     * about d_name                   */
     D*   unsigned int   d_namelen;        /* Length of the name, in bytes
     D*                                     * excluding NULL terminator      */
     D*   char           d_name[_QP0L_DIR_NAME]; /* Name...null terminated   */
     D*
     D* };
     D*
     D p_dirent        s               *
     D dirent          ds                  based(p_dirent)
     D   d_reserv1                   16A
     D   d_reserv2                   10U 0
     D   d_fileno                    10U 0
     D   d_reclen                    10U 0
     D   d_reserv3                   10I 0
     D   d_reserv4                    8A
     D   d_nlsinfo                   12A
     D     nls_ccsid                 10I 0 OVERLAY(d_nlsinfo:1)
     D     nls_cntry                  2A   OVERLAY(d_nlsinfo:5)
     D     nls_lang                   3A   OVERLAY(d_nlsinfo:7)
     D     nls_reserv                 3A   OVERLAY(d_nlsinfo:10)
     D   d_namelen                   10U 0
     D   d_name                     640A

     D*--------------------------------------------------------------------
     D* Open a Directory
     D*
     D* DIR *opendir(const char *dirname)
     D*--------------------------------------------------------------------
     D opendir         PR              *   EXTPROC('opendir')
     D  dirname                        *   VALUE options(*string)

     D*--------------------------------------------------------------------
     D* Read Directory Entry
     D*
     D* struct dirent *readdir(DIR *dirp)
     D*--------------------------------------------------------------------
     D readdir         PR              *   EXTPROC('readdir')
     D  dirp                           *   VALUE

     D*--------------------------------------------------------------------
     D* Close a directory
     D*
     D* int closedir(DIR *dirp)
     D*--------------------------------------------------------------------
     D closedir        PR            10I 0 EXTPROC('closedir')
     D  dirhandle                      *   VALUE

     D*--------------------------------------------------------------------
     D* Get File or Link Information
     D*
     D* int lstat(const char *path, struct stat *buf)
     D*--------------------------------------------------------------------
     D lstat           PR            10I 0 ExtProc('lstat')
     D   path                          *   Value options(*string)
     D   buf                           *   Value

     D getdirsize      PR            20U 0
     D    directory                 640A   const

     D AddRecord       PR
     D    ifs_object                640A   const
     D    size                       20U 0 value

     D S_ISDIR         PR             1N
     D   mode                        10U 0 value

     D size            S             10I 0
     D totalsize       S             20U 0

     c                   eval      size = %size(statds)
     c                   alloc     size          p_statds

     C* This gives us a starting point:
     c                   eval      totalsize = getdirsize('/')

     c                   dealloc                 p_statds
     c                   eval      *inlr = *on


     P*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     P*  This (recursively) totals up the size of each object in
     P*    a directory.
     P*
     P*  This calls AddRecord() for each non-directory object it finds.
     P*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     P getdirsize      B
     D getdirsize      PI            20U 0
     D    directory                 640A   const

     D file_size       S             20U 0
     D total           S             20U 0
     D dh              S               *
     D rpg_name        S            640A
     D last_pos        S             10U 0
     D dir             S            640A

     c                   eval      dh = opendir(%trim(directory))
     c                   if        dh = *NULL
     c                   return    0
     c                   endif

     c     ' '           checkr    directory     last_pos
     c                   if        %subst(directory:last_pos:1) <> '/'
     c                   eval      dir = %trim(directory) + '/'
     c                   else
     c                   eval      dir = %trim(directory)
     c                   endif

     c                   eval      total = 0

     c                   eval      p_dirent = readdir(dh)
     c                   dow       p_dirent <> *NULL

     c                   eval      rpg_name = %str(%addr(d_name))

     c                   if        rpg_name <> '.' and rpg_name<>'..'

     c                   eval      rpg_name = %trim(dir) + rpg_name

     c                   if        lstat(%trim(rpg_name): p_statds) = 0
     c                   if        S_ISDIR(st_mode)
     c                   eval      file_size = getdirsize(rpg_name)
     c                   else
     c                   eval      file_size = st_size
     c                   callp     AddRecord(rpg_name: file_size)
     c                   endif
     c                   eval      total = total + file_size
     c                   endif

     c                   endif

     c                   eval      p_dirent = readdir(dh)
     c                   enddo

     c                   callp     closedir(dh)

     c                   return    total
     P                 E


     P*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     P*  This (recursively) totals up the size of each object in
     P*    a directory.
     P*
     P*  This calls AddRecord() for each non-directory object it finds.
     P*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     P AddRecord       B
     D AddRecord       PI
     D    ifs_object                640A   const
     D    size                       20U 0 value
     C* Here is where you'd write records to your file
     C*   with something like this:
     C*                  eval      filename = ifs_object
     c*                  eval      filesize = size
     c*                  write     my_file
     P                 E



      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      *  This tests a file mode to see if a file is a directory.
      *    (sorry, this is horribly ugly in RPG)
      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     P S_ISDIR         B
     D S_ISDIR         PI             1N
     D   mode                        10U 0 value

     D                 DS
     D  dirmode                1      4U 0
     D  byte1                  1      1A
     D  byte2                  2      2A
     D  byte3                  3      3A
     D  byte4                  4      4A

     c                   eval      dirmode = mode

     c                   bitoff    x'FF'         byte1
     c                   bitoff    x'FE'         byte2
     c                   bitoff    x'0F'         byte3
     c                   bitoff    x'FF'         byte4

     c                   if        dirmode = 16384
     c                   return    *On
     c                   else
     c                   return    *Off
     c                   endif
     P                 E

+---
| This is the Midrange System Mailing List!
| To submit a new message, send your mail to MIDRANGE-L@midrange.com.
| To subscribe to this list send email to MIDRANGE-L-SUB@midrange.com.
| To unsubscribe from this list send email to MIDRANGE-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.