FW: [jcifs] Problem locking using jcifs SmbFileOutputStream

Allen, Michael B (RSCH) Michael_B_Allen at ml.com
Tue Jan 14 13:28:24 EST 2003


Exactly.

> -----Original Message-----
> From:	Mario Rodriguez [SMTP:marior at caclearing.com.ar]
> Sent:	Monday, January 13, 2003 9:21 PM
> To:	Allen, Michael B (RSCH)
> Subject:	Re: [jcifs] Problem locking using jcifs SmbFileOutputStream
> 
> Thank's Mike.
> 
> Your solution work very fine, I was make a few changes into the code and 
> I want to share with you. I don't know how make this changes public if 
> you know please letme know.
> 
> Here in this mail I attach to you two files that I change.
> 
> best regards, and thank's again for your prompt and efective response.
> 
> marior
> 
> 
> Allen, Michael B (RSCH) wrote:
> 
> >CIFS provides for specifying a "share access". Internally the jCIFS library also provides for
> >utilizing it. However for the sake of simplicity we do not explose this attribute in the public API.
> >You would have to modify the jCIFS source to permit the share access flag to be specified
> >externally.
> >
> >To do this you need to familiarize yourself with the SmbComNTCreateAndX constructor which
> >follows:
> >
> >    SmbComNTCreateAndX( String name, int flags, ServerMessageBlock andx ) {
> >        super( andx );
> >        this.name = name;
> >        command = SMB_COM_NT_CREATE_ANDX;
> >
> >        // desiredAccess
> >        desiredAccess = ( flags >>> 16 ) & 0xFFFF;
> >        desiredAccess |= FILE_READ_EA | FILE_READ_ATTRIBUTES;
> >
> >        // extFileAttributes
> >        extFileAttributes = ATTR_NORMAL;
> >
> >        // shareAccess
> >        shareAccess = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
> >
> >        // createDisposition
> >        if(( flags & SmbFile.O_TRUNC ) == SmbFile.O_TRUNC ) {
> >        ....
> >
> >You will see there are quite a few options to the SmbComNTCreateAndX command many of
> >which are hardcoded. In particular the share access is hard coded to permit reading, writing, and
> >deleting the file even if we have it open. To "lock" the file one might specify a shareAccess of
> >FILE_NO_SHARE or perhaps FILE_SHARE_READ would be more polite. Note that this is not
> >a real "lock" but it will achive the effect you seek.
> >
> >To do this you could modify this construtor to accept a share access flag or boolean perhaps
> >that toggles these flags. Then modify the SmbFile.open() function to use this modified
> >constructor. You might add an SmbFile constructor too so that the functionality is exposed in
> >the public API.
> >
> >It might be wise to just hardcode shareAddress = FILE_SHARE_READ at first to see if it does
> >what you want.
> >
> >Note that this will not work with Windows98 or below. Only Samba, NT, 2K, XP, etc.
> >
> >If you do this, let us know how it goes. Perhaps I will add the feature to the main codebase. But
> >I think you're actually the fist person to ask for this functionality.
> >
> >Mike 
> >
> >  
> >
> >>-----Original Message-----
> >>From:	Mario Rodriguez [SMTP:marior at caclearing.com.ar]
> >>Sent:	Monday, January 13, 2003 7:10 PM
> >>To:	jcifs at lists.samba.org
> >>Subject:	[jcifs] Problem locking using jcifs SmbFileOutputStream
> >>
> >>Hi!
> >>
> >>I'm trying to write a long file using SmbFileOutputStream and I need to 
> >>lock this file on the Windows NT resource while I'm writing to this file 
> >>to avoid the use of this file.
> >>
> >>How can I do that?
> >>
> >>This is an example code that I'm using.
> >>
> >>SmbFile pipe=null;
> >>
> >>       try {
> >>          pipe = new SmbFile ("smb://user:passwd@HOST/uploads/thefile.txt");
> >>       }
> >>       catch (MalformedURLException ex)
> >>       {}
> >>       catch (UnknownHostException ex)
> >>       {}
> >>
> >>     
> >>      try {
> >>           byte buffer[] = new byte[150000];
> >>           OutputStream out = null; 
> >>           out = new SmbFileOutputStream(pipe,true);
> >>           for (int i = 0 ; i<20;i++){
> >>             out.write(buffer);
> >>             out.flush();
> >>           }
> >>      }
> >>      catch (IOException ex) {
> >>         ex.printStackTrace();
> >>      }
> >>
> >>   ...
> >>
> >>
> >>best regards.
> >>
> >>marior
> >>
> >>    
> >>
>  <<SmbFile.java>>  <<SmbComNTCreateAndX.java>> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SmbFile.java
Type: text/x-java
Size: 71851 bytes
Desc: not available
Url : http://lists.samba.org/archive/jcifs/attachments/20030113/a3264d21/SmbFile.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SmbComNTCreateAndX.java
Type: text/x-java
Size: 8004 bytes
Desc: not available
Url : http://lists.samba.org/archive/jcifs/attachments/20030113/a3264d21/SmbComNTCreateAndX.bin


More information about the jcifs mailing list