Changeset 05d8495 in rtems


Ignore:
Timestamp:
Jul 26, 2015, 12:56:50 PM (4 years ago)
Author:
Michael Davidsaver <mdavidsaver@…>
Branches:
4.10
Children:
aecb5086
Parents:
4bcbd8d6
git-author:
Michael Davidsaver <mdavidsaver@…> (07/26/15 12:56:50)
git-committer:
Sebastian Huber <sebastian.huber@…> (01/26/17 06:41:38)
Message:

tftpDriver: backport fixes

ensure that node_access is comparable in unmount()

Update #2375.

Location:
cpukit/libnetworking
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libnetworking/lib/tftpDriver.c

    r4bcbd8d6 r05d8495  
    204204 
    205205  mt_entry->fs_info = fs;
    206   mt_entry->mt_fs_root->location.node_access = root_path;
    207   mt_entry->mt_fs_root->location.handlers = &rtems_tftp_handlers;
    208   mt_entry->ops = &rtems_tftp_ops;
     206  mt_entry->mt_fs_root.node_access = root_path;
     207  mt_entry->mt_fs_root.node_access_2 = root_path;
     208  mt_entry->mt_fs_root.handlers = &rtems_tftp_handlers;
     209  mt_entry->mt_fs_root.ops = &rtems_tftp_ops;
    209210 
    210211  /*
     
    265266}
    266267
    267 static void
     268static int
    268269rtems_tftpfs_shutdown (rtems_filesystem_mount_table_entry_t* mt_entry)
    269270{
     
    274275  rtems_semaphore_delete (fs->tftp_mutex);
    275276  free (fs);
    276   free (mt_entry->mt_fs_root->location.node_access);
     277  free (mt_entry->mt_fs_root.node_access);
     278  return 0;
    277279}
    278280
     
    427429        return errno;
    428430    return 0;
     431}
     432
     433static int rtems_tftp_evaluate_for_make(
     434   const char                         *path __attribute__((unused)),       /* IN     */
     435   rtems_filesystem_location_info_t   *pathloc,    /* IN/OUT */
     436   const char                        **name __attribute__((unused))        /* OUT    */
     437)
     438{
     439  pathloc->node_access = NULL;
     440  pathloc->node_access_2 = NULL;
     441  rtems_set_errno_and_return_minus_one (EIO);
    429442}
    430443
     
    483496}
    484497
    485 static void rtems_tftp_eval_path(rtems_filesystem_eval_path_context_t *self)
    486 {
    487     int eval_flags = rtems_filesystem_eval_path_get_flags (self);
    488 
    489     if ((eval_flags & RTEMS_FS_MAKE) == 0) {
    490         int rw = RTEMS_FS_PERMS_READ | RTEMS_FS_PERMS_WRITE;
    491 
    492         if ((eval_flags & rw) != rw) {
    493             rtems_filesystem_location_info_t *currentloc =
    494                 rtems_filesystem_eval_path_get_currentloc (self);
    495             char *current = currentloc->node_access;
    496             size_t currentlen = strlen (current);
    497             const char *path = rtems_filesystem_eval_path_get_path (self);
    498             size_t pathlen = rtems_filesystem_eval_path_get_pathlen (self);
    499             size_t len = currentlen + pathlen;
    500 
    501             rtems_filesystem_eval_path_clear_path (self);
    502 
    503             current = realloc (current, len + 1);
    504             if (current != NULL) {
    505                 memcpy (current + currentlen, path, pathlen);
    506                 current [len] = '\0';
    507                 if (!rtems_tftp_is_directory (current, len)) {
    508                     fixPath (current);
     498static int rtems_tftp_eval_path(
     499  const char                        *pathname,     /* IN     */
     500  size_t                             pathnamelen,  /* IN     */
     501  int                                flags,        /* IN     */
     502  rtems_filesystem_location_info_t  *pathloc       /* IN/OUT */
     503)
     504{
     505    const int rw = RTEMS_LIBIO_PERMS_READ | RTEMS_LIBIO_PERMS_WRITE;
     506
     507    if ((flags & rw) != rw) {
     508        rtems_filesystem_location_info_t *currentloc = pathloc;
     509        char *current = currentloc->node_access;
     510        size_t currentlen = strlen (current);
     511        const char *path = pathname;
     512        size_t pathlen = pathnamelen;
     513        size_t len = currentlen + pathlen;
     514
     515        current = realloc (current, len + 1);
     516        if (current != NULL) {
     517            memcpy (current + currentlen, path, pathlen);
     518            current [len] = '\0';
     519            if (!rtems_tftp_is_directory (current, len)) {
     520                fixPath (current);
     521                currentloc->node_access = current;
     522                currentloc->node_access_2 = current;
     523            } else {
     524                /* this directory might be the FS root,
     525                 * and unmount() compares the pointer
     526                 */
     527                if (strcmp(current, currentloc->mt_entry->mt_fs_root.node_access)==0) {
     528                    free(current);
     529                    currentloc->node_access = currentloc->mt_entry->mt_fs_root.node_access;
     530                    currentloc->node_access_2 = NULL;
     531                } else {
     532                    currentloc->node_access = current;
     533                    currentloc->node_access_2 = current;
    509534                }
    510                 currentloc->node_access = current;
    511             } else {
    512                 rtems_filesystem_eval_path_error (self, ENOMEM);
    513535            }
     536            return 0;
    514537        } else {
    515             rtems_filesystem_eval_path_error (self, EINVAL);
     538            rtems_set_errno_and_return_minus_one (ENOMEM);
    516539        }
    517540    } else {
    518         rtems_filesystem_eval_path_error (self, EIO);
     541        rtems_set_errno_and_return_minus_one (EINVAL);
    519542    }
    520543}
     
    526549    rtems_libio_t *iop,
    527550    char          *full_path_name,
    528     int            oflag
     551    uint32_t       flags,
     552    uint32_t       mode __attribute__((unused))
    529553)
    530554{
     
    573597            return ENOENT;
    574598        memcpy (&farAddress, he->h_addr, sizeof (farAddress));
     599    } else {
     600        return ENOENT; /* TODO, can remove? */
    575601    }
    576602   
     
    654680
    655681    if (fs->flags & TFTPFS_VERBOSE) {
    656         printf("TFTPFS: %d %s %s from %08lx\n", flags,
     682        printf("TFTPFS: %d %s %s from %08lx\n", (unsigned)flags,
    657683               ((flags & O_ACCMODE) == O_RDONLY)?"read":"write",
    658684               remoteFilename, ntohl(farAddress.s_addr));
     
    667693         * Create the request
    668694         */
    669         if ((oflag & O_ACCMODE) == O_RDONLY) {
     695        if ((flags & O_ACCMODE) == O_RDONLY) {
    670696            tp->writing = 0;
    671697            tp->pkbuf.tftpRWRQ.opcode = htons (TFTP_OPCODE_RRQ);
     
    741767    rtems_libio_t *iop,
    742768    const char    *new_name,
    743     int            oflag,
    744     mode_t         mode
     769    uint32_t      oflag,
     770    uint32_t      mode
    745771)
    746772{
     
    763789      printf ("TFTPFS: %s\n", full_path_name);
    764790
    765     err = rtems_tftp_open_worker (iop, full_path_name, oflag);
     791    err = rtems_tftp_open_worker (iop, full_path_name, oflag, mode);
    766792    if (err != 0) {
    767793       rtems_set_errno_and_return_minus_one (err);
     
    9851011}
    9861012
     1013static rtems_filesystem_node_types_t rtems_tftp_node_type(
     1014     rtems_filesystem_location_info_t        *pathloc                 /* IN */
     1015)
     1016{
     1017    const char * path = pathloc->node_access;
     1018    if (!rtems_tftp_is_directory(path, strlen(path)))
     1019        return RTEMS_FILESYSTEM_MEMORY_FILE;
     1020    return RTEMS_FILESYSTEM_DIRECTORY;
     1021}
     1022
    9871023static int rtems_tftp_fstat(
    988     const rtems_filesystem_location_info_t *loc,
     1024    rtems_filesystem_location_info_t *loc,
    9891025    struct stat                            *buf
    9901026)
     
    9991035}
    10001036
    1001 static int rtems_tftp_clone(
     1037static int rtems_tftp_free_node_info(
    10021038    rtems_filesystem_location_info_t *loc
    10031039)
    10041040{
    1005     int rv = 0;
    1006 
    1007     loc->node_access = strdup (loc->node_access);
    1008 
    1009     if (loc->node_access == NULL) {
    1010         errno = ENOMEM;
    1011         rv = -1;
    1012     }
    1013 
    1014     return rv;
    1015 }
    1016 
    1017 static void rtems_tftp_free_node_info(
    1018     const rtems_filesystem_location_info_t *loc
    1019 )
    1020 {
    1021     free (loc->node_access);
    1022 }
    1023 
    1024 static bool rtems_tftp_are_nodes_equal(
    1025   const rtems_filesystem_location_info_t *a,
    1026   const rtems_filesystem_location_info_t *b
    1027 )
    1028 {
    1029   return strcmp (a->node_access, b->node_access) == 0;
     1041    free (loc->node_access_2);
     1042    return 0;
    10301043}
    10311044
    10321045static const rtems_filesystem_operations_table  rtems_tftp_ops = {
    1033     .lock_h = rtems_filesystem_default_lock,
    1034     .unlock_h = rtems_filesystem_default_unlock,
    1035     .eval_path_h = rtems_tftp_eval_path,
    1036     .link_h = rtems_filesystem_default_link,
    1037     .are_nodes_equal_h = rtems_tftp_are_nodes_equal,
    1038     .mknod_h = rtems_filesystem_default_mknod,
    1039     .rmnod_h = rtems_filesystem_default_rmnod,
    1040     .fchmod_h = rtems_filesystem_default_fchmod,
    1041     .chown_h = rtems_filesystem_default_chown,
    1042     .clonenod_h = rtems_tftp_clone,
     1046    .evalpath_h = rtems_tftp_eval_path,
     1047    .evalformake_h = rtems_tftp_evaluate_for_make,
     1048    .node_type_h = rtems_tftp_node_type,
    10431049    .freenod_h = rtems_tftp_free_node_info,
    1044     .mount_h = rtems_filesystem_default_mount,
    1045     .unmount_h = rtems_filesystem_default_unmount,
     1050    .fsmount_me_h = rtems_tftpfs_initialize,
    10461051    .fsunmount_me_h = rtems_tftpfs_shutdown,
    1047     .utime_h = rtems_filesystem_default_utime,
    1048     .symlink_h = rtems_filesystem_default_symlink,
    1049     .readlink_h = rtems_filesystem_default_readlink,
    1050     .rename_h = rtems_filesystem_default_rename,
    1051     .statvfs_h = rtems_filesystem_default_statvfs
    10521052};
    10531053
     
    10571057   .read_h = rtems_tftp_read,
    10581058   .write_h = rtems_tftp_write,
    1059    .ioctl_h = rtems_filesystem_default_ioctl,
    1060    .lseek_h = rtems_filesystem_default_lseek,
    10611059   .fstat_h = rtems_tftp_fstat,
    10621060   .ftruncate_h = rtems_tftp_ftruncate,
    1063    .fsync_h = rtems_filesystem_default_fsync_or_fdatasync,
    1064    .fdatasync_h = rtems_filesystem_default_fsync_or_fdatasync,
    1065    .fcntl_h = rtems_filesystem_default_fcntl,
    1066    .kqfilter_h = rtems_filesystem_default_kqfilter,
    1067    .poll_h = rtems_filesystem_default_poll,
    1068    .readv_h = rtems_filesystem_default_readv,
    1069    .writev_h = rtems_filesystem_default_writev
    10701061};
  • cpukit/libnetworking/rtems/tftp.h

    r4bcbd8d6 r05d8495  
    3737 * Filesystem Mount table entry.
    3838 */
    39 int rtems_tftpfs_initialize(rtems_filesystem_mount_table_entry_t *temp_mt_entry);
     39int rtems_tftpfs_initialize(rtems_filesystem_mount_table_entry_t *temp_mt_entry,
     40                            const void *data);
    4041
    4142#ifdef __cplusplus
Note: See TracChangeset for help on using the changeset viewer.