Beispiel #1
0
void __prof_get_current_tid
(
    /* Pointer to a buffer to hold the task identifier */
    char * tid_ptr,

    /* Maximum size of the buffer */
    int    max
)
{   /* Body */
    KERNEL_DATA_STRUCT_PTR        kernel_data;
    TASK_TEMPLATE_STRUCT_PTR      template_ptr;
    uint_32                       size;

    _GET_KERNEL_DATA(kernel_data);

    template_ptr = kernel_data->ACTIVE_PTR->TASK_TEMPLATE_PTR;

    /* How long is the name? */
    size = _strnlen(template_ptr->TASK_NAME, max);

    /* Copy the string name of the task into the buffer */
    if (size >= max) {
        size = max - 1;
    } /* Endif */
    strncpy(tid_ptr, template_ptr->TASK_NAME, size);

    /* Terminate the copied string */
    tid_ptr[size] = '\0';

} /* Endbody */
_mfs_error MFS_Find_next_slave
    (
    MFS_DRIVE_STRUCT_PTR  drive_ptr,    /*[IN] drive context */
    void     *search_next_ptr           /*[IN] address of search data block indicating the current criteria and the results 
                                        ** of the last search results of this search are placed in this data block */
    )
{
    MFS_SEARCH_DATA_PTR        transfer_ptr;
    MFS_INTERNAL_SEARCH_PTR    internal_search_ptr;
    MFS_DIR_ENTRY_PTR          dir_entry_ptr;
    _mfs_error                 error_code;
    uint32_t                    len;
    bool                    found;
    bool                    match_all;
    bool                    eightdotthree = FALSE;
    char                   *lfn;
    char                       sname[SFILENAME_SIZE+1]; 
    uint32_t                    dotfile = 0;
    MFS_DIR_ENTRY  saved_dir_entry;  

    transfer_ptr = (MFS_SEARCH_DATA_PTR) search_next_ptr;
    error_code = MFS_NO_ERROR;
    found = FALSE;

    if ( transfer_ptr )
    {
        internal_search_ptr = &transfer_ptr->INTERNAL_SEARCH_DATA;

        if ( MFS_alloc_path(&lfn)!= MFS_NO_ERROR )
        {
            return MFS_INSUFFICIENT_MEMORY;
        }

        match_all = MFS_Check_search_string_for_all(internal_search_ptr->SRC_PTR);
        if ( !match_all )
        {
            dotfile = MFS_Is_dot_directory(internal_search_ptr->SRC_PTR);
            if ( dotfile == 0 )
            {
                eightdotthree = MFS_Check_search_string_for_8dot3( internal_search_ptr->SRC_PTR);
            }
        }
        do
        {
            dir_entry_ptr = MFS_Find_directory_entry(drive_ptr, NULL, &internal_search_ptr->CURRENT_CLUSTER, &internal_search_ptr->DIR_ENTRY_INDEX,
                &internal_search_ptr->PREV_CLUSTER, internal_search_ptr->ATTRIBUTE & (~ATTR_EXCLUSIVE), &error_code);

            if ( dir_entry_ptr == NULL && !error_code )
            {
                error_code = MFS_FILE_NOT_FOUND;
                break;
            }

            if ( internal_search_ptr->CURRENT_CLUSTER == CLUSTER_INVALID )
            {
                error_code = MFS_FILE_NOT_FOUND;
                break;
            }

            if ( dir_entry_ptr == NULL )
            {
                break;
            }
            saved_dir_entry=*dir_entry_ptr; 

            /* Make sure the entry is not an LFN entry */
            if ( *dir_entry_ptr->ATTRIBUTE != MFS_ATTR_LFN )
            {
                MFS_Compress_nondotfile (dir_entry_ptr->NAME, sname);

                if ( match_all )
                {
                    found = TRUE;
                }
                else
                {
                    if ( dotfile != 0 )
                    {
                        if ( dotfile == 1 )
                        {
                            found = internal_search_ptr->FULLNAME[0] == dir_entry_ptr->NAME[0];
                        }
                        else if ( dotfile == 2 )
                        {
                            found = (internal_search_ptr->FULLNAME[0] == dir_entry_ptr->NAME[0]) &&
                                    (internal_search_ptr->FULLNAME[1] == dir_entry_ptr->NAME[1]);
                        }
                        else
                        {
                            found = FALSE; /* This shouldn't happen */
                        }
                    }
                    else if ( eightdotthree )
                    {
                        found = MFS_Wildcard_match(internal_search_ptr->FILENAME, dir_entry_ptr->NAME);
                    }
                    else
                    {
                        if ( MFS_get_lfn_dir_cluster(drive_ptr, search_next_ptr, sname, lfn) == MFS_NO_ERROR )
                        {
                            found = MFS_lfn_match(internal_search_ptr->SRC_PTR, lfn, 0);
                        }
                        else
                        {
                            found = MFS_lfn_match(internal_search_ptr->SRC_PTR, sname, 0);
                        }  
                    }  
                }  
            }

            if ( !error_code )
            {
                error_code = MFS_Increment_dir_index(drive_ptr, &internal_search_ptr->CURRENT_CLUSTER,
                    &internal_search_ptr->DIR_ENTRY_INDEX, &internal_search_ptr->PREV_CLUSTER);  
            }

        } while ( (error_code == MFS_NO_ERROR) && (found  == FALSE) );

        if ( error_code == MFS_NO_ERROR )
        {
            transfer_ptr->ATTRIBUTE = mqx_dtohc(saved_dir_entry.ATTRIBUTE);
            transfer_ptr->TIME      = mqx_dtohs(saved_dir_entry.TIME);
            transfer_ptr->DATE      = mqx_dtohs(saved_dir_entry.DATE);
            transfer_ptr->FILE_SIZE = mqx_dtohl(saved_dir_entry.FILE_SIZE);

            /* Transfer the filename */
            len = _strnlen(sname,13);
            if ( sname[len-1] == '.' )
            {
                sname[len-1] = '\0';
            }
            strncpy(transfer_ptr->NAME, sname, 13);
        }

        MFS_free_path((void *)lfn);
    }
    else
    {
        error_code = MFS_INVALID_MEMORY_BLOCK_ADDRESS;
    }  

    return(error_code);
}  
MFS_DIR_ENTRY_PTR MFS_Find_directory_entry
    (
    MFS_DRIVE_STRUCT_PTR  drive_ptr,            /*[IN] drive context */
    char              *file_ptr,             /*[IN] specific name to search for, if NULL then first dir entry */
    uint32_t           *start_cluster_ptr,    /*[IN] start searching in this cluster
                                                **[OUT] set to the cluster number in which search was satisfied */
    uint32_t           *dir_index_ptr,        /*[IN] start searching at this directory entry
                                                **[OUT] if entry is found the index of the next entry is returned */
    uint32_t           *prev_cluster_ptr,     /* [IN] set to the cluster number previous to start_cluster
                                                ** [OUT] set to the cluster number previous to *dir_cluster_ptr */
    unsigned char                 attribute,            /*[IN] search attribute, as per Find_first_file */
    _mfs_error_ptr           error_ptr          /* The pointer carries the error infomation */
    )
{
    MFS_DIR_ENTRY_PTR     dir_entry_ptr = NULL;
    char              *lfn_ptr = NULL;
    bool               found;
    bool               lfn_flag;
    bool               maybe = FALSE;
    bool               found_lfn = FALSE;
    uint32_t               current_cluster, current_index;
    _mfs_error            error_code;
    uint32_t               lfn_len = 0;  
    uint16_t               entries_per_sector;
    uint16_t               k, i;
    char                  lfn_entry[40]; /* LFN entry contains up to 13 UTF16 characters, up to 40 bytes including null term are necessary when encoded using UTF8 */
    char                  fs_file[SFILENAME_SIZE + 1]; 
    uint32_t               prev_cluster = *prev_cluster_ptr; 
    uint32_t               dirname = 0;


    error_code = MFS_NO_ERROR;

    entries_per_sector = drive_ptr->ENTRIES_PER_SECTOR;
    current_cluster = *start_cluster_ptr;
    current_index = *dir_index_ptr;

    found = FALSE;
    lfn_flag = FALSE;

    /* If the name is a LFN, it will be treated differently */
    if ( file_ptr && *file_ptr && !MFS_Dirname_valid(file_ptr) )
    {
        lfn_flag = TRUE;
        lfn_len = _strnlen(file_ptr, PATHNAME_SIZE);
        /* Set pointer just behind the end of the filename */
        lfn_ptr = file_ptr + lfn_len;
        maybe = TRUE;
        found_lfn = FALSE;
        /* We also need special treatement for a directory name */
        if ( attribute == (ATTR_EXCLUSIVE | MFS_ATTR_DIR_NAME) )
        {
            attribute = MFS_ATTR_LFN;
            dirname = 1;
        }
    }
    else if ( file_ptr && *file_ptr )
    {
        MFS_Expand_dotfile(file_ptr, fs_file);
    }
    /*
    ** Search in all clusters within this directory
    */

    do
    {
        /*
        ** Search in all sectors within this cluster
        */
        for ( k = (uint16_t) INDEX_TO_SECTOR(current_index); 
            ((current_cluster == 0) || (k < drive_ptr->BPB.SECTORS_PER_CLUSTER)) && found == FALSE && current_cluster != CLUSTER_EOF;
            k++ )
        {
            dir_entry_ptr = MFS_Read_directory_sector(drive_ptr,current_cluster, k, &error_code);
            if ( dir_entry_ptr == NULL )
            {
                break;
            }

            /*
            ** Search in all entries within this sector
            */
            for ( i = (uint16_t) INDEX_TO_OFFSET(current_index), dir_entry_ptr += i ; i < entries_per_sector && found == FALSE; i++ )
            {
                if ( *dir_entry_ptr->NAME == '\0' ) /* if NEVER USED entry */
                {
                    if ( file_ptr )      /* If not NULL                    */
                    {
                        if ( !*file_ptr )      /* but ""                         */
                        {
                            /* we found it */
                            found = TRUE;
                            break;
                        }
                    }
                    return(NULL);       /* Anyway, stop here-never used entry */
                                        /* if the entry is relevant at all    */

                }
                else if ( (unsigned char) *dir_entry_ptr->NAME == MFS_DEL_FILE )
                {
                    /* If DELETED */ 
                    if ( file_ptr )      /* If not NULL   */
                    {
                        if ( !*file_ptr )      /* but ""  */
                        {
                            found = TRUE;       /* we found it  */
                            break;
                        }
                    }
                }
                else                        /* If REGULAR ENTRY */
                {
                    if ( file_ptr == NULL || *file_ptr )
                    {
                        if ( MFS_Attribute_match(mqx_dtohc(dir_entry_ptr->ATTRIBUTE), 
                            attribute) == TRUE )
                        {
                            if ( !file_ptr )
                            {
                                found = TRUE;
                                break;
                            }
                            else if ( lfn_flag ) /* Searching for a long name */
                            {
                                if ( found_lfn )
                                {
                                    found = TRUE;
                                    break;
                                }
                                if ( !MFS_Attribute_match(mqx_dtohc(dir_entry_ptr->ATTRIBUTE),
                                    MFS_ATTR_LFN) )
                                {
                                    maybe = TRUE; /* Reset maybe */
                                    dir_entry_ptr++;
                                    current_index++;
                                    continue;   /* Not an LFN entry, skip it */ 
                                }
                                if ( !maybe )
                                {
                                    dir_entry_ptr++;
                                    current_index++;
                                    continue;
                                }
                                int chunk_len;
                                chunk_len = MFS_lfn_extract((MFS_LNAME_ENTRY_PTR)dir_entry_ptr, lfn_entry);
                                if(lfn_ptr >= (file_ptr + chunk_len))
                                {
                                    lfn_ptr -= chunk_len;
                                    if ( strncmp(lfn_entry, lfn_ptr, chunk_len) )
                                    {
                                        lfn_ptr = file_ptr + lfn_len; /* reset ptr */
                                        maybe = FALSE;
                                        dir_entry_ptr++;
                                        current_index++;
                                        continue; /* Strings don't match */
                                    }

                                    if ( lfn_ptr == file_ptr )
                                    {
                                        found_lfn = TRUE;
                                        if ( dirname )
                                        {
                                            attribute = ATTR_EXCLUSIVE | MFS_ATTR_DIR_NAME;
                                        }
                                    }
                                }
                                else
                                {
                                    maybe = FALSE;
                                    lfn_ptr = file_ptr + lfn_len; /* reset ptr */
                                }
                            }
                            else /* Searching for a short name */
                            {
                                found = MFS_Wildcard_match(fs_file, dir_entry_ptr->NAME);
                            }  
                        }
                        else
                        {
                            if ( lfn_flag )
                            {
                                attribute = MFS_ATTR_LFN;
                                lfn_ptr = file_ptr + lfn_len; /* reset ptr */
                                maybe = TRUE;
                                found_lfn = FALSE;
                            }
                        }  
                    }
                }  

                if ( found == FALSE )
                {
                    dir_entry_ptr++;
                    current_index++;
                }
            }  
        }  

        if ( found == FALSE )
        {
            error_code = MFS_Increment_dir_index(drive_ptr, &current_cluster, &current_index, &prev_cluster); 
            if ( error_code )
            {
                break;
            }
        }

    } while ( found == FALSE && dir_entry_ptr && current_cluster != CLUSTER_EOF && current_cluster != CLUSTER_INVALID );

    if ( found == FALSE )
    {
        dir_entry_ptr      = NULL;
    }
    else
    {
        *start_cluster_ptr = current_cluster;
        *prev_cluster_ptr = prev_cluster;  
        *dir_index_ptr = current_index;
    }  

    if ( error_ptr )
    {
        *error_ptr = error_code;
    }

    return(dir_entry_ptr);
}  
_mfs_error MFS_Find_first_file
    (
        MFS_DRIVE_STRUCT_PTR drive_ptr,

        unsigned char       attribute,      /*[IN] type of file to find, Search attributes */
        char                *pathname,       /*[IN] optionally the directory and filename to search for */
        MFS_SEARCH_DATA_PTR transfer_ptr    /*[IN] address of search data block into which the results of the search are put */
    )
{
    MFS_INTERNAL_SEARCH_PTR internal_search_ptr;
    char                *temp_dirname;
    char                *temp_filename;
    uint32_t                 current_cluster;
    _mfs_error              error_code;
    uint32_t                 i;
    char                    c;

    if ( (pathname==NULL) || (*pathname=='\0') )
    {
        return MFS_INVALID_PARAMETER;
    }

    if ( transfer_ptr == NULL )
    {
        return MFS_INVALID_MEMORY_BLOCK_ADDRESS;
    }

    error_code = MFS_alloc_2paths(&temp_dirname,&temp_filename);
    if ( error_code != MFS_NO_ERROR )
    {
        return( error_code );
    }

    error_code = MFS_lock_dos_disk( drive_ptr );
    if ( error_code != MFS_NO_ERROR )
    {
        MFS_free_path(temp_dirname);
        MFS_free_path(temp_filename);
        return error_code;
    }

    _mem_zero(transfer_ptr, sizeof (MFS_SEARCH_DATA));
    transfer_ptr->DRIVE_PTR = drive_ptr;

    MFS_Parse_pathname(temp_dirname, temp_filename, pathname);

    current_cluster = drive_ptr->CUR_DIR_CLUSTER;
    current_cluster = MFS_Find_directory(drive_ptr, temp_dirname, current_cluster);

    if ( current_cluster == CLUSTER_INVALID )
    {
        error_code = MFS_PATH_NOT_FOUND;
    }
    else
    {
        /*
        ** The internal search is only initialised if the directory exists.
        */
        internal_search_ptr = &transfer_ptr->INTERNAL_SEARCH_DATA;
        internal_search_ptr->CURRENT_CLUSTER = current_cluster;
        internal_search_ptr->PREV_CLUSTER = CLUSTER_INVALID;  
        internal_search_ptr->DIR_ENTRY_INDEX = 0;

        MFS_Expand_wildcard(temp_filename, internal_search_ptr->FILENAME);   
        internal_search_ptr->FULLNAME = temp_filename;

        i = _strnlen(pathname, PATHNAME_SIZE + FILENAME_SIZE + 1);
        c = pathname[--i];
        while ( (c != '\\') && (c != '/') && (c != ':') && i )
        {
            i--;         
            c = pathname[i];
        }  
        if ( i || c == '\\' || c == '/' )
        {
            i++;
        }

        internal_search_ptr->SRC_PTR = pathname + i;
        internal_search_ptr->ATTRIBUTE = attribute;
        error_code = MFS_Find_next_slave(drive_ptr, transfer_ptr);
    }  

    MFS_free_path(temp_dirname);
    MFS_free_path(temp_filename);
    MFS_unlock(drive_ptr,FALSE);

    return(error_code);
}  
Beispiel #5
0
/*!
 * \cond DOXYGEN_PRIVATE
 * \private
 * 
 * \brief Gets the number that is associated with the name in the names database.
 * 
 * \param[in]  name_handle The handle returned by _name_internal_create.
 * \param[in]  name        The name to be looked up.
 * \param[out] number_ptr  The location where the number is to be returned.
 * 
 * \return MQX_OK
 * \return MQX_COMPONENT_DOES_NOT_EXIST (Name component is not created.)
 * \return NAME_TOO_SHORT (Name is 0 length string.)
 * \return NAME_TOO_LONG (Name is longer than NAME_MAX_NAME_SIZE.)
 * \return MQX_INVALID_COMPONENT_BASE (Name component data are not valid.)
 * \return NAME_NOT_FOUND (Name is not in the names database.) 
 */ 
