diff options
Diffstat (limited to 'fs/hppfs/hppfs_kern.c')
-rw-r--r-- | fs/hppfs/hppfs_kern.c | 435 |
1 files changed, 201 insertions, 234 deletions
diff --git a/fs/hppfs/hppfs_kern.c b/fs/hppfs/hppfs_kern.c index a1e1f0f61aa5..8601d8ef3b55 100644 --- a/fs/hppfs/hppfs_kern.c +++ b/fs/hppfs/hppfs_kern.c | |||
@@ -1,23 +1,24 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2002 Jeff Dike (jdike@karaya.com) | 2 | * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) |
3 | * Licensed under the GPL | 3 | * Licensed under the GPL |
4 | */ | 4 | */ |
5 | 5 | ||
6 | #include <linux/fs.h> | 6 | #include <linux/ctype.h> |
7 | #include <linux/dcache.h> | ||
7 | #include <linux/file.h> | 8 | #include <linux/file.h> |
8 | #include <linux/module.h> | 9 | #include <linux/fs.h> |
9 | #include <linux/init.h> | 10 | #include <linux/init.h> |
10 | #include <linux/slab.h> | ||
11 | #include <linux/list.h> | ||
12 | #include <linux/kernel.h> | 11 | #include <linux/kernel.h> |
13 | #include <linux/ctype.h> | 12 | #include <linux/list.h> |
14 | #include <linux/dcache.h> | 13 | #include <linux/module.h> |
14 | #include <linux/mount.h> | ||
15 | #include <linux/slab.h> | ||
15 | #include <linux/statfs.h> | 16 | #include <linux/statfs.h> |
17 | #include <linux/types.h> | ||
16 | #include <asm/uaccess.h> | 18 | #include <asm/uaccess.h> |
17 | #include <asm/fcntl.h> | ||
18 | #include "os.h" | 19 | #include "os.h" |
19 | 20 | ||
20 | static int init_inode(struct inode *inode, struct dentry *dentry); | 21 | static struct inode *get_inode(struct super_block *, struct dentry *); |
21 | 22 | ||
22 | struct hppfs_data { | 23 | struct hppfs_data { |
23 | struct list_head list; | 24 | struct list_head list; |
@@ -51,14 +52,14 @@ static int is_pid(struct dentry *dentry) | |||
51 | int i; | 52 | int i; |
52 | 53 | ||
53 | sb = dentry->d_sb; | 54 | sb = dentry->d_sb; |
54 | if((sb->s_op != &hppfs_sbops) || (dentry->d_parent != sb->s_root)) | 55 | if ((sb->s_op != &hppfs_sbops) || (dentry->d_parent != sb->s_root)) |
55 | return(0); | 56 | return 0; |
56 | 57 | ||
57 | for(i = 0; i < dentry->d_name.len; i++){ | 58 | for (i = 0; i < dentry->d_name.len; i++) { |
58 | if(!isdigit(dentry->d_name.name[i])) | 59 | if (!isdigit(dentry->d_name.name[i])) |
59 | return(0); | 60 | return 0; |
60 | } | 61 | } |
61 | return(1); | 62 | return 1; |
62 | } | 63 | } |
63 | 64 | ||
64 | static char *dentry_name(struct dentry *dentry, int extra) | 65 | static char *dentry_name(struct dentry *dentry, int extra) |
@@ -70,8 +71,8 @@ static char *dentry_name(struct dentry *dentry, int extra) | |||
70 | 71 | ||
71 | len = 0; | 72 | len = 0; |
72 | parent = dentry; | 73 | parent = dentry; |
73 | while(parent->d_parent != parent){ | 74 | while (parent->d_parent != parent) { |
74 | if(is_pid(parent)) | 75 | if (is_pid(parent)) |
75 | len += strlen("pid") + 1; | 76 | len += strlen("pid") + 1; |
76 | else len += parent->d_name.len + 1; | 77 | else len += parent->d_name.len + 1; |
77 | parent = parent->d_parent; | 78 | parent = parent->d_parent; |
@@ -80,12 +81,13 @@ static char *dentry_name(struct dentry *dentry, int extra) | |||
80 | root = "proc"; | 81 | root = "proc"; |
81 | len += strlen(root); | 82 | len += strlen(root); |
82 | name = kmalloc(len + extra + 1, GFP_KERNEL); | 83 | name = kmalloc(len + extra + 1, GFP_KERNEL); |
83 | if(name == NULL) return(NULL); | 84 | if (name == NULL) |
85 | return NULL; | ||
84 | 86 | ||
85 | name[len] = '\0'; | 87 | name[len] = '\0'; |
86 | parent = dentry; | 88 | parent = dentry; |
87 | while(parent->d_parent != parent){ | 89 | while (parent->d_parent != parent) { |
88 | if(is_pid(parent)){ | 90 | if (is_pid(parent)) { |
89 | seg_name = "pid"; | 91 | seg_name = "pid"; |
90 | seg_len = strlen("pid"); | 92 | seg_len = strlen("pid"); |
91 | } | 93 | } |
@@ -100,27 +102,25 @@ static char *dentry_name(struct dentry *dentry, int extra) | |||
100 | parent = parent->d_parent; | 102 | parent = parent->d_parent; |
101 | } | 103 | } |
102 | strncpy(name, root, strlen(root)); | 104 | strncpy(name, root, strlen(root)); |
103 | return(name); | 105 | return name; |
104 | } | 106 | } |
105 | 107 | ||
106 | struct dentry_operations hppfs_dentry_ops = { | ||
107 | }; | ||
108 | |||
109 | static int file_removed(struct dentry *dentry, const char *file) | 108 | static int file_removed(struct dentry *dentry, const char *file) |
110 | { | 109 | { |
111 | char *host_file; | 110 | char *host_file; |
112 | int extra, fd; | 111 | int extra, fd; |
113 | 112 | ||
114 | extra = 0; | 113 | extra = 0; |
115 | if(file != NULL) extra += strlen(file) + 1; | 114 | if (file != NULL) |
115 | extra += strlen(file) + 1; | ||
116 | 116 | ||
117 | host_file = dentry_name(dentry, extra + strlen("/remove")); | 117 | host_file = dentry_name(dentry, extra + strlen("/remove")); |
118 | if(host_file == NULL){ | 118 | if (host_file == NULL) { |
119 | printk("file_removed : allocation failed\n"); | 119 | printk(KERN_ERR "file_removed : allocation failed\n"); |
120 | return(-ENOMEM); | 120 | return -ENOMEM; |
121 | } | 121 | } |
122 | 122 | ||
123 | if(file != NULL){ | 123 | if (file != NULL) { |
124 | strcat(host_file, "/"); | 124 | strcat(host_file, "/"); |
125 | strcat(host_file, file); | 125 | strcat(host_file, file); |
126 | } | 126 | } |
@@ -128,45 +128,11 @@ static int file_removed(struct dentry *dentry, const char *file) | |||
128 | 128 | ||
129 | fd = os_open_file(host_file, of_read(OPENFLAGS()), 0); | 129 | fd = os_open_file(host_file, of_read(OPENFLAGS()), 0); |
130 | kfree(host_file); | 130 | kfree(host_file); |
131 | if(fd > 0){ | 131 | if (fd > 0) { |
132 | os_close_file(fd); | 132 | os_close_file(fd); |
133 | return(1); | 133 | return 1; |
134 | } | ||
135 | return(0); | ||
136 | } | ||
137 | |||
138 | static void hppfs_read_inode(struct inode *ino) | ||
139 | { | ||
140 | struct inode *proc_ino; | ||
141 | |||
142 | if(HPPFS_I(ino)->proc_dentry == NULL) | ||
143 | return; | ||
144 | |||
145 | proc_ino = HPPFS_I(ino)->proc_dentry->d_inode; | ||
146 | ino->i_uid = proc_ino->i_uid; | ||
147 | ino->i_gid = proc_ino->i_gid; | ||
148 | ino->i_atime = proc_ino->i_atime; | ||
149 | ino->i_mtime = proc_ino->i_mtime; | ||
150 | ino->i_ctime = proc_ino->i_ctime; | ||
151 | ino->i_ino = proc_ino->i_ino; | ||
152 | ino->i_mode = proc_ino->i_mode; | ||
153 | ino->i_nlink = proc_ino->i_nlink; | ||
154 | ino->i_size = proc_ino->i_size; | ||
155 | ino->i_blocks = proc_ino->i_blocks; | ||
156 | } | ||
157 | |||
158 | static struct inode *hppfs_iget(struct super_block *sb) | ||
159 | { | ||
160 | struct inode *inode; | ||
161 | |||
162 | inode = iget_locked(sb, 0); | ||
163 | if (!inode) | ||
164 | return ERR_PTR(-ENOMEM); | ||
165 | if (inode->i_state & I_NEW) { | ||
166 | hppfs_read_inode(inode); | ||
167 | unlock_new_inode(inode); | ||
168 | } | 134 | } |
169 | return inode; | 135 | return 0; |
170 | } | 136 | } |
171 | 137 | ||
172 | static struct dentry *hppfs_lookup(struct inode *ino, struct dentry *dentry, | 138 | static struct dentry *hppfs_lookup(struct inode *ino, struct dentry *dentry, |
@@ -177,55 +143,45 @@ static struct dentry *hppfs_lookup(struct inode *ino, struct dentry *dentry, | |||
177 | int err, deleted; | 143 | int err, deleted; |
178 | 144 | ||
179 | deleted = file_removed(dentry, NULL); | 145 | deleted = file_removed(dentry, NULL); |
180 | if(deleted < 0) | 146 | if (deleted < 0) |
181 | return(ERR_PTR(deleted)); | 147 | return ERR_PTR(deleted); |
182 | else if(deleted) | 148 | else if (deleted) |
183 | return(ERR_PTR(-ENOENT)); | 149 | return ERR_PTR(-ENOENT); |
184 | 150 | ||
185 | err = -ENOMEM; | 151 | err = -ENOMEM; |
186 | parent = HPPFS_I(ino)->proc_dentry; | 152 | parent = HPPFS_I(ino)->proc_dentry; |
187 | mutex_lock(&parent->d_inode->i_mutex); | 153 | mutex_lock(&parent->d_inode->i_mutex); |
188 | proc_dentry = d_lookup(parent, &dentry->d_name); | 154 | proc_dentry = d_lookup(parent, &dentry->d_name); |
189 | if(proc_dentry == NULL){ | 155 | if (proc_dentry == NULL) { |
190 | proc_dentry = d_alloc(parent, &dentry->d_name); | 156 | proc_dentry = d_alloc(parent, &dentry->d_name); |
191 | if(proc_dentry == NULL){ | 157 | if (proc_dentry == NULL) { |
192 | mutex_unlock(&parent->d_inode->i_mutex); | 158 | mutex_unlock(&parent->d_inode->i_mutex); |
193 | goto out; | 159 | goto out; |
194 | } | 160 | } |
195 | new = (*parent->d_inode->i_op->lookup)(parent->d_inode, | 161 | new = (*parent->d_inode->i_op->lookup)(parent->d_inode, |
196 | proc_dentry, NULL); | 162 | proc_dentry, NULL); |
197 | if(new){ | 163 | if (new) { |
198 | dput(proc_dentry); | 164 | dput(proc_dentry); |
199 | proc_dentry = new; | 165 | proc_dentry = new; |
200 | } | 166 | } |
201 | } | 167 | } |
202 | mutex_unlock(&parent->d_inode->i_mutex); | 168 | mutex_unlock(&parent->d_inode->i_mutex); |
203 | 169 | ||
204 | if(IS_ERR(proc_dentry)) | 170 | if (IS_ERR(proc_dentry)) |
205 | return(proc_dentry); | 171 | return proc_dentry; |
206 | 172 | ||
207 | inode = hppfs_iget(ino->i_sb); | 173 | err = -ENOMEM; |
208 | if (IS_ERR(inode)) { | 174 | inode = get_inode(ino->i_sb, proc_dentry); |
209 | err = PTR_ERR(inode); | 175 | if (!inode) |
210 | goto out_dput; | 176 | goto out_dput; |
211 | } | ||
212 | |||
213 | err = init_inode(inode, proc_dentry); | ||
214 | if(err) | ||
215 | goto out_put; | ||
216 | |||
217 | hppfs_read_inode(inode); | ||
218 | 177 | ||
219 | d_add(dentry, inode); | 178 | d_add(dentry, inode); |
220 | dentry->d_op = &hppfs_dentry_ops; | 179 | return NULL; |
221 | return(NULL); | ||
222 | 180 | ||
223 | out_put: | ||
224 | iput(inode); | ||
225 | out_dput: | 181 | out_dput: |
226 | dput(proc_dentry); | 182 | dput(proc_dentry); |
227 | out: | 183 | out: |
228 | return(ERR_PTR(err)); | 184 | return ERR_PTR(err); |
229 | } | 185 | } |
230 | 186 | ||
231 | static const struct inode_operations hppfs_file_iops = { | 187 | static const struct inode_operations hppfs_file_iops = { |
@@ -239,15 +195,16 @@ static ssize_t read_proc(struct file *file, char __user *buf, ssize_t count, | |||
239 | 195 | ||
240 | read = file->f_path.dentry->d_inode->i_fop->read; | 196 | read = file->f_path.dentry->d_inode->i_fop->read; |
241 | 197 | ||
242 | if(!is_user) | 198 | if (!is_user) |
243 | set_fs(KERNEL_DS); | 199 | set_fs(KERNEL_DS); |
244 | 200 | ||
245 | n = (*read)(file, buf, count, &file->f_pos); | 201 | n = (*read)(file, buf, count, &file->f_pos); |
246 | 202 | ||
247 | if(!is_user) | 203 | if (!is_user) |
248 | set_fs(USER_DS); | 204 | set_fs(USER_DS); |
249 | 205 | ||
250 | if(ppos) *ppos = file->f_pos; | 206 | if (ppos) |
207 | *ppos = file->f_pos; | ||
251 | return n; | 208 | return n; |
252 | } | 209 | } |
253 | 210 | ||
@@ -259,24 +216,23 @@ static ssize_t hppfs_read_file(int fd, char __user *buf, ssize_t count) | |||
259 | 216 | ||
260 | n = -ENOMEM; | 217 | n = -ENOMEM; |
261 | new_buf = kmalloc(PAGE_SIZE, GFP_KERNEL); | 218 | new_buf = kmalloc(PAGE_SIZE, GFP_KERNEL); |
262 | if(new_buf == NULL){ | 219 | if (new_buf == NULL) { |
263 | printk("hppfs_read_file : kmalloc failed\n"); | 220 | printk(KERN_ERR "hppfs_read_file : kmalloc failed\n"); |
264 | goto out; | 221 | goto out; |
265 | } | 222 | } |
266 | n = 0; | 223 | n = 0; |
267 | while(count > 0){ | 224 | while (count > 0) { |
268 | cur = min_t(ssize_t, count, PAGE_SIZE); | 225 | cur = min_t(ssize_t, count, PAGE_SIZE); |
269 | err = os_read_file(fd, new_buf, cur); | 226 | err = os_read_file(fd, new_buf, cur); |
270 | if(err < 0){ | 227 | if (err < 0) { |
271 | printk("hppfs_read : read failed, errno = %d\n", | 228 | printk(KERN_ERR "hppfs_read : read failed, " |
272 | err); | 229 | "errno = %d\n", err); |
273 | n = err; | 230 | n = err; |
274 | goto out_free; | 231 | goto out_free; |
275 | } | 232 | } else if (err == 0) |
276 | else if(err == 0) | ||
277 | break; | 233 | break; |
278 | 234 | ||
279 | if(copy_to_user(buf, new_buf, err)){ | 235 | if (copy_to_user(buf, new_buf, err)) { |
280 | n = -EFAULT; | 236 | n = -EFAULT; |
281 | goto out_free; | 237 | goto out_free; |
282 | } | 238 | } |
@@ -297,35 +253,36 @@ static ssize_t hppfs_read(struct file *file, char __user *buf, size_t count, | |||
297 | loff_t off; | 253 | loff_t off; |
298 | int err; | 254 | int err; |
299 | 255 | ||
300 | if(hppfs->contents != NULL){ | 256 | if (hppfs->contents != NULL) { |
301 | if(*ppos >= hppfs->len) return(0); | 257 | if (*ppos >= hppfs->len) |
258 | return 0; | ||
302 | 259 | ||
303 | data = hppfs->contents; | 260 | data = hppfs->contents; |
304 | off = *ppos; | 261 | off = *ppos; |
305 | while(off >= sizeof(data->contents)){ | 262 | while (off >= sizeof(data->contents)) { |
306 | data = list_entry(data->list.next, struct hppfs_data, | 263 | data = list_entry(data->list.next, struct hppfs_data, |
307 | list); | 264 | list); |
308 | off -= sizeof(data->contents); | 265 | off -= sizeof(data->contents); |
309 | } | 266 | } |
310 | 267 | ||
311 | if(off + count > hppfs->len) | 268 | if (off + count > hppfs->len) |
312 | count = hppfs->len - off; | 269 | count = hppfs->len - off; |
313 | copy_to_user(buf, &data->contents[off], count); | 270 | copy_to_user(buf, &data->contents[off], count); |
314 | *ppos += count; | 271 | *ppos += count; |
315 | } | 272 | } else if (hppfs->host_fd != -1) { |
316 | else if(hppfs->host_fd != -1){ | ||
317 | err = os_seek_file(hppfs->host_fd, *ppos); | 273 | err = os_seek_file(hppfs->host_fd, *ppos); |
318 | if(err){ | 274 | if (err) { |
319 | printk("hppfs_read : seek failed, errno = %d\n", err); | 275 | printk(KERN_ERR "hppfs_read : seek failed, " |
320 | return(err); | 276 | "errno = %d\n", err); |
277 | return err; | ||
321 | } | 278 | } |
322 | count = hppfs_read_file(hppfs->host_fd, buf, count); | 279 | count = hppfs_read_file(hppfs->host_fd, buf, count); |
323 | if(count > 0) | 280 | if (count > 0) |
324 | *ppos += count; | 281 | *ppos += count; |
325 | } | 282 | } |
326 | else count = read_proc(hppfs->proc_file, buf, count, ppos, 1); | 283 | else count = read_proc(hppfs->proc_file, buf, count, ppos, 1); |
327 | 284 | ||
328 | return(count); | 285 | return count; |
329 | } | 286 | } |
330 | 287 | ||
331 | static ssize_t hppfs_write(struct file *file, const char __user *buf, size_t len, | 288 | static ssize_t hppfs_write(struct file *file, const char __user *buf, size_t len, |
@@ -342,7 +299,7 @@ static ssize_t hppfs_write(struct file *file, const char __user *buf, size_t len | |||
342 | err = (*write)(proc_file, buf, len, &proc_file->f_pos); | 299 | err = (*write)(proc_file, buf, len, &proc_file->f_pos); |
343 | file->f_pos = proc_file->f_pos; | 300 | file->f_pos = proc_file->f_pos; |
344 | 301 | ||
345 | return(err); | 302 | return err; |
346 | } | 303 | } |
347 | 304 | ||
348 | static int open_host_sock(char *host_file, int *filter_out) | 305 | static int open_host_sock(char *host_file, int *filter_out) |
@@ -354,13 +311,13 @@ static int open_host_sock(char *host_file, int *filter_out) | |||
354 | strcpy(end, "/rw"); | 311 | strcpy(end, "/rw"); |
355 | *filter_out = 1; | 312 | *filter_out = 1; |
356 | fd = os_connect_socket(host_file); | 313 | fd = os_connect_socket(host_file); |
357 | if(fd > 0) | 314 | if (fd > 0) |
358 | return(fd); | 315 | return fd; |
359 | 316 | ||
360 | strcpy(end, "/r"); | 317 | strcpy(end, "/r"); |
361 | *filter_out = 0; | 318 | *filter_out = 0; |
362 | fd = os_connect_socket(host_file); | 319 | fd = os_connect_socket(host_file); |
363 | return(fd); | 320 | return fd; |
364 | } | 321 | } |
365 | 322 | ||
366 | static void free_contents(struct hppfs_data *head) | 323 | static void free_contents(struct hppfs_data *head) |
@@ -368,9 +325,10 @@ static void free_contents(struct hppfs_data *head) | |||
368 | struct hppfs_data *data; | 325 | struct hppfs_data *data; |
369 | struct list_head *ele, *next; | 326 | struct list_head *ele, *next; |
370 | 327 | ||
371 | if(head == NULL) return; | 328 | if (head == NULL) |
329 | return; | ||
372 | 330 | ||
373 | list_for_each_safe(ele, next, &head->list){ | 331 | list_for_each_safe(ele, next, &head->list) { |
374 | data = list_entry(ele, struct hppfs_data, list); | 332 | data = list_entry(ele, struct hppfs_data, list); |
375 | kfree(data); | 333 | kfree(data); |
376 | } | 334 | } |
@@ -387,8 +345,8 @@ static struct hppfs_data *hppfs_get_data(int fd, int filter, | |||
387 | 345 | ||
388 | err = -ENOMEM; | 346 | err = -ENOMEM; |
389 | data = kmalloc(sizeof(*data), GFP_KERNEL); | 347 | data = kmalloc(sizeof(*data), GFP_KERNEL); |
390 | if(data == NULL){ | 348 | if (data == NULL) { |
391 | printk("hppfs_get_data : head allocation failed\n"); | 349 | printk(KERN_ERR "hppfs_get_data : head allocation failed\n"); |
392 | goto failed; | 350 | goto failed; |
393 | } | 351 | } |
394 | 352 | ||
@@ -397,36 +355,36 @@ static struct hppfs_data *hppfs_get_data(int fd, int filter, | |||
397 | head = data; | 355 | head = data; |
398 | *size_out = 0; | 356 | *size_out = 0; |
399 | 357 | ||
400 | if(filter){ | 358 | if (filter) { |
401 | while((n = read_proc(proc_file, data->contents, | 359 | while ((n = read_proc(proc_file, data->contents, |
402 | sizeof(data->contents), NULL, 0)) > 0) | 360 | sizeof(data->contents), NULL, 0)) > 0) |
403 | os_write_file(fd, data->contents, n); | 361 | os_write_file(fd, data->contents, n); |
404 | err = os_shutdown_socket(fd, 0, 1); | 362 | err = os_shutdown_socket(fd, 0, 1); |
405 | if(err){ | 363 | if (err) { |
406 | printk("hppfs_get_data : failed to shut down " | 364 | printk(KERN_ERR "hppfs_get_data : failed to shut down " |
407 | "socket\n"); | 365 | "socket\n"); |
408 | goto failed_free; | 366 | goto failed_free; |
409 | } | 367 | } |
410 | } | 368 | } |
411 | while(1){ | 369 | while (1) { |
412 | n = os_read_file(fd, data->contents, sizeof(data->contents)); | 370 | n = os_read_file(fd, data->contents, sizeof(data->contents)); |
413 | if(n < 0){ | 371 | if (n < 0) { |
414 | err = n; | 372 | err = n; |
415 | printk("hppfs_get_data : read failed, errno = %d\n", | 373 | printk(KERN_ERR "hppfs_get_data : read failed, " |
416 | err); | 374 | "errno = %d\n", err); |
417 | goto failed_free; | 375 | goto failed_free; |
418 | } | 376 | } else if (n == 0) |
419 | else if(n == 0) | ||
420 | break; | 377 | break; |
421 | 378 | ||
422 | *size_out += n; | 379 | *size_out += n; |
423 | 380 | ||
424 | if(n < sizeof(data->contents)) | 381 | if (n < sizeof(data->contents)) |
425 | break; | 382 | break; |
426 | 383 | ||
427 | new = kmalloc(sizeof(*data), GFP_KERNEL); | 384 | new = kmalloc(sizeof(*data), GFP_KERNEL); |
428 | if(new == 0){ | 385 | if (new == 0) { |
429 | printk("hppfs_get_data : data allocation failed\n"); | 386 | printk(KERN_ERR "hppfs_get_data : data allocation " |
387 | "failed\n"); | ||
430 | err = -ENOMEM; | 388 | err = -ENOMEM; |
431 | goto failed_free; | 389 | goto failed_free; |
432 | } | 390 | } |
@@ -435,12 +393,12 @@ static struct hppfs_data *hppfs_get_data(int fd, int filter, | |||
435 | list_add(&new->list, &data->list); | 393 | list_add(&new->list, &data->list); |
436 | data = new; | 394 | data = new; |
437 | } | 395 | } |
438 | return(head); | 396 | return head; |
439 | 397 | ||
440 | failed_free: | 398 | failed_free: |
441 | free_contents(head); | 399 | free_contents(head); |
442 | failed: | 400 | failed: |
443 | return(ERR_PTR(err)); | 401 | return ERR_PTR(err); |
444 | } | 402 | } |
445 | 403 | ||
446 | static struct hppfs_private *hppfs_data(void) | 404 | static struct hppfs_private *hppfs_data(void) |
@@ -448,77 +406,79 @@ static struct hppfs_private *hppfs_data(void) | |||
448 | struct hppfs_private *data; | 406 | struct hppfs_private *data; |
449 | 407 | ||
450 | data = kmalloc(sizeof(*data), GFP_KERNEL); | 408 | data = kmalloc(sizeof(*data), GFP_KERNEL); |
451 | if(data == NULL) | 409 | if (data == NULL) |
452 | return(data); | 410 | return data; |
453 | 411 | ||
454 | *data = ((struct hppfs_private ) { .host_fd = -1, | 412 | *data = ((struct hppfs_private ) { .host_fd = -1, |
455 | .len = -1, | 413 | .len = -1, |
456 | .contents = NULL } ); | 414 | .contents = NULL } ); |
457 | return(data); | 415 | return data; |
458 | } | 416 | } |
459 | 417 | ||
460 | static int file_mode(int fmode) | 418 | static int file_mode(int fmode) |
461 | { | 419 | { |
462 | if(fmode == (FMODE_READ | FMODE_WRITE)) | 420 | if (fmode == (FMODE_READ | FMODE_WRITE)) |
463 | return(O_RDWR); | 421 | return O_RDWR; |
464 | if(fmode == FMODE_READ) | 422 | if (fmode == FMODE_READ) |
465 | return(O_RDONLY); | 423 | return O_RDONLY; |
466 | if(fmode == FMODE_WRITE) | 424 | if (fmode == FMODE_WRITE) |
467 | return(O_WRONLY); | 425 | return O_WRONLY; |
468 | return(0); | 426 | return 0; |
469 | } | 427 | } |
470 | 428 | ||
471 | static int hppfs_open(struct inode *inode, struct file *file) | 429 | static int hppfs_open(struct inode *inode, struct file *file) |
472 | { | 430 | { |
473 | struct hppfs_private *data; | 431 | struct hppfs_private *data; |
474 | struct dentry *proc_dentry; | 432 | struct dentry *proc_dentry; |
433 | struct vfsmount *proc_mnt; | ||
475 | char *host_file; | 434 | char *host_file; |
476 | int err, fd, type, filter; | 435 | int err, fd, type, filter; |
477 | 436 | ||
478 | err = -ENOMEM; | 437 | err = -ENOMEM; |
479 | data = hppfs_data(); | 438 | data = hppfs_data(); |
480 | if(data == NULL) | 439 | if (data == NULL) |
481 | goto out; | 440 | goto out; |
482 | 441 | ||
483 | host_file = dentry_name(file->f_path.dentry, strlen("/rw")); | 442 | host_file = dentry_name(file->f_path.dentry, strlen("/rw")); |
484 | if(host_file == NULL) | 443 | if (host_file == NULL) |
485 | goto out_free2; | 444 | goto out_free2; |
486 | 445 | ||
487 | proc_dentry = HPPFS_I(inode)->proc_dentry; | 446 | proc_dentry = HPPFS_I(inode)->proc_dentry; |
447 | proc_mnt = inode->i_sb->s_fs_info; | ||
488 | 448 | ||
489 | /* XXX This isn't closed anywhere */ | 449 | /* XXX This isn't closed anywhere */ |
490 | data->proc_file = dentry_open(dget(proc_dentry), NULL, | 450 | data->proc_file = dentry_open(dget(proc_dentry), mntget(proc_mnt), |
491 | file_mode(file->f_mode)); | 451 | file_mode(file->f_mode)); |
492 | err = PTR_ERR(data->proc_file); | 452 | err = PTR_ERR(data->proc_file); |
493 | if(IS_ERR(data->proc_file)) | 453 | if (IS_ERR(data->proc_file)) |
494 | goto out_free1; | 454 | goto out_free1; |
495 | 455 | ||
496 | type = os_file_type(host_file); | 456 | type = os_file_type(host_file); |
497 | if(type == OS_TYPE_FILE){ | 457 | if (type == OS_TYPE_FILE) { |
498 | fd = os_open_file(host_file, of_read(OPENFLAGS()), 0); | 458 | fd = os_open_file(host_file, of_read(OPENFLAGS()), 0); |
499 | if(fd >= 0) | 459 | if (fd >= 0) |
500 | data->host_fd = fd; | 460 | data->host_fd = fd; |
501 | else printk("hppfs_open : failed to open '%s', errno = %d\n", | 461 | else |
502 | host_file, -fd); | 462 | printk(KERN_ERR "hppfs_open : failed to open '%s', " |
463 | "errno = %d\n", host_file, -fd); | ||
503 | 464 | ||
504 | data->contents = NULL; | 465 | data->contents = NULL; |
505 | } | 466 | } else if (type == OS_TYPE_DIR) { |
506 | else if(type == OS_TYPE_DIR){ | ||
507 | fd = open_host_sock(host_file, &filter); | 467 | fd = open_host_sock(host_file, &filter); |
508 | if(fd > 0){ | 468 | if (fd > 0) { |
509 | data->contents = hppfs_get_data(fd, filter, | 469 | data->contents = hppfs_get_data(fd, filter, |
510 | data->proc_file, | 470 | data->proc_file, |
511 | file, &data->len); | 471 | file, &data->len); |
512 | if(!IS_ERR(data->contents)) | 472 | if (!IS_ERR(data->contents)) |
513 | data->host_fd = fd; | 473 | data->host_fd = fd; |
514 | } | 474 | } else |
515 | else printk("hppfs_open : failed to open a socket in " | 475 | printk(KERN_ERR "hppfs_open : failed to open a socket " |
516 | "'%s', errno = %d\n", host_file, -fd); | 476 | "in '%s', errno = %d\n", host_file, -fd); |
517 | } | 477 | } |
518 | kfree(host_file); | 478 | kfree(host_file); |
519 | 479 | ||
520 | file->private_data = data; | 480 | file->private_data = data; |
521 | return(0); | 481 | return 0; |
522 | 482 | ||
523 | out_free1: | 483 | out_free1: |
524 | kfree(host_file); | 484 | kfree(host_file); |
@@ -526,34 +486,36 @@ static int hppfs_open(struct inode *inode, struct file *file) | |||
526 | free_contents(data->contents); | 486 | free_contents(data->contents); |
527 | kfree(data); | 487 | kfree(data); |
528 | out: | 488 | out: |
529 | return(err); | 489 | return err; |
530 | } | 490 | } |
531 | 491 | ||
532 | static int hppfs_dir_open(struct inode *inode, struct file *file) | 492 | static int hppfs_dir_open(struct inode *inode, struct file *file) |
533 | { | 493 | { |
534 | struct hppfs_private *data; | 494 | struct hppfs_private *data; |
535 | struct dentry *proc_dentry; | 495 | struct dentry *proc_dentry; |
496 | struct vfsmount *proc_mnt; | ||
536 | int err; | 497 | int err; |
537 | 498 | ||
538 | err = -ENOMEM; | 499 | err = -ENOMEM; |
539 | data = hppfs_data(); | 500 | data = hppfs_data(); |
540 | if(data == NULL) | 501 | if (data == NULL) |
541 | goto out; | 502 | goto out; |
542 | 503 | ||
543 | proc_dentry = HPPFS_I(inode)->proc_dentry; | 504 | proc_dentry = HPPFS_I(inode)->proc_dentry; |
544 | data->proc_file = dentry_open(dget(proc_dentry), NULL, | 505 | proc_mnt = inode->i_sb->s_fs_info; |
506 | data->proc_file = dentry_open(dget(proc_dentry), mntget(proc_mnt), | ||
545 | file_mode(file->f_mode)); | 507 | file_mode(file->f_mode)); |
546 | err = PTR_ERR(data->proc_file); | 508 | err = PTR_ERR(data->proc_file); |
547 | if(IS_ERR(data->proc_file)) | 509 | if (IS_ERR(data->proc_file)) |
548 | goto out_free; | 510 | goto out_free; |
549 | 511 | ||
550 | file->private_data = data; | 512 | file->private_data = data; |
551 | return(0); | 513 | return 0; |
552 | 514 | ||
553 | out_free: | 515 | out_free: |
554 | kfree(data); | 516 | kfree(data); |
555 | out: | 517 | out: |
556 | return(err); | 518 | return err; |
557 | } | 519 | } |
558 | 520 | ||
559 | static loff_t hppfs_llseek(struct file *file, loff_t off, int where) | 521 | static loff_t hppfs_llseek(struct file *file, loff_t off, int where) |
@@ -564,13 +526,13 @@ static loff_t hppfs_llseek(struct file *file, loff_t off, int where) | |||
564 | loff_t ret; | 526 | loff_t ret; |
565 | 527 | ||
566 | llseek = proc_file->f_path.dentry->d_inode->i_fop->llseek; | 528 | llseek = proc_file->f_path.dentry->d_inode->i_fop->llseek; |
567 | if(llseek != NULL){ | 529 | if (llseek != NULL) { |
568 | ret = (*llseek)(proc_file, off, where); | 530 | ret = (*llseek)(proc_file, off, where); |
569 | if(ret < 0) | 531 | if (ret < 0) |
570 | return(ret); | 532 | return ret; |
571 | } | 533 | } |
572 | 534 | ||
573 | return(default_llseek(file, off, where)); | 535 | return default_llseek(file, off, where); |
574 | } | 536 | } |
575 | 537 | ||
576 | static const struct file_operations hppfs_file_fops = { | 538 | static const struct file_operations hppfs_file_fops = { |
@@ -592,11 +554,11 @@ static int hppfs_filldir(void *d, const char *name, int size, | |||
592 | { | 554 | { |
593 | struct hppfs_dirent *dirent = d; | 555 | struct hppfs_dirent *dirent = d; |
594 | 556 | ||
595 | if(file_removed(dirent->dentry, name)) | 557 | if (file_removed(dirent->dentry, name)) |
596 | return(0); | 558 | return 0; |
597 | 559 | ||
598 | return((*dirent->filldir)(dirent->vfs_dirent, name, size, offset, | 560 | return (*dirent->filldir)(dirent->vfs_dirent, name, size, offset, |
599 | inode, type)); | 561 | inode, type); |
600 | } | 562 | } |
601 | 563 | ||
602 | static int hppfs_readdir(struct file *file, void *ent, filldir_t filldir) | 564 | static int hppfs_readdir(struct file *file, void *ent, filldir_t filldir) |
@@ -607,7 +569,8 @@ static int hppfs_readdir(struct file *file, void *ent, filldir_t filldir) | |||
607 | struct hppfs_dirent dirent = ((struct hppfs_dirent) | 569 | struct hppfs_dirent dirent = ((struct hppfs_dirent) |
608 | { .vfs_dirent = ent, | 570 | { .vfs_dirent = ent, |
609 | .filldir = filldir, | 571 | .filldir = filldir, |
610 | .dentry = file->f_path.dentry } ); | 572 | .dentry = file->f_path.dentry |
573 | }); | ||
611 | int err; | 574 | int err; |
612 | 575 | ||
613 | readdir = proc_file->f_path.dentry->d_inode->i_fop->readdir; | 576 | readdir = proc_file->f_path.dentry->d_inode->i_fop->readdir; |
@@ -616,12 +579,12 @@ static int hppfs_readdir(struct file *file, void *ent, filldir_t filldir) | |||
616 | err = (*readdir)(proc_file, &dirent, hppfs_filldir); | 579 | err = (*readdir)(proc_file, &dirent, hppfs_filldir); |
617 | file->f_pos = proc_file->f_pos; | 580 | file->f_pos = proc_file->f_pos; |
618 | 581 | ||
619 | return(err); | 582 | return err; |
620 | } | 583 | } |
621 | 584 | ||
622 | static int hppfs_fsync(struct file *file, struct dentry *dentry, int datasync) | 585 | static int hppfs_fsync(struct file *file, struct dentry *dentry, int datasync) |
623 | { | 586 | { |
624 | return(0); | 587 | return 0; |
625 | } | 588 | } |
626 | 589 | ||
627 | static const struct file_operations hppfs_dir_fops = { | 590 | static const struct file_operations hppfs_dir_fops = { |
@@ -639,7 +602,7 @@ static int hppfs_statfs(struct dentry *dentry, struct kstatfs *sf) | |||
639 | sf->f_files = 0; | 602 | sf->f_files = 0; |
640 | sf->f_ffree = 0; | 603 | sf->f_ffree = 0; |
641 | sf->f_type = HPPFS_SUPER_MAGIC; | 604 | sf->f_type = HPPFS_SUPER_MAGIC; |
642 | return(0); | 605 | return 0; |
643 | } | 606 | } |
644 | 607 | ||
645 | static struct inode *hppfs_alloc_inode(struct super_block *sb) | 608 | static struct inode *hppfs_alloc_inode(struct super_block *sb) |
@@ -647,12 +610,12 @@ static struct inode *hppfs_alloc_inode(struct super_block *sb) | |||
647 | struct hppfs_inode_info *hi; | 610 | struct hppfs_inode_info *hi; |
648 | 611 | ||
649 | hi = kmalloc(sizeof(*hi), GFP_KERNEL); | 612 | hi = kmalloc(sizeof(*hi), GFP_KERNEL); |
650 | if(hi == NULL) | 613 | if (!hi) |
651 | return(NULL); | 614 | return NULL; |
652 | 615 | ||
653 | *hi = ((struct hppfs_inode_info) { .proc_dentry = NULL }); | 616 | hi->proc_dentry = NULL; |
654 | inode_init_once(&hi->vfs_inode); | 617 | inode_init_once(&hi->vfs_inode); |
655 | return(&hi->vfs_inode); | 618 | return &hi->vfs_inode; |
656 | } | 619 | } |
657 | 620 | ||
658 | void hppfs_delete_inode(struct inode *ino) | 621 | void hppfs_delete_inode(struct inode *ino) |
@@ -665,21 +628,31 @@ static void hppfs_destroy_inode(struct inode *inode) | |||
665 | kfree(HPPFS_I(inode)); | 628 | kfree(HPPFS_I(inode)); |
666 | } | 629 | } |
667 | 630 | ||
631 | static void hppfs_put_super(struct super_block *sb) | ||
632 | { | ||
633 | mntput(sb->s_fs_info); | ||
634 | } | ||
635 | |||
668 | static const struct super_operations hppfs_sbops = { | 636 | static const struct super_operations hppfs_sbops = { |
669 | .alloc_inode = hppfs_alloc_inode, | 637 | .alloc_inode = hppfs_alloc_inode, |
670 | .destroy_inode = hppfs_destroy_inode, | 638 | .destroy_inode = hppfs_destroy_inode, |
671 | .delete_inode = hppfs_delete_inode, | 639 | .delete_inode = hppfs_delete_inode, |
672 | .statfs = hppfs_statfs, | 640 | .statfs = hppfs_statfs, |
641 | .put_super = hppfs_put_super, | ||
673 | }; | 642 | }; |
674 | 643 | ||
675 | static int hppfs_readlink(struct dentry *dentry, char __user *buffer, int buflen) | 644 | static int hppfs_readlink(struct dentry *dentry, char __user *buffer, |
645 | int buflen) | ||
676 | { | 646 | { |
677 | struct file *proc_file; | 647 | struct file *proc_file; |
678 | struct dentry *proc_dentry; | 648 | struct dentry *proc_dentry; |
649 | struct vfsmount *proc_mnt; | ||
679 | int ret; | 650 | int ret; |
680 | 651 | ||
681 | proc_dentry = HPPFS_I(dentry->d_inode)->proc_dentry; | 652 | proc_dentry = HPPFS_I(dentry->d_inode)->proc_dentry; |
682 | proc_file = dentry_open(dget(proc_dentry), NULL, O_RDONLY); | 653 | proc_mnt = dentry->d_sb->s_fs_info; |
654 | |||
655 | proc_file = dentry_open(dget(proc_dentry), mntget(proc_mnt), O_RDONLY); | ||
683 | if (IS_ERR(proc_file)) | 656 | if (IS_ERR(proc_file)) |
684 | return PTR_ERR(proc_file); | 657 | return PTR_ERR(proc_file); |
685 | 658 | ||
@@ -694,10 +667,13 @@ static void* hppfs_follow_link(struct dentry *dentry, struct nameidata *nd) | |||
694 | { | 667 | { |
695 | struct file *proc_file; | 668 | struct file *proc_file; |
696 | struct dentry *proc_dentry; | 669 | struct dentry *proc_dentry; |
670 | struct vfsmount *proc_mnt; | ||
697 | void *ret; | 671 | void *ret; |
698 | 672 | ||
699 | proc_dentry = HPPFS_I(dentry->d_inode)->proc_dentry; | 673 | proc_dentry = HPPFS_I(dentry->d_inode)->proc_dentry; |
700 | proc_file = dentry_open(dget(proc_dentry), NULL, O_RDONLY); | 674 | proc_mnt = dentry->d_sb->s_fs_info; |
675 | |||
676 | proc_file = dentry_open(dget(proc_dentry), mntget(proc_mnt), O_RDONLY); | ||
701 | if (IS_ERR(proc_file)) | 677 | if (IS_ERR(proc_file)) |
702 | return proc_file; | 678 | return proc_file; |
703 | 679 | ||
@@ -717,70 +693,72 @@ static const struct inode_operations hppfs_link_iops = { | |||
717 | .follow_link = hppfs_follow_link, | 693 | .follow_link = hppfs_follow_link, |
718 | }; | 694 | }; |
719 | 695 | ||
720 | static int init_inode(struct inode *inode, struct dentry *dentry) | 696 | static struct inode *get_inode(struct super_block *sb, struct dentry *dentry) |
721 | { | 697 | { |
722 | if(S_ISDIR(dentry->d_inode->i_mode)){ | 698 | struct inode *proc_ino = dentry->d_inode; |
699 | struct inode *inode = new_inode(sb); | ||
700 | |||
701 | if (!inode) | ||
702 | return ERR_PTR(-ENOMEM); | ||
703 | |||
704 | if (S_ISDIR(dentry->d_inode->i_mode)) { | ||
723 | inode->i_op = &hppfs_dir_iops; | 705 | inode->i_op = &hppfs_dir_iops; |
724 | inode->i_fop = &hppfs_dir_fops; | 706 | inode->i_fop = &hppfs_dir_fops; |
725 | } | 707 | } else if (S_ISLNK(dentry->d_inode->i_mode)) { |
726 | else if(S_ISLNK(dentry->d_inode->i_mode)){ | ||
727 | inode->i_op = &hppfs_link_iops; | 708 | inode->i_op = &hppfs_link_iops; |
728 | inode->i_fop = &hppfs_file_fops; | 709 | inode->i_fop = &hppfs_file_fops; |
729 | } | 710 | } else { |
730 | else { | ||
731 | inode->i_op = &hppfs_file_iops; | 711 | inode->i_op = &hppfs_file_iops; |
732 | inode->i_fop = &hppfs_file_fops; | 712 | inode->i_fop = &hppfs_file_fops; |
733 | } | 713 | } |
734 | 714 | ||
735 | HPPFS_I(inode)->proc_dentry = dentry; | 715 | HPPFS_I(inode)->proc_dentry = dentry; |
736 | 716 | ||
737 | return(0); | 717 | inode->i_uid = proc_ino->i_uid; |
718 | inode->i_gid = proc_ino->i_gid; | ||
719 | inode->i_atime = proc_ino->i_atime; | ||
720 | inode->i_mtime = proc_ino->i_mtime; | ||
721 | inode->i_ctime = proc_ino->i_ctime; | ||
722 | inode->i_ino = proc_ino->i_ino; | ||
723 | inode->i_mode = proc_ino->i_mode; | ||
724 | inode->i_nlink = proc_ino->i_nlink; | ||
725 | inode->i_size = proc_ino->i_size; | ||
726 | inode->i_blocks = proc_ino->i_blocks; | ||
727 | |||
728 | return 0; | ||
738 | } | 729 | } |
739 | 730 | ||
740 | static int hppfs_fill_super(struct super_block *sb, void *d, int silent) | 731 | static int hppfs_fill_super(struct super_block *sb, void *d, int silent) |
741 | { | 732 | { |
742 | struct inode *root_inode; | 733 | struct inode *root_inode; |
743 | struct file_system_type *procfs; | 734 | struct vfsmount *proc_mnt; |
744 | struct super_block *proc_sb; | 735 | int err = -ENOENT; |
745 | int err; | ||
746 | 736 | ||
747 | err = -ENOENT; | 737 | proc_mnt = do_kern_mount("proc", 0, "proc", NULL); |
748 | procfs = get_fs_type("proc"); | 738 | if (IS_ERR(proc_mnt)) |
749 | if(procfs == NULL) | ||
750 | goto out; | 739 | goto out; |
751 | 740 | ||
752 | if(list_empty(&procfs->fs_supers)) | ||
753 | goto out; | ||
754 | |||
755 | proc_sb = list_entry(procfs->fs_supers.next, struct super_block, | ||
756 | s_instances); | ||
757 | |||
758 | sb->s_blocksize = 1024; | 741 | sb->s_blocksize = 1024; |
759 | sb->s_blocksize_bits = 10; | 742 | sb->s_blocksize_bits = 10; |
760 | sb->s_magic = HPPFS_SUPER_MAGIC; | 743 | sb->s_magic = HPPFS_SUPER_MAGIC; |
761 | sb->s_op = &hppfs_sbops; | 744 | sb->s_op = &hppfs_sbops; |
762 | 745 | sb->s_fs_info = proc_mnt; | |
763 | root_inode = hppfs_iget(sb); | ||
764 | if (IS_ERR(root_inode)) { | ||
765 | err = PTR_ERR(root_inode); | ||
766 | goto out; | ||
767 | } | ||
768 | |||
769 | err = init_inode(root_inode, proc_sb->s_root); | ||
770 | if(err) | ||
771 | goto out_put; | ||
772 | 746 | ||
773 | err = -ENOMEM; | 747 | err = -ENOMEM; |
774 | sb->s_root = d_alloc_root(root_inode); | 748 | root_inode = get_inode(sb, proc_mnt->mnt_sb->s_root); |
775 | if(sb->s_root == NULL) | 749 | if (!root_inode) |
776 | goto out_put; | 750 | goto out_mntput; |
777 | 751 | ||
778 | hppfs_read_inode(root_inode); | 752 | sb->s_root = d_alloc_root(root_inode); |
753 | if (!sb->s_root) | ||
754 | goto out_iput; | ||
779 | 755 | ||
780 | return(0); | 756 | return 0; |
781 | 757 | ||
782 | out_put: | 758 | out_iput: |
783 | iput(root_inode); | 759 | iput(root_inode); |
760 | out_mntput: | ||
761 | mntput(proc_mnt); | ||
784 | out: | 762 | out: |
785 | return(err); | 763 | return(err); |
786 | } | 764 | } |
@@ -802,7 +780,7 @@ static struct file_system_type hppfs_type = { | |||
802 | 780 | ||
803 | static int __init init_hppfs(void) | 781 | static int __init init_hppfs(void) |
804 | { | 782 | { |
805 | return(register_filesystem(&hppfs_type)); | 783 | return register_filesystem(&hppfs_type); |
806 | } | 784 | } |
807 | 785 | ||
808 | static void __exit exit_hppfs(void) | 786 | static void __exit exit_hppfs(void) |
@@ -813,14 +791,3 @@ static void __exit exit_hppfs(void) | |||
813 | module_init(init_hppfs) | 791 | module_init(init_hppfs) |
814 | module_exit(exit_hppfs) | 792 | module_exit(exit_hppfs) |
815 | MODULE_LICENSE("GPL"); | 793 | MODULE_LICENSE("GPL"); |
816 | |||
817 | /* | ||
818 | * Overrides for Emacs so that we follow Linus's tabbing style. | ||
819 | * Emacs will notice this stuff at the end of the file and automatically | ||
820 | * adjust the settings for this buffer only. This must remain at the end | ||
821 | * of the file. | ||
822 | * --------------------------------------------------------------------------- | ||
823 | * Local variables: | ||
824 | * c-file-style: "linux" | ||
825 | * End: | ||
826 | */ | ||