fixed mount, init, parse_mount
This commit is contained in:
parent
af561e98fa
commit
a5080fbb48
3
TODO
3
TODO
|
@ -58,9 +58,6 @@ Findutils:
|
|||
Shell:
|
||||
rc - run command (1 2 3 ~ | <> <<>> & * " parsing) (sig handler)
|
||||
|
||||
Init:
|
||||
sinit - Simple init
|
||||
|
||||
BUGS:
|
||||
ls (unicode strlen, -l flag col)
|
||||
xargs (getopt with glibc)
|
||||
|
|
2
build.sh
2
build.sh
|
@ -12,7 +12,7 @@ if [ -z $CC ]; then
|
|||
fi
|
||||
|
||||
if [ -z $projects ]; then
|
||||
projects="init console-tools coreutils sysutils-linux findutils networking miscutils shell loginutils procps"
|
||||
projects="sysutils-linux init console-tools coreutils findutils networking miscutils shell loginutils procps"
|
||||
fi
|
||||
|
||||
#Compile
|
||||
|
|
1
config.h
1
config.h
|
@ -17,6 +17,7 @@
|
|||
#define MOUNT_CFG "/etc/fstab"
|
||||
#define MOUNT_DEF_FS "ext4"
|
||||
#define MOUNT_LIST "/proc/mounts"
|
||||
#define MOUNT_OPT_SIZE 512
|
||||
|
||||
/* nologin sleep */
|
||||
#define NOLOGIN_SLEEP 60
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#!/bin/sh
|
||||
echo "Mounting.."
|
||||
mount -t proc /proc
|
||||
mount -t sysfs /sys
|
||||
mount -t devtmpfs /dev
|
||||
mount -t tmpfs /tmp
|
||||
mount -o nosuid,noexec,nodev -t proc proc /proc
|
||||
mount -o nosuid,noexec,nodev -t sysfs sysfs /sys
|
||||
mount -o gid=5,mode=0620 -t devtmpfs /dev
|
||||
mount -o nosuid,noexec,nodev,mode=0777 -t tmpfs /tmp
|
||||
|
||||
echo "Starting shell..."
|
||||
sh
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
#!/bin/sh
|
||||
echo "Closing processes..."
|
||||
kill -a -s TERM
|
||||
sleep 5
|
||||
|
||||
echo "Umounting..."
|
||||
umount /proc
|
||||
umount /sys
|
||||
|
|
|
@ -10,33 +10,60 @@ typedef struct {
|
|||
} MU_MOUNT_OPTS;
|
||||
|
||||
MU_MOUNT_OPTS mu_options[] = {
|
||||
{"defaults", NULL, NULL, 0},
|
||||
{"ro", "rw", "Read only / Read and write", MS_RDONLY},
|
||||
{"remount", NULL, "Remount a mounted filesystem", MS_REMOUNT},
|
||||
{"sync", "async", "Writes are [a]synchronous", MS_SYNCHRONOUS},
|
||||
{"nodev", "dev", "(Dis)allow use of special device files", MS_NODEV}
|
||||
{"defaults", NULL, NULL, 0},
|
||||
{"ro", "rw", "Read only / Read and write", MS_RDONLY},
|
||||
{"remount", NULL, "Remount a mounted filesystem", MS_REMOUNT},
|
||||
{"sync", "async", "Writes are [a]synchronous", MS_SYNCHRONOUS},
|
||||
{"nodev", "dev", "(Dis)allow use of special device files", MS_NODEV},
|
||||
{"bind", "rbind", "Bind a file or directory", MS_BIND},
|
||||
{"noexec", "exec", "(Dis)allow use of executable files", MS_NOEXEC},
|
||||
{"noatime", "atime", "Disable/enable updates to inode access times", MS_NOATIME}
|
||||
};
|
||||
|
||||
unsigned long mu_parse_opts(char *str) {
|
||||
unsigned long opt = 1;
|
||||
unsigned long mu_parse_opts(char *str, char *data, const size_t data_size) {
|
||||
memset(data, '\0', data_size);
|
||||
unsigned long opt = 0;
|
||||
size_t data_len = 0;
|
||||
|
||||
char *token = strtok(str, ",");
|
||||
while (token != NULL) {
|
||||
int invalidopt = 1;
|
||||
for (size_t i = 0; i < sizeof(mu_options) / sizeof(mu_options[0]); i++) {
|
||||
if (mu_options[i].opt && !strcmp(token, mu_options[i].opt)) {
|
||||
opt |= mu_options[i].val;
|
||||
invalidopt = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
if (mu_options[i].notopt && !strcmp(token, mu_options[i].notopt)) {
|
||||
opt &= ~mu_options[i].val;
|
||||
invalidopt = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Unknow opt, pass in mount() */
|
||||
size_t len = strlen(token);
|
||||
if (invalidopt && len > 0) {
|
||||
/* Copy token string */
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
if (data_len + 1 >= data_size)
|
||||
break;
|
||||
|
||||
else {
|
||||
data[data_len] = token[i];
|
||||
data_len++;
|
||||
}
|
||||
}
|
||||
|
||||
if (data_len && data_len + 1 < data_size)
|
||||
data[data_len++] = ',';
|
||||
}
|
||||
|
||||
token = strtok(NULL, ",");
|
||||
}
|
||||
|
||||
data[data_len - 1] = '\0';
|
||||
return opt;
|
||||
}
|
||||
|
||||
|
|
|
@ -220,10 +220,10 @@ int print(const struct d_node *node) {
|
|||
char *gr_name = (gr != 0) ? gr->gr_name : "nobody";
|
||||
char *pw_name = (pw != 0) ? pw->pw_name : "nobody";
|
||||
if (h_flag)
|
||||
ret += printf(" 1 %s %s %6s %s %s%c", pw_name, gr_name, mu_humansize(node->stats.st_size), GetDate(node->stats.st_mtime), node->name, (F_flag) ? suf : 0);
|
||||
ret += printf(" %s %s %6s %s %s%c", pw_name, gr_name, mu_humansize(node->stats.st_size), GetDate(node->stats.st_mtime), node->name, (F_flag) ? suf : 0);
|
||||
|
||||
else
|
||||
ret += printf(" 1 %s %s %10jd %s %s%c", pw_name, gr_name, (uintmax_t)node->stats.st_size, GetDate(node->stats.st_mtime), node->name, (F_flag) ? suf : 0);
|
||||
ret += printf(" %s %s %10jd %s %s%c", pw_name, gr_name, (uintmax_t)node->stats.st_size, GetDate(node->stats.st_mtime), node->name, (F_flag) ? suf : 0);
|
||||
}
|
||||
|
||||
if (c_flag && p_flag)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#!/bin/sh
|
||||
project_dir=$(pwd)
|
||||
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
||||
mv reboot $OUTPUT/reboot
|
||||
mv poweroff $OUTPUT/poweroff
|
||||
cp reboot $OUTPUT/reboot
|
||||
cp poweroff $OUTPUT/poweroff
|
||||
|
|
|
@ -35,7 +35,7 @@ void execute(char *argv[], sigset_t *set) {
|
|||
waitpid(pid, &status, 0);
|
||||
|
||||
if (status != 0) {
|
||||
fprintf(stderr, "init: Init script returned %d\nRebooting...", status);
|
||||
fprintf(stderr, "init: Init script returned %d\nRebooting...\n", status);
|
||||
poweroff(SIGKILL);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
#!/bin/sh
|
||||
kill -s USR1 1
|
|
@ -0,0 +1,2 @@
|
|||
#!/bin/sh
|
||||
kill -s KILL 1
|
|
@ -7,8 +7,8 @@
|
|||
#include "parse_mount.h"
|
||||
#include "config.h"
|
||||
|
||||
int do_mount(const char *src, const char *dst, const char *fs_type, unsigned long opt) {
|
||||
if (mount(src, dst, fs_type, opt, NULL) < 0) {
|
||||
int do_mount(const char *src, const char *dst, const char *fs_type, unsigned long opt, char *data) {
|
||||
if (mount(src, dst, fs_type, opt, data) < 0) {
|
||||
fprintf(stderr, "mount: %s: %s\n", src, strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
@ -73,6 +73,8 @@ void print_opts(void) {
|
|||
|
||||
int main(int argc, char **argv) {
|
||||
char *fs_type = MOUNT_DEF_FS;
|
||||
char data[MOUNT_OPT_SIZE + 1];
|
||||
|
||||
unsigned long mode = 0;
|
||||
|
||||
int opt;
|
||||
|
@ -86,7 +88,7 @@ int main(int argc, char **argv) {
|
|||
break;
|
||||
|
||||
case 'o':
|
||||
mode = mu_parse_opts(optarg);
|
||||
mode = mu_parse_opts(optarg, data, sizeof(data));
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -100,10 +102,10 @@ int main(int argc, char **argv) {
|
|||
argv += optind;
|
||||
|
||||
if (argc == 2)
|
||||
return do_mount(argv[0], argv[1], fs_type, mode);
|
||||
return do_mount(argv[0], argv[1], fs_type, mode, data);
|
||||
|
||||
else if (argc == 1)
|
||||
return do_mount(NULL, argv[0], fs_type, mode);
|
||||
return do_mount(NULL, argv[0], fs_type, mode, data);
|
||||
|
||||
else
|
||||
return print_mounts();
|
||||
|
|
Loading…
Reference in New Issue