mount add
This commit is contained in:
parent
67c41c4c93
commit
d4689a0b73
|
@ -6,8 +6,8 @@ const char *objects[] = {
|
|||
"coreutils",
|
||||
"networking",
|
||||
"procps",
|
||||
"sysutils",
|
||||
"findutils",
|
||||
"sysutils",
|
||||
"sysutils-linux",
|
||||
"miscutils",
|
||||
"shell"
|
||||
|
@ -19,6 +19,6 @@ const char *objects[] = {
|
|||
/* Need by spark */
|
||||
#define LDFLAGS "-lm"
|
||||
|
||||
#define CFLAGS "-Wall", "-Werror", "-Wextra", "-pedantic", "-flto", "-Os", "-s", "-I../libmu", "-I../", "--std", "c99", LDFLAGS
|
||||
#define CFLAGS "-Wall", "-Werror", "-Wextra", "-pedantic", "-flto", "-Os", "-s", "-I../libmu", "-I../", LDFLAGS
|
||||
#define CC "cc"
|
||||
#endif
|
||||
|
|
1
config.h
1
config.h
|
@ -15,6 +15,7 @@
|
|||
|
||||
/* mount config */
|
||||
#define MOUNT_CFG "/etc/fstab"
|
||||
#define MOUNT_DEF_FS "ext4"
|
||||
|
||||
/* nologin sleep */
|
||||
#define NOLOGIN_SLEEP 60
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <utmpx.h>
|
||||
#include <time.h>
|
||||
|
||||
int time_to_str(char *buf, size_t len, struct utmpx *usr) {
|
||||
time_t t = usr->ut_tv.tv_sec;
|
||||
struct tm *tmp = localtime(&t);
|
||||
|
||||
if (tmp)
|
||||
strftime(buf, len, "%F %H:%M", tmp);
|
||||
|
||||
else
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
setutxent();
|
||||
|
||||
struct utmpx *usr;
|
||||
while ((usr = getutxent())) {
|
||||
if (usr->ut_type == USER_PROCESS) {
|
||||
char time_buf[20];
|
||||
if (time_to_str(time_buf, sizeof(time_buf), usr))
|
||||
continue;
|
||||
|
||||
printf("%s\t%s\t%s\t(%s)\n", usr->ut_user, usr->ut_line, time_buf, usr->ut_host);
|
||||
}
|
||||
}
|
||||
|
||||
endutxent();
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
#[SRC] [DST] [FS TYPE] [OPTIONS]
|
||||
/dev/sda1 /boot ext4 rw
|
|
@ -27,10 +27,8 @@ SIG signals[] = {
|
|||
{"PIPE", SIGPIPE},
|
||||
{"ALRM", SIGALRM},
|
||||
{"TERM", SIGTERM},
|
||||
{"STKFLT", SIGSTKFLT},
|
||||
{"CHLD", SIGCHLD},
|
||||
{"STOP", SIGSTOP},
|
||||
{"POLL", SIGPOLL}
|
||||
{"STOP", SIGSTOP}
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/mount.h>
|
||||
#include <mntent.h>
|
||||
#include "config.h"
|
||||
|
||||
int do_mount(const char *src, const char *dst, const char *fs_type, unsigned long opt) {
|
||||
#if defined(__linux__)
|
||||
int ret = mount(src, dst, fs_type, opt, NULL);
|
||||
|
||||
#elif defined(__plainos__)
|
||||
int ret = mount(src, dst, fs_type, opt);
|
||||
|
||||
#else
|
||||
int ret = -1;
|
||||
|
||||
#endif
|
||||
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "mount: %s: %s\n", src, strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void parse_fstab(void) {
|
||||
FILE *fp = fopen(MOUNT_CFG, "r");
|
||||
if (fp == NULL) {
|
||||
fprintf(stderr, "mount: %s\n", strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
char *buf = NULL;
|
||||
size_t len = 0;
|
||||
|
||||
while (getline(&buf, &len, fp) != EOF) {
|
||||
if (buf[0] == '#')
|
||||
continue;
|
||||
}
|
||||
|
||||
free(buf);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
char *fs_type = MOUNT_DEF_FS;
|
||||
|
||||
int opt;
|
||||
while ((opt = getopt(argc, argv, "t:ao")) != -1) {
|
||||
switch (opt) {
|
||||
case 'a':
|
||||
parse_fstab();
|
||||
break;
|
||||
|
||||
case 't':
|
||||
fs_type = optarg;
|
||||
break;
|
||||
|
||||
case 'o':
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("mount [DEVICE] [NODE]\n\t[-t Fs type (default %s)] [-o Options]\n\t[-a Mount all fs in /etc/fstab]\n\nOptions:\n\tremount - Remount a mounted filesystem\n\tro - Read only\n", MOUNT_DEF_FS);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if (argc == 2)
|
||||
return do_mount(argv[0], argv[1], fs_type, 0);
|
||||
|
||||
else if (argc == 1)
|
||||
return do_mount(fs_type, argv[0], fs_type, 0);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue