linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* which errno should I use
@ 2001-01-30 16:52 Ralph Blach
  2001-01-30 17:19 ` Wolfgang Denk
  0 siblings, 1 reply; 4+ messages in thread
From: Ralph Blach @ 2001-01-30 16:52 UTC (permalink / raw)
  To: Embedded Linux list

[-- Attachment #1: Type: text/plain, Size: 244 bytes --]

I am writing a character device driver.  I want this device driver to
return an error if the user request less than say 1024 byte of data.
What errno should I use?  Is it legal to return an error if not enouth
bytes are requested?

Thanks

Chip

[-- Attachment #2: Card for Ralph Blach --]
[-- Type: text/x-vcard, Size: 247 bytes --]

begin:vcard
n:Blach;Ralph
tel;work:919-543-1207
x-mozilla-html:TRUE
url:www.ibm.com
org:IBM MicroElectronics
adr:;;3039 Cornwallis		;RTP;NC;27709;USA
version:2.1
email;internet:rcblach@raleigh.ibm.com
x-mozilla-cpt:;15936
fn:Ralph Blach
end:vcard

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: which errno should I use
  2001-01-30 16:52 which errno should I use Ralph Blach
@ 2001-01-30 17:19 ` Wolfgang Denk
  0 siblings, 0 replies; 4+ messages in thread
From: Wolfgang Denk @ 2001-01-30 17:19 UTC (permalink / raw)
  To: Ralph Blach; +Cc: Embedded Linux list


Hi Ralph,

in message <3A76F163.406CBFDB@raleigh.ibm.com> you wrote:
>
> I am writing a character device driver.  I want this device driver to
> return an error if the user request less than say 1024 byte of data.
> What errno should I use?  Is it legal to return an error if not enouth

EINVAL (Invalid argument) is often used in this situation.

> bytes are requested?

Sure. Many character devices have certain restrictions on the I/O size.

Wolfgang Denk

--
Software Engineering:  Embedded and Realtime Systems,  Embedded Linux
Phone: (+49)-8142-4596-87  Fax: (+49)-8142-4596-88  Email: wd@denx.de
Visit us at Embedded Systems: Feb 14-16 2001, Nuremberg, Halle 12/K01
(with TQ Components); our presentation "Starke Zwerge: Embedded Linux
auf PowerPC-Systemen" on Thursday, Feb 15 2001, 13:30 Forum Halle 11.

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: which errno should I use
@ 2001-01-31 18:48 Ian Abbott
  2001-01-31 23:45 ` Ron Bianco
  0 siblings, 1 reply; 4+ messages in thread
From: Ian Abbott @ 2001-01-31 18:48 UTC (permalink / raw)
  To: Embedded Linux list


On Tuesday, January 30, 2001 4:53 PM, Ralph Blach
<rcblach@raleigh.ibm.com> wrote:

> I am writing a character device driver.  I want this device driver to
> return an error if the user request less than say 1024 byte of data.
> What errno should I use?  Is it legal to return an error if not enouth
> bytes are requested?

I have a similar driver that wants exactly one long's worth of data to
be read. If the supplied buffer is smaller than a long, I return 0,
otherwise I return sizeof(long) (assuming their are no other errors).
Admittedly this does not let the user level distinguish "buffer too
small" from "no data", but I let the programmer at the user level deal
with that! Just mention it in the documentation for your driver, if
there is any.

Wolfgang Denk suggested EINVAL. I didn't use that as the man page for
read(2) says that means "fd is attached to an object which is unsuitable
for reading." There's no harm in overloading this meaning though. Just
document what your driver does.

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: which errno should I use
  2001-01-31 18:48 Ian Abbott
@ 2001-01-31 23:45 ` Ron Bianco
  0 siblings, 0 replies; 4+ messages in thread
From: Ron Bianco @ 2001-01-31 23:45 UTC (permalink / raw)
  To: Ian Abbott; +Cc: linuxppc-embedded


Hi Ian,

In your driver's read() fileop implementation, assuming you're using a non-blocking
technique, if the count parameter is not 1024 just return 0 for num byes written to
user's buffer.  The error codes are actually used as -EINVAL for example, any
positive return value or 0 indicates the bytes actually processed.   Also if you're
intending the user program to select() your device then you need to implement the
poll() fileop.

I just finished writing a non-blocking char device driver, so can offer some tips if
need be.

Cheers, Ron

Ron Bianco
Computer Systems Technologist
Level Control Systems
email: ronb@junction.net
phone: 250-549-2558 Ext 8
web:  www.lcsaudio.com


> -----Original Message-----
> From: owner-linuxppc-embedded@lists.linuxppc.org
> [mailto:owner-linuxppc-embedded@lists.linuxppc.org]On Behalf Of Ian
> Abbott
> Sent: Wednesday, January 31, 2001 10:48 AM
> To: Embedded Linux list
> Subject: RE: which errno should I use
>
>
>
> On Tuesday, January 30, 2001 4:53 PM, Ralph Blach
> <rcblach@raleigh.ibm.com> wrote:
>
> > I am writing a character device driver.  I want this device driver to
> > return an error if the user request less than say 1024 byte of data.
> > What errno should I use?  Is it legal to return an error if not enouth
> > bytes are requested?
>
> I have a similar driver that wants exactly one long's worth of data to
> be read. If the supplied buffer is smaller than a long, I return 0,
> otherwise I return sizeof(long) (assuming their are no other errors).
> Admittedly this does not let the user level distinguish "buffer too
> small" from "no data", but I let the programmer at the user level deal
> with that! Just mention it in the documentation for your driver, if
> there is any.
>
> Wolfgang Denk suggested EINVAL. I didn't use that as the man page for
> read(2) says that means "fd is attached to an object which is unsuitable
> for reading." There's no harm in overloading this meaning though. Just
> document what your driver does.
>
>


** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2001-01-31 23:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-01-30 16:52 which errno should I use Ralph Blach
2001-01-30 17:19 ` Wolfgang Denk
  -- strict thread matches above, loose matches on Subject: below --
2001-01-31 18:48 Ian Abbott
2001-01-31 23:45 ` Ron Bianco

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).