× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.




Here is a RPG and C example accessing the IFS systems
* PATH LENGTH PARAMETER
     IPATHLN     DS
     I                                   B   1    40PATHL
     * OPEN INFORMATION PARAMETER
     IOPNINF     DS
     I                                       1   1 EXISTS
     I                                       2   2 NOTTHR
     I                                       3   3 SYNASY
     I                                       4   4 RSV1
     I                                       5   5 SHAREM
     I                                       6   6 ACCESS
     I                                       7   7 OTYPE
     I                                       8  10 RSV3
     * ATTRIBUTE LENGTH PARAMETER
     IATTRLN     DS
     I                                   B   1    40ATTRL
     * RETURN CODE PARAMETER
     IRETCD      DS
     I                                   B   1    40RCLEN
     I                                   B   5    80RTCD
     I                                       9   15 CONDTN
     I                                      16   16 RSV
     I                                      17  272 MSG
     * BYTES TO READ/WRITE PARAMETER
     IBYTRDW       DS                      B   1   40BYT2RW

     * BYTES ACTUALLY READ/WRITTEN PARAMETER
     IBYTACT       DS                      B   1   40BYTARW
G.1.3 Opening an NSF File




     * PARAMETER LIST FOR QHFOPNSF CALL
     C           POPNSF    PLIST
     C                     PARM            FHDLE  16
     C                     PARM            PATH   36
     C                     PARM            PATHL
     C                     PARM            OPNINF
     C                     PARM            ATRTBL  1
     C                     PARM            ATTRLN
     C                     PARM            ACTION  1
     C                     PARM            RETCD

     C* OPEN FILE SUBROUTINE
     C           OPNSF     BEGSR
     C* FILL IN THE PATH AND ATTRIBUTE LENGTHS
     C                     Z-ADD36        PATHL            SET PATH LEN=36

     C                     Z-ADD*ZEROS    ATTRL            ZERO ATTRIBUTE
LNGTH
     C* FILL IN THE OPNINF PARAMETER
     C                     MOVE '0'       EXISTS   1       FAIL IF EXISTS
     C                     MOVE '1'       NOTTHR   1       CREATE IF NOT
THERE
     C                     MOVE '0'       SYNASY   1       ASYNCHRONOUS
     C                     MOVE *BLANKS   RSV1     1
     C                     MOVE '1'       SHAREM   1       DENY NONE
     C                     MOVE '2'       ACCESS   1       READ/WRITE
     C                     MOVE '0'       OTYPE    1       NORMAL
     C                     MOVE *BLANKS   RSV3     3
     C* CALL THE API TO OPEN THE STREAM FILE
     C                     CALL 'QHFOPNSF'POPNSF         50
     C           OPNEND    ENDSR
G.1.4 Writing a File to an NSF Disk




     * PARAMETER LIST FOR QHFRDSF OR QHFWRTSF CALL
     C           PRWSF     PLIST
     C                     PARM           FHDLE   16
     C                     PARM           DATAIN
     C                     PARM           BYT2RW
     C                     PARM           BYTARW
     C                     PARM           RETCD

     C* CALL API TO WRITE TO THE FILE
     C           WRTSF     BEGSR
     C                     Z-ADD256       BYT2RW           SET WRITE
LENGTH=256
     C                     CALL 'QHFWRTSF'PRWSF          50
     C           WRTEND    ENDSR

G.1.5 Closing an NSF File




     * PARAMETER LIST FOR QHFCLOSF CALL
     C           PCLOSF    PLIST
     C                     PARM           FHDLE   16
     C                     PARM           RETCD

     C* CALL API TO CLOSE THE FILE
     C           CLOSF     BEGSR
     C                     CALL 'QHFCLOSF'PCLOSF         50
     C           CLSEND    ENDSR
     C* END OF SAMPLE RPG CALL TO THE HFS API

G.2.1 Integrated File System Function Examples





/*********************************************************************/
     /*          IFS File
systems                                                         */
     /* This program demonstrates the use of various integrated file
*/
     /* system functions applied to the QOPT physical file system
*/
     /* including:
*/
     /*    chdir()     - change current directory
*/
     /*    close()     - close file
*/
     /*    closedir()  - close directory
*/
     /*    creat()     - create file
*/
     /*    lseek()     - seek file (change file offset)
*/
     /*    open()      - open file
*/
     /*    opendir()   - open directory
*/
     /*    read()      - read file
*/
     /*    readdir()   - read directory entry
*/
     /*    rewinddir() - rewind directory entries
*/
     /*    stat()      - directory statistics
*/
     /*    write()     - write file
*/
     /*
*/

