Re: [PATCH 13/16] show-pipesize-in-stat.diff

Andrew Morton
2007-04-02T05:58:39Z

On Sun, 1 Apr 2007 20:17:24 +0200 (MEST) Jan Engelhardt <jengelh@linux01.gwdg.de> wrote:

>
> Show the fill status of a pipe (in bytes) when stat'ing one.
>

Is this useful? It seems rather an obscure thing, and we generally need a
good reason to go adding Linux-specific goodies to standard system calls
like this. What do "other operating systems" do here?

> - stat->size = i_size_read(inode);
> + stat->size = 0;
> + if (S_ISFIFO(inode->i_mode)) {
> + const struct pipe_inode_info *info = inode->i_pipe;
> + int i;
> + stat->size = 0;
> + if (info != NULL) {
> + for (i = 0; i < PIPE_BUFFERS; ++i) {
> + const struct pipe_buffer *buf = &info->bufs[i];
> + if (buf != NULL && buf->page != NULL)
> + stat->size += buf->len;
> + }
> + }
> + } else if (S_ISSOCK(inode->i_mode)) {
> +#ifdef CONFIG_UNIX_MODULE
> + loff_t (*uxsize)(struct inode *) = __symbol_get("unixsock_size");
> + if (uxsize != NULL) {
> + stat->size = uxsize(inode);
> + symbol_put("unixsock_size");
> + }
> +#endif
> +#if defined(CONFIG_UNIX) && !defined(CONFIG_UNIX_MODULE)
> + stat->size = unixsock_size(inode);
> +#endif
> + } else {
> + stat->size = i_size_read(inode);
> + }

That's a bit fugly.

> +loff_t unixsock_size(struct inode *inode) {
> + struct sock *sk = unix_find_socket_byinode(inode);
> + loff_t eax;
> +
> + if(sk == NULL) { return 0; }
> + eax = sk->sk_rcvbuf;
> + sock_put(sk);
> + return eax;
> +}
> +EXPORT_SYMBOL(unixsock_size);

That's wildly incorrect coding style, and it doesn't use tabs.