parent
db0a62fc9f
commit
428ce212a5
@ -0,0 +1,6 @@ |
|||||||
|
#pragma once |
||||||
|
|
||||||
|
struct console; |
||||||
|
|
||||||
|
int shell_prepare(struct console *con, size_t argc, const char **argv); |
||||||
|
int shell_boot(struct console *con, size_t argc, const char **argv); |
@ -0,0 +1,65 @@ |
|||||||
|
#include <stdio.h> |
||||||
|
#include <stdlib.h> |
||||||
|
#include <string.h> |
||||||
|
|
||||||
|
#include <console.h> |
||||||
|
#include <macros.h> |
||||||
|
|
||||||
|
#include <fs/mufs.h> |
||||||
|
|
||||||
|
#include <shell/boot.h> |
||||||
|
|
||||||
|
extern struct mufs *mufs; |
||||||
|
|
||||||
|
int shell_prepare(struct console *con, size_t argc, const char **argv) |
||||||
|
{ |
||||||
|
char buf[256]; |
||||||
|
struct mufs_file *file; |
||||||
|
size_t size, n; |
||||||
|
|
||||||
|
if (argc < 1) { |
||||||
|
fprintf(con->fp, "usage: booting <version>\n"); |
||||||
|
return -1; |
||||||
|
} |
||||||
|
|
||||||
|
if (!mufs) { |
||||||
|
fprintf(con->fp, "error: no file system mounted.\n"); |
||||||
|
return -1; |
||||||
|
} |
||||||
|
|
||||||
|
if (!(file = mufs_open(mufs, "logs/boot.log", MUFS_WRITE | MUFS_APPEND))) { |
||||||
|
fprintf(con->fp, "error: unable to open the file\n"); |
||||||
|
return -1; |
||||||
|
} |
||||||
|
|
||||||
|
n = min(strlen(argv[0]), sizeof(buf) - 2); |
||||||
|
|
||||||
|
memcpy(buf, argv[0], n); |
||||||
|
buf[n++] = '\n'; |
||||||
|
buf[n] = '\0'; |
||||||
|
|
||||||
|
size = mufs_write(file, buf, n); |
||||||
|
mufs_close(file); |
||||||
|
|
||||||
|
if (size < n) { |
||||||
|
fprintf(con->fp, "error: unable to log the version to boot\n"); |
||||||
|
return -1; |
||||||
|
} |
||||||
|
|
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
int shell_boot(struct console *con, size_t argc, const char **argv) |
||||||
|
{ |
||||||
|
(void)con; |
||||||
|
|
||||||
|
if (argc < 1) { |
||||||
|
fprintf(con->fp, "usage: booting ok\n"); |
||||||
|
return -1; |
||||||
|
} |
||||||
|
|
||||||
|
if (strcmp(argv[0], "ok") != 0) |
||||||
|
return -1; |
||||||
|
|
||||||
|
return 0; |
||||||
|
} |
Loading…
Reference in new issue