diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cmds/ntux_cmd_fspath.c | 91 | ||||
-rw-r--r-- | src/driver/ntux_amain.c | 3 | ||||
-rw-r--r-- | src/driver/ntux_driver_ctx.c | 48 | ||||
-rw-r--r-- | src/internal/ntux_driver_impl.h | 6 | ||||
-rw-r--r-- | src/skin/ntux_skin_default.c | 2 | ||||
-rw-r--r-- | src/skin/ntux_skin_fspath.c | 32 |
6 files changed, 181 insertions, 1 deletions
diff --git a/src/cmds/ntux_cmd_fspath.c b/src/cmds/ntux_cmd_fspath.c new file mode 100644 index 0000000..9b25062 --- /dev/null +++ b/src/cmds/ntux_cmd_fspath.c @@ -0,0 +1,91 @@ +/***********************************************************/ +/* ntux: native translation und extension */ +/* Copyright (C) 2016--2022 SysDeer Technologies, LLC */ +/* Released under GPLv2 and GPLv3; see COPYING.NTUX. */ +/***********************************************************/ + +#include <psxabi/sys_sysapi.h> +#include <psxabi/sys_stat.h> +#include <psxabi/sys_errno.h> + +#include <psxxfi/xfi_ofd.h> +#include <psxxfi/xfi_stat.h> +#include <psxxfi/xfi_unicode.h> + +#include <ntux/ntux.h> +#include "ntux_driver_impl.h" +#include "ntux_nolibc_impl.h" +#include "ntux_errinfo_impl.h" + +static int ntux_cmd_fspath_ret(void * buf, int ret) +{ + if (buf) + ntux_free(buf); + + return ret; +} + +int ntux_cmd_fspath(const struct ntux_driver_ctx * dctx, const char * dunit) +{ + intptr_t ret; + int fdout; + int fdcwd; + const unsigned char * unit; + char * str; + void * buf = 0; + const size_t bufsize = 0x10000; + + /* init */ + ntux_driver_set_ectx( + dctx,0,dunit); + + unit = (const unsigned char *)dunit; + + /* fdctx */ + fdout = ntux_driver_fdout(dctx); + fdcwd = ntux_driver_fdcwd(dctx); + + /* buffer */ + if (!(buf = ntux_calloc(1,bufsize))) + if (ntux_errno_set(dctx,ENOMEM)) + return ntux_cmd_fspath_ret( + buf, + NTUX_SYSTEM_ERROR(dctx)); + + str = (char *)buf; + + /* root-relative notation? */ + if (dctx->cctx->drvflags & NTUX_DRIVER_RPATH) { + if ((ret = __sys_fs_rpath( + fdcwd, + (const char *)unit, + 0,buf,bufsize)) < 0) + return ntux_cmd_fspath_ret(buf,ret); + + } else if (dctx->cctx->drvflags & NTUX_DRIVER_APATH) { + if ((ret = __sys_fs_apath( + fdcwd, + (const char *)unit, + 0,buf,bufsize)) < 0) + return ntux_cmd_fspath_ret(buf,ret); + } else if (dctx->cctx->drvflags & NTUX_DRIVER_NPATH) { + if ((ret = __sys_fs_npath( + fdcwd, + (const char *)unit, + 0,buf,bufsize)) < 0) + return ntux_cmd_fspath_ret(buf,ret); + + } else if (dctx->cctx->drvflags & NTUX_DRIVER_DPATH) { + if ((ret = __sys_fs_dpath( + fdcwd, + (const char *)unit, + 0,buf,bufsize)) < 0) + return ntux_cmd_fspath_ret(buf,ret); + } + + /* outupt */ + ntux_dprintf(fdout,"%s\n",str); + + /* all done */ + return ntux_cmd_fspath_ret(buf,0); +} diff --git a/src/driver/ntux_amain.c b/src/driver/ntux_amain.c index dbf5039..d103046 100644 --- a/src/driver/ntux_amain.c +++ b/src/driver/ntux_amain.c @@ -63,6 +63,9 @@ static void ntux_perform_unit_actions( else if (dctx->cctx->cmd == NTUX_CMD_ACEIT) ntux_cmd_aceit(dctx,unit); + + else if (dctx->cctx->cmd == NTUX_CMD_FSPATH) + ntux_cmd_fspath(dctx,unit); } static int ntux_exit(struct ntux_driver_ctx * dctx, int ret) diff --git a/src/driver/ntux_driver_ctx.c b/src/driver/ntux_driver_ctx.c index 3edf1d2..129992c 100644 --- a/src/driver/ntux_driver_ctx.c +++ b/src/driver/ntux_driver_ctx.c @@ -35,6 +35,7 @@ static const char * const ntux_cmd_name[NTUX_CMD_CAP] = { [NTUX_CMD_STRACE] = "strace", [NTUX_CMD_CHMOD] = "chmod", [NTUX_CMD_ACEIT] = "aceit", + [NTUX_CMD_FSPATH] = "fspath", }; /* ntux command options */ @@ -45,6 +46,7 @@ static const struct argv_option * ntux_cmd_options[NTUX_CMD_CAP] = { [NTUX_CMD_STRACE] = ntux_strace_options, [NTUX_CMD_CHMOD] = ntux_chmod_options, [NTUX_CMD_ACEIT] = ntux_aceit_options, + [NTUX_CMD_FSPATH] = ntux_fspath_options, }; /* package info */ @@ -211,6 +213,9 @@ static int ntux_cctx_update( else if (!strcmp(entry->arg,"aceit")) cctx->cmd = NTUX_CMD_ACEIT; + else if (!strcmp(entry->arg,"fspath")) + cctx->cmd = NTUX_CMD_FSPATH; + break; case TAG_LOADER: @@ -258,6 +263,44 @@ static int ntux_cctx_update( case TAG_DUMP: cctx->drvflags |= NTUX_DRIVER_DUMP; break; + + case TAG_SYNTAX: + case TAG_RPATH: + case TAG_APATH: + case TAG_NPATH: + case TAG_DPATH: + cctx->drvflags &= ~(uint64_t)NTUX_DRIVER_RPATH; + cctx->drvflags &= ~(uint64_t)NTUX_DRIVER_APATH; + cctx->drvflags &= ~(uint64_t)NTUX_DRIVER_NPATH; + cctx->drvflags &= ~(uint64_t)NTUX_DRIVER_DPATH; + + if (entry->tag == TAG_SYNTAX) { + if (!strcmp(entry->arg,"relative")) + cctx->drvflags |= NTUX_DRIVER_RPATH; + + else if (!strcmp(entry->arg,"absolute")) + cctx->drvflags |= NTUX_DRIVER_APATH; + + else if (!strcmp(entry->arg,"native")) + cctx->drvflags |= NTUX_DRIVER_NPATH; + + else if (!strcmp(entry->arg,"driver")) + cctx->drvflags |= NTUX_DRIVER_DPATH; + + } else if (entry->tag == TAG_RPATH) { + cctx->drvflags |= NTUX_DRIVER_RPATH; + + } else if (entry->tag == TAG_APATH) { + cctx->drvflags |= NTUX_DRIVER_APATH; + + } else if (entry->tag == TAG_NPATH) { + cctx->drvflags |= NTUX_DRIVER_NPATH; + + } else if (entry->tag == TAG_DPATH) { + cctx->drvflags |= NTUX_DRIVER_DPATH; + } + + break; } } else { (*nunits)++; @@ -299,6 +342,8 @@ static int ntux_cmd_from_program(const char * program) return NTUX_CMD_CHMOD; else if (!strcmp(mark,"aceit")) return NTUX_CMD_ACEIT; + else if (!strcmp(mark,"fspath")) + return NTUX_CMD_FSPATH; return NTUX_CMD_DEFAULT; } @@ -440,6 +485,9 @@ int ntux_get_driver_ctx( else if (cctx.cmd == NTUX_CMD_ACEIT) argv_optv_init(ntux_aceit_options,optv); + else if (cctx.cmd == NTUX_CMD_FSPATH) + argv_optv_init(ntux_fspath_options,optv); + /* spawn, strace */ if ((cctx.cmd == NTUX_CMD_SPAWN) || (cctx.cmd == NTUX_CMD_STRACE)) { argv_scan(argv,optv,&ctx,0); diff --git a/src/internal/ntux_driver_impl.h b/src/internal/ntux_driver_impl.h index cdc8bd3..0b8ba26 100644 --- a/src/internal/ntux_driver_impl.h +++ b/src/internal/ntux_driver_impl.h @@ -19,6 +19,7 @@ extern const struct argv_option ntux_spawn_options[]; extern const struct argv_option ntux_strace_options[]; extern const struct argv_option ntux_chmod_options[]; extern const struct argv_option ntux_aceit_options[]; +extern const struct argv_option ntux_fspath_options[]; enum app_tags { TAG_HELP, @@ -37,6 +38,11 @@ enum app_tags { TAG_ROOTED, TAG_ROOTLESS, TAG_DUMP, + TAG_SYNTAX, + TAG_RPATH, + TAG_APATH, + TAG_NPATH, + TAG_DPATH, }; struct ntux_driver_ctx_impl { diff --git a/src/skin/ntux_skin_default.c b/src/skin/ntux_skin_default.c index 389321e..b7fabc6 100644 --- a/src/skin/ntux_skin_default.c +++ b/src/skin/ntux_skin_default.c @@ -9,7 +9,7 @@ const struct argv_option ntux_default_options[] = { "show usage information [listing %s options only]"}, {"cmd", 0,TAG_CMD,ARGV_OPTARG_REQUIRED,0, - "stat|spawn|strace|chmod|aceit",0, + "stat|spawn|strace|chmod|aceit|fspath",0, "invoke one of the following ntux commands: %s"}, {0,0,0,0,0,0,0,0} diff --git a/src/skin/ntux_skin_fspath.c b/src/skin/ntux_skin_fspath.c new file mode 100644 index 0000000..001d3c8 --- /dev/null +++ b/src/skin/ntux_skin_fspath.c @@ -0,0 +1,32 @@ +#include "ntux_driver_impl.h" +#include "argv/argv.h" + +const struct argv_option ntux_fspath_options[] = { + {"version", 'v',TAG_VERSION,ARGV_OPTARG_NONE,0,0,0, + "show version information"}, + + {"help", 'h',TAG_HELP,ARGV_OPTARG_OPTIONAL,0,"short|long",0, + "show usage information [listing %s options only]"}, + + {"syntax", 's',TAG_SYNTAX,ARGV_OPTARG_REQUIRED,0, + "relative|absolute|native|driver",0, + "print the path using: " + "root-relative notation (e.g. /bar); " + "root-based absolute notation (e.g. /dev/fs/c/foo/bar); " + "native tool notation (e.g. C:\\foo\\bar); or " + "native driver notation (e.g. \\Device\\Harddisk0\\foo\\bar)"}, + + {"rpath", '\0',TAG_RPATH,ARGV_OPTARG_NONE,0,0,0, + "same as --syntax=relative"}, + + {"apath", '\0',TAG_APATH,ARGV_OPTARG_NONE,0,0,0, + "same as --syntax=absolute"}, + + {"npath", '\0',TAG_NPATH,ARGV_OPTARG_NONE,0,0,0, + "same as --syntax=native"}, + + {"dpath", '\0',TAG_DPATH,ARGV_OPTARG_NONE,0,0,0, + "same as --syntax=driver"}, + + {0,0,0,0,0,0,0,0} +}; |