17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*facf4a8dSllai1 * Common Development and Distribution License (the "License"). 6*facf4a8dSllai1 * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*facf4a8dSllai1 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 267c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #ifndef _SYS_PTMS_H 307c478bd9Sstevel@tonic-gate #define _SYS_PTMS_H 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate #ifdef __cplusplus 357c478bd9Sstevel@tonic-gate extern "C" { 367c478bd9Sstevel@tonic-gate #endif 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate /* 397c478bd9Sstevel@tonic-gate * Structures and definitions supporting the pseudo terminal 407c478bd9Sstevel@tonic-gate * drivers. This structure is private and should not be used by any 417c478bd9Sstevel@tonic-gate * applications. 427c478bd9Sstevel@tonic-gate */ 437c478bd9Sstevel@tonic-gate struct pt_ttys { 447c478bd9Sstevel@tonic-gate queue_t *ptm_rdq; /* master's read queue pointer */ 457c478bd9Sstevel@tonic-gate queue_t *pts_rdq; /* slave's read queue pointer */ 467c478bd9Sstevel@tonic-gate mblk_t *pt_nullmsg; /* 0-bytes message block for pts close */ 477c478bd9Sstevel@tonic-gate pid_t pt_pid; /* process id (for debugging) */ 487c478bd9Sstevel@tonic-gate minor_t pt_minor; /* Minor number of this pty */ 497c478bd9Sstevel@tonic-gate int pt_refcnt; /* reference count for ptm_rdq/pts_rdq uses */ 507c478bd9Sstevel@tonic-gate ushort_t pt_state; /* state of master/slave pair */ 517c478bd9Sstevel@tonic-gate kcondvar_t pt_cv; /* condition variable for exclusive access */ 527c478bd9Sstevel@tonic-gate kmutex_t pt_lock; /* Per-element lock */ 537c478bd9Sstevel@tonic-gate zoneid_t pt_zoneid; /* Zone membership for this pty */ 54*facf4a8dSllai1 uid_t pt_ruid; /* Real owner of pty */ 55*facf4a8dSllai1 gid_t pt_rgid; /* Real group owner of pty */ 567c478bd9Sstevel@tonic-gate }; 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate /* 597c478bd9Sstevel@tonic-gate * pt_state values 607c478bd9Sstevel@tonic-gate */ 617c478bd9Sstevel@tonic-gate #define PTLOCK 0x01 /* master/slave pair is locked */ 627c478bd9Sstevel@tonic-gate #define PTMOPEN 0x02 /* master side is open */ 637c478bd9Sstevel@tonic-gate #define PTSOPEN 0x04 /* slave side is open */ 647c478bd9Sstevel@tonic-gate #define PTSTTY 0x08 /* slave side is tty */ 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate #ifdef _KERNEL 677c478bd9Sstevel@tonic-gate 687c478bd9Sstevel@tonic-gate /* 697c478bd9Sstevel@tonic-gate * Multi-threading primitives. 707c478bd9Sstevel@tonic-gate * Values of pt_refcnt: -1 if a writer is accessing the struct 717c478bd9Sstevel@tonic-gate * 0 if no one is reading or writing 727c478bd9Sstevel@tonic-gate * > 0 equals to the number of readers accessing the struct 737c478bd9Sstevel@tonic-gate */ 747c478bd9Sstevel@tonic-gate #define PT_ENTER_READ(p) { \ 757c478bd9Sstevel@tonic-gate mutex_enter(&(p)->pt_lock); \ 767c478bd9Sstevel@tonic-gate while ((p)->pt_refcnt < 0) \ 777c478bd9Sstevel@tonic-gate cv_wait(&((p)->pt_cv), &(p)->pt_lock); \ 787c478bd9Sstevel@tonic-gate (p)->pt_refcnt++; \ 797c478bd9Sstevel@tonic-gate mutex_exit(&(p)->pt_lock); \ 807c478bd9Sstevel@tonic-gate } 817c478bd9Sstevel@tonic-gate 827c478bd9Sstevel@tonic-gate #define PT_ENTER_WRITE(p) { \ 837c478bd9Sstevel@tonic-gate mutex_enter(&(p)->pt_lock); \ 847c478bd9Sstevel@tonic-gate while ((p)->pt_refcnt != 0) \ 857c478bd9Sstevel@tonic-gate cv_wait(&((p)->pt_cv), &(p)->pt_lock); \ 867c478bd9Sstevel@tonic-gate (p)->pt_refcnt = -1; \ 877c478bd9Sstevel@tonic-gate mutex_exit(&(p)->pt_lock); \ 887c478bd9Sstevel@tonic-gate } 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate #define PT_EXIT_READ(p) { \ 917c478bd9Sstevel@tonic-gate mutex_enter(&(p)->pt_lock); \ 927c478bd9Sstevel@tonic-gate ASSERT((p)->pt_refcnt > 0); \ 937c478bd9Sstevel@tonic-gate if ((--((p)->pt_refcnt)) == 0) \ 947c478bd9Sstevel@tonic-gate cv_broadcast(&(p)->pt_cv); \ 957c478bd9Sstevel@tonic-gate mutex_exit(&(p)->pt_lock); \ 967c478bd9Sstevel@tonic-gate } 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate #define PT_EXIT_WRITE(p) { \ 997c478bd9Sstevel@tonic-gate mutex_enter(&(p)->pt_lock); \ 1007c478bd9Sstevel@tonic-gate ASSERT((p)->pt_refcnt == -1); \ 1017c478bd9Sstevel@tonic-gate (p)->pt_refcnt = 0; \ 1027c478bd9Sstevel@tonic-gate cv_broadcast(&(p)->pt_cv); \ 1037c478bd9Sstevel@tonic-gate mutex_exit(&(p)->pt_lock); \ 1047c478bd9Sstevel@tonic-gate } 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate /* 1077c478bd9Sstevel@tonic-gate * ptms_lock and pt_cnt are defined in ptms_conf.c 1087c478bd9Sstevel@tonic-gate */ 1097c478bd9Sstevel@tonic-gate extern kmutex_t ptms_lock; 1107c478bd9Sstevel@tonic-gate extern dev_info_t *pts_dip; /* private copy of devinfo ptr */ 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate extern void ptms_init(void); 1137c478bd9Sstevel@tonic-gate extern struct pt_ttys *pt_ttys_alloc(void); 1147c478bd9Sstevel@tonic-gate extern void ptms_close(struct pt_ttys *, uint_t); 1157c478bd9Sstevel@tonic-gate extern struct pt_ttys *ptms_minor2ptty(minor_t); 116*facf4a8dSllai1 extern int ptms_attach_slave(void); 117*facf4a8dSllai1 extern int ptms_minor_valid(minor_t ptmin, uid_t *uid, gid_t *gid); 118*facf4a8dSllai1 extern int ptms_minor_exists(minor_t ptmin); 119*facf4a8dSllai1 extern void ptms_set_owner(minor_t ptmin, uid_t uid, gid_t gid); 120*facf4a8dSllai1 extern major_t ptms_slave_attached(void); 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate #ifdef DEBUG 1237c478bd9Sstevel@tonic-gate extern void ptms_log(char *, uint_t); 1247c478bd9Sstevel@tonic-gate extern void ptms_logp(char *, uintptr_t); 1257c478bd9Sstevel@tonic-gate #define DDBG(a, b) ptms_log(a, b) 1267c478bd9Sstevel@tonic-gate #define DDBGP(a, b) ptms_logp(a, b) 1277c478bd9Sstevel@tonic-gate #else 1287c478bd9Sstevel@tonic-gate #define DDBG(a, b) 1297c478bd9Sstevel@tonic-gate #define DDBGP(a, b) 1307c478bd9Sstevel@tonic-gate #endif 1317c478bd9Sstevel@tonic-gate 1327c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 1337c478bd9Sstevel@tonic-gate 1347c478bd9Sstevel@tonic-gate /* 1357c478bd9Sstevel@tonic-gate * ioctl commands 1367c478bd9Sstevel@tonic-gate * 1377c478bd9Sstevel@tonic-gate * ISPTM: Determines whether the file descriptor is that of an open master 1387c478bd9Sstevel@tonic-gate * device. Return code of zero indicates that the file descriptor 1397c478bd9Sstevel@tonic-gate * represents master device. 1407c478bd9Sstevel@tonic-gate * 1417c478bd9Sstevel@tonic-gate * UNLKPT: Unlocks the master and slave devices. It returns 0 on success. On 1427c478bd9Sstevel@tonic-gate * failure, the errno is set to EINVAL indicating that the master 1437c478bd9Sstevel@tonic-gate * device is not open. 1447c478bd9Sstevel@tonic-gate * 1457c478bd9Sstevel@tonic-gate * ZONEPT: Sets the zoneid of the pair of master and slave devices. It 1467c478bd9Sstevel@tonic-gate * returns 0 upon success. Used to force a pty 'into' a zone upon 1477c478bd9Sstevel@tonic-gate * zone entry. 148*facf4a8dSllai1 * 149*facf4a8dSllai1 * PT_OWNER: Sets uid and gid for slave device. It returns 0 on success. 150*facf4a8dSllai1 * 1517c478bd9Sstevel@tonic-gate */ 1527c478bd9Sstevel@tonic-gate #define ISPTM (('P'<<8)|1) /* query for master */ 1537c478bd9Sstevel@tonic-gate #define UNLKPT (('P'<<8)|2) /* unlock master/slave pair */ 1547c478bd9Sstevel@tonic-gate #define PTSSTTY (('P'<<8)|3) /* set tty flag */ 1557c478bd9Sstevel@tonic-gate #define ZONEPT (('P'<<8)|4) /* set zone of master/slave pair */ 156*facf4a8dSllai1 #define PT_OWNER (('P'<<8)|5) /* set owner and group for slave device */ 157*facf4a8dSllai1 158*facf4a8dSllai1 typedef struct pt_own { 159*facf4a8dSllai1 uid_t pto_ruid; 160*facf4a8dSllai1 gid_t pto_rgid; 161*facf4a8dSllai1 } pt_own_t; 1627c478bd9Sstevel@tonic-gate 1637c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1647c478bd9Sstevel@tonic-gate } 1657c478bd9Sstevel@tonic-gate #endif 1667c478bd9Sstevel@tonic-gate 1677c478bd9Sstevel@tonic-gate #endif /* _SYS_PTMS_H */ 168