* Advisory record locking support */
| 414 | * Advisory record locking support |
| 415 | */ |
| 416 | int |
| 417 | lf_advlockasync(struct vop_advlockasync_args *ap, struct lockf **statep, |
| 418 | u_quad_t size) |
| 419 | { |
| 420 | struct lockf *state; |
| 421 | struct flock *fl = ap->a_fl; |
| 422 | struct lockf_entry *lock; |
| 423 | struct vnode *vp = ap->a_vp; |
| 424 | caddr_t id = ap->a_id; |
| 425 | int flags = ap->a_flags; |
| 426 | int hash; |
| 427 | struct lock_owner *lo; |
| 428 | off_t start, end, oadd; |
| 429 | int error; |
| 430 | |
| 431 | /* |
| 432 | * Handle the F_UNLKSYS case first - no need to mess about |
| 433 | * creating a lock owner for this one. |
| 434 | */ |
| 435 | if (ap->a_op == F_UNLCKSYS) { |
| 436 | lf_clearremotesys(fl->l_sysid); |
| 437 | return (0); |
| 438 | } |
| 439 | |
| 440 | /* |
| 441 | * Convert the flock structure into a start and end. |
| 442 | */ |
| 443 | switch (fl->l_whence) { |
| 444 | case SEEK_SET: |
| 445 | case SEEK_CUR: |
| 446 | /* |
| 447 | * Caller is responsible for adding any necessary offset |
| 448 | * when SEEK_CUR is used. |
| 449 | */ |
| 450 | start = fl->l_start; |
| 451 | break; |
| 452 | |
| 453 | case SEEK_END: |
| 454 | if (size > OFF_MAX || |
| 455 | (fl->l_start > 0 && size > OFF_MAX - fl->l_start)) |
| 456 | return (EOVERFLOW); |
| 457 | start = size + fl->l_start; |
| 458 | break; |
| 459 | |
| 460 | default: |
| 461 | return (EINVAL); |
| 462 | } |
| 463 | if (start < 0) |
| 464 | return (EINVAL); |
| 465 | if (fl->l_len < 0) { |
| 466 | if (start == 0) |
| 467 | return (EINVAL); |
| 468 | end = start - 1; |
| 469 | start += fl->l_len; |
| 470 | if (start < 0) |
| 471 | return (EINVAL); |
| 472 | } else if (fl->l_len == 0) { |
| 473 | end = OFF_MAX; |
no test coverage detected