Compare commits

...

30 Commits

Author SHA1 Message Date
Godzil
56bf9b87fe 5.8 break the driver (yeah again) allow to fail for now. 2020-08-21 16:16:09 +02:00
Godzil
081f817cac Update kernel support list (more recent version than 5.4 may fail though) 2020-08-21 16:05:41 +02:00
Manoël Trapier
483be78d0d
Update .travis.yml
Change travis stable test branches
5.1 -> 5.3
5.2 -> 5.4
2019-12-13 14:41:30 +00:00
Godzil
61f72c675d Fix kernel-5.1.y and 5.2.y
Fix #13 and Fix #14
2019-07-25 16:31:57 +01:00
Godzil
30f606be39 Remove a useless SUBDIRS in the main makefile. 2019-07-25 16:30:49 +01:00
Godzil
41e61a81f8 Fix kernel 4.9.y
Fix #12
2019-07-25 16:17:24 +01:00
Godzil
ac6def392c This change was not for all 4.4, but just a small subset that does not replicate on later version of the kernel. 2019-07-25 16:16:59 +01:00
Godzil
3e71c6e74f Fix for kernel 4.4.y.
Fix #11
2019-07-25 16:06:53 +01:00
Godzil
9116a9917b Remove a warning about a unused variable 2019-07-25 16:06:14 +01:00
Godzil
f184634d5f Remove unused function 2019-07-25 16:05:59 +01:00
Godzil
a765b0745d Make kernel 5.x stopping to complain about SUBDIR= being deprecated 2019-07-25 15:41:46 +01:00
Godzil
0132d11b4b Fix for kernel 3.10.
Same as 2.6.32, why <linux/aio.h> is included in all other but not that one? I don't know.

Fix #9
2019-07-25 15:41:11 +01:00
Godzil
f404dd7061 It should now build for kernel 2.6.32.
Why <linux/sched.h> is not automatically included in this release is beyond me.

Fix for #8
2019-07-25 15:40:29 +01:00
Godzil
d8fea5550c Remove static function prototypes from kfusd.h and move to kfusd.c and remove useless prototypes and functions.
Also remove reference to "STATIC" instead of "static"
2019-07-25 15:39:22 +01:00
Godzil
101f3687ff Can't get to configure 2.6.13 for now, so let's ignore it at the moment. 2019-07-25 15:36:33 +01:00
Manoël Trapier
68b4fd7b40
Update README.markdown 2019-07-25 12:14:29 +01:00
Godzil
eb9511d9b3 Add an even older version of the kernel. 2019-07-25 12:13:52 +01:00
Godzil
43b1069b54 Update .gitignore 2019-07-25 12:13:11 +01:00
Godzil
d27a3f2ee1 Add test travis build 2019-07-25 11:49:57 +01:00
Godzil
2ce7c94d11 Buffer size need to be at least a page size. (probably better to keep it a multiple of a page size) 2019-07-24 16:08:52 +01:00
Godzil
36fd2b86c5 Add sample udev file 2019-07-24 16:06:37 +01:00
Godzil
c37e562e5f Add example of use of mmap 2019-07-24 16:06:19 +01:00
Godzil
57ae74c803 Update userspace to have proper protection values for mmap and send the proper flags to the callback function. 2019-07-24 16:04:20 +01:00
Godzil
a54adc616d Send proper flags to userspace 2019-07-24 16:01:28 +01:00
Godzil
095ac4569a Update mmap related error to be a bit more useful for debug 2019-07-24 15:59:34 +01:00
Godzil
70f58ed6dc Update 2018 -> 2019 2019-07-24 15:57:48 +01:00
Godzil
596df479c2 Remove all SVN/CVS $Id$ idoms. 2019-07-24 15:55:35 +01:00
Godzil
1cf7fd077c Correct some potential 32bit/64bit issues. 2019-07-24 15:42:37 +01:00
Godzil
75a05048a4 Let's be paranoid: force the packing on important shared structures. 2019-07-24 15:41:21 +01:00
Godzil
0ce298ca33 Remove some warnings, and correct some errors in examples 2019-07-24 15:40:37 +01:00
27 changed files with 569 additions and 167 deletions

2
.gitignore vendored
View File

@ -21,3 +21,5 @@ examples/ioctl
examples/logring examples/logring
examples/pager examples/pager
examples/uid-filter examples/uid-filter
examples/mmap-read
examples/mmap-test

142
.travis.yml Normal file
View 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'

View File

@ -23,8 +23,6 @@ export
#################################################### ####################################################
SUBDIRS = kfusd libfusd examples
default: default:
$(MAKE) -C libfusd $(MAKE) -C libfusd
$(MAKE) -C kfusd $(MAKE) -C kfusd

View File

@ -2,6 +2,8 @@
FUSD: A Linux Framework for User-Space Devices FUSD: A Linux Framework for User-Space Devices
---------------------------------------------- ----------------------------------------------
[![Build Status](https://travis-ci.org/Godzil/fusd.svg?branch=master)](https://travis-ci.org/Godzil/fusd)
**Welcome to FUSD!** **Welcome to FUSD!**
This is FUSD snapshot 20110401, released 18 January 2012. This fork is based This is FUSD snapshot 20110401, released 18 January 2012. This fork is based

View File

@ -7,7 +7,6 @@
% Released under open-source, BSD license % Released under open-source, BSD license
% See LICENSE file for full license % See LICENSE file for full license
% %
% $Id: fusd.tex,v 1.63 2003/08/20 22:00:55 jelson Exp $
\documentclass{article} \documentclass{article}
\addtolength{\topmargin}{-.5in} % repairing LaTeX's huge margins... \addtolength{\topmargin}{-.5in} % repairing LaTeX's huge margins...

View File

@ -1,5 +1,4 @@
% %
% $Id: html.sty,v 1.1 2001/05/12 00:38:48 cvs Exp $
% LaTeX2HTML Version 99.2 : html.sty % LaTeX2HTML Version 99.2 : html.sty
% %
% This file contains definitions of LaTeX commands which are % This file contains definitions of LaTeX commands which are

View File

@ -1,23 +1,27 @@
SRC = console-read.c drums3.c echo.c helloworld.c logring.c pager.c\ SRC = console-read.c drums3.c echo.c helloworld.c logring.c pager.c\
drums2.c drums.c ioctl.c uid-filter.c drums2.c drums.c ioctl.c uid-filter.c
OBJ = console-read.o drums3.o echo.o helloworld.o logring.o pager.o\ 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\ 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) install: $(TARGETS)
clean: clean:
rm -f *.o *.d $(TARGETS) gmon.out *~ rm -f *.o *.d $(TARGETS) gmon.out *~
$(TARGETS): %: %.c mmap-read: mmap-read.c
$(CC) $(GCF) $< -o $@ ../libfusd/libfusd.a $(CC) $< -o $@
$(TARGETS): %: %.c ../libfusd/libfusd.a
$(CC) $(GCF) $< -o $@ ../libfusd/libfusd.a
%.d: %.c %.d: %.c
$(CC) -M $(CFLAGS) $< > $@.$$$$; sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; rm -f $@.$$$$ $(CC) -M $(CFLAGS) $< > $@.$$$$; sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; rm -f $@.$$$$
ifeq ($(MAKECMDGOALS),target) ifeq ($(MAKECMDGOALS),target)
include $(SRC:.c=.d) include $(SRC:.c=.d)
endif endif

View File

@ -40,7 +40,6 @@
* need a template from which to start on a real driver, use pager.c * need a template from which to start on a real driver, use pager.c
* instead. * instead.
* *
* $Id: console-read.c 12351 2007-01-19 07:22:54Z xiphmont $
*/ */
#include <stdio.h> #include <stdio.h>

View File

@ -42,7 +42,6 @@
* directory: /dev/drums/bam, /dev/drums/bum, etc. If you cat one of * 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. * 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> #include <stdio.h>

View File

@ -47,10 +47,10 @@
* to remember if this user has read before; cat /dev/drums/X will * to remember if this user has read before; cat /dev/drums/X will
* read infinitely * read infinitely
* *
* $Id: drums2.c 12355 2007-01-19 17:44:17Z xiphmont $
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>

View File

@ -43,7 +43,6 @@
* However, it also prints a prompt to the console, asking the user if * However, it also prints a prompt to the console, asking the user if
* how loud the drums should be. * how loud the drums should be.
* *
* $Id: drums3.c 12351 2007-01-19 07:22:54Z xiphmont $
*/ */
#include <stdio.h> #include <stdio.h>

View File

@ -41,7 +41,6 @@
* stored. Then, when you read (e.g. "cat /dev/echo"), you get back * stored. Then, when you read (e.g. "cat /dev/echo"), you get back
* whatever you wrote most recently. * whatever you wrote most recently.
* *
* $Id: echo.c 12351 2007-01-19 07:22:54Z xiphmont $
*/ */
#include <stdio.h> #include <stdio.h>

2
examples/fusd.rules Normal file
View File

@ -0,0 +1,2 @@
SUBSYSTEM=="fusd", NAME="fusd/%k"

View File

@ -37,7 +37,6 @@
* hello-world: Simply creates a device called /dev/hello-world, which * hello-world: Simply creates a device called /dev/hello-world, which
* greets you when you try to get it. * greets you when you try to get it.
* *
* $Id: helloworld.c 12351 2007-01-19 07:22:54Z xiphmont $
*/ */
/* EXAMPLE START helloworld.c */ /* EXAMPLE START helloworld.c */

View File

@ -41,7 +41,6 @@
* the other examples, anyway), because this program is both an * the other examples, anyway), because this program is both an
* example and part of the regression test suite. * example and part of the regression test suite.
* *
* $Id: ioctl.c 12351 2007-01-19 07:22:54Z xiphmont $
*/ */
#include <stdio.h> #include <stdio.h>

