aboutsummaryrefslogtreecommitdiffstats
path: root/fs/hppfs
diff options
context:
space:
mode:
authorDave Hansen <haveblue@us.ibm.com>2008-02-15 18:37:00 -0500
committerAl Viro <viro@zeniv.linux.org.uk>2008-03-19 06:39:56 -0400
commit1dd0dd111f1b7591f2848fffdb06044053f66c40 (patch)
tree7913e42fbb43e8d724e547c5ff1d2efa71c2bc57 /fs/hppfs
parent8a4e98d9d758d0eb751916e906fae40bda151b11 (diff)
hppfs pass vfsmount to dentry_open()
Here's patch for hppfs that uses vfs_kern_mount to make sure it always has a procfs instance and passed the vfsmount on through the inode private data. Also fixes a procfs file_system_type leak for every attempted hppfs mount. [ jdike - gave this file a style workover, plus deleted hppfs_dentry_ops ] Acked-by: Al Viro <viro@ZenIV.linux.org.uk> Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jeff Dike <jdike@linux.intel.com> Signed-off-by: Dave Hansen <haveblue@us.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/hppfs')
-rw-r--r--fs/hppfs/hppfs_kern.c364
1 files changed, 188 insertions, 176 deletions
diff --git a/fs/hppfs/hppfs_kern.c b/fs/hppfs/hppfs_kern.c
index a1e1f0f61aa5..0c0f62f5164f 100644
--- a/fs/hppfs/hppfs_kern.c
+++ b/fs/hppfs/hppfs_kern.c
@@ -1,23 +1,25 @@
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
20static int init_inode(struct inode *inode, struct dentry *dentry); 21static int init_inode(struct inode *inode, struct dentry *dentry,
22 struct vfsmount *mnt);
21 23
22struct hppfs_data { 24struct hppfs_data {
23 struct list_head list; 25 struct list_head list;
@@ -33,6 +35,7 @@ struct hppfs_private {
33 35
34struct hppfs_inode_info { 36struct hppfs_inode_info {
35 struct dentry *proc_dentry; 37 struct dentry *proc_dentry;
38 struct vfsmount *proc_mnt;
36 struct inode vfs_inode; 39 struct inode vfs_inode;
37}; 40};
38 41
@@ -51,14 +54,14 @@ static int is_pid(struct dentry *dentry)
51 int i; 54 int i;
52 55
53 sb = dentry->d_sb; 56 sb = dentry->d_sb;
54 if((sb->s_op != &hppfs_sbops) || (dentry->d_parent != sb->s_root)) 57 if ((sb->s_op != &hppfs_sbops) || (dentry->d_parent != sb->s_root))
55 return(0); 58 return 0;
56 59
57 for(i = 0; i < dentry->d_name.len; i++){ 60 for (i = 0; i < dentry->d_name.len; i++) {
58 if(!isdigit(dentry->d_name.name[i])) 61 if (!isdigit(dentry->d_name.name[i]))
59 return(0); 62 return 0;
60 } 63 }
61 return(1); 64 return 1;
62} 65}
63 66
64static char *dentry_name(struct dentry *dentry, int extra) 67static char *dentry_name(struct dentry *dentry, int extra)
@@ -70,8 +73,8 @@ static char *dentry_name(struct dentry *dentry, int extra)
70 73
71 len = 0; 74 len = 0;
72 parent = dentry; 75 parent = dentry;
73 while(parent->d_parent != parent){ 76 while (parent->d_parent != parent) {
74 if(is_pid(parent)) 77 if (is_pid(parent))
75 len += strlen("pid") + 1; 78 len += strlen("pid") + 1;
76 else len += parent->d_name.len + 1; 79 else len += parent->d_name.len + 1;
77 parent = parent->d_parent; 80 parent = parent->d_parent;
@@ -80,12 +83,13 @@ static char *dentry_name(struct dentry *dentry, int extra)
80 root = "proc"; 83 root = "proc";
81 len += strlen(root); 84 len += strlen(root);
82 name = kmalloc(len + extra + 1, GFP_KERNEL); 85 name = kmalloc(len + extra + 1, GFP_KERNEL);
83 if(name == NULL) return(NULL); 86 if (name == NULL)
87 return NULL;
84 88
85 name[len] = '\0'; 89 name[len] = '\0';
86 parent = dentry; 90 parent = dentry;
87 while(parent->d_parent != parent){ 91 while (parent->d_parent != parent) {
88 if(is_pid(parent)){ 92 if (is_pid(parent)) {
89 seg_name = "pid"; 93 seg_name = "pid";
90 seg_len = strlen("pid"); 94 seg_len = strlen("pid");
91 } 95 }
@@ -100,27 +104,25 @@ static char *dentry_name(struct dentry *dentry, int extra)
100 parent = parent->d_parent; 104 parent = parent->d_parent;
101 } 105 }
102 strncpy(name, root, strlen(root)); 106 strncpy(name, root, strlen(root));
103 return(name); 107 return name;
104} 108}
105 109
106struct dentry_operations hppfs_dentry_ops = {
107};
108
109static int file_removed(struct dentry *dentry, const char *file) 110static int file_removed(struct dentry *dentry, const char *file)
110{ 111{
111 char *host_file; 112 char *host_file;
112 int extra, fd; 113 int extra, fd;
113 114
114 extra = 0; 115 extra = 0;
115 if(file != NULL) extra += strlen(file) + 1; 116 if (file != NULL)
117 extra += strlen(file) + 1;
116 118
117 host_file = dentry_name(dentry, extra + strlen("/remove")); 119 host_file = dentry_name(dentry, extra + strlen("/remove"));
118 if(host_file == NULL){ 120 if (host_file == NULL) {
119 printk("file_removed : allocation failed\n"); 121 printk(KERN_ERR "file_removed : allocation failed\n");
120 return(-ENOMEM); 122 return -ENOMEM;
121 } 123 }
122 124
123 if(file != NULL){ 125 if (file != NULL) {
124 strcat(host_file, "/"); 126 strcat(host_file, "/");
125 strcat(host_file, file); 127 strcat(host_file, file);
126 } 128 }
@@ -128,18 +130,18 @@ static int file_removed(struct dentry *dentry, const char *file)
128 130
129 fd = os_open_file(host_file, of_read(OPENFLAGS()), 0); 131 fd = os_open_file(host_file, of_read(OPENFLAGS()), 0);
130 kfree(host_file); 132 kfree(host_file);
131 if(fd > 0){ 133 if (fd > 0) {
132 os_close_file(fd); 134 os_close_file(fd);
133 return(1); 135 return 1;
134 } 136 }
135 return(0); 137 return 0;
136} 138}
137 139
138static void hppfs_read_inode(struct inode *ino) 140static void hppfs_read_inode(struct inode *ino)
139{ 141{
140 struct inode *proc_ino; 142 struct inode *proc_ino;
141 143
142 if(HPPFS_I(ino)->proc_dentry == NULL) 144 if (HPPFS_I(ino)->proc_dentry == NULL)
143 return; 145 return;
144 146
145 proc_ino = HPPFS_I(ino)->proc_dentry->d_inode; 147 proc_ino = HPPFS_I(ino)->proc_dentry->d_inode;
@@ -177,32 +179,32 @@ static struct dentry *hppfs_lookup(struct inode *ino, struct dentry *dentry,
177 int err, deleted; 179 int err, deleted;
178 180
179 deleted = file_removed(dentry, NULL); 181 deleted = file_removed(dentry, NULL);
180 if(deleted < 0) 182 if (deleted < 0)
181 return(ERR_PTR(deleted)); 183 return ERR_PTR(deleted);
182 else if(deleted) 184 else if (deleted)
183 return(ERR_PTR(-ENOENT)); 185 return ERR_PTR(-ENOENT);
184 186
185 err = -ENOMEM; 187 err = -ENOMEM;
186 parent = HPPFS_I(ino)->proc_dentry; 188 parent = HPPFS_I(ino)->proc_dentry;
187 mutex_lock(&parent->d_inode->i_mutex); 189 mutex_lock(&parent->d_inode->i_mutex);
188 proc_dentry = d_lookup(parent, &dentry->d_name); 190 proc_dentry = d_lookup(parent, &dentry->d_name);
189 if(proc_dentry == NULL){ 191 if (proc_dentry == NULL) {
190 proc_dentry = d_alloc(parent, &dentry->d_name); 192 proc_dentry = d_alloc(parent, &dentry->d_name);
191 if(proc_dentry == NULL){ 193 if (proc_dentry == NULL) {
192 mutex_unlock(&parent->d_inode->i_mutex); 194 mutex_unlock(&parent->d_inode->i_mutex);
193 goto out; 195 goto out;
194 } 196 }
195 new = (*parent->d_inode->i_op->lookup)(parent->d_inode, 197 new = (*parent->d_inode->i_op->lookup)(parent->d_inode,
196 proc_dentry, NULL); 198 proc_dentry, NULL);
197 if(new){ 199 if (new) {
198 dput(proc_dentry); 200 dput(proc_dentry);
199 proc_dentry = new; 201 proc_dentry = new;
200 } 202 }
201 } 203 }
202 mutex_unlock(&parent->d_inode->i_mutex); 204 mutex_unlock(&parent->d_inode->i_mutex);
203 205
204 if(IS_ERR(proc_dentry)) 206 if (IS_ERR(proc_dentry))
205 return(proc_dentry); 207 return proc_dentry;
206 208
207 inode = hppfs_iget(ino->i_sb); 209 inode = hppfs_iget(ino->i_sb);
208 if (IS_ERR(inode)) { 210 if (IS_ERR(inode)) {
@@ -210,22 +212,21 @@ static struct dentry *hppfs_lookup(struct inode *ino, struct dentry *dentry,
210 goto out_dput; 212 goto out_dput;
211 } 213 }
212 214
213 err = init_inode(inode, proc_dentry); 215 err = init_inode(inode, proc_dentry, HPPFS_I(ino)->proc_mnt);
214 if(err) 216 if (err)
215 goto out_put; 217 goto out_put;
216 218
217 hppfs_read_inode(inode); 219 hppfs_read_inode(inode);
218 220
219 d_add(dentry, inode); 221 d_add(dentry, inode);
220 dentry->d_op = &hppfs_dentry_ops; 222 return NULL;
221 return(NULL);
222 223
223 out_put: 224 out_put:
224 iput(inode); 225 iput(inode);
225 out_dput: 226 out_dput:
226 dput(proc_dentry); 227 dput(proc_dentry);
227 out: 228 out:
228 return(ERR_PTR(err)); 229 return ERR_PTR(err);
229} 230}
230 231
231static const struct inode_operations hppfs_file_iops = { 232static const struct inode_operations hppfs_file_iops = {
@@ -239,15 +240,16 @@ static ssize_t read_proc(struct file *file, char __user *buf, ssize_t count,
239 240
240 read = file->f_path.dentry->d_inode->i_fop->read; 241 read = file->f_path.dentry->d_inode->i_fop->read;
241 242
242 if(!is_user) 243 if (!is_user)
243 set_fs(KERNEL_DS); 244 set_fs(KERNEL_DS);
244 245
245 n = (*read)(file, buf, count, &file->f_pos); 246 n = (*read)(file, buf, count, &file->f_pos);
246 247
247 if(!is_user) 248 if (!is_user)
248 set_fs(USER_DS); 249 set_fs(USER_DS);
249 250
250 if(ppos) *ppos = file->f_pos; 251 if (ppos)
252 *ppos = file->f_pos;
251 return n; 253 return n;
252} 254}
253 255
@@ -259,24 +261,23 @@ static ssize_t hppfs_read_file(int fd, char __user *buf, ssize_t count)
259 261
260 n = -ENOMEM; 262 n = -ENOMEM;
261 new_buf = kmalloc(PAGE_SIZE, GFP_KERNEL); 263 new_buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
262 if(new_buf == NULL){ 264 if (new_buf == NULL) {
263 printk("hppfs_read_file : kmalloc failed\n"); 265 printk(KERN_ERR "hppfs_read_file : kmalloc failed\n");
264 goto out; 266 goto out;
265 } 267 }
266 n = 0; 268 n = 0;
267 while(count > 0){ 269 while (count > 0) {
268 cur = min_t(ssize_t, count, PAGE_SIZE); 270 cur = min_t(ssize_t, count, PAGE_SIZE);
269 err = os_read_file(fd, new_buf, cur); 271 err = os_read_file(fd, new_buf, cur);
270 if(err < 0){ 272 if (err < 0) {
271 printk("hppfs_read : read failed, errno = %d\n", 273 printk(KERN_ERR "hppfs_read : read failed, "
272 err); 274 "errno = %d\n", err);
273 n = err; 275 n = err;
274 goto out_free; 276 goto out_free;
275 } 277 } else if (err == 0)
276 else if(err == 0)
277 break; 278 break;
278 279
279 if(copy_to_user(buf, new_buf, err)){ 280 if (copy_to_user(buf, new_buf, err)) {
280 n = -EFAULT; 281 n = -EFAULT;
281 goto out_free; 282 goto out_free;
282 } 283 }
@@ -297,35 +298,36 @@ static ssize_t hppfs_read(struct file *file, char __user *buf, size_t count,
297 loff_t off; 298 loff_t off;
298 int err; 299 int err;
299 300
300 if(hppfs->contents != NULL){ 301 if (hppfs->contents != NULL) {
301 if(*ppos >= hppfs->len) return(0); 302 if (*ppos >= hppfs->len)
303 return 0;
302 304
303 data = hppfs->contents; 305 data = hppfs->contents;
304 off = *ppos; 306 off = *ppos;
305 while(off >= sizeof(data->contents)){ 307 while (off >= sizeof(data->contents)) {
306 data = list_entry(data->list.next, struct hppfs_data, 308 data = list_entry(data->list.next, struct hppfs_data,
307 list); 309 list);
308 off -= sizeof(data->contents); 310 off -= sizeof(data->contents);
309 } 311 }
310 312
311 if(off + count > hppfs->len) 313 if (off + count > hppfs->len)
312 count = hppfs->len - off; 314 count = hppfs->len - off;
313 copy_to_user(buf, &data->contents[off], count); 315 copy_to_user(buf, &data->contents[off], count);
314 *ppos += count; 316 *ppos += count;
315 } 317 } else if (hppfs->host_fd != -1) {
316 else if(hppfs->host_fd != -1){
317 err = os_seek_file(hppfs->host_fd, *ppos); 318 err = os_seek_file(hppfs->host_fd, *ppos);
318 if(err){ 319 if (err) {
319 printk("hppfs_read : seek failed, errno = %d\n", err); 320 printk(KERN_ERR "hppfs_read : seek failed, "
320 return(err); 321 "errno = %d\n", err);
322 return err;
321 } 323 }
322 count = hppfs_read_file(hppfs->host_fd, buf, count); 324 count = hppfs_read_file(hppfs->host_fd, buf, count);
323 if(count > 0) 325 if (count > 0)
324 *ppos += count; 326 *ppos += count;
325 } 327 }
326 else count = read_proc(hppfs->proc_file, buf, count, ppos, 1); 328 else count = read_proc(hppfs->proc_file, buf, count, ppos, 1);
327 329
328 return(count); 330 return count;
329} 331}
330 332
331static ssize_t hppfs_write(struct file *file, const char __user *buf, size_t len, 333static ssize_t hppfs_write(struct file *file, const char __user *buf, size_t len,
@@ -342,7 +344,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); 344 err = (*write)(proc_file, buf, len, &proc_file->f_pos);
343 file->f_pos = proc_file->f_pos; 345 file->f_pos = proc_file->f_pos;
344 346
345 return(err); 347 return err;
346} 348}
347 349
348static int open_host_sock(char *host_file, int *filter_out) 350static int open_host_sock(char *host_file, int *filter_out)
@@ -354,13 +356,13 @@ static int open_host_sock(char *host_file, int *filter_out)
354 strcpy(end, "/rw"); 356 strcpy(end, "/rw");
355 *filter_out = 1; 357 *filter_out = 1;
356 fd = os_connect_socket(host_file); 358 fd = os_connect_socket(host_file);
357 if(fd > 0) 359 if (fd > 0)
358 return(fd); 360 return fd;
359 361
360 strcpy(end, "/r"); 362 strcpy(end, "/r");
361 *filter_out = 0; 363 *filter_out = 0;
362 fd = os_connect_socket(host_file); 364 fd = os_connect_socket(host_file);
363 return(fd); 365 return fd;
364} 366}
365 367
366static void free_contents(struct hppfs_data *head) 368static void free_contents(struct hppfs_data *head)
@@ -368,9 +370,10 @@ static void free_contents(struct hppfs_data *head)
368 struct hppfs_data *data; 370 struct hppfs_data *data;
369 struct list_head *ele, *next; 371 struct list_head *ele, *next;
370 372
371 if(head == NULL) return; 373 if (head == NULL)
374 return;
372 375
373 list_for_each_safe(ele, next, &head->list){ 376 list_for_each_safe(ele, next, &head->list) {
374 data = list_entry(ele, struct hppfs_data, list); 377 data = list_entry(ele, struct hppfs_data, list);
375 kfree(data); 378 kfree(data);
376 } 379 }
@@ -387,8 +390,8 @@ static struct hppfs_data *hppfs_get_data(int fd, int filter,
387 390
388 err = -ENOMEM; 391 err = -ENOMEM;
389 data = kmalloc(sizeof(*data), GFP_KERNEL); 392 data = kmalloc(sizeof(*data), GFP_KERNEL);
390 if(data == NULL){ 393 if (data == NULL) {
391 printk("hppfs_get_data : head allocation failed\n"); 394 printk(KERN_ERR "hppfs_get_data : head allocation failed\n");
392 goto failed; 395 goto failed;
393 } 396 }
394 397
@@ -397,36 +400,36 @@ static struct hppfs_data *hppfs_get_data(int fd, int filter,
397 head = data; 400 head = data;
398 *size_out = 0; 401 *size_out = 0;
399 402
400 if(filter){ 403 if (filter) {
401 while((n = read_proc(proc_file, data->contents, 404 while ((n = read_proc(proc_file, data->contents,
402 sizeof(data->contents), NULL, 0)) > 0) 405 sizeof(data->contents), NULL, 0)) > 0)
403 os_write_file(fd, data->contents, n); 406 os_write_file(fd, data->contents, n);
404 err = os_shutdown_socket(fd, 0, 1); 407 err = os_shutdown_socket(fd, 0, 1);
405 if(err){ 408 if (err) {
406 printk("hppfs_get_data : failed to shut down " 409 printk(KERN_ERR "hppfs_get_data : failed to shut down "
407 "socket\n"); 410 "socket\n");
408 goto failed_free; 411 goto failed_free;
409 } 412 }
410 } 413 }
411 while(1){ 414 while (1) {
412 n = os_read_file(fd, data->contents, sizeof(data->contents)); 415 n = os_read_file(fd, data->contents, sizeof(data->contents));
413 if(n < 0){ 416 if (n < 0) {
414 err = n; 417 err = n;
415 printk("hppfs_get_data : read failed, errno = %d\n", 418 printk(KERN_ERR "hppfs_get_data : read failed, "
416 err); 419 "errno = %d\n", err);
417 goto failed_free; 420 goto failed_free;
418 } 421 } else if (n == 0)
419 else if(n == 0)
420 break; 422 break;
421 423
422 *size_out += n; 424 *size_out += n;
423 425
424 if(n < sizeof(data->contents)) 426 if (n < sizeof(data->contents))
425 break; 427 break;
426 428
427 new = kmalloc(sizeof(*data), GFP_KERNEL); 429 new = kmalloc(sizeof(*data), GFP_KERNEL);
428 if(new == 0){ 430 if (new == 0) {
429 printk("hppfs_get_data : data allocation failed\n"); 431 printk(KERN_ERR "hppfs_get_data : data allocation "
432 "failed\n");
430 err = -ENOMEM; 433 err = -ENOMEM;
431 goto failed_free; 434 goto failed_free;
432 } 435 }
@@ -435,12 +438,12 @@ static struct hppfs_data *hppfs_get_data(int fd, int filter,
435 list_add(&new->list, &data->list); 438 list_add(&new->list, &data->list);
436 data = new; 439 data = new;
437 } 440 }
438 return(head); 441 return head;
439 442
440 failed_free: 443 failed_free:
441 free_contents(head); 444 free_contents(head);
442 failed: 445 failed:
443 return(ERR_PTR(err)); 446 return ERR_PTR(err);
444} 447}
445 448
446static struct hppfs_private *hppfs_data(void) 449static struct hppfs_private *hppfs_data(void)
@@ -448,77 +451,79 @@ static struct hppfs_private *hppfs_data(void)
448 struct hppfs_private *data; 451 struct hppfs_private *data;
449 452
450 data = kmalloc(sizeof(*data), GFP_KERNEL); 453 data = kmalloc(sizeof(*data), GFP_KERNEL);
451 if(data == NULL) 454 if (data == NULL)
452 return(data); 455 return data;
453 456
454 *data = ((struct hppfs_private ) { .host_fd = -1, 457 *data = ((struct hppfs_private ) { .host_fd = -1,
455 .len = -1, 458 .len = -1,
456 .contents = NULL } ); 459 .contents = NULL } );
457 return(data); 460 return data;
458} 461}
459 462
460static int file_mode(int fmode) 463static int file_mode(int fmode)
461{ 464{
462 if(fmode == (FMODE_READ | FMODE_WRITE)) 465 if (fmode == (FMODE_READ | FMODE_WRITE))
463 return(O_RDWR); 466 return O_RDWR;
464 if(fmode == FMODE_READ) 467 if (fmode == FMODE_READ)
465 return(O_RDONLY); 468 return O_RDONLY;
466 if(fmode == FMODE_WRITE) 469 if (fmode == FMODE_WRITE)
467 return(O_WRONLY); 470 return O_WRONLY;
468 return(0); 471 return 0;
469} 472}
470 473
471static int hppfs_open(struct inode *inode, struct file *file) 474static int hppfs_open(struct inode *inode, struct file *file)
472{ 475{
473 struct hppfs_private *data; 476 struct hppfs_private *data;
474 struct dentry *proc_dentry; 477 struct dentry *proc_dentry;
478 struct vfsmount *proc_mnt;
475 char *host_file; 479 char *host_file;
476 int err, fd, type, filter; 480 int err, fd, type, filter;
477 481
478 err = -ENOMEM; 482 err = -ENOMEM;
479 data = hppfs_data(); 483 data = hppfs_data();
480 if(data == NULL) 484 if (data == NULL)
481 goto out; 485 goto out;
482 486
483 host_file = dentry_name(file->f_path.dentry, strlen("/rw")); 487 host_file = dentry_name(file->f_path.dentry, strlen("/rw"));
484 if(host_file == NULL) 488 if (host_file == NULL)
485 goto out_free2; 489 goto out_free2;
486 490
487 proc_dentry = HPPFS_I(inode)->proc_dentry; 491 proc_dentry = HPPFS_I(inode)->proc_dentry;
492 proc_mnt = HPPFS_I(inode)->proc_mnt;
488 493
489 /* XXX This isn't closed anywhere */ 494 /* XXX This isn't closed anywhere */
490 data->proc_file = dentry_open(dget(proc_dentry), NULL, 495 data->proc_file = dentry_open(dget(proc_dentry), mntget(proc_mnt),
491 file_mode(file->f_mode)); 496 file_mode(file->f_mode));
492 err = PTR_ERR(data->proc_file); 497 err = PTR_ERR(data->proc_file);
493 if(IS_ERR(data->proc_file)) 498 if (IS_ERR(data->proc_file))
494 goto out_free1; 499 goto out_free1;
495 500
496 type = os_file_type(host_file); 501 type = os_file_type(host_file);
497 if(type == OS_TYPE_FILE){ 502 if (type == OS_TYPE_FILE) {
498 fd = os_open_file(host_file, of_read(OPENFLAGS()), 0); 503 fd = os_open_file(host_file, of_read(OPENFLAGS()), 0);
499 if(fd >= 0) 504 if (fd >= 0)
500 data->host_fd = fd; 505 data->host_fd = fd;
501 else printk("hppfs_open : failed to open '%s', errno = %d\n", 506 else
502 host_file, -fd); 507 printk(KERN_ERR "hppfs_open : failed to open '%s', "
508 "errno = %d\n", host_file, -fd);
503 509
504 data->contents = NULL; 510 data->contents = NULL;
505 } 511 } else if (type == OS_TYPE_DIR) {
506 else if(type == OS_TYPE_DIR){
507 fd = open_host_sock(host_file, &filter); 512 fd = open_host_sock(host_file, &filter);
508 if(fd > 0){ 513 if (fd > 0) {
509 data->contents = hppfs_get_data(fd, filter, 514 data->contents = hppfs_get_data(fd, filter,
510 data->proc_file, 515 data->proc_file,
511 file, &data->len); 516 file, &data->len);
512 if(!IS_ERR(data->contents)) 517 if (!IS_ERR(data->contents))
513 data->host_fd = fd; 518 data->host_fd = fd;
514 } 519 } else
515 else printk("hppfs_open : failed to open a socket in " 520 printk(KERN_ERR "hppfs_open : failed to open a socket "
516 "'%s', errno = %d\n", host_file, -fd); 521 "in '%s', errno = %d\n", host_file, -fd);
517 } 522 }
518 kfree(host_file); 523 kfree(host_file);
519 524
520 file->private_data = data; 525 file->private_data = data;
521 return(0); 526 return 0;
522 527
523 out_free1: 528 out_free1:
524 kfree(host_file); 529 kfree(host_file);
@@ -526,34 +531,36 @@ static int hppfs_open(struct inode *inode, struct file *file)
526 free_contents(data->contents); 531 free_contents(data->contents);
527 kfree(data); 532 kfree(data);
528 out: 533 out:
529 return(err); 534 return err;
530} 535}
531 536
532static int hppfs_dir_open(struct inode *inode, struct file *file) 537static int hppfs_dir_open(struct inode *inode, struct file *file)
533{ 538{
534 struct hppfs_private *data; 539 struct hppfs_private *data;
535 struct dentry *proc_dentry; 540 struct dentry *proc_dentry;
541 struct vfsmount *proc_mnt;
536 int err; 542 int err;
537 543
538 err = -ENOMEM; 544 err = -ENOMEM;
539 data = hppfs_data(); 545 data = hppfs_data();
540 if(data == NULL) 546 if (data == NULL)
541 goto out; 547 goto out;
542 548
543 proc_dentry = HPPFS_I(inode)->proc_dentry; 549 proc_dentry = HPPFS_I(inode)->proc_dentry;
544 data->proc_file = dentry_open(dget(proc_dentry), NULL, 550 proc_mnt = HPPFS_I(inode)->proc_mnt;
551 data->proc_file = dentry_open(dget(proc_dentry), mntget(proc_mnt),
545 file_mode(file->f_mode)); 552 file_mode(file->f_mode));
546 err = PTR_ERR(data->proc_file); 553 err = PTR_ERR(data->proc_file);
547 if(IS_ERR(data->proc_file)) 554 if (IS_ERR(data->proc_file))
548 goto out_free; 555 goto out_free;
549 556
550 file->private_data = data; 557 file->private_data = data;
551 return(0); 558 return 0;
552 559
553 out_free: 560 out_free:
554 kfree(data); 561 kfree(data);
555 out: 562 out:
556 return(err); 563 return err;
557} 564}
558 565
559static loff_t hppfs_llseek(struct file *file, loff_t off, int where) 566static loff_t hppfs_llseek(struct file *file, loff_t off, int where)
@@ -564,13 +571,13 @@ static loff_t hppfs_llseek(struct file *file, loff_t off, int where)
564 loff_t ret; 571 loff_t ret;
565 572
566 llseek = proc_file->f_path.dentry->d_inode->i_fop->llseek; 573 llseek = proc_file->f_path.dentry->d_inode->i_fop->llseek;
567 if(llseek != NULL){ 574 if (llseek != NULL) {
568 ret = (*llseek)(proc_file, off, where); 575 ret = (*llseek)(proc_file, off, where);
569 if(ret < 0) 576 if (ret < 0)
570 return(ret); 577 return ret;
571 } 578 }
572 579
573 return(default_llseek(file, off, where)); 580 return default_llseek(file, off, where);
574} 581}
575 582
576static const struct file_operations hppfs_file_fops = { 583static const struct file_operations hppfs_file_fops = {
@@ -592,11 +599,11 @@ static int hppfs_filldir(void *d, const char *name, int size,
592{ 599{
593 struct hppfs_dirent *dirent = d; 600 struct hppfs_dirent *dirent = d;
594 601
595 if(file_removed(dirent->dentry, name)) 602 if (file_removed(dirent->dentry, name))
596 return(0); 603 return 0;
597 604
598 return((*dirent->filldir)(dirent->vfs_dirent, name, size, offset, 605 return (*dirent->filldir)(dirent->vfs_dirent, name, size, offset,
599 inode, type)); 606 inode, type);
600} 607}
601 608
602static int hppfs_readdir(struct file *file, void *ent, filldir_t filldir) 609static int hppfs_readdir(struct file *file, void *ent, filldir_t filldir)
@@ -607,7 +614,8 @@ static int hppfs_readdir(struct file *file, void *ent, filldir_t filldir)
607 struct hppfs_dirent dirent = ((struct hppfs_dirent) 614 struct hppfs_dirent dirent = ((struct hppfs_dirent)
608 { .vfs_dirent = ent, 615 { .vfs_dirent = ent,
609 .filldir = filldir, 616 .filldir = filldir,
610 .dentry = file->f_path.dentry } ); 617 .dentry = file->f_path.dentry
618 });
611 int err; 619 int err;
612 620
613 readdir = proc_file->f_path.dentry->d_inode->i_fop->readdir; 621 readdir = proc_file->f_path.dentry->d_inode->i_fop->readdir;
@@ -616,12 +624,12 @@ static int hppfs_readdir(struct file *file, void *ent, filldir_t filldir)
616 err = (*readdir)(proc_file, &dirent, hppfs_filldir); 624 err = (*readdir)(proc_file, &dirent, hppfs_filldir);
617 file->f_pos = proc_file->f_pos; 625 file->f_pos = proc_file->f_pos;
618 626
619 return(err); 627 return err;
620} 628}
621 629
622static int hppfs_fsync(struct file *file, struct dentry *dentry, int datasync) 630static int hppfs_fsync(struct file *file, struct dentry *dentry, int datasync)
623{ 631{
624 return(0); 632 return 0;
625} 633}
626 634
627static const struct file_operations hppfs_dir_fops = { 635static const struct file_operations hppfs_dir_fops = {
@@ -639,7 +647,7 @@ static int hppfs_statfs(struct dentry *dentry, struct kstatfs *sf)
639 sf->f_files = 0; 647 sf->f_files = 0;
640 sf->f_ffree = 0; 648 sf->f_ffree = 0;
641 sf->f_type = HPPFS_SUPER_MAGIC; 649 sf->f_type = HPPFS_SUPER_MAGIC;
642 return(0); 650 return 0;
643} 651}
644 652
645static struct inode *hppfs_alloc_inode(struct super_block *sb) 653static struct inode *hppfs_alloc_inode(struct super_block *sb)
@@ -647,12 +655,13 @@ static struct inode *hppfs_alloc_inode(struct super_block *sb)
647 struct hppfs_inode_info *hi; 655 struct hppfs_inode_info *hi;
648 656
649 hi = kmalloc(sizeof(*hi), GFP_KERNEL); 657 hi = kmalloc(sizeof(*hi), GFP_KERNEL);
650 if(hi == NULL) 658 if (!hi)
651 return(NULL); 659 return NULL;
652 660
653 *hi = ((struct hppfs_inode_info) { .proc_dentry = NULL }); 661 hi->proc_dentry = NULL;
662 hi->proc_mnt = NULL;
654 inode_init_once(&hi->vfs_inode); 663 inode_init_once(&hi->vfs_inode);
655 return(&hi->vfs_inode); 664 return &hi->vfs_inode;
656} 665}
657 666
658void hppfs_delete_inode(struct inode *ino) 667void hppfs_delete_inode(struct inode *ino)
@@ -665,21 +674,31 @@ static void hppfs_destroy_inode(struct inode *inode)
665 kfree(HPPFS_I(inode)); 674 kfree(HPPFS_I(inode));
666} 675}
667 676
677static void hppfs_put_super(struct super_block *sb)
678{
679 mntput(HPPFS_I(sb->s_root->d_inode)->proc_mnt);
680}
681
668static const struct super_operations hppfs_sbops = { 682static const struct super_operations hppfs_sbops = {
669 .alloc_inode = hppfs_alloc_inode, 683 .alloc_inode = hppfs_alloc_inode,
670 .destroy_inode = hppfs_destroy_inode, 684 .destroy_inode = hppfs_destroy_inode,
671 .delete_inode = hppfs_delete_inode, 685 .delete_inode = hppfs_delete_inode,
672 .statfs = hppfs_statfs, 686 .statfs = hppfs_statfs,
687 .put_super = hppfs_put_super,
673}; 688};
674 689
675static int hppfs_readlink(struct dentry *dentry, char __user *buffer, int buflen) 690static int hppfs_readlink(struct dentry *dentry, char __user *buffer,
691 int buflen)
676{ 692{
677 struct file *proc_file; 693 struct file *proc_file;
678 struct dentry *proc_dentry; 694 struct dentry *proc_dentry;
695 struct vfsmount *proc_mnt;
679 int ret; 696 int ret;
680 697
681 proc_dentry = HPPFS_I(dentry->d_inode)->proc_dentry; 698 proc_dentry = HPPFS_I(dentry->d_inode)->proc_dentry;
682 proc_file = dentry_open(dget(proc_dentry), NULL, O_RDONLY); 699 proc_mnt = HPPFS_I(dentry->d_inode)->proc_mnt;
700
701 proc_file = dentry_open(dget(proc_dentry), mntget(proc_mnt), O_RDONLY);
683 if (IS_ERR(proc_file)) 702 if (IS_ERR(proc_file))
684 return PTR_ERR(proc_file); 703 return PTR_ERR(proc_file);
685 704
@@ -694,10 +713,13 @@ static void* hppfs_follow_link(struct dentry *dentry, struct nameidata *nd)
694{ 713{
695 struct file *proc_file; 714 struct file *proc_file;
696 struct dentry *proc_dentry; 715 struct dentry *proc_dentry;
716 struct vfsmount *proc_mnt;
697 void *ret; 717 void *ret;
698 718
699 proc_dentry = HPPFS_I(dentry->d_inode)->proc_dentry; 719 proc_dentry = HPPFS_I(dentry->d_inode)->proc_dentry;
700 proc_file = dentry_open(dget(proc_dentry), NULL, O_RDONLY); 720 proc_mnt = HPPFS_I(dentry->d_inode)->proc_mnt;
721
722 proc_file = dentry_open(dget(proc_dentry), mntget(proc_mnt), O_RDONLY);
701 if (IS_ERR(proc_file)) 723 if (IS_ERR(proc_file))
702 return proc_file; 724 return proc_file;
703 725
@@ -717,44 +739,43 @@ static const struct inode_operations hppfs_link_iops = {
717 .follow_link = hppfs_follow_link, 739 .follow_link = hppfs_follow_link,
718}; 740};
719 741
720static int init_inode(struct inode *inode, struct dentry *dentry) 742static int init_inode(struct inode *inode, struct dentry *dentry,
743 struct vfsmount *mnt)
721{ 744{
722 if(S_ISDIR(dentry->d_inode->i_mode)){ 745 if (S_ISDIR(dentry->d_inode->i_mode)) {
723 inode->i_op = &hppfs_dir_iops; 746 inode->i_op = &hppfs_dir_iops;
724 inode->i_fop = &hppfs_dir_fops; 747 inode->i_fop = &hppfs_dir_fops;
725 } 748 } 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; 749 inode->i_op = &hppfs_link_iops;
728 inode->i_fop = &hppfs_file_fops; 750 inode->i_fop = &hppfs_file_fops;
729 } 751 } else {
730 else {
731 inode->i_op = &hppfs_file_iops; 752 inode->i_op = &hppfs_file_iops;
732 inode->i_fop = &hppfs_file_fops; 753 inode->i_fop = &hppfs_file_fops;
733 } 754 }
734 755
735 HPPFS_I(inode)->proc_dentry = dentry; 756 HPPFS_I(inode)->proc_dentry = dentry;
757 HPPFS_I(inode)->proc_mnt = mnt;
736 758
737 return(0); 759 return 0;
738} 760}
739 761
740static int hppfs_fill_super(struct super_block *sb, void *d, int silent) 762static int hppfs_fill_super(struct super_block *sb, void *d, int silent)
741{ 763{
742 struct inode *root_inode; 764 struct inode *root_inode;
743 struct file_system_type *procfs; 765 struct file_system_type *procfs;
744 struct super_block *proc_sb; 766 struct vfsmount *proc_mnt;
745 int err; 767 int err;
746 768
747 err = -ENOENT; 769 err = -ENOENT;
748 procfs = get_fs_type("proc"); 770 procfs = get_fs_type("proc");
749 if(procfs == NULL) 771 if (!procfs)
750 goto out; 772 goto out;
751 773
752 if(list_empty(&procfs->fs_supers)) 774 proc_mnt = vfs_kern_mount(procfs, 0, procfs->name, NULL);
775 put_filesystem(procfs);
776 if (IS_ERR(proc_mnt))
753 goto out; 777 goto out;
754 778
755 proc_sb = list_entry(procfs->fs_supers.next, struct super_block,
756 s_instances);
757
758 sb->s_blocksize = 1024; 779 sb->s_blocksize = 1024;
759 sb->s_blocksize_bits = 10; 780 sb->s_blocksize_bits = 10;
760 sb->s_magic = HPPFS_SUPER_MAGIC; 781 sb->s_magic = HPPFS_SUPER_MAGIC;
@@ -766,21 +787,23 @@ static int hppfs_fill_super(struct super_block *sb, void *d, int silent)
766 goto out; 787 goto out;
767 } 788 }
768 789
769 err = init_inode(root_inode, proc_sb->s_root); 790 err = init_inode(root_inode, proc_mnt->mnt_sb->s_root, proc_mnt);
770 if(err) 791 if (err)
771 goto out_put; 792 goto out_iput;
772 793
773 err = -ENOMEM; 794 err = -ENOMEM;
774 sb->s_root = d_alloc_root(root_inode); 795 sb->s_root = d_alloc_root(root_inode);
775 if(sb->s_root == NULL) 796 if (!sb->s_root)
776 goto out_put; 797 goto out_iput;
777 798
778 hppfs_read_inode(root_inode); 799 hppfs_read_inode(root_inode);
779 800
780 return(0); 801 return 0;
781 802
782 out_put: 803 out_iput:
783 iput(root_inode); 804 iput(root_inode);
805 out_mntput:
806 mntput(proc_mnt);
784 out: 807 out:
785 return(err); 808 return(err);
786} 809}
@@ -802,7 +825,7 @@ static struct file_system_type hppfs_type = {
802 825
803static int __init init_hppfs(void) 826static int __init init_hppfs(void)
804{ 827{
805 return(register_filesystem(&hppfs_type)); 828 return register_filesystem(&hppfs_type);
806} 829}
807 830
808static void __exit exit_hppfs(void) 831static void __exit exit_hppfs(void)
@@ -813,14 +836,3 @@ static void __exit exit_hppfs(void)
813module_init(init_hppfs) 836module_init(init_hppfs)
814module_exit(exit_hppfs) 837module_exit(exit_hppfs)
815MODULE_LICENSE("GPL"); 838MODULE_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 */