| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: vfs_syscalls_50.c,v 1.12 2012/01/29 06:29:04 dholland Exp $ */ | | 1 | /* $NetBSD: vfs_syscalls_50.c,v 1.13 2012/01/29 07:16:00 dholland Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2008 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2008 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Christos Zoulas. | | 8 | * by Christos Zoulas. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -26,27 +26,27 @@ | | | @@ -26,27 +26,27 @@ |
26 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | | 26 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS |
27 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 27 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
28 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 28 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
29 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 29 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
30 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 30 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
31 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 31 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
32 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 32 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
33 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 33 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
34 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 34 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
35 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 35 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
36 | * POSSIBILITY OF SUCH DAMAGE. | | 36 | * POSSIBILITY OF SUCH DAMAGE. |
37 | */ | | 37 | */ |
38 | #include <sys/cdefs.h> | | 38 | #include <sys/cdefs.h> |
39 | __KERNEL_RCSID(0, "$NetBSD: vfs_syscalls_50.c,v 1.12 2012/01/29 06:29:04 dholland Exp $"); | | 39 | __KERNEL_RCSID(0, "$NetBSD: vfs_syscalls_50.c,v 1.13 2012/01/29 07:16:00 dholland Exp $"); |
40 | | | 40 | |
41 | #include <sys/param.h> | | 41 | #include <sys/param.h> |
42 | #include <sys/systm.h> | | 42 | #include <sys/systm.h> |
43 | #include <sys/namei.h> | | 43 | #include <sys/namei.h> |
44 | #include <sys/filedesc.h> | | 44 | #include <sys/filedesc.h> |
45 | #include <sys/kernel.h> | | 45 | #include <sys/kernel.h> |
46 | #include <sys/file.h> | | 46 | #include <sys/file.h> |
47 | #include <sys/stat.h> | | 47 | #include <sys/stat.h> |
48 | #include <sys/socketvar.h> | | 48 | #include <sys/socketvar.h> |
49 | #include <sys/vnode.h> | | 49 | #include <sys/vnode.h> |
50 | #include <sys/mount.h> | | 50 | #include <sys/mount.h> |
51 | #include <sys/proc.h> | | 51 | #include <sys/proc.h> |
52 | #include <sys/uio.h> | | 52 | #include <sys/uio.h> |
| @@ -328,26 +328,27 @@ compat_50_sys_quotactl(struct lwp *l, co | | | @@ -328,26 +328,27 @@ compat_50_sys_quotactl(struct lwp *l, co |
328 | syscallarg(void *) arg; | | 328 | syscallarg(void *) arg; |
329 | } */ | | 329 | } */ |
330 | struct mount *mp; | | 330 | struct mount *mp; |
331 | int error; | | 331 | int error; |
332 | uint8_t error8; | | 332 | uint8_t error8; |
333 | struct vnode *vp; | | 333 | struct vnode *vp; |
334 | int q1cmd = SCARG(uap, cmd); | | 334 | int q1cmd = SCARG(uap, cmd); |
335 | prop_dictionary_t dict, data, cmd; | | 335 | prop_dictionary_t dict, data, cmd; |
336 | prop_array_t cmds, datas; | | 336 | prop_array_t cmds, datas; |
337 | char *bufpath; | | 337 | char *bufpath; |
338 | struct dqblk dqblk; | | 338 | struct dqblk dqblk; |
339 | struct quotaval qv[QUOTA_NLIMITS]; | | 339 | struct quotaval qv[QUOTA_NLIMITS]; |
340 | uint64_t *values[QUOTA_NLIMITS]; | | 340 | uint64_t *values[QUOTA_NLIMITS]; |
| | | 341 | int idtype; |
341 | | | 342 | |
342 | values[QUOTA_LIMIT_BLOCK] = &qv[QUOTA_LIMIT_BLOCK].qv_hardlimit; | | 343 | values[QUOTA_LIMIT_BLOCK] = &qv[QUOTA_LIMIT_BLOCK].qv_hardlimit; |
343 | values[QUOTA_LIMIT_FILE] = &qv[QUOTA_LIMIT_FILE].qv_hardlimit; | | 344 | values[QUOTA_LIMIT_FILE] = &qv[QUOTA_LIMIT_FILE].qv_hardlimit; |
344 | | | 345 | |
345 | error = namei_simple_user(SCARG(uap, path), | | 346 | error = namei_simple_user(SCARG(uap, path), |
346 | NSM_FOLLOW_TRYEMULROOT, &vp); | | 347 | NSM_FOLLOW_TRYEMULROOT, &vp); |
347 | if (error != 0) | | 348 | if (error != 0) |
348 | return (error); | | 349 | return (error); |
349 | error = ENOMEM; | | 350 | error = ENOMEM; |
350 | mp = vp->v_mount; | | 351 | mp = vp->v_mount; |
351 | if ((dict = quota_prop_create()) == NULL) | | 352 | if ((dict = quota_prop_create()) == NULL) |
352 | goto out; | | 353 | goto out; |
353 | if ((cmds = prop_array_create()) == NULL) | | 354 | if ((cmds = prop_array_create()) == NULL) |
| @@ -366,36 +367,38 @@ compat_50_sys_quotactl(struct lwp *l, co | | | @@ -366,36 +367,38 @@ compat_50_sys_quotactl(struct lwp *l, co |
366 | error = copyinstr(SCARG(uap, arg), bufpath, PATH_MAX, NULL); | | 367 | error = copyinstr(SCARG(uap, arg), bufpath, PATH_MAX, NULL); |
367 | if (error != 0) { | | 368 | if (error != 0) { |
368 | free(bufpath, M_TEMP); | | 369 | free(bufpath, M_TEMP); |
369 | goto out_data; | | 370 | goto out_data; |
370 | } | | 371 | } |
371 | if (!prop_dictionary_set_cstring(data, "quotafile", bufpath)) | | 372 | if (!prop_dictionary_set_cstring(data, "quotafile", bufpath)) |
372 | error = ENOMEM; | | 373 | error = ENOMEM; |
373 | free(bufpath, M_TEMP); | | 374 | free(bufpath, M_TEMP); |
374 | if (error) | | 375 | if (error) |
375 | goto out_data; | | 376 | goto out_data; |
376 | error = ENOMEM; | | 377 | error = ENOMEM; |
377 | if (!prop_array_add_and_rel(datas, data)) | | 378 | if (!prop_array_add_and_rel(datas, data)) |
378 | goto out_datas; | | 379 | goto out_datas; |
| | | 380 | idtype = quota_idtype_from_ufs(q1cmd & SUBCMDMASK); |
379 | if (!quota_prop_add_command(cmds, "quotaon", | | 381 | if (!quota_prop_add_command(cmds, "quotaon", |
380 | ufs_quota_class_names[qtype2ufsclass(q1cmd & SUBCMDMASK)], | | 382 | ufs_quota_class_names[idtype], |
381 | datas)) | | 383 | datas)) |
382 | goto out_cmds; | | 384 | goto out_cmds; |
383 | goto do_quotaonoff; | | 385 | goto do_quotaonoff; |
384 | | | 386 | |
385 | case Q_QUOTAOFF: | | 387 | case Q_QUOTAOFF: |
386 | error = ENOMEM; | | 388 | error = ENOMEM; |
| | | 389 | idtype = quota_idtype_from_ufs(q1cmd & SUBCMDMASK); |
387 | if (!quota_prop_add_command(cmds, "quotaoff", | | 390 | if (!quota_prop_add_command(cmds, "quotaoff", |
388 | ufs_quota_class_names[qtype2ufsclass(q1cmd & SUBCMDMASK)], | | 391 | ufs_quota_class_names[idtype], |
389 | datas)) | | 392 | datas)) |
390 | goto out_cmds; | | 393 | goto out_cmds; |
391 | do_quotaonoff: | | 394 | do_quotaonoff: |
392 | if (!prop_dictionary_set_and_rel(dict, "commands", cmds)) | | 395 | if (!prop_dictionary_set_and_rel(dict, "commands", cmds)) |
393 | goto out_dict; | | 396 | goto out_dict; |
394 | error = vfs_quotactl(mp, dict); | | 397 | error = vfs_quotactl(mp, dict); |
395 | if (error) | | 398 | if (error) |
396 | goto out_dict; | | 399 | goto out_dict; |
397 | if ((error = quota_get_cmds(dict, &cmds)) != 0) | | 400 | if ((error = quota_get_cmds(dict, &cmds)) != 0) |
398 | goto out_dict; | | 401 | goto out_dict; |
399 | cmd = prop_array_get(cmds, 0); | | 402 | cmd = prop_array_get(cmds, 0); |
400 | if (cmd == NULL) { | | 403 | if (cmd == NULL) { |
401 | error = EINVAL; | | 404 | error = EINVAL; |
| @@ -407,28 +410,29 @@ do_quotaonoff: | | | @@ -407,28 +410,29 @@ do_quotaonoff: |
407 | } | | 410 | } |
408 | error = error8; | | 411 | error = error8; |
409 | goto out_dict; | | 412 | goto out_dict; |
410 | | | 413 | |
411 | case Q_GETQUOTA: | | 414 | case Q_GETQUOTA: |
412 | error = ENOMEM; | | 415 | error = ENOMEM; |
413 | data = prop_dictionary_create(); | | 416 | data = prop_dictionary_create(); |
414 | if (data == NULL) | | 417 | if (data == NULL) |
415 | goto out_datas; | | 418 | goto out_datas; |
416 | if (!prop_dictionary_set_uint32(data, "id", SCARG(uap, uid))) | | 419 | if (!prop_dictionary_set_uint32(data, "id", SCARG(uap, uid))) |
417 | goto out_data; | | 420 | goto out_data; |
418 | if (!prop_array_add_and_rel(datas, data)) | | 421 | if (!prop_array_add_and_rel(datas, data)) |
419 | goto out_datas; | | 422 | goto out_datas; |
| | | 423 | idtype = quota_idtype_from_ufs(q1cmd & SUBCMDMASK); |
420 | if (!quota_prop_add_command(cmds, "get", | | 424 | if (!quota_prop_add_command(cmds, "get", |
421 | ufs_quota_class_names[qtype2ufsclass(q1cmd & SUBCMDMASK)], | | 425 | ufs_quota_class_names[idtype], |
422 | datas)) | | 426 | datas)) |
423 | goto out_cmds; | | 427 | goto out_cmds; |
424 | if (!prop_dictionary_set_and_rel(dict, "commands", cmds)) | | 428 | if (!prop_dictionary_set_and_rel(dict, "commands", cmds)) |
425 | goto out_dict; | | 429 | goto out_dict; |
426 | error = vfs_quotactl(mp, dict); | | 430 | error = vfs_quotactl(mp, dict); |
427 | if (error) | | 431 | if (error) |
428 | goto out_dict; | | 432 | goto out_dict; |
429 | if ((error = quota_get_cmds(dict, &cmds)) != 0) | | 433 | if ((error = quota_get_cmds(dict, &cmds)) != 0) |
430 | goto out_dict; | | 434 | goto out_dict; |
431 | cmd = prop_array_get(cmds, 0); | | 435 | cmd = prop_array_get(cmds, 0); |
432 | if (cmd == NULL) { | | 436 | if (cmd == NULL) { |
433 | error = EINVAL; | | 437 | error = EINVAL; |
434 | goto out_dict; | | 438 | goto out_dict; |
| @@ -463,28 +467,29 @@ do_quotaonoff: | | | @@ -463,28 +467,29 @@ do_quotaonoff: |
463 | if (error) | | 467 | if (error) |
464 | goto out_datas; | | 468 | goto out_datas; |
465 | dqblk_to_quotavals(&dqblk, &qv[QUOTA_LIMIT_BLOCK], | | 469 | dqblk_to_quotavals(&dqblk, &qv[QUOTA_LIMIT_BLOCK], |
466 | &qv[QUOTA_LIMIT_FILE]); | | 470 | &qv[QUOTA_LIMIT_FILE]); |
467 | | | 471 | |
468 | error = ENOMEM; | | 472 | error = ENOMEM; |
469 | data = quota64toprop(SCARG(uap, uid), 0, values, | | 473 | data = quota64toprop(SCARG(uap, uid), 0, values, |
470 | ufs_quota_entry_names, UFS_QUOTA_NENTRIES, | | 474 | ufs_quota_entry_names, UFS_QUOTA_NENTRIES, |
471 | ufs_quota_limit_names, QUOTA_NLIMITS); | | 475 | ufs_quota_limit_names, QUOTA_NLIMITS); |
472 | if (data == NULL) | | 476 | if (data == NULL) |
473 | goto out_data; | | 477 | goto out_data; |
474 | if (!prop_array_add_and_rel(datas, data)) | | 478 | if (!prop_array_add_and_rel(datas, data)) |
475 | goto out_datas; | | 479 | goto out_datas; |
| | | 480 | idtype = quota_idtype_from_ufs(q1cmd & SUBCMDMASK); |
476 | if (!quota_prop_add_command(cmds, "set", | | 481 | if (!quota_prop_add_command(cmds, "set", |
477 | ufs_quota_class_names[qtype2ufsclass(q1cmd & SUBCMDMASK)], | | 482 | ufs_quota_class_names[idtype], |
478 | datas)) | | 483 | datas)) |
479 | goto out_cmds; | | 484 | goto out_cmds; |
480 | if (!prop_dictionary_set_and_rel(dict, "commands", cmds)) | | 485 | if (!prop_dictionary_set_and_rel(dict, "commands", cmds)) |
481 | goto out_dict; | | 486 | goto out_dict; |
482 | error = vfs_quotactl(mp, dict); | | 487 | error = vfs_quotactl(mp, dict); |
483 | if (error) | | 488 | if (error) |
484 | goto out_dict; | | 489 | goto out_dict; |
485 | if ((error = quota_get_cmds(dict, &cmds)) != 0) | | 490 | if ((error = quota_get_cmds(dict, &cmds)) != 0) |
486 | goto out_dict; | | 491 | goto out_dict; |
487 | cmd = prop_array_get(cmds, 0); | | 492 | cmd = prop_array_get(cmds, 0); |
488 | if (cmd == NULL) { | | 493 | if (cmd == NULL) { |
489 | error = EINVAL; | | 494 | error = EINVAL; |
490 | goto out_dict; | | 495 | goto out_dict; |
| @@ -492,28 +497,29 @@ do_quotaonoff: | | | @@ -492,28 +497,29 @@ do_quotaonoff: |
492 | if (!prop_dictionary_get_int8(cmd, "return", &error8)) { | | 497 | if (!prop_dictionary_get_int8(cmd, "return", &error8)) { |
493 | error = EINVAL; | | 498 | error = EINVAL; |
494 | goto out_dict; | | 499 | goto out_dict; |
495 | } | | 500 | } |
496 | error = error8; | | 501 | error = error8; |
497 | goto out_dict; | | 502 | goto out_dict; |
498 | | | 503 | |
499 | case Q_SYNC: | | 504 | case Q_SYNC: |
500 | /* | | 505 | /* |
501 | * not supported but used only to see if quota is supported, | | 506 | * not supported but used only to see if quota is supported, |
502 | * emulate with a "get version" | | 507 | * emulate with a "get version" |
503 | */ | | 508 | */ |
504 | error = ENOMEM; | | 509 | error = ENOMEM; |
| | | 510 | idtype = quota_idtype_from_ufs(q1cmd & SUBCMDMASK); |
505 | if (!quota_prop_add_command(cmds, "get version", | | 511 | if (!quota_prop_add_command(cmds, "get version", |
506 | ufs_quota_class_names[qtype2ufsclass(q1cmd & SUBCMDMASK)], | | 512 | ufs_quota_class_names[idtype], |
507 | datas)) | | 513 | datas)) |
508 | goto out_cmds; | | 514 | goto out_cmds; |
509 | if (!prop_dictionary_set_and_rel(dict, "commands", cmds)) | | 515 | if (!prop_dictionary_set_and_rel(dict, "commands", cmds)) |
510 | goto out_dict; | | 516 | goto out_dict; |
511 | error = vfs_quotactl(mp, dict); | | 517 | error = vfs_quotactl(mp, dict); |
512 | if (error) | | 518 | if (error) |
513 | goto out_dict; | | 519 | goto out_dict; |
514 | if ((error = quota_get_cmds(dict, &cmds)) != 0) | | 520 | if ((error = quota_get_cmds(dict, &cmds)) != 0) |
515 | goto out_dict; | | 521 | goto out_dict; |
516 | cmd = prop_array_get(cmds, 0); | | 522 | cmd = prop_array_get(cmds, 0); |
517 | if (cmd == NULL) { | | 523 | if (cmd == NULL) { |
518 | error = EINVAL; | | 524 | error = EINVAL; |
519 | goto out_dict; | | 525 | goto out_dict; |