diff options
Diffstat (limited to 'fs/hostfs')
-rw-r--r-- | fs/hostfs/hostfs.h | 9 | ||||
-rw-r--r-- | fs/hostfs/hostfs_kern.c | 226 | ||||
-rw-r--r-- | fs/hostfs/hostfs_user.c | 139 |
3 files changed, 202 insertions, 172 deletions
diff --git a/fs/hostfs/hostfs.h b/fs/hostfs/hostfs.h index 06e5930515fe..6ae9011b95eb 100644 --- a/fs/hostfs/hostfs.h +++ b/fs/hostfs/hostfs.h | |||
@@ -3,7 +3,8 @@ | |||
3 | 3 | ||
4 | #include "os.h" | 4 | #include "os.h" |
5 | 5 | ||
6 | /* These are exactly the same definitions as in fs.h, but the names are | 6 | /* |
7 | * These are exactly the same definitions as in fs.h, but the names are | ||
7 | * changed so that this file can be included in both kernel and user files. | 8 | * changed so that this file can be included in both kernel and user files. |
8 | */ | 9 | */ |
9 | 10 | ||
@@ -21,7 +22,8 @@ | |||
21 | #define HOSTFS_ATTR_FORCE 512 /* Not a change, but a change it */ | 22 | #define HOSTFS_ATTR_FORCE 512 /* Not a change, but a change it */ |
22 | #define HOSTFS_ATTR_ATTR_FLAG 1024 | 23 | #define HOSTFS_ATTR_ATTR_FLAG 1024 |
23 | 24 | ||
24 | /* If you are very careful, you'll notice that these two are missing: | 25 | /* |
26 | * If you are very careful, you'll notice that these two are missing: | ||
25 | * | 27 | * |
26 | * #define ATTR_KILL_SUID 2048 | 28 | * #define ATTR_KILL_SUID 2048 |
27 | * #define ATTR_KILL_SGID 4096 | 29 | * #define ATTR_KILL_SGID 4096 |
@@ -76,7 +78,8 @@ extern int make_symlink(const char *from, const char *to); | |||
76 | extern int unlink_file(const char *file); | 78 | extern int unlink_file(const char *file); |
77 | extern int do_mkdir(const char *file, int mode); | 79 | extern int do_mkdir(const char *file, int mode); |
78 | extern int do_rmdir(const char *file); | 80 | extern int do_rmdir(const char *file); |
79 | extern int do_mknod(const char *file, int mode, unsigned int major, unsigned int minor); | 81 | extern int do_mknod(const char *file, int mode, unsigned int major, |
82 | unsigned int minor); | ||
80 | extern int link_file(const char *from, const char *to); | 83 | extern int link_file(const char *from, const char *to); |
81 | extern int do_readlink(char *file, char *buf, int size); | 84 | extern int do_readlink(char *file, char *buf, int size); |
82 | extern int rename_file(char *from, char *to); | 85 | extern int rename_file(char *from, char *to); |
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 | ||
25 | struct hostfs_inode_info { | 18 | struct 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 | ||
137 | static int read_name(struct inode *ino, char *name) | 130 | static 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 | ||
241 | int hostfs_statfs(struct dentry *dentry, struct kstatfs *sf) | 236 | int 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) | |||
284 | static void hostfs_delete_inode(struct inode *inode) | 280 | static 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 | ||
566 | int hostfs_create(struct inode *dir, struct dentry *dentry, int mode, | 567 | int 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; |
diff --git a/fs/hostfs/hostfs_user.c b/fs/hostfs/hostfs_user.c index d8d54af1b497..35c1a9f33f47 100644 --- a/fs/hostfs/hostfs_user.c +++ b/fs/hostfs/hostfs_user.c | |||
@@ -3,19 +3,21 @@ | |||
3 | * Licensed under the GPL | 3 | * Licensed under the GPL |
4 | */ | 4 | */ |
5 | 5 | ||
6 | #include <unistd.h> | ||
7 | #include <stdio.h> | 6 | #include <stdio.h> |
8 | #include <fcntl.h> | 7 | #include <stddef.h> |
8 | #include <unistd.h> | ||
9 | #include <dirent.h> | 9 | #include <dirent.h> |
10 | #include <errno.h> | 10 | #include <errno.h> |
11 | #include <utime.h> | 11 | #include <fcntl.h> |
12 | #include <string.h> | 12 | #include <string.h> |
13 | #include <sys/stat.h> | 13 | #include <sys/stat.h> |
14 | #include <sys/time.h> | 14 | #include <sys/time.h> |
15 | #include <sys/types.h> | ||
15 | #include <sys/vfs.h> | 16 | #include <sys/vfs.h> |
16 | #include "hostfs.h" | 17 | #include "hostfs.h" |
17 | #include "kern_util.h" | 18 | #include "os.h" |
18 | #include "user.h" | 19 | #include "user.h" |
20 | #include <utime.h> | ||
19 | 21 | ||
20 | int stat_file(const char *path, unsigned long long *inode_out, int *mode_out, | 22 | int stat_file(const char *path, unsigned long long *inode_out, int *mode_out, |
21 | int *nlink_out, int *uid_out, int *gid_out, | 23 | int *nlink_out, int *uid_out, int *gid_out, |
@@ -25,33 +27,41 @@ int stat_file(const char *path, unsigned long long *inode_out, int *mode_out, | |||
25 | { | 27 | { |
26 | struct stat64 buf; | 28 | struct stat64 buf; |
27 | 29 | ||
28 | if(fd >= 0) { | 30 | if (fd >= 0) { |
29 | if (fstat64(fd, &buf) < 0) | 31 | if (fstat64(fd, &buf) < 0) |
30 | return -errno; | 32 | return -errno; |
31 | } else if(lstat64(path, &buf) < 0) { | 33 | } else if (lstat64(path, &buf) < 0) { |
32 | return -errno; | 34 | return -errno; |
33 | } | 35 | } |
34 | 36 | ||
35 | if(inode_out != NULL) *inode_out = buf.st_ino; | 37 | if (inode_out != NULL) |
36 | if(mode_out != NULL) *mode_out = buf.st_mode; | 38 | *inode_out = buf.st_ino; |
37 | if(nlink_out != NULL) *nlink_out = buf.st_nlink; | 39 | if (mode_out != NULL) |
38 | if(uid_out != NULL) *uid_out = buf.st_uid; | 40 | *mode_out = buf.st_mode; |
39 | if(gid_out != NULL) *gid_out = buf.st_gid; | 41 | if (nlink_out != NULL) |
40 | if(size_out != NULL) *size_out = buf.st_size; | 42 | *nlink_out = buf.st_nlink; |
41 | if(atime_out != NULL) { | 43 | if (uid_out != NULL) |
44 | *uid_out = buf.st_uid; | ||
45 | if (gid_out != NULL) | ||
46 | *gid_out = buf.st_gid; | ||
47 | if (size_out != NULL) | ||
48 | *size_out = buf.st_size; | ||
49 | if (atime_out != NULL) { | ||
42 | atime_out->tv_sec = buf.st_atime; | 50 | atime_out->tv_sec = buf.st_atime; |
43 | atime_out->tv_nsec = 0; | 51 | atime_out->tv_nsec = 0; |
44 | } | 52 | } |
45 | if(mtime_out != NULL) { | 53 | if (mtime_out != NULL) { |
46 | mtime_out->tv_sec = buf.st_mtime; | 54 | mtime_out->tv_sec = buf.st_mtime; |
47 | mtime_out->tv_nsec = 0; | 55 | mtime_out->tv_nsec = 0; |
48 | } | 56 | } |
49 | if(ctime_out != NULL) { | 57 | if (ctime_out != NULL) { |
50 | ctime_out->tv_sec = buf.st_ctime; | 58 | ctime_out->tv_sec = buf.st_ctime; |
51 | ctime_out->tv_nsec = 0; | 59 | ctime_out->tv_nsec = 0; |
52 | } | 60 | } |
53 | if(blksize_out != NULL) *blksize_out = buf.st_blksize; | 61 | if (blksize_out != NULL) |
54 | if(blocks_out != NULL) *blocks_out = buf.st_blocks; | 62 | *blksize_out = buf.st_blksize; |
63 | if (blocks_out != NULL) | ||
64 | *blocks_out = buf.st_blocks; | ||
55 | return 0; | 65 | return 0; |
56 | } | 66 | } |
57 | 67 | ||
@@ -59,21 +69,29 @@ int file_type(const char *path, int *maj, int *min) | |||
59 | { | 69 | { |
60 | struct stat64 buf; | 70 | struct stat64 buf; |
61 | 71 | ||
62 | if(lstat64(path, &buf) < 0) | 72 | if (lstat64(path, &buf) < 0) |
63 | return -errno; | 73 | return -errno; |
64 | /*We cannot pass rdev as is because glibc and the kernel disagree | 74 | /* |
65 | *about its definition.*/ | 75 | * We cannot pass rdev as is because glibc and the kernel disagree |
66 | if(maj != NULL) | 76 | * about its definition. |
77 | */ | ||
78 | if (maj != NULL) | ||
67 | *maj = major(buf.st_rdev); | 79 | *maj = major(buf.st_rdev); |
68 | if(min != NULL) | 80 | if (min != NULL) |
69 | *min = minor(buf.st_rdev); | 81 | *min = minor(buf.st_rdev); |
70 | 82 | ||
71 | if(S_ISDIR(buf.st_mode)) return OS_TYPE_DIR; | 83 | if (S_ISDIR(buf.st_mode)) |
72 | else if(S_ISLNK(buf.st_mode)) return OS_TYPE_SYMLINK; | 84 | return OS_TYPE_DIR; |
73 | else if(S_ISCHR(buf.st_mode)) return OS_TYPE_CHARDEV; | 85 | else if (S_ISLNK(buf.st_mode)) |
74 | else if(S_ISBLK(buf.st_mode)) return OS_TYPE_BLOCKDEV; | 86 | return OS_TYPE_SYMLINK; |
75 | else if(S_ISFIFO(buf.st_mode))return OS_TYPE_FIFO; | 87 | else if (S_ISCHR(buf.st_mode)) |
76 | else if(S_ISSOCK(buf.st_mode))return OS_TYPE_SOCK; | 88 | return OS_TYPE_CHARDEV; |
89 | else if (S_ISBLK(buf.st_mode)) | ||
90 | return OS_TYPE_BLOCKDEV; | ||
91 | else if (S_ISFIFO(buf.st_mode)) | ||
92 | return OS_TYPE_FIFO; | ||
93 | else if (S_ISSOCK(buf.st_mode)) | ||
94 | return OS_TYPE_SOCK; | ||
77 | else return OS_TYPE_FILE; | 95 | else return OS_TYPE_FILE; |
78 | } | 96 | } |
79 | 97 | ||
@@ -81,10 +99,13 @@ int access_file(char *path, int r, int w, int x) | |||
81 | { | 99 | { |
82 | int mode = 0; | 100 | int mode = 0; |
83 | 101 | ||
84 | if(r) mode = R_OK; | 102 | if (r) |
85 | if(w) mode |= W_OK; | 103 | mode = R_OK; |
86 | if(x) mode |= X_OK; | 104 | if (w) |
87 | if(access(path, mode) != 0) | 105 | mode |= W_OK; |
106 | if (x) | ||
107 | mode |= X_OK; | ||
108 | if (access(path, mode) != 0) | ||
88 | return -errno; | 109 | return -errno; |
89 | else return 0; | 110 | else return 0; |
90 | } | 111 | } |
@@ -93,18 +114,18 @@ int open_file(char *path, int r, int w, int append) | |||
93 | { | 114 | { |
94 | int mode = 0, fd; | 115 | int mode = 0, fd; |
95 | 116 | ||
96 | if(r && !w) | 117 | if (r && !w) |
97 | mode = O_RDONLY; | 118 | mode = O_RDONLY; |
98 | else if(!r && w) | 119 | else if (!r && w) |
99 | mode = O_WRONLY; | 120 | mode = O_WRONLY; |
100 | else if(r && w) | 121 | else if (r && w) |
101 | mode = O_RDWR; | 122 | mode = O_RDWR; |
102 | else panic("Impossible mode in open_file"); | 123 | else panic("Impossible mode in open_file"); |
103 | 124 | ||
104 | if(append) | 125 | if (append) |
105 | mode |= O_APPEND; | 126 | mode |= O_APPEND; |
106 | fd = open64(path, mode); | 127 | fd = open64(path, mode); |
107 | if(fd < 0) | 128 | if (fd < 0) |
108 | return -errno; | 129 | return -errno; |
109 | else return fd; | 130 | else return fd; |
110 | } | 131 | } |
@@ -115,7 +136,7 @@ void *open_dir(char *path, int *err_out) | |||
115 | 136 | ||
116 | dir = opendir(path); | 137 | dir = opendir(path); |
117 | *err_out = errno; | 138 | *err_out = errno; |
118 | if(dir == NULL) | 139 | if (dir == NULL) |
119 | return NULL; | 140 | return NULL; |
120 | return dir; | 141 | return dir; |
121 | } | 142 | } |
@@ -128,7 +149,7 @@ char *read_dir(void *stream, unsigned long long *pos, | |||
128 | 149 | ||
129 | seekdir(dir, *pos); | 150 | seekdir(dir, *pos); |
130 | ent = readdir(dir); | 151 | ent = readdir(dir); |
131 | if(ent == NULL) | 152 | if (ent == NULL) |
132 | return NULL; | 153 | return NULL; |
133 | *len_out = strlen(ent->d_name); | 154 | *len_out = strlen(ent->d_name); |
134 | *ino_out = ent->d_ino; | 155 | *ino_out = ent->d_ino; |
@@ -141,7 +162,7 @@ int read_file(int fd, unsigned long long *offset, char *buf, int len) | |||
141 | int n; | 162 | int n; |
142 | 163 | ||
143 | n = pread64(fd, buf, len, *offset); | 164 | n = pread64(fd, buf, len, *offset); |
144 | if(n < 0) | 165 | if (n < 0) |
145 | return -errno; | 166 | return -errno; |
146 | *offset += n; | 167 | *offset += n; |
147 | return n; | 168 | return n; |
@@ -152,7 +173,7 @@ int write_file(int fd, unsigned long long *offset, const char *buf, int len) | |||
152 | int n; | 173 | int n; |
153 | 174 | ||
154 | n = pwrite64(fd, buf, len, *offset); | 175 | n = pwrite64(fd, buf, len, *offset); |
155 | if(n < 0) | 176 | if (n < 0) |
156 | return -errno; | 177 | return -errno; |
157 | *offset += n; | 178 | *offset += n; |
158 | return n; | 179 | return n; |
@@ -163,7 +184,7 @@ int lseek_file(int fd, long long offset, int whence) | |||
163 | int ret; | 184 | int ret; |
164 | 185 | ||
165 | ret = lseek64(fd, offset, whence); | 186 | ret = lseek64(fd, offset, whence); |
166 | if(ret < 0) | 187 | if (ret < 0) |
167 | return -errno; | 188 | return -errno; |
168 | return 0; | 189 | return 0; |
169 | } | 190 | } |
@@ -207,7 +228,7 @@ int file_create(char *name, int ur, int uw, int ux, int gr, | |||
207 | mode |= ow ? S_IWOTH : 0; | 228 | mode |= ow ? S_IWOTH : 0; |
208 | mode |= ox ? S_IXOTH : 0; | 229 | mode |= ox ? S_IXOTH : 0; |
209 | fd = open64(name, O_CREAT | O_RDWR, mode); | 230 | fd = open64(name, O_CREAT | O_RDWR, mode); |
210 | if(fd < 0) | 231 | if (fd < 0) |
211 | return -errno; | 232 | return -errno; |
212 | return fd; | 233 | return fd; |
213 | } | 234 | } |
@@ -230,7 +251,7 @@ int set_attr(const char *file, struct hostfs_iattr *attrs, int fd) | |||
230 | if (fd >= 0) { | 251 | if (fd >= 0) { |
231 | if (fchown(fd, attrs->ia_uid, -1)) | 252 | if (fchown(fd, attrs->ia_uid, -1)) |
232 | return -errno; | 253 | return -errno; |
233 | } else if(chown(file, attrs->ia_uid, -1)) { | 254 | } else if (chown(file, attrs->ia_uid, -1)) { |
234 | return -errno; | 255 | return -errno; |
235 | } | 256 | } |
236 | } | 257 | } |
@@ -251,9 +272,11 @@ int set_attr(const char *file, struct hostfs_iattr *attrs, int fd) | |||
251 | } | 272 | } |
252 | } | 273 | } |
253 | 274 | ||
254 | /* Update accessed and/or modified time, in two parts: first set | 275 | /* |
276 | * Update accessed and/or modified time, in two parts: first set | ||
255 | * times according to the changes to perform, and then call futimes() | 277 | * times according to the changes to perform, and then call futimes() |
256 | * or utimes() to apply them. */ | 278 | * or utimes() to apply them. |
279 | */ | ||
257 | ma = (HOSTFS_ATTR_ATIME_SET | HOSTFS_ATTR_MTIME_SET); | 280 | ma = (HOSTFS_ATTR_ATIME_SET | HOSTFS_ATTR_MTIME_SET); |
258 | if (attrs->ia_valid & ma) { | 281 | if (attrs->ia_valid & ma) { |
259 | err = stat_file(file, NULL, NULL, NULL, NULL, NULL, NULL, | 282 | err = stat_file(file, NULL, NULL, NULL, NULL, NULL, NULL, |
@@ -284,11 +307,11 @@ int set_attr(const char *file, struct hostfs_iattr *attrs, int fd) | |||
284 | } | 307 | } |
285 | 308 | ||
286 | /* Note: ctime is not handled */ | 309 | /* Note: ctime is not handled */ |
287 | if(attrs->ia_valid & (HOSTFS_ATTR_ATIME | HOSTFS_ATTR_MTIME)){ | 310 | if (attrs->ia_valid & (HOSTFS_ATTR_ATIME | HOSTFS_ATTR_MTIME)) { |
288 | err = stat_file(file, NULL, NULL, NULL, NULL, NULL, NULL, | 311 | err = stat_file(file, NULL, NULL, NULL, NULL, NULL, NULL, |
289 | &attrs->ia_atime, &attrs->ia_mtime, NULL, | 312 | &attrs->ia_atime, &attrs->ia_mtime, NULL, |
290 | NULL, NULL, fd); | 313 | NULL, NULL, fd); |
291 | if(err != 0) | 314 | if (err != 0) |
292 | return err; | 315 | return err; |
293 | } | 316 | } |
294 | return 0; | 317 | return 0; |
@@ -299,7 +322,7 @@ int make_symlink(const char *from, const char *to) | |||
299 | int err; | 322 | int err; |
300 | 323 | ||
301 | err = symlink(to, from); | 324 | err = symlink(to, from); |
302 | if(err) | 325 | if (err) |
303 | return -errno; | 326 | return -errno; |
304 | return 0; | 327 | return 0; |
305 | } | 328 | } |
@@ -309,7 +332,7 @@ int unlink_file(const char *file) | |||
309 | int err; | 332 | int err; |
310 | 333 | ||
311 | err = unlink(file); | 334 | err = unlink(file); |
312 | if(err) | 335 | if (err) |
313 | return -errno; | 336 | return -errno; |
314 | return 0; | 337 | return 0; |
315 | } | 338 | } |
@@ -319,7 +342,7 @@ int do_mkdir(const char *file, int mode) | |||
319 | int err; | 342 | int err; |
320 | 343 | ||
321 | err = mkdir(file, mode); | 344 | err = mkdir(file, mode); |
322 | if(err) | 345 | if (err) |
323 | return -errno; | 346 | return -errno; |
324 | return 0; | 347 | return 0; |
325 | } | 348 | } |
@@ -329,7 +352,7 @@ int do_rmdir(const char *file) | |||
329 | int err; | 352 | int err; |
330 | 353 | ||
331 | err = rmdir(file); | 354 | err = rmdir(file); |
332 | if(err) | 355 | if (err) |
333 | return -errno; | 356 | return -errno; |
334 | return 0; | 357 | return 0; |
335 | } | 358 | } |
@@ -339,7 +362,7 @@ int do_mknod(const char *file, int mode, unsigned int major, unsigned int minor) | |||
339 | int err; | 362 | int err; |
340 | 363 | ||
341 | err = mknod(file, mode, makedev(major, minor)); | 364 | err = mknod(file, mode, makedev(major, minor)); |
342 | if(err) | 365 | if (err) |
343 | return -errno; | 366 | return -errno; |
344 | return 0; | 367 | return 0; |
345 | } | 368 | } |
@@ -349,7 +372,7 @@ int link_file(const char *to, const char *from) | |||
349 | int err; | 372 | int err; |
350 | 373 | ||
351 | err = link(to, from); | 374 | err = link(to, from); |
352 | if(err) | 375 | if (err) |
353 | return -errno; | 376 | return -errno; |
354 | return 0; | 377 | return 0; |
355 | } | 378 | } |
@@ -359,9 +382,9 @@ int do_readlink(char *file, char *buf, int size) | |||
359 | int n; | 382 | int n; |
360 | 383 | ||
361 | n = readlink(file, buf, size); | 384 | n = readlink(file, buf, size); |
362 | if(n < 0) | 385 | if (n < 0) |
363 | return -errno; | 386 | return -errno; |
364 | if(n < size) | 387 | if (n < size) |
365 | buf[n] = '\0'; | 388 | buf[n] = '\0'; |
366 | return n; | 389 | return n; |
367 | } | 390 | } |
@@ -371,7 +394,7 @@ int rename_file(char *from, char *to) | |||
371 | int err; | 394 | int err; |
372 | 395 | ||
373 | err = rename(from, to); | 396 | err = rename(from, to); |
374 | if(err < 0) | 397 | if (err < 0) |
375 | return -errno; | 398 | return -errno; |
376 | return 0; | 399 | return 0; |
377 | } | 400 | } |
@@ -386,7 +409,7 @@ int do_statfs(char *root, long *bsize_out, long long *blocks_out, | |||
386 | int err; | 409 | int err; |
387 | 410 | ||
388 | err = statfs64(root, &buf); | 411 | err = statfs64(root, &buf); |
389 | if(err < 0) | 412 | if (err < 0) |
390 | return -errno; | 413 | return -errno; |
391 | 414 | ||
392 | *bsize_out = buf.f_bsize; | 415 | *bsize_out = buf.f_bsize; |