Changeset ed903174 in mainline


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)

Location:
uspace
Files:
38 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;
  • uspace/lib/libblock/libblock.c

    rb32c604f 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
  • uspace/lib/libblock/libblock.h

    rb32c604f red903174  
    7474        dev_handle_t dev_handle;
    7575        /** Block offset on the block device. Counted in 'size'-byte blocks. */
    76         bn_t boff;
     76        aoff64_t boff;
    7777        /** Size of the block. */
    7878        size_t size;
     
    9696extern void block_fini(dev_handle_t);
    9797
    98 extern int block_bb_read(dev_handle_t, bn_t);
     98extern int block_bb_read(dev_handle_t, aoff64_t);
    9999extern void *block_bb_get(dev_handle_t);
    100100
     
    102102extern int block_cache_fini(dev_handle_t);
    103103
    104 extern int block_get(block_t **, dev_handle_t, bn_t, int);
     104extern int block_get(block_t **, dev_handle_t, aoff64_t, int);
    105105extern int block_put(block_t *);
    106106
    107 extern int block_seqread(dev_handle_t, off_t *, size_t *, off_t *, void *,
     107extern int block_seqread(dev_handle_t, size_t *, size_t *, aoff64_t *, void *,
    108108    size_t);
    109109
    110110extern int block_get_bsize(dev_handle_t, size_t *);
    111 extern int block_get_nblocks(dev_handle_t, bn_t *);
    112 extern int block_read_direct(dev_handle_t, bn_t, size_t, void *);
    113 extern int block_write_direct(dev_handle_t, bn_t, size_t, const void *);
     111extern int block_get_nblocks(dev_handle_t, aoff64_t *);
     112extern int block_read_direct(dev_handle_t, aoff64_t, size_t, void *);
     113extern int block_write_direct(dev_handle_t, aoff64_t, size_t, const void *);
    114114
    115115#endif
  • uspace/lib/libc/generic/io/io.c

    rb32c604f red903174  
    541541}
    542542
    543 int fseek(FILE *stream, long offset, int origin)
    544 {
    545         off_t rc = lseek(stream->fd, offset, origin);
    546         if (rc == (off_t) (-1)) {
    547                 /* errno has been set by lseek. */
     543int fseek(FILE *stream, off64_t offset, int whence)
     544{
     545        off64_t rc = lseek(stream->fd, offset, whence);
     546        if (rc == (off64_t) (-1)) {
     547                /* errno has been set by lseek64. */
    548548                return -1;
    549549        }
     
    554554}
    555555
    556 int 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;
     556off64_t ftell(FILE *stream)
     557{
     558        return lseek(stream->fd, 0, SEEK_CUR);
    565559}
    566560
  • uspace/lib/libc/generic/mman.c

    rb32c604f red903174  
    3939
    4040void *mmap(void *start, size_t length, int prot, int flags, int fd,
    41     off_t offset)
     41    aoff64_t offset)
    4242{
    4343        if (!start)
  • uspace/lib/libc/generic/vfs/vfs.c

    rb32c604f red903174  
    3535#include <vfs/vfs.h>
    3636#include <vfs/canonify.h>
     37#include <macros.h>
    3738#include <stdlib.h>
    3839#include <unistd.h>
     
    434435}
    435436
    436 off_t lseek(int fildes, off_t offset, int whence)
    437 {
    438         ipcarg_t rc;
    439 
    440         futex_down(&vfs_phone_futex);
    441         async_serialize_start();
    442         vfs_connect();
    443        
    444         ipcarg_t newoffs;
    445         rc = async_req_3_1(vfs_phone, VFS_IN_SEEK, fildes, offset, whence,
    446             &newoffs);
    447 
    448         async_serialize_end();
    449         futex_up(&vfs_phone_futex);
    450 
     437off64_t lseek(int fildes, off64_t offset, int whence)
     438{
     439        futex_down(&vfs_phone_futex);
     440        async_serialize_start();
     441        vfs_connect();
     442       
     443        ipcarg_t newoff_lo;
     444        ipcarg_t newoff_hi;
     445        ipcarg_t rc = async_req_4_2(vfs_phone, VFS_IN_SEEK, fildes,
     446            LOWER32(offset), UPPER32(offset), whence,
     447            &newoff_lo, &newoff_hi);
     448       
     449        async_serialize_end();
     450        futex_up(&vfs_phone_futex);
     451       
    451452        if (rc != EOK)
    452                 return (off_t) -1;
    453        
    454         return (off_t) newoffs;
    455 }
    456 
    457 int ftruncate(int fildes, off_t length)
    458 {
    459         ipcarg_t rc;
    460        
    461         futex_down(&vfs_phone_futex);
    462         async_serialize_start();
    463         vfs_connect();
    464        
    465         rc = async_req_2_0(vfs_phone, VFS_IN_TRUNCATE, fildes, length);
    466         async_serialize_end();
    467         futex_up(&vfs_phone_futex);
     453                return (off64_t) -1;
     454       
     455        return (off64_t) MERGE_LOUP32(newoff_lo, newoff_hi);
     456}
     457
     458int ftruncate(int fildes, aoff64_t length)
     459{
     460        ipcarg_t rc;
     461       
     462        futex_down(&vfs_phone_futex);
     463        async_serialize_start();
     464        vfs_connect();
     465       
     466        rc = async_req_3_0(vfs_phone, VFS_IN_TRUNCATE, fildes,
     467            LOWER32(length), UPPER32(length));
     468        async_serialize_end();
     469        futex_up(&vfs_phone_futex);
     470       
    468471        return (int) rc;
    469472}
     
    479482       
    480483        req = async_send_1(vfs_phone, VFS_IN_FSTAT, fildes, NULL);
    481         rc = async_data_read_start(vfs_phone, (void *)stat, sizeof(struct stat));
     484        rc = async_data_read_start(vfs_phone, (void *) stat, sizeof(struct stat));
    482485        if (rc != EOK) {
    483486                ipcarg_t rc_orig;
     
    553556        if (!abs) {
    554557                free(dirp);
    555                 return ENOMEM;
     558                return NULL;
    556559        }
    557560       
  • uspace/lib/libc/include/limits.h

    rb32c604f red903174  
    4646
    4747#ifdef __CHAR_UNSIGNED__
    48 # define CHAR_MIN UCHAR_MIN
    49 # define CHAR_MAX UCHAR_MAX
     48        #define CHAR_MIN UCHAR_MIN
     49        #define CHAR_MAX UCHAR_MAX
    5050#else
    51 # define CHAR_MIN SCHAR_MIN
    52 # define CHAR_MAX SCHAR_MAX
     51        #define CHAR_MIN SCHAR_MIN
     52        #define CHAR_MAX SCHAR_MAX
    5353#endif
    5454
     
    5959#define USHRT_MAX MAX_UINT16
    6060
     61/* int */
    6162#define INT_MIN MIN_INT32
    6263#define INT_MAX MAX_INT32
     
    6465#define UINT_MAX MAX_UINT32
    6566
     67/* long long int */
    6668#define LLONG_MIN MIN_INT64
    6769#define LLONG_MAX MAX_INT64
     
    6971#define ULLONG_MAX MAX_UINT64
    7072
     73/* off64_t */
     74#define OFF64_MIN MIN_INT64
     75#define OFF64_MAX MAX_INT64
     76
     77/* aoff64_t */
     78#define AOFF64_MIN MIN_UINT64
     79#define AOFF64_MAX MAX_UINT64
     80
    7181#endif
    7282
  • uspace/lib/libc/include/stdio.h

    rb32c604f red903174  
    4646#define BUFSIZ  4096
    4747
    48 #define DEBUG(fmt, ...) \
     48#define DEBUG(fmt, ...)se\
    4949        { \
    5050                char _buf[256]; \
     
    5656#ifndef SEEK_SET
    5757        #define SEEK_SET  0
     58#endif
     59
     60#ifndef SEEK_CUR
    5861        #define SEEK_CUR  1
     62#endif
     63
     64#ifndef SEEK_END
    5965        #define SEEK_END  2
    6066#endif
     
    135141extern size_t fwrite(const void *, size_t, size_t, FILE *);
    136142
    137 extern int fseek(FILE *, long, int);
     143extern int fseek(FILE *, off64_t, int);
    138144extern void rewind(FILE *);
    139 extern int ftell(FILE *);
     145extern off64_t ftell(FILE *);
    140146extern int feof(FILE *);
    141147
  • uspace/lib/libc/include/sys/mman.h

    rb32c604f red903174  
    4141#define MAP_FAILED  ((void *) -1)
    4242
    43 #define MAP_SHARED       (1 << 0)
    44 #define MAP_PRIVATE      (1 << 1)
    45 #define MAP_FIXED        (1 << 2)
    46 #define MAP_ANONYMOUS    (1 << 3)
     43#define MAP_SHARED     (1 << 0)
     44#define MAP_PRIVATE    (1 << 1)
     45#define MAP_FIXED      (1 << 2)
     46#define MAP_ANONYMOUS  (1 << 3)
    4747
    4848#define PROTO_READ   AS_AREA_READ
     
    5050#define PROTO_EXEC   AS_AREA_EXEC
    5151
    52 extern void *mmap(void  *start, size_t length, int prot, int flags, int fd,
    53     off_t offset);
     52extern void *mmap(void *start, size_t length, int prot, int flags, int fd,
     53    aoff64_t offset);
    5454extern int munmap(void *start, size_t length);
    5555
  • uspace/lib/libc/include/sys/stat.h

    rb32c604f red903174  
    3131 */
    3232/** @file
    33  */ 
     33 */
    3434
    3535#ifndef LIBC_SYS_STAT_H_
     
    4848        bool is_file;
    4949        bool is_directory;
    50         off_t size;
     50        aoff64_t size;
    5151        dev_handle_t device;
    5252};
  • uspace/lib/libc/include/sys/typefmt.h

    rb32c604f red903174  
    3939#include <inttypes.h>
    4040
    41 /* off_t */
    42 #define PRIdOFF "ld"
    43 #define PRIuOFF "lu"
    44 #define PRIxOFF "lx"
    45 #define PRIXOFF "lX"
    46 
    47 /* bn_t */
    48 #define PRIdBN PRId64
    49 #define PRIuBN PRIu64
    50 #define PRIxBN PRIx64
    51 #define PRIXBN PRIX64
     41/* off64_t */
     42#define PRIdOFF64 PRId64
     43#define PRIuOFF64 PRIu64
     44#define PRIxOFF64 PRIx64
     45#define PRIXOFF64 PRIX64
    5246
    5347/* (s)size_t */
  • uspace/lib/libc/include/sys/types.h

    rb32c604f red903174  
    3838#include <libarch/types.h>
    3939
    40 typedef long off_t;
    41 typedef int mode_t;
    42 typedef uint64_t bn_t;  /**< Block number type. */
     40typedef unsigned int mode_t;
    4341
     42/** Relative offset */
     43typedef int64_t off64_t;
     44
     45/** Absolute offset */
     46typedef uint64_t aoff64_t;
     47
     48/** Unicode code point */
    4449typedef int32_t wchar_t;
    4550
  • uspace/lib/libc/include/unistd.h

    rb32c604f red903174  
    4747#ifndef SEEK_SET
    4848        #define SEEK_SET  0
     49#endif
     50
     51#ifndef SEEK_CUR
    4952        #define SEEK_CUR  1
     53#endif
     54
     55#ifndef SEEK_END
    5056        #define SEEK_END  2
    5157#endif
     
    5864extern ssize_t read(int, void *, size_t);
    5965
    60 extern off_t lseek(int, off_t, int);
    61 extern int ftruncate(int, off_t);
     66extern off64_t lseek(int, off64_t, int);
     67extern int ftruncate(int, aoff64_t);
    6268
    6369extern int close(int);
     
    6975extern int chdir(const char *);
    7076
    71 extern void _exit(int status) __attribute__ ((noreturn));
    72 extern int usleep(useconds_t uses);
    73 extern unsigned int sleep(unsigned int se);
     77extern void _exit(int) __attribute__((noreturn));
     78extern int usleep(useconds_t);
     79extern unsigned int sleep(unsigned int);
    7480
    7581#endif
  • uspace/lib/libfs/libfs.c

    rb32c604f red903174  
    3737#include "libfs.h"
    3838#include "../../srv/vfs/vfs.h"
     39#include <macros.h>
    3940#include <errno.h>
    4041#include <async.h>
     
    398399                                                ipc_answer_0(rid, rc);
    399400                                        } else {
    400                                                 ipc_answer_5(rid, EOK,
    401                                                     fs_handle, dev_handle,
     401                                                aoff64_t size = ops->size_get(fn);
     402                                                ipc_answer_5(rid, fs_handle,
     403                                                    dev_handle,
    402404                                                    ops->index_get(fn),
    403                                                     ops->size_get(fn),
     405                                                    LOWER32(size),
     406                                                    UPPER32(size),
    404407                                                    ops->lnkcnt_get(fn));
    405408                                                (void) ops->node_put(fn);
     
    478481                                        ipc_answer_0(rid, rc);
    479482                                } else {
    480                                         ipc_answer_5(rid, EOK,
    481                                             fs_handle, dev_handle,
     483                                        aoff64_t size = ops->size_get(fn);
     484                                        ipc_answer_5(rid, fs_handle,
     485                                            dev_handle,
    482486                                            ops->index_get(fn),
    483                                             ops->size_get(fn),
     487                                            LOWER32(size),
     488                                            UPPER32(size),
    484489                                            ops->lnkcnt_get(fn));
    485490                                        (void) ops->node_put(fn);
     
    501506                unsigned int old_lnkcnt = ops->lnkcnt_get(cur);
    502507                rc = ops->unlink(par, cur, component);
    503                 ipc_answer_5(rid, (ipcarg_t) rc, fs_handle, dev_handle,
    504                     ops->index_get(cur), ops->size_get(cur), old_lnkcnt);
     508               
     509                if (rc == EOK) {
     510                        aoff64_t size = ops->size_get(cur);
     511                        ipc_answer_5(rid, fs_handle, dev_handle,
     512                            ops->index_get(cur), LOWER32(size), UPPER32(size),
     513                            old_lnkcnt);
     514                } else
     515                        ipc_answer_0(rid, rc);
     516               
    505517                goto out;
    506518        }
     
    533545                        rc = ops->node_open(cur);
    534546               
    535                 ipc_answer_5(rid, rc, fs_handle, dev_handle,
    536                     ops->index_get(cur), ops->size_get(cur),
    537                     ops->lnkcnt_get(cur));
     547                if (rc == EOK) {
     548                        aoff64_t size = ops->size_get(cur);
     549                        ipc_answer_5(rid, fs_handle, dev_handle,
     550                            ops->index_get(cur), LOWER32(size), UPPER32(size),
     551                            ops->lnkcnt_get(cur));
     552                } else
     553                        ipc_answer_0(rid, rc);
     554               
    538555        } else
    539556                ipc_answer_0(rid, rc);
     
    602619        dev_handle_t dev_handle = IPC_GET_ARG1(*request);
    603620        fs_index_t index = IPC_GET_ARG2(*request);
     621       
    604622        fs_node_t *fn;
    605         int rc;
    606        
    607         rc = ops->node_get(&fn, dev_handle, index);
     623        int rc = ops->node_get(&fn, dev_handle, index);
    608624        on_error(rc, answer_and_return(rid, rc));
    609625       
     
    614630       
    615631        rc = ops->node_open(fn);
    616         ipc_answer_3(rid, rc, ops->size_get(fn), ops->lnkcnt_get(fn),
     632        aoff64_t size = ops->size_get(fn);
     633        ipc_answer_4(rid, rc, LOWER32(size), UPPER32(size), ops->lnkcnt_get(fn),
    617634            (ops->is_file(fn) ? L_FILE : 0) | (ops->is_directory(fn) ? L_DIRECTORY : 0));
    618635       
  • uspace/lib/libfs/libfs.h

    rb32c604f red903174  
    7676         */
    7777        fs_index_t (* index_get)(fs_node_t *);
    78         size_t (* size_get)(fs_node_t *);
     78        aoff64_t (* size_get)(fs_node_t *);
    7979        unsigned int (* lnkcnt_get)(fs_node_t *);
    8080        char (* plb_get_char)(unsigned pos);
  • uspace/srv/bd/file_bd/file_bd.c

    rb32c604f red903174  
    5757
    5858static const size_t block_size = 512;
    59 static bn_t num_blocks;
     59static aoff64_t num_blocks;
    6060static FILE *img;
    6161
     
    210210        /* Check whether access is within device address bounds. */
    211211        if (ba + cnt > num_blocks) {
    212                 printf(NAME ": Accessed blocks %" PRIuBN "-%" PRIuBN ", while "
    213                     "max block number is %" PRIuBN ".\n", ba, ba + cnt - 1,
     212                printf(NAME ": Accessed blocks %" PRIuOFF64 "-%" PRIuOFF64 ", while "
     213                    "max block number is %" PRIuOFF64 ".\n", ba, ba + cnt - 1,
    214214                    num_blocks - 1);
    215215                return ELIMIT;
     
    248248        /* Check whether access is within device address bounds. */
    249249        if (ba + cnt > num_blocks) {
    250                 printf(NAME ": Accessed blocks %" PRIuBN "-%" PRIuBN ", while "
    251                     "max block number is %" PRIuBN ".\n", ba, ba + cnt - 1,
     250                printf(NAME ": Accessed blocks %" PRIuOFF64 "-%" PRIuOFF64 ", while "
     251                    "max block number is %" PRIuOFF64 ".\n", ba, ba + cnt - 1,
    252252                    num_blocks - 1);
    253253                return ELIMIT;
  • 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)
  • uspace/srv/bd/part/mbr_part/mbr_part.c

    rb32c604f red903174  
    9797        bool present;
    9898        /** Address of first block */
    99         bn_t start_addr;
     99        aoff64_t start_addr;
    100100        /** Number of blocks */
    101         bn_t length;
     101        aoff64_t length;
    102102        /** Device representing the partition (outbound device) */
    103103        dev_handle_t dev;
     
    249249                size_mb = (part->length * block_size + 1024 * 1024 - 1)
    250250                    / (1024 * 1024);
    251                 printf(NAME ": Registered device %s: %" PRIuBN " blocks "
     251                printf(NAME ": Registered device %s: %" PRIuOFF64 " blocks "
    252252                    "%" PRIu64 " MB.\n", name, part->length, size_mb);
    253253
  • uspace/srv/clip/clip.c

    rb32c604f red903174  
    145145       
    146146        fibril_mutex_unlock(&clip_mtx);
    147         ipc_answer_2(rid, EOK, (ipcarg_t) size, (ipcarg_t) clip_tag);
     147        ipc_answer_2(rid, EOK, (ipcarg_t) size, (ipcarg_t) tag);
    148148}
    149149
  • uspace/srv/fs/devfs/devfs_ops.c

    rb32c604f red903174  
    3737
    3838#include <ipc/ipc.h>
     39#include <macros.h>
    3940#include <bool.h>
    4041#include <errno.h>
     
    337338}
    338339
    339 static size_t devfs_size_get(fs_node_t *fn)
     340static aoff64_t devfs_size_get(fs_node_t *fn)
    340341{
    341342        return 0;
     
    463464{
    464465        fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
    465         off_t pos = (off_t) IPC_GET_ARG3(*request);
     466        aoff64_t pos =
     467            (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request), IPC_GET_ARG4(*request));
    466468       
    467469        if (index == 0) {
     
    597599{
    598600        fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
    599         off_t pos = (off_t) IPC_GET_ARG3(*request);
    600        
    601601        if (index == 0) {
    602602                ipc_answer_0(rid, ENOTSUP);
  • uspace/srv/fs/fat/fat.h

    rb32c604f red903174  
    8989                        uint16_t        signature;
    9090                } __attribute__ ((packed));
    91                 struct fat32 {
     91                struct {
    9292                        /* FAT32 only */
    9393                        /** Sectors per FAT. */
     
    119119                        /** Signature. */
    120120                        uint16_t        signature;
    121                 } __attribute__ ((packed));
    122         }; 
     121                } fat32 __attribute__ ((packed));
     122        };
    123123} __attribute__ ((packed)) fat_bs_t;
    124124
     
    194194        /** FAT in-core node free list link. */
    195195        link_t                  ffn_link;
    196         size_t                  size;
     196        aoff64_t                size;
    197197        unsigned                lnkcnt;
    198198        unsigned                refcnt;
  • uspace/srv/fs/fat/fat_dentry.c

    rb32c604f red903174  
    8282bool fat_dentry_name_verify(const char *name)
    8383{
    84         unsigned i, dot;
     84        unsigned int i;
     85        unsigned int dot = 0;
    8586        bool dot_found = false;
    8687       
  • uspace/srv/fs/fat/fat_fat.c

    rb32c604f red903174  
    9393
    9494        while (clst < FAT_CLST_LAST1 && clusters < max_clusters) {
    95                 bn_t fsec;      /* sector offset relative to FAT1 */
     95                aoff64_t fsec;  /* sector offset relative to FAT1 */
    9696                unsigned fidx;  /* FAT1 entry index */
    9797
     
    135135int
    136136_fat_block_get(block_t **block, fat_bs_t *bs, dev_handle_t dev_handle,
    137     fat_cluster_t firstc, bn_t bn, int flags)
     137    fat_cluster_t firstc, aoff64_t bn, int flags)
    138138{
    139139        unsigned bps;
     
    196196 * @return              EOK on success or a negative error code.
    197197 */
    198 int fat_fill_gap(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t mcl, off_t pos)
     198int fat_fill_gap(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t mcl, aoff64_t pos)
    199199{
    200200        uint16_t bps;
    201201        unsigned spc;
    202202        block_t *b;
    203         off_t o, boundary;
     203        aoff64_t o, boundary;
    204204        int rc;
    205205
  • uspace/srv/fs/fat/fat_fat.h

    rb32c604f red903174  
    6969
    7070extern int _fat_block_get(block_t **, struct fat_bs *, dev_handle_t,
    71     fat_cluster_t, bn_t, int);
    72  
     71    fat_cluster_t, aoff64_t, int);
     72
    7373extern int fat_append_clusters(struct fat_bs *, struct fat_node *,
    7474    fat_cluster_t);
     
    8585    fat_cluster_t, fat_cluster_t);
    8686extern int fat_fill_gap(struct fat_bs *, struct fat_node *, fat_cluster_t,
    87     off_t);
     87    aoff64_t);
    8888extern int fat_zero_cluster(struct fat_bs *, dev_handle_t, fat_cluster_t);
    8989extern int fat_sanity_check(struct fat_bs *, dev_handle_t);
  • uspace/srv/fs/fat/fat_ops.c

    rb32c604f red903174  
    4545#include <ipc/services.h>
    4646#include <ipc/devmap.h>
     47#include <macros.h>
    4748#include <async.h>
    4849#include <errno.h>
     
    7980static int fat_has_children(bool *, fs_node_t *);
    8081static fs_index_t fat_index_get(fs_node_t *);
    81 static size_t fat_size_get(fs_node_t *);
     82static aoff64_t fat_size_get(fs_node_t *);
    8283static unsigned fat_lnkcnt_get(fs_node_t *);
    8384static char fat_plb_get_char(unsigned);
     
    738739                        goto skip_dots;
    739740                }
    740                 d = (fat_dentry_t *)b->data;
    741                 if (fat_classify_dentry(d) == FAT_DENTRY_LAST ||
    742                     str_cmp(d->name, FAT_NAME_DOT) == 0) {
     741                d = (fat_dentry_t *) b->data;
     742                if ((fat_classify_dentry(d) == FAT_DENTRY_LAST) ||
     743                    (str_cmp((char *) d->name, FAT_NAME_DOT)) == 0) {
    743744                        memset(d, 0, sizeof(fat_dentry_t));
    744                         str_cpy(d->name, 8, FAT_NAME_DOT);
    745                         str_cpy(d->ext, 3, FAT_EXT_PAD);
     745                        str_cpy((char *) d->name, 8, FAT_NAME_DOT);
     746                        str_cpy((char *) d->ext, 3, FAT_EXT_PAD);
    746747                        d->attr = FAT_ATTR_SUBDIR;
    747748                        d->firstc = host2uint16_t_le(childp->firstc);
     
    749750                }
    750751                d++;
    751                 if (fat_classify_dentry(d) == FAT_DENTRY_LAST ||
    752                     str_cmp(d->name, FAT_NAME_DOT_DOT) == 0) {
     752                if ((fat_classify_dentry(d) == FAT_DENTRY_LAST) ||
     753                    (str_cmp((char *) d->name, FAT_NAME_DOT_DOT) == 0)) {
    753754                        memset(d, 0, sizeof(fat_dentry_t));
    754                         str_cpy(d->name, 8, FAT_NAME_DOT_DOT);
    755                         str_cpy(d->ext, 3, FAT_EXT_PAD);
     755                        str_cpy((char *) d->name, 8, FAT_NAME_DOT_DOT);
     756                        str_cpy((char *) d->ext, 3, FAT_EXT_PAD);
    756757                        d->attr = FAT_ATTR_SUBDIR;
    757758                        d->firstc = (parentp->firstc == FAT_CLST_ROOT) ?
     
    915916}
    916917
    917 size_t fat_size_get(fs_node_t *fn)
     918aoff64_t fat_size_get(fs_node_t *fn)
    918919{
    919920        return FAT_NODE(fn)->size;
     
    11571158void fat_read(ipc_callid_t rid, ipc_call_t *request)
    11581159{
    1159         dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request);
    1160         fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request);
    1161         off_t pos = (off_t)IPC_GET_ARG3(*request);
     1160        dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
     1161        fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
     1162        aoff64_t pos =
     1163            (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request), IPC_GET_ARG4(*request));
    11621164        fs_node_t *fn;
    11631165        fat_node_t *nodep;
     
    12231225        } else {
    12241226                unsigned bnum;
    1225                 off_t spos = pos;
     1227                aoff64_t spos = pos;
    12261228                char name[FAT_NAME_LEN + 1 + FAT_EXT_LEN + 1];
    12271229                fat_dentry_t *d;
     
    12391241                bnum = (pos * sizeof(fat_dentry_t)) / bps;
    12401242                while (bnum < nodep->size / bps) {
    1241                         off_t o;
     1243                        aoff64_t o;
    12421244
    12431245                        rc = fat_block_get(&b, bs, nodep, bnum,
     
    12951297void fat_write(ipc_callid_t rid, ipc_call_t *request)
    12961298{
    1297         dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request);
    1298         fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request);
    1299         off_t pos = (off_t)IPC_GET_ARG3(*request);
     1299        dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
     1300        fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
     1301        aoff64_t pos =
     1302            (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request), IPC_GET_ARG4(*request));
    13001303        fs_node_t *fn;
    13011304        fat_node_t *nodep;
     
    13061309        unsigned spc;
    13071310        unsigned bpc;           /* bytes per cluster */
    1308         off_t boundary;
     1311        aoff64_t boundary;
    13091312        int flags = BLOCK_FLAGS_NONE;
    13101313        int rc;
     
    14521455void fat_truncate(ipc_callid_t rid, ipc_call_t *request)
    14531456{
    1454         dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request);
    1455         fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request);
    1456         size_t size = (off_t)IPC_GET_ARG3(*request);
     1457        dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
     1458        fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
     1459        aoff64_t size =
     1460            (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request), IPC_GET_ARG4(*request));
    14571461        fs_node_t *fn;
    14581462        fat_node_t *nodep;
  • uspace/srv/fs/tmpfs/tmpfs.h

    rb32c604f red903174  
    2929/** @addtogroup fs
    3030 * @{
    31  */ 
     31 */
    3232
    3333#ifndef TMPFS_TMPFS_H_
     
    4040#include <bool.h>
    4141#include <adt/hash_table.h>
    42 
    43 #ifndef dprintf
    44 #define dprintf(...)    printf(__VA_ARGS__)
    45 #endif
    4642
    4743#define TMPFS_NODE(node)        ((node) ? (tmpfs_node_t *)(node)->data : NULL)
  • uspace/srv/fs/tmpfs/tmpfs_dump.c

    rb32c604f red903174  
    5555
    5656static bool
    57 tmpfs_restore_recursion(dev_handle_t dev, off_t *bufpos, size_t *buflen,
    58     off_t *pos, fs_node_t *pfn)
     57tmpfs_restore_recursion(dev_handle_t dev, size_t *bufpos, size_t *buflen,
     58    aoff64_t *pos, fs_node_t *pfn)
    5959{
    6060        struct rdentry entry;
     
    171171                return false;
    172172       
    173         off_t bufpos = 0;
     173        size_t bufpos = 0;
    174174        size_t buflen = 0;
    175         off_t pos = 0;
     175        aoff64_t pos = 0;
    176176       
    177177        char tag[6];
  • uspace/srv/fs/tmpfs/tmpfs_ops.c

    rb32c604f red903174  
    2929/** @addtogroup fs
    3030 * @{
    31  */ 
     31 */
    3232
    3333/**
     
    4040#include "../../vfs/vfs.h"
    4141#include <ipc/ipc.h>
     42#include <macros.h>
     43#include <limits.h>
    4244#include <async.h>
    4345#include <errno.h>
     
    9395}
    9496
    95 static size_t tmpfs_size_get(fs_node_t *fn)
     97static aoff64_t tmpfs_size_get(fs_node_t *fn)
    9698{
    9799        return TMPFS_NODE(fn)->size;
     
    509511void tmpfs_read(ipc_callid_t rid, ipc_call_t *request)
    510512{
    511         dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request);
    512         fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request);
    513         off_t pos = (off_t)IPC_GET_ARG3(*request);
    514 
     513        dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
     514        fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
     515        aoff64_t pos =
     516            (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request), IPC_GET_ARG4(*request));
     517       
    515518        /*
    516519         * Lookup the respective TMPFS node.
     
    528531        tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t,
    529532            nh_link);
    530 
     533       
    531534        /*
    532535         * Receive the read request.
     
    535538        size_t size;
    536539        if (!async_data_read_receive(&callid, &size)) {
    537                 ipc_answer_0(callid, EINVAL);   
     540                ipc_answer_0(callid, EINVAL);
    538541                ipc_answer_0(rid, EINVAL);
    539542                return;
     
    542545        size_t bytes;
    543546        if (nodep->type == TMPFS_FILE) {
    544                 bytes = max(0, min(nodep->size - pos, size));
     547                bytes = min(nodep->size - pos, size);
    545548                (void) async_data_read_finalize(callid, nodep->data + pos,
    546549                    bytes);
     
    548551                tmpfs_dentry_t *dentryp;
    549552                link_t *lnk;
    550                 int i;
     553                aoff64_t i;
    551554               
    552555                assert(nodep->type == TMPFS_DIRECTORY);
     
    558561                 */
    559562                for (i = 0, lnk = nodep->cs_head.next;
    560                     i < pos && lnk != &nodep->cs_head;
     563                    (i < pos) && (lnk != &nodep->cs_head);
    561564                    i++, lnk = lnk->next)
    562565                        ;
     
    583586void tmpfs_write(ipc_callid_t rid, ipc_call_t *request)
    584587{
    585         dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request);
    586         fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request);
    587         off_t pos = (off_t)IPC_GET_ARG3(*request);
    588 
     588        dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
     589        fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
     590        aoff64_t pos =
     591            (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request), IPC_GET_ARG4(*request));
     592       
    589593        /*
    590594         * Lookup the respective TMPFS node.
     
    647651void tmpfs_truncate(ipc_callid_t rid, ipc_call_t *request)
    648652{
     653        dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
     654        fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
     655        aoff64_t size =
     656            (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request), IPC_GET_ARG4(*request));
     657       
     658        /*
     659         * Lookup the respective TMPFS node.
     660         */
     661        unsigned long key[] = {
     662                [NODES_KEY_DEV] = dev_handle,
     663                [NODES_KEY_INDEX] = index
     664        };
     665        link_t *hlp = hash_table_find(&nodes, key);
     666        if (!hlp) {
     667                ipc_answer_0(rid, ENOENT);
     668                return;
     669        }
     670        tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t,
     671            nh_link);
     672       
     673        if (size == nodep->size) {
     674                ipc_answer_0(rid, EOK);
     675                return;
     676        }
     677       
     678        if (size > SIZE_MAX) {
     679                ipc_answer_0(rid, ENOMEM);
     680                return;
     681        }
     682       
     683        void *newdata = realloc(nodep->data, size);
     684        if (!newdata) {
     685                ipc_answer_0(rid, ENOMEM);
     686                return;
     687        }
     688       
     689        if (size > nodep->size) {
     690                size_t delta = size - nodep->size;
     691                memset(newdata + nodep->size, 0, delta);
     692        }
     693       
     694        nodep->size = size;
     695        nodep->data = newdata;
     696        ipc_answer_0(rid, EOK);
     697}
     698
     699void tmpfs_close(ipc_callid_t rid, ipc_call_t *request)
     700{
     701        ipc_answer_0(rid, EOK);
     702}
     703
     704void tmpfs_destroy(ipc_callid_t rid, ipc_call_t *request)
     705{
    649706        dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request);
    650707        fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request);
    651         size_t size = (off_t)IPC_GET_ARG3(*request);
    652 
    653         /*
    654          * Lookup the respective TMPFS node.
    655          */
     708        int rc;
     709
    656710        link_t *hlp;
    657711        unsigned long key[] = {
     
    666720        tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t,
    667721            nh_link);
    668 
    669         if (size == nodep->size) {
    670                 ipc_answer_0(rid, EOK);
    671                 return;
    672         }
    673 
    674         void *newdata = realloc(nodep->data, size);
    675         if (!newdata) {
    676                 ipc_answer_0(rid, ENOMEM);
    677                 return;
    678         }
    679         if (size > nodep->size) {
    680                 size_t delta = size - nodep->size;
    681                 memset(newdata + nodep->size, 0, delta);
    682         }
    683         nodep->size = size;
    684         nodep->data = newdata;
    685         ipc_answer_0(rid, EOK);
    686 }
    687 
    688 void tmpfs_close(ipc_callid_t rid, ipc_call_t *request)
    689 {
    690         ipc_answer_0(rid, EOK);
    691 }
    692 
    693 void tmpfs_destroy(ipc_callid_t rid, ipc_call_t *request)
    694 {
    695         dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request);
    696         fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request);
    697         int rc;
    698 
    699         link_t *hlp;
    700         unsigned long key[] = {
    701                 [NODES_KEY_DEV] = dev_handle,
    702                 [NODES_KEY_INDEX] = index
    703         };
    704         hlp = hash_table_find(&nodes, key);
    705         if (!hlp) {
    706                 ipc_answer_0(rid, ENOENT);
    707                 return;
    708         }
    709         tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t,
    710             nh_link);
    711722        rc = tmpfs_destroy_node(FS_NODE(nodep));
    712723        ipc_answer_0(rid, rc);
  • uspace/srv/vfs/vfs.h

    rb32c604f red903174  
    4242#include <ipc/vfs.h>
    4343
    44 // FIXME: according to CONFIG_DEBUG
    45 // #define dprintf(...)  printf(__VA_ARGS__)
    46 
    47 #define dprintf(...)
     44#ifndef dprintf
     45        #define dprintf(...)
     46#endif
    4847
    4948/**
     
    9392        vfs_triplet_t triplet;
    9493        vfs_node_type_t type;
    95         size_t size;
    96         unsigned lnkcnt;
     94        aoff64_t size;
     95        unsigned int lnkcnt;
    9796} vfs_lookup_res_t;
    9897
     
    117116        vfs_node_type_t type;   /**< Partial info about the node type. */
    118117
    119         size_t size;            /**< Cached size if the node is a file. */
     118        aoff64_t size;          /**< Cached size if the node is a file. */
    120119
    121120        /**
     
    141140        bool append;
    142141
    143         /** Current position in the file. */
    144         off_t pos;
     142        /** Current absolute position in the file. */
     143        aoff64_t pos;
    145144} vfs_file_t;
    146145
     
    214213extern void vfs_truncate(ipc_callid_t, ipc_call_t *);
    215214extern void vfs_fstat(ipc_callid_t, ipc_call_t *);
    216 extern void vfs_fstat(ipc_callid_t, ipc_call_t *);
    217215extern void vfs_stat(ipc_callid_t, ipc_call_t *);
    218216extern void vfs_mkdir(ipc_callid_t, ipc_call_t *);
  • uspace/srv/vfs/vfs_lookup.c

    rb32c604f red903174  
    3838#include "vfs.h"
    3939#include <ipc/ipc.h>
     40#include <macros.h>
    4041#include <async.h>
    4142#include <errno.h>
     
    99100        entry.len = len;
    100101
    101         off_t first;    /* the first free index */
    102         off_t last;     /* the last free index */
     102        size_t first;   /* the first free index */
     103        size_t last;    /* the last free index */
    103104
    104105        if (list_empty(&plb_head)) {
     
    177178        memset(plb, 0, cnt2);
    178179        fibril_mutex_unlock(&plb_mutex);
    179 
    180         if ((rc == EOK) && (result)) {
    181                 result->triplet.fs_handle = (fs_handle_t) IPC_GET_ARG1(answer);
    182                 result->triplet.dev_handle = (dev_handle_t) IPC_GET_ARG2(answer);
    183                 result->triplet.index = (fs_index_t) IPC_GET_ARG3(answer);
    184                 result->size = (size_t) IPC_GET_ARG4(answer);
    185                 result->lnkcnt = (unsigned) IPC_GET_ARG5(answer);
    186                 if (lflag & L_FILE)
    187                         result->type = VFS_NODE_FILE;
    188                 else if (lflag & L_DIRECTORY)
    189                         result->type = VFS_NODE_DIRECTORY;
    190                 else
    191                         result->type = VFS_NODE_UNKNOWN;
    192         }
    193 
    194         return rc;
     180       
     181        if (((int) rc < EOK) || (!result))
     182                return (int) rc;
     183       
     184        result->triplet.fs_handle = (fs_handle_t) rc;
     185        result->triplet.dev_handle = (dev_handle_t) IPC_GET_ARG1(answer);
     186        result->triplet.index = (fs_index_t) IPC_GET_ARG2(answer);
     187        result->size =
     188            (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(answer), IPC_GET_ARG4(answer));
     189        result->lnkcnt = (unsigned int) IPC_GET_ARG5(answer);
     190       
     191        if (lflag & L_FILE)
     192                result->type = VFS_NODE_FILE;
     193        else if (lflag & L_DIRECTORY)
     194                result->type = VFS_NODE_DIRECTORY;
     195        else
     196                result->type = VFS_NODE_UNKNOWN;
     197       
     198        return EOK;
    195199}
    196200
     
    214218       
    215219        if (rc == EOK) {
    216                 result->size = (size_t) IPC_GET_ARG1(answer);
    217                 result->lnkcnt = (unsigned) IPC_GET_ARG2(answer);
    218                 if (IPC_GET_ARG3(answer) & L_FILE)
     220                result->size =
     221                    MERGE_LOUP32(IPC_GET_ARG1(answer), IPC_GET_ARG2(answer));
     222                result->lnkcnt = (unsigned int) IPC_GET_ARG3(answer);
     223                if (IPC_GET_ARG4(answer) & L_FILE)
    219224                        result->type = VFS_NODE_FILE;
    220                 else if (IPC_GET_ARG3(answer) & L_DIRECTORY)
     225                else if (IPC_GET_ARG4(answer) & L_DIRECTORY)
    221226                        result->type = VFS_NODE_DIRECTORY;
    222227                else
  • uspace/srv/vfs/vfs_node.c

    rb32c604f red903174  
    242242{
    243243        vfs_node_t *node = hash_table_get_instance(item, vfs_node_t, nh_link);
    244         return (node->fs_handle == key[KEY_FS_HANDLE]) &&
     244        return (node->fs_handle == (fs_handle_t) key[KEY_FS_HANDLE]) &&
    245245            (node->dev_handle == key[KEY_DEV_HANDLE]) &&
    246246            (node->index == key[KEY_INDEX]);
  • uspace/srv/vfs/vfs_ops.c

    rb32c604f red903174  
    3838#include "vfs.h"
    3939#include <ipc/ipc.h>
     40#include <macros.h>
     41#include <limits.h>
    4042#include <async.h>
    4143#include <errno.h>
     
    5355
    5456/* Forward declarations of static functions. */
    55 static int vfs_truncate_internal(fs_handle_t, dev_handle_t, fs_index_t, size_t);
     57static int vfs_truncate_internal(fs_handle_t, dev_handle_t, fs_index_t, aoff64_t);
    5658
    5759/**
     
    353355        vfs_lookup_res_t mp_res;
    354356        vfs_lookup_res_t mr_res;
    355         vfs_node_t *mp_node;
    356357        vfs_node_t *mr_node;
    357358        int phone;
     
    503504        int oflag = IPC_GET_ARG2(*request);
    504505        int mode = IPC_GET_ARG3(*request);
    505         size_t len;
    506506
    507507        /* Ignore mode for now. */
     
    887887{
    888888        int fd = (int) IPC_GET_ARG1(*request);
    889         off_t off = (off_t) IPC_GET_ARG2(*request);
    890         int whence = (int) IPC_GET_ARG3(*request);
    891 
    892 
     889        off64_t off =
     890            (off64_t) MERGE_LOUP32(IPC_GET_ARG2(*request), IPC_GET_ARG3(*request));
     891        int whence = (int) IPC_GET_ARG4(*request);
     892       
    893893        /* Lookup the file structure corresponding to the file descriptor. */
    894894        vfs_file_t *file = vfs_file_get(fd);
     
    897897                return;
    898898        }
    899 
    900         off_t newpos;
     899       
    901900        fibril_mutex_lock(&file->lock);
    902         if (whence == SEEK_SET) {
    903                 file->pos = off;
    904                 fibril_mutex_unlock(&file->lock);
    905                 ipc_answer_1(rid, EOK, off);
    906                 return;
    907         }
    908         if (whence == SEEK_CUR) {
    909                 if (file->pos + off < file->pos) {
     901       
     902        off64_t newoff;
     903        switch (whence) {
     904                case SEEK_SET:
     905                        if (off >= 0) {
     906                                file->pos = (aoff64_t) off;
     907                                fibril_mutex_unlock(&file->lock);
     908                                ipc_answer_1(rid, EOK, off);
     909                                return;
     910                        }
     911                        break;
     912                case SEEK_CUR:
     913                        if ((off >= 0) && (file->pos + off < file->pos)) {
     914                                fibril_mutex_unlock(&file->lock);
     915                                ipc_answer_0(rid, EOVERFLOW);
     916                                return;
     917                        }
     918                       
     919                        if ((off < 0) && (file->pos < (aoff64_t) -off)) {
     920                                fibril_mutex_unlock(&file->lock);
     921                                ipc_answer_0(rid, EOVERFLOW);
     922                                return;
     923                        }
     924                       
     925                        file->pos += off;
     926                        newoff = (file->pos > OFF64_MAX) ? OFF64_MAX : file->pos;
     927                       
    910928                        fibril_mutex_unlock(&file->lock);
    911                         ipc_answer_0(rid, EOVERFLOW);
     929                        ipc_answer_2(rid, EOK, LOWER32(newoff), UPPER32(newoff));
    912930                        return;
    913                 }
    914                 file->pos += off;
    915                 newpos = file->pos;
    916                 fibril_mutex_unlock(&file->lock);
    917                 ipc_answer_1(rid, EOK, newpos);
    918                 return;
    919         }
    920         if (whence == SEEK_END) {
    921                 fibril_rwlock_read_lock(&file->node->contents_rwlock);
    922                 size_t size = file->node->size;
    923                 fibril_rwlock_read_unlock(&file->node->contents_rwlock);
    924                 if (size + off < size) {
     931                case SEEK_END:
     932                        fibril_rwlock_read_lock(&file->node->contents_rwlock);
     933                        aoff64_t size = file->node->size;
     934                       
     935                        if ((off >= 0) && (size + off < size)) {
     936                                fibril_rwlock_read_unlock(&file->node->contents_rwlock);
     937                                fibril_mutex_unlock(&file->lock);
     938                                ipc_answer_0(rid, EOVERFLOW);
     939                                return;
     940                        }
     941                       
     942                        if ((off < 0) && (size < (aoff64_t) -off)) {
     943                                fibril_rwlock_read_unlock(&file->node->contents_rwlock);
     944                                fibril_mutex_unlock(&file->lock);
     945                                ipc_answer_0(rid, EOVERFLOW);
     946                                return;
     947                        }
     948                       
     949                        file->pos = size + off;
     950                        newoff = (file->pos > OFF64_MAX) ? OFF64_MAX : file->pos;
     951                       
     952                        fibril_rwlock_read_unlock(&file->node->contents_rwlock);
    925953                        fibril_mutex_unlock(&file->lock);
    926                         ipc_answer_0(rid, EOVERFLOW);
     954                        ipc_answer_2(rid, EOK, LOWER32(newoff), UPPER32(newoff));
    927955                        return;
    928                 }
    929                 newpos = size + off;
    930                 file->pos = newpos;
    931                 fibril_mutex_unlock(&file->lock);
    932                 ipc_answer_1(rid, EOK, newpos);
    933                 return;
    934         }
     956        }
     957       
    935958        fibril_mutex_unlock(&file->lock);
    936959        ipc_answer_0(rid, EINVAL);
    937960}
    938961
    939 int
    940 vfs_truncate_internal(fs_handle_t fs_handle, dev_handle_t dev_handle,
    941     fs_index_t index, size_t size)
     962int vfs_truncate_internal(fs_handle_t fs_handle, dev_handle_t dev_handle,
     963    fs_index_t index, aoff64_t size)
    942964{
    943965        ipcarg_t rc;
     
    945967       
    946968        fs_phone = vfs_grab_phone(fs_handle);
    947         rc = async_req_3_0(fs_phone, VFS_OUT_TRUNCATE, (ipcarg_t)dev_handle,
    948             (ipcarg_t)index, (ipcarg_t)size);
     969        rc = async_req_4_0(fs_phone, VFS_OUT_TRUNCATE, (ipcarg_t) dev_handle,
     970            (ipcarg_t) index, LOWER32(size), UPPER32(size));
    949971        vfs_release_phone(fs_phone);
    950972        return (int)rc;
     
    954976{
    955977        int fd = IPC_GET_ARG1(*request);
    956         size_t size = IPC_GET_ARG2(*request);
     978        aoff64_t size =
     979            (aoff64_t) MERGE_LOUP32(IPC_GET_ARG2(*request), IPC_GET_ARG3(*request));
    957980        int rc;
    958981
Note: See TracChangeset for help on using the changeset viewer.