summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--include/ntux/ntux.h7
-rw-r--r--project/common.mk2
-rw-r--r--project/extras.mk3
-rw-r--r--src/cmds/ntux_cmd_fspath.c91
-rw-r--r--src/driver/ntux_amain.c3
-rw-r--r--src/driver/ntux_driver_ctx.c48
-rw-r--r--src/internal/ntux_driver_impl.h6
-rw-r--r--src/skin/ntux_skin_default.c2
-rw-r--r--src/skin/ntux_skin_fspath.c32
9 files changed, 193 insertions, 1 deletions
diff --git a/include/ntux/ntux.h b/include/ntux/ntux.h
index 3bd5d83..c7b0078 100644
--- a/include/ntux/ntux.h
+++ b/include/ntux/ntux.h
@@ -41,6 +41,11 @@ extern "C" {
#define NTUX_DRIVER_DUMP 0x1000
+#define NTUX_DRIVER_RPATH 0X10000
+#define NTUX_DRIVER_APATH 0X20000
+#define NTUX_DRIVER_NPATH 0X40000
+#define NTUX_DRIVER_DPATH 0X80000
+
#define NTUX_DRIVER_ANNOTATE_ALWAYS 0x10000000
#define NTUX_DRIVER_ANNOTATE_NEVER 0x20000000
#define NTUX_DRIVER_ANNOTATE_FULL 0x40000000
@@ -66,6 +71,7 @@ enum ntux_cmd {
NTUX_CMD_STRACE,
NTUX_CMD_CHMOD,
NTUX_CMD_ACEIT,
+ NTUX_CMD_FSPATH,
NTUX_CMD_CAP,
};
@@ -143,6 +149,7 @@ ntux_api int ntux_set_driver_fdctx (struct ntux_driver_ctx *, const struct
/* cmd api */
ntux_api int ntux_cmd_aceit (const struct ntux_driver_ctx *, const char *);
ntux_api int ntux_cmd_chmod (const struct ntux_driver_ctx *, const char *);
+ntux_api int ntux_cmd_fspath (const struct ntux_driver_ctx *, const char *);
ntux_api int ntux_cmd_stat (const struct ntux_driver_ctx *, const char *);
ntux_api int ntux_cmd_spawn (const struct ntux_driver_ctx *);
ntux_api int ntux_cmd_strace (const struct ntux_driver_ctx *);
diff --git a/project/common.mk b/project/common.mk
index 77a504a..e99c8e0 100644
--- a/project/common.mk
+++ b/project/common.mk
@@ -9,6 +9,7 @@ DRIVER_SRCS = \
src/skin/ntux_skin_aceit.c \
src/skin/ntux_skin_chmod.c \
src/skin/ntux_skin_default.c \
+ src/skin/ntux_skin_fspath.c \
src/skin/ntux_skin_spawn.c \
src/skin/ntux_skin_strace.c \
@@ -24,6 +25,7 @@ INTERNAL_SRCS = \
CMD_SRCS = \
src/cmds/ntux_cmd_aceit.c \
src/cmds/ntux_cmd_chmod.c \
+ src/cmds/ntux_cmd_fspath.c \
src/cmds/ntux_cmd_spawn.c \
src/cmds/ntux_cmd_stat.c \
src/cmds/ntux_cmd_strace.c \
diff --git a/project/extras.mk b/project/extras.mk
index 15a36c9..2d65b57 100644
--- a/project/extras.mk
+++ b/project/extras.mk
@@ -31,15 +31,18 @@ install-app-extras:
rm -f bin/$(NICKNAME).spawn$(OS_APP_SUFFIX).tmp
rm -f bin/$(NICKNAME).strace$(OS_APP_SUFFIX).tmp
rm -f bin/$(NICKNAME).aceit$(OS_APP_SUFFIX).tmp
+ rm -f bin/$(NICKNAME).fspath$(OS_APP_SUFFIX).tmp
ln -s $(NICKNAME)$(OS_APP_SUFFIX) bin/$(NICKNAME).stat$(OS_APP_SUFFIX).tmp
ln -s $(NICKNAME)$(OS_APP_SUFFIX) bin/$(NICKNAME).chmod$(OS_APP_SUFFIX).tmp
ln -s $(NICKNAME)$(OS_APP_SUFFIX) bin/$(NICKNAME).spawn$(OS_APP_SUFFIX).tmp
ln -s $(NICKNAME)$(OS_APP_SUFFIX) bin/$(NICKNAME).strace$(OS_APP_SUFFIX).tmp
ln -s $(NICKNAME)$(OS_APP_SUFFIX) bin/$(NICKNAME).aceit$(OS_APP_SUFFIX).tmp
+ ln -s $(NICKNAME)$(OS_APP_SUFFIX) bin/$(NICKNAME).fspath$(OS_APP_SUFFIX).tmp
mv bin/$(NICKNAME).stat$(OS_APP_SUFFIX).tmp $(DESTDIR)$(BINDIR)/$(NICKNAME).stat$(OS_APP_SUFFIX)
mv bin/$(NICKNAME).chmod$(OS_APP_SUFFIX).tmp $(DESTDIR)$(BINDIR)/$(NICKNAME).chmod$(OS_APP_SUFFIX)
mv bin/$(NICKNAME).spawn$(OS_APP_SUFFIX).tmp $(DESTDIR)$(BINDIR)/$(NICKNAME).spawn$(OS_APP_SUFFIX)
mv bin/$(NICKNAME).strace$(OS_APP_SUFFIX).tmp $(DESTDIR)$(BINDIR)/$(NICKNAME).strace$(OS_APP_SUFFIX)
mv bin/$(NICKNAME).aceit$(OS_APP_SUFFIX).tmp $(DESTDIR)$(BINDIR)/$(NICKNAME).aceit$(OS_APP_SUFFIX)
+ mv bin/$(NICKNAME).fspath$(OS_APP_SUFFIX).tmp $(DESTDIR)$(BINDIR)/$(NICKNAME).fspath$(OS_APP_SUFFIX)
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}
+};