Changeset 368ee04 in mainline for uspace/lib/posix/source/unistd.c


Ignore:
Timestamp:
2017-04-05T18:10:39Z (7 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
93ad8166
Parents:
39f892a9 (diff), 2166728 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge from lp:~jakub/helenos/vfs-2.5-cherrypick

This merge cherry-picks some of the changesets from Jiri Zarevucky's:

lp:~zarevucky-jiri/helenos/vfs-2.5

and then continues independently, yet sometime in a similar vein.

Roughly speaking, Jiri's branch is merged entirely up to its revision
1926 and then cherry-picked on and off until its revision 1965. Among
these changes are:

  • relativization of the API,
  • client-side roots,
  • server-side mounts,
  • inbox for passing arbitrary files from parent to child,
  • some streamlining and cleanup.

Additional changes include:

  • addressing issues introduced by the above changes,
  • client-side I/O cursors (file positions),
  • all HelenOS file system APIs begin with the vfs_ prefix and can be used after including vfs/vfs.h,
  • removal of some POSIX-ish headers and definitions,
  • additional cleanup.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/posix/source/unistd.c

    r39f892a9 r368ee04  
    4747#include "libc/stats.h"
    4848#include "libc/malloc.h"
     49#include "libc/vfs/vfs.h"
     50
     51aoff64_t posix_pos[MAX_OPEN_FILES];
    4952
    5053/* Array of environment variable strings (NAME=VALUE). */
     
    105108char *posix_getcwd(char *buf, size_t size)
    106109{
    107         char *p = getcwd(buf, size);
    108 
    109         if (p == NULL) {
    110                 errno = -errno;
     110        int rc = rcerrno(vfs_cwd_get, buf, size);
     111        if (rc != EOK)
    111112                return NULL;
    112         }
    113 
    114         return p;
     113        return buf;
    115114}
    116115
     
    122121int posix_chdir(const char *path)
    123122{
    124         return negerrno(chdir, path);
     123        int rc = rcerrno(vfs_cwd_set, path);
     124        if (rc != EOK)
     125                return -1;
     126        return 0;
    125127}
    126128
     
    175177int posix_close(int fildes)
    176178{
    177         return negerrno(close, fildes);
     179        posix_pos[fildes] = 0;
     180        int rc = rcerrno(vfs_put, fildes);
     181        if (rc != EOK)
     182                return -1;
     183        else
     184                return 0;
    178185}
    179186
     
    188195ssize_t posix_read(int fildes, void *buf, size_t nbyte)
    189196{
    190         return negerrno(read, fildes, buf, nbyte);
     197        ssize_t size = rcerrno(vfs_read, fildes, &posix_pos[fildes], buf, nbyte);
     198        if (size < 0)
     199                return -1;
     200        return size;
    191201}
    192202
     
    201211ssize_t posix_write(int fildes, const void *buf, size_t nbyte)
    202212{
    203         return negerrno(write, fildes, buf, nbyte);
     213        ssize_t size = rcerrno(vfs_write, fildes, &posix_pos[fildes], buf, nbyte);
     214        if (size < 0)
     215                return -1;
     216        return size;
    204217}
    205218
     
    215228posix_off_t posix_lseek(int fildes, posix_off_t offset, int whence)
    216229{
    217         return negerrno(lseek, fildes, offset, whence);
     230        struct stat st;
     231        int rc;
     232
     233        switch (whence) {
     234        case SEEK_SET:
     235                posix_pos[fildes] = offset;
     236                break;
     237        case SEEK_CUR:
     238                posix_pos[fildes] += offset;
     239                break;
     240        case SEEK_END:
     241                rc = rcerrno(vfs_stat, fildes, &st);
     242                if (rc != EOK)
     243                        return -1;
     244                posix_pos[fildes] = st.size + offset;
     245                break;
     246        }
     247        if (posix_pos[fildes] > INT64_MAX) {
     248                /* The native width is too large for the POSIX interface. */
     249                errno = ERANGE;
     250                return -1;
     251        }
     252        return posix_pos[fildes];
    218253}
    219254
     
    226261int posix_fsync(int fildes)
    227262{
    228         return negerrno(fsync, fildes);
     263        if (rcerrno(vfs_sync, fildes) != EOK)
     264                return -1;
     265        else
     266                return 0;
    229267}
    230268
     
    238276int posix_ftruncate(int fildes, posix_off_t length)
    239277{
    240         return negerrno(ftruncate, fildes, (aoff64_t) length);
     278        if (rcerrno(vfs_resize, fildes, (aoff64_t) length) != EOK)
     279                return -1;
     280        else
     281                return 0;
    241282}
    242283
     
    249290int posix_rmdir(const char *path)
    250291{
    251         return negerrno(rmdir, path);
     292        if (rcerrno(vfs_unlink_path, path) != EOK)
     293                return -1;
     294        else
     295                return 0;
    252296}
    253297
     
    260304int posix_unlink(const char *path)
    261305{
    262         return negerrno(unlink, path);
     306        if (rcerrno(vfs_unlink_path, path) != EOK)
     307                return -1;
     308        else
     309                return 0;
    263310}
    264311
     
    284331int posix_dup2(int fildes, int fildes2)
    285332{
    286         return negerrno(dup2, fildes, fildes2);
     333        return negerrno(vfs_clone, fildes, fildes2, false);
    287334}
    288335
     
    302349                 * Check file existence by attempting to open it.
    303350                 */
    304                 int fd = negerrno(open, path, O_RDONLY);
    305                 if (fd < 0) {
    306                         /* errno was set by open() */
     351                int fd = posix_open(path, O_RDONLY);
     352                if (fd < 0)
    307353                        return -1;
    308                 }
    309                 close(fd);
     354                posix_close(fd);
    310355                return 0;
    311356        } else {
Note: See TracChangeset for help on using the changeset viewer.