Changeset ed903174 in mainline for uspace/app


Ignore:
Timestamp:
2010-02-10T23:51:23Z (16 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)

Location:
uspace/app
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/cmds/modules/bdd/bdd.c

    rb32c604f red903174  
    7373        size_t block_size;
    7474        int rc;
    75         bn_t ba;
     75        aoff64_t ba;
    7676        uint8_t b;
    7777
  • uspace/app/bdsh/cmds/modules/cat/cat.c

    rb32c604f red903174  
    8585{
    8686        int fd, bytes = 0, count = 0, reads = 0;
    87         off_t total = 0;
     87        off64_t total = 0;
    8888        char *buff = NULL;
    8989
  • uspace/app/bdsh/cmds/modules/cp/cp.c

    rb32c604f red903174  
    7474{
    7575        int fd1, fd2, bytes = 0;
    76         off_t total = 0;
     76        off64_t total = 0;
    7777        int64_t copied = 0;
    7878        char *buff = NULL;
  • uspace/app/mkfat/mkfat.c

    rb32c604f red903174  
    9898        size_t block_size;
    9999        char *endptr;
    100         bn_t dev_nblocks;
     100        aoff64_t dev_nblocks;
    101101
    102102        cfg.total_sectors = 0;
     
    160160                printf(NAME ": Warning, failed to obtain block device size.\n");
    161161        } else {
    162                 printf(NAME ": Block device has %" PRIuBN " blocks.\n",
     162                printf(NAME ": Block device has %" PRIuOFF64 " blocks.\n",
    163163                    dev_nblocks);
    164164                cfg.total_sectors = dev_nblocks;
     
    236236static int fat_blocks_write(struct fat_params const *par, dev_handle_t handle)
    237237{
    238         bn_t addr;
     238        aoff64_t addr;
    239239        uint8_t *buffer;
    240240        int i;
  • uspace/app/taskdump/elf_core.c

    rb32c604f red903174  
    6262#include "include/elf_core.h"
    6363
    64 static off_t align_foff_up(off_t foff, uintptr_t vaddr, size_t page_size);
     64static off64_t align_foff_up(off64_t foff, uintptr_t vaddr, size_t page_size);
    6565static int write_all(int fd, void *data, size_t len);
    6666static int write_mem_area(int fd, as_area_info_t *area, int phoneid);
     
    7979 *                      ENOMEM on out of memory, EIO on write error.
    8080 */
    81 int elf_core_save(const char *file_name, as_area_info_t *ainfo, int n, int phoneid)
     81int elf_core_save(const char *file_name, as_area_info_t *ainfo, unsigned int n, int phoneid)
    8282{
    8383        elf_header_t elf_hdr;
    84         off_t foff;
     84        off64_t foff;
    8585        size_t n_ph;
    8686        elf_word flags;
     
    8989        int fd;
    9090        int rc;
    91         int i;
     91        unsigned int i;
    9292
    9393        n_ph = n;
     
    184184
    185185        for (i = 0; i < n_ph; ++i) {
    186                 if (lseek(fd, p_hdr[i].p_offset, SEEK_SET) == (off_t) -1) {
     186                if (lseek(fd, p_hdr[i].p_offset, SEEK_SET) == (off64_t) -1) {
    187187                        printf("Failed writing memory data.\n");
    188188                        free(p_hdr);
     
    202202
    203203/** Align file offset up to be congruent with vaddr modulo page size. */
    204 static off_t align_foff_up(off_t foff, uintptr_t vaddr, size_t page_size)
    205 {
    206         off_t rfo, rva;
    207         off_t advance;
    208 
    209         rva = vaddr % page_size;
    210         rfo = foff % page_size;
    211 
    212         advance = (rva >= rfo) ? rva - rfo : (page_size + rva - rfo);
    213         return foff + advance;
     204static off64_t align_foff_up(off64_t foff, uintptr_t vaddr, size_t page_size)
     205{
     206        off64_t rva = vaddr % page_size;
     207        off64_t rfo = foff % page_size;
     208       
     209        if (rva >= rfo)
     210                return (foff + (rva - rfo));
     211       
     212        return (foff + (page_size + (rva - rfo)));
    214213}
    215214
  • uspace/app/taskdump/include/elf_core.h

    rb32c604f red903174  
    3636#define ELF_CORE_H_
    3737
    38 int elf_core_save(const char *file_name, as_area_info_t *ainfo, int n, int phoneid);
     38int elf_core_save(const char *file_name, as_area_info_t *ainfo, unsigned int n, int phoneid);
    3939
    4040#endif
  • uspace/app/taskdump/symtab.c

    rb32c604f red903174  
    4949static int section_hdr_load(int fd, const elf_header_t *ehdr, int idx,
    5050    elf_section_header_t *shdr);
    51 static int chunk_load(int fd, off_t start, off_t size, void **ptr);
     51static int chunk_load(int fd, off64_t start, size_t size, void **ptr);
    5252static int read_all(int fd, void *buf, size_t len);
    5353
     
    6565        elf_header_t elf_hdr;
    6666        elf_section_header_t sec_hdr;
    67         off_t shstrt_start, shstrt_size;
     67        off64_t shstrt_start;
     68        size_t shstrt_size;
    6869        char *shstrt, *sec_name;
    6970        void *data;
     
    307308        rc = lseek(fd, elf_hdr->e_shoff + idx * sizeof(elf_section_header_t),
    308309            SEEK_SET);
    309         if (rc == (off_t) -1)
     310        if (rc == (off64_t) -1)
    310311                return EIO;
    311312
     
    328329 * @return              EOK on success or EIO on failure.
    329330 */
    330 static int chunk_load(int fd, off_t start, off_t size, void **ptr)
     331static int chunk_load(int fd, off64_t start, size_t size, void **ptr)
    331332{
    332333        int rc;
    333334
    334335        rc = lseek(fd, start, SEEK_SET);
    335         if (rc == (off_t) -1) {
     336        if (rc == (off64_t) -1) {
    336337                printf("failed seeking chunk\n");
    337338                *ptr = NULL;
Note: See TracChangeset for help on using the changeset viewer.