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;
48 if (argv->v_nmembs == 0)
51 if (argv->v_size > PAGE_SIZE)
54 buf = (void *)__get_free_pages(GFP_NOFS, 0);
57 maxmembs = PAGE_SIZE / argv->v_size;
61 for (i = 0; i < argv->v_nmembs; i += n) {
62 n = (argv->v_nmembs - i < maxmembs) ?
63 argv->v_nmembs - i : maxmembs;
64 if ((dir & _IOC_WRITE) &&
66 (void __user *)argv->v_base + argv->v_size * i,
71 nr = (*dofunc)(nilfs, argv->v_index + i, argv->v_flags, buf,
77 if ((dir & _IOC_READ) &&
79 (void __user *)argv->v_base + argv->v_size * i,
80 buf, argv->v_size * nr)) {
86 argv->v_nmembs = total;
88 free_pages((unsigned long)buf, 0);
92 static int nilfs_ioctl_change_cpmode(struct inode *inode, struct file *filp,
93 unsigned int cmd, void __user *argp)
95 struct inode *cpfile = NILFS_SB(inode->i_sb)->s_nilfs->ns_cpfile;
96 struct nilfs_transaction_info ti;
97 struct nilfs_cpmode cpmode;
100 if (!capable(CAP_SYS_ADMIN))
102 if (copy_from_user(&cpmode, argp, sizeof(cpmode)))
105 nilfs_transaction_begin(inode->i_sb, &ti, 0);
106 ret = nilfs_cpfile_change_cpmode(
107 cpfile, cpmode.cm_cno, cpmode.cm_mode);
108 if (unlikely(ret < 0)) {
109 nilfs_transaction_abort(inode->i_sb);
112 nilfs_transaction_commit(inode->i_sb); /* never fails */
117 nilfs_ioctl_delete_checkpoint(struct inode *inode, struct file *filp,
118 unsigned int cmd, void __user *argp)
120 struct inode *cpfile = NILFS_SB(inode->i_sb)->s_nilfs->ns_cpfile;
121 struct nilfs_transaction_info ti;
125 if (!capable(CAP_SYS_ADMIN))
127 if (copy_from_user(&cno, argp, sizeof(cno)))
130 nilfs_transaction_begin(inode->i_sb, &ti, 0);
131 ret = nilfs_cpfile_delete_checkpoint(cpfile, cno);
132 if (unlikely(ret < 0)) {
133 nilfs_transaction_abort(inode->i_sb);
136 nilfs_transaction_commit(inode->i_sb); /* never fails */
141 nilfs_ioctl_do_get_cpinfo(struct the_nilfs *nilfs, int index, int flags,
142 void *buf, size_t size, size_t nmembs)
144 return nilfs_cpfile_get_cpinfo(nilfs->ns_cpfile, index, flags, buf,
148 static int nilfs_ioctl_get_cpinfo(struct inode *inode, struct file *filp,
149 unsigned int cmd, void __user *argp)
151 struct the_nilfs *nilfs = NILFS_SB(inode->i_sb)->s_nilfs;
152 struct nilfs_argv argv;
155 if (copy_from_user(&argv, argp, sizeof(argv)))
158 down_read(&nilfs->ns_segctor_sem);
159 ret = nilfs_ioctl_wrap_copy(nilfs, &argv, _IOC_DIR(cmd),
160 nilfs_ioctl_do_get_cpinfo);
161 up_read(&nilfs->ns_segctor_sem);
165 if (copy_to_user(argp, &argv, sizeof(argv)))
170 static int nilfs_ioctl_get_cpstat(struct inode *inode, struct file *filp,
171 unsigned int cmd, void __user *argp)
173 struct the_nilfs *nilfs = NILFS_SB(inode->i_sb)->s_nilfs;
174 struct nilfs_cpstat cpstat;
177 down_read(&nilfs->ns_segctor_sem);
178 ret = nilfs_cpfile_get_stat(nilfs->ns_cpfile, &cpstat);
179 up_read(&nilfs->ns_segctor_sem);
183 if (copy_to_user(argp, &cpstat, sizeof(cpstat)))
189 nilfs_ioctl_do_get_suinfo(struct the_nilfs *nilfs, int index, int flags,
190 void *buf, size_t size, size_t nmembs)
192 return nilfs_sufile_get_suinfo(nilfs->ns_sufile, index, buf, nmembs);
195 static int nilfs_ioctl_get_suinfo(struct inode *inode, struct file *filp,
196 unsigned int cmd, void __user *argp)
198 struct the_nilfs *nilfs = NILFS_SB(inode->i_sb)->s_nilfs;
199 struct nilfs_argv argv;
202 if (copy_from_user(&argv, argp, sizeof(argv)))
205 down_read(&nilfs->ns_segctor_sem);
206 ret = nilfs_ioctl_wrap_copy(nilfs, &argv, _IOC_DIR(cmd),
207 nilfs_ioctl_do_get_suinfo);
208 up_read(&nilfs->ns_segctor_sem);
212 if (copy_to_user(argp, &argv, sizeof(argv)))
217 static int nilfs_ioctl_get_sustat(struct inode *inode, struct file *filp,
218 unsigned int cmd, void __user *argp)
220 struct the_nilfs *nilfs = NILFS_SB(inode->i_sb)->s_nilfs;
221 struct nilfs_sustat sustat;
224 down_read(&nilfs->ns_segctor_sem);
225 ret = nilfs_sufile_get_stat(nilfs->ns_sufile, &sustat);
226 up_read(&nilfs->ns_segctor_sem);
230 if (copy_to_user(argp, &sustat, sizeof(sustat)))
236 nilfs_ioctl_do_get_vinfo(struct the_nilfs *nilfs, int index, int flags,
237 void *buf, size_t size, size_t nmembs)
239 return nilfs_dat_get_vinfo(nilfs_dat_inode(nilfs), buf, nmembs);
242 static int nilfs_ioctl_get_vinfo(struct inode *inode, struct file *filp,
243 unsigned int cmd, void __user *argp)
245 struct the_nilfs *nilfs = NILFS_SB(inode->i_sb)->s_nilfs;
246 struct nilfs_argv argv;
249 if (copy_from_user(&argv, argp, sizeof(argv)))
252 down_read(&nilfs->ns_segctor_sem);
253 ret = nilfs_ioctl_wrap_copy(nilfs, &argv, _IOC_DIR(cmd),
254 nilfs_ioctl_do_get_vinfo);
255 up_read(&nilfs->ns_segctor_sem);
259 if (copy_to_user(argp, &argv, sizeof(argv)))
265 nilfs_ioctl_do_get_bdescs(struct the_nilfs *nilfs, int index, int flags,
266 void *buf, size_t size, size_t nmembs)
268 struct inode *dat = nilfs_dat_inode(nilfs);
269 struct nilfs_bmap *bmap = NILFS_I(dat)->i_bmap;
270 struct nilfs_bdesc *bdescs = buf;
273 for (i = 0; i < nmembs; i++) {
274 ret = nilfs_bmap_lookup_at_level(bmap,
276 bdescs[i].bd_level + 1,
277 &bdescs[i].bd_blocknr);
281 bdescs[i].bd_blocknr = 0;
287 static int nilfs_ioctl_get_bdescs(struct inode *inode, struct file *filp,
288 unsigned int cmd, void __user *argp)
290 struct the_nilfs *nilfs = NILFS_SB(inode->i_sb)->s_nilfs;
291 struct nilfs_argv argv;
294 if (copy_from_user(&argv, argp, sizeof(argv)))
297 down_read(&nilfs->ns_segctor_sem);
298 ret = nilfs_ioctl_wrap_copy(nilfs, &argv, _IOC_DIR(cmd),
299 nilfs_ioctl_do_get_bdescs);
300 up_read(&nilfs->ns_segctor_sem);
304 if (copy_to_user(argp, &argv, sizeof(argv)))
309 static int nilfs_ioctl_move_inode_block(struct inode *inode,
310 struct nilfs_vdesc *vdesc,
311 struct list_head *buffers)
313 struct buffer_head *bh;
316 if (vdesc->vd_flags == 0)
317 ret = nilfs_gccache_submit_read_data(
318 inode, vdesc->vd_offset, vdesc->vd_blocknr,
319 vdesc->vd_vblocknr, &bh);
321 ret = nilfs_gccache_submit_read_node(
322 inode, vdesc->vd_blocknr, vdesc->vd_vblocknr, &bh);
324 if (unlikely(ret < 0)) {
327 "%s: invalid virtual block address (%s): "
328 "ino=%llu, cno=%llu, offset=%llu, "
329 "blocknr=%llu, vblocknr=%llu\n",
330 __func__, vdesc->vd_flags ? "node" : "data",
331 (unsigned long long)vdesc->vd_ino,
332 (unsigned long long)vdesc->vd_cno,
333 (unsigned long long)vdesc->vd_offset,
334 (unsigned long long)vdesc->vd_blocknr,
335 (unsigned long long)vdesc->vd_vblocknr);
338 bh->b_private = vdesc;
339 list_add_tail(&bh->b_assoc_buffers, buffers);
344 nilfs_ioctl_do_move_blocks(struct the_nilfs *nilfs, int index, int flags,
345 void *buf, size_t size, size_t nmembs)
348 struct nilfs_vdesc *vdesc;
349 struct buffer_head *bh, *n;
355 for (i = 0, vdesc = buf; i < nmembs; ) {
358 inode = nilfs_gc_iget(nilfs, ino, cno);
359 if (unlikely(inode == NULL)) {
364 ret = nilfs_ioctl_move_inode_block(inode, vdesc,
366 if (unlikely(ret < 0))
369 } while (++i < nmembs &&
370 vdesc->vd_ino == ino && vdesc->vd_cno == cno);
373 list_for_each_entry_safe(bh, n, &buffers, b_assoc_buffers) {
374 ret = nilfs_gccache_wait_and_mark_dirty(bh);
375 if (unlikely(ret < 0)) {
376 if (ret == -EEXIST) {
377 vdesc = bh->b_private;
379 "%s: conflicting %s buffer: "
380 "ino=%llu, cno=%llu, offset=%llu, "
381 "blocknr=%llu, vblocknr=%llu\n",
383 vdesc->vd_flags ? "node" : "data",
384 (unsigned long long)vdesc->vd_ino,
385 (unsigned long long)vdesc->vd_cno,
386 (unsigned long long)vdesc->vd_offset,
387 (unsigned long long)vdesc->vd_blocknr,
388 (unsigned long long)vdesc->vd_vblocknr);
392 list_del_init(&bh->b_assoc_buffers);
393 bh->b_private = NULL;
399 list_for_each_entry_safe(bh, n, &buffers, b_assoc_buffers) {
400 list_del_init(&bh->b_assoc_buffers);
401 bh->b_private = NULL;
407 static inline int nilfs_ioctl_move_blocks(struct the_nilfs *nilfs,
408 struct nilfs_argv *argv,
411 return nilfs_ioctl_wrap_copy(nilfs, argv, dir,
412 nilfs_ioctl_do_move_blocks);
416 nilfs_ioctl_do_delete_checkpoints(struct the_nilfs *nilfs, int index,
417 int flags, void *buf, size_t size,
420 struct inode *cpfile = nilfs->ns_cpfile;
421 struct nilfs_period *periods = buf;
424 for (i = 0; i < nmembs; i++) {
425 ret = nilfs_cpfile_delete_checkpoints(
426 cpfile, periods[i].p_start, periods[i].p_end);
433 static inline int nilfs_ioctl_delete_checkpoints(struct the_nilfs *nilfs,
434 struct nilfs_argv *argv,
437 return nilfs_ioctl_wrap_copy(nilfs, argv, dir,
438 nilfs_ioctl_do_delete_checkpoints);
442 nilfs_ioctl_do_free_vblocknrs(struct the_nilfs *nilfs, int index, int flags,
443 void *buf, size_t size, size_t nmembs)
445 int ret = nilfs_dat_freev(nilfs_dat_inode(nilfs), buf, nmembs);
447 return (ret < 0) ? ret : nmembs;
450 static inline int nilfs_ioctl_free_vblocknrs(struct the_nilfs *nilfs,
451 struct nilfs_argv *argv,
454 return nilfs_ioctl_wrap_copy(nilfs, argv, dir,
455 nilfs_ioctl_do_free_vblocknrs);
459 nilfs_ioctl_do_mark_blocks_dirty(struct the_nilfs *nilfs, int index, int flags,
460 void *buf, size_t size, size_t nmembs)
462 struct inode *dat = nilfs_dat_inode(nilfs);
463 struct nilfs_bmap *bmap = NILFS_I(dat)->i_bmap;
464 struct nilfs_bdesc *bdescs = buf;
467 for (i = 0; i < nmembs; i++) {
468 /* XXX: use macro or inline func to check liveness */
469 ret = nilfs_bmap_lookup_at_level(bmap,
471 bdescs[i].bd_level + 1,
472 &bdescs[i].bd_blocknr);
476 bdescs[i].bd_blocknr = 0;
478 if (bdescs[i].bd_blocknr != bdescs[i].bd_oblocknr)
479 /* skip dead block */
481 if (bdescs[i].bd_level == 0) {
482 ret = nilfs_mdt_mark_block_dirty(dat,
483 bdescs[i].bd_offset);
485 BUG_ON(ret == -ENOENT);
489 ret = nilfs_bmap_mark(bmap, bdescs[i].bd_offset,
492 BUG_ON(ret == -ENOENT);
500 static inline int nilfs_ioctl_mark_blocks_dirty(struct the_nilfs *nilfs,
501 struct nilfs_argv *argv,
504 return nilfs_ioctl_wrap_copy(nilfs, argv, dir,
505 nilfs_ioctl_do_mark_blocks_dirty);
509 nilfs_ioctl_do_free_segments(struct the_nilfs *nilfs, int index, int flags,
510 void *buf, size_t size, size_t nmembs)
512 struct nilfs_sb_info *sbi = nilfs_get_writer(nilfs);
516 ret = nilfs_segctor_add_segments_to_be_freed(
517 NILFS_SC(sbi), buf, nmembs);
518 nilfs_put_writer(nilfs);
520 return (ret < 0) ? ret : nmembs;
523 static inline int nilfs_ioctl_free_segments(struct the_nilfs *nilfs,
524 struct nilfs_argv *argv,
527 return nilfs_ioctl_wrap_copy(nilfs, argv, dir,
528 nilfs_ioctl_do_free_segments);
531 int nilfs_ioctl_prepare_clean_segments(struct the_nilfs *nilfs,
534 struct nilfs_argv argv[5];
537 if (copy_from_user(argv, argp, sizeof(argv)))
541 ret = nilfs_ioctl_move_blocks(nilfs, &argv[0], dir);
544 ret = nilfs_ioctl_delete_checkpoints(nilfs, &argv[1], dir);
547 ret = nilfs_ioctl_free_vblocknrs(nilfs, &argv[2], dir);
550 ret = nilfs_ioctl_mark_blocks_dirty(nilfs, &argv[3], dir);
553 ret = nilfs_ioctl_free_segments(nilfs, &argv[4], dir);
560 BUG(); /* XXX: not implemented yet */
562 BUG();/* XXX: not implemented yet */
564 BUG();/* XXX: not implemented yet */
566 nilfs_remove_all_gcinode(nilfs);
570 static int nilfs_ioctl_clean_segments(struct inode *inode, struct file *filp,
571 unsigned int cmd, void __user *argp)
575 if (!capable(CAP_SYS_ADMIN))
578 ret = nilfs_clean_segments(inode->i_sb, argp);
579 clear_nilfs_cond_nongc_write(NILFS_SB(inode->i_sb)->s_nilfs);
583 static int nilfs_ioctl_test_cond(struct the_nilfs *nilfs, int cond)
585 return (cond & NILFS_TIMEDWAIT_SEG_WRITE) &&
586 nilfs_cond_nongc_write(nilfs);
589 static void nilfs_ioctl_clear_cond(struct the_nilfs *nilfs, int cond)
591 if (cond & NILFS_TIMEDWAIT_SEG_WRITE)
592 clear_nilfs_cond_nongc_write(nilfs);
595 static int nilfs_ioctl_timedwait(struct inode *inode, struct file *filp,
596 unsigned int cmd, void __user *argp)
598 struct the_nilfs *nilfs = NILFS_SB(inode->i_sb)->s_nilfs;
599 struct nilfs_wait_cond wc;
602 if (!capable(CAP_SYS_ADMIN))
604 if (copy_from_user(&wc, argp, sizeof(wc)))
609 wait_event_interruptible_timeout(
610 nilfs->ns_cleanerd_wq,
611 nilfs_ioctl_test_cond(nilfs, wc.wc_cond),
612 timespec_to_jiffies(&wc.wc_timeout)) :
613 wait_event_interruptible(
614 nilfs->ns_cleanerd_wq,
615 nilfs_ioctl_test_cond(nilfs, wc.wc_cond));
617 nilfs_ioctl_clear_cond(nilfs, wc.wc_cond);
620 jiffies_to_timespec(ret, &wc.wc_timeout);
621 if (copy_to_user(argp, &wc, sizeof(wc)))
628 return wc.wc_flags ? -ETIME : 0;
631 static int nilfs_ioctl_sync(struct inode *inode, struct file *filp,
632 unsigned int cmd, void __user *argp)
637 ret = nilfs_construct_segment(inode->i_sb);
642 cno = NILFS_SB(inode->i_sb)->s_nilfs->ns_cno - 1;
643 if (copy_to_user(argp, &cno, sizeof(cno)))
649 int nilfs_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
652 void __user *argp = (void * __user *)arg;
655 case NILFS_IOCTL_CHANGE_CPMODE:
656 return nilfs_ioctl_change_cpmode(inode, filp, cmd, argp);
657 case NILFS_IOCTL_DELETE_CHECKPOINT:
658 return nilfs_ioctl_delete_checkpoint(inode, filp, cmd, argp);
659 case NILFS_IOCTL_GET_CPINFO:
660 return nilfs_ioctl_get_cpinfo(inode, filp, cmd, argp);
661 case NILFS_IOCTL_GET_CPSTAT:
662 return nilfs_ioctl_get_cpstat(inode, filp, cmd, argp);
663 case NILFS_IOCTL_GET_SUINFO:
664 return nilfs_ioctl_get_suinfo(inode, filp, cmd, argp);
665 case NILFS_IOCTL_GET_SUSTAT:
666 return nilfs_ioctl_get_sustat(inode, filp, cmd, argp);
667 case NILFS_IOCTL_GET_VINFO:
668 /* XXX: rename to ??? */
669 return nilfs_ioctl_get_vinfo(inode, filp, cmd, argp);
670 case NILFS_IOCTL_GET_BDESCS:
671 return nilfs_ioctl_get_bdescs(inode, filp, cmd, argp);
672 case NILFS_IOCTL_CLEAN_SEGMENTS:
673 return nilfs_ioctl_clean_segments(inode, filp, cmd, argp);
674 case NILFS_IOCTL_TIMEDWAIT:
675 return nilfs_ioctl_timedwait(inode, filp, cmd, argp);
676 case NILFS_IOCTL_SYNC:
677 return nilfs_ioctl_sync(inode, filp, cmd, argp);
685 #include <linux/compat.h>
687 static int nilfs_compat_locked_ioctl(struct inode *inode, struct file *filp,
688 unsigned int cmd, unsigned long arg)
693 ret = nilfs_ioctl(inode, filp, cmd, arg);
699 nilfs_compat_ioctl_uargv32_to_uargv(struct nilfs_argv32 __user *uargv32,
700 struct nilfs_argv __user *uargv)
703 compat_size_t nmembs, size;
704 compat_int_t index, flags;
706 if (get_user(base, &uargv32->v_base) ||
707 put_user(compat_ptr(base), &uargv->v_base) ||
708 get_user(nmembs, &uargv32->v_nmembs) ||
709 put_user(nmembs, &uargv->v_nmembs) ||
710 get_user(size, &uargv32->v_size) ||
711 put_user(size, &uargv->v_size) ||
712 get_user(index, &uargv32->v_index) ||
713 put_user(index, &uargv->v_index) ||
714 get_user(flags, &uargv32->v_flags) ||
715 put_user(flags, &uargv->v_flags))
721 nilfs_compat_ioctl_uargv_to_uargv32(struct nilfs_argv __user *uargv,
722 struct nilfs_argv32 __user *uargv32)
726 if (get_user(nmembs, &uargv->v_nmembs) ||
727 put_user(nmembs, &uargv32->v_nmembs))
733 nilfs_compat_ioctl_get_by_argv(struct inode *inode, struct file *filp,
734 unsigned int cmd, unsigned long arg)
736 struct nilfs_argv __user *uargv;
737 struct nilfs_argv32 __user *uargv32;
740 uargv = compat_alloc_user_space(sizeof(struct nilfs_argv));
741 uargv32 = compat_ptr(arg);
742 ret = nilfs_compat_ioctl_uargv32_to_uargv(uargv32, uargv);
746 ret = nilfs_compat_locked_ioctl(inode, filp, cmd, (unsigned long)uargv);
750 return nilfs_compat_ioctl_uargv_to_uargv32(uargv, uargv32);
754 nilfs_compat_ioctl_change_cpmode(struct inode *inode, struct file *filp,
755 unsigned int cmd, unsigned long arg)
757 struct nilfs_cpmode __user *ucpmode;
758 struct nilfs_cpmode32 __user *ucpmode32;
761 ucpmode = compat_alloc_user_space(sizeof(struct nilfs_cpmode));
762 ucpmode32 = compat_ptr(arg);
763 if (copy_in_user(&ucpmode->cm_cno, &ucpmode32->cm_cno,
765 get_user(mode, &ucpmode32->cm_mode) ||
766 put_user(mode, &ucpmode->cm_mode))
769 return nilfs_compat_locked_ioctl(
770 inode, filp, cmd, (unsigned long)ucpmode);
775 nilfs_compat_ioctl_delete_checkpoint(struct inode *inode, struct file *filp,
776 unsigned int cmd, unsigned long arg)
778 return nilfs_compat_locked_ioctl(inode, filp, cmd, arg);
782 nilfs_compat_ioctl_get_cpinfo(struct inode *inode, struct file *filp,
783 unsigned int cmd, unsigned long arg)
785 return nilfs_compat_ioctl_get_by_argv(inode, filp, cmd, arg);
789 nilfs_compat_ioctl_get_cpstat(struct inode *inode, struct file *filp,
790 unsigned int cmd, unsigned long arg)
792 return nilfs_compat_locked_ioctl(inode, filp, cmd, arg);
796 nilfs_compat_ioctl_get_suinfo(struct inode *inode, struct file *filp,
797 unsigned int cmd, unsigned long arg)
799 return nilfs_compat_ioctl_get_by_argv(inode, filp, cmd, arg);
803 nilfs_compat_ioctl_get_sustat(struct inode *inode, struct file *filp,
804 unsigned int cmd, unsigned long arg)
806 struct nilfs_sustat __user *usustat;
807 struct nilfs_sustat32 __user *usustat32;
808 time_t ctime, nongc_ctime;
811 usustat = compat_alloc_user_space(sizeof(struct nilfs_sustat));
812 ret = nilfs_compat_locked_ioctl(inode, filp, cmd,
813 (unsigned long)usustat);
817 usustat32 = compat_ptr(arg);
818 if (copy_in_user(&usustat32->ss_nsegs, &usustat->ss_nsegs,
820 copy_in_user(&usustat32->ss_ncleansegs, &usustat->ss_ncleansegs,
822 copy_in_user(&usustat32->ss_ndirtysegs, &usustat->ss_ndirtysegs,
824 get_user(ctime, &usustat->ss_ctime) ||
825 put_user(ctime, &usustat32->ss_ctime) ||
826 get_user(nongc_ctime, &usustat->ss_nongc_ctime) ||
827 put_user(nongc_ctime, &usustat32->ss_nongc_ctime))
833 nilfs_compat_ioctl_get_vinfo(struct inode *inode, struct file *filp,
834 unsigned int cmd, unsigned long arg)
836 return nilfs_compat_ioctl_get_by_argv(inode, filp, cmd, arg);
840 nilfs_compat_ioctl_get_bdescs(struct inode *inode, struct file *filp,
841 unsigned int cmd, unsigned long arg)
843 return nilfs_compat_ioctl_get_by_argv(inode, filp, cmd, arg);
847 nilfs_compat_ioctl_clean_segments(struct inode *inode, struct file *filp,
848 unsigned int cmd, unsigned long arg)
850 struct nilfs_argv __user *uargv;
851 struct nilfs_argv32 __user *uargv32;
854 uargv = compat_alloc_user_space(sizeof(struct nilfs_argv) * 5);
855 uargv32 = compat_ptr(arg);
856 for (i = 0; i < 5; i++) {
857 ret = nilfs_compat_ioctl_uargv32_to_uargv(&uargv32[i],
862 return nilfs_compat_locked_ioctl(
863 inode, filp, cmd, (unsigned long)uargv);
867 nilfs_compat_ioctl_timedwait(struct inode *inode, struct file *filp,
868 unsigned int cmd, unsigned long arg)
870 struct nilfs_wait_cond __user *uwcond;
871 struct nilfs_wait_cond32 __user *uwcond32;
873 int cond, flags, ret;
875 uwcond = compat_alloc_user_space(sizeof(struct nilfs_wait_cond));
876 uwcond32 = compat_ptr(arg);
877 if (get_user(cond, &uwcond32->wc_cond) ||
878 put_user(cond, &uwcond->wc_cond) ||
879 get_user(flags, &uwcond32->wc_flags) ||
880 put_user(flags, &uwcond->wc_flags) ||
881 get_user(ts.tv_sec, &uwcond32->wc_timeout.tv_sec) ||
882 get_user(ts.tv_nsec, &uwcond32->wc_timeout.tv_nsec) ||
883 put_user(ts.tv_sec, &uwcond->wc_timeout.tv_sec) ||
884 put_user(ts.tv_nsec, &uwcond->wc_timeout.tv_nsec))
887 ret = nilfs_compat_locked_ioctl(inode, filp, cmd,
888 (unsigned long)uwcond);
892 if (get_user(ts.tv_sec, &uwcond->wc_timeout.tv_sec) ||
893 get_user(ts.tv_nsec, &uwcond->wc_timeout.tv_nsec) ||
894 put_user(ts.tv_sec, &uwcond32->wc_timeout.tv_sec) ||
895 put_user(ts.tv_nsec, &uwcond32->wc_timeout.tv_nsec))
901 static int nilfs_compat_ioctl_sync(struct inode *inode, struct file *filp,
902 unsigned int cmd, unsigned long arg)
904 return nilfs_compat_locked_ioctl(inode, filp, cmd, arg);
907 long nilfs_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
909 struct inode *inode = filp->f_dentry->d_inode;
912 case NILFS_IOCTL32_CHANGE_CPMODE:
913 return nilfs_compat_ioctl_change_cpmode(
914 inode, filp, NILFS_IOCTL_CHANGE_CPMODE, arg);
915 case NILFS_IOCTL_DELETE_CHECKPOINT:
916 return nilfs_compat_ioctl_delete_checkpoint(
917 inode, filp, cmd, arg);
918 case NILFS_IOCTL32_GET_CPINFO:
919 return nilfs_compat_ioctl_get_cpinfo(
920 inode, filp, NILFS_IOCTL_GET_CPINFO, arg);
921 case NILFS_IOCTL_GET_CPSTAT:
922 return nilfs_compat_ioctl_get_cpstat(inode, filp, cmd, arg);
923 case NILFS_IOCTL32_GET_SUINFO:
924 return nilfs_compat_ioctl_get_suinfo(
925 inode, filp, NILFS_IOCTL_GET_SUINFO, arg);
926 case NILFS_IOCTL32_GET_SUSTAT:
927 return nilfs_compat_ioctl_get_sustat(
928 inode, filp, NILFS_IOCTL_GET_SUSTAT, arg);
929 case NILFS_IOCTL32_GET_VINFO:
930 return nilfs_compat_ioctl_get_vinfo(
931 inode, filp, NILFS_IOCTL_GET_VINFO, arg);
932 case NILFS_IOCTL32_GET_BDESCS:
933 return nilfs_compat_ioctl_get_bdescs(
934 inode, filp, NILFS_IOCTL_GET_BDESCS, arg);
935 case NILFS_IOCTL32_CLEAN_SEGMENTS:
936 return nilfs_compat_ioctl_clean_segments(
937 inode, filp, NILFS_IOCTL_CLEAN_SEGMENTS, arg);
938 case NILFS_IOCTL32_TIMEDWAIT:
939 return nilfs_compat_ioctl_timedwait(
940 inode, filp, NILFS_IOCTL_TIMEDWAIT, arg);
941 case NILFS_IOCTL_SYNC:
942 return nilfs_compat_ioctl_sync(inode, filp, cmd, arg);