int tty_insert_flip_string_flags(struct tty_struct *tty, const unsigned char *chars, const char *flags, size_t size) { struct tty_bufhead *buf = &tty->port->buf; int copied = 0; do { int goal = min_t(size_t, size - copied, TTY_BUFFER_PAGE); int space; unsigned long __flags; struct tty_buffer *tb; spin_lock_irqsave(&buf->lock, __flags); space = __tty_buffer_request_room(tty->port, goal); tb = buf->tail; /* If there is no space then tb may be NULL */ if (unlikely(space == 0)) { spin_unlock_irqrestore(&buf->lock, __flags); break; } memcpy(tb->char_buf_ptr + tb->used, chars, space); memcpy(tb->flag_buf_ptr + tb->used, flags, space); tb->used += space; spin_unlock_irqrestore(&buf->lock, __flags); copied += space; chars += space; flags += space; /* There is a small chance that we need to split the data over several buffers. If this is the case we must loop */ } while (unlikely(size > copied)); return copied; }
/** * tty_buffer_request_room - grow tty buffer if needed * @tty: tty structure * @size: size desired * * Make at least size bytes of linear space available for the tty * buffer. If we fail return the size we managed to find. * * Locking: Takes tty->buf.lock */ int tty_buffer_request_room(struct tty_struct *tty, size_t size) { unsigned long flags; int length; spin_lock_irqsave(&tty->buf.lock, flags); length = __tty_buffer_request_room(tty, size); spin_unlock_irqrestore(&tty->buf.lock, flags); return length; }
int tty_prepare_flip_string_flags(struct tty_struct *tty, unsigned char **chars, char **flags, size_t size) { int space; unsigned long __flags; struct tty_buffer *tb; spin_lock_irqsave(&tty->buf.lock, __flags); space = __tty_buffer_request_room(tty, size); tb = tty->buf.tail; if (likely(space)) { *chars = tb->char_buf_ptr + tb->used; *flags = tb->flag_buf_ptr + tb->used; tb->used += space; } spin_unlock_irqrestore(&tty->buf.lock, __flags); return space; }
int tty_prepare_flip_string(struct tty_struct *tty, unsigned char **chars, size_t size) { struct tty_bufhead *buf = &tty->port->buf; int space; unsigned long flags; struct tty_buffer *tb; spin_lock_irqsave(&buf->lock, flags); space = __tty_buffer_request_room(tty->port, size); tb = buf->tail; if (likely(space)) { *chars = tb->char_buf_ptr + tb->used; memset(tb->flag_buf_ptr + tb->used, TTY_NORMAL, space); tb->used += space; } spin_unlock_irqrestore(&buf->lock, flags); return space; }