Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset ed903174 in mainline for uspace/lib/libblock/libblock.c


Ignore:
Timestamp:
2010-02-10T23:51:23Z (12 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master
Children:
e70edd1
Parents:
b32c604
Message:

implement support for 64bit file offsets

  • the libc API is a small deviation from standard, but we have no reason to keep a strict backward compatibility with ancient code so far
    • the basic signed 64bit offset type is called off64_t
      • lseek() and fseek() take off64_t arguments (since the argument represents a relative offset)
      • ftell() returns off64_t values (since it is a wrapper of lseek())
      • vfs_seek() implementation supports negative offsets when SEEK_CUR and SEEK_END is used
    • aoff64_t is used for internal unsigned representation of sizes (in bytes, blocks, etc.) and absolute offsets
      • mmap() and ftruncate() take aoff64_t arguments (since the full range of the absolute file offset should be used here)
      • struct stat stores the file size as aoff64_t
    • in both cases the explicit range of the types shown in the names is helpful for proper filesystem and IPC interaction
    • note: size_t should be used only for representing in-memory sizes and offsets, not device and file-related information, and vice versa
      • the code base still needs a thorough revision with respect to this rule
    • PRIdOFF64 and PRIuOFF64 can be used for printing the offsets
  • VFS_OUT_LOOKUP returns the 64bit file size in two IPC arguments
    • since all 5 IPC arguments have already been taken, the fs_handle is returned as the return value (fs_handle has only 16 bits, thus the return value can be used for both indicating errors as negative values and returning positive handles)
  • VFS_OUT_READ and VFS_OUT_WRITE use aoff64_t absolute offsets split into two IPC arguments

replace bn_t with aoff64_t as a generic 64bit bytes/block counter type

note: filesystem drivers need to be revised with respect to make sure that all out-of-range checks are correct (especially w.r.t. file and block offsets)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/libblock/libblock.c

    rb32c604 red903174  
    11/*
    2  * Copyright (c) 2008 Jakub Jermar 
    3  * Copyright (c) 2008 Martin Decky 
     2 * Copyright (c) 2008 Jakub Jermar
     3 * Copyright (c) 2008 Martin Decky
    44 * All rights reserved.
    55 *
     
    8181        size_t comm_size;
    8282        void *bb_buf;
    83         bn_t bb_addr;
     83        aoff64_t bb_addr;
    8484        size_t pblock_size;             /**< Physical block size. */
    8585        cache_t *cache;
    8686} devcon_t;
    8787
    88 static int read_blocks(devcon_t *devcon, bn_t ba, size_t cnt);
    89 static int write_blocks(devcon_t *devcon, bn_t ba, size_t cnt);
     88static int read_blocks(devcon_t *devcon, aoff64_t ba, size_t cnt);
     89static int write_blocks(devcon_t *devcon, aoff64_t ba, size_t cnt);
    9090static int get_block_size(int dev_phone, size_t *bsize);
    91 static int get_num_blocks(int dev_phone, bn_t *nblocks);
     91static int get_num_blocks(int dev_phone, aoff64_t *nblocks);
    9292
    9393static devcon_t *devcon_search(dev_handle_t dev_handle)
     
    214214}
    215215
    216 int block_bb_read(dev_handle_t dev_handle, bn_t ba)
     216int block_bb_read(dev_handle_t dev_handle, aoff64_t ba)
    217217{
    218218        void *bb_buf;
     
    334334                }
    335335
    336                 long key = b->boff;
     336                unsigned long key = b->boff;
    337337                hash_table_remove(&cache->block_hash, &key, 1);
    338338               
     
    382382 * @return                      EOK on success or a negative error code.
    383383 */
    384 int block_get(block_t **block, dev_handle_t dev_handle, bn_t boff, int flags)
     384int block_get(block_t **block, dev_handle_t dev_handle, aoff64_t boff, int flags)
    385385{
    386386        devcon_t *devcon;
     
    657657 * @return              EOK on success or a negative return code on failure.
    658658 */
    659 int block_seqread(dev_handle_t dev_handle, off_t *bufpos, size_t *buflen,
    660     off_t *pos, void *dst, size_t size)
    661 {
    662         off_t offset = 0;
     659int block_seqread(dev_handle_t dev_handle, size_t *bufpos, size_t *buflen,
     660    aoff64_t *pos, void *dst, size_t size)
     661{
     662        size_t offset = 0;
    663663        size_t left = size;
    664664        size_t block_size;
     
    690690                }
    691691               
    692                 if (*bufpos == (off_t) *buflen) {
     692                if (*bufpos == *buflen) {
    693693                        /* Refill the communication buffer with a new block. */
    694694                        int rc;
     
    718718 * @return              EOK on success or negative error code on failure.
    719719 */
    720 int block_read_direct(dev_handle_t dev_handle, bn_t ba, size_t cnt, void *buf)
     720int block_read_direct(dev_handle_t dev_handle, aoff64_t ba, size_t cnt, void *buf)
    721721{
    722722        devcon_t *devcon;
     
    746746 * @return              EOK on success or negative error code on failure.
    747747 */
    748 int block_write_direct(dev_handle_t dev_handle, bn_t ba, size_t cnt,
     748int block_write_direct(dev_handle_t dev_handle, aoff64_t ba, size_t cnt,
    749749    const void *data)
    750750{
     
    789789 * @return              EOK on success or negative error code on failure.
    790790 */
    791 int block_get_nblocks(dev_handle_t dev_handle, bn_t *nblocks)
     791int block_get_nblocks(dev_handle_t dev_handle, aoff64_t *nblocks)
    792792{
    793793        devcon_t *devcon;
     
    808808 * @return              EOK on success or negative error code on failure.
    809809 */
    810 static int read_blocks(devcon_t *devcon, bn_t ba, size_t cnt)
     810static int read_blocks(devcon_t *devcon, aoff64_t ba, size_t cnt)
    811811{
    812812        int rc;
     
    816816            UPPER32(ba), cnt);
    817817        if (rc != EOK) {
    818                 printf("Error %d reading %d blocks starting at block %" PRIuBN
     818                printf("Error %d reading %d blocks starting at block %" PRIuOFF64
    819819                    " from device handle %d\n", rc, cnt, ba,
    820820                    devcon->dev_handle);
     
    835835 * @return              EOK on success or negative error code on failure.
    836836 */
    837 static int write_blocks(devcon_t *devcon, bn_t ba, size_t cnt)
     837static int write_blocks(devcon_t *devcon, aoff64_t ba, size_t cnt)
    838838{
    839839        int rc;
     
    843843            UPPER32(ba), cnt);
    844844        if (rc != EOK) {
    845                 printf("Error %d writing %d blocks starting at block %" PRIuBN
     845                printf("Error %d writing %d blocks starting at block %" PRIuOFF64
    846846                    " to device handle %d\n", rc, cnt, ba, devcon->dev_handle);
    847847#ifndef NDEBUG
     
    866866
    867867/** Get total number of blocks on block device. */
    868 static int get_num_blocks(int dev_phone, bn_t *nblocks)
     868static int get_num_blocks(int dev_phone, aoff64_t *nblocks)
    869869{
    870870        ipcarg_t nb_l, nb_h;
     
    873873        rc = async_req_0_2(dev_phone, BD_GET_NUM_BLOCKS, &nb_l, &nb_h);
    874874        if (rc == EOK) {
    875                 *nblocks = (bn_t) MERGE_LOUP32(nb_l, nb_h);
     875                *nblocks = (aoff64_t) MERGE_LOUP32(nb_l, nb_h);
    876876        }
    877877
Note: See TracChangeset for help on using the changeset viewer.