Character Device Driver

Character Device Driver

Post by jvasq.. » Tue, 29 Apr 2003 12:30:02



Can I character device driver access or write to a file? I been told
NO.
If the answer is no please explain why.
If the answer is yes please explain how or where I can find more
information.

My background is writing device drivers for  Windows NT. It was hard
for me to believe that any device driver couldn't read/write to a
file.

John

 
 
 

Character Device Driver

Post by Fritz » Wed, 30 Apr 2003 05:53:26



> Can I character device driver access or write to a file?

It depends on the OS.  Some versions of UNIX make it easier than others.

RFM
--
To reply, translate domain from l33+ 2p33|< to alpha.
                4=a  0=o  3=e  +=t

 
 
 

Character Device Driver

Post by John » Wed, 30 Apr 2003 07:18:39





>> Can I character device driver access or write to a file?

>It depends on the OS.  Some versions of UNIX make it easier than others.

>RFM

So you saying a character device driver can access a file? How about
Solaris or HP-UX?

Where can I get more information about this?

John

 
 
 

Character Device Driver

Post by Vladimir Ivano » Wed, 30 Apr 2003 17:27:56



Quote:> So you saying a character device driver can access a file? How about
> Solaris or HP-UX?

> Where can I get more information about this?

http://docs.sun.com/db/doc/805-7378

--
Vladimir Ivanov

 
 
 

Character Device Driver

Post by Fritz » Thu, 01 May 2003 00:59:51



> So you saying a character device driver can access a file? How about
> Solaris or HP-UX?

In Solaris, there is no public API for accessing files from the kernel.  
It's doable, but you've gotta roll your own functions.

It's been a few years since I've done anything with HP-UX so I can't
comment on that.

AIX and Linux both have kernel functions available for file I/O.

RFM
--
To reply, translate domain from l33+ 2p33|< to alpha.
                4=a  0=o  3=e  +=t

 
 
 

Character Device Driver

Post by John » Thu, 01 May 2003 05:10:56





>> So you saying a character device driver can access a file? How about
>> Solaris or HP-UX?

>In Solaris, there is no public API for accessing files from the kernel.  
>It's doable, but you've gotta roll your own functions.

And how would I do that? There's No kernel function to access a file?

Quote:>It's been a few years since I've done anything with HP-UX so I can't
>comment on that.

Currently I'm more interested in Solaris.
Quote:

>AIX and Linux both have kernel functions available for file I/O.

>RFM

 
 
 

Character Device Driver

Post by John » Thu, 01 May 2003 05:18:39




>> So you saying a character device driver can access a file? How about
>> Solaris or HP-UX?

>> Where can I get more information about this?

>http://docs.sun.com/db/doc/805-7378

Thank for the information. However, I didn't find any information how
a character device driver can access a file.

What I'm trying to do is access a file that contains driver
information. Similar to the way Windows NT has a registry that drivers
and applications can access.

John

 
 
 

Character Device Driver

Post by p.. » Thu, 01 May 2003 05:32:20





>>> So you saying a character device driver can access a file? How about
>>> Solaris or HP-UX?

>>> Where can I get more information about this?

>>http://docs.sun.com/db/doc/805-7378
> Thank for the information. However, I didn't find any information how
> a character device driver can access a file.
> What I'm trying to do is access a file that contains driver
> information. Similar to the way Windows NT has a registry that drivers
> and applications can access.

I don't think you will find it generally possible in un*x as it's a layered system
where kernel mode is quite different from user-mode. ( you could say "It's DESIGNED" )

The "standard way" is to have a user-level utility/daemon do user-level stuff
like reading files etc. ioctl() is usually used for this.

Quote:> John

--
Peter H?kanson        
        IPSec  Sverige      ( At Gothenburg Riverside )
           Sorry about my e-mail address, but i'm trying to keep spam out,
           remove "icke-reklam" if you feel for mailing me. Thanx.
 
 
 

Character Device Driver

Post by Andrew Gabri » Thu, 01 May 2003 15:27:17






>>> So you saying a character device driver can access a file? How about
>>> Solaris or HP-UX?

>>> Where can I get more information about this?

>>http://docs.sun.com/db/doc/805-7378

> Thank for the information. However, I didn't find any information how
> a character device driver can access a file.

> What I'm trying to do is access a file that contains driver
> information. Similar to the way Windows NT has a registry that drivers
> and applications can access.

To retrieve the information from a driver's .conf file, see
the ddi_prop_op(9F) man pages.

If the config data doesn't fit in the .conf file format, then
like another poster said, have a configuration program read
the file, and pass it in through the device driver interface
using special ioctl or some such.

--
Andrew Gabriel
Consultant Software Engineer

 
 
 

Character Device Driver

Post by Fritz » Fri, 02 May 2003 02:23:28



> What I'm trying to do is access a file that contains driver
> information. Similar to the way Windows NT has a registry that drivers
> and applications can access.

In Solaris, driver configuration isn't done by directly reading a file.  
There's a conf file, and there are kernel functions to lookup the
properties that are specified in the file.  See the man pages for
driver.conf(4), ddi_prop_get_int(9F), and ddi_prop_lookup(9F) for
details.  Start here for an online discussion of these:

  http://docs.sun.com/db/doc/806-0633/6j9vn6q3i?a=view

Also, read chapter 4 in the "Writing Device Drivers" book.

As others have noted, the standard way for Unix kernel entities to access
a file is to have a user proxy do it for you.

