[PATCH] Add -t noproc,tmpfs options to mount/umount

Roy Marples uberlord at gentoo.org
Wed Apr 4 11:47:49 PDT 2007


On Wed, 04 Apr 2007 19:56:40 +0200
Natanael Copa <natanael.copa at gmail.com> wrote:
> > +static int match_fstype (struct mntent *mt, const char *fstype)
> > +{
> > +       bool no = false;
> > +       char *fst, *p, *token;
> > +       int retval = 0;
> > +
> > +       if (!mt || ! fstype)
> > +               return -1;
> > +
> > +       fst = p = xstrdup (fstype);
> > +       if (strlen (p) > 2 && p[0] == 'n' && p[1] == 'o') {
> > +               no = true;
> > +               p += 2;
> > +       }
> 
> Shouldn't the test for 'no...' be done on the token inside the look
> below? mount -t nonfs,noshm,ext3,no...

Not really. GNU mount allows nonofs,noshm, whereas BSD mount only
accepts nonfs,shm. I prefer the BSD approach because you can then
have a fs name starting with "no" like so

mount -at ,noddy

Also, commenting on my own code
strlen (p) > 2 && p[0] == 'n' && p[1] == 'o'
could also be written as
strncmp (p, "no", 2)
which may be more readable.


> 
> > +
> > +       while ((token = strsep (&p, ","))) {
> > +               if (strcmp (token, mt->mnt_type) == 0) {
> > +                       if (! no)
> > +                               retval = 0;
> > +                       break;
> > +               }
> > +       }
> 
> Will this really work? seems like only time the func returns anything
> else but 0 is when either mt or fstype is NULL.

Yes, it works.
Basically we tokenize the fstype list by ,
If a token matches the fstype then
   If list prefixed with no, return -1 otherwise 0.
If no match found return -1.


I also for forgot to mention that the patch also matches the sw option
to denote swap as well as swap.

Thanks



More information about the busybox mailing list