Changeset 58898d1d in mainline for uspace/srv/vfs


Ignore:
Timestamp:
2017-03-24T20:31:54Z (9 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8e9b2534
Parents:
c9e3692
Message:

Remove VFS_IN_SEEK from VFS

Location:
uspace/srv/vfs
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/vfs/vfs.h

    rc9e3692 r58898d1d  
    142142        /** Append on write. */
    143143        bool append;
    144 
    145         /** Current absolute position in the file. */
    146         int64_t pos;
    147144} vfs_file_t;
    148145
     
    190187extern int64_t vfs_node_get_size(vfs_node_t *node);
    191188extern bool vfs_node_has_children(vfs_node_t *node);
    192 
    193 #define MAX_OPEN_FILES  128
    194189
    195190extern void *vfs_client_data_create(void);
     
    216211extern int vfs_op_mtab_get(void);
    217212extern int vfs_op_open2(int fd, int flags);
    218 extern int vfs_op_read(int fd, size_t *out_bytes);
     213extern int vfs_op_read(int fd, aoff64_t, size_t *out_bytes);
    219214extern int vfs_op_rename(int basefd, char *old, char *new);
    220 extern int vfs_op_seek(int fd, int64_t offset, int whence, int64_t *out_offset);
    221215extern int vfs_op_statfs(int fd);
    222216extern int vfs_op_sync(int fd);
     
    226220extern int vfs_op_wait_handle(bool high_fd);
    227221extern int vfs_op_walk(int parentfd, int flags, char *path, int *out_fd);
    228 extern int vfs_op_write(int fd, size_t *out_bytes);
     222extern int vfs_op_write(int fd, aoff64_t, size_t *out_bytes);
    229223
    230224extern void vfs_register(ipc_callid_t, ipc_call_t *);
     
    237231} rdwr_io_chunk_t;
    238232
    239 extern int vfs_rdwr_internal(int, bool, rdwr_io_chunk_t *);
     233extern int vfs_rdwr_internal(int, aoff64_t, bool, rdwr_io_chunk_t *);
    240234
    241235extern void vfs_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg);
  • uspace/srv/vfs/vfs_file.c

    rc9e3692 r58898d1d  
    4545#include <adt/list.h>
    4646#include <task.h>
     47#include <vfs/vfs.h>
    4748#include "vfs.h"
    4849
  • uspace/srv/vfs/vfs_ipc.c

    rc9e3692 r58898d1d  
    122122{
    123123        int fd = IPC_GET_ARG1(*request);
     124        aoff64_t pos = MERGE_LOUP32(IPC_GET_ARG2(*request),
     125            IPC_GET_ARG3(*request));
    124126
    125127        size_t bytes = 0;
    126         int rc = vfs_op_read(fd, &bytes);
     128        int rc = vfs_op_read(fd, pos, &bytes);
    127129        async_answer_1(rid, rc, bytes);
    128130}
     
    170172        if (new)
    171173                free(new);
    172 }
    173 
    174 static void vfs_in_seek(ipc_callid_t rid, ipc_call_t *request)
    175 {
    176         int fd = (int) IPC_GET_ARG1(*request);
    177         int64_t off = (int64_t) MERGE_LOUP32(IPC_GET_ARG2(*request), IPC_GET_ARG3(*request));
    178         int whence = (int) IPC_GET_ARG4(*request);
    179 
    180         int64_t new_offset = 0;
    181         int rc = vfs_op_seek(fd, off, whence, &new_offset);
    182         async_answer_2(rid, rc, LOWER32(new_offset), UPPER32(new_offset));
    183174}
    184175
     
    256247{
    257248        int fd = IPC_GET_ARG1(*request);
     249        aoff64_t pos = MERGE_LOUP32(IPC_GET_ARG2(*request),
     250            IPC_GET_ARG3(*request));
    258251
    259252        size_t bytes = 0;
    260         int rc = vfs_op_write(fd, &bytes);
     253        int rc = vfs_op_write(fd, pos, &bytes);
    261254        async_answer_1(rid, rc, bytes);
    262255}
     
    308301                        vfs_in_rename(callid, &call);
    309302                        break;
    310                 case VFS_IN_SEEK:
    311                         vfs_in_seek(callid, &call);
    312                         break;
    313303                case VFS_IN_STATFS:
    314304                        vfs_in_statfs(callid, &call);
  • uspace/srv/vfs/vfs_ops.c

    rc9e3692 r58898d1d  
    343343}
    344344
    345 typedef int (* rdwr_ipc_cb_t)(async_exch_t *, vfs_file_t *, ipc_call_t *,
    346     bool, void *);
    347 
    348 static int rdwr_ipc_client(async_exch_t *exch, vfs_file_t *file,
     345typedef int (* rdwr_ipc_cb_t)(async_exch_t *, vfs_file_t *, aoff64_t,
     346    ipc_call_t *, bool, void *);
     347
     348static int rdwr_ipc_client(async_exch_t *exch, vfs_file_t *file, aoff64_t pos,
    349349    ipc_call_t *answer, bool read, void *data)
    350350{
     
    363363                rc = async_data_read_forward_4_1(exch, VFS_OUT_READ,
    364364                    file->node->service_id, file->node->index,
    365                     LOWER32(file->pos), UPPER32(file->pos), answer);
     365                    LOWER32(pos), UPPER32(pos), answer);
    366366        } else {
    367367                rc = async_data_write_forward_4_1(exch, VFS_OUT_WRITE,
    368368                    file->node->service_id, file->node->index,
    369                     LOWER32(file->pos), UPPER32(file->pos), answer);
     369                    LOWER32(pos), UPPER32(pos), answer);
    370370        }
    371371
     
    374374}
    375375
    376 static int rdwr_ipc_internal(async_exch_t *exch, vfs_file_t *file,
     376static int rdwr_ipc_internal(async_exch_t *exch, vfs_file_t *file, aoff64_t pos,
    377377    ipc_call_t *answer, bool read, void *data)
    378378{
     
    383383       
    384384        aid_t msg = async_send_fast(exch, read ? VFS_OUT_READ : VFS_OUT_WRITE,
    385             file->node->service_id, file->node->index, LOWER32(file->pos),
    386             UPPER32(file->pos), answer);
     385            file->node->service_id, file->node->index, LOWER32(pos),
     386            UPPER32(pos), answer);
    387387        if (msg == 0)
    388388                return EINVAL;
     
    402402}
    403403
    404 static int vfs_rdwr(int fd, bool read, rdwr_ipc_cb_t ipc_cb, void *ipc_cb_data)
     404static int vfs_rdwr(int fd, aoff64_t pos, bool read, rdwr_ipc_cb_t ipc_cb,
     405    void *ipc_cb_data)
    405406{
    406407        /*
     
    463464        async_exch_t *fs_exch = vfs_exchange_grab(file->node->fs_handle);
    464465       
    465         if (!read && file->append)
    466                 file->pos = file->node->size;
     466        if (!read && file->append) {
     467                if (file->node->size == -1)
     468                        file->node->size = vfs_node_get_size(file->node);
     469                pos = file->node->size;
     470        }
    467471       
    468472        /*
     
    470474         */
    471475        ipc_call_t answer;
    472         int rc = ipc_cb(fs_exch, file, &answer, read, ipc_cb_data);
     476        int rc = ipc_cb(fs_exch, file, pos, &answer, read, ipc_cb_data);
    473477       
    474478        vfs_exchange_release(fs_exch);
    475        
    476         size_t bytes = IPC_GET_ARG1(answer);
    477479       
    478480        if (file->node->type == VFS_NODE_DIRECTORY)
     
    491493        }
    492494       
    493         /* Update the position pointer and unlock the open file. */
    494         if (rc == EOK)
    495                 file->pos += bytes;
    496495        vfs_file_put(file);     
    497496
     
    499498}
    500499
    501 int vfs_rdwr_internal(int fd, bool read, rdwr_io_chunk_t *chunk)
    502 {
    503         return vfs_rdwr(fd, read, rdwr_ipc_internal, chunk);
    504 }
    505 
    506 int vfs_op_read(int fd, size_t *out_bytes)
    507 {
    508         return vfs_rdwr(fd, true, rdwr_ipc_client, out_bytes);
     500int vfs_rdwr_internal(int fd, aoff64_t pos, bool read, rdwr_io_chunk_t *chunk)
     501{
     502        return vfs_rdwr(fd, pos, read, rdwr_ipc_internal, chunk);
     503}
     504
     505int vfs_op_read(int fd, aoff64_t pos, size_t *out_bytes)
     506{
     507        return vfs_rdwr(fd, pos, true, rdwr_ipc_client, out_bytes);
    509508}
    510509
     
    608607        fibril_rwlock_write_unlock(&namespace_rwlock);
    609608        return EOK;
    610 }
    611 
    612 int vfs_op_seek(int fd, int64_t offset, int whence, int64_t *out_offset)
    613 {
    614         vfs_file_t *file = vfs_file_get(fd);
    615         if (!file)
    616                 return EBADF;
    617        
    618         switch (whence) {
    619         case SEEK_SET:
    620                 if (offset < 0) {
    621                         vfs_file_put(file);
    622                         return EINVAL;
    623                 }
    624                 file->pos = offset;
    625                 *out_offset = offset;
    626                 vfs_file_put(file);
    627                 return EOK;
    628         case SEEK_CUR:
    629                 if (offset > 0 && file->pos > (INT64_MAX - offset)) {
    630                         vfs_file_put(file);
    631                         return EOVERFLOW;
    632                 }
    633                
    634                 if (offset < 0 && -file->pos > offset) {
    635                         vfs_file_put(file);
    636                         return EOVERFLOW;
    637                 }
    638                
    639                 file->pos += offset;
    640                 *out_offset = file->pos;
    641                 vfs_file_put(file);
    642                 return EOK;
    643         case SEEK_END:
    644                 fibril_rwlock_read_lock(&file->node->contents_rwlock);
    645                 int64_t size = vfs_node_get_size(file->node);
    646                 fibril_rwlock_read_unlock(&file->node->contents_rwlock);
    647                
    648                 if (offset > 0 && size > (INT64_MAX - offset)) {
    649                         vfs_file_put(file);
    650                         return EOVERFLOW;
    651                 }
    652                
    653                 if (offset < 0 && -size > offset) {
    654                         vfs_file_put(file);
    655                         return EOVERFLOW;
    656                 }
    657                
    658                 file->pos = size + offset;
    659                 *out_offset = file->pos;
    660                 vfs_file_put(file);
    661                 return EOK;
    662         }
    663        
    664         vfs_file_put(file);
    665         return EINVAL;
    666609}
    667610
     
    953896}
    954897
    955 int vfs_op_write(int fd, size_t *out_bytes)
    956 {
    957         return vfs_rdwr(fd, false, rdwr_ipc_client, out_bytes);
     898int vfs_op_write(int fd, aoff64_t pos, size_t *out_bytes)
     899{
     900        return vfs_rdwr(fd, pos, false, rdwr_ipc_client, out_bytes);
    958901}
    959902
  • uspace/srv/vfs/vfs_pager.c

    rc9e3692 r58898d1d  
    5050        int rc;
    5151
    52         vfs_file_t *file = vfs_file_get(fd);
    53         if (!file) {
    54                 async_answer_0(rid, ENOENT);
    55                 return;
    56         }
    57 
    5852        page = as_area_create(AS_AREA_ANY, page_size,
    5953            AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE,
     
    6155
    6256        if (page == AS_MAP_FAILED) {
    63                 vfs_file_put(file);
    6457                async_answer_0(rid, ENOMEM);
    6558                return;
     
    7164        };
    7265
    73         file->pos = offset;
    74         vfs_file_put(file);
    75 
    7666        size_t total = 0;
     67        aoff64_t pos = offset;
    7768        do {
    78                 rc = vfs_rdwr_internal(fd, true, &chunk);
     69                rc = vfs_rdwr_internal(fd, pos, true, &chunk);
    7970                if (rc != EOK)
    8071                        break;
     
    8273                        break;
    8374                total += chunk.size;
     75                pos += chunk.size;
    8476                chunk.buffer += chunk.size;
    8577                chunk.size = page_size - total;
Note: See TracChangeset for help on using the changeset viewer.