diff options
-rw-r--r-- | util-linux/mount.c | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/util-linux/mount.c b/util-linux/mount.c index 3ac8ce093..0f213bb30 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c | |||
@@ -332,7 +332,7 @@ static void append_mount_options(char **oldopts, const char *newopts) | |||
332 | } | 332 | } |
333 | 333 | ||
334 | // Use the mount_options list to parse options into flags. | 334 | // Use the mount_options list to parse options into flags. |
335 | // Also return list of unrecognized options if unrecognized != NULL | 335 | // Also update list of unrecognized options if unrecognized != NULL |
336 | static long parse_mount_options(char *options, char **unrecognized) | 336 | static long parse_mount_options(char *options, char **unrecognized) |
337 | { | 337 | { |
338 | long flags = MS_SILENT; | 338 | long flags = MS_SILENT; |
@@ -348,25 +348,35 @@ static long parse_mount_options(char *options, char **unrecognized) | |||
348 | // FIXME: use hasmntopt() | 348 | // FIXME: use hasmntopt() |
349 | // Find this option in mount_options | 349 | // Find this option in mount_options |
350 | for (i = 0; i < ARRAY_SIZE(mount_options); i++) { | 350 | for (i = 0; i < ARRAY_SIZE(mount_options); i++) { |
351 | if (!strcasecmp(option_str, options)) { | 351 | if (strcasecmp(option_str, options) == 0) { |
352 | long fl = mount_options[i]; | 352 | long fl = mount_options[i]; |
353 | if (fl < 0) flags &= fl; | 353 | if (fl < 0) |
354 | else flags |= fl; | 354 | flags &= fl; |
355 | break; | 355 | else |
356 | flags |= fl; | ||
357 | goto found; | ||
356 | } | 358 | } |
357 | option_str += strlen(option_str) + 1; | 359 | option_str += strlen(option_str) + 1; |
358 | } | 360 | } |
359 | // If unrecognized not NULL, append unrecognized mount options | 361 | // We did not recognize this option. |
360 | if (unrecognized && i == ARRAY_SIZE(mount_options)) { | 362 | // If "unrecognized" is not NULL, append option there. |
363 | // Note that we should not append *empty* option - | ||
364 | // in this case we want to pass NULL, not "", to "data" | ||
365 | // parameter of mount(2) syscall. | ||
366 | // This is crucial for filesystems that don't accept | ||
367 | // any arbitrary mount options, like cgroup fs: | ||
368 | // "mount -t cgroup none /mnt" | ||
369 | if (options[0] && unrecognized) { | ||
361 | // Add it to strflags, to pass on to kernel | 370 | // Add it to strflags, to pass on to kernel |
362 | i = *unrecognized ? strlen(*unrecognized) : 0; | 371 | char *p = *unrecognized; |
363 | *unrecognized = xrealloc(*unrecognized, i + strlen(options) + 2); | 372 | unsigned len = p ? strlen(p) : 0; |
373 | *unrecognized = p = xrealloc(p, len + strlen(options) + 2); | ||
364 | 374 | ||
365 | // Comma separated if it's not the first one | 375 | // Comma separated if it's not the first one |
366 | if (i) (*unrecognized)[i++] = ','; | 376 | if (len) p[len++] = ','; |
367 | strcpy((*unrecognized)+i, options); | 377 | strcpy(p + len, options); |
368 | } | 378 | } |
369 | 379 | found: | |
370 | if (!comma) | 380 | if (!comma) |
371 | break; | 381 | break; |
372 | // Advance to next option | 382 | // Advance to next option |