"Fossies" - the Fresh Open Source Software Archive

Member "coda-6.9.5/coda-src/norton/commands.cc" (17 Dec 2007, 6680 Bytes) of package /linux/misc/old/coda-6.9.5.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "commands.cc" see the Fossies "Dox" file reference documentation.

    1 /* BLURB gpl
    2 
    3                            Coda File System
    4                               Release 6
    5 
    6           Copyright (c) 1987-2003 Carnegie Mellon University
    7                   Additional copyrights listed below
    8 
    9 This  code  is  distributed "AS IS" without warranty of any kind under
   10 the terms of the GNU General Public Licence Version 2, as shown in the
   11 file  LICENSE.  The  technical and financial  contributors to Coda are
   12 listed in the file CREDITS.
   13 
   14                         Additional copyrights
   15                            none currently
   16 
   17 #*/
   18 
   19 
   20 
   21 #ifdef __cplusplus
   22 extern "C" {
   23 #endif
   24 
   25 #ifdef HAVE_CONFIG_H
   26 #include <config.h>
   27 #endif
   28 
   29 #include <sys/param.h>
   30 #include <stdio.h>
   31 #include <stdlib.h>
   32 #include "coda_string.h"
   33 
   34 #if defined(__APPLE__) && defined(__MACH__)
   35 #include <mach/mach.h>
   36 #endif
   37 
   38 #ifdef __cplusplus
   39 }
   40 #endif
   41 
   42 #include <parser.h>
   43 #include "norton.h"
   44 
   45 command_t del_commands[] = {
   46 //    { "directory",    notyet,     0,  ""},
   47 //    { "inode",        notyet,     0,  ""},
   48     { "name",       delete_name,        0,  ""},
   49 //    { "vnode",        notyet,     0,  ""},
   50     { "volume",     sh_delete_volume,   0,  ""},
   51     { 0, 0, 0, ""}
   52 };
   53 
   54 command_t create_commands[] = {
   55     { "name",       sh_create_name,     0,  ""},
   56     { 0, 0, 0, ""}
   57 };
   58 
   59 command_t salvage_commands[] = {
   60     { "all",        notyet,     0,  ""},
   61     { "directory",  notyet,     0,  ""},
   62     { "inode",      notyet,     0,  ""},
   63     { "resolution", notyet,     0,  ""},
   64     { "vnode",      notyet,     0,  ""},
   65     { "volume",     notyet,     0,  ""},
   66     { 0, 0, 0, ""}
   67 };
   68 
   69 command_t show_cmds[] = {
   70     { "debug",      show_debug, 0,  ""},
   71     { "directory",  show_dir,   0,  ""},
   72     { "free",       show_free,  0,  ""},
   73     { "heap",       show_heap,  0,  ""},
   74     { "index",      show_index, 0,  ""},
   75 //    { "inode",        notyet,     0,  ""},
   76     { "vnode",      show_vnode, 0,  ""},
   77     { "volume",     show_volume,    0,  ""},
   78     { "volumedetails",  show_volume_details,    0,  ""},
   79     { 0, 0, 0, ""}
   80 };
   81 
   82 command_t list_cmds[] = {
   83     { "volumes",    list_vols,  0,  ""},
   84     { 0, 0, 0, ""}
   85 };
   86 
   87 command_t rename_cmds[] = {
   88     { "volume",     sh_rename_volume,   0,  "Rename volume (args: vol newname"},
   89     { 0, 0, 0, ""}
   90 };
   91 
   92 command_t set_cmds[] = {
   93     { "linkcount",  set_linkcount,  0,  "Set linkcount in vnode (args: vol vnode uniq count)"},
   94     { "debug",  set_debug,  0,  "Set debug level (args: level)"},
   95     { 0, 0, 0, ""}
   96 };
   97 
   98 
   99 command_t commands[] = {
  100     { "?",      Parser_qhelp,   0,        ""},
  101     { "delete",     0,      del_commands,     ""},
  102     { "create",     0,      create_commands,  ""},
  103     { "examine",    examine,    0,        ""},
  104     { "exit",       Parser_exit,    0,        ""},
  105     { "help",       Parser_qhelp,   0,        ""},
  106     { "list",       list_vols,  list_cmds,    ""},
  107     { "quit",       Parser_exit,    0,        ""},
  108     { "rename",     0,      rename_cmds,      ""},
  109 //  { "salvage",    0,      salvage_commands, ""},
  110     { "show",       0,      show_cmds,    ""},
  111     { "set",        0,      set_cmds,     ""},
  112 //  { "truncate",   notyet,     0,        ""},
  113     { "x",      examine,    0,        ""},
  114     { 0, 0, 0, ""}
  115 };
  116 
  117 void InitParsing() {
  118     Parser_init("norton> ", &commands[0]);
  119 }
  120 
  121 void notyet(int argc, char *argv[]) {
  122     char buf[80];
  123     int  i;
  124 
  125     buf[0] = '\0';
  126     for (i = 0; i < argc; i++) {
  127     strcat(buf, argv[i]);
  128     strcat(buf, " ");
  129     }
  130     fprintf(stderr, "'%s' has not been implemented yet.\n", buf);
  131 }
  132 
  133 
  134 #ifdef __MACH__
  135 #ifdef __APPLE__
  136 static long address_ok(vm_address_t addr, vm_size_t size, vm_prot_t perm)
  137 {
  138     kern_return_t  rc;
  139     struct vm_region_basic_info info;
  140     mach_msg_type_number_t infoCnt;
  141     vm_address_t current, end;
  142     mach_port_t object_name;
  143 
  144     infoCnt = VM_REGION_BASIC_INFO_COUNT;
  145 
  146     current = addr;
  147     end = addr + size;
  148     while (current < end) {
  149         rc = vm_region(mach_task_self(), &current, &size, VM_REGION_BASIC_INFO, (vm_region_info_t)&info, &infoCnt, &object_name);
  150         if (rc != KERN_SUCCESS)
  151             return 0;
  152 
  153         if ((info.protection & perm) != perm)
  154             return 0;
  155 
  156         current += size;
  157     }
  158     return 1;
  159 }
  160 #else
  161 static
  162 long address_ok(vm_address_t addr, vm_size_t sz, vm_prot_t perm)
  163 {
  164     vm_address_t    address = addr;
  165     vm_size_t       size;
  166     vm_prot_t       protection;
  167     vm_prot_t       max_protection;
  168     vm_inherit_t    inheritance;
  169     boolean_t       shared;
  170     port_t          object_name;
  171     vm_offset_t     offset;
  172 
  173     while(vm_region(task_self(), &address, &size,
  174             &protection, &max_protection,
  175             &inheritance, &shared,
  176             &object_name, &offset) == KERN_SUCCESS) {
  177     if (address > addr) return(0);
  178     if ((protection & perm) != perm) return(0);
  179     if (address + size >= addr + sz) return(1);
  180     sz = (addr + sz) - (address + size);
  181     addr = address += size;
  182     if (size == 0) break;
  183     }
  184     return(1);
  185 }
  186 #endif /* !__APPLE__ */
  187 #endif /* __MACH__ */
  188 
  189 #if    defined  (__linux__) || defined(__CYGWIN32__) || defined(sun)
  190 #include <sys/mman.h>
  191 #define vm_address_t caddr_t
  192 #define vm_size_t    size_t
  193 #define vm_prot_t    int
  194 #define VM_PROT_READ PROT_READ
  195 static
  196 long address_ok(vm_address_t addr, vm_size_t sz, vm_prot_t perm)
  197 {
  198   return mprotect(addr, sz, perm);
  199 }
  200 #endif
  201 
  202 #if defined(BSD4_4) && !defined(__APPLE__)
  203 #include <sys/mman.h>
  204 #define vm_address_t caddr_t
  205 #define vm_size_t    size_t
  206 #define vm_prot_t    int
  207 #define VM_PROT_READ PROT_READ
  208 static
  209 long address_ok(vm_address_t addr, vm_size_t sz, vm_prot_t perm)
  210 {
  211   fprintf(stderr, "Someone needs to write code for address_ok.\n");
  212   return 1;
  213 }
  214 #endif
  215 
  216 #define BYTES_PER_LINE  16
  217 void examine(int argc, char *argv[])
  218 {
  219     intptr_t baseaddr;
  220     unsigned int *base, *addr;
  221     char *buf;
  222     unsigned int len, i;
  223 
  224     if ((argc != 3) ||
  225     (Parser_uint(argv[1], (unsigned int *)&baseaddr) != 1) ||
  226     (Parser_uint(argv[2], &len) != 1)) {
  227     fprintf(stderr, "Usage: examine <addr> <len>\n");
  228     return;
  229     }
  230     base = (unsigned int *)baseaddr;
  231 
  232     for (addr = base; addr < base + len; addr += BYTES_PER_LINE/sizeof(int))
  233     {
  234     if (!address_ok((vm_address_t)addr,
  235             (vm_size_t)BYTES_PER_LINE/(int)sizeof(int),
  236             VM_PROT_READ))
  237     {
  238         printf("ERROR reading address: %p\n", addr);
  239         break;
  240     }
  241 
  242     printf("%p: ", addr);
  243     for (i = 0; i < BYTES_PER_LINE/sizeof(int); i++) {
  244         printf("  %04x", *(addr + i));
  245     }
  246 
  247     printf("  |");
  248     for (buf = (char *)addr; buf - (char *)addr < BYTES_PER_LINE; buf++) {
  249         if ((*buf >= (char )32 && *buf <= (char)126) || *buf >= (char)161)
  250         printf("%c", *buf);
  251         else
  252         printf(".");
  253     }
  254     printf("|\n");
  255     }
  256 }
  257 
  258 
  259 void set_debug(int argc, char *argv[])
  260 {
  261     unsigned int debug_level;
  262 
  263     if ((argc != 3) ||
  264     (Parser_uint(argv[2], &debug_level) != 1)) {
  265     fprintf(stderr, "Usage: set debug <debug_level>\n");
  266     return;
  267     }
  268 
  269     norton_debug = debug_level;
  270     printf("Debug level set to: %u\n", norton_debug);
  271 }
  272 
  273 void show_debug(int argc, char *argv[]) {
  274     printf("Debug level: %u\n", norton_debug);
  275 }
  276 
  277