Compare commits
45 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
56bf9b87fe | ||
|
|
081f817cac | ||
|
|
483be78d0d | ||
|
|
61f72c675d | ||
|
|
30f606be39 | ||
|
|
41e61a81f8 | ||
|
|
ac6def392c | ||
|
|
3e71c6e74f | ||
|
|
9116a9917b | ||
|
|
f184634d5f | ||
|
|
a765b0745d | ||
|
|
0132d11b4b | ||
|
|
f404dd7061 | ||
|
|
d8fea5550c | ||
|
|
101f3687ff | ||
|
|
68b4fd7b40 | ||
|
|
eb9511d9b3 | ||
|
|
43b1069b54 | ||
|
|
d27a3f2ee1 | ||
|
|
2ce7c94d11 | ||
|
|
36fd2b86c5 | ||
|
|
c37e562e5f | ||
|
|
57ae74c803 | ||
|
|
a54adc616d | ||
|
|
095ac4569a | ||
|
|
70f58ed6dc | ||
|
|
596df479c2 | ||
|
|
1cf7fd077c | ||
|
|
75a05048a4 | ||
|
|
0ce298ca33 | ||
|
|
fa61f857a7 | ||
|
|
684a150a21 | ||
|
|
4db826209e | ||
|
|
1b50ad2d74 | ||
|
|
48264ec40a | ||
|
|
1afa952fb0 | ||
|
|
b208b10645 | ||
|
|
3c0b0cdd4b | ||
|
|
9f496af46b | ||
|
|
fd1f2a7374 | ||
|
|
0678a66b3c | ||
|
|
542d87ea75 | ||
|
|
472265ae8a | ||
|
|
789713fa0b | ||
|
|
efd39ff55a |
2
.gitignore
vendored
2
.gitignore
vendored
@ -21,3 +21,5 @@ examples/ioctl
|
||||
examples/logring
|
||||
examples/pager
|
||||
examples/uid-filter
|
||||
examples/mmap-read
|
||||
examples/mmap-test
|
||||
|
||||
142
.travis.yml
Normal file
142
.travis.yml
Normal file
@ -0,0 +1,142 @@
|
||||
language: c
|
||||
os: linux
|
||||
dist: trusty
|
||||
compiler: gcc
|
||||
|
||||
env:
|
||||
global:
|
||||
- KERNEL_GIT="https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git"
|
||||
|
||||
matrix:
|
||||
include:
|
||||
# Older version of the kernel
|
||||
# - name: "Kernel 2.6.13"
|
||||
# env: KERNEL_BRANCH="v2.6.13" GCC_VER="gcc-4.9"
|
||||
# addons:
|
||||
# apt:
|
||||
# packages:
|
||||
# - gcc-4.9
|
||||
# sources:
|
||||
# - ubuntu-toolchain-r-test
|
||||
|
||||
- name: "Kernel 2.6.32"
|
||||
env: KERNEL_BRANCH="v2.6.32" GCC_VER="gcc-4.9"
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- gcc-4.9
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- name: "Kernel 3.10.0"
|
||||
env: KERNEL_BRANCH="v3.10" GCC_VER="gcc-4.9"
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- gcc-4.9
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
# Here are actively supported kernel
|
||||
- name: "Kernel 3.16.y LTS"
|
||||
env: KERNEL_BRANCH="linux-3.16.y" GCC_VER="gcc-5"
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- gcc-5
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- name: "Kernel 4.4.y LTS"
|
||||
env: KERNEL_BRANCH="linux-4.4.y" GCC_VER="gcc-5"
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- gcc-5
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- name: "Kernel 4.9.y LTS"
|
||||
env: KERNEL_BRANCH="linux-4.9.y" GCC_VER="gcc-6"
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- gcc-6
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- name: "Kernel 4.14.y LTS"
|
||||
env: KERNEL_BRANCH="linux-4.14.y" GCC_VER="gcc-7"
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- libelf-dev
|
||||
- gcc-7
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- name: "Kernel 4.19.y LTS"
|
||||
env: KERNEL_BRANCH="linux-4.19.y" GCC_VER="gcc-7"
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- libelf-dev
|
||||
- gcc-7
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- name: "Kernel 5.4.y LTS"
|
||||
env: KERNEL_BRANCH="linux-5.4.y" GCC_VER="gcc-8"
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- libelf-dev
|
||||
- gcc-8
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
# Stable versions
|
||||
- name: "Kernel 5.7.y STABLE"
|
||||
env: KERNEL_BRANCH="linux-5.7.y" GCC_VER="gcc-8"
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- libelf-dev
|
||||
- gcc-8
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- name: "Kernel 5.8.y STABLE"
|
||||
env: KERNEL_BRANCH="linux-5.8.y" GCC_VER="gcc-8"
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- libelf-dev
|
||||
- gcc-8
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
allow_failures:
|
||||
- name: "Kernel 5.8.y STABLE"
|
||||
|
||||
|
||||
# Here checkout kernels
|
||||
before_script:
|
||||
- eval "export CC=${GCC_VER}"
|
||||
- eval "${CC} --version"
|
||||
- git clone ${KERNEL_GIT} --depth=1 --branch=${KERNEL_BRANCH} ${KERNEL_BRANCH}
|
||||
- pushd .
|
||||
- cd $KERNEL_BRANCH
|
||||
- yes "" | make oldconfig CC=${GCC_VER}
|
||||
- make prepare CC=${GCC_VER}
|
||||
- make scripts CC=${GCC_VER}
|
||||
- popd
|
||||
|
||||
# Now build with kernel sources
|
||||
script:
|
||||
- make KDIR=${PWD}/${KERNEL_BRANCH} CC=${GCC_VER}
|
||||
|
||||
# Not sure if I should cache the kernel source tree...
|
||||
#cache:
|
||||
# directories:
|
||||
# - '$HOME/.sonar/cache'
|
||||
|
||||
2
Makefile
2
Makefile
@ -23,8 +23,6 @@ export
|
||||
|
||||
####################################################
|
||||
|
||||
SUBDIRS = kfusd libfusd examples
|
||||
|
||||
default:
|
||||
$(MAKE) -C libfusd
|
||||
$(MAKE) -C kfusd
|
||||
|
||||
139
README
139
README
@ -1,139 +0,0 @@
|
||||
|
||||
FUSD: A Linux Framework for User-Space Devices
|
||||
----------------------------------------------
|
||||
|
||||
Welcome to FUSD!
|
||||
|
||||
This is FUSD snapshot 20070111, released 11 January 2007. You can get
|
||||
the most recent source, along with online documentation, from xiph.org
|
||||
SVN:
|
||||
|
||||
http://svn.xiph.org/trunk/fusd
|
||||
|
||||
There is extensive documentation available in the 'doc' directory.
|
||||
The FUSD User Manual is available in PDF, Postscript, and HTML format.
|
||||
Most of this documentation dates from earlier versions of fusd; until
|
||||
it is fully updated, it may not cover all features that exist in the
|
||||
current version of fusd.
|
||||
|
||||
FUSD is free and open source software, released under a BSD-style
|
||||
license. See the file 'LICENSE' for details.
|
||||
|
||||
|
||||
QUICK START GUIDE
|
||||
=================
|
||||
|
||||
Instructions for the impatient:
|
||||
|
||||
1- Make sure you're using a system running Linux 2.6.x with udev; this
|
||||
version of fusd is incompatable with the now-deprecated devfs. If the
|
||||
kernel is a packaged version from a distribution, also verify any
|
||||
optional packages needed for building new kernel modules are also
|
||||
installed.
|
||||
|
||||
2- 'make ; make install' builds everything including examples, then
|
||||
installs the libraries, includes and kernel module.
|
||||
|
||||
3- Update the udev configuration (usually in /etc/udev/rules.d/) to
|
||||
include the following rule:
|
||||
|
||||
# fusd device
|
||||
SUBSYSTEM=="fusd", NAME="fusd/%k"
|
||||
|
||||
After updating, restart udevd (skill udevd; udevd -d).
|
||||
|
||||
4- Insert the FUSD kernel module (modprobe kfusd)
|
||||
|
||||
5- Verify the fusd devices /dev/fusd/status and /dev/fusd/control
|
||||
exist. If the modprobe succeeds but no fusd devices appear,
|
||||
doublecheck the udev rule config change and make sure udevd restarted
|
||||
successfully. The kfusd kernel module must be inserted after udev has
|
||||
been correctly configured and restarted.
|
||||
|
||||
6- Try running the helloworld example program (examples/helloworld).
|
||||
When helloworld is running, 'cat /dev/helloworld' should return
|
||||
'Hello, world!'.
|
||||
|
||||
7- For more information, read the User's Manual in the 'doc' directory.
|
||||
|
||||
WHAT IS FUSD?
|
||||
=============
|
||||
|
||||
FUSD (pronounced "fused") is a Linux framework for proxying device
|
||||
file callbacks into user-space, allowing device files to be
|
||||
implemented by daemons instead of kernel code. Despite being
|
||||
implemented in user-space, FUSD devices can look and act just like any
|
||||
other file under /dev which is implemented by kernel callbacks.
|
||||
|
||||
A user-space device driver can do many of the things that kernel
|
||||
drivers can't, such as perform a long-running computation, block while
|
||||
waiting for an event, or read files from the file system. Unlike
|
||||
kernel drivers, a user-space device driver can use other device
|
||||
drivers--that is, access the network, talk to a serial port, get
|
||||
interactive input from the user, pop up GUI windows, or read from
|
||||
disks. User-space drivers implemented using FUSD can be much easier to
|
||||
debug; it is impossible for them to crash the machine, are easily
|
||||
traceable using tools such as gdb, and can be killed and restarted
|
||||
without rebooting. FUSD drivers don't have to be in C--Perl, Python,
|
||||
or any other language that knows how to read from and write to a file
|
||||
descriptor can work with FUSD. User-space drivers can be swapped out,
|
||||
whereas kernel drivers lock physical memory.
|
||||
|
||||
FUSD drivers are conceptually similar to kernel drivers: a set of
|
||||
callback functions called in response to system calls made on file
|
||||
descriptors by user programs. FUSD's C library provides a device
|
||||
registration function, similar to the kernel's devfs_register_chrdev()
|
||||
function, to create new devices. fusd_register() accepts the device
|
||||
name and a structure full of pointers. Those pointers are callback
|
||||
functions which are called in response to certain user system
|
||||
calls--for example, when a process tries to open, close, read from, or
|
||||
write to the device file. The callback functions should conform to
|
||||
the standard definitions of POSIX system call behavior. In many ways,
|
||||
the user-space FUSD callback functions are identical to their kernel
|
||||
counterparts.
|
||||
|
||||
The proxying of kernel system calls that makes this kind of program
|
||||
possible is implemented by FUSD, using a combination of a kernel
|
||||
module and cooperating user-space library. The kernel module
|
||||
implements a character device, /dev/fusd, which is used as a control
|
||||
channel between the two. fusd_register() uses this channel to send a
|
||||
message to the FUSD kernel module, telling the name of the device the
|
||||
user wants to register. The kernel module, in turn, registers that
|
||||
device with the kernel proper using devfs. devfs and the kernel don't
|
||||
know anything unusual is happening; it appears from their point of
|
||||
view that the registered devices are simply being implemented by the
|
||||
FUSD module.
|
||||
|
||||
Later, when kernel makes a callback due to a system call (e.g. when
|
||||
the character device file is opened or read), the FUSD kernel module's
|
||||
callback blocks the calling process, marshals the arguments of the
|
||||
callback into a message and sends it to user-space. Once there, the
|
||||
library half of FUSD unmarshals it and calls whatever user-space
|
||||
callback the FUSD driver passed to fusd_register(). When that
|
||||
user-space callback returns a value, the process happens in reverse:
|
||||
the return value and its side-effects are marshaled by the library
|
||||
and sent to the kernel. The FUSD kernel module unmarshals this
|
||||
message, matches it up with a corresponding outstanding request, and
|
||||
completes the system call. The calling process is completely unaware
|
||||
of this trickery; it simply enters the kernel once, blocks, unblocks,
|
||||
and returns from the system call---just as it would for any other
|
||||
blocking call.
|
||||
|
||||
One of the primary design goals of FUSD is stability. It should
|
||||
not be possible for a FUSD driver to corrupt or crash the kernel,
|
||||
either due to error or malice. Of course, a buggy driver itself may
|
||||
corrupt itself (e.g., due to a buffer overrun). However, strict error
|
||||
checking is implemented at the user-kernel boundary which should
|
||||
prevent drivers from corrupting the kernel or any other user-space
|
||||
process---including the errant driver's own clients, and other FUSD
|
||||
drivers.
|
||||
|
||||
For more information, please see the comprehensive documentation in
|
||||
the 'doc' directory.
|
||||
|
||||
Jeremy Elson <jelson@circlemud.org>
|
||||
August 19, 2003
|
||||
|
||||
updated,
|
||||
Monty <monty@xiph.org>
|
||||
January 11, 2007
|
||||
156
README.markdown
Normal file
156
README.markdown
Normal file
@ -0,0 +1,156 @@
|
||||
|
||||
FUSD: A Linux Framework for User-Space Devices
|
||||
----------------------------------------------
|
||||
|
||||
[](https://travis-ci.org/Godzil/fusd)
|
||||
|
||||
**Welcome to FUSD!**
|
||||
|
||||
This is FUSD snapshot 20110401, released 18 January 2012. This fork is based
|
||||
on the found on the xiph.org SVN tracker. ( http://svn.xiph.org/trunk/fusd )
|
||||
They seems to no longer update this tool (since 11 January 2007) and since it
|
||||
longer compile with recent Linux kernel (at around 2.6.21) and since I need
|
||||
it in personal project, I ported it to newer version (current version is 2.6.32).
|
||||
It is currently no officialy supporting newer kernel, but changes are currently
|
||||
going on to support newer kernel up to 4.15. It is currently building under this
|
||||
line, but don't expect it to work.
|
||||
|
||||
|
||||
Some feature are still missing missing or buggy form the Xiph version (due to
|
||||
changes on the kernel source tree), but it is still usable.
|
||||
|
||||
The official URL for this fork is:
|
||||
|
||||
http://github.com/Godzil/fusd
|
||||
|
||||
There is extensive documentation available in the 'doc' directory.
|
||||
The FUSD User Manual is available in PDF, Postscript, and HTML format.
|
||||
Most of this documentation dates from earlier versions of fusd; until
|
||||
it is fully updated, it may not cover all features that exist in the
|
||||
current version of fusd.
|
||||
|
||||
FUSD is free and open source software, released under a BSD-style
|
||||
license. See the file 'LICENSE' for details.
|
||||
|
||||
|
||||
QUICK START GUIDE
|
||||
=================
|
||||
|
||||
Instructions for the impatient:
|
||||
|
||||
1. Make sure you're using a system running Linux 2.6.x with udev; this
|
||||
version of fusd is incompatable with the now-deprecated devfs. If the
|
||||
kernel is a packaged version from a distribution, also verify any
|
||||
optional packages needed for building new kernel modules are also
|
||||
installed.
|
||||
|
||||
2. 'make ; make install' builds everything including examples, then
|
||||
installs the libraries, includes and kernel module.
|
||||
|
||||
3. Update the udev configuration (usually in /etc/udev/rules.d/) to
|
||||
include the following rule:
|
||||
|
||||
fusd device
|
||||
SUBSYSTEM=="fusd", NAME="fusd/%k"
|
||||
|
||||
After updating, restart udevd (skill udevd; udevd -d).
|
||||
|
||||
4. Insert the FUSD kernel module (`modprobe kfusd`)
|
||||
|
||||
5. Verify the fusd devices /dev/fusd/status and /dev/fusd/control
|
||||
exist. If the modprobe succeeds but no fusd devices appear,
|
||||
double-check the udev rule config change and make sure udevd restarted
|
||||
successfully. The kfusd kernel module must be inserted after udev has
|
||||
been correctly configured and restarted.
|
||||
|
||||
6. Try running the `helloworld` example program (examples/helloworld).
|
||||
When helloworld is running, `cat /dev/helloworld` should return
|
||||
`Hello, world!`.
|
||||
|
||||
7. For more information, read the User's Manual in the 'doc' directory.
|
||||
|
||||
WHAT IS FUSD?
|
||||
=============
|
||||
|
||||
FUSD (pronounced "fused") is a Linux framework for proxying device
|
||||
file callbacks into user-space, allowing device files to be
|
||||
implemented by daemons instead of kernel code. Despite being
|
||||
implemented in user-space, FUSD devices can look and act just like any
|
||||
other file under /dev which is implemented by kernel callbacks.
|
||||
|
||||
A user-space device driver can do many of the things that kernel
|
||||
drivers can't, such as perform a long-running computation, block while
|
||||
waiting for an event, or read files from the file system. Unlike
|
||||
kernel drivers, a user-space device driver can use other device
|
||||
drivers--that is, access the network, talk to a serial port, get
|
||||
interactive input from the user, pop up GUI windows, or read from
|
||||
disks. User-space drivers implemented using FUSD can be much easier to
|
||||
debug; it is impossible for them to crash the machine, are easily
|
||||
traceable using tools such as gdb, and can be killed and restarted
|
||||
without rebooting. FUSD drivers don't have to be in C--Perl, Python,
|
||||
or any other language that knows how to read from and write to a file
|
||||
descriptor can work with FUSD. User-space drivers can be swapped out,
|
||||
whereas kernel drivers lock physical memory.
|
||||
|
||||
FUSD drivers are conceptually similar to kernel drivers: a set of
|
||||
callback functions called in response to system calls made on file
|
||||
descriptors by user programs. FUSD's C library provides a device
|
||||
registration function, similar to the kernel's devfs_register_chrdev()
|
||||
function, to create new devices. fusd_register() accepts the device
|
||||
name and a structure full of pointers. Those pointers are callback
|
||||
functions which are called in response to certain user system
|
||||
calls--for example, when a process tries to open, close, read from, or
|
||||
write to the device file. The callback functions should conform to
|
||||
the standard definitions of POSIX system call behavior. In many ways,
|
||||
the user-space FUSD callback functions are identical to their kernel
|
||||
counterparts.
|
||||
|
||||
The proxying of kernel system calls that makes this kind of program
|
||||
possible is implemented by FUSD, using a combination of a kernel
|
||||
module and cooperating user-space library. The kernel module
|
||||
implements a character device, /dev/fusd, which is used as a control
|
||||
channel between the two. fusd_register() uses this channel to send a
|
||||
message to the FUSD kernel module, telling the name of the device the
|
||||
user wants to register. The kernel module, in turn, registers that
|
||||
device with the kernel proper using devfs. devfs and the kernel don't
|
||||
know anything unusual is happening; it appears from their point of
|
||||
view that the registered devices are simply being implemented by the
|
||||
FUSD module.
|
||||
|
||||
Later, when kernel makes a callback due to a system call (e.g. when
|
||||
the character device file is opened or read), the FUSD kernel module's
|
||||
callback blocks the calling process, marshals the arguments of the
|
||||
callback into a message and sends it to user-space. Once there, the
|
||||
library half of FUSD unmarshals it and calls whatever user-space
|
||||
callback the FUSD driver passed to fusd_register(). When that
|
||||
user-space callback returns a value, the process happens in reverse:
|
||||
the return value and its side-effects are marshaled by the library
|
||||
and sent to the kernel. The FUSD kernel module unmarshals this
|
||||
message, matches it up with a corresponding outstanding request, and
|
||||
completes the system call. The calling process is completely unaware
|
||||
of this trickery; it simply enters the kernel once, blocks, unblocks,
|
||||
and returns from the system call---just as it would for any other
|
||||
blocking call.
|
||||
|
||||
One of the primary design goals of FUSD is stability. It should
|
||||
not be possible for a FUSD driver to corrupt or crash the kernel,
|
||||
either due to error or malice. Of course, a buggy driver itself may
|
||||
corrupt itself (e.g., due to a buffer overrun). However, strict error
|
||||
checking is implemented at the user-kernel boundary which should
|
||||
prevent drivers from corrupting the kernel or any other user-space
|
||||
process---including the errant driver's own clients, and other FUSD
|
||||
drivers.
|
||||
|
||||
For more information, please see the comprehensive documentation in
|
||||
the 'doc' directory.
|
||||
|
||||
> Jeremy Elson <jelson@circlemud.org> <br>
|
||||
> August 19, 2003 <br>
|
||||
|
||||
> updated,<br>
|
||||
> Monty <monty@xiph.org> <br>
|
||||
> January 11, 2007 <br>
|
||||
|
||||
> Updated, <br>
|
||||
> Godzil <godzil@godzil.net> <br>
|
||||
> March 01, 2011 / January 18, 2012 (public release on github)
|
||||
@ -7,7 +7,6 @@
|
||||
% Released under open-source, BSD license
|
||||
% See LICENSE file for full license
|
||||
%
|
||||
% $Id: fusd.tex,v 1.63 2003/08/20 22:00:55 jelson Exp $
|
||||
|
||||
\documentclass{article}
|
||||
\addtolength{\topmargin}{-.5in} % repairing LaTeX's huge margins...
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
%
|
||||
% $Id: html.sty,v 1.1 2001/05/12 00:38:48 cvs Exp $
|
||||
% LaTeX2HTML Version 99.2 : html.sty
|
||||
%
|
||||
% This file contains definitions of LaTeX commands which are
|
||||
|
||||
@ -1,23 +1,27 @@
|
||||
SRC = console-read.c drums3.c echo.c helloworld.c logring.c pager.c\
|
||||
drums2.c drums.c ioctl.c uid-filter.c
|
||||
OBJ = console-read.o drums3.o echo.o helloworld.o logring.o pager.o\
|
||||
drums2.o drums.o ioctl.o uid-filter.o
|
||||
drums2.o drums.o ioctl.o uid-filter.o mmap-test.o
|
||||
TARGETS = console-read drums3 echo helloworld logring pager\
|
||||
drums2 drums ioctl uid-filter
|
||||
drums2 drums ioctl uid-filter mmap-test
|
||||
|
||||
default: $(TARGETS)
|
||||
default: $(TARGETS) mmap-read
|
||||
|
||||
install: $(TARGETS)
|
||||
|
||||
clean:
|
||||
rm -f *.o *.d $(TARGETS) gmon.out *~
|
||||
|
||||
$(TARGETS): %: %.c
|
||||
mmap-read: mmap-read.c
|
||||
$(CC) $< -o $@
|
||||
|
||||
$(TARGETS): %: %.c ../libfusd/libfusd.a
|
||||
$(CC) $(GCF) $< -o $@ ../libfusd/libfusd.a
|
||||
|
||||
%.d: %.c
|
||||
$(CC) -M $(CFLAGS) $< > $@.$$$$; sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; rm -f $@.$$$$
|
||||
|
||||
|
||||
ifeq ($(MAKECMDGOALS),target)
|
||||
include $(SRC:.c=.d)
|
||||
endif
|
||||
|
||||
@ -40,7 +40,6 @@
|
||||
* need a template from which to start on a real driver, use pager.c
|
||||
* instead.
|
||||
*
|
||||
* $Id: console-read.c 12351 2007-01-19 07:22:54Z xiphmont $
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
@ -42,7 +42,6 @@
|
||||
* directory: /dev/drums/bam, /dev/drums/bum, etc. If you cat one of
|
||||
* these devices, it returns a string that's the same as its name.
|
||||
*
|
||||
* $Id: drums.c 12355 2007-01-19 17:44:17Z xiphmont $
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
@ -47,10 +47,10 @@
|
||||
* to remember if this user has read before; cat /dev/drums/X will
|
||||
* read infinitely
|
||||
*
|
||||
* $Id: drums2.c 12355 2007-01-19 17:44:17Z xiphmont $
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@ -43,7 +43,6 @@
|
||||
* However, it also prints a prompt to the console, asking the user if
|
||||
* how loud the drums should be.
|
||||
*
|
||||
* $Id: drums3.c 12351 2007-01-19 07:22:54Z xiphmont $
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
@ -41,7 +41,6 @@
|
||||
* stored. Then, when you read (e.g. "cat /dev/echo"), you get back
|
||||
* whatever you wrote most recently.
|
||||
*
|
||||
* $Id: echo.c 12351 2007-01-19 07:22:54Z xiphmont $
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
2
examples/fusd.rules
Normal file
2
examples/fusd.rules
Normal file
@ -0,0 +1,2 @@
|
||||
SUBSYSTEM=="fusd", NAME="fusd/%k"
|
||||
|
||||
@ -37,7 +37,6 @@
|
||||
* hello-world: Simply creates a device called /dev/hello-world, which
|
||||
* greets you when you try to get it.
|
||||
*
|
||||
* $Id: helloworld.c 12351 2007-01-19 07:22:54Z xiphmont $
|
||||
*/
|
||||
|
||||
/* EXAMPLE START helloworld.c */
|
||||
|
||||
@ -41,7 +41,6 @@
|
||||
* the other examples, anyway), because this program is both an
|
||||
* example and part of the regression test suite.
|
||||
*
|
||||
* $Id: ioctl.c 12351 2007-01-19 07:22:54Z xiphmont $
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
@ -71,7 +71,6 @@
|
||||
* but want to use it on a system that does not have FUSD, check out
|
||||
* emlog at http://www.circlemud.org/~jelson/software/emlog.
|
||||
*
|
||||
* $Id: logring.c 12351 2007-01-19 07:22:54Z xiphmont $
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
110
examples/mmap-read.c
Normal file
110
examples/mmap-read.c
Normal file
@ -0,0 +1,110 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2003 The Regents of the University of California. All
|
||||
* rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* - Neither the name of the University nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* FUSD - The Framework for UserSpace Devices - Example program
|
||||
*
|
||||
* This mmap a file/device and change it a bit.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
static void hexdump(void *ptr_r, int size)
|
||||
{
|
||||
int J, I;
|
||||
unsigned char *ptr = ptr_r;
|
||||
unsigned long Addr = 0;
|
||||
if (ptr == NULL) {
|
||||
puts("NULL POINTER");
|
||||
puts("-------------------------------------------------------------------------------------");
|
||||
return;
|
||||
}
|
||||
while (Addr <= size) {
|
||||
for (J = 0; J < 2; J++) {
|
||||
printf("%08p: ", Addr + ptr);
|
||||
for (I = 0; I < 16; I++, Addr++) { if (Addr <= size) { printf("%02lX ", (unsigned char) ptr[Addr]); } else { printf(" "); } }
|
||||
printf(" | "); Addr -= 16;
|
||||
for (I = 0; I < 16; I++, Addr++) { if (Addr <= size) { putchar(isprint(ptr[Addr]) ? ptr[Addr] : '.'); } else { putchar(' '); } }
|
||||
puts("");
|
||||
}
|
||||
}
|
||||
puts("-------------------------------------------------------------------------------------");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int fd, i;
|
||||
char *ptr;
|
||||
int size = 0;
|
||||
struct stat FileStat;
|
||||
|
||||
srand((unsigned int) time(NULL));
|
||||
|
||||
if (argc != 3) {
|
||||
printf("Usage: %s file size");
|
||||
}
|
||||
|
||||
fd = open(argv[1], O_RDWR);
|
||||
size = atoi(argv[2]);
|
||||
|
||||
ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
|
||||
printf("ptr = %p\n", ptr);
|
||||
|
||||
if ((ptr != NULL) && (ptr != MAP_FAILED)) {
|
||||
|
||||
hexdump(ptr, size);
|
||||
|
||||
/* Let's do some changes */
|
||||
for (i = 0; i < 128; i++) {
|
||||
ptr[i] ^= rand() % 0x100;
|
||||
}
|
||||
|
||||
msync(ptr, size, MS_SYNC|MS_INVALIDATE);
|
||||
|
||||
hexdump(ptr, size);
|
||||
}
|
||||
|
||||
close(fd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
146
examples/mmap-test.c
Normal file
146
examples/mmap-test.c
Normal file
@ -0,0 +1,146 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2003 The Regents of the University of California. All
|
||||
* rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* - Neither the name of the University nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* FUSD - The Framework for UserSpace Devices - Example program
|
||||
*
|
||||
* This example creates a a mmap-able buffer.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include "fusd.h"
|
||||
|
||||
#define MIN(x, y) ((x) < (y) ? (x) : (y))
|
||||
|
||||
#define BUFFER_SIZE 4096
|
||||
|
||||
static char *mmap_buffer;
|
||||
|
||||
static void hexdump(void *ptr_r, int size)
|
||||
{
|
||||
int J, I;
|
||||
unsigned char *ptr = ptr_r;
|
||||
unsigned long Addr = 0;
|
||||
if (ptr == NULL) {
|
||||
puts("NULL POINTER");
|
||||
puts("-------------------------------------------------------------------------------------");
|
||||
return;
|
||||
}
|
||||
while (Addr <= size) {
|
||||
for (J = 0; J < 2; J++) {
|
||||
printf("%08p: ", Addr + ptr);
|
||||
for (I = 0; I < 16; I++, Addr++) { if (Addr <= size) { printf("%02lX ", (unsigned char) ptr[Addr]); } else { printf(" "); } }
|
||||
printf(" | "); Addr -= 16;
|
||||
for (I = 0; I < 16; I++, Addr++) { if (Addr <= size) { putchar(isprint(ptr[Addr]) ? ptr[Addr] : '.'); } else { putchar(' '); } }
|
||||
puts("");
|
||||
}
|
||||
}
|
||||
puts("-------------------------------------------------------------------------------------");
|
||||
}
|
||||
|
||||
ssize_t mmaptest_read(struct fusd_file_info *file, char *user_buffer,
|
||||
size_t user_length, loff_t *offset)
|
||||
{
|
||||
int len;
|
||||
|
||||
if (*offset > BUFFER_SIZE) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
len = MIN(user_length + (*offset), BUFFER_SIZE);
|
||||
memcpy(user_buffer, mmap_buffer + (*offset), len);
|
||||
*offset += len;
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
int tester_mmap(struct fusd_file_info *file, int offset, size_t length, int prot, int flags,
|
||||
void **addr, size_t *out_length)
|
||||
{
|
||||
|
||||
printf("Got a mmap request from PID:%d [offset=%d, size=%d, prot=%X, flags=%X, addr=%p]\n",
|
||||
file->pid, offset, length, prot, flags, *addr);
|
||||
|
||||
if (length <= BUFFER_SIZE) {
|
||||
|
||||
*addr = mmap_buffer;
|
||||
*out_length = BUFFER_SIZE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int do_open(struct fusd_file_info *file)
|
||||
{
|
||||
/* opens and closes always succeed */
|
||||
return 0;
|
||||
}
|
||||
|
||||
int do_close(struct fusd_file_info *file)
|
||||
{
|
||||
/* Show content of the buffer */
|
||||
hexdump(mmap_buffer, 512);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
struct fusd_file_operations drums_fops = {
|
||||
open: do_open,
|
||||
read: mmaptest_read,
|
||||
mmap: tester_mmap,
|
||||
close: do_close
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
|
||||
mmap_buffer = (char *)mmap(NULL, BUFFER_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, -1, 0);
|
||||
|
||||
if (fusd_register("mmap-tester", "mmaptest", "mmap-tester", 0666, NULL, &drums_fops) < 0) {
|
||||
fprintf(stderr, "mmap-tester register failed: %m\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(mmap_buffer, 0xAA, BUFFER_SIZE);
|
||||
|
||||
fprintf(stderr, "calling fusd_run...\n");
|
||||
fusd_run();
|
||||
return 0;
|
||||
}
|
||||
@ -60,7 +60,6 @@
|
||||
* If you close the FD and then reopen it, there will be a race (pages
|
||||
* that arrive between the close and open will not be delivered).
|
||||
*
|
||||
* $Id: pager.c 12355 2007-01-19 17:44:17Z xiphmont $
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
@ -366,12 +365,12 @@ static int fusd_success(struct fusd_file_info *file)
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
/* register the input device */
|
||||
fusd_simple_register("/dev/pager/input", "pager", "input", 0666, NULL,
|
||||
fusd_simple_register("/dev/pager/input", "pager", "pager!input", 0666, NULL,
|
||||
open: fusd_success, close: fusd_success,
|
||||
write: pager_input_write);
|
||||
|
||||
/* register the notification device */
|
||||
fusd_simple_register("/dev/pager/notify", "pager", "notify", 0666, NULL,
|
||||
fusd_simple_register("/dev/pager/notify", "pager", "pager!notify", 0666, NULL,
|
||||
open: pager_notify_open,
|
||||
close: pager_notify_close,
|
||||
read: pager_notify_read,
|
||||
|
||||
@ -42,7 +42,6 @@
|
||||
* not be read by anyone other than the driver owner (not even root!).
|
||||
* When you read from the device, it returns your PID to you.
|
||||
*
|
||||
* $Id: uid-filter.c 12351 2007-01-19 07:22:54Z xiphmont $
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
@ -66,6 +66,8 @@ __BEGIN_DECLS
|
||||
|
||||
#define FUSD_KOR_HACKED_VERSION
|
||||
|
||||
#ifndef __KERNEL__
|
||||
|
||||
struct fusd_file_info; /* forward decl */
|
||||
|
||||
typedef
|
||||
@ -79,7 +81,7 @@ struct fusd_file_operations {
|
||||
int (*ioctl) (struct fusd_file_info *file, int request, void *data);
|
||||
int (*poll_diff) (struct fusd_file_info *file, unsigned int cached_state);
|
||||
int (*unblock) (struct fusd_file_info *file);
|
||||
int (*mmap) (struct fusd_file_info *file, int offset, size_t length, int flags, void** addr, size_t* out_length);
|
||||
int (*mmap) (struct fusd_file_info *file, int offset, size_t length, int prot, int flags, void** addr, size_t* out_length);
|
||||
} fusd_file_operations_t;
|
||||
|
||||
|
||||
@ -105,6 +107,7 @@ struct fusd_file_info {
|
||||
|
||||
/* other info might be added later, e.g. state needed to complete
|
||||
operations... */
|
||||
pthread_mutex_t lock;
|
||||
|
||||
/* request message associated with this call */
|
||||
int fd;
|
||||
@ -112,8 +115,8 @@ struct fusd_file_info {
|
||||
|
||||
} fusd_file_info_t;
|
||||
|
||||
|
||||
|
||||
#define FILE_LOCK(__f) pthread_mutex_lock(&__f->lock)
|
||||
#define FILE_UNLOCK(__f) pthread_mutex_unlock(&__f->lock)
|
||||
|
||||
/*************************** Library Functions ****************************/
|
||||
|
||||
@ -278,6 +281,8 @@ static inline int fusd_get_poll_diff_cached_state(struct fusd_file_info *file)
|
||||
/* returns static string representing the flagset (e.g. RWE) */
|
||||
char *fusd_unparse_flags(int flags);
|
||||
|
||||
#endif /* !__KERNEL__ */
|
||||
|
||||
#ifndef __KERNEL__
|
||||
__END_DECLS
|
||||
#endif
|
||||
|
||||
@ -81,6 +81,8 @@
|
||||
/* other constants */
|
||||
#define FUSD_MSG_MAGIC 0x7a6b93cd
|
||||
|
||||
#pragma pack(1)
|
||||
|
||||
/* user->kernel: register a device */
|
||||
typedef struct {
|
||||
char name[FUSD_MAX_NAME_LENGTH+1];
|
||||
@ -96,7 +98,7 @@ typedef struct {
|
||||
pid_t pid;
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
unsigned int flags; /* flags from file struct */
|
||||
unsigned long flags; /* flags from file struct */
|
||||
void *device_info; /* device info */
|
||||
void *private_info; /* file info */
|
||||
|
||||
@ -104,10 +106,15 @@ typedef struct {
|
||||
* union but it just makes things too complex and doesn't save all
|
||||
* that much memory anyway */
|
||||
ssize_t retval;
|
||||
size_t length;
|
||||
loff_t offset;
|
||||
unsigned long length;
|
||||
unsigned long offset;
|
||||
unsigned int cmd; /* ioctl cmd, poll_diff cached_state */
|
||||
|
||||
/* mmap parameters */
|
||||
unsigned long mmprot;
|
||||
unsigned long mmflags;
|
||||
unsigned long mmoffset;
|
||||
|
||||
union {
|
||||
unsigned long arg; /* ioctl */
|
||||
void *ptr_arg;
|
||||
@ -148,4 +155,6 @@ typedef struct {
|
||||
int num_open;
|
||||
} fusd_status_t;
|
||||
|
||||
#pragma pack()
|
||||
|
||||
#endif /* __FUSD_MSG_H__ */
|
||||
|
||||
@ -37,13 +37,13 @@
|
||||
*
|
||||
* Private header file used by the Linux Kernel Module
|
||||
*
|
||||
* $Id: kfusd.h 12351 2007-01-19 07:22:54Z xiphmont $
|
||||
*/
|
||||
|
||||
#ifndef __KFUSD_H__
|
||||
# define __KFUSD_H__
|
||||
|
||||
# include "fusd_msg.h"
|
||||
# include <linux/version.h>
|
||||
|
||||
/* magic numbers for structure checking; unique w.r.t
|
||||
* /usr/src/linux/Documentation/magic-number.txt */
|
||||
@ -125,8 +125,11 @@ struct fusd_dev_t_s {
|
||||
char *dev_name;
|
||||
struct CLASS *clazz;
|
||||
int owns_class;
|
||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29)
|
||||
struct class_device *device;
|
||||
#else
|
||||
struct device *device;
|
||||
|
||||
#endif
|
||||
void *private_data; /* User's private data */
|
||||
struct cdev* handle;
|
||||
dev_t dev_id;
|
||||
@ -148,30 +151,6 @@ struct fusd_dev_t_s {
|
||||
struct list_head devlist;
|
||||
};
|
||||
|
||||
|
||||
/**** Function Prototypes ****/
|
||||
|
||||
STATIC int maybe_free_fusd_dev(fusd_dev_t *fusd_dev);
|
||||
|
||||
STATIC int find_fusd_file(fusd_dev_t *fusd_dev, fusd_file_t *fusd_file);
|
||||
STATIC int free_fusd_file(fusd_dev_t *fusd_dev, fusd_file_t *fusd_file);
|
||||
|
||||
STATIC int fusd_fops_call_send(fusd_file_t *fusd_file_arg,
|
||||
fusd_msg_t *fusd_msg, struct fusd_transaction** transaction);
|
||||
STATIC int fusd_fops_call_wait(fusd_file_t *fusd_file_arg,
|
||||
fusd_msg_t **fusd_msg_reply, struct fusd_transaction* transaction);
|
||||
STATIC void fusd_fops_call_done(fusd_file_t *fusd_file);
|
||||
|
||||
STATIC void fusd_forge_close(fusd_msg_t *msg, fusd_dev_t *fusd_dev);
|
||||
|
||||
STATIC int fusd_add_transaction(fusd_file_t *fusd_file, int transid, int subcmd, int size, struct fusd_transaction** out_transaction);
|
||||
STATIC void fusd_cleanup_transaction(fusd_file_t *fusd_file, struct fusd_transaction* transaction);
|
||||
STATIC void fusd_remove_transaction(fusd_file_t *fusd_file, struct fusd_transaction* transaction);
|
||||
STATIC struct fusd_transaction* fusd_find_transaction(fusd_file_t *fusd_file, int transid);
|
||||
STATIC struct fusd_transaction* fusd_find_transaction_by_pid(fusd_file_t *fusd_file, int pid);
|
||||
|
||||
|
||||
|
||||
/**** Utility functions & macros ****/
|
||||
|
||||
# ifdef CONFIG_FUSD_USE_WAKEUPSYNC
|
||||
@ -269,8 +248,11 @@ static void fusd_vfree(void *ptr);
|
||||
/* Functions like this should be in the kernel, but they are not. Sigh. */
|
||||
# ifdef CONFIG_SMP
|
||||
|
||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35)
|
||||
DECLARE_MUTEX(atomic_ops);
|
||||
|
||||
#else
|
||||
DEFINE_SEMAPHORE(atomic_ops);
|
||||
#endif
|
||||
static __inline__ int atomic_inc_and_ret(int *i)
|
||||
{
|
||||
int val;
|
||||
|
||||
@ -5,11 +5,11 @@ else
|
||||
KDIR ?= /lib/modules/$(shell uname -r)/build
|
||||
PWD := $(shell pwd)
|
||||
ROOTFS ?=
|
||||
|
||||
GIT_DESCRIBE = $(shell git describe --dirty --tags)
|
||||
KERNEL_VER ?= 2.6.32.7
|
||||
|
||||
default:
|
||||
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) EXTRA_CFLAGS=-I$(PWD)/../include modules
|
||||
$(MAKE) -C $(KDIR) M=$(PWD) EXTRA_CFLAGS="-I$(PWD)/../include -DGIT_DESCRIBE='\"${GIT_DESCRIBE}\"'" V=1 modules
|
||||
|
||||
install:
|
||||
install -d -m 0755 $(ROOTFS)/lib/modules/$(KERNEL_VER)/kernel/drivers/misc
|
||||
|
||||
1096
kfusd/kfusd.c
1096
kfusd/kfusd.c
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,7 @@
|
||||
SRC = libfusd.c
|
||||
OBJ = libfusd.o
|
||||
TARGETS = libfusd.a libfusd.so.0.0
|
||||
GIT_DESCRIBE = $(shell git describe --dirty --tags)
|
||||
|
||||
default: $(TARGETS)
|
||||
|
||||
@ -15,7 +16,7 @@ clean:
|
||||
rm -f *.o *.so *.so.* *.a *.d *.d.* gmon.out *~
|
||||
|
||||
$(TARGETS):
|
||||
$(MAKE) target CFLAGS='-g -O2 $(SCF) $(GCF)'
|
||||
$(MAKE) target CFLAGS='-g -O2 $(SCF) $(GCF) -DGIT_DESCRIBE=\"${GIT_DESCRIBE}\"'
|
||||
|
||||
target: $(OBJ)
|
||||
$(LD) $(OBJ) $(SOLDFLAGS) -o libfusd.so.0.0 $(SLF)
|
||||
|
||||
@ -35,10 +35,9 @@
|
||||
*
|
||||
* authors: jelson and girod
|
||||
*
|
||||
* $Id: libfusd.c 12351 2007-01-19 07:22:54Z xiphmont $
|
||||
*/
|
||||
|
||||
char libfusd_c_id[] = "$Id: libfusd.c 12351 2007-01-19 07:22:54Z xiphmont $";
|
||||
char libfusd_c_id[] = "libfusd.c - FUSD " GIT_DESCRIBE;
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -53,6 +52,11 @@ char libfusd_c_id[] = "$Id: libfusd.c 12351 2007-01-19 07:22:54Z xiphmont $";
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/syscall.h>
|
||||
|
||||
#include "fusd.h"
|
||||
#include "fusd_msg.h"
|
||||
|
||||
@ -72,7 +76,7 @@ char *dev_root = NULL;
|
||||
* struct for each fusd fd.
|
||||
*/
|
||||
static fusd_file_operations_t fusd_fops_set[FD_SETSIZE];
|
||||
fusd_file_operations_t null_fops = { NULL };
|
||||
fusd_file_operations_t null_fops = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
|
||||
|
||||
/*
|
||||
* accessor macros
|
||||
@ -99,7 +103,8 @@ void fusd_init()
|
||||
{
|
||||
static int fusd_init_needed = 1;
|
||||
|
||||
if (fusd_init_needed) {
|
||||
if (fusd_init_needed)
|
||||
{
|
||||
int i;
|
||||
|
||||
fusd_init_needed = 0;
|
||||
@ -123,7 +128,8 @@ int fusd_register(const char *name, const char* clazz, const char* devname, mode
|
||||
fusd_init();
|
||||
|
||||
/* make sure the name is valid and we have a valid set of fops... */
|
||||
if (name == NULL || fops == NULL) {
|
||||
if (name == NULL || fops == NULL)
|
||||
{
|
||||
fprintf(stderr, "fusd_register: invalid name or fops argument\n");
|
||||
retval = -EINVAL;
|
||||
goto done;
|
||||
@ -134,27 +140,33 @@ int fusd_register(const char *name, const char* clazz, const char* devname, mode
|
||||
* to register are SKIP_PREFIX (usually "/dev/"), skip over them.
|
||||
*/
|
||||
if (dev_root != NULL && strlen(name) > strlen(dev_root) &&
|
||||
!strncmp(name, dev_root, strlen(dev_root))) {
|
||||
!strncmp(name, dev_root, strlen(dev_root)))
|
||||
{
|
||||
name += strlen(dev_root);
|
||||
}
|
||||
|
||||
if (strlen(name) > FUSD_MAX_NAME_LENGTH) {
|
||||
fprintf(stderr, "name '%s' too long, sorry :(", name);
|
||||
if (strlen(name) > FUSD_MAX_NAME_LENGTH)
|
||||
{
|
||||
fprintf(stderr, "libfusd: name '%s' too long, sorry :(\n", name);
|
||||
retval = -EINVAL;
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* open the fusd control channel */
|
||||
if ((fd = open(FUSD_CONTROL_DEVNAME, O_RDWR | O_NONBLOCK)) < 0) {
|
||||
if ((fd = open(FUSD_CONTROL_DEVNAME, O_RDWR | O_NONBLOCK)) < 0)
|
||||
{
|
||||
|
||||
/* if the problem is that /dev/fusd does not exist, return the
|
||||
* message "Package not installed", which is hopefully more
|
||||
* illuminating than "no such file or directory" */
|
||||
if (errno == ENOENT) {
|
||||
if (errno == ENOENT)
|
||||
{
|
||||
fprintf(stderr, "libfusd: %s does not exist; ensure FUSD's kernel module is installed\n",
|
||||
FUSD_CONTROL_DEVNAME);
|
||||
retval = -ENOPKG;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
perror("libfusd: trying to open FUSD control channel");
|
||||
retval = -errno;
|
||||
}
|
||||
@ -162,7 +174,8 @@ int fusd_register(const char *name, const char* clazz, const char* devname, mode
|
||||
}
|
||||
|
||||
/* fd in use? */
|
||||
if (FUSD_FD_VALID(fd)) {
|
||||
if (FUSD_FD_VALID(fd))
|
||||
{
|
||||
retval = -EBADF;
|
||||
goto done;
|
||||
}
|
||||
@ -179,7 +192,8 @@ int fusd_register(const char *name, const char* clazz, const char* devname, mode
|
||||
message.parm.register_msg.device_info = device_info;
|
||||
|
||||
/* make the request */
|
||||
if (write(fd, &message, sizeof(fusd_msg_t)) < 0) {
|
||||
if (write(fd, &message, sizeof(fusd_msg_t)) < 0)
|
||||
{
|
||||
retval = -errno;
|
||||
goto done;
|
||||
}
|
||||
@ -190,34 +204,38 @@ int fusd_register(const char *name, const char* clazz, const char* devname, mode
|
||||
|
||||
/* success! */
|
||||
done:
|
||||
if (retval < 0) {
|
||||
if (retval < 0)
|
||||
{
|
||||
if (fd >= 0)
|
||||
close(fd);
|
||||
errno = -retval;
|
||||
retval = -1;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
errno = 0;
|
||||
retval = fd;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
int fusd_unregister(int fd)
|
||||
{
|
||||
if (FUSD_FD_VALID(fd)) {
|
||||
int ret = -1;
|
||||
if (FUSD_FD_VALID(fd))
|
||||
{
|
||||
/* clear fd location */
|
||||
FUSD_SET_FOPS(fd, &null_fops);
|
||||
FD_CLR(fd, &fusd_fds);
|
||||
/* close */
|
||||
return close(fd);
|
||||
ret = close(fd);
|
||||
}
|
||||
else
|
||||
{
|
||||
errno = EBADF;
|
||||
}
|
||||
|
||||
else {
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@ -236,21 +254,25 @@ void fusd_run(void)
|
||||
int i;
|
||||
|
||||
/* locate maxmimum fd in use */
|
||||
for (maxfd=0, i=0; i < FD_SETSIZE; i++) {
|
||||
if (FD_ISSET(i, &fusd_fds)) {
|
||||
for (maxfd=0, i=0; i < FD_SETSIZE; i++)
|
||||
{
|
||||
if (FD_ISSET(i, &fusd_fds))
|
||||
{
|
||||
maxfd = i;
|
||||
}
|
||||
}
|
||||
maxfd++;
|
||||
|
||||
|
||||
while (1) {
|
||||
while (1)
|
||||
{
|
||||
/* select */
|
||||
memmove(&tfds, &fusd_fds, sizeof(fd_set));
|
||||
status = select(maxfd, &tfds, NULL, NULL, NULL);
|
||||
|
||||
/* error? */
|
||||
if (status < 0) {
|
||||
if (status < 0)
|
||||
{
|
||||
perror("libfusd: fusd_run: error on select");
|
||||
continue;
|
||||
}
|
||||
@ -258,14 +280,13 @@ void fusd_run(void)
|
||||
/* readable? */
|
||||
for (i = 0; i < maxfd; i++)
|
||||
if (FD_ISSET(i, &tfds))
|
||||
|
||||
fusd_dispatch(i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
|
||||
/* reads a fusd kernel-to-userspace message from fd, and puts a
|
||||
* fusd_msg into the memory pointed to by msg (we assume we are passed
|
||||
* a buffer managed by the caller). if there is a data portion to the
|
||||
@ -274,39 +295,51 @@ void fusd_run(void)
|
||||
* managed by the caller. */
|
||||
static int fusd_get_message(int fd, fusd_msg_t *msg)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* read the header part into the kernel */
|
||||
if (read(fd, msg, sizeof(fusd_msg_t)) < 0) {
|
||||
if (read(fd, msg, sizeof(fusd_msg_t)) < 0)
|
||||
{
|
||||
if (errno != EAGAIN)
|
||||
perror("error talking to FUSD control channel on header read");
|
||||
return -errno;
|
||||
ret = -errno;
|
||||
goto exit;
|
||||
}
|
||||
msg->data = NULL; /* pointers in kernelspace have no meaning */
|
||||
|
||||
if (msg->magic != FUSD_MSG_MAGIC) {
|
||||
fprintf(stderr, "libfusd magic number failure\n");
|
||||
return -EINVAL;
|
||||
if (msg->magic != FUSD_MSG_MAGIC)
|
||||
{
|
||||
fprintf(stderr, "libfusd: magic number failure\n");
|
||||
ret = -EINVAL;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* if there's a data part to the message, read it from the kernel. */
|
||||
if (msg->datalen) {
|
||||
if ((msg->data = malloc(msg->datalen + 1)) == NULL) {
|
||||
if (msg->datalen)
|
||||
{
|
||||
if ((msg->data = malloc(msg->datalen + 1)) == NULL)
|
||||
{
|
||||
fprintf(stderr, "libfusd: can't allocate memory\n");
|
||||
return -ENOMEM; /* this is bad, we are now unsynced */
|
||||
ret = -ENOMEM; /* this is bad, we are now unsynced */
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (read(fd, msg->data, msg->datalen) < 0) {
|
||||
if (read(fd, msg->data, msg->datalen) < 0)
|
||||
{
|
||||
perror("error talking to FUSD control channel on data read");
|
||||
free(msg->data);
|
||||
msg->data = NULL;
|
||||
return -EIO;
|
||||
ret = -EIO;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* For convenience, we now ensure that the byte *after* the buffer
|
||||
* is set to 0. (Note we malloc'd one extra byte above.) */
|
||||
msg->data[msg->datalen] = '\0';
|
||||
}
|
||||
|
||||
return 0;
|
||||
ret = 0;
|
||||
exit:
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@ -318,10 +351,13 @@ void fusd_fdset_add(fd_set *set, int *max)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < FD_SETSIZE; i++) {
|
||||
if (FD_ISSET(i, &fusd_fds)) {
|
||||
for (i = 0; i < FD_SETSIZE; i++)
|
||||
{
|
||||
if (FD_ISSET(i, &fusd_fds))
|
||||
{
|
||||
FD_SET(i, set);
|
||||
if (i > *max) {
|
||||
if (i > *max)
|
||||
{
|
||||
*max = i;
|
||||
}
|
||||
}
|
||||
@ -340,6 +376,7 @@ void fusd_dispatch_fdset(fd_set *set)
|
||||
for (i = 0; i < FD_SETSIZE; i++)
|
||||
if (FD_ISSET(i, set) && FD_ISSET(i, &fusd_fds))
|
||||
fusd_dispatch(i);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -361,14 +398,16 @@ static int fusd_dispatch_one(int fd, fusd_file_operations_t *fops)
|
||||
int user_retval = 0; /* returned to the user who made the syscall */
|
||||
|
||||
/* check for valid, look up ops */
|
||||
if (fops == NULL) {
|
||||
if (fops == NULL)
|
||||
{
|
||||
fprintf(stderr, "fusd_dispatch: no fops provided!\n");
|
||||
driver_retval = -EBADF;
|
||||
goto out_noreply;
|
||||
}
|
||||
|
||||
/* allocate memory for fusd_msg_t */
|
||||
if ((msg = malloc(sizeof(fusd_msg_t))) == NULL) {
|
||||
if ((msg = malloc(sizeof(fusd_msg_t))) == NULL)
|
||||
{
|
||||
driver_retval = -ENOMEM;
|
||||
fprintf(stderr, "libfusd: can't allocate memory\n");
|
||||
goto out_noreply;
|
||||
@ -381,7 +420,8 @@ static int fusd_dispatch_one(int fd, fusd_file_operations_t *fops)
|
||||
|
||||
/* allocate file info struct */
|
||||
file = malloc(sizeof(fusd_file_info_t));
|
||||
if (NULL == file) {
|
||||
if (NULL == file)
|
||||
{
|
||||
fprintf(stderr, "libfusd: can't allocate memory\n");
|
||||
driver_retval = -ENOMEM;
|
||||
goto out_noreply;
|
||||
@ -389,6 +429,11 @@ static int fusd_dispatch_one(int fd, fusd_file_operations_t *fops)
|
||||
|
||||
/* fill the file info struct */
|
||||
memset(file, '\0', sizeof(fusd_file_info_t));
|
||||
|
||||
pthread_mutex_init(&file->lock, NULL);
|
||||
|
||||
FILE_LOCK(file);
|
||||
|
||||
file->fd = fd;
|
||||
file->device_info = msg->parm.fops_msg.device_info;
|
||||
file->private_data = msg->parm.fops_msg.private_info;
|
||||
@ -398,9 +443,12 @@ static int fusd_dispatch_one(int fd, fusd_file_operations_t *fops)
|
||||
file->gid = msg->parm.fops_msg.gid;
|
||||
file->fusd_msg = msg;
|
||||
|
||||
FILE_UNLOCK(file);
|
||||
|
||||
/* right now we only handle fops requests */
|
||||
if (msg->cmd != FUSD_FOPS_CALL && msg->cmd != FUSD_FOPS_NONBLOCK &&
|
||||
msg->cmd != FUSD_FOPS_CALL_DROPREPLY) {
|
||||
msg->cmd != FUSD_FOPS_CALL_DROPREPLY)
|
||||
{
|
||||
fprintf(stderr, "libfusd: got unknown msg->cmd from kernel\n");
|
||||
user_retval = -EINVAL;
|
||||
goto send_reply;
|
||||
@ -410,55 +458,69 @@ static int fusd_dispatch_one(int fd, fusd_file_operations_t *fops)
|
||||
user_retval = -ENOSYS;
|
||||
//printf("dispatch_one: subcmd: %d - ", msg->subcmd);
|
||||
|
||||
switch (msg->subcmd) {
|
||||
|
||||
switch (msg->subcmd)
|
||||
{
|
||||
case FUSD_OPEN:
|
||||
//printf("FUSD_OPEN\n");
|
||||
if (fops && fops->open)
|
||||
user_retval = fops->open(file);
|
||||
break;
|
||||
|
||||
case FUSD_CLOSE:
|
||||
//printf("FUSD_CLOSE\n");
|
||||
if (fops && fops->close)
|
||||
user_retval = fops->close(file);
|
||||
break;
|
||||
|
||||
case FUSD_READ:
|
||||
//printf("FUSD_READ\n");
|
||||
/* allocate a buffer and make the call */
|
||||
if (fops && fops->read) {
|
||||
if ((msg->data = malloc(msg->parm.fops_msg.length)) == NULL) {
|
||||
if (fops && fops->read)
|
||||
{
|
||||
if ((msg->data = malloc(msg->parm.fops_msg.length)) == NULL)
|
||||
{
|
||||
user_retval = -ENOMEM;
|
||||
fprintf(stderr, "libfusd: can't allocate memory\n");
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
msg->datalen = msg->parm.fops_msg.length;
|
||||
user_retval = fops->read(file, msg->data, msg->datalen,
|
||||
&msg->parm.fops_msg.offset);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case FUSD_WRITE:
|
||||
//printf("FUSD_WRITE\n");
|
||||
if (fops && fops->write)
|
||||
user_retval = fops->write(file, msg->data, msg->datalen,
|
||||
&msg->parm.fops_msg.offset);
|
||||
break;
|
||||
|
||||
case FUSD_MMAP:
|
||||
//printf("FUSD_MMAP\n");
|
||||
if (fops && fops->mmap)
|
||||
{
|
||||
user_retval = fops->mmap(file, msg->parm.fops_msg.offset, msg->parm.fops_msg.length, msg->parm.fops_msg.flags,
|
||||
&msg->parm.fops_msg.arg.ptr_arg, &msg->parm.fops_msg.length);
|
||||
user_retval = fops->mmap(file, msg->parm.fops_msg.mmoffset, msg->parm.fops_msg.length, msg->parm.fops_msg.mmprot,
|
||||
msg->parm.fops_msg.mmflags, &msg->parm.fops_msg.arg.ptr_arg, &msg->parm.fops_msg.length);
|
||||
}
|
||||
break;
|
||||
|
||||
case FUSD_IOCTL:
|
||||
//printf("FUSD_IOCTL\n");
|
||||
if (fops && fops->ioctl) {
|
||||
if (fops && fops->ioctl)
|
||||
{
|
||||
/* in the case of an ioctl read, allocate a buffer for the
|
||||
* driver to write to, IF there isn't already a buffer. (there
|
||||
* might already be a buffer if this is a read+write) */
|
||||
if ((_IOC_DIR(msg->parm.fops_msg.cmd) & _IOC_READ) &&
|
||||
msg->data == NULL) {
|
||||
msg->data == NULL)
|
||||
{
|
||||
msg->datalen = _IOC_SIZE(msg->parm.fops_msg.cmd);
|
||||
if ((msg->data = malloc(msg->datalen)) == NULL) {
|
||||
if ((msg->data = malloc(msg->datalen)) == NULL)
|
||||
{
|
||||
user_retval = -ENOMEM;
|
||||
break;
|
||||
}
|
||||
@ -505,20 +567,25 @@ static int fusd_dispatch_one(int fd, fusd_file_operations_t *fops)
|
||||
|
||||
/* send_reply is only used for success */
|
||||
send_reply:
|
||||
if (-user_retval <= 0xff) {
|
||||
if (-user_retval <= 0xff)
|
||||
{
|
||||
/* 0xff is the maximum legal return value (?) - return val to user */
|
||||
driver_retval = fusd_return(file, user_retval);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* if we got a FUSD_NOREPLY, don't free the msg structure */
|
||||
driver_retval = 0;
|
||||
}
|
||||
|
||||
/* this is common to both errors and success */
|
||||
done:
|
||||
if (driver_retval < 0) {
|
||||
if (driver_retval < 0)
|
||||
{
|
||||
errno = -driver_retval;
|
||||
driver_retval = -1;
|
||||
}
|
||||
|
||||
return driver_retval;
|
||||
}
|
||||
|
||||
@ -538,7 +605,8 @@ void fusd_dispatch(int fd)
|
||||
fusd_file_operations_t *fops = NULL;
|
||||
|
||||
/* make sure we have a valid FD, and get its fops structure */
|
||||
if (!FUSD_FD_VALID(fd)) {
|
||||
if (!FUSD_FD_VALID(fd))
|
||||
{
|
||||
errno = EBADF;
|
||||
retval = -1;
|
||||
fprintf(stderr, "libfusd: not a valid FUSD FD\n");
|
||||
@ -547,7 +615,8 @@ void fusd_dispatch(int fd)
|
||||
fops = FUSD_GET_FOPS(fd);
|
||||
|
||||
/* now keep dispatching until a dispatch returns an error */
|
||||
do {
|
||||
do
|
||||
{
|
||||
retval = fusd_dispatch_one(fd, fops);
|
||||
|
||||
if (retval >= 0)
|
||||
@ -557,7 +626,8 @@ void fusd_dispatch(int fd)
|
||||
/* if we've dispatched at least one message successfully, and then
|
||||
* stopped because of EAGAIN - do not report an error. this is the
|
||||
* common case. */
|
||||
if (num_dispatches > 0 && errno == EAGAIN) {
|
||||
if (num_dispatches > 0 && errno == EAGAIN)
|
||||
{
|
||||
retval = 0;
|
||||
errno = 0;
|
||||
}
|
||||
@ -565,6 +635,7 @@ void fusd_dispatch(int fd)
|
||||
out:
|
||||
if (retval < 0 && errno != EPIPE)
|
||||
fprintf(stderr, "libfusd: fusd_dispatch error on fd %d: [%d] %m\n", fd, retval);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -581,9 +652,22 @@ void fusd_destroy(struct fusd_file_info *file)
|
||||
if (file == NULL)
|
||||
return;
|
||||
|
||||
FILE_LOCK(file);
|
||||
|
||||
if (file->fusd_msg != NULL)
|
||||
{
|
||||
if (file->fusd_msg->data != NULL)
|
||||
{
|
||||
free(file->fusd_msg->data);
|
||||
file->fusd_msg->data = NULL;
|
||||
}
|
||||
free(file->fusd_msg);
|
||||
file->fusd_msg = NULL;
|
||||
}
|
||||
FILE_UNLOCK(file);
|
||||
|
||||
pthread_mutex_destroy(&file->lock);
|
||||
|
||||
free(file);
|
||||
}
|
||||
|
||||
@ -600,22 +684,31 @@ int fusd_return(fusd_file_info_t *file, ssize_t retval)
|
||||
fusd_msg_t *msg = NULL;
|
||||
int fd;
|
||||
int driver_retval = 0;
|
||||
int ret;
|
||||
struct iovec iov[2];
|
||||
|
||||
if (file == NULL) {
|
||||
if (file == NULL)
|
||||
{
|
||||
fprintf(stderr, "fusd_return: NULL file\n");
|
||||
return -EINVAL;
|
||||
ret = -EINVAL;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
FILE_LOCK(file);
|
||||
|
||||
fd = file->fd;
|
||||
if (!FUSD_FD_VALID(fd)) {
|
||||
if (!FUSD_FD_VALID(fd))
|
||||
{
|
||||
fprintf(stderr, "fusd_return: badfd (fd %d)\n", fd);
|
||||
return -EBADF;
|
||||
ret = -EBADF;
|
||||
goto exit_unlock;
|
||||
}
|
||||
|
||||
if ((msg = file->fusd_msg) == NULL) {
|
||||
if ((msg = file->fusd_msg) == NULL)
|
||||
{
|
||||
fprintf(stderr, "fusd_return: fusd_msg is gone\n");
|
||||
return -EINVAL;
|
||||
ret = -EINVAL;
|
||||
goto exit_unlock;
|
||||
}
|
||||
|
||||
/* if this was a "DONTREPLY" message, just free the struct */
|
||||
@ -623,24 +716,29 @@ int fusd_return(fusd_file_info_t *file, ssize_t retval)
|
||||
goto free_memory;
|
||||
|
||||
/* do we copy data back to kernel? how much? */
|
||||
switch(msg->subcmd) {
|
||||
switch(msg->subcmd)
|
||||
{
|
||||
case FUSD_READ:
|
||||
/* these operations can return data to userspace */
|
||||
if (retval > 0) {
|
||||
msg->datalen = MIN(retval, msg->parm.fops_msg.length);
|
||||
if (retval > 0)
|
||||
{
|
||||
msg->datalen = MIN((int)retval, (int)msg->parm.fops_msg.length);
|
||||
retval = msg->datalen;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
msg->datalen = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case FUSD_IOCTL:
|
||||
/* ioctl CAN (in read mode) return data to userspace */
|
||||
if ((retval == 0) &&
|
||||
(_IOC_DIR(msg->parm.fops_msg.cmd) & _IOC_READ))
|
||||
if (/*(retval == 0) && */ (_IOC_DIR(msg->parm.fops_msg.cmd) & _IOC_READ) )
|
||||
msg->datalen = _IOC_SIZE(msg->parm.fops_msg.cmd);
|
||||
else
|
||||
msg->datalen = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
/* open, close, write, etc. do not return data */
|
||||
msg->datalen = 0;
|
||||
@ -656,29 +754,35 @@ int fusd_return(fusd_file_info_t *file, ssize_t retval)
|
||||
/* pid is NOT copied back. */
|
||||
|
||||
/* send message to kernel */
|
||||
if (msg->datalen && msg->data != NULL) {
|
||||
if (msg->datalen && msg->data != NULL)
|
||||
{
|
||||
//printf("(msg->datalen [%d] && msg->data != NULL [%p]", msg->datalen, msg->data);
|
||||
iov[0].iov_base = msg;
|
||||
iov[0].iov_len = sizeof(fusd_msg_t);
|
||||
iov[1].iov_base = msg->data;
|
||||
iov[1].iov_len = msg->datalen;
|
||||
#if 0
|
||||
driver_retval = writev(fd, iov, 2);
|
||||
#else
|
||||
driver_retval = ioctl(fd, 0xb16b00b5, iov);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
driver_retval = write(fd, msg, sizeof(fusd_msg_t));
|
||||
}
|
||||
|
||||
free_memory:
|
||||
FILE_UNLOCK(file);
|
||||
|
||||
fusd_destroy(file);
|
||||
|
||||
ret = 0;
|
||||
if (driver_retval < 0)
|
||||
return -errno;
|
||||
else
|
||||
return 0;
|
||||
ret = -errno;
|
||||
goto exit;
|
||||
|
||||
exit_unlock:
|
||||
FILE_UNLOCK(file);
|
||||
|
||||
exit:
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user