RFM
--
To reply, translate domain from l33+ 2p33|< to alpha.
                4=a  0=o  3=e  +=t

 
 
 

Character Device Driver

Post by John » Fri, 02 May 2003 05:43:00





>> What I'm trying to do is access a file that contains driver
>> information. Similar to the way Windows NT has a registry that drivers
>> and applications can access.

>In Solaris, driver configuration isn't done by directly reading a file.  
>There's a conf file, and there are kernel functions to lookup the
>properties that are specified in the file.  See the man pages for
>driver.conf(4), ddi_prop_get_int(9F), and ddi_prop_lookup(9F) for
>details.  Start here for an online discussion of these:

>  http://docs.sun.com/db/doc/806-0633/6j9vn6q3i?a=view

>Also, read chapter 4 in the "Writing Device Drivers" book.

>As others have noted, the standard way for Unix kernel entities to access
>a file is to have a user proxy do it for you.

>RFM

What started this discussion is that we have a PCI adaptor with
loadable firmware. This firmware changes the way the adaptor  behaves
(personality). Having 2 device driver, one to handle one personality
and the other to handle the other make it difficult to know which
adaptor goes with which driver.

The easiest way would be to create 1 device driver that handle both
personalities and with an ioctl call have the user change the adaptors
personality.

In windows NT, it was easy; just made an entry into the register. Made
a user program that allowed the user to modify the register to change
the adaptor from personality 1 to personality 2. The registry entry
was keyed on bus/slot number of the adaptor.

 
 
 

Character Device Driver

Post by Fritz » Fri, 02 May 2003 08:25:34



> In windows NT, it was easy; just made an entry into the register. Made
> a user program that allowed the user to modify the register to change
> the adaptor from personality 1 to personality 2. The registry entry
> was keyed on bus/slot number of the adaptor.

If personalities change during runtime, the driver.conf file probably isn't
the best approach.  If that's the case, the tactic is probably to write a
user program to send an ioctl to the driver directly.  There's not a good
way to asynchronously notify a kernel module of a change in a file.

Can the driver detect which firmware the adapter is operating with?

RFM
--
To reply, translate domain from l33+ 2p33|< to alpha.
                4=a  0=o  3=e  +=t

 
 
 

Character Device Driver

Post by Joseph Reut » Sat, 03 May 2003 00:40:20





[snip]

> Currently I'm more interested in Solaris.

In solaris, the driver.conf(4) file is the analog of the Windows Registry.
I use it to turn debugging on and off in drivers, so I suspect it will
work for your purpose of distinguishing between two downloads. Just
define a property with an integer value. Access the property as described
in a prior posting.

Joseph Reuter
----------
In theory, theory and practice are the same;
in practice, they're not.

 
 
 

Character Device Driver

Post by KJK::Hyperio » Mon, 19 May 2003 07:32:59


Quote:> Can I character device driver access or write to a file? I been told
> NO.

you've probably been told you *shouldn't* access files from kernel
mode, and it's generally true

Quote:> If the answer is no please explain why.

you should never put a text parser in kernel mode. All a device driver
should do is communicating with the hardware and other parts of the
system, and manipulate the simplest binary data possible. I see you
need a configuration file for your device - well, don't. Parse the
configuration file in an user-mode program, and pass the pre-parsed
data to the driver through a custom IOCTL

Quote:> My background is writing device drivers for  Windows NT. It was hard
> for me to believe that any device driver couldn't read/write to a
> file.

well, I don't know about Solaris, but in Windows NT, you can open files
from kernel mode. You open them with ZwCreateFile, and read from/write
to them with ZwReadFile/ZwWriteFile (all of which are documented in the
DDK) - not to mention you can build the IRPs by yourself (documented
too) for the maximum flexibility you could ask for
 
 
 

1. EOF for character device drivers

Hello people,

First, sorry if you have read this posting in one of the other
groups already.

The Problem:

I have developed a SCSI Target device driver on Solaris 2.5.1 to
driver a direct-access device we developed.  The driver and
device work fine, and I support both block and character modes.

As recommended on the Device Drivers Developers Couse I have implemented
the character I/O as calls to the strategy(9E) using physio(9F).

If I run a command like:
  # cat <raw_dev> | gzip > backup.file
all goes well until the end.  A read for data beyond the end of
the device is made, and an I/O error occurs - which is the error
I return if a request is made for data beyond the limit of the
device.

My questions are these:

If I get a request for a block execeds the device limit should I
clip the request and only process the data for which there is data?

When I get a request for data beyond the limit of the device what
error should I return?

Is there some call I should be making to the kernel to inform it of the
limit of the character device.

Many thanks for reading this far and special thanks if you can offer
any help.  

--

############## Steve Dobson
#######      # Computing Devices Company Ltd
#######  ##  # Castleham Road, St. Leonards On Sea, TN38 9NJ, UK.
#        ##  #
#######  ##  # Tel:   +44-(0)1424-853481 x2418
#######      # Fax:   +44-(0)1424-851520


                      URL:  WWW.Krasnegar.Demon.Co.UK

2. exmh Questions

3. Character device drivers and the foibles of minphys

4. linux kernel bug report: 2.4.10-pre5, kernel BUG at page_alloc.c:191 during using of NTFS read-only fs

5. Using DMA in a character device driver under SCO UNIX

6. BUG: MS-DOS fs

7. Character Device Drivers

8. Red Hat 60. Question

9. How to change a module to a character device driver

10. character device, block device , raw device?

11. Writing character special device drivers for Solaris

12. Character driver -> networked device

13. Device Driver Template - Character