Skip to content

Commit c8b91ac

Browse files
author
Al Viro
committed
clean statfs-like syscalls up
New helpers: user_statfs() and fd_statfs(), taking userland pathname and descriptor resp. and filling struct kstatfs. Syscalls of statfs family (native, compat and foreign - osf and hpux on alpha and parisc resp.) switched to those. Removes some boilerplate code, simplifies cleanup on errors... Signed-off-by: Al Viro <[email protected]>
1 parent 73d049a commit c8b91ac

File tree

5 files changed

+123
-204
lines changed

5 files changed

+123
-204
lines changed

arch/alpha/kernel/osf_sys.c

+8-28
Original file line numberDiff line numberDiff line change
@@ -230,44 +230,24 @@ linux_to_osf_statfs(struct kstatfs *linux_stat, struct osf_statfs __user *osf_st
230230
return copy_to_user(osf_stat, &tmp_stat, bufsiz) ? -EFAULT : 0;
231231
}
232232

233-
static int
234-
do_osf_statfs(struct path *path, struct osf_statfs __user *buffer,
235-
unsigned long bufsiz)
233+
SYSCALL_DEFINE3(osf_statfs, const char __user *, pathname,
234+
struct osf_statfs __user *, buffer, unsigned long, bufsiz)
236235
{
237236
struct kstatfs linux_stat;
238-
int error = vfs_statfs(path, &linux_stat);
237+
int error = user_statfs(pathname, &linux_stat);
239238
if (!error)
240239
error = linux_to_osf_statfs(&linux_stat, buffer, bufsiz);
241240
return error;
242241
}
243242

244-
SYSCALL_DEFINE3(osf_statfs, const char __user *, pathname,
245-
struct osf_statfs __user *, buffer, unsigned long, bufsiz)
246-
{
247-
struct path path;
248-
int retval;
249-
250-
retval = user_path(pathname, &path);
251-
if (!retval) {
252-
retval = do_osf_statfs(&path, buffer, bufsiz);
253-
path_put(&path);
254-
}
255-
return retval;
256-
}
257-
258243
SYSCALL_DEFINE3(osf_fstatfs, unsigned long, fd,
259244
struct osf_statfs __user *, buffer, unsigned long, bufsiz)
260245
{
261-
struct file *file;
262-
int retval;
263-
264-
retval = -EBADF;
265-
file = fget(fd);
266-
if (file) {
267-
retval = do_osf_statfs(&file->f_path, buffer, bufsiz);
268-
fput(file);
269-
}
270-
return retval;
246+
struct kstatfs linux_stat;
247+
int error = fd_statfs(fd, &linux_stat);
248+
if (!error)
249+
error = linux_to_osf_statfs(&linux_stat, buffer, bufsiz);
250+
return error;
271251
}
272252

273253
/*

arch/parisc/hpux/sys_hpux.c

+22-43
Original file line numberDiff line numberDiff line change
@@ -185,62 +185,41 @@ struct hpux_statfs {
185185
int16_t f_pad;
186186
};
187187

188-
static int do_statfs_hpux(struct path *path, struct hpux_statfs *buf)
188+
static int do_statfs_hpux(struct kstatfs *st, struct hpux_statfs __user *p)
189189
{
190-
struct kstatfs st;
191-
int retval;
192-
193-
retval = vfs_statfs(path, &st);
194-
if (retval)
195-
return retval;
196-
197-
memset(buf, 0, sizeof(*buf));
198-
buf->f_type = st.f_type;
199-
buf->f_bsize = st.f_bsize;
200-
buf->f_blocks = st.f_blocks;
201-
buf->f_bfree = st.f_bfree;
202-
buf->f_bavail = st.f_bavail;
203-
buf->f_files = st.f_files;
204-
buf->f_ffree = st.f_ffree;
205-
buf->f_fsid[0] = st.f_fsid.val[0];
206-
buf->f_fsid[1] = st.f_fsid.val[1];
207-
190+
struct hpux_statfs buf;
191+
memset(&buf, 0, sizeof(buf));
192+
buf.f_type = st->f_type;
193+
buf.f_bsize = st->f_bsize;
194+
buf.f_blocks = st->f_blocks;
195+
buf.f_bfree = st->f_bfree;
196+
buf.f_bavail = st->f_bavail;
197+
buf.f_files = st->f_files;
198+
buf.f_ffree = st->f_ffree;
199+
buf.f_fsid[0] = st->f_fsid.val[0];
200+
buf.f_fsid[1] = st->f_fsid.val[1];
201+
if (copy_to_user(p, &buf, sizeof(buf)))
202+
return -EFAULT;
208203
return 0;
209204
}
210205

211206
/* hpux statfs */
212207
asmlinkage long hpux_statfs(const char __user *pathname,
213208
struct hpux_statfs __user *buf)
214209
{
215-
struct path path;
216-
int error;
217-
218-
error = user_path(pathname, &path);
219-
if (!error) {
220-
struct hpux_statfs tmp;
221-
error = do_statfs_hpux(&path, &tmp);
222-
if (!error && copy_to_user(buf, &tmp, sizeof(tmp)))
223-
error = -EFAULT;
224-
path_put(&path);
225-
}
210+
struct kstatfs st;
211+
int error = user_statfs(pathname, &st);
212+
if (!error)
213+
error = do_statfs_hpux(&st, buf);
226214
return error;
227215
}
228216

