Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/libc/generic/vfs/vfs.c

    red903174 rb9067dfa  
    3535#include <vfs/vfs.h>
    3636#include <vfs/canonify.h>
    37 #include <macros.h>
    3837#include <stdlib.h>
    3938#include <unistd.h>
     
    121120    const char *opts, unsigned int flags)
    122121{
    123         int null_id = -1;
    124         char null[DEVMAP_NAME_MAXLEN];
    125        
    126         if (str_cmp(fqdn, "") == 0) {
    127                 /* No device specified, create a fresh
    128                    null/%d device instead */
    129                 null_id = devmap_null_create();
    130                
    131                 if (null_id == -1)
    132                         return ENOMEM;
    133                
    134                 snprintf(null, DEVMAP_NAME_MAXLEN, "null/%d", null_id);
    135                 fqdn = null;
    136         }
    137        
     122        int res;
     123        ipcarg_t rc;
     124        ipcarg_t rc_orig;
     125        aid_t req;
    138126        dev_handle_t dev_handle;
    139         int res = devmap_device_get_handle(fqdn, &dev_handle, flags);
    140         if (res != EOK) {
    141                 if (null_id != -1)
    142                         devmap_null_destroy(null_id);
    143                
     127       
     128        res = devmap_device_get_handle(fqdn, &dev_handle, flags);
     129        if (res != EOK)
    144130                return res;
    145         }
    146131       
    147132        size_t mpa_size;
    148133        char *mpa = absolutize(mp, &mpa_size);
    149         if (!mpa) {
    150                 if (null_id != -1)
    151                         devmap_null_destroy(null_id);
    152                
    153                 return ENOMEM;
    154         }
    155        
    156         futex_down(&vfs_phone_futex);
    157         async_serialize_start();
    158         vfs_connect();
    159        
    160         ipcarg_t rc_orig;
    161         aid_t req = async_send_2(vfs_phone, VFS_IN_MOUNT, dev_handle, flags, NULL);
    162         ipcarg_t rc = async_data_write_start(vfs_phone, (void *) mpa, mpa_size);
     134        if (!mpa)
     135                return ENOMEM;
     136       
     137        futex_down(&vfs_phone_futex);
     138        async_serialize_start();
     139        vfs_connect();
     140       
     141        req = async_send_2(vfs_phone, VFS_IN_MOUNT, dev_handle, flags, NULL);
     142        rc = async_data_write_start(vfs_phone, (void *) mpa, mpa_size);
    163143        if (rc != EOK) {
    164144                async_wait_for(req, &rc_orig);
     
    166146                futex_up(&vfs_phone_futex);
    167147                free(mpa);
    168                
    169                 if (null_id != -1)
    170                         devmap_null_destroy(null_id);
    171                
    172148                if (rc_orig == EOK)
    173149                        return (int) rc;
     
    182158                futex_up(&vfs_phone_futex);
    183159                free(mpa);
    184                
    185                 if (null_id != -1)
    186                         devmap_null_destroy(null_id);
    187                
    188                 if (rc_orig == EOK)
    189                         return (int) rc;
    190                 else
    191                         return (int) rc_orig;
    192         }
    193        
     160                if (rc_orig == EOK)
     161                        return (int) rc;
     162                else
     163                        return (int) rc_orig;
     164        }
     165
    194166        rc = async_data_write_start(vfs_phone, (void *) fs_name, str_size(fs_name));
    195167        if (rc != EOK) {
     
    198170                futex_up(&vfs_phone_futex);
    199171                free(mpa);
    200                
    201                 if (null_id != -1)
    202                         devmap_null_destroy(null_id);
    203                
    204                 if (rc_orig == EOK)
    205                         return (int) rc;
    206                 else
    207                         return (int) rc_orig;
    208         }
    209        
     172                if (rc_orig == EOK)
     173                        return (int) rc;
     174                else
     175                        return (int) rc_orig;
     176        }
     177
    210178        /* Ask VFS whether it likes fs_name. */
    211179        rc = async_req_0_0(vfs_phone, IPC_M_PING);
     
    215183                futex_up(&vfs_phone_futex);
    216184                free(mpa);
    217                
    218                 if (null_id != -1)
    219                         devmap_null_destroy(null_id);
    220                
    221185                if (rc_orig == EOK)
    222186                        return (int) rc;
     
    229193        futex_up(&vfs_phone_futex);
    230194        free(mpa);
    231        
    232         if ((rc != EOK) && (null_id != -1))
    233                 devmap_null_destroy(null_id);
    234195       
    235196        return (int) rc;
     
    435396}
    436397
    437 off64_t lseek(int fildes, off64_t offset, int whence)
    438 {
    439         futex_down(&vfs_phone_futex);
    440         async_serialize_start();
    441         vfs_connect();
    442        
    443         ipcarg_t newoff_lo;
    444         ipcarg_t newoff_hi;
    445         ipcarg_t rc = async_req_4_2(vfs_phone, VFS_IN_SEEK, fildes,
    446             LOWER32(offset), UPPER32(offset), whence,
    447             &newoff_lo, &newoff_hi);
    448        
    449         async_serialize_end();
    450         futex_up(&vfs_phone_futex);
    451        
     398off_t lseek(int fildes, off_t offset, int whence)
     399{
     400        ipcarg_t rc;
     401
     402        futex_down(&vfs_phone_futex);
     403        async_serialize_start();
     404        vfs_connect();
     405       
     406        ipcarg_t newoffs;
     407        rc = async_req_3_1(vfs_phone, VFS_IN_SEEK, fildes, offset, whence,
     408            &newoffs);
     409
     410        async_serialize_end();
     411        futex_up(&vfs_phone_futex);
     412
    452413        if (rc != EOK)
    453                 return (off64_t) -1;
    454        
    455         return (off64_t) MERGE_LOUP32(newoff_lo, newoff_hi);
    456 }
    457 
    458 int ftruncate(int fildes, aoff64_t length)
    459 {
    460         ipcarg_t rc;
    461        
    462         futex_down(&vfs_phone_futex);
    463         async_serialize_start();
    464         vfs_connect();
    465        
    466         rc = async_req_3_0(vfs_phone, VFS_IN_TRUNCATE, fildes,
    467             LOWER32(length), UPPER32(length));
    468         async_serialize_end();
    469         futex_up(&vfs_phone_futex);
    470        
     414                return (off_t) -1;
     415       
     416        return (off_t) newoffs;
     417}
     418
     419int ftruncate(int fildes, off_t length)
     420{
     421        ipcarg_t rc;
     422       
     423        futex_down(&vfs_phone_futex);
     424        async_serialize_start();
     425        vfs_connect();
     426       
     427        rc = async_req_2_0(vfs_phone, VFS_IN_TRUNCATE, fildes, length);
     428        async_serialize_end();
     429        futex_up(&vfs_phone_futex);
    471430        return (int) rc;
    472431}
     
    482441       
    483442        req = async_send_1(vfs_phone, VFS_IN_FSTAT, fildes, NULL);
    484         rc = async_data_read_start(vfs_phone, (void *) stat, sizeof(struct stat));
     443        rc = async_data_read_start(vfs_phone, (void *)stat, sizeof(struct stat));
    485444        if (rc != EOK) {
    486445                ipcarg_t rc_orig;
     
    556515        if (!abs) {
    557516                free(dirp);
    558                 return NULL;
     517                return ENOMEM;
    559518        }
    560519       
Note: See TracChangeset for help on using the changeset viewer.