|
Lines 92-97
Link Here
|
| 92 |
#include <linux/smp_lock.h> |
92 |
#include <linux/smp_lock.h> |
| 93 |
#include <linux/device.h> |
93 |
#include <linux/device.h> |
| 94 |
#include <linux/idr.h> |
94 |
#include <linux/idr.h> |
|
|
95 |
#include <linux/wait.h> |
| 95 |
|
96 |
|
| 96 |
#include <asm/uaccess.h> |
97 |
#include <asm/uaccess.h> |
| 97 |
#include <asm/system.h> |
98 |
#include <asm/system.h> |
|
Lines 120-129
Link Here
|
| 120 |
|
121 |
|
| 121 |
EXPORT_SYMBOL(tty_std_termios); |
122 |
EXPORT_SYMBOL(tty_std_termios); |
| 122 |
|
123 |
|
|
|
124 |
/* This list gets poked at by procfs and various bits of boot up code. This |
| 125 |
could do with some rationalisation such as pulling the tty proc function |
| 126 |
into this file */ |
| 127 |
|
| 123 |
LIST_HEAD(tty_drivers); /* linked list of tty drivers */ |
128 |
LIST_HEAD(tty_drivers); /* linked list of tty drivers */ |
| 124 |
struct tty_ldisc ldiscs[NR_LDISCS]; /* line disc dispatch table */ |
|
|
| 125 |
|
129 |
|
| 126 |
/* Semaphore to protect creating and releasing a tty */ |
130 |
/* Semaphore to protect creating and releasing a tty. This is shared with |
|
|
131 |
vt.c for deeply disgusting hack reasons */ |
| 127 |
DECLARE_MUTEX(tty_sem); |
132 |
DECLARE_MUTEX(tty_sem); |
| 128 |
|
133 |
|
| 129 |
#ifdef CONFIG_UNIX98_PTYS |
134 |
#ifdef CONFIG_UNIX98_PTYS |
|
Lines 224-288
Link Here
|
| 224 |
return 0; |
229 |
return 0; |
| 225 |
} |
230 |
} |
| 226 |
|
231 |
|
|
|
232 |
/* |
| 233 |
* This is probably overkill for real world processors but |
| 234 |
* they are not on hot paths so a little discipline won't do |
| 235 |
* any harm. |
| 236 |
*/ |
| 237 |
|
| 238 |
static void tty_set_termios_ldisc(struct tty_struct *tty, int num) |
| 239 |
{ |
| 240 |
down(&tty->termios_sem); |
| 241 |
tty->termios->c_line = num; |
| 242 |
up(&tty->termios_sem); |
| 243 |
} |
| 244 |
|
| 245 |
/* |
| 246 |
* This guards the refcounted line discipline lists. The lock |
| 247 |
* must be taken with irqs off because there are hangup path |
| 248 |
* callers who will do ldisc lookups and cannot sleep. |
| 249 |
*/ |
| 250 |
|
| 251 |
static spinlock_t tty_ldisc_lock = SPIN_LOCK_UNLOCKED; |
| 252 |
static DECLARE_WAIT_QUEUE_HEAD(tty_ldisc_wait); |
| 253 |
static struct tty_ldisc tty_ldiscs[NR_LDISCS]; /* line disc dispatch table */ |
| 254 |
|
| 227 |
int tty_register_ldisc(int disc, struct tty_ldisc *new_ldisc) |
255 |
int tty_register_ldisc(int disc, struct tty_ldisc *new_ldisc) |
| 228 |
{ |
256 |
{ |
|
|
257 |
unsigned long flags; |
| 258 |
int ret = 0; |
| 259 |
|
| 229 |
if (disc < N_TTY || disc >= NR_LDISCS) |
260 |
if (disc < N_TTY || disc >= NR_LDISCS) |
| 230 |
return -EINVAL; |
261 |
return -EINVAL; |
| 231 |
|
262 |
|
|
|
263 |
spin_lock_irqsave(&tty_ldisc_lock, flags); |
| 232 |
if (new_ldisc) { |
264 |
if (new_ldisc) { |
| 233 |
ldiscs[disc] = *new_ldisc; |
265 |
tty_ldiscs[disc] = *new_ldisc; |
| 234 |
ldiscs[disc].flags |= LDISC_FLAG_DEFINED; |
266 |
tty_ldiscs[disc].num = disc; |
| 235 |
ldiscs[disc].num = disc; |
267 |
tty_ldiscs[disc].flags |= LDISC_FLAG_DEFINED; |
| 236 |
} else |
268 |
tty_ldiscs[disc].refcount = 0; |
| 237 |
memset(&ldiscs[disc], 0, sizeof(struct tty_ldisc)); |
269 |
} else { |
|
|
270 |
if(tty_ldiscs[disc].refcount) |
| 271 |
ret = -EBUSY; |
| 272 |
else |
| 273 |
tty_ldiscs[disc].flags &= ~LDISC_FLAG_DEFINED; |
| 274 |
} |
| 275 |
spin_unlock_irqrestore(&tty_ldisc_lock, flags); |
| 238 |
|
276 |
|
| 239 |
return 0; |
277 |
return ret; |
| 240 |
} |
278 |
} |
| 241 |
|
279 |
|
| 242 |
EXPORT_SYMBOL(tty_register_ldisc); |
280 |
EXPORT_SYMBOL(tty_register_ldisc); |
| 243 |
|
281 |
|
| 244 |
/* Set the discipline of a tty line. */ |
282 |
struct tty_ldisc *tty_ldisc_get(int disc) |
|
|
283 |
{ |
| 284 |
unsigned long flags; |
| 285 |
struct tty_ldisc *ld; |
| 286 |
|
| 287 |
if (disc < N_TTY || disc >= NR_LDISCS) |
| 288 |
return NULL; |
| 289 |
|
| 290 |
spin_lock_irqsave(&tty_ldisc_lock, flags); |
| 291 |
|
| 292 |
ld = &tty_ldiscs[disc]; |
| 293 |
/* Check the entry is defined */ |
| 294 |
if(ld->flags & LDISC_FLAG_DEFINED) |
| 295 |
{ |
| 296 |
/* If the module is being unloaded we can't use it */ |
| 297 |
if (!try_module_get(ld->owner)) |
| 298 |
ld = NULL; |
| 299 |
else /* lock it */ |
| 300 |
ld->refcount++; |
| 301 |
} |
| 302 |
else |
| 303 |
ld = NULL; |
| 304 |
spin_unlock_irqrestore(&tty_ldisc_lock, flags); |
| 305 |
return ld; |
| 306 |
} |
| 307 |
|
| 308 |
EXPORT_SYMBOL_GPL(tty_ldisc_get); |
| 309 |
|
| 310 |
void tty_ldisc_put(int disc) |
| 311 |
{ |
| 312 |
struct tty_ldisc *ld; |
| 313 |
unsigned long flags; |
| 314 |
|
| 315 |
if (disc < N_TTY || disc >= NR_LDISCS) |
| 316 |
BUG(); |
| 317 |
|
| 318 |
spin_lock_irqsave(&tty_ldisc_lock, flags); |
| 319 |
ld = &tty_ldiscs[disc]; |
| 320 |
if(ld->refcount == 0) |
| 321 |
BUG(); |
| 322 |
ld->refcount --; |
| 323 |
module_put(ld->owner); |
| 324 |
spin_unlock_irqrestore(&tty_ldisc_lock, flags); |
| 325 |
} |
| 326 |
|
| 327 |
EXPORT_SYMBOL_GPL(tty_ldisc_put); |
| 328 |
|
| 329 |
void tty_ldisc_assign(struct tty_struct *tty, struct tty_ldisc *ld) |
| 330 |
{ |
| 331 |
tty->ldisc = *ld; |
| 332 |
tty->ldisc.refcount = 0; |
| 333 |
} |
| 334 |
|
| 335 |
/** |
| 336 |
* tty_ldisc_try - internal helper |
| 337 |
* @tty: the tty |
| 338 |
* |
| 339 |
* Make a single attempt to grab and bump the refcount on |
| 340 |
* the tty ldisc. Return 0 on failure or 1 on success. This is |
| 341 |
* used to implement both the waiting and non waiting versions |
| 342 |
* of tty_ldisc_ref |
| 343 |
*/ |
| 344 |
|
| 345 |
static int tty_ldisc_try(struct tty_struct *tty) |
| 346 |
{ |
| 347 |
unsigned long flags; |
| 348 |
struct tty_ldisc *ld; |
| 349 |
int ret = 0; |
| 350 |
|
| 351 |
spin_lock_irqsave(&tty_ldisc_lock, flags); |
| 352 |
ld = &tty->ldisc; |
| 353 |
if(test_bit(TTY_LDISC, &tty->flags)) |
| 354 |
{ |
| 355 |
ld->refcount++; |
| 356 |
ret = 1; |
| 357 |
} |
| 358 |
spin_unlock_irqrestore(&tty_ldisc_lock, flags); |
| 359 |
return ret; |
| 360 |
} |
| 361 |
|
| 362 |
/** |
| 363 |
* tty_ldisc_ref_wait - wait for the tty ldisc |
| 364 |
* @tty: tty device |
| 365 |
* |
| 366 |
* Dereference the line discipline for the terminal and take a |
| 367 |
* reference to it. If the line discipline is in flux then |
| 368 |
* wait patiently until it changes. |
| 369 |
* |
| 370 |
* Note: Must not be called from an IRQ/timer context. The caller |
| 371 |
* must also be careful not to hold other locks that will deadlock |
| 372 |
* against a discipline change, such as an existing ldisc reference |
| 373 |
* (which we check for) |
| 374 |
*/ |
| 375 |
|
| 376 |
struct tty_ldisc *tty_ldisc_ref_wait(struct tty_struct *tty) |
| 377 |
{ |
| 378 |
/* wait_event is a macro */ |
| 379 |
wait_event(tty_ldisc_wait, tty_ldisc_try(tty)); |
| 380 |
if(tty->ldisc.refcount == 0) |
| 381 |
printk(KERN_ERR "tty_ldisc_ref_wait\n"); |
| 382 |
return &tty->ldisc; |
| 383 |
} |
| 384 |
|
| 385 |
EXPORT_SYMBOL_GPL(tty_ldisc_ref_wait); |
| 386 |
|
| 387 |
/** |
| 388 |
* tty_ldisc_ref - get the tty ldisc |
| 389 |
* @tty: tty device |
| 390 |
* |
| 391 |
* Dereference the line discipline for the terminal and take a |
| 392 |
* reference to it. If the line discipline is in flux then |
| 393 |
* return NULL. Can be called from IRQ and timer functions. |
| 394 |
*/ |
| 395 |
|
| 396 |
struct tty_ldisc *tty_ldisc_ref(struct tty_struct *tty) |
| 397 |
{ |
| 398 |
if(tty_ldisc_try(tty)) |
| 399 |
return &tty->ldisc; |
| 400 |
return NULL; |
| 401 |
} |
| 402 |
|
| 403 |
EXPORT_SYMBOL_GPL(tty_ldisc_ref); |
| 404 |
|
| 405 |
/** |
| 406 |
* tty_ldisc_deref - free a tty ldisc reference |
| 407 |
* @ld: reference to free up |
| 408 |
* |
| 409 |
* Undoes the effect of tty_ldisc_ref or tty_ldisc_ref_wait. May |
| 410 |
* be called in IRQ context. |
| 411 |
*/ |
| 412 |
|
| 413 |
void tty_ldisc_deref(struct tty_ldisc *ld) |
| 414 |
{ |
| 415 |
unsigned long flags; |
| 416 |
|
| 417 |
if(ld == NULL) |
| 418 |
BUG(); |
| 419 |
|
| 420 |
spin_lock_irqsave(&tty_ldisc_lock, flags); |
| 421 |
if(ld->refcount == 0) |
| 422 |
printk(KERN_ERR "tty_ldisc_deref: no references.\n"); |
| 423 |
else |
| 424 |
ld->refcount--; |
| 425 |
if(ld->refcount == 0) |
| 426 |
wake_up(&tty_ldisc_wait); |
| 427 |
spin_unlock_irqrestore(&tty_ldisc_lock, flags); |
| 428 |
} |
| 429 |
|
| 430 |
EXPORT_SYMBOL_GPL(tty_ldisc_deref); |
| 431 |
|
| 432 |
/** |
| 433 |
* tty_ldisc_enable - allow ldisc use |
| 434 |
* @tty: terminal to activate ldisc on |
| 435 |
* |
| 436 |
* Set the TTY_LDISC flag when the line discipline can be called |
| 437 |
* again. Do neccessary wakeups for existing sleepers. |
| 438 |
* |
| 439 |
* Note: nobody should set this bit except via this function. Clearing |
| 440 |
* directly is allowed. |
| 441 |
*/ |
| 442 |
|
| 443 |
static void tty_ldisc_enable(struct tty_struct *tty) |
| 444 |
{ |
| 445 |
set_bit(TTY_LDISC, &tty->flags); |
| 446 |
wake_up(&tty_ldisc_wait); |
| 447 |
} |
| 448 |
|
| 449 |
/** |
| 450 |
* tty_set_ldisc - set line discipline |
| 451 |
* @tty: the terminal to set |
| 452 |
* @ldisc: the line discipline |
| 453 |
* |
| 454 |
* Set the discipline of a tty line. Must be called from a process |
| 455 |
* context. |
| 456 |
*/ |
| 457 |
|
| 245 |
static int tty_set_ldisc(struct tty_struct *tty, int ldisc) |
458 |
static int tty_set_ldisc(struct tty_struct *tty, int ldisc) |
| 246 |
{ |
459 |
{ |
| 247 |
int retval = 0; |
460 |
int retval = 0; |
| 248 |
struct tty_ldisc o_ldisc; |
461 |
struct tty_ldisc o_ldisc; |
| 249 |
char buf[64]; |
462 |
char buf[64]; |
|
|
463 |
int work; |
| 464 |
unsigned long flags; |
| 465 |
struct tty_ldisc *ld; |
| 250 |
|
466 |
|
| 251 |
if ((ldisc < N_TTY) || (ldisc >= NR_LDISCS)) |
467 |
if ((ldisc < N_TTY) || (ldisc >= NR_LDISCS)) |
| 252 |
return -EINVAL; |
468 |
return -EINVAL; |
|
|
469 |
|
| 470 |
restart: |
| 471 |
|
| 472 |
if (tty->ldisc.num == ldisc) |
| 473 |
return 0; /* We are already in the desired discipline */ |
| 474 |
|
| 475 |
ld = tty_ldisc_get(ldisc); |
| 253 |
/* Eduardo Blanco <ejbs@cs.cs.com.uy> */ |
476 |
/* Eduardo Blanco <ejbs@cs.cs.com.uy> */ |
| 254 |
/* Cyrus Durgin <cider@speakeasy.org> */ |
477 |
/* Cyrus Durgin <cider@speakeasy.org> */ |
| 255 |
if (!(ldiscs[ldisc].flags & LDISC_FLAG_DEFINED)) { |
478 |
if (ld == NULL) { |
| 256 |
request_module("tty-ldisc-%d", ldisc); |
479 |
request_module("tty-ldisc-%d", ldisc); |
|
|
480 |
ld = tty_ldisc_get(ldisc); |
| 257 |
} |
481 |
} |
| 258 |
if (!(ldiscs[ldisc].flags & LDISC_FLAG_DEFINED)) |
482 |
if (ld == NULL) |
| 259 |
return -EINVAL; |
483 |
return -EINVAL; |
| 260 |
|
484 |
|
| 261 |
if (tty->ldisc.num == ldisc) |
|
|
| 262 |
return 0; /* We are already in the desired discipline */ |
| 263 |
|
| 264 |
if (!try_module_get(ldiscs[ldisc].owner)) |
| 265 |
return -EINVAL; |
| 266 |
|
| 267 |
o_ldisc = tty->ldisc; |
485 |
o_ldisc = tty->ldisc; |
| 268 |
|
486 |
|
| 269 |
tty_wait_until_sent(tty, 0); |
487 |
tty_wait_until_sent(tty, 0); |
|
|
488 |
|
| 489 |
/* |
| 490 |
* Make sure we don't change while someone holds a |
| 491 |
* reference to the line discipline. The TTY_LDISC bit |
| 492 |
* prevents anyone taking a reference once it is clear. |
| 493 |
* We need the lock to avoid racing reference takers. |
| 494 |
*/ |
| 495 |
|
| 496 |
spin_lock_irqsave(&tty_ldisc_lock, flags); |
| 497 |
if(tty->ldisc.refcount) |
| 498 |
{ |
| 499 |
/* Free the new ldisc we grabbed. Must drop the lock |
| 500 |
first. */ |
| 501 |
spin_unlock_irqrestore(&tty_ldisc_lock, flags); |
| 502 |
tty_ldisc_put(ldisc); |
| 503 |
/* |
| 504 |
* There are several reasons we may be busy, including |
| 505 |
* random momentary I/O traffic. We must therefore |
| 506 |
* retry. We could distinguish between blocking ops |
| 507 |
* and retries if we made tty_ldisc_wait() smarter. That |
| 508 |
* is up for discussion. |
| 509 |
*/ |
| 510 |
if(wait_event_interruptible(tty_ldisc_wait, tty->ldisc.refcount == 0) < 0) |
| 511 |
return -ERESTARTSYS; |
| 512 |
goto restart; |
| 513 |
} |
| 514 |
clear_bit(TTY_LDISC, &tty->flags); |
| 515 |
clear_bit(TTY_DONT_FLIP, &tty->flags); |
| 516 |
spin_unlock_irqrestore(&tty_ldisc_lock, flags); |
| 270 |
|
517 |
|
|
|
518 |
/* |
| 519 |
* From this point on we know nobody has an ldisc |
| 520 |
* usage reference, nor can they obtain one until |
| 521 |
* we say so later on. |
| 522 |
*/ |
| 523 |
|
| 524 |
work = cancel_delayed_work(&tty->flip.work); |
| 525 |
/* |
| 526 |
* Wait for ->hangup_work and ->flip.work handlers to terminate |
| 527 |
*/ |
| 528 |
|
| 529 |
flush_scheduled_work(); |
| 271 |
/* Shutdown the current discipline. */ |
530 |
/* Shutdown the current discipline. */ |
| 272 |
if (tty->ldisc.close) |
531 |
if (tty->ldisc.close) |
| 273 |
(tty->ldisc.close)(tty); |
532 |
(tty->ldisc.close)(tty); |
| 274 |
|
533 |
|
| 275 |
/* Now set up the new line discipline. */ |
534 |
/* Now set up the new line discipline. */ |
| 276 |
tty->ldisc = ldiscs[ldisc]; |
535 |
tty_ldisc_assign(tty, ld); |
| 277 |
tty->termios->c_line = ldisc; |
536 |
tty_set_termios_ldisc(tty, ldisc); |
| 278 |
if (tty->ldisc.open) |
537 |
if (tty->ldisc.open) |
| 279 |
retval = (tty->ldisc.open)(tty); |
538 |
retval = (tty->ldisc.open)(tty); |
| 280 |
if (retval < 0) { |
539 |
if (retval < 0) { |
| 281 |
tty->ldisc = o_ldisc; |
540 |
tty_ldisc_put(ldisc); |
| 282 |
tty->termios->c_line = tty->ldisc.num; |
541 |
/* There is an outstanding reference here so this is safe */ |
|
|
542 |
tty_ldisc_assign(tty, tty_ldisc_get(o_ldisc.num)); |
| 543 |
tty_set_termios_ldisc(tty, tty->ldisc.num); |
| 283 |
if (tty->ldisc.open && (tty->ldisc.open(tty) < 0)) { |
544 |
if (tty->ldisc.open && (tty->ldisc.open(tty) < 0)) { |
| 284 |
tty->ldisc = ldiscs[N_TTY]; |
545 |
tty_ldisc_put(o_ldisc.num); |
| 285 |
tty->termios->c_line = N_TTY; |
546 |
/* This driver is always present */ |
|
|
547 |
tty_ldisc_assign(tty, tty_ldisc_get(N_TTY)); |
| 548 |
tty_set_termios_ldisc(tty, N_TTY); |
| 286 |
if (tty->ldisc.open) { |
549 |
if (tty->ldisc.open) { |
| 287 |
int r = tty->ldisc.open(tty); |
550 |
int r = tty->ldisc.open(tty); |
| 288 |
|
551 |
|
|
Lines 292-303
Link Here
|
| 292 |
tty_name(tty, buf), r); |
555 |
tty_name(tty, buf), r); |
| 293 |
} |
556 |
} |
| 294 |
} |
557 |
} |
| 295 |
} else { |
|
|
| 296 |
module_put(o_ldisc.owner); |
| 297 |
} |
558 |
} |
|
|
559 |
/* At this point we hold a reference to the new ldisc and a |
| 560 |
a reference to the old ldisc. If we ended up flipping back |
| 561 |
to the existing ldisc we have two references to it */ |
| 298 |
|
562 |
|
| 299 |
if (tty->ldisc.num != o_ldisc.num && tty->driver->set_ldisc) |
563 |
if (tty->ldisc.num != o_ldisc.num && tty->driver->set_ldisc) |
| 300 |
tty->driver->set_ldisc(tty); |
564 |
tty->driver->set_ldisc(tty); |
|
|
565 |
|
| 566 |
tty_ldisc_put(o_ldisc.num); |
| 567 |
|
| 568 |
/* |
| 569 |
* Allow ldisc referencing to occur as soon as the driver |
| 570 |
* ldisc callback completes. |
| 571 |
*/ |
| 572 |
|
| 573 |
tty_ldisc_enable(tty); |
| 574 |
|
| 575 |
/* Restart it in case no characters kick it off. Safe if |
| 576 |
already running */ |
| 577 |
if(work) |
| 578 |
schedule_delayed_work(&tty->flip.work, 1); |
| 301 |
return retval; |
579 |
return retval; |
| 302 |
} |
580 |
} |
| 303 |
|
581 |
|
|
Lines 413-418
Link Here
|
| 413 |
|
691 |
|
| 414 |
static spinlock_t redirect_lock = SPIN_LOCK_UNLOCKED; |
692 |
static spinlock_t redirect_lock = SPIN_LOCK_UNLOCKED; |
| 415 |
static struct file *redirect; |
693 |
static struct file *redirect; |
|
|
694 |
|
| 695 |
/** |
| 696 |
* tty_wakeup - request more data |
| 697 |
* @tty: terminal |
| 698 |
* |
| 699 |
* Internal and external helper for wakeups of tty. This function |
| 700 |
* informs the line discipline if present that the driver is ready |
| 701 |
* to receive more output data. |
| 702 |
*/ |
| 703 |
|
| 704 |
void tty_wakeup(struct tty_struct *tty) |
| 705 |
{ |
| 706 |
struct tty_ldisc *ld; |
| 707 |
|
| 708 |
if (test_bit(TTY_DO_WRITE_WAKEUP, &tty->flags)) { |
| 709 |
ld = tty_ldisc_ref(tty); |
| 710 |
if(ld) { |
| 711 |
if(ld->write_wakeup) |
| 712 |
ld->write_wakeup(tty); |
| 713 |
tty_ldisc_deref(ld); |
| 714 |
} |
| 715 |
} |
| 716 |
wake_up_interruptible(&tty->write_wait); |
| 717 |
} |
| 718 |
|
| 719 |
EXPORT_SYMBOL_GPL(tty_wakeup); |
| 720 |
|
| 721 |
/** |
| 722 |
* tty_ldisc_flush - flush line discipline queue |
| 723 |
* @tty: tty |
| 724 |
* |
| 725 |
* Flush the line discipline queue (if any) for this tty. If there |
| 726 |
* is no line discipline active this is a no-op. |
| 727 |
*/ |
| 728 |
|
| 729 |
void tty_ldisc_flush(struct tty_struct *tty) |
| 730 |
{ |
| 731 |
struct tty_ldisc *ld = tty_ldisc_ref(tty); |
| 732 |
if(ld) { |
| 733 |
if(ld->flush_buffer) |
| 734 |
ld->flush_buffer(tty); |
| 735 |
tty_ldisc_deref(ld); |
| 736 |
} |
| 737 |
} |
| 738 |
|
| 739 |
EXPORT_SYMBOL_GPL(tty_ldisc_flush); |
| 740 |
|
| 416 |
/* |
741 |
/* |
| 417 |
* This can be called by the "eventd" kernel thread. That is process synchronous, |
742 |
* This can be called by the "eventd" kernel thread. That is process synchronous, |
| 418 |
* but doesn't hold any locks, so we need to make sure we have the appropriate |
743 |
* but doesn't hold any locks, so we need to make sure we have the appropriate |
|
Lines 424-429
Link Here
|
| 424 |
struct file * cons_filp = NULL; |
749 |
struct file * cons_filp = NULL; |
| 425 |
struct file *filp, *f = NULL; |
750 |
struct file *filp, *f = NULL; |
| 426 |
struct task_struct *p; |
751 |
struct task_struct *p; |
|
|
752 |
struct tty_ldisc *ld; |
| 427 |
int closecount = 0, n; |
753 |
int closecount = 0, n; |
| 428 |
|
754 |
|
| 429 |
if (!tty) |
755 |
if (!tty) |
|
Lines 441-446
Link Here
|
| 441 |
|
767 |
|
| 442 |
check_tty_count(tty, "do_tty_hangup"); |
768 |
check_tty_count(tty, "do_tty_hangup"); |
| 443 |
file_list_lock(); |
769 |
file_list_lock(); |
|
|
770 |
/* This breaks for file handles being sent over AF_UNIX sockets ? */ |
| 444 |
list_for_each_entry(filp, &tty->tty_files, f_list) { |
771 |
list_for_each_entry(filp, &tty->tty_files, f_list) { |
| 445 |
if (filp->f_op->write == redirected_tty_write) |
772 |
if (filp->f_op->write == redirected_tty_write) |
| 446 |
cons_filp = filp; |
773 |
cons_filp = filp; |
|
Lines 453-473
Link Here
|
| 453 |
file_list_unlock(); |
780 |
file_list_unlock(); |
| 454 |
|
781 |
|
| 455 |
/* FIXME! What are the locking issues here? This may me overdoing things.. |
782 |
/* FIXME! What are the locking issues here? This may me overdoing things.. |
| 456 |
* this question is especially important now that we've removed the irqlock. */ |
783 |
* this question is especially important now that we've removed the irqlock. */ |
| 457 |
{ |
|
|
| 458 |
unsigned long flags; |
| 459 |
|
784 |
|
| 460 |
local_irq_save(flags); // FIXME: is this safe? |
785 |
ld = tty_ldisc_ref(tty); |
| 461 |
if (tty->ldisc.flush_buffer) |
786 |
if(ld != NULL) /* We may have no line discipline at this point */ |
| 462 |
tty->ldisc.flush_buffer(tty); |
787 |
{ |
|
|
788 |
if (ld->flush_buffer) |
| 789 |
ld->flush_buffer(tty); |
| 463 |
if (tty->driver->flush_buffer) |
790 |
if (tty->driver->flush_buffer) |
| 464 |
tty->driver->flush_buffer(tty); |
791 |
tty->driver->flush_buffer(tty); |
| 465 |
if ((test_bit(TTY_DO_WRITE_WAKEUP, &tty->flags)) && |
792 |
if ((test_bit(TTY_DO_WRITE_WAKEUP, &tty->flags)) && |
| 466 |
tty->ldisc.write_wakeup) |
793 |
ld->write_wakeup) |
| 467 |
(tty->ldisc.write_wakeup)(tty); |
794 |
ld->write_wakeup(tty); |
| 468 |
local_irq_restore(flags); // FIXME: is this safe? |
795 |
if (ld->hangup) |
|
|
796 |
ld->hangup(tty); |
| 469 |
} |
797 |
} |
| 470 |
|
798 |
|
|
|
799 |
/* FIXME: Once we trust the LDISC code better we can wait here for |
| 800 |
ldisc completion and fix the driver call race */ |
| 801 |
|
| 471 |
wake_up_interruptible(&tty->write_wait); |
802 |
wake_up_interruptible(&tty->write_wait); |
| 472 |
wake_up_interruptible(&tty->read_wait); |
803 |
wake_up_interruptible(&tty->read_wait); |
| 473 |
|
804 |
|
|
Lines 476-497
Link Here
|
| 476 |
* N_TTY. |
807 |
* N_TTY. |
| 477 |
*/ |
808 |
*/ |
| 478 |
if (tty->driver->flags & TTY_DRIVER_RESET_TERMIOS) |
809 |
if (tty->driver->flags & TTY_DRIVER_RESET_TERMIOS) |
|
|
810 |
{ |
| 811 |
down(&tty->termios_sem); |
| 479 |
*tty->termios = tty->driver->init_termios; |
812 |
*tty->termios = tty->driver->init_termios; |
| 480 |
if (tty->ldisc.num != ldiscs[N_TTY].num) { |
813 |
up(&tty->termios_sem); |
| 481 |
if (tty->ldisc.close) |
|
|
| 482 |
(tty->ldisc.close)(tty); |
| 483 |
module_put(tty->ldisc.owner); |
| 484 |
|
| 485 |
tty->ldisc = ldiscs[N_TTY]; |
| 486 |
tty->termios->c_line = N_TTY; |
| 487 |
if (tty->ldisc.open) { |
| 488 |
int i = (tty->ldisc.open)(tty); |
| 489 |
if (i < 0) |
| 490 |
printk(KERN_ERR "do_tty_hangup: N_TTY open: " |
| 491 |
"error %d\n", -i); |
| 492 |
} |
| 493 |
} |
814 |
} |
| 494 |
|
815 |
|
|
|
816 |
/* Defer ldisc switch */ |
| 817 |
/* tty_deferred_ldisc_switch(N_TTY); |
| 818 |
|
| 819 |
This should get done automatically when the port closes and |
| 820 |
tty_release is called */ |
| 821 |
|
| 495 |
read_lock(&tasklist_lock); |
822 |
read_lock(&tasklist_lock); |
| 496 |
if (tty->session > 0) { |
823 |
if (tty->session > 0) { |
| 497 |
do_each_task_pid(tty->session, PIDTYPE_SID, p) { |
824 |
do_each_task_pid(tty->session, PIDTYPE_SID, p) { |
|
Lines 523-528
Link Here
|
| 523 |
tty->driver->close(tty, cons_filp); |
850 |
tty->driver->close(tty, cons_filp); |
| 524 |
} else if (tty->driver->hangup) |
851 |
} else if (tty->driver->hangup) |
| 525 |
(tty->driver->hangup)(tty); |
852 |
(tty->driver->hangup)(tty); |
|
|
853 |
|
| 854 |
/* We don't want to have driver/ldisc interactions beyond |
| 855 |
the ones we did here. The driver layer expects no |
| 856 |
calls after ->hangup() from the ldisc side. However we |
| 857 |
can't yet guarantee all that */ |
| 858 |
|
| 859 |
set_bit(TTY_HUPPED, &tty->flags); |
| 860 |
if (ld) { |
| 861 |
tty_ldisc_enable(tty); |
| 862 |
tty_ldisc_deref(ld); |
| 863 |
} |
| 526 |
unlock_kernel(); |
864 |
unlock_kernel(); |
| 527 |
if (f) |
865 |
if (f) |
| 528 |
fput(f); |
866 |
fput(f); |
|
Lines 638-646
Link Here
|
| 638 |
} |
976 |
} |
| 639 |
if (tty->driver->start) |
977 |
if (tty->driver->start) |
| 640 |
(tty->driver->start)(tty); |
978 |
(tty->driver->start)(tty); |
| 641 |
if ((test_bit(TTY_DO_WRITE_WAKEUP, &tty->flags)) && |
979 |
|
| 642 |
tty->ldisc.write_wakeup) |
980 |
/* If we have a running line discipline it may need kicking */ |
| 643 |
(tty->ldisc.write_wakeup)(tty); |
981 |
tty_wakeup(tty); |
| 644 |
wake_up_interruptible(&tty->write_wait); |
982 |
wake_up_interruptible(&tty->write_wait); |
| 645 |
} |
983 |
} |
| 646 |
|
984 |
|
|
Lines 652-657
Link Here
|
| 652 |
int i; |
990 |
int i; |
| 653 |
struct tty_struct * tty; |
991 |
struct tty_struct * tty; |
| 654 |
struct inode *inode; |
992 |
struct inode *inode; |
|
|
993 |
struct tty_ldisc *ld; |
| 655 |
|
994 |
|
| 656 |
tty = (struct tty_struct *)file->private_data; |
995 |
tty = (struct tty_struct *)file->private_data; |
| 657 |
inode = file->f_dentry->d_inode; |
996 |
inode = file->f_dentry->d_inode; |
|
Lines 660-670
Link Here
|
| 660 |
if (!tty || (test_bit(TTY_IO_ERROR, &tty->flags))) |
999 |
if (!tty || (test_bit(TTY_IO_ERROR, &tty->flags))) |
| 661 |
return -EIO; |
1000 |
return -EIO; |
| 662 |
|
1001 |
|
|
|
1002 |
/* We want to wait for the line discipline to sort out in this |
| 1003 |
situation */ |
| 1004 |
ld = tty_ldisc_ref_wait(tty); |
| 663 |
lock_kernel(); |
1005 |
lock_kernel(); |
| 664 |
if (tty->ldisc.read) |
1006 |
if (ld->read) |
| 665 |
i = (tty->ldisc.read)(tty,file,buf,count); |
1007 |
i = (ld->read)(tty,file,buf,count); |
| 666 |
else |
1008 |
else |
| 667 |
i = -EIO; |
1009 |
i = -EIO; |
|
|
1010 |
tty_ldisc_deref(ld); |
| 668 |
unlock_kernel(); |
1011 |
unlock_kernel(); |
| 669 |
if (i > 0) |
1012 |
if (i > 0) |
| 670 |
inode->i_atime = CURRENT_TIME; |
1013 |
inode->i_atime = CURRENT_TIME; |
|
Lines 726-741
Link Here
|
| 726 |
{ |
1069 |
{ |
| 727 |
struct tty_struct * tty; |
1070 |
struct tty_struct * tty; |
| 728 |
struct inode *inode = file->f_dentry->d_inode; |
1071 |
struct inode *inode = file->f_dentry->d_inode; |
| 729 |
|
1072 |
ssize_t ret; |
|
|
1073 |
struct tty_ldisc *ld; |
| 1074 |
|
| 730 |
tty = (struct tty_struct *)file->private_data; |
1075 |
tty = (struct tty_struct *)file->private_data; |
| 731 |
if (tty_paranoia_check(tty, inode, "tty_write")) |
1076 |
if (tty_paranoia_check(tty, inode, "tty_write")) |
| 732 |
return -EIO; |
1077 |
return -EIO; |
| 733 |
if (!tty || !tty->driver->write || (test_bit(TTY_IO_ERROR, &tty->flags))) |
1078 |
if (!tty || !tty->driver->write || (test_bit(TTY_IO_ERROR, &tty->flags))) |
| 734 |
return -EIO; |
1079 |
return -EIO; |
| 735 |
if (!tty->ldisc.write) |
1080 |
|
| 736 |
return -EIO; |
1081 |
ld = tty_ldisc_ref_wait(tty); |
| 737 |
return do_tty_write(tty->ldisc.write, tty, file, |
1082 |
if (!ld->write) |
|
|
1083 |
ret = -EIO; |
| 1084 |
else |
| 1085 |
ret = do_tty_write(ld->write, tty, file, |
| 738 |
(const unsigned char __user *)buf, count); |
1086 |
(const unsigned char __user *)buf, count); |
|
|
1087 |
tty_ldisc_deref(ld); |
| 1088 |
return ret; |
| 739 |
} |
1089 |
} |
| 740 |
|
1090 |
|
| 741 |
ssize_t redirected_tty_write(struct file * file, const char __user * buf, size_t count, |
1091 |
ssize_t redirected_tty_write(struct file * file, const char __user * buf, size_t count, |
|
Lines 932-937
Link Here
|
| 932 |
* If we fail here just call release_mem to clean up. No need |
1282 |
* If we fail here just call release_mem to clean up. No need |
| 933 |
* to decrement the use counts, as release_mem doesn't care. |
1283 |
* to decrement the use counts, as release_mem doesn't care. |
| 934 |
*/ |
1284 |
*/ |
|
|
1285 |
|
| 935 |
if (tty->ldisc.open) { |
1286 |
if (tty->ldisc.open) { |
| 936 |
retval = (tty->ldisc.open)(tty); |
1287 |
retval = (tty->ldisc.open)(tty); |
| 937 |
if (retval) |
1288 |
if (retval) |
|
Lines 944-950
Link Here
|
| 944 |
(tty->ldisc.close)(tty); |
1295 |
(tty->ldisc.close)(tty); |
| 945 |
goto release_mem_out; |
1296 |
goto release_mem_out; |
| 946 |
} |
1297 |
} |
|
|
1298 |
tty_ldisc_enable(o_tty); |
| 947 |
} |
1299 |
} |
|
|
1300 |
tty_ldisc_enable(tty); |
| 948 |
goto success; |
1301 |
goto success; |
| 949 |
|
1302 |
|
| 950 |
/* |
1303 |
/* |
|
Lines 973-978
Link Here
|
| 973 |
tty->count++; |
1326 |
tty->count++; |
| 974 |
tty->driver = driver; /* N.B. why do this every time?? */ |
1327 |
tty->driver = driver; /* N.B. why do this every time?? */ |
| 975 |
|
1328 |
|
|
|
1329 |
/* FIXME */ |
| 1330 |
if(!test_bit(TTY_LDISC, &tty->flags)) |
| 1331 |
printk(KERN_ERR "init_dev but no ldisc\n"); |
| 976 |
success: |
1332 |
success: |
| 977 |
*ret_tty = tty; |
1333 |
*ret_tty = tty; |
| 978 |
|
1334 |
|
|
Lines 1076-1081
Link Here
|
| 1076 |
int devpts_master, devpts; |
1432 |
int devpts_master, devpts; |
| 1077 |
int idx; |
1433 |
int idx; |
| 1078 |
char buf[64]; |
1434 |
char buf[64]; |
|
|
1435 |
unsigned long flags; |
| 1079 |
|
1436 |
|
| 1080 |
tty = (struct tty_struct *)filp->private_data; |
1437 |
tty = (struct tty_struct *)filp->private_data; |
| 1081 |
if (tty_paranoia_check(tty, filp->f_dentry->d_inode, "release_dev")) |
1438 |
if (tty_paranoia_check(tty, filp->f_dentry->d_inode, "release_dev")) |
|
Lines 1152-1158
Link Here
|
| 1152 |
} |
1509 |
} |
| 1153 |
} |
1510 |
} |
| 1154 |
#endif |
1511 |
#endif |
| 1155 |
|
|
|
| 1156 |
if (tty->driver->close) |
1512 |
if (tty->driver->close) |
| 1157 |
tty->driver->close(tty, filp); |
1513 |
tty->driver->close(tty, filp); |
| 1158 |
|
1514 |
|
|
Lines 1276-1311
Link Here
|
| 1276 |
#ifdef TTY_DEBUG_HANGUP |
1632 |
#ifdef TTY_DEBUG_HANGUP |
| 1277 |
printk(KERN_DEBUG "freeing tty structure..."); |
1633 |
printk(KERN_DEBUG "freeing tty structure..."); |
| 1278 |
#endif |
1634 |
#endif |
| 1279 |
|
|
|
| 1280 |
/* |
1635 |
/* |
| 1281 |
* Prevent flush_to_ldisc() from rescheduling the work for later. Then |
1636 |
* Prevent flush_to_ldisc() from rescheduling the work for later. Then |
| 1282 |
* kill any delayed work. |
1637 |
* kill any delayed work. As this is the final close it does not |
|
|
1638 |
* race with the set_ldisc code path. |
| 1283 |
*/ |
1639 |
*/ |
|
|
1640 |
clear_bit(TTY_LDISC, &tty->flags); |
| 1284 |
clear_bit(TTY_DONT_FLIP, &tty->flags); |
1641 |
clear_bit(TTY_DONT_FLIP, &tty->flags); |
| 1285 |
cancel_delayed_work(&tty->flip.work); |
1642 |
cancel_delayed_work(&tty->flip.work); |
| 1286 |
|
1643 |
|
| 1287 |
/* |
1644 |
/* |
| 1288 |
* Wait for ->hangup_work and ->flip.work handlers to terminate |
1645 |
* Wait for ->hangup_work and ->flip.work handlers to terminate |
| 1289 |
*/ |
1646 |
*/ |
|
|
1647 |
|
| 1290 |
flush_scheduled_work(); |
1648 |
flush_scheduled_work(); |
| 1291 |
|
1649 |
|
|
|
1650 |
/* |
| 1651 |
* Wait for any short term users (we know they are just driver |
| 1652 |
* side waiters as the file is closing so user count on the file |
| 1653 |
* side is zero. |
| 1654 |
*/ |
| 1655 |
spin_lock_irqsave(&tty_ldisc_lock, flags); |
| 1656 |
while(tty->ldisc.refcount) |
| 1657 |
{ |
| 1658 |
spin_unlock_irqrestore(&tty_ldisc_lock, flags); |
| 1659 |
wait_event(tty_ldisc_wait, tty->ldisc.refcount == 0); |
| 1660 |
spin_lock_irqsave(&tty_ldisc_lock, flags); |
| 1661 |
} |
| 1662 |
spin_unlock_irqrestore(&tty_ldisc_lock, flags); |
| 1292 |
/* |
1663 |
/* |
| 1293 |
* Shutdown the current line discipline, and reset it to N_TTY. |
1664 |
* Shutdown the current line discipline, and reset it to N_TTY. |
| 1294 |
* N.B. why reset ldisc when we're releasing the memory?? |
1665 |
* N.B. why reset ldisc when we're releasing the memory?? |
|
|
1666 |
* |
| 1667 |
* FIXME: this MUST get fixed for the new reflocking |
| 1295 |
*/ |
1668 |
*/ |
| 1296 |
if (tty->ldisc.close) |
1669 |
if (tty->ldisc.close) |
| 1297 |
(tty->ldisc.close)(tty); |
1670 |
(tty->ldisc.close)(tty); |
| 1298 |
module_put(tty->ldisc.owner); |
1671 |
tty_ldisc_put(tty->ldisc.num); |
| 1299 |
|
1672 |
|
| 1300 |
tty->ldisc = ldiscs[N_TTY]; |
1673 |
/* |
| 1301 |
tty->termios->c_line = N_TTY; |
1674 |
* Switch the line discipline back |
|
|
1675 |
*/ |
| 1676 |
tty_ldisc_assign(tty, tty_ldisc_get(N_TTY)); |
| 1677 |
tty_set_termios_ldisc(tty,N_TTY); |
| 1302 |
if (o_tty) { |
1678 |
if (o_tty) { |
|
|
1679 |
/* FIXME: could o_tty be in setldisc here ? */ |
| 1680 |
clear_bit(TTY_LDISC, &o_tty->flags); |
| 1303 |
if (o_tty->ldisc.close) |
1681 |
if (o_tty->ldisc.close) |
| 1304 |
(o_tty->ldisc.close)(o_tty); |
1682 |
(o_tty->ldisc.close)(o_tty); |
| 1305 |
module_put(o_tty->ldisc.owner); |
1683 |
tty_ldisc_put(o_tty->ldisc.num); |
| 1306 |
o_tty->ldisc = ldiscs[N_TTY]; |
1684 |
tty_ldisc_assign(o_tty, tty_ldisc_get(N_TTY)); |
|
|
1685 |
tty_set_termios_ldisc(o_tty,N_TTY); |
| 1307 |
} |
1686 |
} |
| 1308 |
|
|
|
| 1309 |
/* |
1687 |
/* |
| 1310 |
* The release_mem function takes care of the details of clearing |
1688 |
* The release_mem function takes care of the details of clearing |
| 1311 |
* the slots and preserving the termios structure. |
1689 |
* the slots and preserving the termios structure. |
|
Lines 1345-1350
Link Here
|
| 1345 |
unsigned short saved_flags = filp->f_flags; |
1723 |
unsigned short saved_flags = filp->f_flags; |
| 1346 |
|
1724 |
|
| 1347 |
nonseekable_open(inode, filp); |
1725 |
nonseekable_open(inode, filp); |
|
|
1726 |
|
| 1348 |
retry_open: |
1727 |
retry_open: |
| 1349 |
noctty = filp->f_flags & O_NOCTTY; |
1728 |
noctty = filp->f_flags & O_NOCTTY; |
| 1350 |
index = -1; |
1729 |
index = -1; |
|
Lines 1508-1521
Link Here
|
| 1508 |
static unsigned int tty_poll(struct file * filp, poll_table * wait) |
1887 |
static unsigned int tty_poll(struct file * filp, poll_table * wait) |
| 1509 |
{ |
1888 |
{ |
| 1510 |
struct tty_struct * tty; |
1889 |
struct tty_struct * tty; |
|
|
1890 |
struct tty_ldisc *ld; |
| 1891 |
int ret = 0; |
| 1511 |
|
1892 |
|
| 1512 |
tty = (struct tty_struct *)filp->private_data; |
1893 |
tty = (struct tty_struct *)filp->private_data; |
| 1513 |
if (tty_paranoia_check(tty, filp->f_dentry->d_inode, "tty_poll")) |
1894 |
if (tty_paranoia_check(tty, filp->f_dentry->d_inode, "tty_poll")) |
| 1514 |
return 0; |
1895 |
return 0; |
| 1515 |
|
1896 |
|
| 1516 |
if (tty->ldisc.poll) |
1897 |
ld = tty_ldisc_ref_wait(tty); |
| 1517 |
return (tty->ldisc.poll)(tty, filp, wait); |
1898 |
if (ld->poll) |
| 1518 |
return 0; |
1899 |
ret = (ld->poll)(tty, filp, wait); |
|
|
1900 |
tty_ldisc_deref(ld); |
| 1901 |
return ret; |
| 1519 |
} |
1902 |
} |
| 1520 |
|
1903 |
|
| 1521 |
static int tty_fasync(int fd, struct file * filp, int on) |
1904 |
static int tty_fasync(int fd, struct file * filp, int on) |
|
Lines 1547-1558
Link Here
|
| 1547 |
static int tiocsti(struct tty_struct *tty, char __user *p) |
1930 |
static int tiocsti(struct tty_struct *tty, char __user *p) |
| 1548 |
{ |
1931 |
{ |
| 1549 |
char ch, mbz = 0; |
1932 |
char ch, mbz = 0; |
| 1550 |
|
1933 |
struct tty_ldisc *ld; |
|
|
1934 |
|
| 1551 |
if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN)) |
1935 |
if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN)) |
| 1552 |
return -EPERM; |
1936 |
return -EPERM; |
| 1553 |
if (get_user(ch, p)) |
1937 |
if (get_user(ch, p)) |
| 1554 |
return -EFAULT; |
1938 |
return -EFAULT; |
| 1555 |
tty->ldisc.receive_buf(tty, &ch, &mbz, 1); |
1939 |
ld = tty_ldisc_ref_wait(tty); |
|
|
1940 |
ld->receive_buf(tty, &ch, &mbz, 1); |
| 1941 |
tty_ldisc_deref(ld); |
| 1556 |
return 0; |
1942 |
return 0; |
| 1557 |
} |
1943 |
} |
| 1558 |
|
1944 |
|
|
Lines 1800-1805
Link Here
|
| 1800 |
struct tty_struct *tty, *real_tty; |
2186 |
struct tty_struct *tty, *real_tty; |
| 1801 |
void __user *p = (void __user *)arg; |
2187 |
void __user *p = (void __user *)arg; |
| 1802 |
int retval; |
2188 |
int retval; |
|
|
2189 |
struct tty_ldisc *ld; |
| 1803 |
|
2190 |
|
| 1804 |
tty = (struct tty_struct *)file->private_data; |
2191 |
tty = (struct tty_struct *)file->private_data; |
| 1805 |
if (tty_paranoia_check(tty, inode, "tty_ioctl")) |
2192 |
if (tty_paranoia_check(tty, inode, "tty_ioctl")) |
|
Lines 1889-1894
Link Here
|
| 1889 |
case TIOCGSID: |
2276 |
case TIOCGSID: |
| 1890 |
return tiocgsid(tty, real_tty, p); |
2277 |
return tiocgsid(tty, real_tty, p); |
| 1891 |
case TIOCGETD: |
2278 |
case TIOCGETD: |
|
|
2279 |
/* FIXME: check this is ok */ |
| 1892 |
return put_user(tty->ldisc.num, (int __user *)p); |
2280 |
return put_user(tty->ldisc.num, (int __user *)p); |
| 1893 |
case TIOCSETD: |
2281 |
case TIOCSETD: |
| 1894 |
return tiocsetd(tty, p); |
2282 |
return tiocsetd(tty, p); |
|
Lines 1925-1957
Link Here
|
| 1925 |
case TIOCMBIC: |
2313 |
case TIOCMBIC: |
| 1926 |
case TIOCMBIS: |
2314 |
case TIOCMBIS: |
| 1927 |
return tty_tiocmset(tty, file, cmd, p); |
2315 |
return tty_tiocmset(tty, file, cmd, p); |
| 1928 |
/* |
|
|
| 1929 |
* Without the real device to which /dev/console is connected, |
| 1930 |
* blogd can not work. |
| 1931 |
* blogd spawns a pty/tty pair, |
| 1932 |
* set /dev/console to the tty of that pair (ioctl TIOCCONS), |
| 1933 |
* then reads in all input from the current /dev/console, |
| 1934 |
* buffer or write the readed data to /var/log/boot.msg |
| 1935 |
* _and_ to the original real device. |
| 1936 |
*/ |
| 1937 |
case TIOCGDEV: |
| 1938 |
{ |
| 1939 |
unsigned int ret = new_encode_dev(tty_devnum(real_tty)); |
| 1940 |
return put_user(ret, (unsigned int __user *)p); |
| 1941 |
} |
| 1942 |
|
| 1943 |
} |
2316 |
} |
| 1944 |
if (tty->driver->ioctl) { |
2317 |
if (tty->driver->ioctl) { |
| 1945 |
int retval = (tty->driver->ioctl)(tty, file, cmd, arg); |
2318 |
retval = (tty->driver->ioctl)(tty, file, cmd, arg); |
| 1946 |
if (retval != -ENOIOCTLCMD) |
2319 |
if (retval != -ENOIOCTLCMD) |
| 1947 |
return retval; |
2320 |
return retval; |
| 1948 |
} |
2321 |
} |
| 1949 |
if (tty->ldisc.ioctl) { |
2322 |
ld = tty_ldisc_ref_wait(tty); |
| 1950 |
int retval = (tty->ldisc.ioctl)(tty, file, cmd, arg); |
2323 |
retval = -EINVAL; |
| 1951 |
if (retval != -ENOIOCTLCMD) |
2324 |
if (ld->ioctl) { |
| 1952 |
return retval; |
2325 |
retval = ld->ioctl(tty, file, cmd, arg); |
|
|
2326 |
if (retval == -ENOIOCTLCMD) |
| 2327 |
retval = -EINVAL; |
| 1953 |
} |
2328 |
} |
| 1954 |
return -EINVAL; |
2329 |
tty_ldisc_deref(ld); |
|
|
2330 |
return retval; |
| 1955 |
} |
2331 |
} |
| 1956 |
|
2332 |
|
| 1957 |
|
2333 |
|
|
Lines 1984-1997
Link Here
|
| 1984 |
int session; |
2360 |
int session; |
| 1985 |
int i; |
2361 |
int i; |
| 1986 |
struct file *filp; |
2362 |
struct file *filp; |
|
|
2363 |
struct tty_ldisc *disc; |
| 1987 |
|
2364 |
|
| 1988 |
if (!tty) |
2365 |
if (!tty) |
| 1989 |
return; |
2366 |
return; |
| 1990 |
session = tty->session; |
2367 |
session = tty->session; |
| 1991 |
if (tty->ldisc.flush_buffer) |
2368 |
|
| 1992 |
tty->ldisc.flush_buffer(tty); |
2369 |
/* We don't want an ldisc switch during this */ |
|
|
2370 |
disc = tty_ldisc_ref(tty); |
| 2371 |
if (disc && disc->flush_buffer) |
| 2372 |
disc->flush_buffer(tty); |
| 2373 |
tty_ldisc_deref(disc); |
| 2374 |
|
| 1993 |
if (tty->driver->flush_buffer) |
2375 |
if (tty->driver->flush_buffer) |
| 1994 |
tty->driver->flush_buffer(tty); |
2376 |
tty->driver->flush_buffer(tty); |
|
|
2377 |
|
| 1995 |
read_lock(&tasklist_lock); |
2378 |
read_lock(&tasklist_lock); |
| 1996 |
do_each_task_pid(session, PIDTYPE_SID, p) { |
2379 |
do_each_task_pid(session, PIDTYPE_SID, p) { |
| 1997 |
if (p->signal->tty == tty || session > 0) { |
2380 |
if (p->signal->tty == tty || session > 0) { |
|
Lines 2043-2066
Link Here
|
| 2043 |
|
2426 |
|
| 2044 |
/* |
2427 |
/* |
| 2045 |
* This routine is called out of the software interrupt to flush data |
2428 |
* This routine is called out of the software interrupt to flush data |
| 2046 |
* from the flip buffer to the line discipline. |
2429 |
* from the flip buffer to the line discipline. |
| 2047 |
*/ |
2430 |
*/ |
|
|
2431 |
|
| 2048 |
static void flush_to_ldisc(void *private_) |
2432 |
static void flush_to_ldisc(void *private_) |
| 2049 |
{ |
2433 |
{ |
| 2050 |
struct tty_struct *tty = (struct tty_struct *) private_; |
2434 |
struct tty_struct *tty = (struct tty_struct *) private_; |
| 2051 |
unsigned char *cp; |
2435 |
unsigned char *cp; |
| 2052 |
char *fp; |
2436 |
char *fp; |
| 2053 |
int count; |
2437 |
int count; |
| 2054 |
unsigned long flags; |
2438 |
unsigned long flags; |
|
|
2439 |
struct tty_ldisc *disc; |
| 2440 |
|
| 2441 |
disc = tty_ldisc_ref(tty); |
| 2442 |
if (disc == NULL) /* !TTY_LDISC */ |
| 2443 |
return; |
| 2055 |
|
2444 |
|
| 2056 |
if (test_bit(TTY_DONT_FLIP, &tty->flags)) { |
2445 |
if (test_bit(TTY_DONT_FLIP, &tty->flags)) { |
| 2057 |
/* |
2446 |
/* |
| 2058 |
* Do it after the next timer tick: |
2447 |
* Do it after the next timer tick: |
| 2059 |
*/ |
2448 |
*/ |
| 2060 |
schedule_delayed_work(&tty->flip.work, 1); |
2449 |
schedule_delayed_work(&tty->flip.work, 1); |
| 2061 |
return; |
2450 |
goto out; |
| 2062 |
} |
2451 |
} |
| 2063 |
|
|
|
| 2064 |
spin_lock_irqsave(&tty->read_lock, flags); |
2452 |
spin_lock_irqsave(&tty->read_lock, flags); |
| 2065 |
if (tty->flip.buf_num) { |
2453 |
if (tty->flip.buf_num) { |
| 2066 |
cp = tty->flip.char_buf + TTY_FLIPBUF_SIZE; |
2454 |
cp = tty->flip.char_buf + TTY_FLIPBUF_SIZE; |
|
Lines 2079-2085
Link Here
|
| 2079 |
tty->flip.count = 0; |
2467 |
tty->flip.count = 0; |
| 2080 |
spin_unlock_irqrestore(&tty->read_lock, flags); |
2468 |
spin_unlock_irqrestore(&tty->read_lock, flags); |
| 2081 |
|
2469 |
|
| 2082 |
tty->ldisc.receive_buf(tty, cp, fp, count); |
2470 |
disc->receive_buf(tty, cp, fp, count); |
|
|
2471 |
out: |
| 2472 |
tty_ldisc_deref(disc); |
| 2473 |
} |
| 2474 |
|
| 2475 |
/* |
| 2476 |
* Call the ldisc flush directly from a driver. This function may |
| 2477 |
* return an error and need retrying by the user. |
| 2478 |
*/ |
| 2479 |
|
| 2480 |
int tty_push_data(struct tty_struct *tty, unsigned char *cp, unsigned char *fp, int count) |
| 2481 |
{ |
| 2482 |
int ret = 0; |
| 2483 |
struct tty_ldisc *disc; |
| 2484 |
|
| 2485 |
disc = tty_ldisc_ref(tty); |
| 2486 |
if(test_bit(TTY_DONT_FLIP, &tty->flags)) |
| 2487 |
ret = -EAGAIN; |
| 2488 |
else if(disc == NULL) |
| 2489 |
ret = -EIO; |
| 2490 |
else |
| 2491 |
disc->receive_buf(tty, cp, fp, count); |
| 2492 |
tty_ldisc_deref(disc); |
| 2493 |
return ret; |
| 2494 |
|
| 2083 |
} |
2495 |
} |
| 2084 |
|
2496 |
|
| 2085 |
/* |
2497 |
/* |
|
Lines 2101-2109
Link Here
|
| 2101 |
|
2513 |
|
| 2102 |
static int n_baud_table = ARRAY_SIZE(baud_table); |
2514 |
static int n_baud_table = ARRAY_SIZE(baud_table); |
| 2103 |
|
2515 |
|
|
|
2516 |
/** |
| 2517 |
* tty_termios_baud_rate |
| 2518 |
* @termios: termios structure |
| 2519 |
* |
| 2520 |
* Convert termios baud rate data into a speed. This should be called |
| 2521 |
* with the termios lock held if this termios is a terminal termios |
| 2522 |
* structure. May change the termios data. |
| 2523 |
*/ |
| 2524 |
|
| 2104 |
int tty_termios_baud_rate(struct termios *termios) |
2525 |
int tty_termios_baud_rate(struct termios *termios) |
| 2105 |
{ |
2526 |
{ |
| 2106 |
unsigned int cbaud = termios->c_cflag & CBAUD; |
2527 |
unsigned int cbaud; |
|
|
2528 |
|
| 2529 |
cbaud = termios->c_cflag & CBAUD; |
| 2107 |
|
2530 |
|
| 2108 |
if (cbaud & CBAUDEX) { |
2531 |
if (cbaud & CBAUDEX) { |
| 2109 |
cbaud &= ~CBAUDEX; |
2532 |
cbaud &= ~CBAUDEX; |
|
Lines 2113-2124
Link Here
|
| 2113 |
else |
2536 |
else |
| 2114 |
cbaud += 15; |
2537 |
cbaud += 15; |
| 2115 |
} |
2538 |
} |
| 2116 |
|
|
|
| 2117 |
return baud_table[cbaud]; |
2539 |
return baud_table[cbaud]; |
| 2118 |
} |
2540 |
} |
| 2119 |
|
2541 |
|
| 2120 |
EXPORT_SYMBOL(tty_termios_baud_rate); |
2542 |
EXPORT_SYMBOL(tty_termios_baud_rate); |
| 2121 |
|
2543 |
|
|
|
2544 |
/** |
| 2545 |
* tty_get_baud_rate - get tty bit rates |
| 2546 |
* @tty: tty to query |
| 2547 |
* |
| 2548 |
* Returns the baud rate as an integer for this terminal. The |
| 2549 |
* termios lock must be held by the caller and the terminal bit |
| 2550 |
* flags may be updated. |
| 2551 |
*/ |
| 2552 |
|
| 2122 |
int tty_get_baud_rate(struct tty_struct *tty) |
2553 |
int tty_get_baud_rate(struct tty_struct *tty) |
| 2123 |
{ |
2554 |
{ |
| 2124 |
int baud = tty_termios_baud_rate(tty->termios); |
2555 |
int baud = tty_termios_baud_rate(tty->termios); |
|
Lines 2137-2142
Link Here
|
| 2137 |
|
2568 |
|
| 2138 |
EXPORT_SYMBOL(tty_get_baud_rate); |
2569 |
EXPORT_SYMBOL(tty_get_baud_rate); |
| 2139 |
|
2570 |
|
|
|
2571 |
/** |
| 2572 |
* tty_flip_buffer_push - terminal |
| 2573 |
* @tty: tty to push |
| 2574 |
* |
| 2575 |
* Queue a push of the terminal flip buffers to the line discipline. This |
| 2576 |
* function must not be called from IRQ context if tty->low_latency is set. |
| 2577 |
* |
| 2578 |
* In the event of the queue being busy for flipping the work will be |
| 2579 |
* held off and retried later. |
| 2580 |
*/ |
| 2581 |
|
| 2140 |
void tty_flip_buffer_push(struct tty_struct *tty) |
2582 |
void tty_flip_buffer_push(struct tty_struct *tty) |
| 2141 |
{ |
2583 |
{ |
| 2142 |
if (tty->low_latency) |
2584 |
if (tty->low_latency) |
|
Lines 2154-2165
Link Here
|
| 2154 |
{ |
2596 |
{ |
| 2155 |
memset(tty, 0, sizeof(struct tty_struct)); |
2597 |
memset(tty, 0, sizeof(struct tty_struct)); |
| 2156 |
tty->magic = TTY_MAGIC; |
2598 |
tty->magic = TTY_MAGIC; |
| 2157 |
tty->ldisc = ldiscs[N_TTY]; |
2599 |
tty_ldisc_assign(tty, tty_ldisc_get(N_TTY)); |
| 2158 |
tty->pgrp = -1; |
2600 |
tty->pgrp = -1; |
| 2159 |
tty->flip.char_buf_ptr = tty->flip.char_buf; |
2601 |
tty->flip.char_buf_ptr = tty->flip.char_buf; |
| 2160 |
tty->flip.flag_buf_ptr = tty->flip.flag_buf; |
2602 |
tty->flip.flag_buf_ptr = tty->flip.flag_buf; |
| 2161 |
INIT_WORK(&tty->flip.work, flush_to_ldisc, tty); |
2603 |
INIT_WORK(&tty->flip.work, flush_to_ldisc, tty); |
| 2162 |
init_MUTEX(&tty->flip.pty_sem); |
2604 |
init_MUTEX(&tty->flip.pty_sem); |
|
|
2605 |
init_MUTEX(&tty->termios_sem); |
| 2163 |
init_waitqueue_head(&tty->write_wait); |
2606 |
init_waitqueue_head(&tty->write_wait); |
| 2164 |
init_waitqueue_head(&tty->read_wait); |
2607 |
init_waitqueue_head(&tty->read_wait); |
| 2165 |
INIT_WORK(&tty->hangup_work, do_tty_hangup, tty); |
2608 |
INIT_WORK(&tty->hangup_work, do_tty_hangup, tty); |