229217
asmlinkage long hpux_fstatfs(unsigned int fd, struct hpux_statfs __user * buf)
230218
{
231-
struct file *file;
232-
struct hpux_statfs tmp;
233-
int error;
234-
235-
error = -EBADF;
236-
file = fget(fd);
237-
if (!file)
238-
goto out;
239-
error = do_statfs_hpux(&file->f_path, &tmp);
240-
if (!error && copy_to_user(buf, &tmp, sizeof(tmp)))
241-
error = -EFAULT;
242-
fput(file);
243-
out:
219+
struct kstatfs st;
220+
int error = fd_statfs(fd, &st);
221+
if (!error)
222+
error = do_statfs_hpux(&st, buf);
244223
return error;
245224
}
246225

fs/compat.c

+10-38
Original file line numberDiff line numberDiff line change
@@ -262,35 +262,19 @@ static int put_compat_statfs(struct compat_statfs __user *ubuf, struct kstatfs *
262262
*/
263263
asmlinkage long compat_sys_statfs(const char __user *pathname, struct compat_statfs __user *buf)
264264
{
265-
struct path path;
266-
int error;
267-
268-
error = user_path(pathname, &path);
269-
if (!error) {
270-
struct kstatfs tmp;
271-
error = vfs_statfs(&path, &tmp);
272-
if (!error)
273-
error = put_compat_statfs(buf, &tmp);
274-
path_put(&path);
275-
}
265+
struct kstatfs tmp;
266+
int error = user_statfs(pathname, &tmp);
267+
if (!error)
268+
error = put_compat_statfs(buf, &tmp);
276269
return error;
277270
}
278271

279272
asmlinkage long compat_sys_fstatfs(unsigned int fd, struct compat_statfs __user *buf)
280273
{
281-
struct file * file;
282274
struct kstatfs tmp;
283-
int error;
284-
285-
error = -EBADF;
286-
file = fget(fd);
287-
if (!file)
288-
goto out;
289-
error = vfs_statfs(&file->f_path, &tmp);
275+
int error = fd_statfs(fd, &tmp);
290276
if (!error)
291277
error = put_compat_statfs(buf, &tmp);
292-
fput(file);
293-
out:
294278
return error;
295279
}
296280

@@ -329,41 +313,29 @@ static int put_compat_statfs64(struct compat_statfs64 __user *ubuf, struct kstat
329313

330314
asmlinkage long compat_sys_statfs64(const char __user *pathname, compat_size_t sz, struct compat_statfs64 __user *buf)
331315
{
332-
struct path path;
316+
struct kstatfs tmp;
333317
int error;
334318

335319
if (sz != sizeof(*buf))
336320
return -EINVAL;
337321

338-
error = user_path(pathname, &path);
339-
if (!error) {
340-
struct kstatfs tmp;
341-
error = vfs_statfs(&path, &tmp);
342-
if (!error)
343-
error = put_compat_statfs64(buf, &tmp);
344-
path_put(&path);
345-
}
322+
error = user_statfs(pathname, &tmp);
323+
if (!error)
324+
error = put_compat_statfs64(buf, &tmp);
346325
return error;
347326
}
348327

349328
asmlinkage long compat_sys_fstatfs64(unsigned int fd, compat_size_t sz, struct compat_statfs64 __user *buf)
350329
{
351-
struct file * file;
352330
struct kstatfs tmp;
353331
int error;
354332

355333
if (sz != sizeof(*buf))
356334
return -EINVAL;
357335

358-
error = -EBADF;
359-
file = fget(fd);
360-
if (!file)
361-
goto out;
362-
error = vfs_statfs(&file->f_path, &tmp);
336+
error = fd_statfs(fd, &tmp);
363337
if (!error)
364338
error = put_compat_statfs64(buf, &tmp);
365-
fput(file);
366-
out:
367339
return error;
368340
}
369341

0 commit comments

Comments
 (0)