Ignore:
Timestamp:
2010-02-10T23:51:23Z (14 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e70edd1
Parents:
b32c604f
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/srv/bd/part/guid_part/guid_part.c

    rb32c604f red903174  
    7979        bool present;
    8080        /** Address of first block */
    81         bn_t start_addr;
     81        aoff64_t start_addr;
    8282        /** Number of blocks */
    83         bn_t length;
     83        aoff64_t length;
    8484        /** Device representing the partition (outbound device) */
    8585        dev_handle_t dev;
     
    101101static void gpt_pte_to_part(const gpt_entry_t *pte, part_t *part);
    102102static void gpt_connection(ipc_callid_t iid, ipc_call_t *icall);
    103 static int gpt_bd_read(part_t *p, bn_t ba, size_t cnt, void *buf);
    104 static int gpt_bd_write(part_t *p, bn_t ba, size_t cnt, const void *buf);
    105 static int gpt_bsa_translate(part_t *p, bn_t ba, size_t cnt, bn_t *gba);
     103static int gpt_bd_read(part_t *p, aoff64_t ba, size_t cnt, void *buf);
     104static int gpt_bd_write(part_t *p, aoff64_t ba, size_t cnt, const void *buf);
     105static int gpt_bsa_translate(part_t *p, aoff64_t ba, size_t cnt, aoff64_t *gba);
    106106
    107107int main(int argc, char **argv)
     
    199199                    / (1024 * 1024);
    200200                printf(NAME ": Registered device %s: %" PRIu64 " blocks "
    201                     "%" PRIuBN " MB.\n", name, part->length, size_mb);
     201                    "%" PRIuOFF64 " MB.\n", name, part->length, size_mb);
    202202
    203203                part->dev = dev;
     
    319319        int flags;
    320320        int retval;
    321         bn_t ba;
     321        aoff64_t ba;
    322322        size_t cnt;
    323323        part_t *part;
     
    402402
    403403/** Read blocks from partition. */
    404 static int gpt_bd_read(part_t *p, bn_t ba, size_t cnt, void *buf)
    405 {
    406         bn_t gba;
     404static int gpt_bd_read(part_t *p, aoff64_t ba, size_t cnt, void *buf)
     405{
     406        aoff64_t gba;
    407407
    408408        if (gpt_bsa_translate(p, ba, cnt, &gba) != EOK)
     
    413413
    414414/** Write blocks to partition. */
    415 static int gpt_bd_write(part_t *p, bn_t ba, size_t cnt, const void *buf)
    416 {
    417         bn_t gba;
     415static int gpt_bd_write(part_t *p, aoff64_t ba, size_t cnt, const void *buf)
     416{
     417        aoff64_t gba;
    418418
    419419        if (gpt_bsa_translate(p, ba, cnt, &gba) != EOK)
     
    424424
    425425/** Translate block segment address with range checking. */
    426 static int gpt_bsa_translate(part_t *p, bn_t ba, size_t cnt, bn_t *gba)
     426static int gpt_bsa_translate(part_t *p, aoff64_t ba, size_t cnt, aoff64_t *gba)
    427427{
    428428        if (ba + cnt > p->length)
Note: See TracChangeset for help on using the changeset viewer.