Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:18

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup rtems_rfs
0007  *
0008  * @brief RTEMS File Systems Trace Support
0009  */
0010 /*
0011  *  COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
0012  *
0013  * Redistribution and use in source and binary forms, with or without
0014  * modification, are permitted provided that the following conditions
0015  * are met:
0016  * 1. Redistributions of source code must retain the above copyright
0017  *    notice, this list of conditions and the following disclaimer.
0018  * 2. Redistributions in binary form must reproduce the above copyright
0019  *    notice, this list of conditions and the following disclaimer in the
0020  *    documentation and/or other materials provided with the distribution.
0021  *
0022  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0023  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0024  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0025  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0026  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0027  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0028  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0029  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0030  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0031  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0032  * POSSIBILITY OF SUCH DAMAGE.
0033  */
0034 
0035 #ifdef HAVE_CONFIG_H
0036 #include "config.h"
0037 #endif
0038 
0039 #include <string.h>
0040 #include <rtems/rfs/rtems-rfs-trace.h>
0041 
0042 #if RTEMS_RFS_TRACE
0043 static rtems_rfs_trace_mask rtems_rfs_trace_flags;
0044 
0045 bool
0046 rtems_rfs_trace (rtems_rfs_trace_mask mask)
0047 {
0048   bool result = false;
0049   if (mask & rtems_rfs_trace_flags)
0050     result = true;
0051   return result;
0052 }
0053 
0054 rtems_rfs_trace_mask
0055 rtems_rfs_trace_set_mask (rtems_rfs_trace_mask mask)
0056 {
0057   rtems_rfs_trace_mask state = rtems_rfs_trace_flags;
0058   rtems_rfs_trace_flags |= mask;
0059   return state;
0060 }
0061 
0062 rtems_rfs_trace_mask
0063 rtems_rfs_trace_clear_mask (rtems_rfs_trace_mask mask)
0064 {
0065   rtems_rfs_trace_mask state = rtems_rfs_trace_flags;
0066   rtems_rfs_trace_flags &= ~mask;
0067   return state;
0068 }
0069 
0070 int
0071 rtems_rfs_trace_shell_command (int argc, char *argv[])
0072 {
0073   const char* table[] =
0074   {
0075     "open",
0076     "close",
0077     "mutex",
0078     "buffer-open",
0079     "buffer-close",
0080     "buffer-sync",
0081     "buffer-release",
0082     "buffer-chains",
0083     "buffer-handle-request",
0084     "buffer-handle-release",
0085     "buffer-setblksize",
0086     "buffers-release",
0087     "block-find",
0088     "block-map-grow",
0089     "block-map-shrink",
0090     "group-open",
0091     "group-close",
0092     "group-bitmaps",
0093     "inode-open",
0094     "inode-close",
0095     "inode-load",
0096     "inode-unload",
0097     "inode-create",
0098     "inode-delete",
0099     "link",
0100     "unlink",
0101     "dir-lookup-ino",
0102     "dir-lookup-ino-check",
0103     "dir-lookup-ino-found",
0104     "dir-add-entry",
0105     "dir-del-entry",
0106     "dir-read",
0107     "dir-empty",
0108     "symlink",
0109     "symlink-read",
0110     "file-open",
0111     "file-close",
0112     "file-io",
0113     "file-set"
0114   };
0115 
0116   rtems_rfs_trace_mask set_value = 0;
0117   rtems_rfs_trace_mask clear_value = 0;
0118   bool                 set = true;
0119   int                  arg;
0120   int                  t;
0121 
0122   for (arg = 1; arg < argc; arg++)
0123   {
0124     if (argv[arg][0] == '-')
0125     {
0126       switch (argv[arg][1])
0127       {
0128         case 'h':
0129           printf ("usage: %s [-hl] [set/clear] [flags]\n", argv[0]);
0130           return 0;
0131         case 'l':
0132           printf ("%s: valid flags to set or clear are:\n", argv[0]);
0133           for (t = 0; t < (sizeof (table) / sizeof (const char*)); t++)
0134             printf ("  %s\n", table[t]);
0135           return 0;
0136         default:
0137           printf ("error: unknown option\n");
0138           return 1;
0139       }
0140     }
0141     else
0142     {
0143       if (strcmp (argv[arg], "set") == 0)
0144         set = true;
0145       if (strcmp (argv[arg], "clear") == 0)
0146         set = false;
0147       else if (strcmp (argv[arg], "all") == 0)
0148       {
0149         if (set)
0150           set_value = RTEMS_RFS_TRACE_ALL;
0151         else
0152           clear_value = RTEMS_RFS_TRACE_ALL;
0153       }
0154       else
0155       {
0156         for (t = 0; t < (sizeof (table) / sizeof (const char*)); t++)
0157         {
0158           if (strcmp (argv[arg], table[t]) == 0)
0159           {
0160             if (set)
0161               set_value = 1ULL << t;
0162             else
0163               clear_value = 1ULL << t;
0164             break;
0165           }
0166         }
0167       }
0168 
0169       rtems_rfs_trace_flags |= set_value;
0170       rtems_rfs_trace_flags &= ~clear_value;
0171     }
0172   }
0173 
0174   return 0;
0175 }
0176 
0177 #endif