fs_shell: Integrate btrfs_shell's command_cat into fs_shell itself.
This commit is contained in:
@@ -56,8 +56,7 @@ BuildPlatformMergeObject <build>btrfs.o : $(btrfsSources) $(utilitySources) ;
|
|||||||
|
|
||||||
BuildPlatformMain <build>btrfs_shell
|
BuildPlatformMain <build>btrfs_shell
|
||||||
:
|
:
|
||||||
additional_commands.cpp
|
# no extra files
|
||||||
command_cat.cpp
|
|
||||||
:
|
:
|
||||||
<build>btrfs.o
|
<build>btrfs.o
|
||||||
<build>fs_shell.a $(HOST_LIBSUPC++) $(HOST_LIBSTDC++)
|
<build>fs_shell.a $(HOST_LIBSUPC++) $(HOST_LIBSTDC++)
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
#include "fssh.h"
|
|
||||||
|
|
||||||
#include "command_cat.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace FSShell {
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
register_additional_commands()
|
|
||||||
{
|
|
||||||
CommandManager::Default()->AddCommands(
|
|
||||||
command_cat, "cat", "concatenate file(s) to stdout",
|
|
||||||
NULL
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace FSShell
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include "syscalls.h"
|
|
||||||
#include "system_dependencies.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace FSShell {
|
|
||||||
|
|
||||||
|
|
||||||
fssh_status_t
|
|
||||||
command_cat(int argc, const char* const* argv)
|
|
||||||
{
|
|
||||||
long numBytes = 10;
|
|
||||||
int fileStart = 1;
|
|
||||||
if (argc < 2 || strcmp(argv[1], "--help") == 0) {
|
|
||||||
printf(
|
|
||||||
"Usage: %s [ -n ] [FILE]...\n"
|
|
||||||
"\t -n\tNumber of bytes to read\n",
|
|
||||||
argv[0]
|
|
||||||
);
|
|
||||||
return FSSH_B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (argc > 3 && strcmp(argv[1], "-n") == 0) {
|
|
||||||
fileStart += 2;
|
|
||||||
numBytes = strtol(argv[2], NULL, 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* const* files = argv + fileStart;
|
|
||||||
for (; *files; files++) {
|
|
||||||
const char* file = *files;
|
|
||||||
int fd = _kern_open(-1, file, O_RDONLY, O_RDONLY);
|
|
||||||
if (fd < 0) {
|
|
||||||
fssh_dprintf("Error: %s\n", fssh_strerror(fd));
|
|
||||||
return FSSH_B_BAD_VALUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
char buffer[numBytes + 1];
|
|
||||||
if (buffer == NULL) {
|
|
||||||
fssh_dprintf("Error: No memory\n");
|
|
||||||
_kern_close(fd);
|
|
||||||
return FSSH_B_NO_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_kern_read(fd, 0, buffer, numBytes) != numBytes) {
|
|
||||||
fssh_dprintf("Error: fail to read, length: %i\n", numBytes);
|
|
||||||
_kern_close(fd);
|
|
||||||
return FSSH_B_BAD_VALUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
_kern_close(fd);
|
|
||||||
buffer[numBytes] = '\0';
|
|
||||||
printf("%s\n", buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
return FSSH_B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace FSShell
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
#ifndef COMMAND_CAT_H
|
|
||||||
#define COMMAND_CAT_H
|
|
||||||
|
|
||||||
|
|
||||||
#include "fssh_types.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace FSShell {
|
|
||||||
|
|
||||||
|
|
||||||
fssh_status_t command_cat(int argc, const char* const* argv);
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace FSShell
|
|
||||||
|
|
||||||
|
|
||||||
#endif // COMMAND_CAT_H
|
|
||||||
@@ -25,6 +25,7 @@
|
|||||||
#include "fssh_errno.h"
|
#include "fssh_errno.h"
|
||||||
#include "fssh_errors.h"
|
#include "fssh_errors.h"
|
||||||
#include "fssh_fs_info.h"
|
#include "fssh_fs_info.h"
|
||||||
|
#include "fssh_fcntl.h"
|
||||||
#include "fssh_module.h"
|
#include "fssh_module.h"
|
||||||
#include "fssh_node_monitor.h"
|
#include "fssh_node_monitor.h"
|
||||||
#include "fssh_stat.h"
|
#include "fssh_stat.h"
|
||||||
@@ -687,6 +688,54 @@ command_chmod(int argc, const char* const* argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static fssh_status_t
|
||||||
|
command_cat(int argc, const char* const* argv)
|
||||||
|
{
|
||||||
|
size_t numBytes = 10;
|
||||||
|
int fileStart = 1;
|
||||||
|
if (argc < 2 || strcmp(argv[1], "--help") == 0) {
|
||||||
|
printf("Usage: %s [ -n ] [FILE]...\n"
|
||||||
|
"\t -n\tNumber of bytes to read\n",
|
||||||
|
argv[0]);
|
||||||
|
return FSSH_B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argc > 3 && strcmp(argv[1], "-n") == 0) {
|
||||||
|
fileStart += 2;
|
||||||
|
numBytes = strtol(argv[2], NULL, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* const* files = argv + fileStart;
|
||||||
|
for (; *files; files++) {
|
||||||
|
const char* file = *files;
|
||||||
|
int fd = _kern_open(-1, file, FSSH_O_RDONLY, FSSH_O_RDONLY);
|
||||||
|
if (fd < 0) {
|
||||||
|
fprintf(stderr, "error: %s\n", fssh_strerror(fd));
|
||||||
|
return FSSH_B_BAD_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
char buffer[numBytes + 1];
|
||||||
|
if (buffer == NULL) {
|
||||||
|
fprintf(stderr, "error: No memory\n");
|
||||||
|
_kern_close(fd);
|
||||||
|
return FSSH_B_NO_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_kern_read(fd, 0, buffer, numBytes) != (ssize_t)numBytes) {
|
||||||
|
fprintf(stderr, "error reading: %s\n", fssh_strerror(fd));
|
||||||
|
_kern_close(fd);
|
||||||
|
return FSSH_B_BAD_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
_kern_close(fd);
|
||||||
|
buffer[numBytes] = '\0';
|
||||||
|
printf("%s\n", buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
return FSSH_B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static fssh_status_t
|
static fssh_status_t
|
||||||
command_help(int argc, const char* const* argv)
|
command_help(int argc, const char* const* argv)
|
||||||
{
|
{
|
||||||
@@ -1214,6 +1263,7 @@ register_commands()
|
|||||||
command_cd, "cd", "change current directory",
|
command_cd, "cd", "change current directory",
|
||||||
command_chmod, "chmod", "change file permissions",
|
command_chmod, "chmod", "change file permissions",
|
||||||
command_cp, "cp", "copy files and directories",
|
command_cp, "cp", "copy files and directories",
|
||||||
|
command_cat, "cat", "concatenate file(s) to stdout",
|
||||||
command_help, "help", "list supported commands",
|
command_help, "help", "list supported commands",
|
||||||
command_info, "info", "prints volume informations",
|
command_info, "info", "prints volume informations",
|
||||||
command_ioctl, "ioctl", "ioctl() on root, for FS debugging only",
|
command_ioctl, "ioctl", "ioctl() on root, for FS debugging only",
|
||||||
|
|||||||
Reference in New Issue
Block a user