aboutsummaryrefslogtreecommitdiffstats
path: root/fs/stat.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-05-06 20:47:30 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-05-06 20:47:30 -0400
commita52dd971f947893bc7735396c74cfa591f0a7558 (patch)
tree34c846f65ca97b70df13cad2e9a8beac59677da0 /fs/stat.c
parentd48b97b403d23f6df0b990cee652bdf9a52337a3 (diff)
vfs: de-crapify "cp_new_stat()" function
It's an unreadable mess of 32-bit vs 64-bit #ifdef's that mostly follow a rather simple pattern. Make a helper #define to handle that pattern, in the process making the code both shorter and more readable. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/stat.c')
-rw-r--r--fs/stat.c32
1 files changed, 14 insertions, 18 deletions
diff --git a/fs/stat.c b/fs/stat.c
index c733dc5753ae..2b5d55eb9d9a 100644
--- a/fs/stat.c
+++ b/fs/stat.c
@@ -190,24 +190,28 @@ SYSCALL_DEFINE2(fstat, unsigned int, fd, struct __old_kernel_stat __user *, stat
190 190
191#endif /* __ARCH_WANT_OLD_STAT */ 191#endif /* __ARCH_WANT_OLD_STAT */
192 192
193#if BITS_PER_LONG == 32
194# define choose_32_64(a,b) a
195#else
196# define choose_32_64(a,b) b
197#endif
198
199#define valid_dev(x) choose_32_64(old_valid_dev,new_valid_dev)(x)
200#define encode_dev(x) choose_32_64(old_encode_dev,new_encode_dev)(x)
201
193static int cp_new_stat(struct kstat *stat, struct stat __user *statbuf) 202static int cp_new_stat(struct kstat *stat, struct stat __user *statbuf)
194{ 203{
195 struct stat tmp; 204 struct stat tmp;
196 205
197#if BITS_PER_LONG == 32 206 if (!valid_dev(stat->dev) || !valid_dev(stat->rdev))
198 if (!old_valid_dev(stat->dev) || !old_valid_dev(stat->rdev))
199 return -EOVERFLOW; 207 return -EOVERFLOW;
200#else 208#if BITS_PER_LONG == 32
201 if (!new_valid_dev(stat->dev) || !new_valid_dev(stat->rdev)) 209 if (stat->size > MAX_NON_LFS)
202 return -EOVERFLOW; 210 return -EOVERFLOW;
203#endif 211#endif
204 212
205 memset(&tmp, 0, sizeof(tmp)); 213 memset(&tmp, 0, sizeof(tmp));
206#if BITS_PER_LONG == 32 214 tmp.st_dev = encode_dev(stat->dev);
207 tmp.st_dev = old_encode_dev(stat->dev);
208#else
209 tmp.st_dev = new_encode_dev(stat->dev);
210#endif
211 tmp.st_ino = stat->ino; 215 tmp.st_ino = stat->ino;
212 if (sizeof(tmp.st_ino) < sizeof(stat->ino) && tmp.st_ino != stat->ino) 216 if (sizeof(tmp.st_ino) < sizeof(stat->ino) && tmp.st_ino != stat->ino)
213 return -EOVERFLOW; 217 return -EOVERFLOW;
@@ -217,15 +221,7 @@ static int cp_new_stat(struct kstat *stat, struct stat __user *statbuf)
217 return -EOVERFLOW; 221 return -EOVERFLOW;
218 SET_UID(tmp.st_uid, stat->uid); 222 SET_UID(tmp.st_uid, stat->uid);
219 SET_GID(tmp.st_gid, stat->gid); 223 SET_GID(tmp.st_gid, stat->gid);
220#if BITS_PER_LONG == 32 224 tmp.st_rdev = encode_dev(stat->rdev);
221 tmp.st_rdev = old_encode_dev(stat->rdev);
222#else
223 tmp.st_rdev = new_encode_dev(stat->rdev);
224#endif
225#if BITS_PER_LONG == 32
226 if (stat->size > MAX_NON_LFS)
227 return -EOVERFLOW;
228#endif
229 tmp.st_size = stat->size; 225 tmp.st_size = stat->size;
230 tmp.st_atime = stat->atime.tv_sec; 226 tmp.st_atime = stat->atime.tv_sec;
231 tmp.st_mtime = stat->mtime.tv_sec; 227 tmp.st_mtime = stat->mtime.tv_sec;