Problem with opening file as read only on ntfs share.

derrell at derrell at
Mon Aug 7 13:00:57 GMT 2006

Raja Umar Iqbal <uiqbal at> writes:

> Its me Umar again with little issue in libsmbclient. I have libsmbclient 
> 3.0.20-4 on suse 10. The issue i am having is in this code.
> if ((dwCreationDisposition & OPEN_EXISTING))
> {
> 	DWORD dwExistingFileFlags = O_RDONLY | O_CREAT | O_EXCL;
> 	m_hFile = pCtx->open(pCtx, (LPCTSTR) m_csFilePath, dwExistingFileFlags, 0);
> 	m_dwLastError = errno;
> 	if (!m_hFile && m_dwLastError != EEXIST)
> 	{
> 	       //Nthing,  but print the error.
> 		CString csSysError;
> 		csSysError.Format(_T("(%d) %s"), m_dwLastError, (LPCTSTR) 	
> fnGetErrorMsg(m_dwLastError));
> 		if (m_pLog)
> 			m_pLog->SetFormatLog(__TFILE__, __LINE__, kLogSectFile, (dwDesiredAccess & 	
> GENERIC_WRITE) ? -2 : -1, (LPCTSTR) pPath, (LPCTSTR) csSysError);
> 			return -1;
> 	}	
> }
> the error  string is  System error: (13) Permission denied.
> I want to open an already existent file on an ntfs filesystem share, when
> this issue arises, if the share on network is on FAT32 then i can read the
> file. I don't know what the issue is but the code is pasted and i can't seem
> to figure out what's the issue with ntfs share.
> Konqueror using the same libsmbclient let's me open the file in readonly
> mode and copy this file.

O_EXCL will disallow opening the file if it already is open by another task.
Is the file already open before you try to open it here?

Also, I'm not sure about the combination of O_RDONLY and O_CREAT.  One implies
that you won't be writing to the file while the other implies that you want to
create the file (a which implies writing).  I'd try O_RDRW instead of O_RDONLY
if you want the file to be created if it doesn't exist; or remove the O_CREAT
flag.  BTW, it looks like you may already know that the file exists due to the
(dwCreationDisposition & OPEN_EXISTING) so O_CREAT is therefore unnecessary.

Otherwise, without a lot more detail, I have no idea what the problem is.  We
open files residing on NTFS all the time.  If you want, you can open a bug in
bugzilla and attach to the bug a raw packet trace generated with:

  tcpdump -s 0 -w file_will_not_open.pcap

and I'll take a look.  Be sure to select "component" = "libsmbclient" in the
bug report.



ps. Please post your questions to the mailing list rather than directly to me.
That way, others have the chance to offer suggestions.  I'm cc'ing the list on
this reply.

More information about the samba-technical mailing list