Exemple #1
0
int
_fat_block_zero(
    rtems_filesystem_mount_table_entry_t *mt_entry,
    uint32_t                              start,
    uint32_t                              offset,
    uint32_t                              count)
{
    int                 rc = RC_OK;
    fat_fs_info_t      *fs_info = mt_entry->fs_info;
    uint32_t            blk  = start;
    uint32_t            ofs = offset;
    rtems_bdbuf_buffer *block = NULL;
    uint32_t            c = 0;

    while(count > 0)
    {
        c = MIN(count, (fs_info->vol.bps - ofs));

        if (c == fs_info->vol.bps)
            rc = fat_buf_access(fs_info, blk, FAT_OP_TYPE_GET, &block);
        else
            rc = fat_buf_access(fs_info, blk, FAT_OP_TYPE_READ, &block);
        if (rc != RC_OK)
            return -1;

        memset((block->buffer + ofs), 0, c);

        fat_buf_mark_modified(fs_info);

        count -= c;
        blk++;
        ofs = 0;
    }
    return 0;
}
/* _fat_block_read --
 *     This function reads 'count' bytes from device filesystem is mounted on,
 *     starts at 'start+offset' position where 'start' computed in sectors
 *     and 'offset' is offset inside sector (reading may cross sectors
 *     boundary; in this case assumed we want to read sequential sector(s))
 *
 * PARAMETERS:
 *     mt_entry - mount table entry
 *     start    - sector num to start read from
 *     offset   - offset inside sector 'start'
 *     count    - count of bytes to read
 *     buff     - buffer provided by user
 *
 * RETURNS:
 *     bytes read on success, or -1 if error occured
 *     and errno set appropriately
 */
ssize_t
_fat_block_read(
    rtems_filesystem_mount_table_entry_t *mt_entry,
    uint32_t                              start,
    uint32_t                              offset,
    uint32_t                              count,
    void                                 *buff
    )
{
    int                     rc = RC_OK;
    register fat_fs_info_t *fs_info = mt_entry->fs_info;
    ssize_t                 cmpltd = 0;
    uint32_t                blk = start;
    uint32_t                ofs = offset;
    bdbuf_buffer           *block = NULL;
    uint32_t                c = 0;

    while (count > 0)
    {
        rc = fat_buf_access(fs_info, blk, FAT_OP_TYPE_READ, &block);
        if (rc != RC_OK)
            return -1;

        c = MIN(count, (fs_info->vol.bps - ofs));
        memcpy((buff + cmpltd), (block->buffer + ofs), c);

        count -= c;
        cmpltd += c;
        blk++;
        ofs = 0;
    }
    return cmpltd;
}
/* _fat_block_write --
 *     This function write 'count' bytes to device filesystem is mounted on,
 *     starts at 'start+offset' position where 'start' computed in sectors
 *     and 'offset' is offset inside sector (writing may cross sectors
 *     boundary; in this case assumed we want to write sequential sector(s))
 *
 * PARAMETERS:
 *     mt_entry - mount table entry
 *     start    - sector num to start read from
 *     offset   - offset inside sector 'start'
 *     count    - count of bytes to write
 *     buff     - buffer provided by user
 *
 * RETURNS:
 *     bytes written on success, or -1 if error occured
 *     and errno set appropriately
 */
ssize_t
_fat_block_write(
    rtems_filesystem_mount_table_entry_t *mt_entry,
    uint32_t                              start,
    uint32_t                              offset,
    uint32_t                              count,
    const void                           *buff)
{
    int            rc = RC_OK;
    fat_fs_info_t *fs_info = mt_entry->fs_info;
    ssize_t        cmpltd = 0;
    uint32_t       blk  = start;
    uint32_t       ofs = offset;
    bdbuf_buffer  *block = NULL;
    uint32_t       c = 0;

    while(count > 0)
    {
        c = MIN(count, (fs_info->vol.bps - ofs));

        if (c == fs_info->vol.bps)
            rc = fat_buf_access(fs_info, blk, FAT_OP_TYPE_GET, &block);
        else
            rc = fat_buf_access(fs_info, blk, FAT_OP_TYPE_READ, &block);
        if (rc != RC_OK)
            return -1;

        memcpy((block->buffer + ofs), (buff + cmpltd), c);

        fat_buf_mark_modified(fs_info);

        count -= c;
        cmpltd +=c;
        blk++;
        ofs = 0;
    }
    return cmpltd;
}