Changeset 58898d1d in mainline for uspace/srv/vfs/vfs_ops.c


Ignore:
Timestamp:
2017-03-24T20:31:54Z (8 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

File:
1 edited

Legend:

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