Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset ed903174 in mainline for uspace/srv/vfs/vfs_lookup.c


Ignore:
Timestamp:
2010-02-10T23:51:23Z (12 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master
Children:
e70edd1
Parents:
b32c604
Message:

implement support for 64bit file offsets

  • the libc API is a small deviation from standard, but we have no reason to keep a strict backward compatibility with ancient code so far
    • the basic signed 64bit offset type is called off64_t
      • lseek() and fseek() take off64_t arguments (since the argument represents a relative offset)
      • ftell() returns off64_t values (since it is a wrapper of lseek())
      • vfs_seek() implementation supports negative offsets when SEEK_CUR and SEEK_END is used
    • aoff64_t is used for internal unsigned representation of sizes (in bytes, blocks, etc.) and absolute offsets
      • mmap() and ftruncate() take aoff64_t arguments (since the full range of the absolute file offset should be used here)
      • struct stat stores the file size as aoff64_t
    • in both cases the explicit range of the types shown in the names is helpful for proper filesystem and IPC interaction
    • note: size_t should be used only for representing in-memory sizes and offsets, not device and file-related information, and vice versa
      • the code base still needs a thorough revision with respect to this rule
    • PRIdOFF64 and PRIuOFF64 can be used for printing the offsets
  • VFS_OUT_LOOKUP returns the 64bit file size in two IPC arguments
    • since all 5 IPC arguments have already been taken, the fs_handle is returned as the return value (fs_handle has only 16 bits, thus the return value can be used for both indicating errors as negative values and returning positive handles)
  • VFS_OUT_READ and VFS_OUT_WRITE use aoff64_t absolute offsets split into two IPC arguments

replace bn_t with aoff64_t as a generic 64bit bytes/block counter type

note: filesystem drivers need to be revised with respect to make sure that all out-of-range checks are correct (especially w.r.t. file and block offsets)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/vfs/vfs_lookup.c

    rb32c604 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
Note: See TracChangeset for help on using the changeset viewer.