* we implement a very minimal set of ioctls for compatibility with sockets. */
| 1341 | * we implement a very minimal set of ioctls for compatibility with sockets. |
| 1342 | */ |
| 1343 | static int |
| 1344 | pipe_ioctl(struct file *fp, u_long cmd, void *data, struct ucred *active_cred, |
| 1345 | struct thread *td) |
| 1346 | { |
| 1347 | struct pipe *mpipe = fp->f_data; |
| 1348 | int error; |
| 1349 | |
| 1350 | PIPE_LOCK(mpipe); |
| 1351 | |
| 1352 | #ifdef MAC |
| 1353 | error = mac_pipe_check_ioctl(active_cred, mpipe->pipe_pair, cmd, data); |
| 1354 | if (error) { |
| 1355 | PIPE_UNLOCK(mpipe); |
| 1356 | return (error); |
| 1357 | } |
| 1358 | #endif |
| 1359 | |
| 1360 | error = 0; |
| 1361 | switch (cmd) { |
| 1362 | case FIONBIO: |
| 1363 | break; |
| 1364 | |
| 1365 | case FIOASYNC: |
| 1366 | if (*(int *)data) { |
| 1367 | mpipe->pipe_state |= PIPE_ASYNC; |
| 1368 | } else { |
| 1369 | mpipe->pipe_state &= ~PIPE_ASYNC; |
| 1370 | } |
| 1371 | break; |
| 1372 | |
| 1373 | case FIONREAD: |
| 1374 | if (!(fp->f_flag & FREAD)) { |
| 1375 | *(int *)data = 0; |
| 1376 | PIPE_UNLOCK(mpipe); |
| 1377 | return (0); |
| 1378 | } |
| 1379 | if (mpipe->pipe_pages.cnt != 0) |
| 1380 | *(int *)data = mpipe->pipe_pages.cnt; |
| 1381 | else |
| 1382 | *(int *)data = mpipe->pipe_buffer.cnt; |
| 1383 | break; |
| 1384 | |
| 1385 | case FIOSETOWN: |
| 1386 | PIPE_UNLOCK(mpipe); |
| 1387 | error = fsetown(*(int *)data, &mpipe->pipe_sigio); |
| 1388 | goto out_unlocked; |
| 1389 | |
| 1390 | case FIOGETOWN: |
| 1391 | *(int *)data = fgetown(&mpipe->pipe_sigio); |
| 1392 | break; |
| 1393 | |
| 1394 | /* This is deprecated, FIOSETOWN should be used instead. */ |
| 1395 | case TIOCSPGRP: |
| 1396 | PIPE_UNLOCK(mpipe); |
| 1397 | error = fsetown(-(*(int *)data), &mpipe->pipe_sigio); |
| 1398 | goto out_unlocked; |
| 1399 | |
| 1400 | /* This is deprecated, FIOGETOWN should be used instead. */ |
nothing calls this directly
no test coverage detected