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>
This commit is contained in:
Jeff Dike
2007-10-16 01:27:13 -07:00
committed by Linus Torvalds
parent baabd156e2
commit 84b3db04ca
3 changed files with 202 additions and 172 deletions

View File

@@ -3,7 +3,8 @@
#include "os.h" #include "os.h"
/* These are exactly the same definitions as in fs.h, but the names are /*
* These are exactly the same definitions as in fs.h, but the names are
* changed so that this file can be included in both kernel and user files. * changed so that this file can be included in both kernel and user files.
*/ */
@@ -21,7 +22,8 @@
#define HOSTFS_ATTR_FORCE 512 /* Not a change, but a change it */ #define HOSTFS_ATTR_FORCE 512 /* Not a change, but a change it */
#define HOSTFS_ATTR_ATTR_FLAG 1024 #define HOSTFS_ATTR_ATTR_FLAG 1024
/* If you are very careful, you'll notice that these two are missing: /*
* If you are very careful, you'll notice that these two are missing:
* *
* #define ATTR_KILL_SUID 2048 * #define ATTR_KILL_SUID 2048
* #define ATTR_KILL_SGID 4096 * #define ATTR_KILL_SGID 4096
@@ -76,7 +78,8 @@ extern int make_symlink(const char *from, const char *to);
extern int unlink_file(const char *file); extern int unlink_file(const char *file);
extern int do_mkdir(const char *file, int mode); extern int do_mkdir(const char *file, int mode);
extern int do_rmdir(const char *file); extern int do_rmdir(const char *file);
extern int do_mknod(const char *file, int mode, unsigned int major, unsigned int minor); extern int do_mknod(const char *file, int mode, unsigned int major,
unsigned int minor);
extern int link_file(const char *from, const char *to); extern int link_file(const char *from, const char *to);
extern int do_readlink(char *file, char *buf, int size); extern int do_readlink(char *file, char *buf, int size);
extern int rename_file(char *from, char *to); extern int rename_file(char *from, char *to);

View File

@@ -6,21 +6,14 @@
* 2003-02-10 Petr Baudis <pasky@ucw.cz> * 2003-02-10 Petr Baudis <pasky@ucw.cz>
*/ */
#include <linux/stddef.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/init.h> #include <linux/mm.h>
#include <linux/slab.h>
#include <linux/pagemap.h> #include <linux/pagemap.h>
#include <linux/blkdev.h>
#include <linux/list.h>
#include <linux/statfs.h> #include <linux/statfs.h>
#include <linux/kdev_t.h>
#include <asm/uaccess.h>
#include "hostfs.h" #include "hostfs.h"
#include "kern_util.h"
#include "kern.h"
#include "init.h" #include "init.h"
#include "kern.h"
struct hostfs_inode_info { struct hostfs_inode_info {
char *host_filename; char *host_filename;
@@ -136,7 +129,8 @@ static char *inode_name(struct inode *ino, int extra)
static int read_name(struct inode *ino, char *name) static int read_name(struct inode *ino, char *name)
{ {
/* The non-int inode fields are copied into ints by stat_file and /*
* The non-int inode fields are copied into ints by stat_file and
* then copied into the inode because passing the actual pointers * then copied into the inode because passing the actual pointers
* in and having them treated as int * breaks on big-endian machines * in and having them treated as int * breaks on big-endian machines
*/ */
@@ -213,7 +207,8 @@ static int read_inode(struct inode *ino)
char *name; char *name;
int err = 0; int err = 0;
/* Unfortunately, we are called from iget() when we don't have a dentry /*
* Unfortunately, we are called from iget() when we don't have a dentry
* allocated yet. * allocated yet.
*/ */
if (list_empty(&ino->i_dentry)) if (list_empty(&ino->i_dentry))
@@ -240,7 +235,8 @@ static int read_inode(struct inode *ino)
int hostfs_statfs(struct dentry *dentry, struct kstatfs *sf) int hostfs_statfs(struct dentry *dentry, struct kstatfs *sf)
{ {
/* do_statfs uses struct statfs64 internally, but the linux kernel /*
* do_statfs uses struct statfs64 internally, but the linux kernel
* struct statfs still has 32-bit versions for most of these fields, * struct statfs still has 32-bit versions for most of these fields,
* so we convert them here * so we convert them here
*/ */
@@ -295,8 +291,10 @@ static void hostfs_destroy_inode(struct inode *inode)
{ {
kfree(HOSTFS_I(inode)->host_filename); kfree(HOSTFS_I(inode)->host_filename);
/*XXX: This should not happen, probably. The check is here for /*
* additional safety.*/ * XXX: This should not happen, probably. The check is here for
* additional safety.
*/
if (HOSTFS_I(inode)->fd != -1) { if (HOSTFS_I(inode)->fd != -1) {
close_file(&HOSTFS_I(inode)->fd); close_file(&HOSTFS_I(inode)->fd);
printk(KERN_DEBUG "Closing host fd in .destroy_inode\n"); printk(KERN_DEBUG "Closing host fd in .destroy_inode\n");
@@ -353,7 +351,8 @@ int hostfs_file_open(struct inode *ino, struct file *file)
if ((mode & HOSTFS_I(ino)->mode) == mode) if ((mode & HOSTFS_I(ino)->mode) == mode)
return 0; return 0;
/* The file may already have been opened, but with the wrong access, /*
* The file may already have been opened, but with the wrong access,
* so this resets things and reopens the file with the new access. * so this resets things and reopens the file with the new access.
*/ */
if (HOSTFS_I(ino)->fd != -1) { if (HOSTFS_I(ino)->fd != -1) {
@@ -452,7 +451,8 @@ int hostfs_readpage(struct file *file, struct page *page)
buffer = kmap(page); buffer = kmap(page);
err = read_file(FILE_HOSTFS_I(file)->fd, &start, buffer, err = read_file(FILE_HOSTFS_I(file)->fd, &start, buffer,
PAGE_CACHE_SIZE); PAGE_CACHE_SIZE);
if(err < 0) goto out; if (err < 0)
goto out;
memset(&buffer[err], 0, PAGE_CACHE_SIZE - err); memset(&buffer[err], 0, PAGE_CACHE_SIZE - err);
@@ -494,7 +494,8 @@ int hostfs_write_end(struct file *file, struct address_space *mapping,
if (!PageUptodate(page) && err == PAGE_CACHE_SIZE) if (!PageUptodate(page) && err == PAGE_CACHE_SIZE)
SetPageUptodate(page); SetPageUptodate(page);
/* If err > 0, write_file has added err to pos, so we are comparing /*
* If err > 0, write_file has added err to pos, so we are comparing
* i_size against the last byte written. * i_size against the last byte written.
*/ */
if (err > 0 && (pos > inode->i_size)) if (err > 0 && (pos > inode->i_size))
@@ -572,7 +573,8 @@ int hostfs_create(struct inode *dir, struct dentry *dentry, int mode,
error = -ENOMEM; error = -ENOMEM;
inode = iget(dir->i_sb, 0); inode = iget(dir->i_sb, 0);
if(inode == NULL) goto out; if (inode == NULL)
goto out;
error = init_inode(inode, dentry); error = init_inode(inode, dentry);
if (error) if (error)
@@ -959,8 +961,10 @@ static int hostfs_fill_sb_common(struct super_block *sb, void *d, int silent)
goto out_put; goto out_put;
HOSTFS_I(root_inode)->host_filename = host_root_path; HOSTFS_I(root_inode)->host_filename = host_root_path;
/* Avoid that in the error path, iput(root_inode) frees again /*
* host_root_path through hostfs_destroy_inode! */ * Avoid that in the error path, iput(root_inode) frees again
* host_root_path through hostfs_destroy_inode!
*/
host_root_path = NULL; host_root_path = NULL;
err = -ENOMEM; err = -ENOMEM;

View File

@@ -3,19 +3,21 @@
* Licensed under the GPL * Licensed under the GPL
*/ */
#include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <fcntl.h> #include <stddef.h>
#include <unistd.h>
#include <dirent.h> #include <dirent.h>
#include <errno.h> #include <errno.h>
#include <utime.h> #include <fcntl.h>
#include <string.h> #include <string.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/types.h>
#include <sys/vfs.h> #include <sys/vfs.h>
#include "hostfs.h" #include "hostfs.h"
#include "kern_util.h" #include "os.h"
#include "user.h" #include "user.h"
#include <utime.h>
int stat_file(const char *path, unsigned long long *inode_out, int *mode_out, int stat_file(const char *path, unsigned long long *inode_out, int *mode_out,
int *nlink_out, int *uid_out, int *gid_out, int *nlink_out, int *uid_out, int *gid_out,
@@ -32,12 +34,18 @@ int stat_file(const char *path, unsigned long long *inode_out, int *mode_out,
return -errno; return -errno;
} }
if(inode_out != NULL) *inode_out = buf.st_ino; if (inode_out != NULL)
if(mode_out != NULL) *mode_out = buf.st_mode; *inode_out = buf.st_ino;
if(nlink_out != NULL) *nlink_out = buf.st_nlink; if (mode_out != NULL)
if(uid_out != NULL) *uid_out = buf.st_uid; *mode_out = buf.st_mode;
if(gid_out != NULL) *gid_out = buf.st_gid; if (nlink_out != NULL)
if(size_out != NULL) *size_out = buf.st_size; *nlink_out = buf.st_nlink;
if (uid_out != NULL)
*uid_out = buf.st_uid;
if (gid_out != NULL)
*gid_out = buf.st_gid;
if (size_out != NULL)
*size_out = buf.st_size;
if (atime_out != NULL) { if (atime_out != NULL) {
atime_out->tv_sec = buf.st_atime; atime_out->tv_sec = buf.st_atime;
atime_out->tv_nsec = 0; atime_out->tv_nsec = 0;
@@ -50,8 +58,10 @@ int stat_file(const char *path, unsigned long long *inode_out, int *mode_out,
ctime_out->tv_sec = buf.st_ctime; ctime_out->tv_sec = buf.st_ctime;
ctime_out->tv_nsec = 0; ctime_out->tv_nsec = 0;
} }
if(blksize_out != NULL) *blksize_out = buf.st_blksize; if (blksize_out != NULL)
if(blocks_out != NULL) *blocks_out = buf.st_blocks; *blksize_out = buf.st_blksize;
if (blocks_out != NULL)
*blocks_out = buf.st_blocks;
return 0; return 0;
} }
@@ -61,19 +71,27 @@ int file_type(const char *path, int *maj, int *min)
if (lstat64(path, &buf) < 0) if (lstat64(path, &buf) < 0)
return -errno; return -errno;
/*We cannot pass rdev as is because glibc and the kernel disagree /*
*about its definition.*/ * We cannot pass rdev as is because glibc and the kernel disagree
* about its definition.
*/
if (maj != NULL) if (maj != NULL)
*maj = major(buf.st_rdev); *maj = major(buf.st_rdev);
if (min != NULL) if (min != NULL)
*min = minor(buf.st_rdev); *min = minor(buf.st_rdev);
if(S_ISDIR(buf.st_mode)) return OS_TYPE_DIR; if (S_ISDIR(buf.st_mode))
else if(S_ISLNK(buf.st_mode)) return OS_TYPE_SYMLINK; return OS_TYPE_DIR;
else if(S_ISCHR(buf.st_mode)) return OS_TYPE_CHARDEV; else if (S_ISLNK(buf.st_mode))
else if(S_ISBLK(buf.st_mode)) return OS_TYPE_BLOCKDEV; return OS_TYPE_SYMLINK;
else if(S_ISFIFO(buf.st_mode))return OS_TYPE_FIFO; else if (S_ISCHR(buf.st_mode))
else if(S_ISSOCK(buf.st_mode))return OS_TYPE_SOCK; return OS_TYPE_CHARDEV;
else if (S_ISBLK(buf.st_mode))
return OS_TYPE_BLOCKDEV;
else if (S_ISFIFO(buf.st_mode))
return OS_TYPE_FIFO;
else if (S_ISSOCK(buf.st_mode))
return OS_TYPE_SOCK;
else return OS_TYPE_FILE; else return OS_TYPE_FILE;
} }
@@ -81,9 +99,12 @@ int access_file(char *path, int r, int w, int x)
{ {
int mode = 0; int mode = 0;
if(r) mode = R_OK; if (r)
if(w) mode |= W_OK; mode = R_OK;
if(x) mode |= X_OK; if (w)
mode |= W_OK;
if (x)
mode |= X_OK;
if (access(path, mode) != 0) if (access(path, mode) != 0)
return -errno; return -errno;
else return 0; else return 0;
@@ -251,9 +272,11 @@ int set_attr(const char *file, struct hostfs_iattr *attrs, int fd)
} }
} }
/* Update accessed and/or modified time, in two parts: first set /*
* Update accessed and/or modified time, in two parts: first set
* times according to the changes to perform, and then call futimes() * times according to the changes to perform, and then call futimes()
* or utimes() to apply them. */ * or utimes() to apply them.
*/
ma = (HOSTFS_ATTR_ATIME_SET | HOSTFS_ATTR_MTIME_SET); ma = (HOSTFS_ATTR_ATIME_SET | HOSTFS_ATTR_MTIME_SET);
if (attrs->ia_valid & ma) { if (attrs->ia_valid & ma) {
err = stat_file(file, NULL, NULL, NULL, NULL, NULL, NULL, err = stat_file(file, NULL, NULL, NULL, NULL, NULL, NULL,