2 * ioctl.c - NILFS ioctl operations.
4 * Copyright (C) 2007, 2008 Nippon Telegraph and Telephone Corporation.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * Written by Koji Sato <koji@osrg.net>.
24 #include <linux/wait.h>
25 #include <linux/smp_lock.h> /* lock_kernel(), unlock_kernel() */
26 #include <linux/capability.h> /* capable() */
27 #include <linux/uaccess.h> /* copy_from_user(), copy_to_user() */
28 #include <linux/nilfs2_fs.h>
37 static int nilfs_ioctl_wrap_copy(struct the_nilfs *nilfs,
38 struct nilfs_argv *argv, int dir,
39 ssize_t (*dofunc)(struct the_nilfs *,
41 void *, size_t, size_t))
44 size_t maxmembs, total, n;
49 if (argv->v_nmembs == 0)
52 if (argv->v_size > PAGE_SIZE)
55 buf = (void *)__get_free_pages(GFP_NOFS, 0);
58 maxmembs = PAGE_SIZE / argv->v_size;
63 for (i = 0; i < argv->v_nmembs; i += n) {
64 n = (argv->v_nmembs - i < maxmembs) ?
65 argv->v_nmembs - i : maxmembs;
66 if ((dir & _IOC_WRITE) &&
68 (void __user *)argv->v_base + argv->v_size * i,
74 nr = dofunc(nilfs, &pos, argv->v_flags, buf, argv->v_size,
80 if ((dir & _IOC_READ) &&
82 (void __user *)argv->v_base + argv->v_size * i,
83 buf, argv->v_size * nr)) {
93 argv->v_nmembs = total;
95 free_pages((unsigned long)buf, 0);
99 static int nilfs_ioctl_change_cpmode(struct inode *inode, struct file *filp,
100 unsigned int cmd, void __user *argp)
102 struct inode *cpfile = NILFS_SB(inode->i_sb)->s_nilfs->ns_cpfile;
103 struct nilfs_transaction_info ti;
104 struct nilfs_cpmode cpmode;
107 if (!capable(CAP_SYS_ADMIN))
109 if (copy_from_user(&cpmode, argp, sizeof(cpmode)))
112 nilfs_transaction_begin(inode->i_sb, &ti, 0);
113 ret = nilfs_cpfile_change_cpmode(
114 cpfile, cpmode.cm_cno, cpmode.cm_mode);
115 if (unlikely(ret < 0)) {
116 nilfs_transaction_abort(inode->i_sb);
119 nilfs_transaction_commit(inode->i_sb); /* never fails */
124 nilfs_ioctl_delete_checkpoint(struct inode *inode, struct file *filp,
125 unsigned int cmd, void __user *argp)
127 struct inode *cpfile = NILFS_SB(inode->i_sb)->s_nilfs->ns_cpfile;
128 struct nilfs_transaction_info ti;
132 if (!capable(CAP_SYS_ADMIN))
134 if (copy_from_user(&cno, argp, sizeof(cno)))
137 nilfs_transaction_begin(inode->i_sb, &ti, 0);
138 ret = nilfs_cpfile_delete_checkpoint(cpfile, cno);
139 if (unlikely(ret < 0)) {
140 nilfs_transaction_abort(inode->i_sb);
143 nilfs_transaction_commit(inode->i_sb); /* never fails */
148 nilfs_ioctl_do_get_cpinfo(struct the_nilfs *nilfs, __u64 *posp, int flags,
149 void *buf, size_t size, size_t nmembs)
151 return nilfs_cpfile_get_cpinfo(nilfs->ns_cpfile, posp, flags, buf,
155 static int nilfs_ioctl_get_cpinfo(struct inode *inode, struct file *filp,
156 unsigned int cmd, void __user *argp)
158 struct the_nilfs *nilfs = NILFS_SB(inode->i_sb)->s_nilfs;
159 struct nilfs_argv argv;
162 if (copy_from_user(&argv, argp, sizeof(argv)))
165 down_read(&nilfs->ns_segctor_sem);
166 ret = nilfs_ioctl_wrap_copy(nilfs, &argv, _IOC_DIR(cmd),
167 nilfs_ioctl_do_get_cpinfo);
168 up_read(&nilfs->ns_segctor_sem);
172 if (copy_to_user(argp, &argv, sizeof(argv)))
177 static int nilfs_ioctl_get_cpstat(struct inode *inode, struct file *filp,
178 unsigned int cmd, void __user *argp)
180 struct the_nilfs *nilfs = NILFS_SB(inode->i_sb)->s_nilfs;
181 struct nilfs_cpstat cpstat;
184 down_read(&nilfs->ns_segctor_sem);
185 ret = nilfs_cpfile_get_stat(nilfs->ns_cpfile, &cpstat);
186 up_read(&nilfs->ns_segctor_sem);
190 if (copy_to_user(argp, &cpstat, sizeof(cpstat)))
196 nilfs_ioctl_do_get_suinfo(struct the_nilfs *nilfs, __u64 *posp, int flags,
197 void *buf, size_t size, size_t nmembs)
199 return nilfs_sufile_get_suinfo(nilfs->ns_sufile, *posp, buf, nmembs);
202 static int nilfs_ioctl_get_suinfo(struct inode *inode, struct file *filp,
203 unsigned int cmd, void __user *argp)
205 struct the_nilfs *nilfs = NILFS_SB(inode->i_sb)->s_nilfs;
206 struct nilfs_argv argv;
209 if (copy_from_user(&argv, argp, sizeof(argv)))
212 down_read(&nilfs->ns_segctor_sem);
213 ret = nilfs_ioctl_wrap_copy(nilfs, &argv, _IOC_DIR(cmd),
214 nilfs_ioctl_do_get_suinfo);
215 up_read(&nilfs->ns_segctor_sem);
219 if (copy_to_user(argp, &argv, sizeof(argv)))
224 static int nilfs_ioctl_get_sustat(struct inode *inode, struct file *filp,
225 unsigned int cmd, void __user *argp)
227 struct the_nilfs *nilfs = NILFS_SB(inode->i_sb)->s_nilfs;
228 struct nilfs_sustat sustat;
231 down_read(&nilfs->ns_segctor_sem);
232 ret = nilfs_sufile_get_stat(nilfs->ns_sufile, &sustat);
233 up_read(&nilfs->ns_segctor_sem);
237 if (copy_to_user(argp, &sustat, sizeof(sustat)))
243 nilfs_ioctl_do_get_vinfo(struct the_nilfs *nilfs, __u64 *posp, int flags,
244 void *buf, size_t size, size_t nmembs)
246 return nilfs_dat_get_vinfo(nilfs_dat_inode(nilfs), buf, nmembs);
249 static int nilfs_ioctl_get_vinfo(struct inode *inode, struct file *filp,
250 unsigned int cmd, void __user *argp)
252 struct the_nilfs *nilfs = NILFS_SB(inode->i_sb)->s_nilfs;
253 struct nilfs_argv argv;
256 if (copy_from_user(&argv, argp, sizeof(argv)))
259 down_read(&nilfs->ns_segctor_sem);
260 ret = nilfs_ioctl_wrap_copy(nilfs, &argv, _IOC_DIR(cmd),
261 nilfs_ioctl_do_get_vinfo);
262 up_read(&nilfs->ns_segctor_sem);
266 if (copy_to_user(argp, &argv, sizeof(argv)))
272 nilfs_ioctl_do_get_bdescs(struct the_nilfs *nilfs, __u64 *posp, int flags,
273 void *buf, size_t size, size_t nmembs)
275 struct inode *dat = nilfs_dat_inode(nilfs);
276 struct nilfs_bmap *bmap = NILFS_I(dat)->i_bmap;
277 struct nilfs_bdesc *bdescs = buf;
280 for (i = 0; i < nmembs; i++) {
281 ret = nilfs_bmap_lookup_at_level(bmap,
283 bdescs[i].bd_level + 1,
284 &bdescs[i].bd_blocknr);
288 bdescs[i].bd_blocknr = 0;
294 static int nilfs_ioctl_get_bdescs(struct inode *inode, struct file *filp,
295 unsigned int cmd, void __user *argp)
297 struct the_nilfs *nilfs = NILFS_SB(inode->i_sb)->s_nilfs;
298 struct nilfs_argv argv;
301 if (copy_from_user(&argv, argp, sizeof(argv)))
304 down_read(&nilfs->ns_segctor_sem);
305 ret = nilfs_ioctl_wrap_copy(nilfs, &argv, _IOC_DIR(cmd),
306 nilfs_ioctl_do_get_bdescs);
307 up_read(&nilfs->ns_segctor_sem);
311 if (copy_to_user(argp, &argv, sizeof(argv)))
316 static int nilfs_ioctl_move_inode_block(struct inode *inode,
317 struct nilfs_vdesc *vdesc,
318 struct list_head *buffers)
320 struct buffer_head *bh;
323 if (vdesc->vd_flags == 0)
324 ret = nilfs_gccache_submit_read_data(
325 inode, vdesc->vd_offset, vdesc->vd_blocknr,
326 vdesc->vd_vblocknr, &bh);
328 ret = nilfs_gccache_submit_read_node(
329 inode, vdesc->vd_blocknr, vdesc->vd_vblocknr, &bh);
331 if (unlikely(ret < 0)) {
334 "%s: invalid virtual block address (%s): "
335 "ino=%llu, cno=%llu, offset=%llu, "
336 "blocknr=%llu, vblocknr=%llu\n",
337 __func__, vdesc->vd_flags ? "node" : "data",
338 (unsigned long long)vdesc->vd_ino,
339 (unsigned long long)vdesc->vd_cno,
340 (unsigned long long)vdesc->vd_offset,
341 (unsigned long long)vdesc->vd_blocknr,
342 (unsigned long long)vdesc->vd_vblocknr);
345 bh->b_private = vdesc;
346 list_add_tail(&bh->b_assoc_buffers, buffers);
351 nilfs_ioctl_do_move_blocks(struct the_nilfs *nilfs, __u64 *posp, int flags,
352 void *buf, size_t size, size_t nmembs)
355 struct nilfs_vdesc *vdesc;
356 struct buffer_head *bh, *n;
362 for (i = 0, vdesc = buf; i < nmembs; ) {
365 inode = nilfs_gc_iget(nilfs, ino, cno);
366 if (unlikely(inode == NULL)) {
371 ret = nilfs_ioctl_move_inode_block(inode, vdesc,
373 if (unlikely(ret < 0))
376 } while (++i < nmembs &&
377 vdesc->vd_ino == ino && vdesc->vd_cno == cno);
380 list_for_each_entry_safe(bh, n, &buffers, b_assoc_buffers) {
381 ret = nilfs_gccache_wait_and_mark_dirty(bh);
382 if (unlikely(ret < 0)) {
383 if (ret == -EEXIST) {
384 vdesc = bh->b_private;
386 "%s: conflicting %s buffer: "
387 "ino=%llu, cno=%llu, offset=%llu, "
388 "blocknr=%llu, vblocknr=%llu\n",
390 vdesc->vd_flags ? "node" : "data",
391 (unsigned long long)vdesc->vd_ino,
392 (unsigned long long)vdesc->vd_cno,
393 (unsigned long long)vdesc->vd_offset,
394 (unsigned long long)vdesc->vd_blocknr,
395 (unsigned long long)vdesc->vd_vblocknr);
399 list_del_init(&bh->b_assoc_buffers);
400 bh->b_private = NULL;
406 list_for_each_entry_safe(bh, n, &buffers, b_assoc_buffers) {
407 list_del_init(&bh->b_assoc_buffers);
408 bh->b_private = NULL;
414 static inline int nilfs_ioctl_move_blocks(struct the_nilfs *nilfs,
415 struct nilfs_argv *argv,
418 return nilfs_ioctl_wrap_copy(nilfs, argv, dir,
419 nilfs_ioctl_do_move_blocks);
423 nilfs_ioctl_do_delete_checkpoints(struct the_nilfs *nilfs, __u64 *posp,
424 int flags, void *buf, size_t size,
427 struct inode *cpfile = nilfs->ns_cpfile;
428 struct nilfs_period *periods = buf;
431 for (i = 0; i < nmembs; i++) {
432 ret = nilfs_cpfile_delete_checkpoints(
433 cpfile, periods[i].p_start, periods[i].p_end);
440 static inline int nilfs_ioctl_delete_checkpoints(struct the_nilfs *nilfs,
441 struct nilfs_argv *argv,
444 return nilfs_ioctl_wrap_copy(nilfs, argv, dir,
445 nilfs_ioctl_do_delete_checkpoints);
449 nilfs_ioctl_do_free_vblocknrs(struct the_nilfs *nilfs, __u64 *posp, int flags,
450 void *buf, size_t size, size_t nmembs)
452 int ret = nilfs_dat_freev(nilfs_dat_inode(nilfs), buf, nmembs);
454 return (ret < 0) ? ret : nmembs;
457 static inline int nilfs_ioctl_free_vblocknrs(struct the_nilfs *nilfs,
458 struct nilfs_argv *argv,
461 return nilfs_ioctl_wrap_copy(nilfs, argv, dir,
462 nilfs_ioctl_do_free_vblocknrs);
466 nilfs_ioctl_do_mark_blocks_dirty(struct the_nilfs *nilfs, __u64 *posp,
467 int flags, void *buf, size_t size,
470 struct inode *dat = nilfs_dat_inode(nilfs);
471 struct nilfs_bmap *bmap = NILFS_I(dat)->i_bmap;
472 struct nilfs_bdesc *bdescs = buf;
475 for (i = 0; i < nmembs; i++) {
476 /* XXX: use macro or inline func to check liveness */
477 ret = nilfs_bmap_lookup_at_level(bmap,
479 bdescs[i].bd_level + 1,
480 &bdescs[i].bd_blocknr);
484 bdescs[i].bd_blocknr = 0;
486 if (bdescs[i].bd_blocknr != bdescs[i].bd_oblocknr)
487 /* skip dead block */
489 if (bdescs[i].bd_level == 0) {
490 ret = nilfs_mdt_mark_block_dirty(dat,
491 bdescs[i].bd_offset);
493 BUG_ON(ret == -ENOENT);
497 ret = nilfs_bmap_mark(bmap, bdescs[i].bd_offset,
500 BUG_ON(ret == -ENOENT);
508 static inline int nilfs_ioctl_mark_blocks_dirty(struct the_nilfs *nilfs,
509 struct nilfs_argv *argv,
512 return nilfs_ioctl_wrap_copy(nilfs, argv, dir,
513 nilfs_ioctl_do_mark_blocks_dirty);
517 nilfs_ioctl_do_free_segments(struct the_nilfs *nilfs, __u64 *posp, int flags,
518 void *buf, size_t size, size_t nmembs)
520 struct nilfs_sb_info *sbi = nilfs_get_writer(nilfs);
524 ret = nilfs_segctor_add_segments_to_be_freed(
525 NILFS_SC(sbi), buf, nmembs);
526 nilfs_put_writer(nilfs);
528 return (ret < 0) ? ret : nmembs;
531 static inline int nilfs_ioctl_free_segments(struct the_nilfs *nilfs,
532 struct nilfs_argv *argv,
535 return nilfs_ioctl_wrap_copy(nilfs, argv, dir,
536 nilfs_ioctl_do_free_segments);
539 int nilfs_ioctl_prepare_clean_segments(struct the_nilfs *nilfs,
542 struct nilfs_argv argv[5];
545 if (copy_from_user(argv, argp, sizeof(argv)))
549 ret = nilfs_ioctl_move_blocks(nilfs, &argv[0], dir);
552 ret = nilfs_ioctl_delete_checkpoints(nilfs, &argv[1], dir);
555 ret = nilfs_ioctl_free_vblocknrs(nilfs, &argv[2], dir);
558 ret = nilfs_ioctl_mark_blocks_dirty(nilfs, &argv[3], dir);
561 ret = nilfs_ioctl_free_segments(nilfs, &argv[4], dir);
568 BUG(); /* XXX: not implemented yet */
570 BUG();/* XXX: not implemented yet */
572 BUG();/* XXX: not implemented yet */
574 nilfs_remove_all_gcinode(nilfs);
578 static int nilfs_ioctl_clean_segments(struct inode *inode, struct file *filp,
579 unsigned int cmd, void __user *argp)
583 if (!capable(CAP_SYS_ADMIN))
586 ret = nilfs_clean_segments(inode->i_sb, argp);
587 clear_nilfs_cond_nongc_write(NILFS_SB(inode->i_sb)->s_nilfs);
591 static int nilfs_ioctl_test_cond(struct the_nilfs *nilfs, int cond)
593 return (cond & NILFS_TIMEDWAIT_SEG_WRITE) &&
594 nilfs_cond_nongc_write(nilfs);
597 static void nilfs_ioctl_clear_cond(struct the_nilfs *nilfs, int cond)
599 if (cond & NILFS_TIMEDWAIT_SEG_WRITE)
600 clear_nilfs_cond_nongc_write(nilfs);
603 static int nilfs_ioctl_timedwait(struct inode *inode, struct file *filp,
604 unsigned int cmd, void __user *argp)
606 struct the_nilfs *nilfs = NILFS_SB(inode->i_sb)->s_nilfs;
607 struct nilfs_wait_cond wc;
610 if (!capable(CAP_SYS_ADMIN))
612 if (copy_from_user(&wc, argp, sizeof(wc)))
617 wait_event_interruptible_timeout(
618 nilfs->ns_cleanerd_wq,
619 nilfs_ioctl_test_cond(nilfs, wc.wc_cond),
620 timespec_to_jiffies(&wc.wc_timeout)) :
621 wait_event_interruptible(
622 nilfs->ns_cleanerd_wq,
623 nilfs_ioctl_test_cond(nilfs, wc.wc_cond));
625 nilfs_ioctl_clear_cond(nilfs, wc.wc_cond);
628 jiffies_to_timespec(ret, &wc.wc_timeout);
629 if (copy_to_user(argp, &wc, sizeof(wc)))
636 return wc.wc_flags ? -ETIME : 0;
639 static int nilfs_ioctl_sync(struct inode *inode, struct file *filp,
640 unsigned int cmd, void __user *argp)
645 ret = nilfs_construct_segment(inode->i_sb);
650 cno = NILFS_SB(inode->i_sb)->s_nilfs->ns_cno - 1;
651 if (copy_to_user(argp, &cno, sizeof(cno)))
657 int nilfs_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
660 void __user *argp = (void * __user *)arg;
663 case NILFS_IOCTL_CHANGE_CPMODE:
664 return nilfs_ioctl_change_cpmode(inode, filp, cmd, argp);
665 case NILFS_IOCTL_DELETE_CHECKPOINT:
666 return nilfs_ioctl_delete_checkpoint(inode, filp, cmd, argp);
667 case NILFS_IOCTL_GET_CPINFO:
668 return nilfs_ioctl_get_cpinfo(inode, filp, cmd, argp);
669 case NILFS_IOCTL_GET_CPSTAT:
670 return nilfs_ioctl_get_cpstat(inode, filp, cmd, argp);
671 case NILFS_IOCTL_GET_SUINFO:
672 return nilfs_ioctl_get_suinfo(inode, filp, cmd, argp);
673 case NILFS_IOCTL_GET_SUSTAT:
674 return nilfs_ioctl_get_sustat(inode, filp, cmd, argp);
675 case NILFS_IOCTL_GET_VINFO:
676 /* XXX: rename to ??? */
677 return nilfs_ioctl_get_vinfo(inode, filp, cmd, argp);
678 case NILFS_IOCTL_GET_BDESCS:
679 return nilfs_ioctl_get_bdescs(inode, filp, cmd, argp);
680 case NILFS_IOCTL_CLEAN_SEGMENTS:
681 return nilfs_ioctl_clean_segments(inode, filp, cmd, argp);
682 case NILFS_IOCTL_TIMEDWAIT:
683 return nilfs_ioctl_timedwait(inode, filp, cmd, argp);
684 case NILFS_IOCTL_SYNC:
685 return nilfs_ioctl_sync(inode, filp, cmd, argp);
693 #include <linux/compat.h>
695 static int nilfs_compat_locked_ioctl(struct inode *inode, struct file *filp,
696 unsigned int cmd, unsigned long arg)
701 ret = nilfs_ioctl(inode, filp, cmd, arg);
707 nilfs_compat_ioctl_uargv32_to_uargv(struct nilfs_argv32 __user *uargv32,
708 struct nilfs_argv __user *uargv)
711 compat_size_t nmembs, size;
712 compat_int_t index, flags;
714 if (get_user(base, &uargv32->v_base) ||
715 put_user(compat_ptr(base), &uargv->v_base) ||
716 get_user(nmembs, &uargv32->v_nmembs) ||
717 put_user(nmembs, &uargv->v_nmembs) ||
718 get_user(size, &uargv32->v_size) ||
719 put_user(size, &uargv->v_size) ||
720 get_user(index, &uargv32->v_index) ||
721 put_user(index, &uargv->v_index) ||
722 get_user(flags, &uargv32->v_flags) ||
723 put_user(flags, &uargv->v_flags))
729 nilfs_compat_ioctl_uargv_to_uargv32(struct nilfs_argv __user *uargv,
730 struct nilfs_argv32 __user *uargv32)
734 if (get_user(nmembs, &uargv->v_nmembs) ||
735 put_user(nmembs, &uargv32->v_nmembs))
741 nilfs_compat_ioctl_get_by_argv(struct inode *inode, struct file *filp,
742 unsigned int cmd, unsigned long arg)
744 struct nilfs_argv __user *uargv;
745 struct nilfs_argv32 __user *uargv32;
748 uargv = compat_alloc_user_space(sizeof(struct nilfs_argv));
749 uargv32 = compat_ptr(arg);
750 ret = nilfs_compat_ioctl_uargv32_to_uargv(uargv32, uargv);
754 ret = nilfs_compat_locked_ioctl(inode, filp, cmd, (unsigned long)uargv);
758 return nilfs_compat_ioctl_uargv_to_uargv32(uargv, uargv32);
762 nilfs_compat_ioctl_change_cpmode(struct inode *inode, struct file *filp,
763 unsigned int cmd, unsigned long arg)
765 struct nilfs_cpmode __user *ucpmode;
766 struct nilfs_cpmode32 __user *ucpmode32;
769 ucpmode = compat_alloc_user_space(sizeof(struct nilfs_cpmode));
770 ucpmode32 = compat_ptr(arg);
771 if (copy_in_user(&ucpmode->cm_cno, &ucpmode32->cm_cno,
773 get_user(mode, &ucpmode32->cm_mode) ||
774 put_user(mode, &ucpmode->cm_mode))
777 return nilfs_compat_locked_ioctl(
778 inode, filp, cmd, (unsigned long)ucpmode);
783 nilfs_compat_ioctl_delete_checkpoint(struct inode *inode, struct file *filp,
784 unsigned int cmd, unsigned long arg)
786 return nilfs_compat_locked_ioctl(inode, filp, cmd, arg);
790 nilfs_compat_ioctl_get_cpinfo(struct inode *inode, struct file *filp,
791 unsigned int cmd, unsigned long arg)
793 return nilfs_compat_ioctl_get_by_argv(inode, filp, cmd, arg);
797 nilfs_compat_ioctl_get_cpstat(struct inode *inode, struct file *filp,
798 unsigned int cmd, unsigned long arg)
800 return nilfs_compat_locked_ioctl(inode, filp, cmd, arg);
804 nilfs_compat_ioctl_get_suinfo(struct inode *inode, struct file *filp,
805 unsigned int cmd, unsigned long arg)
807 return nilfs_compat_ioctl_get_by_argv(inode, filp, cmd, arg);
811 nilfs_compat_ioctl_get_sustat(struct inode *inode, struct file *filp,
812 unsigned int cmd, unsigned long arg)
814 struct nilfs_sustat __user *usustat;
815 struct nilfs_sustat32 __user *usustat32;
816 time_t ctime, nongc_ctime;
819 usustat = compat_alloc_user_space(sizeof(struct nilfs_sustat));
820 ret = nilfs_compat_locked_ioctl(inode, filp, cmd,
821 (unsigned long)usustat);
825 usustat32 = compat_ptr(arg);
826 if (copy_in_user(&usustat32->ss_nsegs, &usustat->ss_nsegs,
828 copy_in_user(&usustat32->ss_ncleansegs, &usustat->ss_ncleansegs,
830 copy_in_user(&usustat32->ss_ndirtysegs, &usustat->ss_ndirtysegs,
832 get_user(ctime, &usustat->ss_ctime) ||
833 put_user(ctime, &usustat32->ss_ctime) ||
834 get_user(nongc_ctime, &usustat->ss_nongc_ctime) ||
835 put_user(nongc_ctime, &usustat32->ss_nongc_ctime))
841 nilfs_compat_ioctl_get_vinfo(struct inode *inode, struct file *filp,
842 unsigned int cmd, unsigned long arg)
844 return nilfs_compat_ioctl_get_by_argv(inode, filp, cmd, arg);
848 nilfs_compat_ioctl_get_bdescs(struct inode *inode, struct file *filp,
849 unsigned int cmd, unsigned long arg)
851 return nilfs_compat_ioctl_get_by_argv(inode, filp, cmd, arg);
855 nilfs_compat_ioctl_clean_segments(struct inode *inode, struct file *filp,
856 unsigned int cmd, unsigned long arg)
858 struct nilfs_argv __user *uargv;
859 struct nilfs_argv32 __user *uargv32;
862 uargv = compat_alloc_user_space(sizeof(struct nilfs_argv) * 5);
863 uargv32 = compat_ptr(arg);
864 for (i = 0; i < 5; i++) {
865 ret = nilfs_compat_ioctl_uargv32_to_uargv(&uargv32[i],
870 return nilfs_compat_locked_ioctl(
871 inode, filp, cmd, (unsigned long)uargv);
875 nilfs_compat_ioctl_timedwait(struct inode *inode, struct file *filp,
876 unsigned int cmd, unsigned long arg)
878 struct nilfs_wait_cond __user *uwcond;
879 struct nilfs_wait_cond32 __user *uwcond32;
881 int cond, flags, ret;
883 uwcond = compat_alloc_user_space(sizeof(struct nilfs_wait_cond));
884 uwcond32 = compat_ptr(arg);
885 if (get_user(cond, &uwcond32->wc_cond) ||
886 put_user(cond, &uwcond->wc_cond) ||
887 get_user(flags, &uwcond32->wc_flags) ||
888 put_user(flags, &uwcond->wc_flags) ||
889 get_user(ts.tv_sec, &uwcond32->wc_timeout.tv_sec) ||
890 get_user(ts.tv_nsec, &uwcond32->wc_timeout.tv_nsec) ||
891 put_user(ts.tv_sec, &uwcond->wc_timeout.tv_sec) ||
892 put_user(ts.tv_nsec, &uwcond->wc_timeout.tv_nsec))
895 ret = nilfs_compat_locked_ioctl(inode, filp, cmd,
896 (unsigned long)uwcond);
900 if (get_user(ts.tv_sec, &uwcond->wc_timeout.tv_sec) ||
901 get_user(ts.tv_nsec, &uwcond->wc_timeout.tv_nsec) ||
902 put_user(ts.tv_sec, &uwcond32->wc_timeout.tv_sec) ||
903 put_user(ts.tv_nsec, &uwcond32->wc_timeout.tv_nsec))
909 static int nilfs_compat_ioctl_sync(struct inode *inode, struct file *filp,
910 unsigned int cmd, unsigned long arg)
912 return nilfs_compat_locked_ioctl(inode, filp, cmd, arg);
915 long nilfs_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
917 struct inode *inode = filp->f_dentry->d_inode;
920 case NILFS_IOCTL32_CHANGE_CPMODE:
921 return nilfs_compat_ioctl_change_cpmode(
922 inode, filp, NILFS_IOCTL_CHANGE_CPMODE, arg);
923 case NILFS_IOCTL_DELETE_CHECKPOINT:
924 return nilfs_compat_ioctl_delete_checkpoint(
925 inode, filp, cmd, arg);
926 case NILFS_IOCTL32_GET_CPINFO:
927 return nilfs_compat_ioctl_get_cpinfo(
928 inode, filp, NILFS_IOCTL_GET_CPINFO, arg);
929 case NILFS_IOCTL_GET_CPSTAT:
930 return nilfs_compat_ioctl_get_cpstat(inode, filp, cmd, arg);
931 case NILFS_IOCTL32_GET_SUINFO:
932 return nilfs_compat_ioctl_get_suinfo(
933 inode, filp, NILFS_IOCTL_GET_SUINFO, arg);
934 case NILFS_IOCTL32_GET_SUSTAT:
935 return nilfs_compat_ioctl_get_sustat(
936 inode, filp, NILFS_IOCTL_GET_SUSTAT, arg);
937 case NILFS_IOCTL32_GET_VINFO:
938 return nilfs_compat_ioctl_get_vinfo(
939 inode, filp, NILFS_IOCTL_GET_VINFO, arg);
940 case NILFS_IOCTL32_GET_BDESCS:
941 return nilfs_compat_ioctl_get_bdescs(
942 inode, filp, NILFS_IOCTL_GET_BDESCS, arg);
943 case NILFS_IOCTL32_CLEAN_SEGMENTS:
944 return nilfs_compat_ioctl_clean_segments(
945 inode, filp, NILFS_IOCTL_CLEAN_SEGMENTS, arg);
946 case NILFS_IOCTL32_TIMEDWAIT:
947 return nilfs_compat_ioctl_timedwait(
948 inode, filp, NILFS_IOCTL_TIMEDWAIT, arg);
949 case NILFS_IOCTL_SYNC:
950 return nilfs_compat_ioctl_sync(inode, filp, cmd, arg);