File: kml.c

package info (click to toggle)
kernel-image-2.4.18-hppa 62.3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 156,012 kB
  • ctags: 448,723
  • sloc: ansic: 2,586,445; asm: 145,047; makefile: 8,574; sh: 3,097; perl: 2,578; yacc: 1,177; tcl: 577; lex: 352; awk: 251; lisp: 218; sed: 72
file content (199 lines) | stat: -rw-r--r-- 6,180 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#include <linux/errno.h>
#include <linux/slab.h>
#include <linux/vmalloc.h>
#define __NO_VERSION__
#include <linux/module.h>
#include <asm/uaccess.h>

#include <linux/intermezzo_fs.h>
#include <linux/intermezzo_upcall.h>
#include <linux/intermezzo_psdev.h>
#include <linux/intermezzo_kml.h>

static struct presto_file_set * kml_getfset (char *path)
{
        return presto_path2fileset(path);
}

/* Send the KML buffer and related volume info into kernel */
int begin_kml_reint (struct file *file, unsigned long arg)
{
        struct {
                char *volname;
                int   namelen;  
                char *recbuf;
                int   reclen;     /* int   newpos; */
        } input;
        struct kml_fsdata *kml_fsdata = NULL;
        struct presto_file_set *fset = NULL;
        char   *path;
        int    error;

        ENTRY;
        /* allocate buffer & copy it to kernel space */
        error = copy_from_user(&input, (char *)arg, sizeof(input));
        if ( error ) {
                EXIT;
                return error;
        }

        if (input.reclen > kml_fsdata->kml_maxsize)
                return -ENOMEM; /* we'll find solution to this in the future */

        PRESTO_ALLOC(path, char *, input.namelen + 1);
        if ( !path ) {
                EXIT;
                return -ENOMEM;
        }
        error = copy_from_user(path, input.volname, input.namelen);
        if ( error ) {
                PRESTO_FREE(path, input.namelen + 1);
                EXIT;
                return error;
        }
        path[input.namelen] = '\0';
        fset = kml_getfset (path);
        PRESTO_FREE(path, input.namelen + 1);

        kml_fsdata = FSET_GET_KMLDATA(fset);
        /* read the buf from user memory here */
        error = copy_from_user(kml_fsdata->kml_buf, input.recbuf, input.reclen);
        if ( error ) {
                EXIT;
                return error;
        }
        kml_fsdata->kml_len = input.reclen;

        decode_kmlrec (&kml_fsdata->kml_reint_cache,
                        kml_fsdata->kml_buf, kml_fsdata->kml_len);

        kml_fsdata->kml_reint_current = kml_fsdata->kml_reint_cache.next;
        kml_fsdata->kml_reintpos = 0;
        kml_fsdata->kml_count = 0;
        return 0;
}

/* DO_KML_REINT  */
int do_kml_reint (struct file *file, unsigned long arg)
{
        struct {
                char *volname;
                int   namelen;  
                char *path;
                int pathlen;
                int recno;
                int offset;
                int len;
                int generation;
                __u64 ino;
        } input;
        int error;
        char   *path;
        struct kml_rec *close_rec;
        struct kml_fsdata *kml_fsdata;
        struct presto_file_set *fset;

        ENTRY;
        error = copy_from_user(&input, (char *)arg, sizeof(input));
        if ( error ) {
                EXIT;
                return error;
        }
        PRESTO_ALLOC(path, char *, input.namelen + 1);
        if ( !path ) {
                EXIT;
                return -ENOMEM;
        }
        error = copy_from_user(path, input.volname, input.namelen);
        if ( error ) {
                PRESTO_FREE(path, input.namelen + 1);
                EXIT;
                return error;
        }
        path[input.namelen] = '\0';
        fset = kml_getfset (path);
        PRESTO_FREE(path, input.namelen + 1);

        kml_fsdata = FSET_GET_KMLDATA(fset);

        error = kml_reintbuf(kml_fsdata, 
                fset->fset_mtpt->d_name.name, 
                &close_rec);

        if (error == KML_CLOSE_BACKFETCH && close_rec != NULL) {
                struct kml_close *close = &close_rec->rec_kml.close;
                input.ino = close->ino;
                input.generation = close->generation;
                if (strlen (close->path) + 1 < input.pathlen) {
                        strcpy (input.path, close->path);
                        input.pathlen = strlen (close->path) + 1;
                        input.recno = close_rec->rec_tail.recno;
                        input.offset = close_rec->rec_kml_offset;
                        input.len = close_rec->rec_size;
                        input.generation = close->generation;
                        input.ino = close->ino;
                }
                else {
                        CDEBUG(D_KML, "KML_DO_REINT::no space to save:%d < %d",
                                strlen (close->path) + 1, input.pathlen);
                        error = -ENOMEM;
                }
                copy_to_user((char *)arg, &input, sizeof (input));
        }
        return error;
}

/* END_KML_REINT */
int end_kml_reint (struct file *file, unsigned long arg)
{
        /* Free KML buffer and related volume info */
        struct {
                char *volname;
                int   namelen;  
#if 0
                int   count; 
                int   newpos; 
#endif
        } input;
        struct presto_file_set *fset = NULL;
        struct kml_fsdata *kml_fsdata = NULL;
        int error;
        char *path;

        ENTRY;
        error = copy_from_user(&input, (char *)arg, sizeof(input));
        if ( error ) {
               EXIT;
               return error;
        }

        PRESTO_ALLOC(path, char *, input.namelen + 1);
        if ( !path ) {
                EXIT;
                return -ENOMEM;
        }
        error = copy_from_user(path, input.volname, input.namelen);
        if ( error ) {
                PRESTO_FREE(path, input.namelen + 1);
                EXIT;
                return error;
        }
        path[input.namelen] = '\0';
        fset = kml_getfset (path);
        PRESTO_FREE(path, input.namelen + 1);

        kml_fsdata = FSET_GET_KMLDATA(fset);
        delete_kmlrec (&kml_fsdata->kml_reint_cache);

        /* kml reint support */
        kml_fsdata->kml_reint_current = NULL;
        kml_fsdata->kml_len = 0;
        kml_fsdata->kml_reintpos = 0;
        kml_fsdata->kml_count = 0;
#if 0
        input.newpos = kml_upc->newpos;
        input.count = kml_upc->count;
        copy_to_user((char *)arg, &input, sizeof (input));
#endif
        return error;
}