_mqx_uint _name_find_internal
(
    void             *name_handle,
    char          *name,
    _mqx_max_type_ptr number_ptr
)
{ /* Body */
    register NAME_COMPONENT_STRUCT_PTR name_manager_ptr;
    register NAME_STRUCT_PTR           name_ptr;
    register _mqx_uint                 i;

    name_manager_ptr = (NAME_COMPONENT_STRUCT_PTR) name_handle;
#if MQX_CHECK_ERRORS
    if (name_manager_ptr == NULL)
    {
        return (MQX_COMPONENT_DOES_NOT_EXIST);
    } /* Endif */
    if (*name == '\0')
    {
        /* Cannot find 0 length string name */
        return (NAME_TOO_SHORT);
    } /* Endif */
    if (_strnlen(name, NAME_MAX_NAME_SIZE) >= NAME_MAX_NAME_SIZE)
    {
        return (NAME_TOO_LONG);
    } /* Endif */
#endif /* MQX_CHECK_ERRORS */
#if MQX_CHECK_VALIDITY
    if (name_manager_ptr->VALID != NAME_VALID)
    {
        return (MQX_INVALID_COMPONENT_BASE);
    } /* Endif */
#endif /* MQX_CHECK_VALIDITY */

    /* Scan to end of table, if found, return number */
    while (TRUE)
    {
        i = name_manager_ptr->NUMBER_IN_BLOCK + 1;
        name_ptr = (NAME_STRUCT_PTR) & name_manager_ptr->NAMES[0];
        while (--i)
        {
            if (name_ptr->NAME[0] != '\0')
            {
                if (strncmp(name_ptr->NAME, name, (_mqx_uint) NAME_MAX_NAME_SIZE - 1) == 0)
                { /* MATCH */
                    *number_ptr = name_ptr->NUMBER;
                    return (MQX_OK);
                } /* Endif */
            } /* Endif */
            name_ptr++;
        } /* Endwhile */
        if (name_manager_ptr->NEXT_TABLE == NULL)
        {
            return (NAME_NOT_FOUND);
        } /* Endif */
        name_manager_ptr = name_manager_ptr->NEXT_TABLE;
#if MQX_CHECK_VALIDITY
        if (name_manager_ptr->VALID != NAME_VALID)
        {
            return (MQX_INVALID_COMPONENT_BASE);
        } /* Endif */
#endif /* MQX_CHECK_VALIDITY */
    } /* Endwhile */
} /* Endbody */
Beispiel #6
0
/*!
 * \cond DOXYGEN_PRIVATE
 * \private
 * 
 * \brief This function removes a name from the name component.
 * 
 * \param[in] name_handle The handle returned by _name_internal_create.
 * \param[in] name        The name to be deleted.
 * 
 * \return MQX_OK
 * \return MQX_COMPONENT_DOES_NOT_EXIST (Name component is not created.)
 * \return MQX_INVALID_COMPONENT_BASE (Name component data are not valid.)
 * \return NAME_TOO_SHORT (Name is 0 length string.)
 * \return NAME_TOO_LONG (Name is longer than NAME_MAX_NAME_SIZE.)
 * \return NAME_NOT_FOUND (Name is not in the names database.) 
 */ 
