BPX2OPN fails when trying to open existing file for read/stat

71 Views Asked by At

I am trying to use the BPX2OPN service to open an existing HFS file and determine how many bytes are in it. The examples I have found are only for creating a file and not opening an existing one, but I assume I can use it to open an existing file as well.

Here is the code I am using:

        USING PARMS,R1
        L   R10,PPATHL
        ST  R10,PATHLEN
        L   R9,PPATHA
        ST  R9,PATHNAME
        LA  R8,STAT#LENGTH
        ST  R8,STATL
        XC  S_MODE,S_MODE
        MVI S_MODE2,S_IRUSR
        XC  O_FLAGS(OPNF#LENGTH),O_FLAGS
        MVI O_FLAGS4,O_RDONLY

        L   R2,0(,R9)
        L   R3,4(,R9)
        L   R4,8(,R9)
        L   R5,12(,R9)
        L   R6,16(,R9)

        CALL  BPX2OPN,                                                 x
               (PATHLEN,                                               x
               PATHNAME,                                               x
               O_FLAGS,                                                x
               S_MODE,                                                 x
               STATL,                                                  x
               STAT,                                                   x
               RV,                                                     x
               RC,                                                     x
               RN),MF=(E,BPXOPND)
        L     R7,RV
        L     R8,RC
        L     R9,RN
        LA 0,27
        ST 0,0(,0)

where I force an abend after the call. My code is 31-bit AMODE. I am seeing the following registers:

D                                           406 00000010     DATA AT PSW  26908F58 - 001B5000  0000BFAF  B06C4740
D                                           406 00000010     AR/GR 0: 00000000/00000000_0000001B   1: 00000002/00000000_00000072
D                                           406 00000010           2: 00000000/00000000_4B4B6184   3: 00000000/00000000_81A38161
D                                           406 00000010           4: 00000000/00000000_A2859989   5: 00000000/00000000_85A24BA3
D                                           406 00000010           6: 00000000/00000000_A7A30000   7: 00000000/00000000_FFFFFFFF
D                                           406 00000010           8: 00000000/00000000_00000079   9: 00000000/00000000_0594003A
D                                           406 00000010           A: 00000000/00000000_00000012   B: 00000000/00000000_2690CE40
D                                           406 00000010           C: 00000000/00000000_A6908E8E   D: 00000000/00000000_2690CE40
D                                           406 00000010           E: 00000000/00000000_A6908F4A   F: 00000000/00000050_00000000

Looking at the registers, R7 indicates a failure (-1), R8 is the return code (0x79) which is EINVAL and the right byte of R9 (the reason code) is 0x3A which seems to indicate that I have a NULL in my path name but if you look at R2,R3,R4,R5,R6 there are no NULLs (it is ../data/series.txt in EBCDIC). I thought perhaps I needed the address of the length instead of the length stored in the parm list, but doing that gives me an EBADADDR code. Any suggestions on how I have coded this wrong, or if perhaps I can't use this service, is appreciated.

1

There are 1 best solutions below

1
mike On

I was able to solve my problem eventually

I was storing the wrong thing into PATHNAME - I was storing a pointer into PATHNAME, which the macro was loading the address of, instead of just using the address directly. So, instead of:

ST  R9,PATHNAME

I should instead have just loaded up R9 (or some other register) and referenced it directly in the macro, e.g.

       CALL  BPX2OPN,                                                 x
               (PATHLEN,                                               x
               (R9),                                                   x
               O_FLAGS,                                                x
               S_MODE,                                                 x
               STATL,                                                  x
               STAT,                                                   x
               RV,                                                     x
               RC,                                                     x
               RN),MF=(E,BPXOPND)

which works fine and the call is succeeding.