Changeset ed903174 in mainline for uspace/srv/fs


Ignore:
Timestamp:
2010-02-10T23:51:23Z (15 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/srv/fs
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • 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);
Note: See TracChangeset for help on using the changeset viewer.