_mqx_uint _name_delete_internal
(
    void    *name_handle,
    char *name
)
{ /* Body */
    NAME_COMPONENT_STRUCT_PTR          base_name_manager_ptr;
    register NAME_COMPONENT_STRUCT_PTR name_manager_ptr;
    register NAME_STRUCT_PTR           name_ptr;
    register _mqx_uint                 i;

    name_manager_ptr = (NAME_COMPONENT_STRUCT_PTR) name_handle;
#if MQX_CHECK_ERRORS
    if (name_manager_ptr == NULL)
    {
        return (MQX_COMPONENT_DOES_NOT_EXIST);
    } /* Endif */
#endif /* MQX_CHECK_ERRORS */

    base_name_manager_ptr = name_manager_ptr;

    /* We are modifying the table, so lets get exclusive access */
    _int_disable();
#if MQX_CHECK_VALIDITY
    if (name_manager_ptr->VALID != NAME_VALID)
    {
        _int_enable();
        return (MQX_INVALID_COMPONENT_BASE);
    } /* Endif */
#endif /* MQX_CHECK_VALIDITY */
#if MQX_CHECK_ERRORS
    if (*name == '\0')
    {
        /* Cannot delete 0 length string name */
        _int_enable();
        return (NAME_TOO_SHORT);
    } /* Endif */
    if (_strnlen(name, NAME_MAX_NAME_SIZE) >= NAME_MAX_NAME_SIZE)
    {
        _int_enable();
        return (NAME_TOO_LONG);
    } /* Endif */
#endif /* MQX_CHECK_ERRORS */
#if MQX_CHECK_VALIDITY
    if (base_name_manager_ptr->VALID != NAME_VALID)
    {
        _int_enable();
        return (MQX_INVALID_COMPONENT_BASE);
    } /* Endif */
#endif /* MQX_CHECK_VALIDITY */
    _lwsem_wait((LWSEM_STRUCT_PTR) (&base_name_manager_ptr->SEM));

    _int_enable();

    /* Scan to end of table, and if the name found, delete it */
    while (TRUE)
    {
        i = name_manager_ptr->NUMBER_IN_BLOCK + 1;
        name_ptr = &name_manager_ptr->NAMES[0];
        while (--i)
        {
            if (name_ptr->NAME[0] != '\0')
            {
                if (strncmp(name_ptr->NAME, name, (_mqx_uint) NAME_MAX_NAME_SIZE - 1) == 0)
                { /* MATCH */
                    name_ptr->NAME[0] = '\0';
                    name_ptr->NUMBER = 0;
                    base_name_manager_ptr->NUMBER--;
                    _lwsem_post((LWSEM_STRUCT_PTR) (&base_name_manager_ptr->SEM));
                    return (MQX_OK);
                } /* Endif */
            } /* Endif */
            name_ptr++;
        } /* Endwhile */
        if (name_manager_ptr->NEXT_TABLE == NULL)
        {
            _lwsem_post((LWSEM_STRUCT_PTR) (&base_name_manager_ptr->SEM));
            return (NAME_NOT_FOUND);
        }
        else
        {
            name_manager_ptr = name_manager_ptr->NEXT_TABLE;
#if MQX_CHECK_VALIDITY
            if (name_manager_ptr->VALID != NAME_VALID)
            {
                _lwsem_post((LWSEM_STRUCT_PTR) (&base_name_manager_ptr->SEM));
                return (MQX_INVALID_COMPONENT_BASE);
            } /* Endif */
#endif /* MQX_CHECK_VALIDITY */
        } /* Endif */
    } /* Endwhile */
} /* Endbody */
Beispiel #7
0
/*!
 * \cond DOXYGEN_PRIVATE
 * \private
 * 
 * \brief This function adds a name to the name component along with the 
 * _mqx_max_type number associated with the name.
 * 
 * \param[in] name_handle The handle returned by _name_internal_create.
 * \param[in] name        The name to be associated with the number.
 * \param[in] number      The number to be associated with the name.
 * 
 * \return MQX_OK
 * \return MQX_OUT_OF_MEMORY (MQX cannot allocate memory for the name component.)
 * \return MQX_COMPONENT_DOES_NOT_EXIST (Name component is not created.)
 * \return MQX_INVALID_COMPONENT_BASE (Name component data is not valid.)
 * \return NAME_TOO_SHORT (Name is 0 length string.)
 * \return NAME_TOO_LONG (Name is longer than NAME_MAX_NAME_SIZE.)
 * \return NAME_EXISTS (Name is already in the names database.)
 * \return NAME_TABLE_FULL (Names database is full.) 
 */ 
