Changeset ed903174 in mainline for uspace/lib/libfs


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/lib/libfs
Files:
2 edited

Legend:

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