# Detecting share violations over cifs with PHP? Feature request

- Thread: https://externals.io/message/45577
- Original archive: https://news-web.php.net/php.internals/45577
- Started by Ian Tighe on 2009-09-16T09:14:55+00:00
- Messages: 6
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #45577 — Ian Tighe — 2009-09-16T09:14:55+00:00

URL: https://externals.io/message/45577#45577

Hi. I hope this has been sent to the right place.
I am using files that are mount.cif share files. My client is a samba linux box but acting as a client over cifs to an XP box (several in fact). 
I am descending the share recursively with opendir and readdir detecting files ( and of course directories ) before doing my processing.
I note from a wireshark trace I am getting errors - sharing violations reported by XP. I would very much like to detect these events to take action - ignore the file for instance - but right now I have a true or false return from readdir, is_dir, is_file or is_link which is not very helpful during a fault condition such as a sharing violation. In other words a sharing violation looks like a readdir saying no more files!

It seems that once the error condition comes about all my reads of a directory and tests of file types fail until I reach the end of that directory and all of its parent directories. This is not so good.

Am I missing a trick here? If not is it possible to bring out more error information so that I can detect these events. An error array as an additional overloaded argument to readdir, opendir (indeed any I/O) where the first element has the normal true/false perhaps but a second element has a return code for smb/cifs/file_system failure/error/warning condition?

Thanks

Ian

---

## #45578 — Alain Williams — 2009-09-16T09:30:31+00:00

URL: https://externals.io/message/45577#45578 · In reply to: #45577

> Hi. I hope this has been sent to the right place.
> I am using files that are mount.cif share files. My client is a samba linux box but acting as a client over cifs to an XP box (several in fact). 
> I am descending the share recursively with opendir and readdir detecting files ( and of course directories ) before doing my processing.
> I note from a wireshark trace I am getting errors - sharing violations reported by XP. I would very much like to detect these events to take action - ignore the file for instance - but right now I have a true or false return from readdir, is_dir, is_file or is_link which is not very helpful during a fault condition such as a sharing violation. In other words a sharing violation looks like a readdir saying no more files!
> 
> It seems that once the error condition comes about all my reads of a directory and tests of file types fail until I reach the end of that directory and all of its parent directories. This is not so good.
> 
> Am I missing a trick here? If not is it possible to bring out more error information so that I can detect these events. An error array as an additional overloaded argument to readdir, opendir (indeed any I/O) where the first element has the normal true/false perhaps but a second element has a return code for smb/cifs/file_system failure/error/warning condition?

Exporting the value of errno would be really useful here.
However: the value would be OS specific which would damage PHP program portability.

Maybe a function like get_last_os_error() might be appropriate. This would return is PHP error number,
ie map OS specific info (which is sometimes more than just errno) onto something OS independent. This might
be a non tiny amount of work, but is only done if the application *really* wants/needs to know.

What the function might return could be an array, where different elements contain different levels
of details - including the OS specific stuff (some people are not bothered by portablity).
I don't know.

-- 
Alain Williams
Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer.
+44 (0) 787 668 0256  http://www.phcomp.co.uk/
Parliament Hill Computers Ltd. Registration Information: http://www.phcomp.co.uk/contact.php
Past chairman of UKUUG: http://www.ukuug.org/
#include <std_disclaimer.h

---

## #45584 — Keisial — 2009-09-17T11:48:06+00:00

URL: https://externals.io/message/45577#45584 · In reply to: #45577

Ian Tighe wrote:
> Hi. I hope this has been sent to the right place.
> I am using files that are mount.cif share files. My client is a samba linux box but acting as a client over cifs to an XP box (several in fact). 
> I am descending the share recursively with opendir and readdir detecting files ( and of course directories ) before doing my processing.
> I note from a wireshark trace I am getting errors - sharing violations reported by XP. I would very much like to detect these events to take action - ignore the file for instance - but right now I have a true or false return from readdir, is_dir, is_file or is_link which is not very helpful during a fault condition such as a sharing violation. In other words a sharing violation looks like a readdir saying no more files!
>
> It seems that once the error condition comes about all my reads of a directory and tests of file types fail until I reach the end of that directory and all of its parent directories. This is not so good.
>
> Am I missing a trick here? If not is it possible to bring out more error information so that I can detect these events. An error array as an additional overloaded argument to readdir, opendir (indeed any I/O) where the first element has the normal true/false perhaps but a second element has a return code for smb/cifs/file_system failure/error/warning condition?
>
> Thanks
>
> Ian
>   
What are you doing that triggers that error? I would expect a sharing
violation to be related to trying to read/write files opened exclusively
by other program, not by traversing a directory tree. Do you know how to
reproduce it?

---

## #45585 — Ian Tighe — 2009-09-17T12:35:11+00:00

URL: https://externals.io/message/45577#45585 · In reply to: #45584

Hi ,
I am using readdir with a view to selecting files for opening and reading or 
just taking a stat of them. I am doing this recursively. I test the output 
from readdir to see if its a file or dir or link etc and this works well. 
This suddenly changes though and an item is returned by readdir (that is a 
filename) but its type cannot be determined - it is not of any type at all! 
So looking at a wireshark trace revealed there had been a sharing violation 
but I was blissfully unaware of this.

I am seeking to have such an error condition made available so that ANY i/o 
op can be tested not just for true or false but to further establish the i/o 
outcome and hence track sharing violations amongst other errors. Apart from 
the type issue above, my substantive point about readdir was this: If I get 
a false reply I am not sure if I had a failed i/o operation or I had come to 
the end of a directory list. As far as I can see ( and I may be wrong of 
course ) there is for PHP no difference between the two but the impact is 
significantly different. It was more to demonstrate that error reporting is 
fairly clumsy in these circumstances.

It is certainly true all the files I have seen so far that cause this 
problem related to either iTunes or Microsoft - especially internet explorer 
8 recovery files. It must be they are exclusively locked and any attempt by 
my software makes to read them brings about a violation which cannot be 
detected, cannot be recovered from and thus not handled by me.

I cannot reliably repeat it as I can barely detect it other than my software 
will carry on looking for files and directories and not being able to 
recognise types and actions I wanted are not carried out.  I have a 
wireshark trace of the smb protocol exchanges if that helps but it basically 
says trans2 query path request, trans2 query path response , create_andx 
request (which is probably a stat), which is retried several times and 
finally a create andx response indicating a sharing violation. If I could 
get hold of that in PHP I could react.............
Thanks
Ian

----- Original Message ----- 
From: "Keisial" <keisial@gmail.com>
To: "Ian Tighe" <ian.tighe@latitude-51.co.uk>; <internals@lists.php.net>
Sent: Thursday, September 17, 2009 12:48 PM
Subject: Re: [PHP-DEV] Detecting share violations over cifs with PHP? 
Feature request


> Ian Tighe wrote:
> > […]
> What are you doing that triggers that error? I would expect a sharing
> violation to be related to trying to read/write files opened exclusively
> by other program, not by traversing a directory tree. Do you know how to
> reproduce it?

---

## #45586 — Keisial — 2009-09-17T12:54:13+00:00

URL: https://externals.io/message/45577#45586 · In reply to: #45585

Ian Tighe `wrote:
> Hi ,
> I am using readdir with a view to selecting files for opening and
> reading or just taking a stat of them. I am doing this recursively. I
> test the output from readdir to see if its a file or dir or link etc
> and this works well. This suddenly changes though and an item is
> returned by readdir (that is a filename) but its type cannot be
> determined - it is not of any type at all! So looking at a wireshark
> trace revealed there had been a sharing violation but I was blissfully
> unaware of this.
>
> I am seeking to have such an error condition made available so that
> ANY i/o op can be tested not just for true or false but to further
> establish the i/o outcome and hence track sharing violations amongst
> other errors. Apart from the type issue above, my substantive point
> about readdir was this: If I get a false reply I am not sure if I had
> a failed i/o operation or I had come to the end of a directory list.
> As far as I can see ( and I may be wrong of course ) there is for PHP
> no difference between the two but the impact is significantly
> different. It was more to demonstrate that error reporting is fairly
> clumsy in these circumstances.
The `readdir()` system call doesn't have a better error checking. It will
return a null pointer on error, just as on eof. The only way to check if
it had an error is by setting errno to 0 before the call and checking
its status after it. And the reported shouldn't happen anyway, since
they are application errors (passing a bad fd...) not reading problems.

Perhaps the sharing violation should be reported by `stat()` instead of
 `readdir()`?

> It is certainly true all the files I have seen so far that cause this
> problem related to either iTunes or Microsoft - especially internet
> explorer 8 recovery files. It must be they are exclusively locked and
> any attempt by my software makes to read them brings about a violation
> which cannot be detected, cannot be recovered from and thus not
> handled by me.
>
> I cannot reliably repeat it as I can barely detect it other than my
> software will carry on looking for files and directories and not being
> able to recognise types and actions I wanted are not carried out.  I
> have a wireshark trace of the smb protocol exchanges if that helps but
> it basically says trans2 query path request, trans2 query path
> response , create_andx request (which is probably a stat), which is
> retried several times and finally a create andx response indicating a
> sharing violation. If I could get hold of that in PHP I could
> react.............
> Thanks
> Ian

---

## #45587 — Ian Tighe — 2009-09-17T13:11:21+00:00

URL: https://externals.io/message/45577#45587 · In reply to: #45586

Yes readdir was an example and I am saying error reporting is not very good.
I am suggesting ( requesting a feature ) that all I/O functions should 
return better information so we can detect outcomes of I/O - whichever 
function is used, whatever file system, whatever circumstance.

----- Original Message ----- 
From: "Keisial" <keisial@gmail.com>
To: "Ian Tighe" <ian.tighe@latitude-51.co.uk>
Cc: <internals@lists.php.net>
Sent: Thursday, September 17, 2009 1:54 PM
Subject: Re: [PHP-DEV] Detecting share violations over cifs with PHP? 
Feature request


> Ian Tighe `wrote:
> > […]
> The `readdir()` system call doesn't have a better error checking. It will
> return a null pointer on error, just as on eof. The only way to check if
> it had an error is by setting errno to 0 before the call and checking
> its status after it. And the reported shouldn't happen anyway, since
> they are application errors (passing a bad fd...) not reading problems.
>
> Perhaps the sharing violation should be reported by `stat()` instead of
> `readdir()`?
>
> > […]
