On Mon, Jun 14, 2004 at 13:27:58 +0530, aksingh@hss.hns.com wrote: > The write system call can return a number of error codes to the > application that calls it. EBADF, EINVAL, EFAULT, EFBIG ..etc as stated in > man write. Does a driver write method for a char device, have to return all > these return codes, or the kernel manages some of them itself, like > EBADF--"fd is not a valid file descriptor or is not open for writing". The > drivers I see generally return only a small subset of these error codes. When you are coding the ->write method for the device, you return the most appropriate of the error codes for each problem you ran across. The errors mentioned are what applications will expect and be able to deal with and thus what you CAN return. Return errors when appropriate. Now, to the question, yes, there are many places in the generic code, that may return error. Most notably EBADF is returned right at the begining, when the filehandle (number) is resolved to the struct file, EINVAL is next, if the flags in struct file do not indicate writing and EFAULT, which is returned if the generic code fails to page in the buffer (so the driver does not need to deal with swapped pages). Also not all errors may happen for any file. Eg. the EFBIG error only happens, if you open large (>2GiB) file using 32-bit version of given syscall. It does not happen on non-seekable things. ------------------------------------------------------------------------------- Jan 'Bulb' Hudec <bulb@ucw.cz>
Attachment:
signature.asc
Description: Digital signature