Changeset 08232ee in mainline


Ignore:
Timestamp:
2010-01-09T21:52:07Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
9245413
Parents:
dccf721
Message:

Obtain block device size automatically, if possible. Implement ftell(). Fix seek implementation in VFS if whence == SEEK_END.

Location:
uspace
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/mkfat/mkfat.c

    rdccf721 r08232ee  
    9393        size_t block_size;
    9494        char *endptr;
     95        bn_t dev_nblocks;
    9596
    9697        cfg.total_sectors = 0;
     
    144145                printf(NAME ": Error determining device block size.\n");
    145146                return 2;
     147        }
     148
     149        rc = block_get_nblocks(handle, &dev_nblocks);
     150        if (rc != EOK) {
     151                printf(NAME ": Warning, failed to obtain block device size.\n");
     152        } else {
     153                printf(NAME ": Block device has %llu blocks.\n", dev_nblocks);
     154                cfg.total_sectors = dev_nblocks;
    146155        }
    147156
     
    240249        }
    241250
    242         printf("fat_sectors=%d\n", par->fat_sectors);
    243251        /* File allocation tables */
    244252        for (i = 0; i < fat_count; ++i) {
  • uspace/lib/libblock/libblock.c

    rdccf721 r08232ee  
    8787static int write_blocks(devcon_t *devcon, bn_t ba, size_t cnt);
    8888static int get_block_size(int dev_phone, size_t *bsize);
     89static int get_num_blocks(int dev_phone, bn_t *nblocks);
    8990
    9091static devcon_t *devcon_search(dev_handle_t dev_handle)
     
    738739}
    739740
     741/** Get number of blocks on device.
     742 *
     743 * @param dev_handle    Device handle of the block device.
     744 * @param nblocks       Output number of blocks.
     745 *
     746 * @return              EOK on success or negative error code on failure.
     747 */
     748int block_get_nblocks(dev_handle_t dev_handle, bn_t *nblocks)
     749{
     750        devcon_t *devcon;
     751
     752        devcon = devcon_search(dev_handle);
     753        assert(devcon);
     754       
     755        return get_num_blocks(devcon->dev_phone, nblocks);
     756}
     757
    740758/** Read blocks from block device.
    741759 *
     
    789807}
    790808
     809/** Get total number of blocks on block device. */
     810static int get_num_blocks(int dev_phone, bn_t *nblocks)
     811{
     812        ipcarg_t nb_l, nb_h;
     813        int rc;
     814
     815        rc = async_req_0_2(dev_phone, BD_GET_NUM_BLOCKS, &nb_l, &nb_h);
     816        if (rc == EOK) {
     817                *nblocks = (bn_t) MERGE_LOUP32(nb_l, nb_h);
     818        }
     819
     820        return rc;
     821}
     822
    791823/** @}
    792824 */
  • uspace/lib/libblock/libblock.h

    rdccf721 r08232ee  
    6060#define BLOCK_FLAGS_NOREAD      1
    6161
    62 typedef uint64_t bn_t;  /**< Block number type. */
    63 
    6462typedef struct block {
    6563        /** Mutex protecting the reference count. */
     
    110108
    111109extern int block_get_bsize(dev_handle_t, size_t *);
     110extern int block_get_nblocks(dev_handle_t, bn_t *);
    112111extern int block_read_direct(dev_handle_t, bn_t, size_t, void *);
    113112extern int block_write_direct(dev_handle_t, bn_t, size_t, const void *);
  • uspace/lib/libc/generic/io/io.c

    rdccf721 r08232ee  
    554554}
    555555
     556int ftell(FILE *stream)
     557{
     558        off_t rc = lseek(stream->fd, 0, SEEK_CUR);
     559        if (rc == (off_t) (-1)) {
     560                /* errno has been set by lseek. */
     561                return -1;
     562        }
     563
     564        return rc;
     565}
     566
    556567void rewind(FILE *stream)
    557568{
  • uspace/lib/libc/include/ipc/bd.h

    rdccf721 r08232ee  
    4040typedef enum {
    4141        BD_GET_BLOCK_SIZE = IPC_FIRST_USER_METHOD,
     42        BD_GET_NUM_BLOCKS,
    4243        BD_READ_BLOCKS,
    4344        BD_WRITE_BLOCKS
  • uspace/lib/libc/include/sys/types.h

    rdccf721 r08232ee  
    4040typedef long off_t;
    4141typedef int mode_t;
     42typedef uint64_t bn_t;  /**< Block number type. */
    4243
    4344typedef int32_t wchar_t;
  • uspace/srv/bd/ata_bd/ata_bd.c

    rdccf721 r08232ee  
    296296                        ipc_answer_1(callid, EOK, block_size);
    297297                        continue;
     298                case BD_GET_NUM_BLOCKS:
     299                        ipc_answer_2(callid, EOK, LOWER32(disk[disk_id].blocks),
     300                            UPPER32(disk[disk_id].blocks));
     301                        continue;
    298302                default:
    299303                        retval = EINVAL;
  • uspace/srv/bd/file_bd/file_bd.c

    rdccf721 r08232ee  
    5656
    5757static const size_t block_size = 512;
     58static bn_t num_blocks;
    5859static FILE *img;
    5960
     
    99100{
    100101        int rc;
     102        long img_size;
    101103
    102104        rc = devmap_driver_register(NAME, file_bd_connection);
     
    109111        if (img == NULL)
    110112                return EINVAL;
     113
     114        if (fseek(img, 0, SEEK_END) != 0) {
     115                fclose(img);
     116                return EIO;
     117        }
     118
     119        img_size = ftell(img);
     120        if (img_size < 0) {
     121                fclose(img);
     122                return EIO;
     123        }
     124
     125        num_blocks = img_size / block_size;
    111126
    112127        fibril_mutex_initialize(&dev_lock);
     
    174189                        ipc_answer_1(callid, EOK, block_size);
    175190                        continue;
     191                case BD_GET_NUM_BLOCKS:
     192                        ipc_answer_2(callid, EOK, LOWER32(num_blocks),
     193                            UPPER32(num_blocks));
     194                        continue;
    176195                default:
    177196                        retval = EINVAL;
  • uspace/srv/bd/gxe_bd/gxe_bd.c

    rdccf721 r08232ee  
    234234                        ipc_answer_1(callid, EOK, block_size);
    235235                        continue;
     236                case BD_GET_NUM_BLOCKS:
     237                        retval = ENOTSUP;
     238                        break;
    236239                default:
    237240                        retval = EINVAL;
  • uspace/srv/bd/part/mbr_part/mbr_part.c

    rdccf721 r08232ee  
    463463                        ipc_answer_1(callid, EOK, block_size);
    464464                        continue;
    465 
     465                case BD_GET_NUM_BLOCKS:
     466                        ipc_answer_2(callid, EOK, LOWER32(part->length),
     467                            UPPER32(part->length));
     468                        continue;
    466469                default:
    467470                        retval = EINVAL;
  • uspace/srv/bd/rd/rd.c

    rdccf721 r08232ee  
    153153                        ipc_answer_1(callid, EOK, block_size);
    154154                        continue;
     155                case BD_GET_NUM_BLOCKS:
     156                        ipc_answer_2(callid, EOK, LOWER32(rd_size / block_size),
     157                            UPPER32(rd_size / block_size));
     158                        continue;
    155159                default:
    156160                        /*
  • uspace/srv/vfs/vfs_ops.c

    rdccf721 r08232ee  
    900900                }
    901901                newpos = size + off;
     902                file->pos = newpos;
    902903                fibril_mutex_unlock(&file->lock);
    903904                ipc_answer_1(rid, EOK, newpos);
Note: See TracChangeset for help on using the changeset viewer.