Changeset d1941587 in rtems


Ignore:
Timestamp:
01/12/01 13:44:12 (23 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
3f777d0e
Parents:
5c27c80
Message:

2001-01-12 Jake Janovetz <janovetz@…>

  • src/imfs/imfs.h, src/imfs/imfs_creat.c, src/imfs/imfs_debug.c, src/imfs/imfs_eval.c, src/imfs/imfs_fchmod.c, src/imfs/imfs_handlers_memfile.c, src/imfs/imfs_init.c, src/imfs/imfs_initsupp.c, src/imfs/imfs_stat.c, src/imfs/memfile.c, src/imfs/miniimfs_init.c: Final developmental update to "tarfs". When rtems_tarfs_load() is called, it checks the permissions on each file. If there is write permission, it just creates a standard file using "creat()" and therefore, uses the IMFS MEMORY_FILE. If there is no write permission, it creates a LINEAR_FILE node with the appropriate properties. If the permission is ever changed to writeable, IMFS_fchmod converts it to a regular memory file.
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • c/src/exec/libfs/ChangeLog

    r5c27c80 rd1941587  
     12001-01-12      Jake Janovetz <janovetz@uiuc.edu>
     2
     3        * src/imfs/imfs.h, src/imfs/imfs_creat.c, src/imfs/imfs_debug.c,
     4        src/imfs/imfs_eval.c, src/imfs/imfs_fchmod.c,
     5        src/imfs/imfs_handlers_memfile.c, src/imfs/imfs_init.c,
     6        src/imfs/imfs_initsupp.c, src/imfs/imfs_stat.c, src/imfs/memfile.c,
     7        src/imfs/miniimfs_init.c: Final developmental update to "tarfs".
     8        When rtems_tarfs_load() is called, it checks the permissions
     9        on each file.  If there is write permission, it just creates a
     10        standard file using "creat()" and therefore, uses the IMFS MEMORY_FILE.
     11        If there is no write permission, it creates a LINEAR_FILE node
     12        with the appropriate properties.  If the permission is ever changed
     13        to writeable, IMFS_fchmod converts it to a regular memory file.
     14
    1152000-12-12      Jake Janovetz <janovetz@uiuc.edu>
    216
  • c/src/exec/libfs/src/imfs/imfs.h

    r5c27c80 rd1941587  
    131131#define IMFS_SYM_LINK      RTEMS_FILESYSTEM_SYM_LINK
    132132#define IMFS_MEMORY_FILE   RTEMS_FILESYSTEM_MEMORY_FILE
    133 #define IMFS_LINEAR_FILE   (RTEMS_FILESYSTEM_MEMORY_FILE + 1)
     133#define IMFS_LINEAR_FILE   (IMFS_MEMORY_FILE + 1)
    134134
    135135#define IMFS_NUMBER_OF_TYPES  (IMFS_LINEAR_FILE + 1)
     
    265265);
    266266
    267 int rtems_tarfs_mount(
     267int rtems_tarfs_load(
    268268   char          *mountpoint,
    269269   unsigned char *addr,
  • c/src/exec/libfs/src/imfs/imfs_fchmod.c

    r5c27c80 rd1941587  
    4545    set_errno_and_return_minus_one( EPERM );
    4646
     47  /*
     48   * If we make a linear-file writeable, construct a block file
     49   * from it first.
     50   */
     51  if ( (jnode->type == IMFS_LINEAR_FILE) &&
     52       (mode & (S_IWUSR | S_IWGRP | S_IWOTH)) )
     53  {
     54    unsigned32 count = jnode->info.linearfile.size;
     55    const unsigned char *buffer = jnode->info.linearfile.direct;
     56
     57    jnode->type = IMFS_MEMORY_FILE;
     58    jnode->info.file.size            = 0;
     59    jnode->info.file.indirect        = 0;
     60    jnode->info.file.doubly_indirect = 0;
     61    jnode->info.file.triply_indirect = 0;
     62    if (IMFS_memfile_write(jnode, 0, buffer, count) == -1)
     63       return(-1);
     64  }
     65
    4766  jnode->st_mode &= ~(S_IRWXU | S_IRWXG | S_IRWXO);
    4867  jnode->st_mode |= mode;
  • c/src/exec/libfs/src/imfs/imfs_handlers_memfile.c

    r5c27c80 rd1941587  
    2323  memfile_open,
    2424  memfile_close,
    25   linearfile_read,
     25  memfile_read,
    2626  NULL,                /* write */
    2727  memfile_ioctl,
    28   linearfile_lseek,
     28  memfile_lseek,
    2929  IMFS_stat,
    30   NULL,                /* chmod */
     30  IMFS_fchmod,
    3131  NULL,                /* ftruncate */
    3232  NULL,                /* fpathconf */
     
    3434  IMFS_fdatasync,
    3535  IMFS_fcntl,
    36   NULL                 /* rmnod */
     36  memfile_rmnod
    3737};
    3838
  • c/src/exec/libfs/src/imfs/imfs_load_tar.c

    r5c27c80 rd1941587  
    55 * File entries are created as IMFS_LINEAR_FILE nodes with their nods
    66 * pointing to addresses in the TAR image.
    7  *
    8  *  $Id$
    9  *
    107 *************************************************************************/
    118
    129#include <rtems.h>
    13 #include <rtems/libio.h>
     10#include <rtems/libio_.h>
    1411#include <string.h>
    1512#include <chain.h>
     
    111108
    112109/**************************************************************************
    113  * rtems_tarfs_mount
     110 * rtems_tarfs_load
    114111 *
    115  * Here we create the mountpoint directory and mount the tarfs at
     112 * Here we create the mountpoint directory and load the tarfs at
    116113 * that node.  Once the IMFS has been mounted, we work through the
    117114 * tar image and perform as follows:
     
    122119 *************************************************************************/
    123120int
    124 rtems_tarfs_mount(char *mountpoint,
    125                   unsigned char *tar_image,
    126                   unsigned long tar_size)
     121rtems_tarfs_load(char *mountpoint,
     122                 unsigned char *tar_image,
     123                 unsigned long tar_size)
    127124{
    128125   rtems_filesystem_location_info_t root_loc;
     
    134131   unsigned char   linkflag;
    135132   unsigned long   file_size;
     133   unsigned long   file_mode;
    136134   int             offset;
    137135   unsigned long   nblocks;
     
    142140   status = rtems_filesystem_evaluate_path(mountpoint, 0, &root_loc, 0);
    143141   if (status != 0)
     142      return(-1);
     143
     144   if (root_loc.ops != &IMFS_ops)
    144145      return(-1);
    145146
     
    165166
    166167      linkflag   = hdr_ptr[156];
     168      file_mode  = octal2ulong(&hdr_ptr[100], 8);
    167169      file_size  = octal2ulong(&hdr_ptr[124], 12);
    168 
    169170      hdr_chksum = (int)octal2ulong(&hdr_ptr[148], 8);
     171
    170172      if (compute_tar_header_checksum(hdr_ptr) != hdr_chksum)
    171173         break;
     
    180182      {
    181183         strcpy(full_filename, mountpoint);
    182          strcat(full_filename, "/");
     184         if (full_filename[strlen(full_filename)-1] != '/')
     185            strcat(full_filename, "/");
    183186         strcat(full_filename, filename);
    184187         mkdir(full_filename, S_IRWXU | S_IRWXG | S_IRWXO);
    185188      }
    186       else if (linkflag == LF_NORMAL)
     189      /******************************************************************
     190       * Create a LINEAR_FILE node if no user write permission.
     191       *****************************************************************/
     192      else if ((linkflag == LF_NORMAL) &&
     193               ((file_mode & 0200) == 0000))
    187194      {
    188195         const char  *name;
    189 
    190196
    191197         loc = root_loc;
     
    203209         offset += 512 * nblocks;
    204210      }
     211      /******************************************************************
     212       * Create a regular MEMORY_FILE if write permission exists.
     213       *****************************************************************/
     214      else if ((linkflag == LF_NORMAL) &&
     215               ((file_mode & 0200) == 0200))
     216      {
     217         int fd;
     218         int n, left, ptr;
     219
     220         strcpy(full_filename, mountpoint);
     221         if (full_filename[strlen(full_filename)-1] != '/')
     222            strcat(full_filename, "/");
     223         strcat(full_filename, filename);
     224
     225         fd = creat(full_filename, S_IRUSR|S_IWUSR | S_IRGRP|S_IWGRP);
     226         if (fd != -1)
     227         {
     228            left = file_size;
     229            ptr  = offset;
     230            while ((n = write(fd, &tar_image[ptr], left)) > 0)
     231            {
     232               left -= n;
     233               ptr += n;
     234            }
     235            close(fd);
     236         }
     237
     238         nblocks = (((file_size) + 511) & ~511) / 512;
     239         offset += 512 * nblocks;
     240      }
    205241   }
    206242
  • c/src/exec/libfs/src/imfs/memfile.c

    r5c27c80 rd1941587  
    198198  the_jnode = iop->file_info;
    199199
    200   if (IMFS_memfile_extend( the_jnode, iop->offset ))
    201     set_errno_and_return_minus_one( ENOSPC );
    202 
    203   iop->size = the_jnode->info.file.size;
     200  if (the_jnode->type == IMFS_LINEAR_FILE) {
     201    if (iop->offset > the_jnode->info.linearfile.size)
     202      iop->offset = the_jnode->info.linearfile.size;
     203  }
     204  else {  /* Must be a block file (IMFS_MEMORY_FILE). */
     205    if (IMFS_memfile_extend( the_jnode, iop->offset ))
     206      set_errno_and_return_minus_one( ENOSPC );
     207
     208    iop->size = the_jnode->info.file.size;
     209  }
    204210  return iop->offset;
    205211}
     
    500506    for ( i=0 ; i<IMFS_MEMFILE_BLOCK_SLOTS ; i++ ) {
    501507      p = (block_p *) info->triply_indirect[i];
    502       if (!p)  /* ensure we have a valid pointer */
    503         break;
    504508      for ( j=0 ; j<IMFS_MEMFILE_BLOCK_SLOTS ; j++ ) {
    505509        if ( p[j] ) {
     
    555559    set_errno_and_return_minus_one( EIO );
    556560
    557   assert( the_jnode->type == IMFS_MEMORY_FILE );
    558   if ( the_jnode->type != IMFS_MEMORY_FILE )
     561  assert( the_jnode->type == IMFS_MEMORY_FILE ||
     562          the_jnode->type == IMFS_LINEAR_FILE );
     563  if ( the_jnode->type != IMFS_MEMORY_FILE &&
     564       the_jnode->type != IMFS_LINEAR_FILE )
    559565    set_errno_and_return_minus_one( EIO );
    560566
     
    574580  if ( !my_length )
    575581    set_errno_and_return_minus_one( EINVAL );
     582
     583  /*
     584   *  Linear files (as created from a tar file are easier to handle
     585   *  than block files).
     586   */
     587  if (the_jnode->type == IMFS_LINEAR_FILE) {
     588    unsigned char  *file_ptr;
     589
     590    file_ptr = (unsigned char *)the_jnode->info.linearfile.direct;
     591
     592    if (my_length > (the_jnode->info.linearfile.size - start))
     593      my_length = the_jnode->info.linearfile.size - start;
     594
     595    memcpy(dest, &file_ptr[start], my_length);
     596
     597    IMFS_update_atime( the_jnode );
     598
     599    return my_length;
     600  }
    576601
    577602  /*
     
    10911116     * Free memory associated with a memory file.
    10921117     */
    1093 
    1094     IMFS_memfile_remove( the_jnode );
     1118    if (the_jnode->type != IMFS_LINEAR_FILE)
     1119      IMFS_memfile_remove( the_jnode );
    10951120
    10961121    free( the_jnode );
  • c/src/libfs/ChangeLog

    r5c27c80 rd1941587  
     12001-01-12      Jake Janovetz <janovetz@uiuc.edu>
     2
     3        * src/imfs/imfs.h, src/imfs/imfs_creat.c, src/imfs/imfs_debug.c,
     4        src/imfs/imfs_eval.c, src/imfs/imfs_fchmod.c,
     5        src/imfs/imfs_handlers_memfile.c, src/imfs/imfs_init.c,
     6        src/imfs/imfs_initsupp.c, src/imfs/imfs_stat.c, src/imfs/memfile.c,
     7        src/imfs/miniimfs_init.c: Final developmental update to "tarfs".
     8        When rtems_tarfs_load() is called, it checks the permissions
     9        on each file.  If there is write permission, it just creates a
     10        standard file using "creat()" and therefore, uses the IMFS MEMORY_FILE.
     11        If there is no write permission, it creates a LINEAR_FILE node
     12        with the appropriate properties.  If the permission is ever changed
     13        to writeable, IMFS_fchmod converts it to a regular memory file.
     14
    1152000-12-12      Jake Janovetz <janovetz@uiuc.edu>
    216
  • c/src/libfs/src/imfs/imfs.h

    r5c27c80 rd1941587  
    131131#define IMFS_SYM_LINK      RTEMS_FILESYSTEM_SYM_LINK
    132132#define IMFS_MEMORY_FILE   RTEMS_FILESYSTEM_MEMORY_FILE
    133 #define IMFS_LINEAR_FILE   (RTEMS_FILESYSTEM_MEMORY_FILE + 1)
     133#define IMFS_LINEAR_FILE   (IMFS_MEMORY_FILE + 1)
    134134
    135135#define IMFS_NUMBER_OF_TYPES  (IMFS_LINEAR_FILE + 1)
     
    265265);
    266266
    267 int rtems_tarfs_mount(
     267int rtems_tarfs_load(
    268268   char          *mountpoint,
    269269   unsigned char *addr,
  • c/src/libfs/src/imfs/imfs_fchmod.c

    r5c27c80 rd1941587  
    4545    set_errno_and_return_minus_one( EPERM );
    4646
     47  /*
     48   * If we make a linear-file writeable, construct a block file
     49   * from it first.
     50   */
     51  if ( (jnode->type == IMFS_LINEAR_FILE) &&
     52       (mode & (S_IWUSR | S_IWGRP | S_IWOTH)) )
     53  {
     54    unsigned32 count = jnode->info.linearfile.size;
     55    const unsigned char *buffer = jnode->info.linearfile.direct;
     56
     57    jnode->type = IMFS_MEMORY_FILE;
     58    jnode->info.file.size            = 0;
     59    jnode->info.file.indirect        = 0;
     60    jnode->info.file.doubly_indirect = 0;
     61    jnode->info.file.triply_indirect = 0;
     62    if (IMFS_memfile_write(jnode, 0, buffer, count) == -1)
     63       return(-1);
     64  }
     65
    4766  jnode->st_mode &= ~(S_IRWXU | S_IRWXG | S_IRWXO);
    4867  jnode->st_mode |= mode;
  • c/src/libfs/src/imfs/imfs_handlers_memfile.c

    r5c27c80 rd1941587  
    2323  memfile_open,
    2424  memfile_close,
    25   linearfile_read,
     25  memfile_read,
    2626  NULL,                /* write */
    2727  memfile_ioctl,
    28   linearfile_lseek,
     28  memfile_lseek,
    2929  IMFS_stat,
    30   NULL,                /* chmod */
     30  IMFS_fchmod,
    3131  NULL,                /* ftruncate */
    3232  NULL,                /* fpathconf */
     
    3434  IMFS_fdatasync,
    3535  IMFS_fcntl,
    36   NULL                 /* rmnod */
     36  memfile_rmnod
    3737};
    3838
  • c/src/libfs/src/imfs/imfs_load_tar.c

    r5c27c80 rd1941587  
    55 * File entries are created as IMFS_LINEAR_FILE nodes with their nods
    66 * pointing to addresses in the TAR image.
    7  *
    8  *  $Id$
    9  *
    107 *************************************************************************/
    118
    129#include <rtems.h>
    13 #include <rtems/libio.h>
     10#include <rtems/libio_.h>
    1411#include <string.h>
    1512#include <chain.h>
     
    111108
    112109/**************************************************************************
    113  * rtems_tarfs_mount
     110 * rtems_tarfs_load
    114111 *
    115  * Here we create the mountpoint directory and mount the tarfs at
     112 * Here we create the mountpoint directory and load the tarfs at
    116113 * that node.  Once the IMFS has been mounted, we work through the
    117114 * tar image and perform as follows:
     
    122119 *************************************************************************/
    123120int
    124 rtems_tarfs_mount(char *mountpoint,
    125                   unsigned char *tar_image,
    126                   unsigned long tar_size)
     121rtems_tarfs_load(char *mountpoint,
     122                 unsigned char *tar_image,
     123                 unsigned long tar_size)
    127124{
    128125   rtems_filesystem_location_info_t root_loc;
     
    134131   unsigned char   linkflag;
    135132   unsigned long   file_size;
     133   unsigned long   file_mode;
    136134   int             offset;
    137135   unsigned long   nblocks;
     
    142140   status = rtems_filesystem_evaluate_path(mountpoint, 0, &root_loc, 0);
    143141   if (status != 0)
     142      return(-1);
     143
     144   if (root_loc.ops != &IMFS_ops)
    144145      return(-1);
    145146
     
    165166
    166167      linkflag   = hdr_ptr[156];
     168      file_mode  = octal2ulong(&hdr_ptr[100], 8);
    167169      file_size  = octal2ulong(&hdr_ptr[124], 12);
    168 
    169170      hdr_chksum = (int)octal2ulong(&hdr_ptr[148], 8);
     171
    170172      if (compute_tar_header_checksum(hdr_ptr) != hdr_chksum)
    171173         break;
     
    180182      {
    181183         strcpy(full_filename, mountpoint);
    182          strcat(full_filename, "/");
     184         if (full_filename[strlen(full_filename)-1] != '/')
     185            strcat(full_filename, "/");
    183186         strcat(full_filename, filename);
    184187         mkdir(full_filename, S_IRWXU | S_IRWXG | S_IRWXO);
    185188      }
    186       else if (linkflag == LF_NORMAL)
     189      /******************************************************************
     190       * Create a LINEAR_FILE node if no user write permission.
     191       *****************************************************************/
     192      else if ((linkflag == LF_NORMAL) &&
     193               ((file_mode & 0200) == 0000))
    187194      {
    188195         const char  *name;
    189 
    190196
    191197         loc = root_loc;
     
    203209         offset += 512 * nblocks;
    204210      }
     211      /******************************************************************
     212       * Create a regular MEMORY_FILE if write permission exists.
     213       *****************************************************************/
     214      else if ((linkflag == LF_NORMAL) &&
     215               ((file_mode & 0200) == 0200))
     216      {
     217         int fd;
     218         int n, left, ptr;
     219
     220         strcpy(full_filename, mountpoint);
     221         if (full_filename[strlen(full_filename)-1] != '/')
     222            strcat(full_filename, "/");
     223         strcat(full_filename, filename);
     224
     225         fd = creat(full_filename, S_IRUSR|S_IWUSR | S_IRGRP|S_IWGRP);
     226         if (fd != -1)
     227         {
     228            left = file_size;
     229            ptr  = offset;
     230            while ((n = write(fd, &tar_image[ptr], left)) > 0)
     231            {
     232               left -= n;
     233               ptr += n;
     234            }
     235            close(fd);
     236         }
     237
     238         nblocks = (((file_size) + 511) & ~511) / 512;
     239         offset += 512 * nblocks;
     240      }
    205241   }
    206242
  • c/src/libfs/src/imfs/memfile.c

    r5c27c80 rd1941587  
    198198  the_jnode = iop->file_info;
    199199
    200   if (IMFS_memfile_extend( the_jnode, iop->offset ))
    201     set_errno_and_return_minus_one( ENOSPC );
    202 
    203   iop->size = the_jnode->info.file.size;
     200  if (the_jnode->type == IMFS_LINEAR_FILE) {
     201    if (iop->offset > the_jnode->info.linearfile.size)
     202      iop->offset = the_jnode->info.linearfile.size;
     203  }
     204  else {  /* Must be a block file (IMFS_MEMORY_FILE). */
     205    if (IMFS_memfile_extend( the_jnode, iop->offset ))
     206      set_errno_and_return_minus_one( ENOSPC );
     207
     208    iop->size = the_jnode->info.file.size;
     209  }
    204210  return iop->offset;
    205211}
     
    500506    for ( i=0 ; i<IMFS_MEMFILE_BLOCK_SLOTS ; i++ ) {
    501507      p = (block_p *) info->triply_indirect[i];
    502       if (!p)  /* ensure we have a valid pointer */
    503         break;
    504508      for ( j=0 ; j<IMFS_MEMFILE_BLOCK_SLOTS ; j++ ) {
    505509        if ( p[j] ) {
     
    555559    set_errno_and_return_minus_one( EIO );
    556560
    557   assert( the_jnode->type == IMFS_MEMORY_FILE );
    558   if ( the_jnode->type != IMFS_MEMORY_FILE )
     561  assert( the_jnode->type == IMFS_MEMORY_FILE ||
     562          the_jnode->type == IMFS_LINEAR_FILE );
     563  if ( the_jnode->type != IMFS_MEMORY_FILE &&
     564       the_jnode->type != IMFS_LINEAR_FILE )
    559565    set_errno_and_return_minus_one( EIO );
    560566
     
    574580  if ( !my_length )
    575581    set_errno_and_return_minus_one( EINVAL );
     582
     583  /*
     584   *  Linear files (as created from a tar file are easier to handle
     585   *  than block files).
     586   */
     587  if (the_jnode->type == IMFS_LINEAR_FILE) {
     588    unsigned char  *file_ptr;
     589
     590    file_ptr = (unsigned char *)the_jnode->info.linearfile.direct;
     591
     592    if (my_length > (the_jnode->info.linearfile.size - start))
     593      my_length = the_jnode->info.linearfile.size - start;
     594
     595    memcpy(dest, &file_ptr[start], my_length);
     596
     597    IMFS_update_atime( the_jnode );
     598
     599    return my_length;
     600  }
    576601
    577602  /*
     
    10911116     * Free memory associated with a memory file.
    10921117     */
    1093 
    1094     IMFS_memfile_remove( the_jnode );
     1118    if (the_jnode->type != IMFS_LINEAR_FILE)
     1119      IMFS_memfile_remove( the_jnode );
    10951120
    10961121    free( the_jnode );
  • cpukit/libfs/ChangeLog

    r5c27c80 rd1941587  
     12001-01-12      Jake Janovetz <janovetz@uiuc.edu>
     2
     3        * src/imfs/imfs.h, src/imfs/imfs_creat.c, src/imfs/imfs_debug.c,
     4        src/imfs/imfs_eval.c, src/imfs/imfs_fchmod.c,
     5        src/imfs/imfs_handlers_memfile.c, src/imfs/imfs_init.c,
     6        src/imfs/imfs_initsupp.c, src/imfs/imfs_stat.c, src/imfs/memfile.c,
     7        src/imfs/miniimfs_init.c: Final developmental update to "tarfs".
     8        When rtems_tarfs_load() is called, it checks the permissions
     9        on each file.  If there is write permission, it just creates a
     10        standard file using "creat()" and therefore, uses the IMFS MEMORY_FILE.
     11        If there is no write permission, it creates a LINEAR_FILE node
     12        with the appropriate properties.  If the permission is ever changed
     13        to writeable, IMFS_fchmod converts it to a regular memory file.
     14
    1152000-12-12      Jake Janovetz <janovetz@uiuc.edu>
    216
  • cpukit/libfs/src/imfs/imfs.h

    r5c27c80 rd1941587  
    131131#define IMFS_SYM_LINK      RTEMS_FILESYSTEM_SYM_LINK
    132132#define IMFS_MEMORY_FILE   RTEMS_FILESYSTEM_MEMORY_FILE
    133 #define IMFS_LINEAR_FILE   (RTEMS_FILESYSTEM_MEMORY_FILE + 1)
     133#define IMFS_LINEAR_FILE   (IMFS_MEMORY_FILE + 1)
    134134
    135135#define IMFS_NUMBER_OF_TYPES  (IMFS_LINEAR_FILE + 1)
     
    265265);
    266266
    267 int rtems_tarfs_mount(
     267int rtems_tarfs_load(
    268268   char          *mountpoint,
    269269   unsigned char *addr,
  • cpukit/libfs/src/imfs/imfs_fchmod.c

    r5c27c80 rd1941587  
    4545    set_errno_and_return_minus_one( EPERM );
    4646
     47  /*
     48   * If we make a linear-file writeable, construct a block file
     49   * from it first.
     50   */
     51  if ( (jnode->type == IMFS_LINEAR_FILE) &&
     52       (mode & (S_IWUSR | S_IWGRP | S_IWOTH)) )
     53  {
     54    unsigned32 count = jnode->info.linearfile.size;
     55    const unsigned char *buffer = jnode->info.linearfile.direct;
     56
     57    jnode->type = IMFS_MEMORY_FILE;
     58    jnode->info.file.size            = 0;
     59    jnode->info.file.indirect        = 0;
     60    jnode->info.file.doubly_indirect = 0;
     61    jnode->info.file.triply_indirect = 0;
     62    if (IMFS_memfile_write(jnode, 0, buffer, count) == -1)
     63       return(-1);
     64  }
     65
    4766  jnode->st_mode &= ~(S_IRWXU | S_IRWXG | S_IRWXO);
    4867  jnode->st_mode |= mode;
  • cpukit/libfs/src/imfs/imfs_handlers_memfile.c

    r5c27c80 rd1941587  
    2323  memfile_open,
    2424  memfile_close,
    25   linearfile_read,
     25  memfile_read,
    2626  NULL,                /* write */
    2727  memfile_ioctl,
    28   linearfile_lseek,
     28  memfile_lseek,
    2929  IMFS_stat,
    30   NULL,                /* chmod */
     30  IMFS_fchmod,
    3131  NULL,                /* ftruncate */
    3232  NULL,                /* fpathconf */
     
    3434  IMFS_fdatasync,
    3535  IMFS_fcntl,
    36   NULL                 /* rmnod */
     36  memfile_rmnod
    3737};
    3838
  • cpukit/libfs/src/imfs/imfs_load_tar.c

    r5c27c80 rd1941587  
    55 * File entries are created as IMFS_LINEAR_FILE nodes with their nods
    66 * pointing to addresses in the TAR image.
    7  *
    8  *  $Id$
    9  *
    107 *************************************************************************/
    118
    129#include <rtems.h>
    13 #include <rtems/libio.h>
     10#include <rtems/libio_.h>
    1411#include <string.h>
    1512#include <chain.h>
     
    111108
    112109/**************************************************************************
    113  * rtems_tarfs_mount
     110 * rtems_tarfs_load
    114111 *
    115  * Here we create the mountpoint directory and mount the tarfs at
     112 * Here we create the mountpoint directory and load the tarfs at
    116113 * that node.  Once the IMFS has been mounted, we work through the
    117114 * tar image and perform as follows:
     
    122119 *************************************************************************/
    123120int
    124 rtems_tarfs_mount(char *mountpoint,
    125                   unsigned char *tar_image,
    126                   unsigned long tar_size)
     121rtems_tarfs_load(char *mountpoint,
     122                 unsigned char *tar_image,
     123                 unsigned long tar_size)
    127124{
    128125   rtems_filesystem_location_info_t root_loc;
     
    134131   unsigned char   linkflag;
    135132   unsigned long   file_size;
     133   unsigned long   file_mode;
    136134   int             offset;
    137135   unsigned long   nblocks;
     
    142140   status = rtems_filesystem_evaluate_path(mountpoint, 0, &root_loc, 0);
    143141   if (status != 0)
     142      return(-1);
     143
     144   if (root_loc.ops != &IMFS_ops)
    144145      return(-1);
    145146
     
    165166
    166167      linkflag   = hdr_ptr[156];
     168      file_mode  = octal2ulong(&hdr_ptr[100], 8);
    167169      file_size  = octal2ulong(&hdr_ptr[124], 12);
    168 
    169170      hdr_chksum = (int)octal2ulong(&hdr_ptr[148], 8);
     171
    170172      if (compute_tar_header_checksum(hdr_ptr) != hdr_chksum)
    171173         break;
     
    180182      {
    181183         strcpy(full_filename, mountpoint);
    182          strcat(full_filename, "/");
     184         if (full_filename[strlen(full_filename)-1] != '/')
     185            strcat(full_filename, "/");
    183186         strcat(full_filename, filename);
    184187         mkdir(full_filename, S_IRWXU | S_IRWXG | S_IRWXO);
    185188      }
    186       else if (linkflag == LF_NORMAL)
     189      /******************************************************************
     190       * Create a LINEAR_FILE node if no user write permission.
     191       *****************************************************************/
     192      else if ((linkflag == LF_NORMAL) &&
     193               ((file_mode & 0200) == 0000))
    187194      {
    188195         const char  *name;
    189 
    190196
    191197         loc = root_loc;
     
    203209         offset += 512 * nblocks;
    204210      }
     211      /******************************************************************
     212       * Create a regular MEMORY_FILE if write permission exists.
     213       *****************************************************************/
     214      else if ((linkflag == LF_NORMAL) &&
     215               ((file_mode & 0200) == 0200))
     216      {
     217         int fd;
     218         int n, left, ptr;
     219
     220         strcpy(full_filename, mountpoint);
     221         if (full_filename[strlen(full_filename)-1] != '/')
     222            strcat(full_filename, "/");
     223         strcat(full_filename, filename);
     224
     225         fd = creat(full_filename, S_IRUSR|S_IWUSR | S_IRGRP|S_IWGRP);
     226         if (fd != -1)
     227         {
     228            left = file_size;
     229            ptr  = offset;
     230            while ((n = write(fd, &tar_image[ptr], left)) > 0)
     231            {
     232               left -= n;
     233               ptr += n;
     234            }
     235            close(fd);
     236         }
     237
     238         nblocks = (((file_size) + 511) & ~511) / 512;
     239         offset += 512 * nblocks;
     240      }
    205241   }
    206242
  • cpukit/libfs/src/imfs/memfile.c

    r5c27c80 rd1941587  
    198198  the_jnode = iop->file_info;
    199199
    200   if (IMFS_memfile_extend( the_jnode, iop->offset ))
    201     set_errno_and_return_minus_one( ENOSPC );
    202 
    203   iop->size = the_jnode->info.file.size;
     200  if (the_jnode->type == IMFS_LINEAR_FILE) {
     201    if (iop->offset > the_jnode->info.linearfile.size)
     202      iop->offset = the_jnode->info.linearfile.size;
     203  }
     204  else {  /* Must be a block file (IMFS_MEMORY_FILE). */
     205    if (IMFS_memfile_extend( the_jnode, iop->offset ))
     206      set_errno_and_return_minus_one( ENOSPC );
     207
     208    iop->size = the_jnode->info.file.size;
     209  }
    204210  return iop->offset;
    205211}
     
    500506    for ( i=0 ; i<IMFS_MEMFILE_BLOCK_SLOTS ; i++ ) {
    501507      p = (block_p *) info->triply_indirect[i];
    502       if (!p)  /* ensure we have a valid pointer */
    503         break;
    504508      for ( j=0 ; j<IMFS_MEMFILE_BLOCK_SLOTS ; j++ ) {
    505509        if ( p[j] ) {
     
    555559    set_errno_and_return_minus_one( EIO );
    556560
    557   assert( the_jnode->type == IMFS_MEMORY_FILE );
    558   if ( the_jnode->type != IMFS_MEMORY_FILE )
     561  assert( the_jnode->type == IMFS_MEMORY_FILE ||
     562          the_jnode->type == IMFS_LINEAR_FILE );
     563  if ( the_jnode->type != IMFS_MEMORY_FILE &&
     564       the_jnode->type != IMFS_LINEAR_FILE )
    559565    set_errno_and_return_minus_one( EIO );
    560566
     
    574580  if ( !my_length )
    575581    set_errno_and_return_minus_one( EINVAL );
     582
     583  /*
     584   *  Linear files (as created from a tar file are easier to handle
     585   *  than block files).
     586   */
     587  if (the_jnode->type == IMFS_LINEAR_FILE) {
     588    unsigned char  *file_ptr;
     589
     590    file_ptr = (unsigned char *)the_jnode->info.linearfile.direct;
     591
     592    if (my_length > (the_jnode->info.linearfile.size - start))
     593      my_length = the_jnode->info.linearfile.size - start;
     594
     595    memcpy(dest, &file_ptr[start], my_length);
     596
     597    IMFS_update_atime( the_jnode );
     598
     599    return my_length;
     600  }
    576601
    577602  /*
     
    10911116     * Free memory associated with a memory file.
    10921117     */
    1093 
    1094     IMFS_memfile_remove( the_jnode );
     1118    if (the_jnode->type != IMFS_LINEAR_FILE)
     1119      IMFS_memfile_remove( the_jnode );
    10951120
    10961121    free( the_jnode );
Note: See TracChangeset for help on using the changeset viewer.