Changeset a43a3466 in rtems


Ignore:
Timestamp:
Feb 15, 2015, 9:38:15 AM (5 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
c34f94f7
Parents:
f785492
git-author:
Sebastian Huber <sebastian.huber@…> (02/15/15 09:38:15)
git-committer:
Sebastian Huber <sebastian.huber@…> (02/15/15 10:26:39)
Message:

IMFS: Implement variable length node names

This reduces the average node size and adds more flexibility.

Files:
6 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libfs/src/imfs/imfs.h

    rf785492 ra43a3466  
    231231 */
    232232
    233 #define IMFS_NAME_MAX  32
     233#define IMFS_NAME_MAX _POSIX_NAME_MAX
    234234
    235235/*
     236
    236237 *  The control structure for an IMFS jnode.
    237238 */
     
    240241  rtems_chain_node    Node;                  /* for chaining them together */
    241242  IMFS_jnode_t       *Parent;                /* Parent node */
    242   char                name[IMFS_NAME_MAX+1]; /* "basename" */
     243  const char         *name;                  /* "basename" (not \0 terminated) */
     244  uint16_t            namelen;               /* Length of "basename" */
     245  uint16_t            flags;                 /* Node flags */
    243246  mode_t              st_mode;               /* File mode */
    244247  unsigned short      reference_count;
     
    253256  const IMFS_node_control *control;
    254257};
     258
     259#define IMFS_NODE_FLAG_NAME_ALLOCATED 0x1
    255260
    256261typedef struct {
  • cpukit/libfs/src/imfs/imfs_creat.c

    rf785492 ra43a3466  
    3636  IMFS_jnode_t *node;
    3737
    38   allocated_node = calloc( 1, node_size );
     38  allocated_node = calloc( 1, node_size + namelen );
    3939  if ( allocated_node == NULL ) {
    4040    errno = ENOMEM;
     
    4646    allocated_node,
    4747    node_control,
    48     name,
     48    (char *) allocated_node + node_size,
    4949    namelen,
    5050    mode,
     
    5353  if ( node != NULL ) {
    5454    IMFS_jnode_t *parent = parentloc->node_access;
     55
     56    memcpy( node->name, name, namelen );
    5557
    5658    /*
  • cpukit/libfs/src/imfs/imfs_eval.c

    rf785492 ra43a3466  
    5656      while ( current != tail ) {
    5757        IMFS_jnode_t *entry = (IMFS_jnode_t *) current;
    58         bool match = strncmp( entry->name, token, tokenlen ) == 0
    59           && entry->name [tokenlen] == '\0';
     58        bool match = entry->namelen == tokenlen
     59          && memcmp( entry->name, token, tokenlen ) == 0;
    6060
    6161        if ( match ) {
  • cpukit/libfs/src/imfs/imfs_initsupp.c

    rf785492 ra43a3466  
    7979   *  Fill in the basic information
    8080   */
     81  node->name = name;
     82  node->namelen = namelen;
    8183  node->reference_count = 1;
    8284  node->st_nlink = 1;
    83   memcpy( node->name, name, namelen );
    84   node->name [namelen] = '\0';
    8585  node->control = node_control;
    8686
     
    193193void IMFS_node_destroy_default( IMFS_jnode_t *node )
    194194{
     195  if ( ( node->flags & IMFS_NODE_FLAG_NAME_ALLOCATED ) != 0 ) {
     196    free( node->name );
     197  }
     198
    195199  free( node );
    196200}
  • cpukit/libfs/src/imfs/imfs_rename.c

    rf785492 ra43a3466  
    3131)
    3232{
    33   int rv = 0;
    3433  IMFS_jnode_t *node = oldloc->node_access;
    3534  IMFS_jnode_t *new_parent = newparentloc->node_access;
     35  char *allocated_name;
    3636
    3737  /*
     
    4040   */
    4141
    42   if ( node->Parent != NULL ) {
    43     if ( namelen < IMFS_NAME_MAX ) {
    44       memcpy( node->name, name, namelen );
    45       node->name [namelen] = '\0';
    46 
    47       IMFS_remove_from_directory( node );
    48       IMFS_add_to_directory( new_parent, node );
    49       IMFS_update_ctime( node );
    50     } else {
    51       errno = ENAMETOOLONG;
    52       rv = -1;
    53     }
    54   } else {
    55     errno = EINVAL;
    56     rv = -1;
     42  if ( node->Parent == NULL ) {
     43    rtems_set_errno_and_return_minus_one( EINVAL );
    5744  }
    5845
    59   return rv;
     46  if ( namelen >= IMFS_NAME_MAX ) {
     47    rtems_set_errno_and_return_minus_one( ENAMETOOLONG );
     48  }
     49
     50  allocated_name = malloc( namelen );
     51  if ( allocated_name == NULL ) {
     52    rtems_set_errno_and_return_minus_one( ENOMEM );
     53  }
     54
     55  memcpy( allocated_name, name, namelen );
     56
     57  if ( ( node->flags & IMFS_NODE_FLAG_NAME_ALLOCATED ) != 0 ) {
     58    free( node->name );
     59  }
     60
     61  node->name = allocated_name;
     62  node->namelen = namelen;
     63  node->flags |= IMFS_NODE_FLAG_NAME_ALLOCATED;
     64
     65  IMFS_remove_from_directory( node );
     66  IMFS_add_to_directory( new_parent, node );
     67  IMFS_update_ctime( node );
     68
     69  return 0;
    6070}
  • testsuites/psxtests/psxstat/test.c

    rf785492 ra43a3466  
    172172
    173173char *Bad_paths[] = {
    174   "/my_mount_point/links/ENAMETOOLONG__________________________",
     174  "/my_mount_point/links/ENAMETOOLONG________________________________________"
     175  "__________________________________________________________________________"
     176  "__________________________________________________________________________"
     177  "__________________________________________________________________________"
     178  "______________________________________",
    175179  "/my_mount_point/dir1/file4/NOTADIR",
    176180  "/my_mount_point/dir1/dir1/EACCES__",
Note: See TracChangeset for help on using the changeset viewer.