mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-31 22:48:21 +00:00
mount syscall and simple mount program
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
#include <sys/mount.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
void usage(char *name) {
|
||||
fprintf(stderr, "%s: usage: %s [-d device] mountpoint filesystem\n", name, name);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
char *dev = NULL;
|
||||
char *mountp = NULL;
|
||||
char *fs = NULL;
|
||||
bool devnext = false;
|
||||
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
if (strcmp(argv[i], "-d") == 0) {
|
||||
devnext = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (devnext) {
|
||||
devnext = false;
|
||||
dev = argv[i];
|
||||
} else if (mountp == NULL)
|
||||
mountp = argv[i];
|
||||
else if (fs == NULL)
|
||||
fs = argv[i];
|
||||
else
|
||||
usage(argv[0]);
|
||||
}
|
||||
|
||||
if (mount == NULL || fs == NULL)
|
||||
usage(argv[0]);
|
||||
|
||||
if (mount(dev, mountp, fs, 0, NULL) == -1) {
|
||||
perror("mount failed");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Reference in New Issue
Block a user