Hash :
8f629bf6
Author :
Thomas de Grivel
Date :
2025-08-22T00:24:26
mount_ext4fs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
/* ext4fs
* Copyright 2025 kmx.io <contact@kmx.io>
*
* Permission is hereby granted to use this software granted the above
* copyright notice and this permission paragraph are included in all
* copies and substantial portions of this software.
*
* THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
* PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
#include <sys/types.h>
#include <sys/mount.h>
#include <err.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "mntopts.h"
void ext4fs_usage(void);
static const struct mntopt mopts[] = {
MOPT_STDOPTS,
MOPT_UPDATE,
{ NULL }
};
int
main(int argc, char *argv[])
{
struct ufs_args args; /* XXX ffs_args */
int ch, mntflags;
char fs_name[PATH_MAX], *errcause;
mntflags = 0;
optind = optreset = 1; /* Reset for parse of new argv. */
while ((ch = getopt(argc, argv, "o:")) != -1)
switch (ch) {
case 'o':
getmntopts(optarg, mopts, &mntflags);
break;
default:
ext4fs_usage();
}
argc -= optind;
argv += optind;
if (argc != 2)
ext4fs_usage();
args.fspec = argv[0]; /* The name of the device file. */
if (realpath(argv[1], fs_name) == NULL) /* The mount point. */
err(1, "realpath %s", argv[1]);
#define DEFAULT_ROOTUID -2
args.export_info.ex_root = DEFAULT_ROOTUID;
if (mntflags & MNT_RDONLY)
args.export_info.ex_flags = MNT_EXRDONLY;
else
args.export_info.ex_flags = 0;
if (mount(MOUNT_EXT4FS, fs_name, mntflags, &args) == -1) {
switch (errno) {
case EMFILE:
errcause = "mount table full";
break;
case EINVAL:
errcause =
"specified device does not match mounted device";
break;
case EOPNOTSUPP:
errcause = "filesystem not supported by kernel";
break;
default:
errcause = strerror(errno);
break;
}
errx(1, "%s on %s: %s", args.fspec, fs_name, errcause);
}
exit(0);
}
void
ext4fs_usage(void)
{
(void)fprintf(stderr,
"usage: mount_ext4fs [-o options] special node\n");
exit(1);
}