unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer <fw@deneb.enyo.de>
To: Adhemerval Zanella via Libc-alpha <libc-alpha@sourceware.org>
Subject: Re: [PATCH 02/10] linux: Simplify opendir buffer allocation
Date: Tue, 21 Apr 2020 12:28:31 +0200	[thread overview]
Message-ID: <875zdtuo8g.fsf@mid.deneb.enyo.de> (raw)
In-Reply-To: <20200417132209.22065-2-adhemerval.zanella@linaro.org> (Adhemerval Zanella via Libc-alpha's message of "Fri, 17 Apr 2020 10:22:01 -0300")

* Adhemerval Zanella via Libc-alpha:

> THe fallback allocation is removed, so the possible size constraint
> should be analized just once; __alloc_dir assumes that 'statp'
> argument is non-null, and the max_buffer_size move to close its
> used.

Type: analized

> +    return NULL;
> +
> +  /* The st_blksize value of the directory is used as a hint for the
> +     size of the buffer which receives struct dirent values from the
> +     kernel.  st_blksize is limited to max_buffer_size, in case the
> +     file system provides a bogus value.  */
> +  enum { max_buffer_size = 1U << 20 };
> +
> +  const size_t allocation_size = 4 * BUFSIZ;
> +  _Static_assert (allocation_size >= sizeof (struct dirent64),
> +		  "allocation_size < sizeof (struct dirent64)");
> +
>    /* Increase allocation if requested, but not if the value appears to
> +     be bogus.  It will be between 32Kb (for blocksizes smaller than BUFSIZ)
> +     up to 1Mb.  */
> +  size_t allocation = MIN (MAX ((size_t) statp->st_blksize, allocation_size),
> +			   max_buffer_size);
>  
>    DIR *dirp = (DIR *) malloc (sizeof (DIR) + allocation);
>    if (dirp == NULL)
>      {
> +      if (close_fd)
> +	__close_nocancel_nostatus (fd);
> +      return NULL;
>      }
>  
>    dirp->fd = fd;

This looks okay to me.  I wonder if we should just use 32 KiB
uncodintionally, though?

  reply	other threads:[~2020-04-21 10:28 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-17 13:22 [PATCH 01/10] linux: Move posix dir implementations to Linux Adhemerval Zanella via Libc-alpha
2020-04-17 13:22 ` [PATCH 02/10] linux: Simplify opendir buffer allocation Adhemerval Zanella via Libc-alpha
2020-04-21 10:28   ` Florian Weimer [this message]
2020-04-23 21:27     ` Rafal Luzynski via Libc-alpha
2020-04-29 17:09       ` Adhemerval Zanella via Libc-alpha
2020-04-23 21:39     ` Adhemerval Zanella via Libc-alpha
2020-04-24 10:11       ` Florian Weimer
2020-04-24 12:08         ` Adhemerval Zanella via Libc-alpha
2020-04-24 13:08           ` Florian Weimer
2020-04-17 13:22 ` [PATCH 03/10] linux: Add __readdir_unlocked Adhemerval Zanella via Libc-alpha
2020-04-21 10:41   ` Florian Weimer
2020-04-21 12:03     ` Adhemerval Zanella via Libc-alpha
2020-04-21 12:16       ` Florian Weimer
2020-04-21 13:00         ` Adhemerval Zanella via Libc-alpha
2020-05-27 16:38           ` Adhemerval Zanella via Libc-alpha
2020-04-17 13:22 ` [PATCH 04/10] linux: Use internal DIR locks when accessing filepos on telldir Adhemerval Zanella via Libc-alpha
2020-04-21 10:33   ` Florian Weimer
2020-04-17 13:22 ` [PATCH 05/10] linux: Use getdents64 on non-LFS readdir Adhemerval Zanella via Libc-alpha
2020-04-17 13:22 ` [PATCH 06/10] linux: Set internal DIR filepos as off64_t [BZ #23960, BZ #24050] Adhemerval Zanella via Libc-alpha
2020-04-20 15:01   ` Andreas Schwab
2020-04-20 15:02     ` Florian Weimer
2020-04-20 15:06       ` Andreas Schwab
2020-04-21 12:04         ` Adhemerval Zanella via Libc-alpha
2020-04-17 13:22 ` [PATCH 07/10] linux: Add __readdir64_unlocked Adhemerval Zanella via Libc-alpha
2020-04-17 13:22 ` [PATCH 08/10] linux: Add __old_readdir64_unlocked Adhemerval Zanella via Libc-alpha
2020-04-17 13:22 ` [PATCH 09/10] linux: Use getdents64 on readdir64 compat implementation Adhemerval Zanella via Libc-alpha
2020-04-17 13:22 ` [PATCH 10/10] dirent: Deprecate getdirentries Adhemerval Zanella via Libc-alpha
2020-04-22 10:10   ` Florian Weimer
2020-04-20 14:53 ` [PATCH 01/10] linux: Move posix dir implementations to Linux Andreas Schwab
2020-04-21 10:15   ` Florian Weimer
2020-04-21 11:51   ` Adhemerval Zanella via Libc-alpha
2020-05-27 16:35 ` Adhemerval Zanella via Libc-alpha

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/libc/involved.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=875zdtuo8g.fsf@mid.deneb.enyo.de \
    --to=fw@deneb.enyo.de \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).