[jcifs] SmbRandomAccessFile for read-only access

Michael B Allen ioplex at gmail.com
Thu Jun 6 18:56:32 MDT 2013


On Thu, Jun 6, 2013 at 3:27 AM, Somnath Kundu <skundu07 at gmail.com> wrote:
> Hello,
>
> I was trying to use 'SmbRandomAccessFile' class with mode value "r" for
> reading some file data, but it was not working. From the source code, it
> appears that for mode value "r", the 'access' value remains set to '0', and
> hence this problem. I had to modify the code as below to make it working.

Hi Somnath,

SmbComNTCreateAndX automatically adds FILE_READ_DATA.

Perhaps you should post precisely what actually happens and describe
why you think it is in error.

>
> BTW, what is the meaning of 'WRITE_OPTIONS' value as '0x0842' (as I do not
> see any description in the code), and I see the default zero value is being
> converted to '0x0040' later in the code?

Those are options specific to if the file is created. I don't recall
what each bit actually means. I don't think they were documented when
I wrote the code. They may be now.

Mike

-- 
Michael B Allen
Java Active Directory Integration
http://www.ioplex.com/


> -----------------Original code v1.3.17--------------
>     private static final int WRITE_OPTIONS = 0x0842;
>     ........
>     private int openFlags, access = 0, readSize, writeSize, ch, options = 0;
>     ......
>     public SmbRandomAccessFile( SmbFile file, String mode )
>             throws SmbException, MalformedURLException, UnknownHostException
> {
>         this.file = file;
>         if( mode.equals( "r" )) {
>             this.openFlags = SmbFile.O_CREAT | SmbFile.O_RDONLY;
>         } else if( mode.equals( "rw" )) {
>             this.openFlags = SmbFile.O_CREAT | SmbFile.O_RDWR |
> SmbFile.O_APPEND;
>             write_andx_resp = new SmbComWriteAndXResponse();
>             options = WRITE_OPTIONS;
>             access = SmbConstants.FILE_READ_DATA |
> SmbConstants.FILE_WRITE_DATA;
>         } else {
>             throw new IllegalArgumentException( "Invalid mode" );
>         }
>         .........
>     }
> -----------------Modified code----------------------------------
>     ........
>     public SmbRandomAccessFile( SmbFile file, String mode )
>             throws SmbException, MalformedURLException, UnknownHostException
> {
>         this.file = file;
>         if( mode.equals( "r" )) {
>             this.openFlags = SmbFile.O_RDONLY;
>             access = SmbConstants.FILE_READ_DATA;
>         } else if( mode.equals( "rw" )) {
>             this.openFlags = SmbFile.O_CREAT | SmbFile.O_RDWR |
> SmbFile.O_APPEND;
>             write_andx_resp = new SmbComWriteAndXResponse();
>             options = WRITE_OPTIONS;
>             access = SmbConstants.FILE_READ_DATA |
> SmbConstants.FILE_WRITE_DATA;
>         } else {
>             throw new IllegalArgumentException( "Invalid mode" );
>         }
> -------------------------------------------------------------------
>
> Many thanks for providing this library free of cost.
>
> Beast regards,
> Somnath Kundu


More information about the jCIFS mailing list