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


Ignore:
Timestamp:
2017-04-05T18:10:39Z (8 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/fcntl.c

    r39f892a9 r368ee04  
    100100 *
    101101 * @param pathname Path to the file.
    102  * @param flags Access mode flags.
     102 * @param posix_flags Access mode flags.
    103103 */
    104 int posix_open(const char *pathname, int flags, ...)
     104int posix_open(const char *pathname, int posix_flags, ...)
    105105{
    106         mode_t mode = 0;
    107         if ((flags & O_CREAT) > 0) {
     106        int rc;
     107        posix_mode_t posix_mode = 0;
     108        if (posix_flags & O_CREAT) {
    108109                va_list args;
    109                 va_start(args, flags);
    110                 mode = va_arg(args, mode_t);
     110                va_start(args, posix_flags);
     111                posix_mode = va_arg(args, posix_mode_t);
    111112                va_end(args);
     113                (void) posix_mode;
    112114        }
    113115
    114         return negerrno(open, pathname, flags, mode);
     116        if (((posix_flags & (O_RDONLY | O_WRONLY | O_RDWR)) == 0) ||
     117            ((posix_flags & (O_RDONLY | O_WRONLY)) == (O_RDONLY | O_WRONLY)) ||
     118            ((posix_flags & (O_RDONLY | O_RDWR)) == (O_RDONLY | O_RDWR)) ||
     119            ((posix_flags & (O_WRONLY | O_RDWR)) == (O_WRONLY | O_RDWR))) {
     120                errno = EINVAL;
     121                return -1;
     122        }
     123
     124        int flags = WALK_REGULAR;
     125        if (posix_flags & O_CREAT) {
     126                if (posix_flags & O_EXCL)
     127                        flags |= WALK_MUST_CREATE;
     128                else
     129                        flags |= WALK_MAY_CREATE;
     130        }
     131
     132        int mode =
     133            ((posix_flags & O_RDWR) ? MODE_READ | MODE_WRITE : 0) |
     134            ((posix_flags & O_RDONLY) ? MODE_READ : 0) |
     135            ((posix_flags & O_WRONLY) ? MODE_WRITE : 0) |
     136            ((posix_flags & O_APPEND) ? MODE_APPEND : 0);
     137
     138        int file = rcerrno(vfs_lookup, pathname, flags);
     139        if (file < 0)
     140                return -1;
     141
     142        rc = rcerrno(vfs_open, file, mode);
     143        if (rc != EOK) {
     144                vfs_put(file);
     145                return -1;
     146        }
     147
     148        if (posix_flags & O_TRUNC) {
     149                if (posix_flags & (O_RDWR | O_WRONLY)) {
     150                        rc = rcerrno(vfs_resize, file, 0);
     151                        if (rc != EOK) {
     152                                vfs_put(file);
     153                                return -1;
     154                        }
     155                }
     156        }
     157
     158        return file;
    115159}
    116160
    117161/** @}
    118162 */
     163
Note: See TracChangeset for help on using the changeset viewer.