支持binutils大部分工具
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
#include <pthread.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include "u_sys.h"
|
||||
int ls(int argc, char *agrv[])
|
||||
@@ -28,7 +29,9 @@ int ls(int argc, char *agrv[])
|
||||
}
|
||||
while ((ptr = readdir(dir)) != NULL)
|
||||
{
|
||||
printf("%s \n", ptr->d_name);
|
||||
struct stat st = {0};
|
||||
stat(ptr->d_name, &st);
|
||||
printf("%s\t\t\t%dB\n", ptr->d_name, st.st_size);
|
||||
}
|
||||
closedir(dir);
|
||||
return 0;
|
||||
@@ -58,7 +61,38 @@ int cat(int argc, char *argv[])
|
||||
return 0;
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN), cat, cat, cat command);
|
||||
int hex(int argc, char *argv[])
|
||||
{
|
||||
int i = 0;
|
||||
if (argc != 2)
|
||||
{
|
||||
return (-1);
|
||||
}
|
||||
|
||||
FILE *fp;
|
||||
char c;
|
||||
int ret;
|
||||
|
||||
if ((fp = fopen(argv[1], "rb")) == NULL)
|
||||
{
|
||||
return errno;
|
||||
}
|
||||
|
||||
while ((ret = fread( &c, 1,1,fp)) == 1)
|
||||
{
|
||||
printf("%02x ", c);
|
||||
i++;
|
||||
if (i % 16 == 0)
|
||||
{
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
printf("\nsize:%dB\n", i);
|
||||
fclose(fp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN), hex, hex, hex command);
|
||||
int kill(int argc, char *argv[])
|
||||
{
|
||||
if (argc < 2)
|
||||
|
||||
@@ -3,9 +3,8 @@
|
||||
#include "fs_backend.h"
|
||||
#include "u_types.h"
|
||||
#include <sys/uio.h>
|
||||
#include <time.h>
|
||||
#include <sys/stat.h>
|
||||
// #include <unistd.h>
|
||||
#include <time.h>
|
||||
|
||||
#define ARG_1_BE(ap, arg0, type0) \
|
||||
do \
|
||||
@@ -94,6 +93,7 @@ long be_set_thread_area(void *p);
|
||||
long be_getdents(long fd, char *buf, size_t size);
|
||||
long be_mkdir(const char *path, mode_t mode);
|
||||
long be_symlink(const char *src, const char *dst);
|
||||
long be_stat(const char *path, void *buf);
|
||||
int be_clone(int (*func)(void *), void *stack, int flags, void *args, pid_t *ptid, void *tls, pid_t *ctid);
|
||||
umword_t be_munmap(void *start, size_t len);
|
||||
umword_t be_mmap(void *start,
|
||||
|
||||
@@ -7,19 +7,18 @@
|
||||
#include <assert.h>
|
||||
#include <cons_cli.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/uio.h>
|
||||
#include <u_env.h>
|
||||
#include <u_log.h>
|
||||
#include <u_prot.h>
|
||||
#include <u_sema.h>
|
||||
#include <u_task.h>
|
||||
#include <u_util.h>
|
||||
#include <u_sema.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
AUTO_CALL(101)
|
||||
void fs_backend_init(void)
|
||||
{
|
||||
@@ -439,6 +438,25 @@ long be_getdents(long fd, char *buf, size_t size)
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// int stat(const char *pathname, struct stat *buf);
|
||||
long be_stat(const char *path, void *_buf)
|
||||
{
|
||||
struct kstat *buf = _buf;
|
||||
return fs_stat((char *)path, buf);
|
||||
}
|
||||
long be_fstat(int fd, void *_buf)
|
||||
{
|
||||
struct kstat *buf = _buf;
|
||||
fd_map_entry_t u_fd;
|
||||
int ret = fd_map_get(fd, &u_fd);
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
return -EBADF;
|
||||
}
|
||||
return fs_fstat(u_fd.priv_fd, (void *)buf);
|
||||
}
|
||||
long sys_be_getdents(va_list ap)
|
||||
{
|
||||
long fd;
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
struct kstat {
|
||||
dev_t st_dev;
|
||||
long st_dev;
|
||||
int __st_dev_padding;
|
||||
long __st_ino_truncated;
|
||||
mode_t st_mode;
|
||||
nlink_t st_nlink;
|
||||
uid_t st_uid;
|
||||
gid_t st_gid;
|
||||
dev_t st_rdev;
|
||||
long st_rdev;
|
||||
int __st_rdev_padding;
|
||||
off_t st_size;
|
||||
long st_size;
|
||||
blksize_t st_blksize;
|
||||
blkcnt_t st_blocks;
|
||||
long st_blocks;
|
||||
long st_atime_sec;
|
||||
long st_atime_nsec;
|
||||
long st_mtime_sec;
|
||||
long st_mtime_nsec;
|
||||
long st_ctime_sec;
|
||||
long st_ctime_nsec;
|
||||
ino_t st_ino;
|
||||
};
|
||||
long st_ino;
|
||||
};
|
||||
@@ -67,7 +67,9 @@ static int fstatat_statx(int fd, const char *restrict path, struct stat *restric
|
||||
};
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef NO_LITTLE_MODE
|
||||
#include "syscall_backend.h"
|
||||
#endif
|
||||
#ifdef SYS_fstatat
|
||||
|
||||
#include "kstat.h"
|
||||
@@ -78,7 +80,11 @@ static int fstatat_kstat(int fd, const char *restrict path, struct stat *restric
|
||||
struct kstat kst;
|
||||
|
||||
if (flag==AT_EMPTY_PATH && fd>=0 && !*path) {
|
||||
#ifdef NO_LITTLE_MODE
|
||||
ret = __syscall(SYS_fstat, fd, &kst);
|
||||
#else
|
||||
ret = be_fstat(fd, &kst);
|
||||
#endif
|
||||
if (ret==-EBADF && __syscall(SYS_fcntl, fd, F_GETFD)>=0) {
|
||||
ret = __syscall(SYS_fstatat, fd, path, &kst, flag);
|
||||
if (ret==-EINVAL) {
|
||||
@@ -97,8 +103,14 @@ static int fstatat_kstat(int fd, const char *restrict path, struct stat *restric
|
||||
ret = __syscall(SYS_lstat, path, &kst);
|
||||
#endif
|
||||
#ifdef SYS_stat
|
||||
else if ((fd == AT_FDCWD || *path=='/') && !flag)
|
||||
ret = __syscall(SYS_stat, path, &kst);
|
||||
else if ((fd == AT_FDCWD || *path=='/') && !flag) {
|
||||
#ifdef NO_LITTLE_MODE
|
||||
ret = __syscall(SYS_stat, path, &kst);
|
||||
#else
|
||||
ret = be_stat( path, &kst);
|
||||
#endif
|
||||
|
||||
}
|
||||
#endif
|
||||
else ret = __syscall(SYS_fstatat, fd, path, &kst, flag);
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ int fs_write(sd_t _fd, void *buf, size_t len);
|
||||
int fs_readdir(sd_t _fd, dirent_t *dirent);
|
||||
int fs_lseek(sd_t _fd, int offs, int whence);
|
||||
int fs_ftruncate(sd_t _fd, off_t off);
|
||||
int fs_fstat(sd_t _fd, int fd, stat_t *stat);
|
||||
int fs_fstat(sd_t _fd, stat_t *stat);
|
||||
int fs_ioctl(sd_t _fd, int req, void *arg);
|
||||
int fs_fcntl(sd_t _fd, int cmd, void *arg);
|
||||
int fs_fsync(sd_t _fd);
|
||||
@@ -20,6 +20,6 @@ int fs_symlink(const char *src, const char *dst);
|
||||
int fs_mkdir(char *path);
|
||||
int fs_rmdir(char *path);
|
||||
int fs_rename(char *old, char *new);
|
||||
int fs_stat(char *path, stat_t *buf);
|
||||
int fs_stat(char *path, void *buf);
|
||||
int fs_readlink(const char *path, char *buf, int bufsize);
|
||||
int fs_statfs(const char *path, statfs_t *buf);
|
||||
|
||||
@@ -17,7 +17,7 @@ void fs_svr_close(int fd);
|
||||
int fs_svr_readdir(int fd, dirent_t *dir);
|
||||
int fs_svr_lseek(int fd, int offs, int whence);
|
||||
int fs_svr_ftruncate(int fd, off_t off);
|
||||
int fs_svr_fstat(int fd, stat_t *buf);
|
||||
int fs_svr_fstat(int fd, void *buf);
|
||||
int fs_svr_ioctl(int fd, int req, void *arg);
|
||||
int fs_svr_fcntl(int fd, int cmd, void *arg);
|
||||
int fs_svr_fsync(int fd);
|
||||
@@ -26,6 +26,6 @@ int fs_svr_symlink(const char *existing, const char *new);
|
||||
int fs_svr_mkdir(char *path);
|
||||
int fs_svr_rmdir(char *path);
|
||||
int fs_svr_rename(char *old, char *new);
|
||||
int fs_svr_stat(const char *path, struct stat *buf);
|
||||
int fs_svr_stat(const char *path, void *buf);
|
||||
ssize_t fs_svr_readlink(const char *path, char *buf, size_t bufsize);
|
||||
int fs_svr_statfs(const char *path, struct statfs *buf);
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
#define rpc_ref_file_array_t rpc_ref_array_uint32_t_uint8_t_32_t
|
||||
#define rpc_file_array_t rpc_array_uint32_t_uint8_t_32_t
|
||||
#elif CONFIG_THREAD_MSG_BUG_LEN == 256
|
||||
#define FS_RPC_BUF_LEN 96
|
||||
#define rpc_ref_file_array_t rpc_ref_array_uint32_t_uint8_t_96_t
|
||||
#define rpc_file_array_t rpc_array_uint32_t_uint8_t_96_t
|
||||
#define FS_RPC_BUF_LEN (128)
|
||||
#define rpc_ref_file_array_t rpc_ref_array_uint32_t_uint8_t_128_t
|
||||
#define rpc_file_array_t rpc_array_uint32_t_uint8_t_128_t
|
||||
#elif CONFIG_THREAD_MSG_BUG_LEN == 512
|
||||
#define FS_RPC_BUF_LEN (128 + 32)
|
||||
#define rpc_ref_file_array_t rpc_ref_array_uint32_t_uint8_t_160_t
|
||||
|
||||
@@ -11,7 +11,10 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include "kstat.h"
|
||||
typedef struct kstat kstat_t;
|
||||
RPC_TYPE_DEF_ALL(kstat_t)
|
||||
/*open*/
|
||||
RPC_GENERATION_CALL3(TRUE, fs_t, FS_PROT, FS_OPEN, open,
|
||||
rpc_ref_file_array_t, rpc_file_array_t, RPC_DIR_IN, RPC_TYPE_DATA, path,
|
||||
@@ -244,8 +247,8 @@ int fs_ftruncate(sd_t _fd, off_t off)
|
||||
// int fstat(int fd, struct stat *statbuf);
|
||||
RPC_GENERATION_CALL2(TRUE, fs_t, FS_PROT, FS_FSTAT, fstat,
|
||||
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, fd,
|
||||
rpc_stat_t_t, rpc_stat_t_t, RPC_DIR_OUT, RPC_TYPE_DATA, statbuf)
|
||||
int fs_fstat(sd_t _fd, stat_t *stat)
|
||||
rpc_kstat_t_t, rpc_kstat_t_t, RPC_DIR_OUT, RPC_TYPE_DATA, statbuf)
|
||||
int fs_fstat(sd_t _fd, kstat_t *stat)
|
||||
{
|
||||
obj_handler_t hd = mk_sd_init_raw(_fd).hd;
|
||||
int fd = mk_sd_init_raw(_fd).fd;
|
||||
@@ -253,7 +256,7 @@ int fs_fstat(sd_t _fd, stat_t *stat)
|
||||
rpc_int_t rpc_fd = {
|
||||
.data = fd,
|
||||
};
|
||||
rpc_stat_t_t rpc_statbuf;
|
||||
rpc_kstat_t_t rpc_statbuf;
|
||||
msg_tag_t tag;
|
||||
|
||||
if (!stat)
|
||||
@@ -498,16 +501,17 @@ int fs_rename(char *old, char *new)
|
||||
// int stat(const char *restrict path, struct stat *restrict buf)
|
||||
RPC_GENERATION_CALL2(TRUE, fs_t, FS_PROT, FS_STAT, stat,
|
||||
rpc_ref_file_array_t, rpc_file_array_t, RPC_DIR_IN, RPC_TYPE_DATA, path,
|
||||
rpc_stat_t_t, rpc_stat_t_t, RPC_DIR_OUT, RPC_TYPE_DATA, buf)
|
||||
rpc_kstat_t_t, rpc_kstat_t_t, RPC_DIR_OUT, RPC_TYPE_DATA, buf)
|
||||
|
||||
int fs_stat(char *path, stat_t *buf)
|
||||
int fs_stat(char *path, void *_buf)
|
||||
{
|
||||
kstat_t *buf = (kstat_t *)_buf;
|
||||
obj_handler_t hd;
|
||||
if (!buf)
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
int ret = ns_query(path, &hd, 0x1);
|
||||
int ret = ns_query(path, &hd, 0x0);
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
@@ -517,7 +521,7 @@ int fs_stat(char *path, stat_t *buf)
|
||||
.data = (uint8_t *)(&path[ret]),
|
||||
.len = strlen(&path[ret]) + 1,
|
||||
};
|
||||
rpc_stat_t_t rpc_buf;
|
||||
rpc_kstat_t_t rpc_buf;
|
||||
msg_tag_t tag;
|
||||
|
||||
tag = fs_t_stat_call(hd, &rpc_path, &rpc_buf);
|
||||
|
||||
@@ -6,7 +6,10 @@
|
||||
#include "u_rpc.h"
|
||||
#include "fs_types.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include "kstat.h"
|
||||
typedef struct kstat kstat_t;
|
||||
RPC_TYPE_DEF_ALL(kstat_t)
|
||||
/*open*/
|
||||
RPC_GENERATION_OP3(fs_t, FS_PROT, FS_OPEN, open,
|
||||
rpc_ref_file_array_t, rpc_file_array_t, RPC_DIR_IN, RPC_TYPE_DATA, path,
|
||||
@@ -109,14 +112,14 @@ RPC_GENERATION_DISPATCH2(fs_t, FS_PROT, FS_FTRUNCATE, ftruncate,
|
||||
/*fstat*/
|
||||
RPC_GENERATION_OP2(fs_t, FS_PROT, FS_FSTAT, fstat,
|
||||
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, fd,
|
||||
rpc_stat_t_t, rpc_stat_t_t, RPC_DIR_OUT, RPC_TYPE_DATA, statbuf)
|
||||
rpc_kstat_t_t, rpc_kstat_t_t, RPC_DIR_OUT, RPC_TYPE_DATA, statbuf)
|
||||
{
|
||||
int ret = fs_svr_fstat(fd->data, &statbuf->data);
|
||||
return ret;
|
||||
}
|
||||
RPC_GENERATION_DISPATCH2(fs_t, FS_PROT, FS_FSTAT, fstat,
|
||||
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, fd,
|
||||
rpc_stat_t_t, rpc_stat_t_t, RPC_DIR_OUT, RPC_TYPE_DATA, statbuf)
|
||||
rpc_kstat_t_t, rpc_kstat_t_t, RPC_DIR_OUT, RPC_TYPE_DATA, statbuf)
|
||||
|
||||
/*ioctl*/
|
||||
RPC_GENERATION_OP3(fs_t, FS_PROT, FS_IOCTL, ioctl,
|
||||
@@ -222,14 +225,14 @@ RPC_GENERATION_DISPATCH2(fs_t, FS_PROT, FS_RENAME, rename,
|
||||
// int stat(const char *restrict path, struct stat *restrict buf)
|
||||
RPC_GENERATION_OP2(fs_t, FS_PROT, FS_STAT, stat,
|
||||
rpc_ref_file_array_t, rpc_file_array_t, RPC_DIR_IN, RPC_TYPE_DATA, path,
|
||||
rpc_stat_t_t, rpc_stat_t_t, RPC_DIR_OUT, RPC_TYPE_DATA, buf)
|
||||
rpc_kstat_t_t, rpc_kstat_t_t, RPC_DIR_OUT, RPC_TYPE_DATA, buf)
|
||||
{
|
||||
path->data[path->len - 1] = 0;
|
||||
return fs_svr_stat(path->data, &buf->data);
|
||||
}
|
||||
RPC_GENERATION_DISPATCH2(fs_t, FS_PROT, FS_STAT, stat,
|
||||
rpc_ref_file_array_t, rpc_file_array_t, RPC_DIR_IN, RPC_TYPE_DATA, path,
|
||||
rpc_stat_t_t, rpc_stat_t_t, RPC_DIR_OUT, RPC_TYPE_DATA, buf)
|
||||
rpc_kstat_t_t, rpc_kstat_t_t, RPC_DIR_OUT, RPC_TYPE_DATA, buf)
|
||||
|
||||
// ssize_t readlink(const char *restrict path, char *restrict buf, size_t bufsize)
|
||||
RPC_GENERATION_OP3(fs_t, FS_PROT, FS_READLINK, readlink,
|
||||
|
||||
@@ -22,7 +22,9 @@
|
||||
#include <dirent.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/statfs.h>
|
||||
|
||||
typedef struct stat stat_t;
|
||||
// typedef struct kstat kstat_t;
|
||||
typedef struct statfs statfs_t;
|
||||
typedef struct dirent dirent_t;
|
||||
|
||||
@@ -190,6 +192,7 @@ RPC_TYPE_DEF_ALL(umword_t) //!< 定义所有的
|
||||
RPC_TYPE_DEF_ALL(mword_t) //!< 定义所有的
|
||||
RPC_TYPE_DEF_ALL(dirent_t) //!< 目录类型
|
||||
RPC_TYPE_DEF_ALL(stat_t)
|
||||
// RPC_TYPE_DEF_ALL(kstat_t)
|
||||
RPC_TYPE_DEF_ALL(statfs_t)
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user