bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

showtrans --active


From: David Walter
Subject: showtrans --active
Date: Sat, 10 Aug 2002 23:54:36 -0400
User-agent: Gnus/5.090007 (Oort Gnus v0.07) XEmacs/21.4 (Honest Recruiter, i386-unknown-gnu0.2)

While testing  some translator builds I found  that I  often wanted to
know the active translator running on an inode,  without trying to use
ps.

Attached is the  unified diff to  showtrans and the Makefile.


-- 
/^\
\ /     ASCII RIBBON CAMPAIGN
 X        AGAINST HTML MAIL
/ \

--- showtrans.c.orig    Tue May 28 19:56:34 2002
+++ showtrans.c Sat Aug 10 23:31:55 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,17 +38,136 @@
   {"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}
 };
 
+
+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
+  // This may be a special case left over from the boot process.
+  ////////////////////////////////////////////////////////////////////////
+  // 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); // get the file w/o the 
translator 
+/*  fprintf(stderr, "trans_node: %i\nerrno: %i\n", trans_node, errno); */
+ 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); // get the file w/o the 
translator 
+  
+  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, ' ');
+/*   error(0,0, "%s:%i:%s", __FILE__,__LINE__, toptransinfo); */
+  *trans = toptransinfo;
+  *trans_len = transinfolen;
+
+  if (storeinfo)
+    store_free(storeinfo);
+
+
+  return 0;
+////////////////////////////////////////////////////////////////////////
+  // from here not used.
+  char* fsname;
+  if(storeinfo && storeinfo->name)   //  no store information (not active 
mount point?) 
+     fsname = strdup(storeinfo->name);
+  else
+     fsname = strdup(strrchr(strchr(toptransinfo, ',')+1, '/')+1);
+
+  if(!fsname){
+     return ENOMEM;
+  }
+
+  char* type = malloc(transinfolen);
+  memset(type, 0, transinfolen);
+  char* options = malloc(transinfolen);
+  memset(options, 0, transinfolen);
+
+  if(!type || !options){
+    if(type)
+      free(type);
+    if(options)
+      free(options);
+    return ENOMEM;
+  }
+
+  sscanf(options_start, "%s %s", type, options);
+
+  *trans_len = asprintf(trans, "%s %s %s", fsname, type, options);
+/*   error(0,0, "%s:%i:%s", __FILE__,__LINE__, *information); */
+  
+
+  if (storeinfo)
+    store_free(storeinfo);
+
+  if(type)
+    free(type);
+
+  if(options)
+    free(options);
+
+  return 0;
+}
 static char *args_doc = "FILE...";
 static char *doc = "Show the passive translator of FILE..."
 "\vA FILE argument of `-' prints the translator on the node"
 " attached to standard input.";
 
 /* ---------------------------------------------------------------- */
-
+// #error "still bug in the file - /mnt/16 fails.?"
 int
 main (int argc, char *argv[])
 {
@@ -57,24 +176,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 +221,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);
 
-           case EINVAL:
-             /* NODE just doesn't have a translator.  */
-             if (!silent && print_prefix && show_untrans)
-               puts (name);
+            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);
+
+               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 +284,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 +296,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 \




reply via email to

[Prev in Thread] Current Thread [Next in Thread]