diff options
Diffstat (limited to 'fs/nilfs2/ioctl.c')
-rw-r--r-- | fs/nilfs2/ioctl.c | 281 |
1 files changed, 146 insertions, 135 deletions
diff --git a/fs/nilfs2/ioctl.c b/fs/nilfs2/ioctl.c index 108d281ebca5..50ff3f2cdf24 100644 --- a/fs/nilfs2/ioctl.c +++ b/fs/nilfs2/ioctl.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include <linux/smp_lock.h> /* lock_kernel(), unlock_kernel() */ | 25 | #include <linux/smp_lock.h> /* lock_kernel(), unlock_kernel() */ |
26 | #include <linux/capability.h> /* capable() */ | 26 | #include <linux/capability.h> /* capable() */ |
27 | #include <linux/uaccess.h> /* copy_from_user(), copy_to_user() */ | 27 | #include <linux/uaccess.h> /* copy_from_user(), copy_to_user() */ |
28 | #include <linux/vmalloc.h> | ||
28 | #include <linux/nilfs2_fs.h> | 29 | #include <linux/nilfs2_fs.h> |
29 | #include "nilfs.h" | 30 | #include "nilfs.h" |
30 | #include "segment.h" | 31 | #include "segment.h" |
@@ -147,29 +148,12 @@ static ssize_t | |||
147 | nilfs_ioctl_do_get_cpinfo(struct the_nilfs *nilfs, __u64 *posp, int flags, | 148 | nilfs_ioctl_do_get_cpinfo(struct the_nilfs *nilfs, __u64 *posp, int flags, |
148 | void *buf, size_t size, size_t nmembs) | 149 | void *buf, size_t size, size_t nmembs) |
149 | { | 150 | { |
150 | return nilfs_cpfile_get_cpinfo(nilfs->ns_cpfile, posp, flags, buf, | ||
151 | nmembs); | ||
152 | } | ||
153 | |||
154 | static int nilfs_ioctl_get_cpinfo(struct inode *inode, struct file *filp, | ||
155 | unsigned int cmd, void __user *argp) | ||
156 | { | ||
157 | struct the_nilfs *nilfs = NILFS_SB(inode->i_sb)->s_nilfs; | ||
158 | struct nilfs_argv argv; | ||
159 | int ret; | 151 | int ret; |
160 | 152 | ||
161 | if (copy_from_user(&argv, argp, sizeof(argv))) | ||
162 | return -EFAULT; | ||
163 | |||
164 | down_read(&nilfs->ns_segctor_sem); | 153 | down_read(&nilfs->ns_segctor_sem); |
165 | ret = nilfs_ioctl_wrap_copy(nilfs, &argv, _IOC_DIR(cmd), | 154 | ret = nilfs_cpfile_get_cpinfo(nilfs->ns_cpfile, posp, flags, buf, |
166 | nilfs_ioctl_do_get_cpinfo); | 155 | nmembs); |
167 | up_read(&nilfs->ns_segctor_sem); | 156 | up_read(&nilfs->ns_segctor_sem); |
168 | if (ret < 0) | ||
169 | return ret; | ||
170 | |||
171 | if (copy_to_user(argp, &argv, sizeof(argv))) | ||
172 | ret = -EFAULT; | ||
173 | return ret; | 157 | return ret; |
174 | } | 158 | } |
175 | 159 | ||
@@ -195,28 +179,11 @@ static ssize_t | |||
195 | nilfs_ioctl_do_get_suinfo(struct the_nilfs *nilfs, __u64 *posp, int flags, | 179 | nilfs_ioctl_do_get_suinfo(struct the_nilfs *nilfs, __u64 *posp, int flags, |
196 | void *buf, size_t size, size_t nmembs) | 180 | void *buf, size_t size, size_t nmembs) |
197 | { | 181 | { |
198 | return nilfs_sufile_get_suinfo(nilfs->ns_sufile, *posp, buf, nmembs); | ||
199 | } | ||
200 | |||
201 | static int nilfs_ioctl_get_suinfo(struct inode *inode, struct file *filp, | ||
202 | unsigned int cmd, void __user *argp) | ||
203 | { | ||
204 | struct the_nilfs *nilfs = NILFS_SB(inode->i_sb)->s_nilfs; | ||
205 | struct nilfs_argv argv; | ||
206 | int ret; | 182 | int ret; |
207 | 183 | ||
208 | if (copy_from_user(&argv, argp, sizeof(argv))) | ||
209 | return -EFAULT; | ||
210 | |||
211 | down_read(&nilfs->ns_segctor_sem); | 184 | down_read(&nilfs->ns_segctor_sem); |
212 | ret = nilfs_ioctl_wrap_copy(nilfs, &argv, _IOC_DIR(cmd), | 185 | ret = nilfs_sufile_get_suinfo(nilfs->ns_sufile, *posp, buf, nmembs); |
213 | nilfs_ioctl_do_get_suinfo); | ||
214 | up_read(&nilfs->ns_segctor_sem); | 186 | up_read(&nilfs->ns_segctor_sem); |
215 | if (ret < 0) | ||
216 | return ret; | ||
217 | |||
218 | if (copy_to_user(argp, &argv, sizeof(argv))) | ||
219 | ret = -EFAULT; | ||
220 | return ret; | 187 | return ret; |
221 | } | 188 | } |
222 | 189 | ||
@@ -242,28 +209,11 @@ static ssize_t | |||
242 | nilfs_ioctl_do_get_vinfo(struct the_nilfs *nilfs, __u64 *posp, int flags, | 209 | nilfs_ioctl_do_get_vinfo(struct the_nilfs *nilfs, __u64 *posp, int flags, |
243 | void *buf, size_t size, size_t nmembs) | 210 | void *buf, size_t size, size_t nmembs) |
244 | { | 211 | { |
245 | return nilfs_dat_get_vinfo(nilfs_dat_inode(nilfs), buf, nmembs); | ||
246 | } | ||
247 | |||
248 | static int nilfs_ioctl_get_vinfo(struct inode *inode, struct file *filp, | ||
249 | unsigned int cmd, void __user *argp) | ||
250 | { | ||
251 | struct the_nilfs *nilfs = NILFS_SB(inode->i_sb)->s_nilfs; | ||
252 | struct nilfs_argv argv; | ||
253 | int ret; | 212 | int ret; |
254 | 213 | ||
255 | if (copy_from_user(&argv, argp, sizeof(argv))) | ||
256 | return -EFAULT; | ||
257 | |||
258 | down_read(&nilfs->ns_segctor_sem); | 214 | down_read(&nilfs->ns_segctor_sem); |
259 | ret = nilfs_ioctl_wrap_copy(nilfs, &argv, _IOC_DIR(cmd), | 215 | ret = nilfs_dat_get_vinfo(nilfs_dat_inode(nilfs), buf, nmembs); |
260 | nilfs_ioctl_do_get_vinfo); | ||
261 | up_read(&nilfs->ns_segctor_sem); | 216 | up_read(&nilfs->ns_segctor_sem); |
262 | if (ret < 0) | ||
263 | return ret; | ||
264 | |||
265 | if (copy_to_user(argp, &argv, sizeof(argv))) | ||
266 | ret = -EFAULT; | ||
267 | return ret; | 217 | return ret; |
268 | } | 218 | } |
269 | 219 | ||
@@ -276,17 +226,21 @@ nilfs_ioctl_do_get_bdescs(struct the_nilfs *nilfs, __u64 *posp, int flags, | |||
276 | struct nilfs_bdesc *bdescs = buf; | 226 | struct nilfs_bdesc *bdescs = buf; |
277 | int ret, i; | 227 | int ret, i; |
278 | 228 | ||
229 | down_read(&nilfs->ns_segctor_sem); | ||
279 | for (i = 0; i < nmembs; i++) { | 230 | for (i = 0; i < nmembs; i++) { |
280 | ret = nilfs_bmap_lookup_at_level(bmap, | 231 | ret = nilfs_bmap_lookup_at_level(bmap, |
281 | bdescs[i].bd_offset, | 232 | bdescs[i].bd_offset, |
282 | bdescs[i].bd_level + 1, | 233 | bdescs[i].bd_level + 1, |
283 | &bdescs[i].bd_blocknr); | 234 | &bdescs[i].bd_blocknr); |
284 | if (ret < 0) { | 235 | if (ret < 0) { |
285 | if (ret != -ENOENT) | 236 | if (ret != -ENOENT) { |
237 | up_read(&nilfs->ns_segctor_sem); | ||
286 | return ret; | 238 | return ret; |
239 | } | ||
287 | bdescs[i].bd_blocknr = 0; | 240 | bdescs[i].bd_blocknr = 0; |
288 | } | 241 | } |
289 | } | 242 | } |
243 | up_read(&nilfs->ns_segctor_sem); | ||
290 | return nmembs; | 244 | return nmembs; |
291 | } | 245 | } |
292 | 246 | ||
@@ -300,10 +254,11 @@ static int nilfs_ioctl_get_bdescs(struct inode *inode, struct file *filp, | |||
300 | if (copy_from_user(&argv, argp, sizeof(argv))) | 254 | if (copy_from_user(&argv, argp, sizeof(argv))) |
301 | return -EFAULT; | 255 | return -EFAULT; |
302 | 256 | ||
303 | down_read(&nilfs->ns_segctor_sem); | 257 | if (argv.v_size != sizeof(struct nilfs_bdesc)) |
258 | return -EINVAL; | ||
259 | |||
304 | ret = nilfs_ioctl_wrap_copy(nilfs, &argv, _IOC_DIR(cmd), | 260 | ret = nilfs_ioctl_wrap_copy(nilfs, &argv, _IOC_DIR(cmd), |
305 | nilfs_ioctl_do_get_bdescs); | 261 | nilfs_ioctl_do_get_bdescs); |
306 | up_read(&nilfs->ns_segctor_sem); | ||
307 | if (ret < 0) | 262 | if (ret < 0) |
308 | return ret; | 263 | return ret; |
309 | 264 | ||
@@ -346,10 +301,10 @@ static int nilfs_ioctl_move_inode_block(struct inode *inode, | |||
346 | return 0; | 301 | return 0; |
347 | } | 302 | } |
348 | 303 | ||
349 | static ssize_t | 304 | static int nilfs_ioctl_move_blocks(struct the_nilfs *nilfs, |
350 | nilfs_ioctl_do_move_blocks(struct the_nilfs *nilfs, __u64 *posp, int flags, | 305 | struct nilfs_argv *argv, void *buf) |
351 | void *buf, size_t size, size_t nmembs) | ||
352 | { | 306 | { |
307 | size_t nmembs = argv->v_nmembs; | ||
353 | struct inode *inode; | 308 | struct inode *inode; |
354 | struct nilfs_vdesc *vdesc; | 309 | struct nilfs_vdesc *vdesc; |
355 | struct buffer_head *bh, *n; | 310 | struct buffer_head *bh, *n; |
@@ -410,19 +365,10 @@ nilfs_ioctl_do_move_blocks(struct the_nilfs *nilfs, __u64 *posp, int flags, | |||
410 | return ret; | 365 | return ret; |
411 | } | 366 | } |
412 | 367 | ||
413 | static inline int nilfs_ioctl_move_blocks(struct the_nilfs *nilfs, | 368 | static int nilfs_ioctl_delete_checkpoints(struct the_nilfs *nilfs, |
414 | struct nilfs_argv *argv, | 369 | struct nilfs_argv *argv, void *buf) |
415 | int dir) | ||
416 | { | ||
417 | return nilfs_ioctl_wrap_copy(nilfs, argv, dir, | ||
418 | nilfs_ioctl_do_move_blocks); | ||
419 | } | ||
420 | |||
421 | static ssize_t | ||
422 | nilfs_ioctl_do_delete_checkpoints(struct the_nilfs *nilfs, __u64 *posp, | ||
423 | int flags, void *buf, size_t size, | ||
424 | size_t nmembs) | ||
425 | { | 370 | { |
371 | size_t nmembs = argv->v_nmembs; | ||
426 | struct inode *cpfile = nilfs->ns_cpfile; | 372 | struct inode *cpfile = nilfs->ns_cpfile; |
427 | struct nilfs_period *periods = buf; | 373 | struct nilfs_period *periods = buf; |
428 | int ret, i; | 374 | int ret, i; |
@@ -436,36 +382,21 @@ nilfs_ioctl_do_delete_checkpoints(struct the_nilfs *nilfs, __u64 *posp, | |||
436 | return nmembs; | 382 | return nmembs; |
437 | } | 383 | } |
438 | 384 | ||
439 | static inline int nilfs_ioctl_delete_checkpoints(struct the_nilfs *nilfs, | 385 | static int nilfs_ioctl_free_vblocknrs(struct the_nilfs *nilfs, |
440 | struct nilfs_argv *argv, | 386 | struct nilfs_argv *argv, void *buf) |
441 | int dir) | ||
442 | { | 387 | { |
443 | return nilfs_ioctl_wrap_copy(nilfs, argv, dir, | 388 | size_t nmembs = argv->v_nmembs; |
444 | nilfs_ioctl_do_delete_checkpoints); | 389 | int ret; |
445 | } | ||
446 | 390 | ||
447 | static ssize_t | 391 | ret = nilfs_dat_freev(nilfs_dat_inode(nilfs), buf, nmembs); |
448 | nilfs_ioctl_do_free_vblocknrs(struct the_nilfs *nilfs, __u64 *posp, int flags, | ||
449 | void *buf, size_t size, size_t nmembs) | ||
450 | { | ||
451 | int ret = nilfs_dat_freev(nilfs_dat_inode(nilfs), buf, nmembs); | ||
452 | 392 | ||
453 | return (ret < 0) ? ret : nmembs; | 393 | return (ret < 0) ? ret : nmembs; |
454 | } | 394 | } |
455 | 395 | ||
456 | static inline int nilfs_ioctl_free_vblocknrs(struct the_nilfs *nilfs, | 396 | static int nilfs_ioctl_mark_blocks_dirty(struct the_nilfs *nilfs, |
457 | struct nilfs_argv *argv, | 397 | struct nilfs_argv *argv, void *buf) |
458 | int dir) | ||
459 | { | ||
460 | return nilfs_ioctl_wrap_copy(nilfs, argv, dir, | ||
461 | nilfs_ioctl_do_free_vblocknrs); | ||
462 | } | ||
463 | |||
464 | static ssize_t | ||
465 | nilfs_ioctl_do_mark_blocks_dirty(struct the_nilfs *nilfs, __u64 *posp, | ||
466 | int flags, void *buf, size_t size, | ||
467 | size_t nmembs) | ||
468 | { | 398 | { |
399 | size_t nmembs = argv->v_nmembs; | ||
469 | struct inode *dat = nilfs_dat_inode(nilfs); | 400 | struct inode *dat = nilfs_dat_inode(nilfs); |
470 | struct nilfs_bmap *bmap = NILFS_I(dat)->i_bmap; | 401 | struct nilfs_bmap *bmap = NILFS_I(dat)->i_bmap; |
471 | struct nilfs_bdesc *bdescs = buf; | 402 | struct nilfs_bdesc *bdescs = buf; |
@@ -504,55 +435,37 @@ nilfs_ioctl_do_mark_blocks_dirty(struct the_nilfs *nilfs, __u64 *posp, | |||
504 | return nmembs; | 435 | return nmembs; |
505 | } | 436 | } |
506 | 437 | ||
507 | static inline int nilfs_ioctl_mark_blocks_dirty(struct the_nilfs *nilfs, | 438 | static int nilfs_ioctl_free_segments(struct the_nilfs *nilfs, |
508 | struct nilfs_argv *argv, | 439 | struct nilfs_argv *argv, void *buf) |
509 | int dir) | ||
510 | { | 440 | { |
511 | return nilfs_ioctl_wrap_copy(nilfs, argv, dir, | 441 | size_t nmembs = argv->v_nmembs; |
512 | nilfs_ioctl_do_mark_blocks_dirty); | 442 | struct nilfs_sb_info *sbi = nilfs->ns_writer; |
513 | } | ||
514 | |||
515 | static ssize_t | ||
516 | nilfs_ioctl_do_free_segments(struct the_nilfs *nilfs, __u64 *posp, int flags, | ||
517 | void *buf, size_t size, size_t nmembs) | ||
518 | { | ||
519 | struct nilfs_sb_info *sbi = nilfs_get_writer(nilfs); | ||
520 | int ret; | 443 | int ret; |
521 | 444 | ||
522 | if (unlikely(!sbi)) | 445 | if (unlikely(!sbi)) { |
446 | /* never happens because called for a writable mount */ | ||
447 | WARN_ON(1); | ||
523 | return -EROFS; | 448 | return -EROFS; |
449 | } | ||
524 | ret = nilfs_segctor_add_segments_to_be_freed( | 450 | ret = nilfs_segctor_add_segments_to_be_freed( |
525 | NILFS_SC(sbi), buf, nmembs); | 451 | NILFS_SC(sbi), buf, nmembs); |
526 | nilfs_put_writer(nilfs); | ||
527 | 452 | ||
528 | return (ret < 0) ? ret : nmembs; | 453 | return (ret < 0) ? ret : nmembs; |
529 | } | 454 | } |
530 | 455 | ||
531 | static inline int nilfs_ioctl_free_segments(struct the_nilfs *nilfs, | ||
532 | struct nilfs_argv *argv, | ||
533 | int dir) | ||
534 | { | ||
535 | return nilfs_ioctl_wrap_copy(nilfs, argv, dir, | ||
536 | nilfs_ioctl_do_free_segments); | ||
537 | } | ||
538 | |||
539 | int nilfs_ioctl_prepare_clean_segments(struct the_nilfs *nilfs, | 456 | int nilfs_ioctl_prepare_clean_segments(struct the_nilfs *nilfs, |
540 | void __user *argp) | 457 | struct nilfs_argv *argv, void **kbufs) |
541 | { | 458 | { |
542 | struct nilfs_argv argv[5]; | ||
543 | const char *msg; | 459 | const char *msg; |
544 | int dir, ret; | 460 | int ret; |
545 | |||
546 | if (copy_from_user(argv, argp, sizeof(argv))) | ||
547 | return -EFAULT; | ||
548 | 461 | ||
549 | dir = _IOC_WRITE; | 462 | ret = nilfs_ioctl_move_blocks(nilfs, &argv[0], kbufs[0]); |
550 | ret = nilfs_ioctl_move_blocks(nilfs, &argv[0], dir); | ||
551 | if (ret < 0) { | 463 | if (ret < 0) { |
552 | msg = "cannot read source blocks"; | 464 | msg = "cannot read source blocks"; |
553 | goto failed; | 465 | goto failed; |
554 | } | 466 | } |
555 | ret = nilfs_ioctl_delete_checkpoints(nilfs, &argv[1], dir); | 467 | |
468 | ret = nilfs_ioctl_delete_checkpoints(nilfs, &argv[1], kbufs[1]); | ||
556 | if (ret < 0) { | 469 | if (ret < 0) { |
557 | /* | 470 | /* |
558 | * can safely abort because checkpoints can be removed | 471 | * can safely abort because checkpoints can be removed |
@@ -561,7 +474,7 @@ int nilfs_ioctl_prepare_clean_segments(struct the_nilfs *nilfs, | |||
561 | msg = "cannot delete checkpoints"; | 474 | msg = "cannot delete checkpoints"; |
562 | goto failed; | 475 | goto failed; |
563 | } | 476 | } |
564 | ret = nilfs_ioctl_free_vblocknrs(nilfs, &argv[2], dir); | 477 | ret = nilfs_ioctl_free_vblocknrs(nilfs, &argv[2], kbufs[2]); |
565 | if (ret < 0) { | 478 | if (ret < 0) { |
566 | /* | 479 | /* |
567 | * can safely abort because DAT file is updated atomically | 480 | * can safely abort because DAT file is updated atomically |
@@ -570,7 +483,7 @@ int nilfs_ioctl_prepare_clean_segments(struct the_nilfs *nilfs, | |||
570 | msg = "cannot delete virtual blocks from DAT file"; | 483 | msg = "cannot delete virtual blocks from DAT file"; |
571 | goto failed; | 484 | goto failed; |
572 | } | 485 | } |
573 | ret = nilfs_ioctl_mark_blocks_dirty(nilfs, &argv[3], dir); | 486 | ret = nilfs_ioctl_mark_blocks_dirty(nilfs, &argv[3], kbufs[3]); |
574 | if (ret < 0) { | 487 | if (ret < 0) { |
575 | /* | 488 | /* |
576 | * can safely abort because the operation is nondestructive. | 489 | * can safely abort because the operation is nondestructive. |
@@ -578,7 +491,7 @@ int nilfs_ioctl_prepare_clean_segments(struct the_nilfs *nilfs, | |||
578 | msg = "cannot mark copying blocks dirty"; | 491 | msg = "cannot mark copying blocks dirty"; |
579 | goto failed; | 492 | goto failed; |
580 | } | 493 | } |
581 | ret = nilfs_ioctl_free_segments(nilfs, &argv[4], dir); | 494 | ret = nilfs_ioctl_free_segments(nilfs, &argv[4], kbufs[4]); |
582 | if (ret < 0) { | 495 | if (ret < 0) { |
583 | /* | 496 | /* |
584 | * can safely abort because this operation is atomic. | 497 | * can safely abort because this operation is atomic. |
@@ -598,9 +511,75 @@ int nilfs_ioctl_prepare_clean_segments(struct the_nilfs *nilfs, | |||
598 | static int nilfs_ioctl_clean_segments(struct inode *inode, struct file *filp, | 511 | static int nilfs_ioctl_clean_segments(struct inode *inode, struct file *filp, |
599 | unsigned int cmd, void __user *argp) | 512 | unsigned int cmd, void __user *argp) |
600 | { | 513 | { |
514 | struct nilfs_argv argv[5]; | ||
515 | const static size_t argsz[5] = { | ||
516 | sizeof(struct nilfs_vdesc), | ||
517 | sizeof(struct nilfs_period), | ||
518 | sizeof(__u64), | ||
519 | sizeof(struct nilfs_bdesc), | ||
520 | sizeof(__u64), | ||
521 | }; | ||
522 | void __user *base; | ||
523 | void *kbufs[5]; | ||
524 | struct the_nilfs *nilfs; | ||
525 | size_t len, nsegs; | ||
526 | int n, ret; | ||
527 | |||
601 | if (!capable(CAP_SYS_ADMIN)) | 528 | if (!capable(CAP_SYS_ADMIN)) |
602 | return -EPERM; | 529 | return -EPERM; |
603 | return nilfs_clean_segments(inode->i_sb, argp); | 530 | |
531 | if (copy_from_user(argv, argp, sizeof(argv))) | ||
532 | return -EFAULT; | ||
533 | |||
534 | nsegs = argv[4].v_nmembs; | ||
535 | if (argv[4].v_size != argsz[4]) | ||
536 | return -EINVAL; | ||
537 | /* | ||
538 | * argv[4] points to segment numbers this ioctl cleans. We | ||
539 | * use kmalloc() for its buffer because memory used for the | ||
540 | * segment numbers is enough small. | ||
541 | */ | ||
542 | kbufs[4] = memdup_user((void __user *)(unsigned long)argv[4].v_base, | ||
543 | nsegs * sizeof(__u64)); | ||
544 | if (IS_ERR(kbufs[4])) | ||
545 | return PTR_ERR(kbufs[4]); | ||
546 | |||
547 | nilfs = NILFS_SB(inode->i_sb)->s_nilfs; | ||
548 | |||
549 | for (n = 0; n < 4; n++) { | ||
550 | ret = -EINVAL; | ||
551 | if (argv[n].v_size != argsz[n]) | ||
552 | goto out_free; | ||
553 | |||
554 | if (argv[n].v_nmembs > nsegs * nilfs->ns_blocks_per_segment) | ||
555 | goto out_free; | ||
556 | |||
557 | len = argv[n].v_size * argv[n].v_nmembs; | ||
558 | base = (void __user *)(unsigned long)argv[n].v_base; | ||
559 | if (len == 0) { | ||
560 | kbufs[n] = NULL; | ||
561 | continue; | ||
562 | } | ||
563 | |||
564 | kbufs[n] = vmalloc(len); | ||
565 | if (!kbufs[n]) { | ||
566 | ret = -ENOMEM; | ||
567 | goto out_free; | ||
568 | } | ||
569 | if (copy_from_user(kbufs[n], base, len)) { | ||
570 | ret = -EFAULT; | ||
571 | vfree(kbufs[n]); | ||
572 | goto out_free; | ||
573 | } | ||
574 | } | ||
575 | |||
576 | ret = nilfs_clean_segments(inode->i_sb, argv, kbufs); | ||
577 | |||
578 | out_free: | ||
579 | while (--n > 0) | ||
580 | vfree(kbufs[n]); | ||
581 | kfree(kbufs[4]); | ||
582 | return ret; | ||
604 | } | 583 | } |
605 | 584 | ||
606 | static int nilfs_ioctl_sync(struct inode *inode, struct file *filp, | 585 | static int nilfs_ioctl_sync(struct inode *inode, struct file *filp, |
@@ -621,6 +600,33 @@ static int nilfs_ioctl_sync(struct inode *inode, struct file *filp, | |||
621 | return 0; | 600 | return 0; |
622 | } | 601 | } |
623 | 602 | ||
603 | static int nilfs_ioctl_get_info(struct inode *inode, struct file *filp, | ||
604 | unsigned int cmd, void __user *argp, | ||
605 | size_t membsz, | ||
606 | ssize_t (*dofunc)(struct the_nilfs *, | ||
607 | __u64 *, int, | ||
608 | void *, size_t, size_t)) | ||
609 | |||
610 | { | ||
611 | struct the_nilfs *nilfs = NILFS_SB(inode->i_sb)->s_nilfs; | ||
612 | struct nilfs_argv argv; | ||
613 | int ret; | ||
614 | |||
615 | if (copy_from_user(&argv, argp, sizeof(argv))) | ||
616 | return -EFAULT; | ||
617 | |||
618 | if (argv.v_size != membsz) | ||
619 | return -EINVAL; | ||
620 | |||
621 | ret = nilfs_ioctl_wrap_copy(nilfs, &argv, _IOC_DIR(cmd), dofunc); | ||
622 | if (ret < 0) | ||
623 | return ret; | ||
624 | |||
625 | if (copy_to_user(argp, &argv, sizeof(argv))) | ||
626 | ret = -EFAULT; | ||
627 | return ret; | ||
628 | } | ||
629 | |||
624 | long nilfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) | 630 | long nilfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) |
625 | { | 631 | { |
626 | struct inode *inode = filp->f_dentry->d_inode; | 632 | struct inode *inode = filp->f_dentry->d_inode; |
@@ -632,16 +638,21 @@ long nilfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) | |||
632 | case NILFS_IOCTL_DELETE_CHECKPOINT: | 638 | case NILFS_IOCTL_DELETE_CHECKPOINT: |
633 | return nilfs_ioctl_delete_checkpoint(inode, filp, cmd, argp); | 639 | return nilfs_ioctl_delete_checkpoint(inode, filp, cmd, argp); |
634 | case NILFS_IOCTL_GET_CPINFO: | 640 | case NILFS_IOCTL_GET_CPINFO: |
635 | return nilfs_ioctl_get_cpinfo(inode, filp, cmd, argp); | 641 | return nilfs_ioctl_get_info(inode, filp, cmd, argp, |
642 | sizeof(struct nilfs_cpinfo), | ||
643 | nilfs_ioctl_do_get_cpinfo); | ||
636 | case NILFS_IOCTL_GET_CPSTAT: | 644 | case NILFS_IOCTL_GET_CPSTAT: |
637 | return nilfs_ioctl_get_cpstat(inode, filp, cmd, argp); | 645 | return nilfs_ioctl_get_cpstat(inode, filp, cmd, argp); |
638 | case NILFS_IOCTL_GET_SUINFO: | 646 | case NILFS_IOCTL_GET_SUINFO: |
639 | return nilfs_ioctl_get_suinfo(inode, filp, cmd, argp); | 647 | return nilfs_ioctl_get_info(inode, filp, cmd, argp, |
648 | sizeof(struct nilfs_suinfo), | ||
649 | nilfs_ioctl_do_get_suinfo); | ||
640 | case NILFS_IOCTL_GET_SUSTAT: | 650 | case NILFS_IOCTL_GET_SUSTAT: |
641 | return nilfs_ioctl_get_sustat(inode, filp, cmd, argp); | 651 | return nilfs_ioctl_get_sustat(inode, filp, cmd, argp); |
642 | case NILFS_IOCTL_GET_VINFO: | 652 | case NILFS_IOCTL_GET_VINFO: |
643 | /* XXX: rename to ??? */ | 653 | return nilfs_ioctl_get_info(inode, filp, cmd, argp, |
644 | return nilfs_ioctl_get_vinfo(inode, filp, cmd, argp); | 654 | sizeof(struct nilfs_vinfo), |
655 | nilfs_ioctl_do_get_vinfo); | ||
645 | case NILFS_IOCTL_GET_BDESCS: | 656 | case NILFS_IOCTL_GET_BDESCS: |
646 | return nilfs_ioctl_get_bdescs(inode, filp, cmd, argp); | 657 | return nilfs_ioctl_get_bdescs(inode, filp, cmd, argp); |
647 | case NILFS_IOCTL_CLEAN_SEGMENTS: | 658 | case NILFS_IOCTL_CLEAN_SEGMENTS: |