~ubuntu-branches/ubuntu/jaunty/fuse/jaunty-security

« back to all changes in this revision

Viewing changes to example/null.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2008-01-29 10:38:39 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20080129103839-kmz63d04pnttuuoc
Tags: 2.7.2-1ubuntu1
* Resynchronise with Debian. Remaining changes:
  - Don't install the init script; install the udev rule and the module
    configuration file instead.
  - debian/45-fuse.rules: set /dev/fuse group to fuse.
  - debian/fuse-utils.modprobe: module configuration file that mounts the
    control filesystem when fuse is loaded and unmounts it when fuse is
    unloaded, along with checking that the control FS is mounting before
    unmounting it.
  - debian/fuse-utils.install: add the udev rule, the module configuration
    file, and ulockmgr_server.
  - Load fuse on install, and set it so it gets loaded on reboot.
  - Move fusermount and ulockmgr_server to /bin and associated libraries
    to /lib.
  - Create libfuse2-udeb and fuse-utils-udeb.
  - Copy /sbin/mount.fuse and the fuse kernel module into the initramfs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
    FUSE: Filesystem in Userspace
3
 
    Copyright (C) 2001-2007  Miklos Szeredi <miklos@szeredi.hu>
4
 
 
5
 
    This program can be distributed under the terms of the GNU GPL.
6
 
    See the file COPYING.
7
 
 
8
 
    gcc -Wall `pkg-config fuse --cflags --libs` null.c -o null
 
2
  FUSE: Filesystem in Userspace
 
3
  Copyright (C) 2001-2007  Miklos Szeredi <miklos@szeredi.hu>
 
4
 
 
5
  This program can be distributed under the terms of the GNU GPL.
 
6
  See the file COPYING.
 
7
 
 
8
  gcc -Wall `pkg-config fuse --cflags --libs` null.c -o null
9
9
*/
10
10
 
11
11
#define FUSE_USE_VERSION 26
18
18
 
19
19
static int null_getattr(const char *path, struct stat *stbuf)
20
20
{
21
 
    if(strcmp(path, "/") != 0)
22
 
        return -ENOENT;
23
 
 
24
 
    stbuf->st_mode = S_IFREG | 0644;
25
 
    stbuf->st_nlink = 1;
26
 
    stbuf->st_uid = getuid();
27
 
    stbuf->st_gid = getgid();
28
 
    stbuf->st_size = (1ULL << 32); /* 4G */
29
 
    stbuf->st_blocks = 0;
30
 
    stbuf->st_atime = stbuf->st_mtime = stbuf->st_ctime = time(NULL);
31
 
 
32
 
    return 0;
 
21
        if(strcmp(path, "/") != 0)
 
22
                return -ENOENT;
 
23
 
 
24
        stbuf->st_mode = S_IFREG | 0644;
 
25
        stbuf->st_nlink = 1;
 
26
        stbuf->st_uid = getuid();
 
27
        stbuf->st_gid = getgid();
 
28
        stbuf->st_size = (1ULL << 32); /* 4G */
 
29
        stbuf->st_blocks = 0;
 
30
        stbuf->st_atime = stbuf->st_mtime = stbuf->st_ctime = time(NULL);
 
31
 
 
32
        return 0;
33
33
}
34
34
 
35
35
static int null_truncate(const char *path, off_t size)
36
36
{
37
 
    (void) size;
38
 
 
39
 
    if(strcmp(path, "/") != 0)
40
 
        return -ENOENT;
41
 
 
42
 
    return 0;
 
37
        (void) size;
 
38
 
 
39
        if(strcmp(path, "/") != 0)
 
40
                return -ENOENT;
 
41
 
 
42
        return 0;
43
43
}
44
44
 
45
45
static int null_open(const char *path, struct fuse_file_info *fi)
46
46
{
47
 
    (void) fi;
48
 
 
49
 
    if(strcmp(path, "/") != 0)
50
 
        return -ENOENT;
51
 
 
52
 
    return 0;
 
47
        (void) fi;
 
48
 
 
49
        if(strcmp(path, "/") != 0)
 
50
                return -ENOENT;
 
51
 
 
52
        return 0;
53
53
}
54
54
 
55
55
static int null_read(const char *path, char *buf, size_t size,
56
 
                     off_t offset, struct fuse_file_info *fi)
 
56
                     off_t offset, struct fuse_file_info *fi)
57
57
{
58
 
    (void) buf;
59
 
    (void) offset;
60
 
    (void) fi;
61
 
 
62
 
    if(strcmp(path, "/") != 0)
63
 
        return -ENOENT;
64
 
 
65
 
    return size;
 
58
        (void) buf;
 
59
        (void) offset;
 
60
        (void) fi;
 
61
 
 
62
        if(strcmp(path, "/") != 0)
 
63
                return -ENOENT;
 
64
 
 
65
        return size;
66
66
}
67
67
 
68
68
static int null_write(const char *path, const char *buf, size_t size,
69
 
                     off_t offset, struct fuse_file_info *fi)
 
69
                      off_t offset, struct fuse_file_info *fi)
70
70
{
71
 
    (void) buf;
72
 
    (void) offset;
73
 
    (void) fi;
74
 
 
75
 
    if(strcmp(path, "/") != 0)
76
 
        return -ENOENT;
77
 
 
78
 
    return size;
 
71
        (void) buf;
 
72
        (void) offset;
 
73
        (void) fi;
 
74
 
 
75
        if(strcmp(path, "/") != 0)
 
76
                return -ENOENT;
 
77
 
 
78
        return size;
79
79
}
80
80
 
81
81
static struct fuse_operations null_oper = {
82
 
    .getattr    = null_getattr,
83
 
    .truncate   = null_truncate,
84
 
    .open       = null_open,
85
 
    .read       = null_read,
86
 
    .write      = null_write,
 
82
        .getattr        = null_getattr,
 
83
        .truncate       = null_truncate,
 
84
        .open           = null_open,
 
85
        .read           = null_read,
 
86
        .write          = null_write,
87
87
};
88
88
 
89
89
int main(int argc, char *argv[])
90
90
{
91
 
    return fuse_main(argc, argv, &null_oper, NULL);
 
91
        return fuse_main(argc, argv, &null_oper, NULL);
92
92
}