/*********************************************************************/
     #include <stdio.h>
     #include <unistd.h>
     #include <sys/types.h>
     #include <dirent.h>
     #include <sys/stat.h>
     #include <fcntl.h>

     void main (void)
     {

/*****************************************************************/
         /* local variables, contents and defines
*/

/*****************************************************************/
         char path[294];                     /* optical path
*/
         DIR *dirP;                          /* pointer to the directory
*/
         int filedes;                        /* open file descriptor
*/
         struct dirent *direntP;             /* directory entry structure
*/
         struct stat info;                   /* dir/file information
*/
         int volume_number;                  /* what it says...
*/
         int rc = 0;                         /* function return codes
*/
         int kk = 0;                         /* local counter
*/
         char data[] = "The quick red fox jumped over the fence";


/*****************************************************************/
         /* Retrieve the list of volumes from the QOPT physical file
*/
         /* system by opening the QOPT pfs root directory and reading the
*/
         /* directory entries.
*/

/*****************************************************************/
         memset(path,                        /* clear path name
*/
         0x00,
         sizeof(path));
         strcpy(path,                        /* set physical file system
*/
         "/QOPT");
         rc = stat("/QOPT", &info);;          /* determine number of files
*/
         if (rc != 0)
         perror("stat() failed:");

         dirP = opendir(path);               /* open the directory
*/
         if (dirP == NULL)
         perror("opendir() failed:");

         for (kk = 1; kk <= info.st_nlink; kk++)
         {
         direntP = readdir(dirP);
         if (direntP == NULL)
         perror("readdir() failed:");
         printf("%d) %s\n", kk, direntP->d_name);
         }


/*****************************************************************/
         /* Prompt user for the volume they want to work with and make it
*/
         /* the current directory.
*/

/*****************************************************************/
         printf("\nEnter the number the volume you want to work with:\n");

         scanf("%d", &volume_number);;

         rewinddir(dirP);                   /* beginning of directory
*/
         for (kk = 1; kk <= volume_number; kk++)
         direntP = readdir(dirP);       /* get requested dir. entry   */

         strcat(path, "/");
         strcat(path, direntP->d_name);
         rc = chdir(path);                  /* set current working dir.
*/
         if (rc != 0)
         perror("chdir() failed:");
         if (getcwd(path, sizeof(path)) == NULL)
         perror("getcwd() failed:");
         printf("\nThe current working directory is:  %s\n", path);

         rc = closedir(dirP);               /* close the directory
*/
         if (rc != 0)
         perror("closedir() failed:");


/*****************************************************************/
         /* Create and open a file write only.  If the file exists it
*/
         /* will be truncated.  The owner will have read, write, and
*/
         /* execute authority to the file.
*/

/*****************************************************************/
         strcat(path, "/");
         printf("\nEnter a file name:\n");
         scanf("%s", &path[strlen(path)]);

         filedes = creat(path, S_IRWXU);
         if (filedes == -1)
         {
         perror("creat() failed");
         return;
         }

         rc = write(filedes, data, sizeof(data));
         if (rc == -1)
         perror("write() failed:");

         close(filedes);


/*****************************************************************/
         /* Read back the file and print it.
*/

/*****************************************************************/
         memset(data, 0x00, sizeof(data));
         filedes = open(path, O_RDWR);
         if (filedes == -1)
         {
         perror("open() failed");
         return;
         }

         read(filedes, data, sizeof(data));
         if (filedes == -1)
         {
         perror("read() failed");
         return;
         }
         printf("\nThe data written to file is:  %s\n", data);


/*****************************************************************/
         /* Change the offset into the file and change part of it.  Read
*/
         /* the entire file, print it out and close the file.
*/

/*****************************************************************/
         lseek(filedes, 4, SEEK_SET);
         rc = write(filedes, "slow old ", 9);
         if (rc == -1)
         {
         perror("write() failed");
         return;
         }
         lseek(filedes, 18, SEEK_SET);
         rc = write(filedes, "went under ", 11);
         if (rc == -1)
         {
         perror("write() failed");
         return;
         }

         lseek(filedes, 0, SEEK_SET);
         read(filedes, data, sizeof(data));
         if (filedes == -1)
         {
         perror("read() failed");
         return;
         }
         printf("\nThe data now is:  %s\n", data);

         close(filedes);

         printf("Done...\n");
         return;

     }



Harry Williams wrote:

>  Does anyone  have an example reading an IFS or NSF object.  I have
> API's from
> > RPG, but I do not have the DD specifications or know how to access
> these
> > objects in MI.
>
> Happy Holidays.
> Harry
>
> _______________________________________________
> This is the MI Programming on the AS400 / iSeries (MI400) mailing list
> To post a message email: MI400@midrange.com
> To subscribe, unsubscribe, or change list options,
> visit: http://lists.midrange.com/cgi-bin/listinfo/mi400
> or email: MI400-request@midrange.com
> Before posting, please take a moment to review the archives
> at http://archive.midrange.com/mi400.



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.