Commit 84b3db04 authored by Jeff Dike's avatar Jeff Dike Committed by Linus Torvalds

uml: fix hostfs style

Style fixes in hostfs.
Signed-off-by: default avatarJeff Dike <jdike@linux.intel.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent baabd156
...@@ -3,7 +3,8 @@ ...@@ -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 @@ ...@@ -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); ...@@ -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);
......
This diff is collapsed.
...@@ -3,19 +3,21 @@ ...@@ -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,
...@@ -25,33 +27,41 @@ int stat_file(const char *path, unsigned long long *inode_out, int *mode_out, ...@@ -25,33 +27,41 @@ int stat_file(const char *path, unsigned long long *inode_out, int *mode_out,
{ {
struct stat64 buf; struct stat64 buf;
if(fd >= 0) { if (fd >= 0) {
if (fstat64(fd, &buf) < 0) if (fstat64(fd, &buf) < 0)
return -errno; return -errno;
} else if(lstat64(path, &buf) < 0) { } else if (lstat64(path, &buf) < 0) {
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(atime_out != NULL) { 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) {
atime_out->tv_sec = buf.st_atime; atime_out->tv_sec = buf.st_atime;
atime_out->tv_nsec = 0; atime_out->tv_nsec = 0;
} }
if(mtime_out != NULL) { if (mtime_out != NULL) {
mtime_out->tv_sec = buf.st_mtime; mtime_out->tv_sec = buf.st_mtime;
mtime_out->tv_nsec = 0; mtime_out->tv_nsec = 0;
} }
if(ctime_out != NULL) { if (ctime_out != NULL) {
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;
} }
...@@ -59,21 +69,29 @@ int file_type(const char *path, int *maj, int *min) ...@@ -59,21 +69,29 @@ int file_type(const char *path, int *maj, int *min)
{ {
struct stat64 buf; struct stat64 buf;
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
if(maj != NULL) * about its definition.
*/
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,10 +99,13 @@ int access_file(char *path, int r, int w, int x) ...@@ -81,10 +99,13 @@ 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)
if(access(path, mode) != 0) mode |= W_OK;
if (x)
mode |= X_OK;
if (access(path, mode) != 0)
return -errno; return -errno;
else return 0; else return 0;
} }
...@@ -93,18 +114,18 @@ int open_file(char *path, int r, int w, int append) ...@@ -93,18 +114,18 @@ int open_file(char *path, int r, int w, int append)
{ {
int mode = 0, fd; int mode = 0, fd;
if(r && !w) if (r && !w)
mode = O_RDONLY; mode = O_RDONLY;
else if(!r && w) else if (!r && w)
mode = O_WRONLY; mode = O_WRONLY;
else if(r && w) else if (r && w)
mode = O_RDWR; mode = O_RDWR;
else panic("Impossible mode in open_file"); else panic("Impossible mode in open_file");
if(append) if (append)
mode |= O_APPEND; mode |= O_APPEND;
fd = open64(path, mode); fd = open64(path, mode);
if(fd < 0) if (fd < 0)
return -errno; return -errno;
else return fd; else return fd;
} }
...@@ -115,7 +136,7 @@ void *open_dir(char *path, int *err_out) ...@@ -115,7 +136,7 @@ void *open_dir(char *path, int *err_out)
dir = opendir(path); dir = opendir(path);
*err_out = errno; *err_out = errno;
if(dir == NULL) if (dir == NULL)
return NULL; return NULL;
return dir; return dir;
} }
...@@ -128,7 +149,7 @@ char *read_dir(void *stream, unsigned long long *pos, ...@@ -128,7 +149,7 @@ char *read_dir(void *stream, unsigned long long *pos,
seekdir(dir, *pos); seekdir(dir, *pos);
ent = readdir(dir); ent = readdir(dir);
if(ent == NULL) if (ent == NULL)
return NULL; return NULL;
*len_out = strlen(ent->d_name); *len_out = strlen(ent->d_name);
*ino_out = ent->d_ino; *ino_out = ent->d_ino;
...@@ -141,7 +162,7 @@ int read_file(int fd, unsigned long long *offset, char *buf, int len) ...@@ -141,7 +162,7 @@ int read_file(int fd, unsigned long long *offset, char *buf, int len)
int n; int n;
n = pread64(fd, buf, len, *offset); n = pread64(fd, buf, len, *offset);
if(n < 0) if (n < 0)
return -errno; return -errno;
*offset += n; *offset += n;
return n; return n;
...@@ -152,7 +173,7 @@ int write_file(int fd, unsigned long long *offset, const char *buf, int len) ...@@ -152,7 +173,7 @@ int write_file(int fd, unsigned long long *offset, const char *buf, int len)
int n; int n;
n = pwrite64(fd, buf, len, *offset); n = pwrite64(fd, buf, len, *offset);
if(n < 0) if (n < 0)
return -errno; return -errno;
*offset += n; *offset += n;
return n; return n;
...@@ -163,7 +184,7 @@ int lseek_file(int fd, long long offset, int whence) ...@@ -163,7 +184,7 @@ int lseek_file(int fd, long long offset, int whence)
int ret; int ret;
ret = lseek64(fd, offset, whence); ret = lseek64(fd, offset, whence);
if(ret < 0) if (ret < 0)
return -errno; return -errno;
return 0; return 0;
} }
...@@ -207,7 +228,7 @@ int file_create(char *name, int ur, int uw, int ux, int gr, ...@@ -207,7 +228,7 @@ int file_create(char *name, int ur, int uw, int ux, int gr,
mode |= ow ? S_IWOTH : 0; mode |= ow ? S_IWOTH : 0;
mode |= ox ? S_IXOTH : 0; mode |= ox ? S_IXOTH : 0;
fd = open64(name, O_CREAT | O_RDWR, mode); fd = open64(name, O_CREAT | O_RDWR, mode);
if(fd < 0) if (fd < 0)
return -errno; return -errno;
return fd; return fd;
} }
...@@ -230,7 +251,7 @@ int set_attr(const char *file, struct hostfs_iattr *attrs, int fd) ...@@ -230,7 +251,7 @@ int set_attr(const char *file, struct hostfs_iattr *attrs, int fd)
if (fd >= 0) { if (fd >= 0) {
if (fchown(fd, attrs->ia_uid, -1)) if (fchown(fd, attrs->ia_uid, -1))
return -errno; return -errno;
} else if(chown(file, attrs->ia_uid, -1)) { } else if (chown(file, attrs->ia_uid, -1)) {
return -errno; return -errno;
} }
} }
...@@ -251,9 +272,11 @@ int set_attr(const char *file, struct hostfs_iattr *attrs, int fd) ...@@ -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,
...@@ -284,11 +307,11 @@ int set_attr(const char *file, struct hostfs_iattr *attrs, int fd) ...@@ -284,11 +307,11 @@ int set_attr(const char *file, struct hostfs_iattr *attrs, int fd)
} }
/* Note: ctime is not handled */ /* Note: ctime is not handled */
if(attrs->ia_valid & (HOSTFS_ATTR_ATIME | HOSTFS_ATTR_MTIME)){ if (attrs->ia_valid & (HOSTFS_ATTR_ATIME | HOSTFS_ATTR_MTIME)) {
err = stat_file(file, NULL, NULL, NULL, NULL, NULL, NULL, err = stat_file(file, NULL, NULL, NULL, NULL, NULL, NULL,
&attrs->ia_atime, &attrs->ia_mtime, NULL, &attrs->ia_atime, &attrs->ia_mtime, NULL,
NULL, NULL, fd); NULL, NULL, fd);
if(err != 0) if (err != 0)
return err; return err;
} }
return 0; return 0;
...@@ -299,7 +322,7 @@ int make_symlink(const char *from, const char *to) ...@@ -299,7 +322,7 @@ int make_symlink(const char *from, const char *to)
int err; int err;
err = symlink(to, from); err = symlink(to, from);
if(err) if (err)
return -errno; return -errno;
return 0; return 0;
} }
...@@ -309,7 +332,7 @@ int unlink_file(const char *file) ...@@ -309,7 +332,7 @@ int unlink_file(const char *file)
int err; int err;
err = unlink(file); err = unlink(file);
if(err) if (err)
return -errno; return -errno;
return 0; return 0;
} }
...@@ -319,7 +342,7 @@ int do_mkdir(const char *file, int mode) ...@@ -319,7 +342,7 @@ int do_mkdir(const char *file, int mode)
int err; int err;
err = mkdir(file, mode); err = mkdir(file, mode);
if(err) if (err)
return -errno; return -errno;
return 0; return 0;
} }
...@@ -329,7 +352,7 @@ int do_rmdir(const char *file) ...@@ -329,7 +352,7 @@ int do_rmdir(const char *file)
int err; int err;
err = rmdir(file); err = rmdir(file);
if(err) if (err)
return -errno; return -errno;
return 0; return 0;
} }
...@@ -339,7 +362,7 @@ int do_mknod(const char *file, int mode, unsigned int major, unsigned int minor) ...@@ -339,7 +362,7 @@ int do_mknod(const char *file, int mode, unsigned int major, unsigned int minor)
int err; int err;
err = mknod(file, mode, makedev(major, minor)); err = mknod(file, mode, makedev(major, minor));
if(err) if (err)
return -errno; return -errno;
return 0; return 0;
} }
...@@ -349,7 +372,7 @@ int link_file(const char *to, const char *from) ...@@ -349,7 +372,7 @@ int link_file(const char *to, const char *from)
int err; int err;
err = link(to, from); err = link(to, from);
if(err) if (err)
return -errno; return -errno;
return 0; return 0;
} }
...@@ -359,9 +382,9 @@ int do_readlink(char *file, char *buf, int size) ...@@ -359,9 +382,9 @@ int do_readlink(char *file, char *buf, int size)
int n; int n;
n = readlink(file, buf, size); n = readlink(file, buf, size);
if(n < 0) if (n < 0)
return -errno; return -errno;
if(n < size) if (n < size)
buf[n] = '\0'; buf[n] = '\0';
return n; return n;
} }
...@@ -371,7 +394,7 @@ int rename_file(char *from, char *to) ...@@ -371,7 +394,7 @@ int rename_file(char *from, char *to)
int err; int err;
err = rename(from, to); err = rename(from, to);
if(err < 0) if (err < 0)
return -errno; return -errno;
return 0; return 0;
} }
...@@ -386,7 +409,7 @@ int do_statfs(char *root, long *bsize_out, long long *blocks_out, ...@@ -386,7 +409,7 @@ int do_statfs(char *root, long *bsize_out, long long *blocks_out,
int err; int err;
err = statfs64(root, &buf); err = statfs64(root, &buf);
if(err < 0) if (err < 0)
return -errno; return -errno;
*bsize_out = buf.f_bsize; *bsize_out = buf.f_bsize;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment