[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: showtrans --active
From: |
David Walter |
Subject: |
Re: showtrans --active |
Date: |
Fri, 16 Aug 2002 19:19:07 -0400 |
User-agent: |
Gnus/5.090007 (Oort Gnus v0.07) XEmacs/21.4 (Honest Recruiter, i386-unknown-gnu0.2) |
dwalter@syr.edu (David Walter) writes:
I decided to repost a modestly cleaner patch to showtrans than
previous.
Patch to utils/showtrans.c and utils/Makefile
--- showtrans.c.orig Tue May 28 19:56:34 2002
+++ showtrans.c Sun Aug 11 08:50:12 2002
@@ -26,10 +26,10 @@
#include <unistd.h>
#include <version.h>
#include <sys/mman.h>
-
#include <error.h>
#include <argz.h>
-
+#include <hurd/hurd_types.h>
+#include <hurd/store.h>
const char *argp_program_version = STANDARD_HURD_VERSION (showtrans);
static struct argp_option options[] =
@@ -38,6 +38,8 @@
{"no-prefix", 'P', 0, 0, "Never display `FILENAME: ' before translators"},
{"silent", 's', 0, 0, "No output; useful when checking error status"},
{"quiet", 'q', 0, OPTION_ALIAS | OPTION_HIDDEN},
+ {"active", 'a', 0, 0, "show active translators. Denoted by an * "},
+ {"passive", 'd', 0, 0, "(d)efaults to passive, but allow the user to
force printing both."},
{"translated",'t', 0, 0, "Only display files that have translators"},
{0, 0}
};
@@ -47,7 +49,80 @@
"\vA FILE argument of `-' prints the translator on the node"
" attached to standard input.";
-/* ---------------------------------------------------------------- */
+
+error_t
+get_active_translator_information(const char* path, char**trans, int*trans_len)
+{
+ char *transinfo = NULL;
+ char *toptransinfo = NULL;
+
+ file_t trans_node;
+
+ int transinfolen = 0;
+
+ struct store *storeinfo = NULL;
+
+ char *
+ _hurd_canonicalize_directory_name_internal (file_t thisdir,
+ char *buf,
+ size_t size);
+
+ errno = 0;
+ // step 1. is there an active translator on this path?
+
+ // file_t file = file_name_lookup_carefully (path, 0, 0);
+ ////////////////////////////////////////////////////////////////////////
+ // determine if this is an (actively) translated path or not.
+ ////////////////////////////////////////////////////////////////////////
+ if(strcmp(path, "/") != 0) { // skip if root, special
case for root.
+
+ file_t file = file_name_lookup(path, O_NOTRANS, 0); // get the file w/o
the translator
+ fsys_t fsys;
+
+ error_t active_trans_rc = file_get_translator_cntl(file, &fsys); // get
the active translator if there is one.
+ mach_port_deallocate(mach_task_self(), file);
+ if(active_trans_rc)
+ return EINVAL;
+ }
+ ////////////////////////////////////////////////////////////////////////
+ // The root partition (in particular) needs to use the storeio info
+ ////////////////////////////////////////////////////////////////////////
+ // Others (other translated nodes) require only the information from
+ // the translator.
+ ////////////////////////////////////////////////////////////////////////
+
+ ////////////////////////////////////////////////////////////////////////
+ // it is actively translated, get the information re: the translation
+ ////////////////////////////////////////////////////////////////////////
+
+ trans_node = file_name_lookup(path, 0, 0666);
+ int s_rc = store_create(trans_node, STORE_INACTIVE|STORE_NO_FILEIO, 0,
&storeinfo);
+ int m_rc = mach_port_deallocate(mach_task_self(), trans_node);
+
+
+ trans_node = file_name_lookup(path, 0, 0666);
+
+ int f_rc = file_get_fs_options(trans_node, &toptransinfo, &transinfolen);
+ m_rc = mach_port_deallocate(mach_task_self(), trans_node);
+
+ if (trans_node == MACH_PORT_NULL || f_rc != 0 ){ // || m_rc !=
KERN_SUCCESS){
+ if (toptransinfo != NULL) munmap(toptransinfo,transinfolen);
+ return EINVAL;
+ }
+
+ char* options_start = toptransinfo + strlen(toptransinfo) + 1;
+
+ argz_stringify(toptransinfo, transinfolen, ' ');
+
+ *trans = toptransinfo;
+ *trans_len = transinfolen;
+
+ if (storeinfo)
+ store_free(storeinfo);
+
+
+ return 0;
+}
int
main (int argc, char *argv[])
@@ -57,24 +132,43 @@
/* Some option flags. -1 for PRINT_PREFIX means use the default. */
int print_prefix = -1, silent = 0, show_untrans = 1;
+ boolean_t show_active = FALSE;
+ boolean_t show_passive = FALSE;
/* If NODE is MACH_PORT_NULL, prints an error message and exits, otherwise
prints the translator on NODE, possibly prefixed by `NAME:', and
deallocates NODE. */
void print_node_trans (file_t node, char *name)
{
- if (node == MACH_PORT_NULL)
+ error_t err = 0;
+ typedef mach_port_t fsys_t;
+
+ if (node == MACH_PORT_NULL){
error (0, errno, "%s", name);
- else
- {
+ return;
+ }
+ // Can't get here unless node is okay.
char buf[1024], *trans = buf;
size_t trans_len = sizeof (buf);
- error_t err = file_get_translator (node, &trans, &trans_len);
-
- switch (err)
+ typedef enum REQUEST
{
- case 0:
- /* Make the '\0's in TRANS printable. */
+ passive, /* default */
+ active, /* only */
+ both, /* print two lines if they exist */
+ }
+ REQUEST;
+ REQUEST request = passive;
+ if(show_active && !show_passive)
+ request = active;
+ if(show_active && show_passive)
+ request = both;
+
+ switch(request){
+ case both:
+ case passive:
+ node = file_name_lookup(name, O_NOTRANS, 0); /* get the file w/o
the translator */
+ err = file_get_translator (node, &trans, &trans_len);
argz_stringify (trans, trans_len, ' ');
+ if(!err){
if (!silent)
{
@@ -83,26 +177,57 @@
else
printf ("%.*s\n", (int) trans_len, trans);
}
-
if (trans != buf)
munmap (trans, trans_len);
-
status = 0;
+ }
+ if(request!=both) break;
+ // *NOTICE* fall through if doing both
+ case active:
+ if(strcmp(name, "/") != 0) { // skip if root, special
case for root.
+ file_t file = file_name_lookup(name, O_NOTRANS, 0); /* get the
file w/o the translator */
+ fsys_t fsys;
+
+ error_t no_active_trans = file_get_translator_cntl(file,
&fsys); /* get the active translator if there is one. */
+ mach_port_deallocate(mach_task_self(), file);
+ if(no_active_trans) return;
+ }
- break;
+ /* first try for a non file system? type translator */
+ file_t file = file_name_lookup(name, 0, 0);
+ err = file_get_translator(file, &trans, &trans_len);
+
+ if(err)
+ /* if we get a translator from the node, it was a good
translator */
+ err = file_get_translator (node, &trans, &trans_len);
+
+ /* if we can't then, is this a filesystem? Fall back plan use
storeio. */
+
+ if(err)
+ err = get_active_translator_information(name, &trans,
&trans_len);
+
+ if(!err){
+ argz_stringify (trans, trans_len, ' ');
+ trans[trans_len] = '\0';
+ if (!silent)
+ {
+ if (print_prefix)
+ printf ("*%s: %.*s\n", name, (int) trans_len, trans);
+ else
+ printf ("*%.*s\n", (int) trans_len, trans);
+ }
+ if (trans != buf)
+ munmap (trans, trans_len);
- case EINVAL:
- /* NODE just doesn't have a translator. */
- if (!silent && print_prefix && show_untrans)
- puts (name);
+ status = 0;
+ }
break;
default:
- error (0, err, "%s", name);
+ break;
}
-
mach_port_deallocate (mach_task_self (), node);
- }
+ return;
}
/* Parse a command line option. */
@@ -115,8 +240,9 @@
/* By default, only print a prefix if there are multiple files. */
print_prefix = state->next < state->argc;
- if (strcmp (arg, "-") != 0)
+ if (strcmp (arg, "-") != 0){
print_node_trans (file_name_lookup (arg, O_NOTRANS, 0), arg);
+ }
else
print_node_trans (getdport (0), "-");
break;
@@ -126,7 +252,8 @@
case 'P': print_prefix = 0; break;
case 's': case 'q': silent = 1; break;
case 't': show_untrans = 0; break;
-
+ case 'a': show_active = 1; break;
+ case 'd': show_passive = 1; break;
case ARGP_KEY_NO_ARGS:
argp_usage (state); /* exits */
--- Makefile.orig Sat Aug 10 23:45:41 2002
+++ Makefile Sat Aug 10 23:46:01 2002
@@ -68,6 +68,8 @@
storecat msgport mount: \
../libshouldbeinlibc/libshouldbeinlibc.a
+showtrans: ../libstore/libstore.a
+
$(filter-out $(special-targets), $(targets)): %: %.o
rpctrace: ../libthreads/libthreads.a \
--
/^\
\ / ASCII RIBBON CAMPAIGN
X AGAINST HTML MAIL
/ \
- showtrans --active, David Walter, 2002/08/10
- Re: showtrans --active, Roland McGrath, 2002/08/11
- Re: showtrans --active, Niels Möller, 2002/08/11
- Re: showtrans --active, David Walter,,,, 2002/08/11
- Re: showtrans --active, Marcus Brinkmann, 2002/08/17
- Re: showtrans --active, David Walter, 2002/08/18
- Re: showtrans --active, Niels Möller, 2002/08/20