_mqx_uint _name_add_internal
(
    void         *name_handle,
    char     *name,
    _mqx_max_type number
)
{ /* Body */
    NAME_COMPONENT_STRUCT_PTR          base_name_manager_ptr;
    register NAME_COMPONENT_STRUCT_PTR name_manager_ptr;
    register NAME_STRUCT_PTR           name_ptr;
    register NAME_STRUCT_PTR           saved_name_ptr;
    register _mqx_uint                 i;
    _mqx_uint                          result = MQX_OK;

#if MQX_CHECK_ERRORS
    if (*name == '\0')
    {
        /* Cannot add 0 length string name */
        return (NAME_TOO_SHORT);
    } /* Endif */
    if (_strnlen(name, NAME_MAX_NAME_SIZE) >= NAME_MAX_NAME_SIZE)
    {
        return (NAME_TOO_LONG);
    } /* Endif */
#endif /* MQX_CHECK_ERRORS */

    name_manager_ptr = (NAME_COMPONENT_STRUCT_PTR) name_handle;
#if MQX_CHECK_ERRORS
    if (name_manager_ptr == NULL)
    {
        return (MQX_COMPONENT_DOES_NOT_EXIST);
    } /* Endif */
#endif /* MQX_CHECK_ERRORS */
    base_name_manager_ptr = name_manager_ptr;

    /* We are modifying the table, so lets get exclusive access */
    _int_disable();
#if MQX_CHECK_VALIDITY
    if ((name_manager_ptr->VALID != NAME_VALID) || (base_name_manager_ptr->VALID != NAME_VALID))
    {
        _int_enable();
        return (MQX_INVALID_COMPONENT_BASE);
    } /* Endif */
#endif /* MQX_CHECK_VALIDITY */
    _lwsem_wait((LWSEM_STRUCT_PTR) (&base_name_manager_ptr->SEM));
    _int_enable();

    /* 
     * Scan to end of table, looking for a duplicate name..
     * simultaneously, remember the first empty slot found
     */
    saved_name_ptr = NULL;
    while (TRUE)
    {
        i = name_manager_ptr->NUMBER_IN_BLOCK + 1;
        name_ptr = &name_manager_ptr->NAMES[0];
        while (--i)
        {
            if (name_ptr->NAME[0] == '\0')
            {
                if (saved_name_ptr == NULL)
                {
                    saved_name_ptr = name_ptr;
                } /* Endif */
            }
            else
            {
                if (strncmp(name_ptr->NAME, name, (_mqx_uint) NAME_MAX_NAME_SIZE - 1) == 0)
                { /* MATCH */
                    result = NAME_EXISTS;
                    break;
                } /* Endif */
            } /* Endif */
            name_ptr++;
        } /* Endwhile */
        if ((name_manager_ptr->NEXT_TABLE == NULL) || (result != MQX_OK))
        {
            break;
        } /* Endif */
        name_manager_ptr = name_manager_ptr->NEXT_TABLE;
    } /* Endwhile */

    if (result == MQX_OK)
    {
        /* We have scanned the whole table, and the original name was not found */

        if (saved_name_ptr == NULL)
        {
            /* 
             * An empty slot was not found in the table so we must try to
             * grow the name table
             */
            if (base_name_manager_ptr->GROW_NUMBER && ((name_manager_ptr->TOTAL_NUMBER
                            + base_name_manager_ptr->GROW_NUMBER) <= base_name_manager_ptr->MAX_NUMBER))
            {
                result = _name_create_handle_internal((void **) &name_manager_ptr->NEXT_TABLE,
                                base_name_manager_ptr->GROW_NUMBER, base_name_manager_ptr->GROW_NUMBER,
                                base_name_manager_ptr->MAX_NUMBER, (name_manager_ptr->TOTAL_NUMBER
                                                + base_name_manager_ptr->GROW_NUMBER));
                if (result == MQX_OK)
                {
                    name_manager_ptr = name_manager_ptr->NEXT_TABLE;
                    saved_name_ptr = &name_manager_ptr->NAMES[0];
                } /* Endif */
            }
            else
            {
                result = NAME_TABLE_FULL;
            } /* Endif */
        } /* Endif */

        if (saved_name_ptr != NULL)
        {
            strncpy(saved_name_ptr->NAME, name, (_mqx_uint) NAME_MAX_NAME_SIZE - 1);
            saved_name_ptr->NAME[NAME_MAX_NAME_SIZE - 1] = '\0';
            saved_name_ptr->NUMBER = number;
            base_name_manager_ptr->NUMBER++;
        }/* Endif */
    }/* Endif */

    _lwsem_post((LWSEM_STRUCT_PTR) (&base_name_manager_ptr->SEM));

    return (result);
} /* Endbody */
Beispiel #8
0
Datei: srv.c Projekt: 20150/3dmoo
u32 srv_SyncRequest()
{
    u32 cid = mem_Read32(arm11_ServiceBufferAddress() + 0x80);

    // Read command-id.
    switch(cid) {

    case 0x10002:
        DEBUG("srv_Initialize\n");

        // XXX: check +4, flags?
        mem_Write32(arm11_ServiceBufferAddress() + 0x84, 0); //no error
        PAUSE();
        return 0;

    case 0x20000:
        DEBUG("srv_GetProcSemaphore\n");

        mem_Write32(arm11_ServiceBufferAddress() + 0x84, 0); //no error
        mem_Write32(arm11_ServiceBufferAddress() + 0x88, 0); //done in sm 4.4
        mem_Write32(arm11_ServiceBufferAddress() + 0x8C, eventhandle);
        return 0;

        char names[9];
    case 0x000400C0:
        DEBUG("srv_UnRegisterService --todo--\n");

        // Read rest of command header
        mem_Read((u8*)&req, arm11_ServiceBufferAddress() + 0x84, sizeof(req));

        memcpy(names, req.name, 8);
        names[8] = '\0';

        DEBUG("name=%s, namelen=%u\n", names, req.name_len);

        return 0;

    case 0x00030100:
        DEBUG("srv_registerService\n");

        // Read rest of command header
        mem_Read((u8*)&req, arm11_ServiceBufferAddress() + 0x84, sizeof(req));

        memcpy(names, req.name, 8);
        names[8] = '\0';

        DEBUG("name=%s, namelen=%u, unk=0x%x\n", names, req.name_len,
              req.unk2);


        ownservice[ownservice_num].name = calloc(9,sizeof(u8));
        memcpy(ownservice[ownservice_num].name, req.name, sizeof(req.name));

        ownservice[ownservice_num].handle = handle_New(HANDLE_TYPE_SERVICE_UNMOUNTED, SERVICE_DIRECT);

        handleinfo* oldhi = handle_Get(ownservice[ownservice_num].handle);

        if (oldhi == NULL) {
            ERROR("getting handle.\n");
            return 0x0;
        }

        oldhi->misc[0] = 0; //numb of connected todo more than one

        mem_Write32(arm11_ServiceBufferAddress() + 0x84, 0); //no error
        mem_Write32(arm11_ServiceBufferAddress() + 0x8C, ownservice[ownservice_num].handle); //return handle
        ownservice_num++;
        return 0;

    case 0x50100:
        DEBUG("srv_GetServiceHandle\n");

        // Read rest of command header
        mem_Read((u8*)&req, arm11_ServiceBufferAddress() + 0x84, sizeof(req));

        memcpy(names, req.name, 8);
        names[8] = '\0';

        DEBUG("name=%s, namelen=%u, unk=0x%x\n", names, req.name_len,
              req.unk2);
        PAUSE();

        u32 i;
        for(i=0; i<ARRAY_SIZE(services); i++) {
            // Find service in list.
            if(memcmp(req.name, services[i].name, _strnlen(services[i].name, 8)) == 0) {


                // Write result.
                mem_Write32(arm11_ServiceBufferAddress() + 0x84, 0);

                // Write handle_out.
                mem_Write32(arm11_ServiceBufferAddress() + 0x8C, services[i].handle);

                return 0;
            }
        }

        ERROR("Unimplemented service: %s\n", req.name);
        arm11_Dump(); //HANDLE_SERV_STAT_INITING
        //exit(1);
        mem_Write32(arm11_ServiceBufferAddress() + 0x8C, 0xDEADBABE);
        return 0;

    case 0x00080100:
        DEBUG("srv_GetHandle\n");

        // Read rest of command header
        mem_Read((u8*)&req, arm11_ServiceBufferAddress() + 0x84, sizeof(req));

        memcpy(names, req.name, 8);
        names[8] = '\0';

        DEBUG("name=%s, namelen=%u, unk=0x%x\n", names, req.name_len,
              req.unk2);
        PAUSE();

        // Write result.
        mem_Write32(arm11_ServiceBufferAddress() + 0x84, 0);

        mem_Write32(arm11_ServiceBufferAddress() + 0x8C, 0x1234);

        ERROR("Unimplemented handle: %s\n", req.name);
        arm11_Dump();
        return 0;


    case 0x90040: // EnableNotificationType
        DEBUG("srv_EnableNotificationType\n");

        u32 type = mem_Read32(arm11_ServiceBufferAddress() + 0x84);
        DEBUG("STUBBED, type=%x\n", type);

        mem_Write32(arm11_ServiceBufferAddress() + 0x84, 0);
        return 0;

    case 0xa0040: // DisableNotificationType
        DEBUG("srv_DisableNotificationType\n");

        type = mem_Read32(arm11_ServiceBufferAddress() + 0x84);
        DEBUG("STUBBED, type=%x\n", type);

        mem_Write32(arm11_ServiceBufferAddress() + 0x84, 0); //no error
        return 0;

    case 0xB0000: // GetNotificationType
        DEBUG("srv_GetNotificationType\n");
        //mem_Dbugdump();
        mem_Write32(arm11_ServiceBufferAddress() + 0x84, 0); //worked
        mem_Write32(arm11_ServiceBufferAddress() + 0x88, 0); //type
        return 0;

    default:
        ERROR("Unimplemented command %08x in \"srv:\"\n", cid);
        arm11_Dump();
        mem_Write32(arm11_ServiceBufferAddress() + 0x84, 0xFFFFFFFF); //worked
        return 0;
        //exit(1);
    }

    return 0;
}