Opening a /dev file from Kernel space - Linux

This is a discussion on Opening a /dev file from Kernel space - Linux ; Hi, I want to open the serilal driver (/dev/ttyS0) from the kernel space. I need to write a character driver in the kernel (the requirements of the project insist that it will be inside the kernel) that gets special strings ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Opening a /dev file from Kernel space

  1. Opening a /dev file from Kernel space

    Hi,
    I want to open the serilal driver (/dev/ttyS0) from the kernel space.
    I need to write a character driver in the kernel (the requirements of
    the project insist that it will be inside the kernel) that gets special
    strings from user and pass them to the serial.

    In order to implement that I thought of opening the serial driver as if
    I was a user and with the file descriptor to read()/write()/ioctl()
    etc...

    Can I do this from the kernel space?
    Do you have maybe a better idea how to implement?

    Thanks
    Hagit


  2. Re: Opening a /dev file from Kernel space

    > I want to open the serilal driver (/dev/ttyS0) from the kernel space.
    > I need to write a character driver in the kernel (the requirements of
    > the project insist that it will be inside the kernel) that gets special
    > strings from user and pass them to the serial.
    >
    > In order to implement that I thought of opening the serial driver as if
    > I was a user and with the file descriptor to read()/write()/ioctl()
    > etc...
    >
    > Can I do this from the kernel space?
    > Do you have maybe a better idea how to implement?


    This sounds like a "line discipline" for a serial device: a special way
    to interpret the byte stream flowing between the user and the device:
    something other than uninterpreted, 1-for-1 transport.

    The most common line discipline is the code for a VGA text console
    which performs character echoing (so you can see what you type), handles
    backspace-as-delete, rings the bell for control-G, sends SIGINT for
    control-C, turns ('\r') into newline ('\n') on input, turns
    newline ('\n') into carriage_return + linefeed ("\r\n") on ouput, etc.

    The user opens the device, performs an ioctl() to choose the line
    discipline, then transfers data using read() or write(). The line
    discipline is a "filter" which resides inside the kernel, instead
    of in a shell pipeline. See linux/Documentation/tty.txt.

    --


  3. Re: Opening a /dev file from Kernel space


    John Reiser wrote:
    > > I want to open the serilal driver (/dev/ttyS0) from the kernel space.
    > > I need to write a character driver in the kernel (the requirements of
    > > the project insist that it will be inside the kernel) that gets special
    > > strings from user and pass them to the serial.
    > >
    > > In order to implement that I thought of opening the serial driver as if
    > > I was a user and with the file descriptor to read()/write()/ioctl()
    > > etc...
    > >
    > > Can I do this from the kernel space?
    > > Do you have maybe a better idea how to implement?

    >
    > This sounds like a "line discipline" for a serial device: a special way
    > to interpret the byte stream flowing between the user and the device:
    > something other than uninterpreted, 1-for-1 transport.
    >
    > The most common line discipline is the code for a VGA text console
    > which performs character echoing (so you can see what you type), handles
    > backspace-as-delete, rings the bell for control-G, sends SIGINT for
    > control-C, turns ('\r') into newline ('\n') on input, turns
    > newline ('\n') into carriage_return + linefeed ("\r\n") on ouput, etc.
    >
    > The user opens the device, performs an ioctl() to choose the line
    > discipline, then transfers data using read() or write(). The line
    > discipline is a "filter" which resides inside the kernel, instead
    > of in a shell pipeline. See linux/Documentation/tty.txt.
    >
    > --


    Thanks but the serial driver is just one of the drivers I want to open
    from the kernel space.
    I need a generic way to open devices (via /dev) from the kernel space.
    The projetc requirments defines that user should open my special driver
    and do some operations on the device.
    Anyway, I thought about opening the /dev/KernelDriver (like ttyS0 or
    dv1394) from my special driver. User shall open my driver and
    send/receive like it was the kernel driver. I will pass the
    send/receivew of the user to the kernel driver I have opened from the
    kernel.
    What do u say?
    Is there any way to do it?
    open the device and get the file descriptor to use in read() write()???


+ Reply to Thread