Bug 27207 - mount examples don't match the mount function signature
Summary: mount examples don't match the mount function signature
Status: UNCONFIRMED
Alias: None
Product: glibc
Classification: Unclassified
Component: manual (show other bugs)
Version: 2.32
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-01-19 18:07 UTC by John McCabe
Modified: 2021-01-20 13:14 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
Proposed patch to fix it (495 bytes, patch)
2021-01-20 13:14 UTC, John McCabe
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description John McCabe 2021-01-19 18:07:04 UTC
In section 31.3.2, "Mount, Unmount, Remount", the signature of the mount function is declared as:

  int mount (const char *special_file, const char *dir, const char *fstype, unsigned long int options, const void *data)

Later in the documentation, the following examples are provided:

  Example:

    #include <sys/mount.h>

    mount("/dev/hdb", "/cdrom", MS_MGC_VAL | MS_RDONLY | MS_NOSUID, "");

    mount("/dev/hda2", "/mnt", MS_MGC_VAL | MS_REMOUNT, "");

Both of these examples have the options flags as the 3rd parameter, with an empty string as the 4th. As these are MS_REMOUNT examples, it looks like the 4th parameter in the examples is meant to represent the filesystem type, so the 3rd and 4th parameters are the wrong way round.
Comment 1 John McCabe 2021-01-19 18:19:41 UTC
More details:

Contained in sysinfo.texi:

This section:

----
@smallexample
@group
#include <sys/mount.h>

mount("/dev/hdb", "/cdrom", MS_MGC_VAL | MS_RDONLY | MS_NOSUID, "");

mount("/dev/hda2", "/mnt", MS_MGC_VAL | MS_REMOUNT, "");

@end group
@end smallexample
----

Probably needs to change to:

----
@smallexample
@group
#include <sys/mount.h>

mount("/dev/hdb", "/cdrom",  "", MS_MGC_VAL | MS_RDONLY | MS_NOSUID);

mount("/dev/hda2", "/mnt", "", MS_MGC_VAL | MS_REMOUNT);

@end group
@end smallexample
----
Comment 2 Michael Kerrisk 2021-01-20 12:14:03 UTC
I confirm this bug.

However, since mount(2) is not variadic, the change should probably be:

----
@smallexample
@group
#include <sys/mount.h>

mount("/dev/hdb", "/cdrom",  "", MS_MGC_VAL | MS_RDONLY | MS_NOSUID, NULL);

mount("/dev/hda2", "/mnt", "", MS_MGC_VAL | MS_REMOUNT, NULL);

@end group
@end smallexample
----

(That is, add the fifth argument in each call.)
Comment 3 John McCabe 2021-01-20 13:11:48 UTC
Good call; that's correct!
Comment 4 John McCabe 2021-01-20 13:14:29 UTC
Created attachment 13138 [details]
Proposed patch to fix it