aboutsummaryrefslogtreecommitdiffstats
path: root/fs/hostfs/hostfs_kern.c
diff options
context:
space:
mode:
authorJeff Dike <jdike@addtoit.com>2007-10-16 04:27:13 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-10-16 12:43:07 -0400
commit84b3db04ca15a90273745e391462faf658b1e825 (patch)
tree0a2d3e591ab26d0a98d492119396497210a351ec /fs/hostfs/hostfs_kern.c
parentbaabd156e243e513873417b62e51346ece609934 (diff)
uml: fix hostfs style
Style fixes in hostfs. Signed-off-by: Jeff Dike <jdike@linux.intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/hostfs/hostfs_kern.c')
-rw-r--r--fs/hostfs/hostfs_kern.c226
1 files changed, 115 insertions, 111 deletions
diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
index 39b0cdcc94d0..8966b050196e 100644
--- a/fs/hostfs/hostfs_kern.c
+++ b/fs/hostfs/hostfs_kern.c
@@ -6,21 +6,14 @@
6 * 2003-02-10 Petr Baudis <pasky@ucw.cz> 6 * 2003-02-10 Petr Baudis <pasky@ucw.cz>
7 */ 7 */
8 8
9#include <linux/stddef.h>
10#include <linux/fs.h> 9#include <linux/fs.h>
11#include <linux/module.h> 10#include <linux/module.h>
12#include <linux/init.h> 11#include <linux/mm.h>
13#include <linux/slab.h>
14#include <linux/pagemap.h> 12#include <linux/pagemap.h>
15#include <linux/blkdev.h>
16#include <linux/list.h>
17#include <linux/statfs.h> 13#include <linux/statfs.h>
18#include <linux/kdev_t.h>
19#include <asm/uaccess.h>
20#include "hostfs.h" 14#include "hostfs.h"
21#include "kern_util.h"
22#include "kern.h"
23#include "init.h" 15#include "init.h"
16#include "kern.h"
24 17
25struct hostfs_inode_info { 18struct hostfs_inode_info {
26 char *host_filename; 19 char *host_filename;
@@ -61,18 +54,18 @@ static int __init hostfs_args(char *options, int *add)
61 char *ptr; 54 char *ptr;
62 55
63 ptr = strchr(options, ','); 56 ptr = strchr(options, ',');
64 if(ptr != NULL) 57 if (ptr != NULL)
65 *ptr++ = '\0'; 58 *ptr++ = '\0';
66 if(*options != '\0') 59 if (*options != '\0')
67 root_ino = options; 60 root_ino = options;
68 61
69 options = ptr; 62 options = ptr;
70 while(options){ 63 while (options) {
71 ptr = strchr(options, ','); 64 ptr = strchr(options, ',');
72 if(ptr != NULL) 65 if (ptr != NULL)
73 *ptr++ = '\0'; 66 *ptr++ = '\0';
74 if(*options != '\0'){ 67 if (*options != '\0') {
75 if(!strcmp(options, "append")) 68 if (!strcmp(options, "append"))
76 append = 1; 69 append = 1;
77 else printf("hostfs_args - unsupported option - %s\n", 70 else printf("hostfs_args - unsupported option - %s\n",
78 options); 71 options);
@@ -102,7 +95,7 @@ static char *dentry_name(struct dentry *dentry, int extra)
102 95
103 len = 0; 96 len = 0;
104 parent = dentry; 97 parent = dentry;
105 while(parent->d_parent != parent){ 98 while (parent->d_parent != parent) {
106 len += parent->d_name.len + 1; 99 len += parent->d_name.len + 1;
107 parent = parent->d_parent; 100 parent = parent->d_parent;
108 } 101 }
@@ -110,12 +103,12 @@ static char *dentry_name(struct dentry *dentry, int extra)
110 root = HOSTFS_I(parent->d_inode)->host_filename; 103 root = HOSTFS_I(parent->d_inode)->host_filename;
111 len += strlen(root); 104 len += strlen(root);
112 name = kmalloc(len + extra + 1, GFP_KERNEL); 105 name = kmalloc(len + extra + 1, GFP_KERNEL);
113 if(name == NULL) 106 if (name == NULL)
114 return NULL; 107 return NULL;
115 108
116 name[len] = '\0'; 109 name[len] = '\0';
117 parent = dentry; 110 parent = dentry;
118 while(parent->d_parent != parent){ 111 while (parent->d_parent != parent) {
119 len -= parent->d_name.len + 1; 112 len -= parent->d_name.len + 1;
120 name[len] = '/'; 113 name[len] = '/';
121 strncpy(&name[len + 1], parent->d_name.name, 114 strncpy(&name[len + 1], parent->d_name.name,
@@ -136,7 +129,8 @@ static char *inode_name(struct inode *ino, int extra)
136 129
137static int read_name(struct inode *ino, char *name) 130static int read_name(struct inode *ino, char *name)
138{ 131{
139 /* The non-int inode fields are copied into ints by stat_file and 132 /*
133 * The non-int inode fields are copied into ints by stat_file and
140 * then copied into the inode because passing the actual pointers 134 * then copied into the inode because passing the actual pointers
141 * in and having them treated as int * breaks on big-endian machines 135 * in and having them treated as int * breaks on big-endian machines
142 */ 136 */
@@ -149,7 +143,7 @@ static int read_name(struct inode *ino, char *name)
149 err = stat_file(name, &i_ino, &i_mode, &i_nlink, &ino->i_uid, 143 err = stat_file(name, &i_ino, &i_mode, &i_nlink, &ino->i_uid,
150 &ino->i_gid, &i_size, &ino->i_atime, &ino->i_mtime, 144 &ino->i_gid, &i_size, &ino->i_atime, &ino->i_mtime,
151 &ino->i_ctime, &i_blksize, &i_blocks, -1); 145 &ino->i_ctime, &i_blksize, &i_blocks, -1);
152 if(err) 146 if (err)
153 return err; 147 return err;
154 148
155 ino->i_ino = i_ino; 149 ino->i_ino = i_ino;
@@ -166,33 +160,33 @@ static char *follow_link(char *link)
166 char *name, *resolved, *end; 160 char *name, *resolved, *end;
167 161
168 len = 64; 162 len = 64;
169 while(1){ 163 while (1) {
170 n = -ENOMEM; 164 n = -ENOMEM;
171 name = kmalloc(len, GFP_KERNEL); 165 name = kmalloc(len, GFP_KERNEL);
172 if(name == NULL) 166 if (name == NULL)
173 goto out; 167 goto out;
174 168
175 n = do_readlink(link, name, len); 169 n = do_readlink(link, name, len);
176 if(n < len) 170 if (n < len)
177 break; 171 break;
178 len *= 2; 172 len *= 2;
179 kfree(name); 173 kfree(name);
180 } 174 }
181 if(n < 0) 175 if (n < 0)
182 goto out_free; 176 goto out_free;
183 177
184 if(*name == '/') 178 if (*name == '/')
185 return name; 179 return name;
186 180
187 end = strrchr(link, '/'); 181 end = strrchr(link, '/');
188 if(end == NULL) 182 if (end == NULL)
189 return name; 183 return name;
190 184
191 *(end + 1) = '\0'; 185 *(end + 1) = '\0';
192 len = strlen(link) + strlen(name) + 1; 186 len = strlen(link) + strlen(name) + 1;
193 187
194 resolved = kmalloc(len, GFP_KERNEL); 188 resolved = kmalloc(len, GFP_KERNEL);
195 if(resolved == NULL){ 189 if (resolved == NULL) {
196 n = -ENOMEM; 190 n = -ENOMEM;
197 goto out_free; 191 goto out_free;
198 } 192 }
@@ -213,20 +207,21 @@ static int read_inode(struct inode *ino)
213 char *name; 207 char *name;
214 int err = 0; 208 int err = 0;
215 209
216 /* Unfortunately, we are called from iget() when we don't have a dentry 210 /*
211 * Unfortunately, we are called from iget() when we don't have a dentry
217 * allocated yet. 212 * allocated yet.
218 */ 213 */
219 if(list_empty(&ino->i_dentry)) 214 if (list_empty(&ino->i_dentry))
220 goto out; 215 goto out;
221 216
222 err = -ENOMEM; 217 err = -ENOMEM;
223 name = inode_name(ino, 0); 218 name = inode_name(ino, 0);
224 if(name == NULL) 219 if (name == NULL)
225 goto out; 220 goto out;
226 221
227 if(file_type(name, NULL, NULL) == OS_TYPE_SYMLINK){ 222 if (file_type(name, NULL, NULL) == OS_TYPE_SYMLINK) {
228 name = follow_link(name); 223 name = follow_link(name);
229 if(IS_ERR(name)){ 224 if (IS_ERR(name)) {
230 err = PTR_ERR(name); 225 err = PTR_ERR(name);
231 goto out; 226 goto out;
232 } 227 }
@@ -240,7 +235,8 @@ static int read_inode(struct inode *ino)
240 235
241int hostfs_statfs(struct dentry *dentry, struct kstatfs *sf) 236int hostfs_statfs(struct dentry *dentry, struct kstatfs *sf)
242{ 237{
243 /* do_statfs uses struct statfs64 internally, but the linux kernel 238 /*
239 * do_statfs uses struct statfs64 internally, but the linux kernel
244 * struct statfs still has 32-bit versions for most of these fields, 240 * struct statfs still has 32-bit versions for most of these fields,
245 * so we convert them here 241 * so we convert them here
246 */ 242 */
@@ -255,7 +251,7 @@ int hostfs_statfs(struct dentry *dentry, struct kstatfs *sf)
255 &sf->f_bsize, &f_blocks, &f_bfree, &f_bavail, &f_files, 251 &sf->f_bsize, &f_blocks, &f_bfree, &f_bavail, &f_files,
256 &f_ffree, &sf->f_fsid, sizeof(sf->f_fsid), 252 &f_ffree, &sf->f_fsid, sizeof(sf->f_fsid),
257 &sf->f_namelen, sf->f_spare); 253 &sf->f_namelen, sf->f_spare);
258 if(err) 254 if (err)
259 return err; 255 return err;
260 sf->f_blocks = f_blocks; 256 sf->f_blocks = f_blocks;
261 sf->f_bfree = f_bfree; 257 sf->f_bfree = f_bfree;
@@ -271,7 +267,7 @@ static struct inode *hostfs_alloc_inode(struct super_block *sb)
271 struct hostfs_inode_info *hi; 267 struct hostfs_inode_info *hi;
272 268
273 hi = kmalloc(sizeof(*hi), GFP_KERNEL); 269 hi = kmalloc(sizeof(*hi), GFP_KERNEL);
274 if(hi == NULL) 270 if (hi == NULL)
275 return NULL; 271 return NULL;
276 272
277 *hi = ((struct hostfs_inode_info) { .host_filename = NULL, 273 *hi = ((struct hostfs_inode_info) { .host_filename = NULL,
@@ -284,7 +280,7 @@ static struct inode *hostfs_alloc_inode(struct super_block *sb)
284static void hostfs_delete_inode(struct inode *inode) 280static void hostfs_delete_inode(struct inode *inode)
285{ 281{
286 truncate_inode_pages(&inode->i_data, 0); 282 truncate_inode_pages(&inode->i_data, 0);
287 if(HOSTFS_I(inode)->fd != -1) { 283 if (HOSTFS_I(inode)->fd != -1) {
288 close_file(&HOSTFS_I(inode)->fd); 284 close_file(&HOSTFS_I(inode)->fd);
289 HOSTFS_I(inode)->fd = -1; 285 HOSTFS_I(inode)->fd = -1;
290 } 286 }
@@ -295,9 +291,11 @@ static void hostfs_destroy_inode(struct inode *inode)
295{ 291{
296 kfree(HOSTFS_I(inode)->host_filename); 292 kfree(HOSTFS_I(inode)->host_filename);
297 293
298 /*XXX: This should not happen, probably. The check is here for 294 /*
299 * additional safety.*/ 295 * XXX: This should not happen, probably. The check is here for
300 if(HOSTFS_I(inode)->fd != -1) { 296 * additional safety.
297 */
298 if (HOSTFS_I(inode)->fd != -1) {
301 close_file(&HOSTFS_I(inode)->fd); 299 close_file(&HOSTFS_I(inode)->fd);
302 printk(KERN_DEBUG "Closing host fd in .destroy_inode\n"); 300 printk(KERN_DEBUG "Closing host fd in .destroy_inode\n");
303 } 301 }
@@ -327,17 +325,17 @@ int hostfs_readdir(struct file *file, void *ent, filldir_t filldir)
327 int error, len; 325 int error, len;
328 326
329 name = dentry_name(file->f_path.dentry, 0); 327 name = dentry_name(file->f_path.dentry, 0);
330 if(name == NULL) 328 if (name == NULL)
331 return -ENOMEM; 329 return -ENOMEM;
332 dir = open_dir(name, &error); 330 dir = open_dir(name, &error);
333 kfree(name); 331 kfree(name);
334 if(dir == NULL) 332 if (dir == NULL)
335 return -error; 333 return -error;
336 next = file->f_pos; 334 next = file->f_pos;
337 while((name = read_dir(dir, &next, &ino, &len)) != NULL){ 335 while ((name = read_dir(dir, &next, &ino, &len)) != NULL) {
338 error = (*filldir)(ent, name, len, file->f_pos, 336 error = (*filldir)(ent, name, len, file->f_pos,
339 ino, DT_UNKNOWN); 337 ino, DT_UNKNOWN);
340 if(error) break; 338 if (error) break;
341 file->f_pos = next; 339 file->f_pos = next;
342 } 340 }
343 close_dir(dir); 341 close_dir(dir);
@@ -350,32 +348,33 @@ int hostfs_file_open(struct inode *ino, struct file *file)
350 int mode = 0, r = 0, w = 0, fd; 348 int mode = 0, r = 0, w = 0, fd;
351 349
352 mode = file->f_mode & (FMODE_READ | FMODE_WRITE); 350 mode = file->f_mode & (FMODE_READ | FMODE_WRITE);
353 if((mode & HOSTFS_I(ino)->mode) == mode) 351 if ((mode & HOSTFS_I(ino)->mode) == mode)
354 return 0; 352 return 0;
355 353
356 /* The file may already have been opened, but with the wrong access, 354 /*
355 * The file may already have been opened, but with the wrong access,
357 * so this resets things and reopens the file with the new access. 356 * so this resets things and reopens the file with the new access.
358 */ 357 */
359 if(HOSTFS_I(ino)->fd != -1){ 358 if (HOSTFS_I(ino)->fd != -1) {
360 close_file(&HOSTFS_I(ino)->fd); 359 close_file(&HOSTFS_I(ino)->fd);
361 HOSTFS_I(ino)->fd = -1; 360 HOSTFS_I(ino)->fd = -1;
362 } 361 }
363 362
364 HOSTFS_I(ino)->mode |= mode; 363 HOSTFS_I(ino)->mode |= mode;
365 if(HOSTFS_I(ino)->mode & FMODE_READ) 364 if (HOSTFS_I(ino)->mode & FMODE_READ)
366 r = 1; 365 r = 1;
367 if(HOSTFS_I(ino)->mode & FMODE_WRITE) 366 if (HOSTFS_I(ino)->mode & FMODE_WRITE)
368 w = 1; 367 w = 1;
369 if(w) 368 if (w)
370 r = 1; 369 r = 1;
371 370
372 name = dentry_name(file->f_path.dentry, 0); 371 name = dentry_name(file->f_path.dentry, 0);
373 if(name == NULL) 372 if (name == NULL)
374 return -ENOMEM; 373 return -ENOMEM;
375 374
376 fd = open_file(name, r, w, append); 375 fd = open_file(name, r, w, append);
377 kfree(name); 376 kfree(name);
378 if(fd < 0) 377 if (fd < 0)
379 return fd; 378 return fd;
380 FILE_HOSTFS_I(file)->fd = fd; 379 FILE_HOSTFS_I(file)->fd = fd;
381 380
@@ -423,7 +422,7 @@ int hostfs_writepage(struct page *page, struct writeback_control *wbc)
423 base = ((unsigned long long) page->index) << PAGE_CACHE_SHIFT; 422 base = ((unsigned long long) page->index) << PAGE_CACHE_SHIFT;
424 423
425 err = write_file(HOSTFS_I(inode)->fd, &base, buffer, count); 424 err = write_file(HOSTFS_I(inode)->fd, &base, buffer, count);
426 if(err != count){ 425 if (err != count) {
427 ClearPageUptodate(page); 426 ClearPageUptodate(page);
428 goto out; 427 goto out;
429 } 428 }
@@ -452,7 +451,8 @@ int hostfs_readpage(struct file *file, struct page *page)
452 buffer = kmap(page); 451 buffer = kmap(page);
453 err = read_file(FILE_HOSTFS_I(file)->fd, &start, buffer, 452 err = read_file(FILE_HOSTFS_I(file)->fd, &start, buffer,
454 PAGE_CACHE_SIZE); 453 PAGE_CACHE_SIZE);
455 if(err < 0) goto out; 454 if (err < 0)
455 goto out;
456 456
457 memset(&buffer[err], 0, PAGE_CACHE_SIZE - err); 457 memset(&buffer[err], 0, PAGE_CACHE_SIZE - err);
458 458
@@ -494,7 +494,8 @@ int hostfs_write_end(struct file *file, struct address_space *mapping,
494 if (!PageUptodate(page) && err == PAGE_CACHE_SIZE) 494 if (!PageUptodate(page) && err == PAGE_CACHE_SIZE)
495 SetPageUptodate(page); 495 SetPageUptodate(page);
496 496
497 /* If err > 0, write_file has added err to pos, so we are comparing 497 /*
498 * If err > 0, write_file has added err to pos, so we are comparing
498 * i_size against the last byte written. 499 * i_size against the last byte written.
499 */ 500 */
500 if (err > 0 && (pos > inode->i_size)) 501 if (err > 0 && (pos > inode->i_size))
@@ -520,28 +521,28 @@ static int init_inode(struct inode *inode, struct dentry *dentry)
520 int maj, min; 521 int maj, min;
521 dev_t rdev = 0; 522 dev_t rdev = 0;
522 523
523 if(dentry){ 524 if (dentry) {
524 name = dentry_name(dentry, 0); 525 name = dentry_name(dentry, 0);
525 if(name == NULL) 526 if (name == NULL)
526 goto out; 527 goto out;
527 type = file_type(name, &maj, &min); 528 type = file_type(name, &maj, &min);
528 /*Reencode maj and min with the kernel encoding.*/ 529 /* Reencode maj and min with the kernel encoding.*/
529 rdev = MKDEV(maj, min); 530 rdev = MKDEV(maj, min);
530 kfree(name); 531 kfree(name);
531 } 532 }
532 else type = OS_TYPE_DIR; 533 else type = OS_TYPE_DIR;
533 534
534 err = 0; 535 err = 0;
535 if(type == OS_TYPE_SYMLINK) 536 if (type == OS_TYPE_SYMLINK)
536 inode->i_op = &page_symlink_inode_operations; 537 inode->i_op = &page_symlink_inode_operations;
537 else if(type == OS_TYPE_DIR) 538 else if (type == OS_TYPE_DIR)
538 inode->i_op = &hostfs_dir_iops; 539 inode->i_op = &hostfs_dir_iops;
539 else inode->i_op = &hostfs_iops; 540 else inode->i_op = &hostfs_iops;
540 541
541 if(type == OS_TYPE_DIR) inode->i_fop = &hostfs_dir_fops; 542 if (type == OS_TYPE_DIR) inode->i_fop = &hostfs_dir_fops;
542 else inode->i_fop = &hostfs_file_fops; 543 else inode->i_fop = &hostfs_file_fops;
543 544
544 if(type == OS_TYPE_SYMLINK) 545 if (type == OS_TYPE_SYMLINK)
545 inode->i_mapping->a_ops = &hostfs_link_aops; 546 inode->i_mapping->a_ops = &hostfs_link_aops;
546 else inode->i_mapping->a_ops = &hostfs_aops; 547 else inode->i_mapping->a_ops = &hostfs_aops;
547 548
@@ -564,7 +565,7 @@ static int init_inode(struct inode *inode, struct dentry *dentry)
564} 565}
565 566
566int hostfs_create(struct inode *dir, struct dentry *dentry, int mode, 567int hostfs_create(struct inode *dir, struct dentry *dentry, int mode,
567 struct nameidata *nd) 568 struct nameidata *nd)
568{ 569{
569 struct inode *inode; 570 struct inode *inode;
570 char *name; 571 char *name;
@@ -572,27 +573,28 @@ int hostfs_create(struct inode *dir, struct dentry *dentry, int mode,
572 573
573 error = -ENOMEM; 574 error = -ENOMEM;
574 inode = iget(dir->i_sb, 0); 575 inode = iget(dir->i_sb, 0);
575 if(inode == NULL) goto out; 576 if (inode == NULL)
577 goto out;
576 578
577 error = init_inode(inode, dentry); 579 error = init_inode(inode, dentry);
578 if(error) 580 if (error)
579 goto out_put; 581 goto out_put;
580 582
581 error = -ENOMEM; 583 error = -ENOMEM;
582 name = dentry_name(dentry, 0); 584 name = dentry_name(dentry, 0);
583 if(name == NULL) 585 if (name == NULL)
584 goto out_put; 586 goto out_put;
585 587
586 fd = file_create(name, 588 fd = file_create(name,
587 mode & S_IRUSR, mode & S_IWUSR, mode & S_IXUSR, 589 mode & S_IRUSR, mode & S_IWUSR, mode & S_IXUSR,
588 mode & S_IRGRP, mode & S_IWGRP, mode & S_IXGRP, 590 mode & S_IRGRP, mode & S_IWGRP, mode & S_IXGRP,
589 mode & S_IROTH, mode & S_IWOTH, mode & S_IXOTH); 591 mode & S_IROTH, mode & S_IWOTH, mode & S_IXOTH);
590 if(fd < 0) 592 if (fd < 0)
591 error = fd; 593 error = fd;
592 else error = read_name(inode, name); 594 else error = read_name(inode, name);
593 595
594 kfree(name); 596 kfree(name);
595 if(error) 597 if (error)
596 goto out_put; 598 goto out_put;
597 599
598 HOSTFS_I(inode)->fd = fd; 600 HOSTFS_I(inode)->fd = fd;
@@ -615,25 +617,25 @@ struct dentry *hostfs_lookup(struct inode *ino, struct dentry *dentry,
615 617
616 err = -ENOMEM; 618 err = -ENOMEM;
617 inode = iget(ino->i_sb, 0); 619 inode = iget(ino->i_sb, 0);
618 if(inode == NULL) 620 if (inode == NULL)
619 goto out; 621 goto out;
620 622
621 err = init_inode(inode, dentry); 623 err = init_inode(inode, dentry);
622 if(err) 624 if (err)
623 goto out_put; 625 goto out_put;
624 626
625 err = -ENOMEM; 627 err = -ENOMEM;
626 name = dentry_name(dentry, 0); 628 name = dentry_name(dentry, 0);
627 if(name == NULL) 629 if (name == NULL)
628 goto out_put; 630 goto out_put;
629 631
630 err = read_name(inode, name); 632 err = read_name(inode, name);
631 kfree(name); 633 kfree(name);
632 if(err == -ENOENT){ 634 if (err == -ENOENT) {
633 iput(inode); 635 iput(inode);
634 inode = NULL; 636 inode = NULL;
635 } 637 }
636 else if(err) 638 else if (err)
637 goto out_put; 639 goto out_put;
638 640
639 d_add(dentry, inode); 641 d_add(dentry, inode);
@@ -652,7 +654,7 @@ static char *inode_dentry_name(struct inode *ino, struct dentry *dentry)
652 int len; 654 int len;
653 655
654 file = inode_name(ino, dentry->d_name.len + 1); 656 file = inode_name(ino, dentry->d_name.len + 1);
655 if(file == NULL) 657 if (file == NULL)
656 return NULL; 658 return NULL;
657 strcat(file, "/"); 659 strcat(file, "/");
658 len = strlen(file); 660 len = strlen(file);
@@ -666,10 +668,10 @@ int hostfs_link(struct dentry *to, struct inode *ino, struct dentry *from)
666 char *from_name, *to_name; 668 char *from_name, *to_name;
667 int err; 669 int err;
668 670
669 if((from_name = inode_dentry_name(ino, from)) == NULL) 671 if ((from_name = inode_dentry_name(ino, from)) == NULL)
670 return -ENOMEM; 672 return -ENOMEM;
671 to_name = dentry_name(to, 0); 673 to_name = dentry_name(to, 0);
672 if(to_name == NULL){ 674 if (to_name == NULL) {
673 kfree(from_name); 675 kfree(from_name);
674 return -ENOMEM; 676 return -ENOMEM;
675 } 677 }
@@ -684,9 +686,9 @@ int hostfs_unlink(struct inode *ino, struct dentry *dentry)
684 char *file; 686 char *file;
685 int err; 687 int err;
686 688
687 if((file = inode_dentry_name(ino, dentry)) == NULL) 689 if ((file = inode_dentry_name(ino, dentry)) == NULL)
688 return -ENOMEM; 690 return -ENOMEM;
689 if(append) 691 if (append)
690 return -EPERM; 692 return -EPERM;
691 693
692 err = unlink_file(file); 694 err = unlink_file(file);
@@ -699,7 +701,7 @@ int hostfs_symlink(struct inode *ino, struct dentry *dentry, const char *to)
699 char *file; 701 char *file;
700 int err; 702 int err;
701 703
702 if((file = inode_dentry_name(ino, dentry)) == NULL) 704 if ((file = inode_dentry_name(ino, dentry)) == NULL)
703 return -ENOMEM; 705 return -ENOMEM;
704 err = make_symlink(file, to); 706 err = make_symlink(file, to);
705 kfree(file); 707 kfree(file);
@@ -711,7 +713,7 @@ int hostfs_mkdir(struct inode *ino, struct dentry *dentry, int mode)
711 char *file; 713 char *file;
712 int err; 714 int err;
713 715
714 if((file = inode_dentry_name(ino, dentry)) == NULL) 716 if ((file = inode_dentry_name(ino, dentry)) == NULL)
715 return -ENOMEM; 717 return -ENOMEM;
716 err = do_mkdir(file, mode); 718 err = do_mkdir(file, mode);
717 kfree(file); 719 kfree(file);
@@ -723,7 +725,7 @@ int hostfs_rmdir(struct inode *ino, struct dentry *dentry)
723 char *file; 725 char *file;
724 int err; 726 int err;
725 727
726 if((file = inode_dentry_name(ino, dentry)) == NULL) 728 if ((file = inode_dentry_name(ino, dentry)) == NULL)
727 return -ENOMEM; 729 return -ENOMEM;
728 err = do_rmdir(file); 730 err = do_rmdir(file);
729 kfree(file); 731 kfree(file);
@@ -737,26 +739,26 @@ int hostfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
737 int err = -ENOMEM; 739 int err = -ENOMEM;
738 740
739 inode = iget(dir->i_sb, 0); 741 inode = iget(dir->i_sb, 0);
740 if(inode == NULL) 742 if (inode == NULL)
741 goto out; 743 goto out;
742 744
743 err = init_inode(inode, dentry); 745 err = init_inode(inode, dentry);
744 if(err) 746 if (err)
745 goto out_put; 747 goto out_put;
746 748
747 err = -ENOMEM; 749 err = -ENOMEM;
748 name = dentry_name(dentry, 0); 750 name = dentry_name(dentry, 0);
749 if(name == NULL) 751 if (name == NULL)
750 goto out_put; 752 goto out_put;
751 753
752 init_special_inode(inode, mode, dev); 754 init_special_inode(inode, mode, dev);
753 err = do_mknod(name, mode, MAJOR(dev), MINOR(dev)); 755 err = do_mknod(name, mode, MAJOR(dev), MINOR(dev));
754 if(err) 756 if (err)
755 goto out_free; 757 goto out_free;
756 758
757 err = read_name(inode, name); 759 err = read_name(inode, name);
758 kfree(name); 760 kfree(name);
759 if(err) 761 if (err)
760 goto out_put; 762 goto out_put;
761 763
762 d_instantiate(dentry, inode); 764 d_instantiate(dentry, inode);
@@ -776,9 +778,9 @@ int hostfs_rename(struct inode *from_ino, struct dentry *from,
776 char *from_name, *to_name; 778 char *from_name, *to_name;
777 int err; 779 int err;
778 780
779 if((from_name = inode_dentry_name(from_ino, from)) == NULL) 781 if ((from_name = inode_dentry_name(from_ino, from)) == NULL)
780 return -ENOMEM; 782 return -ENOMEM;
781 if((to_name = inode_dentry_name(to_ino, to)) == NULL){ 783 if ((to_name = inode_dentry_name(to_ino, to)) == NULL) {
782 kfree(from_name); 784 kfree(from_name);
783 return -ENOMEM; 785 return -ENOMEM;
784 } 786 }
@@ -801,12 +803,12 @@ int hostfs_permission(struct inode *ino, int desired, struct nameidata *nd)
801 return -ENOMEM; 803 return -ENOMEM;
802 804
803 if (S_ISCHR(ino->i_mode) || S_ISBLK(ino->i_mode) || 805 if (S_ISCHR(ino->i_mode) || S_ISBLK(ino->i_mode) ||
804 S_ISFIFO(ino->i_mode) || S_ISSOCK(ino->i_mode)) 806 S_ISFIFO(ino->i_mode) || S_ISSOCK(ino->i_mode))
805 err = 0; 807 err = 0;
806 else 808 else
807 err = access_file(name, r, w, x); 809 err = access_file(name, r, w, x);
808 kfree(name); 810 kfree(name);
809 if(!err) 811 if (!err)
810 err = generic_permission(ino, desired, NULL); 812 err = generic_permission(ino, desired, NULL);
811 return err; 813 return err;
812} 814}
@@ -823,50 +825,50 @@ int hostfs_setattr(struct dentry *dentry, struct iattr *attr)
823 if (err) 825 if (err)
824 return err; 826 return err;
825 827
826 if(append) 828 if (append)
827 attr->ia_valid &= ~ATTR_SIZE; 829 attr->ia_valid &= ~ATTR_SIZE;
828 830
829 attrs.ia_valid = 0; 831 attrs.ia_valid = 0;
830 if(attr->ia_valid & ATTR_MODE){ 832 if (attr->ia_valid & ATTR_MODE) {
831 attrs.ia_valid |= HOSTFS_ATTR_MODE; 833 attrs.ia_valid |= HOSTFS_ATTR_MODE;
832 attrs.ia_mode = attr->ia_mode; 834 attrs.ia_mode = attr->ia_mode;
833 } 835 }
834 if(attr->ia_valid & ATTR_UID){ 836 if (attr->ia_valid & ATTR_UID) {
835 attrs.ia_valid |= HOSTFS_ATTR_UID; 837 attrs.ia_valid |= HOSTFS_ATTR_UID;
836 attrs.ia_uid = attr->ia_uid; 838 attrs.ia_uid = attr->ia_uid;
837 } 839 }
838 if(attr->ia_valid & ATTR_GID){ 840 if (attr->ia_valid & ATTR_GID) {
839 attrs.ia_valid |= HOSTFS_ATTR_GID; 841 attrs.ia_valid |= HOSTFS_ATTR_GID;
840 attrs.ia_gid = attr->ia_gid; 842 attrs.ia_gid = attr->ia_gid;
841 } 843 }
842 if(attr->ia_valid & ATTR_SIZE){ 844 if (attr->ia_valid & ATTR_SIZE) {
843 attrs.ia_valid |= HOSTFS_ATTR_SIZE; 845 attrs.ia_valid |= HOSTFS_ATTR_SIZE;
844 attrs.ia_size = attr->ia_size; 846 attrs.ia_size = attr->ia_size;
845 } 847 }
846 if(attr->ia_valid & ATTR_ATIME){ 848 if (attr->ia_valid & ATTR_ATIME) {
847 attrs.ia_valid |= HOSTFS_ATTR_ATIME; 849 attrs.ia_valid |= HOSTFS_ATTR_ATIME;
848 attrs.ia_atime = attr->ia_atime; 850 attrs.ia_atime = attr->ia_atime;
849 } 851 }
850 if(attr->ia_valid & ATTR_MTIME){ 852 if (attr->ia_valid & ATTR_MTIME) {
851 attrs.ia_valid |= HOSTFS_ATTR_MTIME; 853 attrs.ia_valid |= HOSTFS_ATTR_MTIME;
852 attrs.ia_mtime = attr->ia_mtime; 854 attrs.ia_mtime = attr->ia_mtime;
853 } 855 }
854 if(attr->ia_valid & ATTR_CTIME){ 856 if (attr->ia_valid & ATTR_CTIME) {
855 attrs.ia_valid |= HOSTFS_ATTR_CTIME; 857 attrs.ia_valid |= HOSTFS_ATTR_CTIME;
856 attrs.ia_ctime = attr->ia_ctime; 858 attrs.ia_ctime = attr->ia_ctime;
857 } 859 }
858 if(attr->ia_valid & ATTR_ATIME_SET){ 860 if (attr->ia_valid & ATTR_ATIME_SET) {
859 attrs.ia_valid |= HOSTFS_ATTR_ATIME_SET; 861 attrs.ia_valid |= HOSTFS_ATTR_ATIME_SET;
860 } 862 }
861 if(attr->ia_valid & ATTR_MTIME_SET){ 863 if (attr->ia_valid & ATTR_MTIME_SET) {
862 attrs.ia_valid |= HOSTFS_ATTR_MTIME_SET; 864 attrs.ia_valid |= HOSTFS_ATTR_MTIME_SET;
863 } 865 }
864 name = dentry_name(dentry, 0); 866 name = dentry_name(dentry, 0);
865 if(name == NULL) 867 if (name == NULL)
866 return -ENOMEM; 868 return -ENOMEM;
867 err = set_attr(name, &attrs, fd); 869 err = set_attr(name, &attrs, fd);
868 kfree(name); 870 kfree(name);
869 if(err) 871 if (err)
870 return err; 872 return err;
871 873
872 return inode_setattr(dentry->d_inode, attr); 874 return inode_setattr(dentry->d_inode, attr);
@@ -906,13 +908,13 @@ int hostfs_link_readpage(struct file *file, struct page *page)
906 908
907 buffer = kmap(page); 909 buffer = kmap(page);
908 name = inode_name(page->mapping->host, 0); 910 name = inode_name(page->mapping->host, 0);
909 if(name == NULL) 911 if (name == NULL)
910 return -ENOMEM; 912 return -ENOMEM;
911 err = do_readlink(name, buffer, PAGE_CACHE_SIZE); 913 err = do_readlink(name, buffer, PAGE_CACHE_SIZE);
912 kfree(name); 914 kfree(name);
913 if(err == PAGE_CACHE_SIZE) 915 if (err == PAGE_CACHE_SIZE)
914 err = -E2BIG; 916 err = -E2BIG;
915 else if(err > 0){ 917 else if (err > 0) {
916 flush_dcache_page(page); 918 flush_dcache_page(page);
917 SetPageUptodate(page); 919 SetPageUptodate(page);
918 if (PageError(page)) ClearPageError(page); 920 if (PageError(page)) ClearPageError(page);
@@ -945,31 +947,33 @@ static int hostfs_fill_sb_common(struct super_block *sb, void *d, int silent)
945 err = -ENOMEM; 947 err = -ENOMEM;
946 host_root_path = kmalloc(strlen(root_ino) + 1 948 host_root_path = kmalloc(strlen(root_ino) + 1
947 + strlen(req_root) + 1, GFP_KERNEL); 949 + strlen(req_root) + 1, GFP_KERNEL);
948 if(host_root_path == NULL) 950 if (host_root_path == NULL)
949 goto out; 951 goto out;
950 952
951 sprintf(host_root_path, "%s/%s", root_ino, req_root); 953 sprintf(host_root_path, "%s/%s", root_ino, req_root);
952 954
953 root_inode = iget(sb, 0); 955 root_inode = iget(sb, 0);
954 if(root_inode == NULL) 956 if (root_inode == NULL)
955 goto out_free; 957 goto out_free;
956 958
957 err = init_inode(root_inode, NULL); 959 err = init_inode(root_inode, NULL);
958 if(err) 960 if (err)
959 goto out_put; 961 goto out_put;
960 962
961 HOSTFS_I(root_inode)->host_filename = host_root_path; 963 HOSTFS_I(root_inode)->host_filename = host_root_path;
962 /* Avoid that in the error path, iput(root_inode) frees again 964 /*
963 * host_root_path through hostfs_destroy_inode! */ 965 * Avoid that in the error path, iput(root_inode) frees again
966 * host_root_path through hostfs_destroy_inode!
967 */
964 host_root_path = NULL; 968 host_root_path = NULL;
965 969
966 err = -ENOMEM; 970 err = -ENOMEM;
967 sb->s_root = d_alloc_root(root_inode); 971 sb->s_root = d_alloc_root(root_inode);
968 if(sb->s_root == NULL) 972 if (sb->s_root == NULL)
969 goto out_put; 973 goto out_put;
970 974
971 err = read_inode(root_inode); 975 err = read_inode(root_inode);
972 if(err){ 976 if (err) {
973 /* No iput in this case because the dput does that for us */ 977 /* No iput in this case because the dput does that for us */
974 dput(sb->s_root); 978 dput(sb->s_root);
975 sb->s_root = NULL; 979 sb->s_root = NULL;