View File

@ -71,7 +71,6 @@
* but want to use it on a system that does not have FUSD, check out * but want to use it on a system that does not have FUSD, check out
* emlog at http://www.circlemud.org/~jelson/software/emlog. * emlog at http://www.circlemud.org/~jelson/software/emlog.
* *
* $Id: logring.c 12351 2007-01-19 07:22:54Z xiphmont $
*/ */
#include <stdio.h> #include <stdio.h>

110
examples/mmap-read.c Normal file
View 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
View 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;
}

View File

@ -60,7 +60,6 @@
* If you close the FD and then reopen it, there will be a race (pages * 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). * 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> #include <stdio.h>
@ -366,12 +365,12 @@ static int fusd_success(struct fusd_file_info *file)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
/* register the input device */ /* 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, open: fusd_success, close: fusd_success,
write: pager_input_write); write: pager_input_write);
/* register the notification device */ /* 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, open: pager_notify_open,
close: pager_notify_close, close: pager_notify_close,
read: pager_notify_read, read: pager_notify_read,

View File

@ -42,7 +42,6 @@
* not be read by anyone other than the driver owner (not even root!). * 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. * 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> #include <stdio.h>

View File

@ -81,7 +81,7 @@ struct fusd_file_operations {
int (*ioctl) (struct fusd_file_info *file, int request, void *data); int (*ioctl) (struct fusd_file_info *file, int request, void *data);
int (*poll_diff) (struct fusd_file_info *file, unsigned int cached_state); int (*poll_diff) (struct fusd_file_info *file, unsigned int cached_state);
int (*unblock) (struct fusd_file_info *file); 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; } fusd_file_operations_t;

View File

@ -81,6 +81,8 @@
/* other constants */ /* other constants */
#define FUSD_MSG_MAGIC 0x7a6b93cd #define FUSD_MSG_MAGIC 0x7a6b93cd
#pragma pack(1)
/* user->kernel: register a device */ /* user->kernel: register a device */
typedef struct { typedef struct {
char name[FUSD_MAX_NAME_LENGTH+1]; char name[FUSD_MAX_NAME_LENGTH+1];
@ -96,7 +98,7 @@ typedef struct {
pid_t pid; pid_t pid;
uid_t uid; uid_t uid;
gid_t gid; gid_t gid;
unsigned int flags; /* flags from file struct */ unsigned long flags; /* flags from file struct */
void *device_info; /* device info */ void *device_info; /* device info */
void *private_info; /* file 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 * union but it just makes things too complex and doesn't save all
* that much memory anyway */ * that much memory anyway */
ssize_t retval; ssize_t retval;
size_t length; unsigned long length;
loff_t offset; unsigned long offset;
unsigned int cmd; /* ioctl cmd, poll_diff cached_state */ unsigned int cmd; /* ioctl cmd, poll_diff cached_state */
/* mmap parameters */
unsigned long mmprot;
unsigned long mmflags;
unsigned long mmoffset;
union { union {
unsigned long arg; /* ioctl */ unsigned long arg; /* ioctl */
void *ptr_arg; void *ptr_arg;
@ -148,4 +155,6 @@ typedef struct {
int num_open; int num_open;
} fusd_status_t; } fusd_status_t;
#pragma pack()
#endif /* __FUSD_MSG_H__ */ #endif /* __FUSD_MSG_H__ */

View File

@ -37,7 +37,6 @@
* *
* Private header file used by the Linux Kernel Module * Private header file used by the Linux Kernel Module
* *
* $Id: kfusd.h 12351 2007-01-19 07:22:54Z xiphmont $
*/ */
#ifndef __KFUSD_H__ #ifndef __KFUSD_H__
@ -151,30 +150,6 @@ struct fusd_dev_t_s {
/* pointer to allow a dev to be placed on a dev_list */ /* pointer to allow a dev to be placed on a dev_list */
struct list_head devlist; 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 ****/ /**** Utility functions & macros ****/

View File

@ -9,7 +9,7 @@ GIT_DESCRIBE = $(shell git describe --dirty --tags)
KERNEL_VER ?= 2.6.32.7 KERNEL_VER ?= 2.6.32.7
default: default:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) EXTRA_CFLAGS="-I$(PWD)/../include -DGIT_DESCRIBE='\"${GIT_DESCRIBE}\"'" V=1 modules $(MAKE) -C $(KDIR) M=$(PWD) EXTRA_CFLAGS="-I$(PWD)/../include -DGIT_DESCRIBE='\"${GIT_DESCRIBE}\"'" V=1 modules
install: install:
install -d -m 0755 $(ROOTFS)/lib/modules/$(KERNEL_VER)/kernel/drivers/misc install -d -m 0755 $(ROOTFS)/lib/modules/$(KERNEL_VER)/kernel/drivers/misc

View File

@ -38,9 +38,8 @@
* Copyright (c) 2001, Sensoria Corporation * Copyright (c) 2001, Sensoria Corporation
* Copyright (c) 2002-2003, Regents of the University of California * Copyright (c) 2002-2003, Regents of the University of California
* Copyright (c) 2007 Monty and Xiph.Org * Copyright (c) 2007 Monty and Xiph.Org
* Copyright (c) 2009-2018 Manoel Trapier <godzil@godzil.net> * Copyright (c) 2009-2019 Manoel Trapier <godzil@godzil.net>
* *
* $Id: kfusd.c 12354 2007-01-19 17:26:14Z xiphmont $
*/ */
/* /*
@ -66,6 +65,8 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/aio.h>
#include <linux/mman.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/vmalloc.h> #include <linux/vmalloc.h>
#include <linux/poll.h> #include <linux/poll.h>
@ -75,6 +76,7 @@
#include <linux/cdev.h> #include <linux/cdev.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/highmem.h> #include <linux/highmem.h>
#include <linux/sched.h>
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
#include <linux/sched/signal.h> #include <linux/sched/signal.h>
@ -86,8 +88,6 @@
#include <asm/pgtable.h> #include <asm/pgtable.h>
#include <asm/pgalloc.h> #include <asm/pgalloc.h>
#define STATIC
#ifndef GIT_DESCRIBE #ifndef GIT_DESCRIBE
#define GIT_DESCRIBE "unknownversion-dirty" #define GIT_DESCRIBE "unknownversion-dirty"
#endif #endif
@ -145,10 +145,15 @@
#define CLASS_DEVICE_DESTROY(a, b) device_destroy(a, b) #define CLASS_DEVICE_DESTROY(a, b) device_destroy(a, b)
#endif #endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
#define GET_USER_PAGES(t,m,s,n,w,f,p,v) get_user_pages_remote(t,m,s,n,(w?FOLL_WRITE:0)|(f?FOLL_FORCE:0),p,v, NULL) #define GET_USER_PAGES(t,m,s,n,w,f,p,v) get_user_pages_remote(t,m,s,n,(w?FOLL_WRITE:0)|(f?FOLL_FORCE:0),p,v, NULL)
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0)
#define GET_USER_PAGES(t,m,s,n,w,f,p,v) get_user_pages_remote(t,m,s,n,(w?FOLL_WRITE:0)|(f?FOLL_FORCE:0),p,v)
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 6, 0) #elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 6, 0)
#define GET_USER_PAGES(t,m,s,n,w,f,p,v) get_user_pages_remote(t,m,s,n,w,f,p,v) #define GET_USER_PAGES(t,m,s,n,w,f,p,v) get_user_pages_remote(t,m,s,n,w,f,p,v)
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 168) && LINUX_VERSION_CODE < KERNEL_VERSION(4, 5, 0)
/* WTH? a small subset of 4.4 have changes that does not exist until 4.9 with a new function name */
#define GET_USER_PAGES(t,m,s,n,w,f,p,v) get_user_pages(t,m,s,n,(w?FOLL_WRITE:0)|(f?FOLL_FORCE:0),p,v)
#else #else
#define GET_USER_PAGES(t, m, s, n, w, f, p, v) get_user_pages(t,m,s,n,w,f,p,v) #define GET_USER_PAGES(t, m, s, n, w, f, p, v) get_user_pages(t,m,s,n,w,f,p,v)
#endif #endif
@ -169,11 +174,11 @@
#error "***FUSD doesn't work before Linux Kernel v2.6.13" #error "***FUSD doesn't work before Linux Kernel v2.6.13"
#endif #endif
STATIC struct cdev *fusd_control_cdev; static struct cdev *fusd_control_cdev;
STATIC struct cdev *fusd_status_cdev; static struct cdev *fusd_status_cdev;
STATIC dev_t control_id; static dev_t control_id;
STATIC dev_t status_id; static dev_t status_id;
static struct CLASS *fusd_class; static struct CLASS *fusd_class;
@ -186,13 +191,13 @@ static struct device *fusd_status_device;
#endif #endif
/* version number incremented for each registered device */ /* version number incremented for each registered device */
STATIC int last_version = 1; static int last_version = 1;
/* version number incremented for each transaction to userspace */ /* version number incremented for each transaction to userspace */
STATIC int last_transid = 1; static int last_transid = 1;
/* wait queue that is awakened when new devices are registered */ /* wait queue that is awakened when new devices are registered */
STATIC DECLARE_WAIT_QUEUE_HEAD (new_device_wait); static DECLARE_WAIT_QUEUE_HEAD (new_device_wait);
/* the list of valid devices, and sem to protect it */ /* the list of valid devices, and sem to protect it */
LIST_HEAD (fusd_devlist_head); LIST_HEAD (fusd_devlist_head);
@ -205,16 +210,36 @@ DEFINE_SEMAPHORE (fusd_devlist_sem);
//#ifdef MODULE_LICENSE //#ifdef MODULE_LICENSE
MODULE_AUTHOR ("Jeremy Elson <jelson@acm.org> (c)2001"); MODULE_AUTHOR ("Jeremy Elson <jelson@acm.org> (c)2001");
MODULE_AUTHOR ("Manoel Trapier <godzil@godzil.net> (c)2009-2018"); MODULE_AUTHOR ("Manoel Trapier <godzil@godzil.net> (c)2009-2019");
MODULE_VERSION(GIT_DESCRIBE); MODULE_VERSION(GIT_DESCRIBE);
MODULE_LICENSE ("GPL"); MODULE_LICENSE ("GPL");
//#endif //#endif
/**** 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_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);
/***************************Debugging Support*****************************/ /***************************Debugging Support*****************************/
#ifdef CONFIG_FUSD_DEBUG #ifdef CONFIG_FUSD_DEBUG
STATIC int fusd_debug_level = CONFIG_FUSD_DEBUGLEVEL; static int fusd_debug_level = CONFIG_FUSD_DEBUGLEVEL;
module_param (fusd_debug_level, int, S_IRUGO); module_param (fusd_debug_level, int, S_IRUGO);
# define BUFSIZE 1000 /* kernel's kmalloc pool has a 1012-sized bucket */ # define BUFSIZE 1000 /* kernel's kmalloc pool has a 1012-sized bucket */
@ -223,7 +248,7 @@ static int debug_throttle = 0; /* emit a maximum number of debug
out the machine accidentally if a out the machine accidentally if a
daemon disappears with open files */ daemon disappears with open files */
STATIC void rdebug_real(char *fmt, ...) static void rdebug_real(char *fmt, ...)
{ {
va_list ap; va_list ap;
int len; int len;
@ -276,7 +301,7 @@ typedef struct
mem_debug_t *mem_debug; mem_debug_t *mem_debug;
STATIC int fusd_mem_init (void) static int fusd_mem_init (void)
{ {
int i; int i;
@ -296,7 +321,7 @@ STATIC int fusd_mem_init (void)
return 0; return 0;
} }
STATIC void fusd_mem_cleanup (void) static void fusd_mem_cleanup (void)
{ {
int i; int i;
int count = 0; int count = 0;
@ -312,7 +337,7 @@ STATIC void fusd_mem_cleanup (void)
kfree(mem_debug); kfree(mem_debug);
} }
STATIC void fusd_mem_add (void *ptr, int line, int size) static void fusd_mem_add (void *ptr, int line, int size)
{ {
int i; int i;
@ -332,7 +357,7 @@ STATIC void fusd_mem_add (void *ptr, int line, int size)
RDEBUG(1, "WARNING - memdebug out of space!!!!"); RDEBUG(1, "WARNING - memdebug out of space!!!!");
} }
STATIC void fusd_mem_del (void *ptr) static void fusd_mem_del (void *ptr)
{ {
int i; int i;
for ( i = 0; i < MAX_MEM_DEBUG; i++ ) for ( i = 0; i < MAX_MEM_DEBUG; i++ )
@ -346,7 +371,7 @@ STATIC void fusd_mem_del (void *ptr)
RDEBUG(2, "WARNING - memdebug is confused!!!!"); RDEBUG(2, "WARNING - memdebug is confused!!!!");
} }
STATIC void *fusd_kmalloc (size_t size, int type, int line) static void *fusd_kmalloc (size_t size, int type, int line)
{ {
void *ptr = kmalloc(size, type); void *ptr = kmalloc(size, type);
down(&fusd_memdebug_sem); down(&fusd_memdebug_sem);
@ -355,7 +380,7 @@ STATIC void *fusd_kmalloc (size_t size, int type, int line)
return ptr; return ptr;
} }
STATIC void fusd_kfree (void *ptr) static void fusd_kfree (void *ptr)
{ {
down(&fusd_memdebug_sem); down(&fusd_memdebug_sem);
fusd_mem_del(ptr); fusd_mem_del(ptr);
@ -363,7 +388,7 @@ STATIC void fusd_kfree (void *ptr)
up(&fusd_memdebug_sem); up(&fusd_memdebug_sem);
} }
STATIC void *fusd_vmalloc (size_t size, int line) static void *fusd_vmalloc (size_t size, int line)
{ {
void *ptr = vmalloc(size); void *ptr = vmalloc(size);
down(&fusd_memdebug_sem); down(&fusd_memdebug_sem);
@ -372,7 +397,7 @@ STATIC void *fusd_vmalloc (size_t size, int line)
return ptr; return ptr;
} }
STATIC void fusd_vfree (void *ptr) static void fusd_vfree (void *ptr)
{ {
down(&fusd_memdebug_sem); down(&fusd_memdebug_sem);
fusd_mem_del(ptr); fusd_mem_del(ptr);
@ -391,7 +416,7 @@ STATIC void fusd_vfree (void *ptr)
/************** STATE MANAGEMENT AND BOOKKEEPING UTILITIES ***************/ /************** STATE MANAGEMENT AND BOOKKEEPING UTILITIES ***************/
/*************************************************************************/ /*************************************************************************/
STATIC inline void init_fusd_msg(fusd_msg_t *fusd_msg) static inline void init_fusd_msg(fusd_msg_t *fusd_msg)
{ {
if (fusd_msg == NULL) if (fusd_msg == NULL)
return; return;
@ -404,7 +429,7 @@ STATIC inline void init_fusd_msg(fusd_msg_t *fusd_msg)
/* /*
* free a fusd_msg, and NULL out the pointer that points to that fusd_msg. * free a fusd_msg, and NULL out the pointer that points to that fusd_msg.
*/ */
STATIC inline void free_fusd_msg(fusd_msg_t **fusd_msg) static inline void free_fusd_msg(fusd_msg_t **fusd_msg)
{ {
if (fusd_msg == NULL || *fusd_msg == NULL) if (fusd_msg == NULL || *fusd_msg == NULL)
return; return;
@ -425,7 +450,7 @@ STATIC inline void free_fusd_msg(fusd_msg_t **fusd_msg)
* num_files<array_size/4, the size is halved. Array is kept as is if * num_files<array_size/4, the size is halved. Array is kept as is if
* the malloc fails. Returns a pointer to the new file struct or NULL * the malloc fails. Returns a pointer to the new file struct or NULL
* if there isn't one. */ * if there isn't one. */
STATIC fusd_file_t **fusd_dev_adjsize(fusd_dev_t *fusd_dev) static fusd_file_t **fusd_dev_adjsize(fusd_dev_t *fusd_dev)
{ {
fusd_file_t **old_array; fusd_file_t **old_array;
int old_size; int old_size;
@ -489,7 +514,7 @@ STATIC fusd_file_t **fusd_dev_adjsize(fusd_dev_t *fusd_dev)
* *
* Returns: 1 if the device was freed * Returns: 1 if the device was freed
* 0 if the device still exists (and can be unlocked) */ * 0 if the device still exists (and can be unlocked) */
STATIC int maybe_free_fusd_dev(fusd_dev_t *fusd_dev) static int maybe_free_fusd_dev(fusd_dev_t *fusd_dev)
{ {
fusd_msgC_t *ptr, *next; fusd_msgC_t *ptr, *next;
@ -563,7 +588,7 @@ STATIC int maybe_free_fusd_dev(fusd_dev_t *fusd_dev)
* device state itself is freed. * device state itself is freed.
* *
*/ */
STATIC void zombify_dev(fusd_dev_t *fusd_dev) static void zombify_dev(fusd_dev_t *fusd_dev)
{ {
int i; int i;
@ -588,7 +613,7 @@ STATIC void zombify_dev(fusd_dev_t *fusd_dev)
* returns index if found, -1 if not found. ASSUMES WE HAVE A VALID * returns index if found, -1 if not found. ASSUMES WE HAVE A VALID
* fusd_dev. fusd_file may be NULL if we are searching for an empty * fusd_dev. fusd_file may be NULL if we are searching for an empty
* slot. */ * slot. */
STATIC int find_fusd_file(fusd_dev_t *fusd_dev, fusd_file_t *fusd_file) static int find_fusd_file(fusd_dev_t *fusd_dev, fusd_file_t *fusd_file)
{ {
int i, num_files = fusd_dev->num_files; int i, num_files = fusd_dev->num_files;
fusd_file_t **files = fusd_dev->files; fusd_file_t **files = fusd_dev->files;
@ -607,7 +632,7 @@ STATIC int find_fusd_file(fusd_dev_t *fusd_dev, fusd_file_t *fusd_file)
* freed. If the device is freed, then do not try to unlock it! * freed. If the device is freed, then do not try to unlock it!
* (Callers: Check the return value before unlocking!) * (Callers: Check the return value before unlocking!)
*/ */
STATIC int free_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)
{ {
int i; int i;
struct list_head *tmp, *it; struct list_head *tmp, *it;
@ -673,7 +698,7 @@ STATIC int free_fusd_file(fusd_dev_t *fusd_dev, fusd_file_t *fusd_file)
* call on that file descriptor -- well, we lose. Clear state of that * call on that file descriptor -- well, we lose. Clear state of that
* old syscall out and continue as usual. * old syscall out and continue as usual.
*/ */
STATIC struct fusd_transaction *fusd_find_incomplete_transaction(fusd_file_t *fusd_file, int subcmd) static struct fusd_transaction *fusd_find_incomplete_transaction(fusd_file_t *fusd_file, int subcmd)
{ {
struct fusd_transaction *transaction = fusd_find_transaction_by_pid(fusd_file, current->pid); struct fusd_transaction *transaction = fusd_find_transaction_by_pid(fusd_file, current->pid);
if (transaction == NULL) if (transaction == NULL)
@ -692,7 +717,7 @@ STATIC struct fusd_transaction *fusd_find_incomplete_transaction(fusd_file_t *fu
return transaction; return transaction;
} }
STATIC int send_to_dev(fusd_dev_t *fusd_dev, fusd_msg_t *fusd_msg, int locked) static int send_to_dev(fusd_dev_t *fusd_dev, fusd_msg_t *fusd_msg, int locked)
{ {
fusd_msgC_t *fusd_msgC; fusd_msgC_t *fusd_msgC;
@ -735,7 +760,7 @@ zombie_dev:
* free_fusd_file, when we throw away a reply that had been * free_fusd_file, when we throw away a reply that had been
* pending for a restart. * pending for a restart.
*/ */
STATIC void fusd_forge_close(fusd_msg_t *msg, fusd_dev_t *fusd_dev) static void fusd_forge_close(fusd_msg_t *msg, fusd_dev_t *fusd_dev)
{ {
RDEBUG(2, "/dev/%s tried to complete an open for transid %ld, " RDEBUG(2, "/dev/%s tried to complete an open for transid %ld, "
"forging a close", NAME(fusd_dev), msg->parm.fops_msg.transid); "forging a close", NAME(fusd_dev), msg->parm.fops_msg.transid);
@ -751,7 +776,7 @@ STATIC void fusd_forge_close(fusd_msg_t *msg, fusd_dev_t *fusd_dev)
* NOTE - we are already holding the lock on fusd_file_arg when this * NOTE - we are already holding the lock on fusd_file_arg when this
* function is called, but NOT the lock on the fusd_dev * function is called, but NOT the lock on the fusd_dev
*/ */
STATIC int fusd_fops_call_send(fusd_file_t *fusd_file_arg, static int fusd_fops_call_send(fusd_file_t *fusd_file_arg,
fusd_msg_t *fusd_msg, struct fusd_transaction **transaction) fusd_msg_t *fusd_msg, struct fusd_transaction **transaction)
{ {
fusd_dev_t *fusd_dev; fusd_dev_t *fusd_dev;
@ -825,7 +850,7 @@ invalid_file:
* NOTE - we are already holding the lock on fusd_file_arg when this * NOTE - we are already holding the lock on fusd_file_arg when this
* function is called, but NOT the lock on the fusd_dev * function is called, but NOT the lock on the fusd_dev
*/ */
STATIC int fusd_fops_call_wait(fusd_file_t *fusd_file_arg, static int fusd_fops_call_wait(fusd_file_t *fusd_file_arg,
fusd_msg_t **fusd_msg_reply, struct fusd_transaction *transaction) fusd_msg_t **fusd_msg_reply, struct fusd_transaction *transaction)
{ {
fusd_dev_t *fusd_dev; fusd_dev_t *fusd_dev;
@ -931,16 +956,6 @@ zombie_dev:
return -EPIPE; return -EPIPE;
} }
/* fusd client system call handlers should call this after they call
* fops_call, to destroy the message that was returned to them. */
STATIC void fusd_transaction_done(struct fusd_transaction *transaction)
{
transaction->transid = -1;
transaction->pid = 0;
}
/********* Functions for opening a FUSD device *******************/ /********* Functions for opening a FUSD device *******************/
@ -1082,7 +1097,7 @@ int fusd_dev_add_file(struct file *file, fusd_dev_t *fusd_dev, fusd_file_t **fus
return 0; return 0;
} }
STATIC struct fusd_dev_t_s *find_user_device(int dev_id) static struct fusd_dev_t_s *find_user_device(int dev_id)
{ {
struct list_head *entry; struct list_head *entry;
down(&fusd_devlist_sem); down(&fusd_devlist_sem);
@ -1103,7 +1118,7 @@ STATIC struct fusd_dev_t_s *find_user_device(int dev_id)
* A client has called open() has been called on a registered device. * A client has called open() has been called on a registered device.
* See comment higher up for detailed notes on this function. * See comment higher up for detailed notes on this function.
*/ */
STATIC int fusd_client_open(struct inode *inode, struct file *file) static int fusd_client_open(struct inode *inode, struct file *file)
{ {
int retval; int retval;
int device_freed = 0; int device_freed = 0;
@ -1188,7 +1203,7 @@ STATIC int fusd_client_open(struct inode *inode, struct file *file)
/* close() has been called on a registered device. like /* close() has been called on a registered device. like
* fusd_client_open, we must lock the entire device. */ * fusd_client_open, we must lock the entire device. */
STATIC int fusd_client_release(struct inode *inode, struct file *file) static int fusd_client_release(struct inode *inode, struct file *file)
{ {
int retval; int retval;
fusd_file_t *fusd_file; fusd_file_t *fusd_file;
@ -1229,7 +1244,7 @@ invalid_file:
return -EPIPE; return -EPIPE;
} }
STATIC ssize_t fusd_client_read(struct file *file, char *buf, static ssize_t fusd_client_read(struct file *file, char *buf,
size_t count, loff_t *offset) size_t count, loff_t *offset)
{ {
fusd_dev_t *fusd_dev; fusd_dev_t *fusd_dev;
@ -1326,7 +1341,7 @@ zombie_dev:
return -EPIPE; return -EPIPE;
} }
STATIC int fusd_add_transaction(fusd_file_t *fusd_file, int transid, int subcmd, int size, static int fusd_add_transaction(fusd_file_t *fusd_file, int transid, int subcmd, int size,
struct fusd_transaction **out_transaction) struct fusd_transaction **out_transaction)
{ {
struct fusd_transaction *transaction = (struct fusd_transaction *) KMALLOC(sizeof(struct fusd_transaction), struct fusd_transaction *transaction = (struct fusd_transaction *) KMALLOC(sizeof(struct fusd_transaction),
@ -1350,13 +1365,13 @@ STATIC int fusd_add_transaction(fusd_file_t *fusd_file, int transid, int subcmd,
return 0; return 0;
} }
STATIC void fusd_cleanup_transaction(fusd_file_t *fusd_file, struct fusd_transaction *transaction) static void fusd_cleanup_transaction(fusd_file_t *fusd_file, struct fusd_transaction *transaction)
{ {
free_fusd_msg(&transaction->msg_in); free_fusd_msg(&transaction->msg_in);
fusd_remove_transaction(fusd_file, transaction); fusd_remove_transaction(fusd_file, transaction);
} }
STATIC void fusd_remove_transaction(fusd_file_t *fusd_file, struct fusd_transaction *transaction) static void fusd_remove_transaction(fusd_file_t *fusd_file, struct fusd_transaction *transaction)
{ {
down(&fusd_file->transactions_sem); down(&fusd_file->transactions_sem);
list_del(&transaction->list); list_del(&transaction->list);
@ -1365,7 +1380,7 @@ STATIC void fusd_remove_transaction(fusd_file_t *fusd_file, struct fusd_transact
KFREE(transaction); KFREE(transaction);
} }
STATIC struct fusd_transaction *fusd_find_transaction(fusd_file_t *fusd_file, int transid) static struct fusd_transaction *fusd_find_transaction(fusd_file_t *fusd_file, int transid)
{ {
struct list_head *i; struct list_head *i;
down(&fusd_file->transactions_sem); down(&fusd_file->transactions_sem);
@ -1383,7 +1398,7 @@ STATIC struct fusd_transaction *fusd_find_transaction(fusd_file_t *fusd_file, in
return NULL; return NULL;
} }
STATIC struct fusd_transaction *fusd_find_transaction_by_pid(fusd_file_t *fusd_file, int pid) static struct fusd_transaction *fusd_find_transaction_by_pid(fusd_file_t *fusd_file, int pid)
{ {
struct list_head *i; struct list_head *i;
down(&fusd_file->transactions_sem); down(&fusd_file->transactions_sem);
@ -1401,7 +1416,7 @@ STATIC struct fusd_transaction *fusd_find_transaction_by_pid(fusd_file_t *fusd_f
return NULL; return NULL;
} }
STATIC ssize_t fusd_client_write(struct file *file, static ssize_t fusd_client_write(struct file *file,
const char *buffer, const char *buffer,
size_t length, size_t length,
loff_t *offset) loff_t *offset)
@ -1499,10 +1514,10 @@ zombie_dev:
} }
#ifndef HAVE_UNLOCKED_IOCTL #ifndef HAVE_UNLOCKED_IOCTL
STATIC int fusd_client_ioctl(struct inode *inode, struct file *file, static int fusd_client_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, unsigned long arg) unsigned int cmd, unsigned long arg)
#else #else
STATIC long fusd_client_unlocked_ioctl (struct file *file, static long fusd_client_unlocked_ioctl (struct file *file,
unsigned int cmd, unsigned long arg) unsigned int cmd, unsigned long arg)
#endif #endif
{ {
@ -1599,15 +1614,14 @@ static void fusd_client_mm_open(struct vm_area_struct *vma);
static void fusd_client_mm_close(struct vm_area_struct *vma); static void fusd_client_mm_close(struct vm_area_struct *vma);
/* int (*fault)(struct vm_area_struct *vma, struct vm_fault *vmf); */ #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 17, 0)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) static vm_fault_t fusd_client_fault (struct vm_fault *vmf);
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
static int fusd_client_fault (struct vm_fault *vmf); static int fusd_client_fault (struct vm_fault *vmf);
#elif LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 30) #elif LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 30)
static int fusd_client_fault (struct vm_area_struct *vma, struct vm_fault *vmf); static int fusd_client_fault (struct vm_area_struct *vma, struct vm_fault *vmf);
#else #else
static int fusd_client_fault(struct vm_area_struct *vma, struct vm_fault *vmf, int *type); static int fusd_client_fault(struct vm_area_struct *vma, struct vm_fault *vmf, int *type);
#endif #endif
static struct vm_operations_struct fusd_remap_vm_ops = { static struct vm_operations_struct fusd_remap_vm_ops = {
@ -1620,7 +1634,7 @@ struct fusd_mmap_instance {
fusd_dev_t *fusd_dev; fusd_dev_t *fusd_dev;
fusd_file_t *fusd_file; fusd_file_t *fusd_file;
unsigned long addr; unsigned long addr;
int size; unsigned long size;
atomic_t refcount; atomic_t refcount;
}; };
@ -1664,8 +1678,17 @@ static int fusd_client_mmap(struct file *file, struct vm_area_struct *vma)
/* send the message */ /* send the message */
init_fusd_msg(&fusd_msg); init_fusd_msg(&fusd_msg);
fusd_msg.subcmd = FUSD_MMAP; fusd_msg.subcmd = FUSD_MMAP;
fusd_msg.parm.fops_msg.offset = vma->vm_pgoff << PAGE_SHIFT; fusd_msg.parm.fops_msg.mmoffset = vma->vm_pgoff << PAGE_SHIFT;
fusd_msg.parm.fops_msg.flags = vma->vm_flags;
fusd_msg.parm.fops_msg.mmprot = ((vma->vm_flags & VM_READ) ? PROT_READ : 0) |
((vma->vm_flags & VM_WRITE) ? PROT_WRITE : 0) |
((vma->vm_flags & VM_EXEC) ? PROT_EXEC : 0);
fusd_msg.parm.fops_msg.mmflags = ((vma->vm_flags & VM_SHARED) ? MAP_SHARED : 0 ) |
((vma->vm_flags & VM_GROWSDOWN) ? MAP_GROWSDOWN : 0) |
((vma->vm_flags & VM_DENYWRITE) ? MAP_DENYWRITE : 0) |
((vma->vm_flags & VM_EXEC) ? MAP_EXECUTABLE : 0) |
((vma->vm_flags & VM_LOCKED) ? MAP_LOCKED : 0);
fusd_msg.parm.fops_msg.length = vma->vm_end - vma->vm_start; fusd_msg.parm.fops_msg.length = vma->vm_end - vma->vm_start;
/* send message to userspace */ /* send message to userspace */
@ -1712,7 +1735,9 @@ zombie_dev:
return -EPIPE; return -EPIPE;
} }
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 17, 0)
static vm_fault_t fusd_client_fault (struct vm_fault *vmf)
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
static int fusd_client_fault (struct vm_fault *vmf) static int fusd_client_fault (struct vm_fault *vmf)
#elif LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 30) #elif LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 30)
static int fusd_client_fault (struct vm_area_struct *vma, struct vm_fault *vmf) static int fusd_client_fault (struct vm_area_struct *vma, struct vm_fault *vmf)
@ -1737,8 +1762,11 @@ static int fusd_client_fault(struct vm_area_struct *vma, struct vm_fault *vmf, i
#endif #endif
// todo: worry about size // todo: worry about size
if (offset > mmap_instance->size) if (offset > mmap_instance->size) {
RDEBUG(2,
"Current offset bigger than block size: cannot accept");
goto out; goto out;
}
down_read(&mmap_instance->fusd_dev->task->mm->mmap_sem); down_read(&mmap_instance->fusd_dev->task->mm->mmap_sem);
result = GET_USER_PAGES(mmap_instance->fusd_dev->task, mmap_instance->fusd_dev->task->mm, result = GET_USER_PAGES(mmap_instance->fusd_dev->task, mmap_instance->fusd_dev->task->mm,
@ -1746,9 +1774,9 @@ static int fusd_client_fault(struct vm_area_struct *vma, struct vm_fault *vmf, i
up_read(&mmap_instance->fusd_dev->task->mm->mmap_sem); up_read(&mmap_instance->fusd_dev->task->mm->mmap_sem);
if (PageAnon(vmf->page)) { if (PageAnon(page)) {
RDEBUG(2, RDEBUG(2, "Cannot mmap non anonymous pages: The server is sharing a private page.\n"
"Cannot mmap anonymous pages. Be sure to allocate your shared buffer with MAP_SHARED | MAP_ANONYMOUS"); "Be sure to allocate your shared buffer with mmap and MAP_SHARED | MAP_ANONYMOUS as flags.");
return VM_FAULT_SIGBUS; return VM_FAULT_SIGBUS;
} }
@ -1783,7 +1811,7 @@ out:
* cached from the driver. * cached from the driver.
* *
*/ */
STATIC unsigned int fusd_client_poll(struct file *file, poll_table *wait) static unsigned int fusd_client_poll(struct file *file, poll_table *wait)
{ {
fusd_dev_t *fusd_dev; fusd_dev_t *fusd_dev;
fusd_file_t *fusd_file; fusd_file_t *fusd_file;
@ -1860,7 +1888,7 @@ invalid_file:
} }
#ifndef HAVE_UNLOCKED_IOCTL #ifndef HAVE_UNLOCKED_IOCTL
STATIC struct file_operations fusd_client_fops = { static struct file_operations fusd_client_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.open = fusd_client_open, .open = fusd_client_open,
.release = fusd_client_release, .release = fusd_client_release,
@ -1871,7 +1899,7 @@ STATIC struct file_operations fusd_client_fops = {
.mmap = fusd_client_mmap .mmap = fusd_client_mmap
}; };
#else #else
STATIC struct file_operations fusd_client_fops = { static struct file_operations fusd_client_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.open = fusd_client_open, .open = fusd_client_open,
.release = fusd_client_release, .release = fusd_client_release,
@ -1888,7 +1916,7 @@ STATIC struct file_operations fusd_client_fops = {
/*************************************************************************/ /*************************************************************************/
STATIC fusd_file_t *find_fusd_reply_file(fusd_dev_t *fusd_dev, fusd_msg_t *msg) static fusd_file_t *find_fusd_reply_file(fusd_dev_t *fusd_dev, fusd_msg_t *msg)
{ {
/* first, try the hint */ /* first, try the hint */
int i = msg->parm.fops_msg.hint; int i = msg->parm.fops_msg.hint;
@ -1913,7 +1941,7 @@ STATIC fusd_file_t *find_fusd_reply_file(fusd_dev_t *fusd_dev, fusd_msg_t *msg)
/* Process an incoming reply to a message dispatched by /* Process an incoming reply to a message dispatched by
* fusd_fops_call. Called by fusd_write when a driver writes to * fusd_fops_call. Called by fusd_write when a driver writes to
* /dev/fusd. */ * /dev/fusd. */
STATIC int fusd_fops_reply(fusd_dev_t *fusd_dev, fusd_msg_t *msg) static int fusd_fops_reply(fusd_dev_t *fusd_dev, fusd_msg_t *msg)
{ {
fusd_file_t *fusd_file; fusd_file_t *fusd_file;
struct fusd_transaction *transaction; struct fusd_transaction *transaction;
@ -1962,7 +1990,7 @@ discard:
} }
/* special function to process responses to POLL_DIFF */ /* special function to process responses to POLL_DIFF */
STATIC int fusd_polldiff_reply(fusd_dev_t *fusd_dev, fusd_msg_t *msg) static int fusd_polldiff_reply(fusd_dev_t *fusd_dev, fusd_msg_t *msg)
{ {
fusd_file_t *fusd_file; fusd_file_t *fusd_file;
@ -1989,13 +2017,7 @@ STATIC int fusd_polldiff_reply(fusd_dev_t *fusd_dev, fusd_msg_t *msg)
return 0; return 0;
} }
STATIC int systest(struct super_block *sb, void *data) static int fusd_register_device(fusd_dev_t *fusd_dev,
{
return 1;
}
STATIC int fusd_register_device(fusd_dev_t *fusd_dev,
register_msg_t register_msg) register_msg_t register_msg)
{ {
int error = 0; int error = 0;
@ -2122,7 +2144,7 @@ register_failed:
/****************************************************************************/ /****************************************************************************/
/* open() called on /dev/fusd itself */ /* open() called on /dev/fusd itself */
STATIC int fusd_open(struct inode *inode, struct file *file) static int fusd_open(struct inode *inode, struct file *file)
{ {
fusd_dev_t *fusd_dev = NULL; fusd_dev_t *fusd_dev = NULL;
fusd_file_t **file_array = NULL; fusd_file_t **file_array = NULL;
@ -2167,7 +2189,7 @@ dev_malloc_failed:
/* close() called on /dev/fusd itself. destroy the device that /* close() called on /dev/fusd itself. destroy the device that
* was registered by it, if any. */ * was registered by it, if any. */
STATIC int fusd_release(struct inode *inode, struct file *file) static int fusd_release(struct inode *inode, struct file *file)
{ {
fusd_dev_t *fusd_dev; fusd_dev_t *fusd_dev;
@ -2226,7 +2248,7 @@ invalid_dev:
* This function processes messages coming from userspace device drivers * This function processes messages coming from userspace device drivers
* (i.e., writes to the /dev/fusd control channel.) * (i.e., writes to the /dev/fusd control channel.)
*/ */
STATIC ssize_t fusd_process_write(struct file *file, static ssize_t fusd_process_write(struct file *file,
const char *user_msg_buffer, size_t user_msg_len, const char *user_msg_buffer, size_t user_msg_len,
const char *user_data_buffer, size_t user_data_len) const char *user_data_buffer, size_t user_data_len)
{ {
@ -2374,7 +2396,7 @@ invalid_dev:
return -EPIPE; return -EPIPE;
} }
STATIC ssize_t fusd_write(struct file *file, static ssize_t fusd_write(struct file *file,
const char *buffer, const char *buffer,
size_t length, size_t length,
loff_t *offset) loff_t *offset)
@ -2384,7 +2406,7 @@ STATIC ssize_t fusd_write(struct file *file,
} }
#ifndef HAVE_UNLOCKED_IOCTL #ifndef HAVE_UNLOCKED_IOCTL
STATIC ssize_t fusd_writev(struct file *file, static ssize_t fusd_writev(struct file *file,
const struct iovec *iov, const struct iovec *iov,
unsigned long count, unsigned long count,
loff_t *offset) loff_t *offset)
@ -2402,7 +2424,7 @@ STATIC ssize_t fusd_writev(struct file *file,
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 0) #elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 0)
ssize_t fusd_write_iter (struct kiocb *iocb, struct iov_iter *iov) ssize_t fusd_write_iter (struct kiocb *iocb, struct iov_iter *iov)
{ {
unsigned long count = iov_iter_count(iov); // unsigned long count = iov_iter_count(iov);
char *msg, *data; char *msg, *data;
size_t msg_len, data_len; size_t msg_len, data_len;
@ -2425,7 +2447,7 @@ ssize_t fusd_write_iter (struct kiocb *iocb, struct iov_iter *iov)
data, data_len); data, data_len);
} }
#else #else
STATIC ssize_t fusd_aio_write (struct kiocb *iocb, static ssize_t fusd_aio_write (struct kiocb *iocb,
const struct iovec *iov, const struct iovec *iov,
unsigned long count, unsigned long count,
loff_t offset) loff_t offset)
@ -2443,10 +2465,10 @@ STATIC ssize_t fusd_aio_write (struct kiocb *iocb,
#endif #endif
#ifndef HAVE_UNLOCKED_IOCTL #ifndef HAVE_UNLOCKED_IOCTL
STATIC int fusd_ioctl(struct inode *inode, struct file *file, static int fusd_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, unsigned long arg) unsigned int cmd, unsigned long arg)
#else #else
STATIC long fusd_unlocked_ioctl (struct file *file, static long fusd_unlocked_ioctl (struct file *file,
unsigned int cmd, unsigned long arg) unsigned int cmd, unsigned long arg)
#endif #endif
{ {
@ -2516,7 +2538,7 @@ STATIC long fusd_unlocked_ioctl (struct file *file,
* message queue.) */ * message queue.) */
/* do a "header" read: used by fusd_read */ /* do a "header" read: used by fusd_read */
STATIC int fusd_read_header(char *user_buffer, size_t user_length, fusd_msg_t *msg) static int fusd_read_header(char *user_buffer, size_t user_length, fusd_msg_t *msg)
{ {
int len = sizeof(fusd_msg_t); int len = sizeof(fusd_msg_t);
@ -2532,7 +2554,7 @@ STATIC int fusd_read_header(char *user_buffer, size_t user_length, fusd_msg_t *m
} }
/* do a "data" read: used by fusd_read */ /* do a "data" read: used by fusd_read */
STATIC int fusd_read_data(char *user_buffer, size_t user_length, fusd_msg_t *msg) static int fusd_read_data(char *user_buffer, size_t user_length, fusd_msg_t *msg)
{ {
int len = msg->datalen; int len = msg->datalen;
@ -2556,7 +2578,7 @@ STATIC int fusd_read_data(char *user_buffer, size_t user_length, fusd_msg_t *msg
return len; return len;
} }
STATIC ssize_t fusd_read(struct file *file, static ssize_t fusd_read(struct file *file,
char *user_buffer, /* The buffer to fill with data */ char *user_buffer, /* The buffer to fill with data */
size_t user_length, /* The length of the buffer */ size_t user_length, /* The length of the buffer */
loff_t *offset) /* Our offset in the file */ loff_t *offset) /* Our offset in the file */
@ -2639,7 +2661,7 @@ invalid_dev:
} }
/* a poll on /dev/fusd itself (the control channel) */ /* a poll on /dev/fusd itself (the control channel) */
STATIC unsigned int fusd_poll(struct file *file, poll_table *wait) static unsigned int fusd_poll(struct file *file, poll_table *wait)
{ {
fusd_dev_t *fusd_dev; fusd_dev_t *fusd_dev;
GET_FUSD_DEV(file->private_data, fusd_dev); GET_FUSD_DEV(file->private_data, fusd_dev);
@ -2655,7 +2677,7 @@ invalid_dev:
} }
#ifndef HAVE_UNLOCKED_IOCTL #ifndef HAVE_UNLOCKED_IOCTL
STATIC struct file_operations fusd_fops = { static struct file_operations fusd_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.open = fusd_open, .open = fusd_open,
.read = fusd_read, .read = fusd_read,
@ -2666,7 +2688,7 @@ STATIC struct file_operations fusd_fops = {
.poll = fusd_poll, .poll = fusd_poll,
}; };
#else #else
STATIC struct file_operations fusd_fops = { static struct file_operations fusd_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.open = fusd_open, .open = fusd_open,
.read = fusd_read, .read = fusd_read,
@ -2694,7 +2716,7 @@ typedef struct fusd_status_state {
} fusd_statcontext_t; } fusd_statcontext_t;
/* open() called on /dev/fusd/status */ /* open() called on /dev/fusd/status */
STATIC int fusd_status_open(struct inode *inode, struct file *file) static int fusd_status_open(struct inode *inode, struct file *file)
{ {
int error = 0; int error = 0;
fusd_statcontext_t *fs; fusd_statcontext_t *fs;
@ -2718,7 +2740,7 @@ out:
} }
/* close on /dev/fusd_status */ /* close on /dev/fusd_status */
STATIC int fusd_status_release(struct inode *inode, struct file *file) static int fusd_status_release(struct inode *inode, struct file *file)
{ {
fusd_statcontext_t *fs = (fusd_statcontext_t *) file->private_data; fusd_statcontext_t *fs = (fusd_statcontext_t *) file->private_data;
@ -2734,10 +2756,10 @@ STATIC int fusd_status_release(struct inode *inode, struct file *file)
/* ioctl() on /dev/fusd/status */ /* ioctl() on /dev/fusd/status */
#ifndef HAVE_UNLOCKED_IOCTL #ifndef HAVE_UNLOCKED_IOCTL
STATIC int fusd_status_ioctl(struct inode *inode, struct file *file, static int fusd_status_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, unsigned long arg) unsigned int cmd, unsigned long arg)
#else #else
STATIC long fusd_status_unlocked_ioctl (struct file *file, static long fusd_status_unlocked_ioctl (struct file *file,
unsigned int cmd, unsigned long arg) unsigned int cmd, unsigned long arg)
#endif #endif
{ {
@ -2768,7 +2790,7 @@ STATIC long fusd_status_unlocked_ioctl (struct file *file,
* If there isn't at least space_needed difference between buf_size * If there isn't at least space_needed difference between buf_size
* and len, the existing contents are moved into a larger buffer. * and len, the existing contents are moved into a larger buffer.
*/ */
STATIC int maybe_expand_buffer(char **buf, int *buf_size, int len, static int maybe_expand_buffer(char **buf, int *buf_size, int len,
int space_needed) int space_needed)
{ {
if (*buf_size - len < space_needed) { if (*buf_size - len < space_needed) {
@ -2789,7 +2811,7 @@ STATIC int maybe_expand_buffer(char **buf, int *buf_size, int len,
} }
/* Build a text buffer containing current fusd status. */ /* Build a text buffer containing current fusd status. */
STATIC void fusd_status_build_text(fusd_statcontext_t *fs) static void fusd_status_build_text(fusd_statcontext_t *fs)
{ {
int buf_size = 512; int buf_size = 512;
char *buf = KMALLOC(buf_size, GFP_KERNEL); char *buf = KMALLOC(buf_size, GFP_KERNEL);
@ -2827,7 +2849,8 @@ STATIC void fusd_status_build_text(fusd_statcontext_t *fs)
} }
len += snprintf(buf + len, buf_size - len, len += snprintf(buf + len, buf_size - len,
"\nFUSD $Id:$ - %d devices used by %d clients\n", "\nFUSD %s - %d devices used by %d clients\n",
GIT_DESCRIBE,
total_files, total_clients); total_files, total_clients);
out: out:
@ -2843,7 +2866,7 @@ out:
} }
/* Build the binary version of status */ /* Build the binary version of status */
STATIC void fusd_status_build_binary(fusd_statcontext_t *fs) static void fusd_status_build_binary(fusd_statcontext_t *fs)
{ {
int buf_size = 512; int buf_size = 512;
char *buf = KMALLOC(buf_size, GFP_KERNEL); char *buf = KMALLOC(buf_size, GFP_KERNEL);
@ -2894,7 +2917,7 @@ out:
fs->need_new_status = 0; fs->need_new_status = 0;
} }
STATIC ssize_t fusd_status_read(struct file *file, static ssize_t fusd_status_read(struct file *file,
char *user_buffer, /* The buffer to fill with data */ char *user_buffer, /* The buffer to fill with data */
size_t user_length, /* The length of the buffer */ size_t user_length, /* The length of the buffer */
loff_t *offset) /* Our offset in the file */ loff_t *offset) /* Our offset in the file */
@ -2937,7 +2960,7 @@ STATIC ssize_t fusd_status_read(struct file *file,
} }
/* a poll on /dev/fusd itself (the control channel) */ /* a poll on /dev/fusd itself (the control channel) */
STATIC unsigned int fusd_status_poll(struct file *file, poll_table *wait) static unsigned int fusd_status_poll(struct file *file, poll_table *wait)
{ {
fusd_statcontext_t *fs = (fusd_statcontext_t *) file->private_data; fusd_statcontext_t *fs = (fusd_statcontext_t *) file->private_data;
@ -2950,7 +2973,7 @@ STATIC unsigned int fusd_status_poll(struct file *file, poll_table *wait)
} }
#ifndef HAVE_UNLOCKED_IOCTL #ifndef HAVE_UNLOCKED_IOCTL
STATIC struct file_operations fusd_status_fops = { static struct file_operations fusd_status_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.open = fusd_status_open, .open = fusd_status_open,
.ioctl = fusd_status_ioctl, .ioctl = fusd_status_ioctl,
@ -2959,7 +2982,7 @@ STATIC struct file_operations fusd_status_fops = {
.poll = fusd_status_poll, .poll = fusd_status_poll,
}; };
#else #else
STATIC struct file_operations fusd_status_fops = { static struct file_operations fusd_status_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.open = fusd_status_open, .open = fusd_status_open,
.unlocked_ioctl = fusd_status_unlocked_ioctl, .unlocked_ioctl = fusd_status_unlocked_ioctl,
@ -2972,7 +2995,7 @@ STATIC struct file_operations fusd_status_fops = {
/*************************************************************************/ /*************************************************************************/
STATIC int init_fusd(void) static int init_fusd(void)
{ {
int retval; int retval;
@ -3083,7 +3106,7 @@ fail0:
return retval; return retval;
} }
STATIC void cleanup_fusd(void) static void cleanup_fusd(void)
{ {
RDEBUG(1, "cleaning up"); RDEBUG(1, "cleaning up");

View File

@ -1,6 +1,7 @@
SRC = libfusd.c SRC = libfusd.c
OBJ = libfusd.o OBJ = libfusd.o
TARGETS = libfusd.a libfusd.so.0.0 TARGETS = libfusd.a libfusd.so.0.0
GIT_DESCRIBE = $(shell git describe --dirty --tags)
default: $(TARGETS) default: $(TARGETS)
@ -15,7 +16,7 @@ clean:
rm -f *.o *.so *.so.* *.a *.d *.d.* gmon.out *~ rm -f *.o *.so *.so.* *.a *.d *.d.* gmon.out *~
$(TARGETS): $(TARGETS):
$(MAKE) target CFLAGS='-g -O2 $(SCF) $(GCF)' $(MAKE) target CFLAGS='-g -O2 $(SCF) $(GCF) -DGIT_DESCRIBE=\"${GIT_DESCRIBE}\"'
target: $(OBJ) target: $(OBJ)
$(LD) $(OBJ) $(SOLDFLAGS) -o libfusd.so.0.0 $(SLF) $(LD) $(OBJ) $(SOLDFLAGS) -o libfusd.so.0.0 $(SLF)

View File

@ -35,10 +35,9 @@
* *
* authors: jelson and girod * 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 <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -504,8 +503,8 @@ static int fusd_dispatch_one(int fd, fusd_file_operations_t *fops)
//printf("FUSD_MMAP\n"); //printf("FUSD_MMAP\n");
if (fops && fops->mmap) if (fops && fops->mmap)
{ {
user_retval = fops->mmap(file, msg->parm.fops_msg.offset, msg->parm.fops_msg.length, msg->parm.fops_msg.flags, user_retval = fops->mmap(file, msg->parm.fops_msg.mmoffset, msg->parm.fops_msg.length, msg->parm.fops_msg.mmprot,
&msg->parm.fops_msg.arg.ptr_arg, &msg->parm.fops_msg.length); msg->parm.fops_msg.mmflags, &msg->parm.fops_msg.arg.ptr_arg, &msg->parm.fops_msg.length);
} }
break; break;