Hello Ahmed, To round up to whole pages, add one page when the division leaves a remainder. For a nonnegative size and a positive page_size, I’d use size / page_size + (size % page_size != 0).
With 4096-byte pages, both 4096 and 4097 bytes give a quotient of 1, so ((size / page_size) != 0) is true in both cases. Only 4097 bytes needs a second page. Best regards, Alperen Erkan On Tue, Nov 24, 2026 at 9:43 PM Ahmed Khider <[email protected]> wrote: > Hello > > I modified the patch. > > The values->(mode_t) -1 pass normally with -Wall -Wextra > > It requires this warning : > > -Wsign-conversion > > > the if statement > > if (size == 0) > { > argp_error (state, "argument must be bigger than zero"); > return EINVAL; > } > > is for : > tmpfs_page_limit = (values->size + vm_page_size - 1) / vm_page_size; > > If the size is 0, it will give it unlimited memory > > > > On Tue, Nov 24, 2026 at 8:43 PM Diego Nieto Cid <[email protected]> wrote: > >> Hi, >> >> Can you add some description to the commit message regarding >> what the mode_t casting tries to achieve? For those of us >> who have no idea of what the code should be doing with the >> values->mode field :P >> >> Does it silence a warning? Which one? Under what architecture? >> >> My attempt at compiling tmpfs doesn't trigger anything unusual >> in connection to the field. >> >> >> On Tue, Nov 24, 2026 at 10:59:02PM +0300, Ahmed Khider wrote: >> > --- >> > tmpfs/tmpfs.c | 20 ++++++++++++++------ >> > 1 file changed, 14 insertions(+), 6 deletions(-) >> > >> > diff --git a/tmpfs/tmpfs.c b/tmpfs/tmpfs.c >> > index ad5e298..fa4c37a 100644 >> > --- a/tmpfs/tmpfs.c >> > +++ b/tmpfs/tmpfs.c >> > @@ -55,6 +55,7 @@ struct node *diskfs_root_node; >> > mach_port_t default_pager; >> > >> > off_t tmpfs_page_limit, tmpfs_space_used; >> > +off_t tmpfs_size_limit = UINT_MAX; >> >> There doesn't seem to be any other assignment to this >> variable and only one usage. I can't see its purpose. >> >> > mode_t tmpfs_root_mode = -1; >> > >> > error_t >> > @@ -125,6 +126,11 @@ parse_opt_size (const char *arg, struct argp_state >> *state, off_t *newsize) >> > argp_error (state, "argument must be a number"); >> > return EINVAL; >> > } >> > + if (size == 0) >> > + { >> > + argp_error (state, "argument must be bigger than zero"); >> > + return EINVAL; >> > + } >> > if (size < 0) >> > { >> > argp_error (state, "negative size not meaningful"); >> > @@ -163,12 +169,13 @@ parse_opt_size (const char *arg, struct >> argp_state *state, off_t *newsize) >> > } >> > } >> > size = (off_t) size; >> > - if (size < 0) >> > + if (size > tmpfs_size_limit ) >> >> This looks correct as it was. If operations over the parsed size >> overflow, this signed `size` would, when casted, become negative. >> Which is what the if was checking. >> >> Am I right? >> >> > { >> > argp_error (state, "size too large"); >> > return EINVAL; >> > } >> > >> > + >> >> Spuriuos change. >> >> > *newsize = size; >> > >> > return 0; >> > @@ -191,7 +198,7 @@ parse_opt (int key, char *arg, struct argp_state >> *state) >> > return ENOMEM; >> > state->hook = values; >> > values->size = -1; >> > - values->mode = -1; >> > + values->mode = (mode_t) -1; >> > break; >> > case ARGP_KEY_FINI: >> > free (values); >> > @@ -200,9 +207,10 @@ parse_opt (int key, char *arg, struct argp_state >> *state) >> > >> > case 'm': /* --mode=OCTAL */ >> > { >> > + errno = 0; >> > char *end = NULL; >> > mode_t mode = strtoul (arg, &end, 8); >> > - if (end == NULL || end == arg) >> > + if (errno = 0 || *end != '\0' || end == arg) >> >> This should read `errno != 0`. >> >> > { >> > argp_error (state, "argument must be an octal number"); >> > return EINVAL; >> > @@ -257,7 +265,7 @@ parse_opt (int key, char *arg, struct argp_state >> *state) >> > >> > case ARGP_KEY_SUCCESS: >> > /* All options parse successfully, so implement ours if >> possible. */ >> > - tmpfs_page_limit = values->size / vm_page_size; >> > + tmpfs_page_limit = (values->size + vm_page_size - 1) / >> vm_page_size; >> > tmpfs_root_mode = values->mode; >> > break; >> > >> > @@ -419,7 +427,7 @@ main (int argc, char **argv) >> > if (err) >> > { >> > error (0, err, "cannot stat underlying node"); >> > - if (tmpfs_root_mode == -1) >> > + if (tmpfs_root_mode == (mode_t) -1) >> > diskfs_root_node->dn_stat.st_mode |= 0777 | S_ISVTX; >> > else >> > diskfs_root_node->dn_stat.st_mode |= tmpfs_root_mode; >> > @@ -429,7 +437,7 @@ main (int argc, char **argv) >> > } >> > else >> > { >> > - if (tmpfs_root_mode == -1) >> > + if (tmpfs_root_mode == (mode_t) -1) >> > { >> > diskfs_root_node->dn_stat.st_mode |= st.st_mode &~ S_IFMT; >> > if (S_ISREG (st.st_mode) && (st.st_mode & 0111) == 0) >> > -- >> > 2.47.3 >> > >> > >> >> Thanks. >> >
