diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2010-06-06 20:08:56 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2010-08-09 16:48:10 -0400 |
commit | 39b743c6199a317ffac67fcae1dd05be3142633a (patch) | |
tree | 98e1ba53623f9844f192ab94df47717b4e00ed3b /fs/hostfs | |
parent | 5e2df28cc62fdc3f4900de23f4ec69e6312f78a4 (diff) |
switch stat_file() to passing a single struct rather than fsckloads of pointers
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/hostfs')
-rw-r--r-- | fs/hostfs/hostfs.h | 20 | ||||
-rw-r--r-- | fs/hostfs/hostfs_kern.c | 31 | ||||
-rw-r--r-- | fs/hostfs/hostfs_user.c | 75 |
3 files changed, 58 insertions, 68 deletions
diff --git a/fs/hostfs/hostfs.h b/fs/hostfs/hostfs.h index 2f34f8f2134b..3a52edef9948 100644 --- a/fs/hostfs/hostfs.h +++ b/fs/hostfs/hostfs.h | |||
@@ -53,11 +53,21 @@ struct hostfs_iattr { | |||
53 | struct timespec ia_ctime; | 53 | struct timespec ia_ctime; |
54 | }; | 54 | }; |
55 | 55 | ||
56 | extern int stat_file(const char *path, unsigned long long *inode_out, | 56 | struct hostfs_stat { |
57 | int *mode_out, int *nlink_out, int *uid_out, int *gid_out, | 57 | unsigned long long ino; |
58 | unsigned long long *size_out, struct timespec *atime_out, | 58 | unsigned int mode; |
59 | struct timespec *mtime_out, struct timespec *ctime_out, | 59 | unsigned int nlink; |
60 | int *blksize_out, unsigned long long *blocks_out, int fd); | 60 | unsigned int uid; |
61 | unsigned int gid; | ||
62 | unsigned long long size; | ||
63 | struct timespec atime, mtime, ctime; | ||
64 | unsigned int blksize; | ||
65 | unsigned long long blocks; | ||
66 | unsigned int maj; | ||
67 | unsigned int min; | ||
68 | }; | ||
69 | |||
70 | extern int stat_file(const char *path, struct hostfs_stat *p, int fd); | ||
61 | extern int access_file(char *path, int r, int w, int x); | 71 | extern int access_file(char *path, int r, int w, int x); |
62 | extern int open_file(char *path, int r, int w, int append); | 72 | extern int open_file(char *path, int r, int w, int append); |
63 | extern int file_type(const char *path, int *maj, int *min); | 73 | extern int file_type(const char *path, int *maj, int *min); |
diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c index 5a77ed3dfd7e..420a826ae0f2 100644 --- a/fs/hostfs/hostfs_kern.c +++ b/fs/hostfs/hostfs_kern.c | |||
@@ -131,28 +131,21 @@ static char *inode_name(struct inode *ino, int extra) | |||
131 | 131 | ||
132 | static int read_name(struct inode *ino, char *name) | 132 | static int read_name(struct inode *ino, char *name) |
133 | { | 133 | { |
134 | /* | 134 | struct hostfs_stat st; |
135 | * The non-int inode fields are copied into ints by stat_file and | 135 | int err = stat_file(name, &st, -1); |
136 | * then copied into the inode because passing the actual pointers | ||
137 | * in and having them treated as int * breaks on big-endian machines | ||
138 | */ | ||
139 | int err; | ||
140 | int i_mode, i_nlink, i_blksize; | ||
141 | unsigned long long i_size; | ||
142 | unsigned long long i_ino; | ||
143 | unsigned long long i_blocks; | ||
144 | |||
145 | err = stat_file(name, &i_ino, &i_mode, &i_nlink, &ino->i_uid, | ||
146 | &ino->i_gid, &i_size, &ino->i_atime, &ino->i_mtime, | ||
147 | &ino->i_ctime, &i_blksize, &i_blocks, -1); | ||
148 | if (err) | 136 | if (err) |
149 | return err; | 137 | return err; |
150 | 138 | ||
151 | ino->i_ino = i_ino; | 139 | ino->i_ino = st.ino; |
152 | ino->i_mode = i_mode; | 140 | ino->i_mode = st.mode; |
153 | ino->i_nlink = i_nlink; | 141 | ino->i_nlink = st.nlink; |
154 | ino->i_size = i_size; | 142 | ino->i_uid = st.uid; |
155 | ino->i_blocks = i_blocks; | 143 | ino->i_gid = st.gid; |
144 | ino->i_atime = st.atime; | ||
145 | ino->i_mtime = st.mtime; | ||
146 | ino->i_ctime = st.ctime; | ||
147 | ino->i_size = st.size; | ||
148 | ino->i_blocks = st.blocks; | ||
156 | return 0; | 149 | return 0; |
157 | } | 150 | } |
158 | 151 | ||
diff --git a/fs/hostfs/hostfs_user.c b/fs/hostfs/hostfs_user.c index 4b8c666ba28f..701d454a6791 100644 --- a/fs/hostfs/hostfs_user.c +++ b/fs/hostfs/hostfs_user.c | |||
@@ -19,11 +19,27 @@ | |||
19 | #include "user.h" | 19 | #include "user.h" |
20 | #include <utime.h> | 20 | #include <utime.h> |
21 | 21 | ||
22 | int stat_file(const char *path, unsigned long long *inode_out, int *mode_out, | 22 | static void stat64_to_hostfs(const struct stat64 *buf, struct hostfs_stat *p) |
23 | int *nlink_out, int *uid_out, int *gid_out, | 23 | { |
24 | unsigned long long *size_out, struct timespec *atime_out, | 24 | p->ino = buf->st_ino; |
25 | struct timespec *mtime_out, struct timespec *ctime_out, | 25 | p->mode = buf->st_mode; |
26 | int *blksize_out, unsigned long long *blocks_out, int fd) | 26 | p->nlink = buf->st_nlink; |
27 | p->uid = buf->st_uid; | ||
28 | p->gid = buf->st_gid; | ||
29 | p->size = buf->st_size; | ||
30 | p->atime.tv_sec = buf->st_atime; | ||
31 | p->atime.tv_nsec = 0; | ||
32 | p->ctime.tv_sec = buf->st_ctime; | ||
33 | p->ctime.tv_nsec = 0; | ||
34 | p->mtime.tv_sec = buf->st_mtime; | ||
35 | p->mtime.tv_nsec = 0; | ||
36 | p->blksize = buf->st_blksize; | ||
37 | p->blocks = buf->st_blocks; | ||
38 | p->maj = os_major(buf->st_rdev); | ||
39 | p->min = os_minor(buf->st_rdev); | ||
40 | } | ||
41 | |||
42 | int stat_file(const char *path, struct hostfs_stat *p, int fd) | ||
27 | { | 43 | { |
28 | struct stat64 buf; | 44 | struct stat64 buf; |
29 | 45 | ||
@@ -33,35 +49,7 @@ int stat_file(const char *path, unsigned long long *inode_out, int *mode_out, | |||
33 | } else if (lstat64(path, &buf) < 0) { | 49 | } else if (lstat64(path, &buf) < 0) { |
34 | return -errno; | 50 | return -errno; |
35 | } | 51 | } |
36 | 52 | stat64_to_hostfs(&buf, p); | |
37 | if (inode_out != NULL) | ||
38 | *inode_out = buf.st_ino; | ||
39 | if (mode_out != NULL) | ||
40 | *mode_out = buf.st_mode; | ||
41 | if (nlink_out != NULL) | ||
42 | *nlink_out = buf.st_nlink; | ||
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) { | ||
50 | atime_out->tv_sec = buf.st_atime; | ||
51 | atime_out->tv_nsec = 0; | ||
52 | } | ||
53 | if (mtime_out != NULL) { | ||
54 | mtime_out->tv_sec = buf.st_mtime; | ||
55 | mtime_out->tv_nsec = 0; | ||
56 | } | ||
57 | if (ctime_out != NULL) { | ||
58 | ctime_out->tv_sec = buf.st_ctime; | ||
59 | ctime_out->tv_nsec = 0; | ||
60 | } | ||
61 | if (blksize_out != NULL) | ||
62 | *blksize_out = buf.st_blksize; | ||
63 | if (blocks_out != NULL) | ||
64 | *blocks_out = buf.st_blocks; | ||
65 | return 0; | 53 | return 0; |
66 | } | 54 | } |
67 | 55 | ||
@@ -235,8 +223,8 @@ int file_create(char *name, int ur, int uw, int ux, int gr, | |||
235 | 223 | ||
236 | int set_attr(const char *file, struct hostfs_iattr *attrs, int fd) | 224 | int set_attr(const char *file, struct hostfs_iattr *attrs, int fd) |
237 | { | 225 | { |
226 | struct hostfs_stat st; | ||
238 | struct timeval times[2]; | 227 | struct timeval times[2]; |
239 | struct timespec atime_ts, mtime_ts; | ||
240 | int err, ma; | 228 | int err, ma; |
241 | 229 | ||
242 | if (attrs->ia_valid & HOSTFS_ATTR_MODE) { | 230 | if (attrs->ia_valid & HOSTFS_ATTR_MODE) { |
@@ -279,15 +267,14 @@ int set_attr(const char *file, struct hostfs_iattr *attrs, int fd) | |||
279 | */ | 267 | */ |
280 | ma = (HOSTFS_ATTR_ATIME_SET | HOSTFS_ATTR_MTIME_SET); | 268 | ma = (HOSTFS_ATTR_ATIME_SET | HOSTFS_ATTR_MTIME_SET); |
281 | if (attrs->ia_valid & ma) { | 269 | if (attrs->ia_valid & ma) { |
282 | err = stat_file(file, NULL, NULL, NULL, NULL, NULL, NULL, | 270 | err = stat_file(file, &st, fd); |
283 | &atime_ts, &mtime_ts, NULL, NULL, NULL, fd); | ||
284 | if (err != 0) | 271 | if (err != 0) |
285 | return err; | 272 | return err; |
286 | 273 | ||
287 | times[0].tv_sec = atime_ts.tv_sec; | 274 | times[0].tv_sec = st.atime.tv_sec; |
288 | times[0].tv_usec = atime_ts.tv_nsec / 1000; | 275 | times[0].tv_usec = st.atime.tv_nsec / 1000; |
289 | times[1].tv_sec = mtime_ts.tv_sec; | 276 | times[1].tv_sec = st.mtime.tv_sec; |
290 | times[1].tv_usec = mtime_ts.tv_nsec / 1000; | 277 | times[1].tv_usec = st.mtime.tv_nsec / 1000; |
291 | 278 | ||
292 | if (attrs->ia_valid & HOSTFS_ATTR_ATIME_SET) { | 279 | if (attrs->ia_valid & HOSTFS_ATTR_ATIME_SET) { |
293 | times[0].tv_sec = attrs->ia_atime.tv_sec; | 280 | times[0].tv_sec = attrs->ia_atime.tv_sec; |
@@ -308,9 +295,9 @@ int set_attr(const char *file, struct hostfs_iattr *attrs, int fd) | |||
308 | 295 | ||
309 | /* Note: ctime is not handled */ | 296 | /* Note: ctime is not handled */ |
310 | if (attrs->ia_valid & (HOSTFS_ATTR_ATIME | HOSTFS_ATTR_MTIME)) { | 297 | if (attrs->ia_valid & (HOSTFS_ATTR_ATIME | HOSTFS_ATTR_MTIME)) { |
311 | err = stat_file(file, NULL, NULL, NULL, NULL, NULL, NULL, | 298 | err = stat_file(file, &st, fd); |
312 | &attrs->ia_atime, &attrs->ia_mtime, NULL, | 299 | attrs->ia_atime = st.atime; |
313 | NULL, NULL, fd); | 300 | attrs->ia_mtime = st.mtime; |
314 | if (err != 0) | 301 | if (err != 0) |
315 | return err; | 302 | return err; |
316 | } | 303 | } |