libsmb2 icon indicating copy to clipboard operation
libsmb2 copied to clipboard

using extension of errno for conversion from smb2 status

Open amandeepgautam opened this issue 6 years ago • 1 comments

Hi! We have been using the library and find it difficult to remap all smb2 codes to errno. For example, if we would like to differentiate between 0 sized reads were due to end of file or client did not have enough credits, we cannot do that as library maps end of file and success error code to 0. There can be other scenarios where this will be useful as well.

I am planning to write a errors.h file with an extended list of codes like: #define EENDOFFILE 2001

Let me know what you think.

amandeepgautam avatar Oct 21 '19 09:10 amandeepgautam

On Mon, Oct 21, 2019 at 7:34 PM Aman Deep Gautam [email protected] wrote:

Hi! We have been using the library and find it difficult to remap all smb2 codes to errno. For example, if we would like to differentiate between 0 sized reads were due to end of file or client did not have enough credits, we cannot do that as library maps end of file and success error code to 0. There can be other scenarios where this will be useful as well.

You are using smb2_[p]read or the async version? That is correct, you can not get specific NT error codes from this function since it is supposed to emulate the errno codes from "man 2 read".

But you should get a -errno value returned if an error happened. If it was end of file then we have a specific check for that error in https://github.com/sahlberg/libsmb2/blob/master/lib/libsmb2.c#L1172 which should return -errno specifically for all errors that are not end of file.

If the error was from the server, it will be mapped https://github.com/sahlberg/libsmb2/blob/master/lib/errors.c#L160 which since we don't have that many mapped will map to -EIO for most errors.

If the error happened locally we would never reach read_cb() and the -errno will be returned straight from where the error happened. this will probably most likely be -EIO or something.

So I think we already get the semantics you want. If end of file happened then we will return 0 from the read, as we should and if a different type of error happened we will return -errno, most likely -EIO.

Or do you need to be able to distinguish between individual types of NT status codes? NTFS conditions or issues with the transport and the errno range is not sufficient then you probably should not use smb2_read() but instead call smb2_cmd_read_async() directly. That gives you access to the raw NT status codes for all server side errors.

Remaining would be that you will need to ensure that any local error that are emitted would have to be a suitable -errno number. Most are probably -EIO/-EINVAL or -ENOMEM.

But remember, any -errno value that is returned from the smb2_ like functions must be valid errno values.

I am planning to write a errors.h file with an extended list of codes like: #define EENDOFFILE 2001

Let me know what you think.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/sahlberg/libsmb2/issues/115?email_source=notifications&email_token=AADY3ED5EXKRIWR5HXOK4ULQPVZRLA5CNFSM4JC2WE22YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HTDT5WQ, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADY3EBLE2QD7KSHDZYEOTLQPVZRLANCNFSM4JC2WE2Q .

sahlberg avatar Oct 21 '19 10:10 sahlberg

declaring github issues bancruptcy

sahlberg avatar Mar 29 '24 08:03 sahlberg