Q
Evaluate Weigh the pros and cons of technologies, products and projects you are considering.

Trouble reading a text file

I'm trying to read a text file and add its content to a member. I'd like to access those files (textfile and member) by the IFS. The problem I'm facing now is that I want to create a new member (the check if the member already exist is done), but it fails by returning me a "3021-error (EINVAL-error)" when I'm doing the 'open'-API on the member.

I'm using the following code (free-format):

 
----------------------------- 
w_wrfile = '/QSYS.LIB/MYTEST.LIB/FTAR.FILE/L550010.MBR'; 
  
flags = O_WRONLY + O_CREAT + O_TRUNC; 
  
mode = S_IRUSR + S_IWUSR + S_IRGRP + S_IWGRP; 
  
fdw = ifs_open(%trimr(w_wrfile):flags:mode); 
  
if fdw < 0; 
 z_msg = 'error : ' + %editc(errno:'X'); else;  z_msg = 'filed opened well';  ifs_close(fdw); endif; 
----------------------------- 
  

Can you please tell me what I'm doing wrong? I think it has something to do with mode-parameter passed to the open-API.

It does look as if it's the mode parameter. You are creating this member in the QSYS file system, which has certain important restrictions. The document describing open() says, for the O_CREAT flag:

"For all other file systems, the group ID (GID) of the file is set to the GID of the directory in which the file is created. File permission bits are set according to mode, except for those set in the file mode creation mask of the job. The S_ISUID (set-user-ID) and S_ISGID (set-group-ID) bits are also set according to mode. The file type bits in mode are ignored. All other bits in mode must be cleared (not set) or a [EINVAL] error is returned."

So your line (mode = S_IRUSR + S_IWUSR + S_IRGRP + S_IWGRP;)looks wrong -- you are setting bits that should not be set for this filing system. Change this line and try again.

==================================
MORE INFORMATION ON THIS TOPIC
==================================

The Best Web Links: tips, tutorials and more.

Visit the ITKnowledge Exchange and get answers to your developing questions fast.

Ask the Experts yourself: Our application development gurus are waiting to answer your programming questions.

This was last published in May 2005

Dig Deeper on iSeries application development tools

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataCenter

  • How do I size a UPS unit?

    Your data center UPS sizing needs are dependent on a variety of factors. Develop configurations and determine the estimated UPS ...

  • How to enhance FTP server security

    If you still use FTP servers in your organization, use IP address whitelists, login restrictions and data encryption -- and just ...

  • 3 ways to approach cloud bursting

    With different cloud bursting techniques and tools from Amazon, Zerto, VMware and Oracle, admins can bolster cloud connections ...

Close