Changeset cb4e992 in rtems


Ignore:
Timestamp:
Jan 19, 2010, 7:31:00 PM (12 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 5, master
Children:
2d2dcab2
Parents:
f1eb199a
Message:

2010-01-19 Joel Sherrill <joel.sherrill@…>

  • libfs/src/imfs/imfs.h, libfs/src/imfs/imfs_creat.c, libfs/src/imfs/imfs_initsupp.c, libfs/src/imfs/imfs_link.c, libfs/src/imfs/imfs_load_tar.c, libfs/src/imfs/imfs_mknod.c, libfs/src/imfs/imfs_symlink.c: Create special helper method for creating the j-node for the root directory. This lets us assume that every j-node created otherwise has a parent node.
Location:
cpukit
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • cpukit/ChangeLog

    rf1eb199a rcb4e992  
     12010-01-19      Joel Sherrill <joel.sherrill@oarcorp.com>
     2
     3        * libfs/src/imfs/imfs.h, libfs/src/imfs/imfs_creat.c,
     4        libfs/src/imfs/imfs_initsupp.c, libfs/src/imfs/imfs_link.c,
     5        libfs/src/imfs/imfs_load_tar.c, libfs/src/imfs/imfs_mknod.c,
     6        libfs/src/imfs/imfs_symlink.c: Create special helper method for
     7        creating the j-node for the root directory. This lets us assume that
     8        every j-node created otherwise has a parent node.
     9
    1102010-01-18      Sebastian Huber <sebastian.huber@embedded-brains.de>
    211
  • cpukit/libfs/src/imfs/imfs.h

    rf1eb199a rcb4e992  
    22 *  Header file for the In-Memory File System
    33 *
    4  *  COPYRIGHT (c) 1989-2007.
     4 *  COPYRIGHT (c) 1989-2010.
    55 *  On-Line Applications Research Corporation (OAR).
    66 *
     
    323323);
    324324
    325 
    326325extern int IMFS_link(
    327326  rtems_filesystem_location_info_t  *to_loc,      /* IN */
     
    351350  rtems_filesystem_location_info_t  *pathloc       /* IN/OUT */
    352351);
     352
     353extern IMFS_jnode_t *IMFS_allocate_node(
     354  IMFS_jnode_types_t                type,         /* IN  */
     355  const char                       *name,         /* IN  */
     356  mode_t                            mode          /* IN  */
     357);
     358
     359extern IMFS_jnode_t *IMFS_create_root_node(void);
    353360
    354361extern IMFS_jnode_t *IMFS_create_node(
     
    361368
    362369extern int IMFS_evaluate_for_make(
    363   const char                         *path,        /* IN     */
    364   rtems_filesystem_location_info_t   *pathloc,     /* IN/OUT */
    365   const char                        **name         /* OUT    */
     370  const char                         *path,       /* IN     */
     371  rtems_filesystem_location_info_t   *pathloc,    /* IN/OUT */
     372  const char                        **name        /* OUT    */
    366373);
    367374
  • cpukit/libfs/src/imfs/imfs_creat.c

    rf1eb199a rcb4e992  
    44 *  Routine to create a new in memory file system node.
    55 *
    6  *  COPYRIGHT (c) 1989-1999.
     6 *  COPYRIGHT (c) 1989-2010.
    77 *  On-Line Applications Research Corporation (OAR).
    88 *
     
    2424#include <rtems/libio_.h>
    2525
     26/*
     27 *  Create an IMFS filesystem node of an arbitrary type that is NOT
     28 *  the root directory node.
     29 */
    2630IMFS_jnode_t *IMFS_create_node(
    2731  rtems_filesystem_location_info_t *parent_loc,
     
    3337{
    3438  IMFS_jnode_t        *node;
    35   struct timeval       tv;
    36   IMFS_jnode_t        *parent = NULL;
     39  IMFS_jnode_t        *parent;
    3740  IMFS_fs_info_t      *fs_info;
    3841
    39   if ( parent_loc != NULL )
    40     parent = parent_loc->node_access;
     42  /*
     43   *  MUST have a parent node to call this routine.
     44   */
     45  if ( parent_loc == NULL )
     46    return NULL;
    4147
    4248  /*
    43    *  Allocate an IMFS jnode
     49   *  Allocate filesystem node and fill in basic information
    4450   */
    45 
    46   node = calloc( 1, sizeof( IMFS_jnode_t ) );
     51  node  = IMFS_allocate_node( type, name, mode & ~rtems_filesystem_umask );
    4752  if ( !node )
    4853    return NULL;
    4954
    5055  /*
    51    *  Fill in the basic information
    52    */
    53 
    54   node->st_nlink = 1;
    55   node->type     = type;
    56   strncpy( node->name, name, IMFS_NAME_MAX );
    57 
    58   /*
    59    *  Fill in the mode and permission information for the jnode structure.
    60    */
    61 
    62   node->st_mode = mode & ~rtems_filesystem_umask;
    63 
    64 #if defined(RTEMS_POSIX_API)
    65   node->st_uid = geteuid();
    66   node->st_gid = getegid();
    67 #else
    68   node->st_uid = 0;
    69   node->st_gid = 0;
    70 #endif
    71 
    72   /*
    73    *  Now set all the times.
    74    */
    75 
    76   gettimeofday( &tv, 0 );
    77 
    78   node->stat_atime  = (time_t) tv.tv_sec;
    79   node->stat_mtime  = (time_t) tv.tv_sec;
    80   node->stat_ctime  = (time_t) tv.tv_sec;
    81 
    82   /*
    8356   *  Set the type specific information
    8457   */
    85 
    8658  switch (type) {
    8759    case IMFS_DIRECTORY:
     
    12395
    12496  /*
    125    *  If this node has a parent, then put it in that directory list.
     97   *  This node MUST have a parent, so put it in that directory list.
    12698   */
     99  parent       = parent_loc->node_access;
     100  fs_info      = parent_loc->mt_entry->fs_info;
    127101
    128   if ( parent ) {
    129     rtems_chain_append( &parent->info.directory.Entries, &node->Node );
    130     node->Parent = parent;
     102  node->Parent = parent;
     103  node->st_ino = ++fs_info->ino_count;
    131104
    132     fs_info = parent_loc->mt_entry->fs_info;
    133     node->st_ino = ++fs_info->ino_count;
    134   }
    135 
     105  rtems_chain_append( &parent->info.directory.Entries, &node->Node );
    136106
    137107  return node;
    138108}
     109
     110/*
     111 *  Allocate filesystem node and fill in basic information
     112 */
     113IMFS_jnode_t *IMFS_allocate_node(
     114  IMFS_jnode_types_t                type,
     115  const char                       *name,
     116  mode_t                            mode
     117)
     118{
     119  IMFS_jnode_t        *node;
     120  struct timeval       tv;
     121
     122  /*
     123   *  Allocate an IMFS jnode
     124   */
     125  node = calloc( 1, sizeof( IMFS_jnode_t ) );
     126  if ( !node )
     127    return NULL;
     128
     129  /*
     130   *  Fill in the basic information
     131   */
     132  node->st_nlink = 1;
     133  node->type     = type;
     134  strncpy( node->name, name, IMFS_NAME_MAX );
     135
     136  /*
     137   *  Fill in the mode and permission information for the jnode structure.
     138   */
     139  node->st_mode = mode;
     140  #if defined(RTEMS_POSIX_API)
     141    node->st_uid = geteuid();
     142    node->st_gid = getegid();
     143  #else
     144    node->st_uid = 0;
     145    node->st_gid = 0;
     146  #endif
     147
     148  /*
     149   *  Now set all the times.
     150   */
     151  gettimeofday( &tv, 0 );
     152
     153  node->stat_atime  = (time_t) tv.tv_sec;
     154  node->stat_mtime  = (time_t) tv.tv_sec;
     155  node->stat_ctime  = (time_t) tv.tv_sec;
     156
     157  return node;
     158}
     159
     160IMFS_jnode_t *IMFS_create_root_node(void)
     161{
     162  IMFS_jnode_t        *node;
     163
     164  /*
     165   *  Allocate filesystem node and fill in basic information
     166   */
     167  node = IMFS_allocate_node( IMFS_DIRECTORY, "", (S_IFDIR | 0755) );
     168  if ( !node )
     169    return NULL;
     170
     171  /*
     172   *  Set the type specific information
     173   *
     174   *  NOTE: Root node is always a directory.
     175   */
     176  rtems_chain_initialize_empty(&node->info.directory.Entries);
     177
     178  return node;
     179}
  • cpukit/libfs/src/imfs/imfs_initsupp.c

    rf1eb199a rcb4e992  
    22 *  IMFS Initialization
    33 *
    4  *  COPYRIGHT (c) 1989-1999.
     4 *  COPYRIGHT (c) 1989-2010.
    55 *  On-Line Applications Research Corporation (OAR).
    66 *
     
    4444  bool is_valid = false;
    4545  int bit_mask;
     46
    4647  /*
    4748   * check, whether requested bytes per block is valid
    4849   */
    49   for (bit_mask = 16;
    50        !is_valid && (bit_mask <= 512);
    51        bit_mask <<= 1) {
     50  for (bit_mask = 16; !is_valid && (bit_mask <= 512); bit_mask <<= 1) {
    5251    if (bit_mask == requested_bytes_per_block) {
    5352      is_valid = true;
     
    5857                           : default_bytes_per_block);
    5958  return 0;
    60 
    6159}
    6260
     
    6563 *  IMFS_initialize
    6664 */
    67 
    6865int IMFS_initialize_support(
    6966  rtems_filesystem_mount_table_entry_t        *temp_mt_entry,
     
    8885   *  NOTE: UNIX root is 755 and owned by root/root (0/0).
    8986   */
    90 
    91   temp_mt_entry->mt_fs_root.node_access = IMFS_create_node(
    92     NULL,
    93     IMFS_DIRECTORY,
    94     "",
    95     ( S_IFDIR | 0755 ),
    96     NULL
    97   );
    98 
     87  temp_mt_entry->mt_fs_root.node_access      = IMFS_create_root_node();
    9988  temp_mt_entry->mt_fs_root.handlers         = directory_handlers;
    10089  temp_mt_entry->mt_fs_root.ops              = op_table;
     
    10594   */
    10695  fs_info = calloc( 1, sizeof( IMFS_fs_info_t ) );
    107   if ( !fs_info ){
     96  if ( !fs_info ) {
    10897    free(temp_mt_entry->mt_fs_root.node_access);
    10998    rtems_set_errno_and_return_minus_one(ENOMEM);
  • cpukit/libfs/src/imfs/imfs_link.c

    rf1eb199a rcb4e992  
    3939   *  Verify this node can be linked to.
    4040   */
    41 
    4241  info.hard_link.link_node = to_loc->node_access;
    4342  if ( info.hard_link.link_node->st_nlink >= LINK_MAX )
     
    4746   * Remove any separators at the end of the string.
    4847   */
    49 
    5048  IMFS_get_token( token, strlen( token ), new_name, &i );
    5149
     
    5351   *  Create a new link node.
    5452   *
    55    * NOTE: Coverity thinks this is a resource leak since a node
    56    *       is created but never deleted.  The scope of the allocation
    57    *       is that of a file -- not this method.  Coverity Id 19.
     53   *  NOTE: Coverity Id 19 reports this as a leak
     54   *        While technically not a leak, it indicated that IMFS_create_node
     55   *        was ONLY passed a NULL when we created the root node.  We
     56   *        added a new IMFS_create_root_node() so this path no longer
     57   *        existed.  The result was simpler code which should not have
     58   *        this path.
    5859   */
    59 
    6060  new_node = IMFS_create_node(
    6161    parent_loc,
     
    7272   * Increment the link count of the node being pointed to.
    7373   */
    74 
    7574  info.hard_link.link_node->st_nlink++;
    7675  IMFS_update_ctime( info.hard_link.link_node );
  • cpukit/libfs/src/imfs/imfs_load_tar.c

    rf1eb199a rcb4e992  
    8080 */
    8181int rtems_tarfs_load(
    82   char *mountpoint,
     82  char    *mountpoint,
    8383  uint8_t *tar_image,
    84   size_t tar_size
     84  size_t   tar_size
    8585)
    8686{
    87    rtems_filesystem_location_info_t root_loc;
    88    rtems_filesystem_location_info_t loc;
    89    const char     *hdr_ptr;
    90    char            filename[100];
    91    char            full_filename[256];
    92    int             hdr_chksum;
    93    unsigned char   linkflag;
    94    unsigned long   file_size;
    95    unsigned long   file_mode;
    96    int             offset;
    97    unsigned long   nblocks;
    98    IMFS_jnode_t    *node;
    99    int             status;
     87   rtems_filesystem_location_info_t  root_loc;
     88   rtems_filesystem_location_info_t  loc;
     89   const char                       *hdr_ptr;
     90   char                             filename[100];
     91   char                             full_filename[256];
     92   int                              hdr_chksum;
     93   unsigned char                    linkflag;
     94   unsigned long                    file_size;
     95   unsigned long                    file_mode;
     96   int                              offset;
     97   unsigned long                    nblocks;
     98   IMFS_jnode_t                    *node;
     99   int                              status;
    100100
    101    status = rtems_filesystem_evaluate_path(mountpoint, strlen(mountpoint),
    102                                            0, &root_loc, 0);
     101   status = rtems_filesystem_evaluate_path(
     102      mountpoint,
     103      strlen(mountpoint),
     104      0,
     105      &root_loc,
     106      0
     107   );
    103108   if (status != 0)
    104       return(-1);
     109      return -1;
    105110
    106111   if (root_loc.ops != &IMFS_ops)
     
    112117   offset = 0;
    113118   while (1) {
    114       if (offset + 512 > tar_size)
    115          break;
     119    if (offset + 512 > tar_size)
     120      break;
    116121
    117       /*
    118        * Read a header.
    119        */
    120       hdr_ptr = (char *) &tar_image[offset];
    121       offset += 512;
    122       if (strncmp(&hdr_ptr[257], "ustar  ", 7))
    123          break;
     122    /*
     123     * Read a header.
     124     */
     125    hdr_ptr = (char *) &tar_image[offset];
     126    offset += 512;
     127    if (strncmp(&hdr_ptr[257], "ustar  ", 7))
     128      break;
    124129
    125       strncpy(filename, hdr_ptr, MAX_NAME_FIELD_SIZE);
    126       filename[MAX_NAME_FIELD_SIZE] = '\0';
     130    strncpy(filename, hdr_ptr, MAX_NAME_FIELD_SIZE);
     131    filename[MAX_NAME_FIELD_SIZE] = '\0';
    127132
    128       linkflag   = hdr_ptr[156];
    129       file_mode  = _rtems_octal2ulong(&hdr_ptr[100], 8);
    130       file_size  = _rtems_octal2ulong(&hdr_ptr[124], 12);
    131       hdr_chksum = _rtems_octal2ulong(&hdr_ptr[148], 8);
     133    linkflag   = hdr_ptr[156];
     134    file_mode  = _rtems_octal2ulong(&hdr_ptr[100], 8);
     135    file_size  = _rtems_octal2ulong(&hdr_ptr[124], 12);
     136    hdr_chksum = _rtems_octal2ulong(&hdr_ptr[148], 8);
    132137
    133       if (_rtems_tar_header_checksum(hdr_ptr) != hdr_chksum)
    134          break;
     138    if (_rtems_tar_header_checksum(hdr_ptr) != hdr_chksum)
     139      break;
    135140
    136       /*
    137        * Generate an IMFS node depending on the file type.
    138        * - For directories, just create directories as usual.  IMFS
    139        *   will take care of the rest.
    140        * - For files, create a file node with special tarfs properties.
    141        */
    142       if (linkflag == DIRTYPE) {
    143          strcpy(full_filename, mountpoint);
    144          if (full_filename[strlen(full_filename)-1] != '/')
    145             strcat(full_filename, "/");
    146          strcat(full_filename, filename);
    147          mkdir(full_filename, S_IRWXU | S_IRWXG | S_IRWXO);
     141    /*
     142     * Generate an IMFS node depending on the file type.
     143     * - For directories, just create directories as usual.  IMFS
     144     *   will take care of the rest.
     145     * - For files, create a file node with special tarfs properties.
     146     */
     147    if (linkflag == DIRTYPE) {
     148      strcpy(full_filename, mountpoint);
     149      if (full_filename[strlen(full_filename)-1] != '/')
     150        strcat(full_filename, "/");
     151      strcat(full_filename, filename);
     152      mkdir(full_filename, S_IRWXU | S_IRWXG | S_IRWXO);
     153    }
     154    /*
     155     * Create a LINEAR_FILE node
     156     *
     157     *  NOTE: Coverity Id 20 reports this as a leak.
     158     *        While technically not a leak, it indicated that
     159     *        IMFS_create_node was ONLY passed a NULL when we created the
     160     *        root node.  We added a new IMFS_create_root_node() so this
     161     *        path no longer existed.  The result was simpler code which
     162     *        should not have this path.
     163     */
     164    else if (linkflag == REGTYPE) {
     165      const char  *name;
     166
     167      loc = root_loc;
     168      if (IMFS_evaluate_for_make(filename, &loc, &name) == 0) {
     169        node = IMFS_create_node(
     170          &loc,
     171          IMFS_LINEAR_FILE, (char *)name,
     172          (file_mode & (S_IRWXU | S_IRWXG | S_IRWXO)) | S_IFREG,
     173          NULL
     174        );
     175        node->info.linearfile.size   = file_size;
     176        node->info.linearfile.direct = &tar_image[offset];
    148177      }
    149       /*
    150        * Create a LINEAR_FILE node
    151        *
    152        * NOTE: Coverity thinks this is a resource leak since a node
    153        *       is created but never deleted.  The scope of the allocation
    154        *       is that of a file -- not this method.  Coverity Id 20.
    155        */
    156       else if (linkflag == REGTYPE) {
    157          const char  *name;
    158178
    159          loc = root_loc;
    160          if (IMFS_evaluate_for_make(filename, &loc, &name) == 0) {
    161             node = IMFS_create_node(&loc,
    162                         IMFS_LINEAR_FILE, (char *)name,
    163                         (file_mode & (S_IRWXU | S_IRWXG | S_IRWXO)) | S_IFREG,
    164                         NULL);
    165             node->info.linearfile.size   = file_size;
    166             node->info.linearfile.direct = &tar_image[offset];
    167          }
    168 
    169          nblocks = (((file_size) + 511) & ~511) / 512;
    170          offset += 512 * nblocks;
    171       }
    172    }
    173 
    174    return status;
     179      nblocks = (((file_size) + 511) & ~511) / 512;
     180      offset += 512 * nblocks;
     181    }
     182  }
     183  return status;
    175184}
    176185
  • cpukit/libfs/src/imfs/imfs_mknod.c

    rf1eb199a rcb4e992  
    4747   *  Figure out what type of IMFS node this is.
    4848   */
    49 
    5049  if ( S_ISDIR(mode) )
    5150    type = IMFS_DIRECTORY;
     
    6564   *  Allocate and fill in an IMFS jnode
    6665   *
    67    * NOTE: Coverity thinks this is a resource leak since a node
    68    *       is created but never deleted.  The scope of the allocation
    69    *       is that of a file -- not this method.  Coverity Id 21.
     66   *  NOTE: Coverity Id 21 reports this as a leak.
     67   *        While technically not a leak, it indicated that IMFS_create_node
     68   *        was ONLY passed a NULL when we created the root node.  We
     69   *        added a new IMFS_create_root_node() so this path no longer
     70   *        existed.  The result was simpler code which should not have
     71   *        this path.
    7072   */
    7173  new_node = IMFS_create_node(
  • cpukit/libfs/src/imfs/imfs_symlink.c

    rf1eb199a rcb4e992  
    4141   * Remove any separators at the end of the string.
    4242   */
    43 
    4443  IMFS_get_token( node_name, strlen( node_name ), new_name, &i );
    4544
     
    4746   * Duplicate link name
    4847   */
    49 
    5048  info.sym_link.name = strdup(link_name);
    5149  if (info.sym_link.name == NULL) {
     
    5654   *  Create a new link node.
    5755   *
    58    *  NOTE: Coverity CID 22 notes this as a resource leak.  We are ignoring
    59    *        this analysis because in this particular case it is wrong. This
    60    *        method creates a symbolic link node for the IMFS.  The memory
    61    *        allocated must persist for the life of the symbolic link not
    62    *        the life of the method.
     56   *  NOTE: Coverity CID 22 notes this as a resource leak.
     57   *        While technically not a leak, it indicated that IMFS_create_node
     58   *        was ONLY passed a NULL when we created the root node.  We
     59   *        added a new IMFS_create_root_node() so this path no longer
     60   *        existed.  The result was simpler code which should not have
     61   *        this path.
    6362   */
    64 
    6563  new_node = IMFS_create_node(
    6664    parent_loc,
Note: See TracChangeset for help on using the changeset viewer.