Changeset 6dae798 in mainline


Ignore:
Timestamp:
2026-03-18T12:47:36Z (16 hours ago)
Author:
GitHub <noreply@…>
Parents:
222774a (diff), 34832c3 (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.
git-author:
Vít Skalický <skalicky@…> (2026-03-18 12:47:36)
git-committer:
GitHub <noreply@…> (2026-03-18 12:47:36)
Message:

Merge 34832c3e4df70614df5caa7d44b985f0460ef8ec into 222774a69b1583c34db4419abfda9fa6a1031f74

Location:
uspace
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/meson.build

    r222774a r6dae798  
    3535        'blkdump',
    3636        'calculator',
     37        'cmpdirs',
    3738        'copy',
    3839        'corecfg',
  • uspace/lib/c/generic/dirent.c

    r222774a r6dae798  
    11/*
    22 * Copyright (c) 2008 Jakub Jermar
     3 * Copyright (c) 2026 Vít Skalický
    34 * All rights reserved.
    45 *
     
    4748};
    4849
    49 /** Open directory.
     50/** Like opendir_handle, but takes ownership of the handle if successful. */
     51static DIR *opendir_internal(int handle)
     52{
     53        DIR *dirp = malloc(sizeof(DIR));
     54        if (!dirp) {
     55                errno = ENOMEM;
     56                return NULL;
     57        }
     58
     59        errno_t rc = vfs_open(handle, MODE_READ);
     60        if (rc != EOK) {
     61                free(dirp);
     62                errno = rc;
     63                return NULL;
     64        }
     65
     66        dirp->fd = handle;
     67        dirp->pos = 0;
     68        return dirp;
     69}
     70
     71/** Open directory by its handle (a.k.a. file descriptor).
     72 *
     73 * @param handle Directory handle
     74 * @return Non-NULL pointer on success. On error returns @c NULL and sets errno.
     75 */
     76DIR *opendir_handle(int handle)
     77{
     78        int my_handle;
     79        // Clone the file handle, otherwise closedir would put the
     80        // handle that was passed to us here by the caller and that we don't own.
     81        errno_t rc = vfs_clone(handle, -1, false, &my_handle);
     82        if (rc != EOK) {
     83                errno = rc;
     84                return NULL;
     85        }
     86
     87        DIR *dirp = opendir_internal(my_handle);
     88        if (!dirp) {
     89                rc = errno;
     90                vfs_put(my_handle);
     91                errno = rc;
     92                return NULL;
     93        }
     94        return dirp;
     95}
     96
     97/** Open directory by its pathname.
    5098 *
    5199 * @param dirname Directory pathname
     
    55103DIR *opendir(const char *dirname)
    56104{
    57         DIR *dirp = malloc(sizeof(DIR));
    58         if (!dirp) {
    59                 errno = ENOMEM;
    60                 return NULL;
    61         }
    62 
    63105        int fd;
    64106        errno_t rc = vfs_lookup(dirname, WALK_DIRECTORY, &fd);
    65107        if (rc != EOK) {
    66                 free(dirp);
    67108                errno = rc;
    68109                return NULL;
    69110        }
    70111
    71         rc = vfs_open(fd, MODE_READ);
    72         if (rc != EOK) {
    73                 free(dirp);
     112        DIR *dirp = opendir_internal(fd);
     113        if (!dirp) {
     114                rc = errno;
    74115                vfs_put(fd);
    75116                errno = rc;
    76117                return NULL;
    77118        }
    78 
    79         dirp->fd = fd;
    80         dirp->pos = 0;
    81119        return dirp;
    82120}
    83121
    84 /** Read directory entry.
     122/** Read current directory entry and advance to the next one.
    85123 *
    86124 * @param dirp Open directory
  • uspace/lib/c/generic/vfs/vfs.c

    r222774a r6dae798  
    12591259 *
    12601260 * @param parent        File handle of the parent node where the walk starts
    1261  * @param path          Parent-relative path to be walked
     1261 * @param path          Parent-relative absolute path to be walked (an
     1262 *                      absolute path with the parent being the root).
     1263 *                      If /foo is parent and path is "/bar/baz", the
     1264 *                      result would be /foo/bar/baz. Just "bar/baz" is
     1265 *                      not valid.
    12621266 * @param flags         Flags influencing the walk
    12631267 * @param[out] handle   File handle representing the result on success.
  • uspace/lib/c/include/dirent.h

    r222774a r6dae798  
    11/*
    22 * Copyright (c) 2008 Jakub Jermar
     3 * Copyright (c) 2026 Vít Skalický
    34 * All rights reserved.
    45 *
     
    4647typedef struct __dirstream DIR;
    4748
     49extern DIR *opendir_handle(int handle);
    4850extern DIR *opendir(const char *);
    4951extern struct dirent *readdir(DIR *);
  • uspace/srv/vfs/vfs_lookup.c

    r222774a r6dae798  
    325325 *
    326326 * @param base    The file from which to perform the lookup.
    327  * @param path    Path to be resolved; it must be a NULL-terminated
    328  *                string.
     327 * @param path    Path to be resolved; It must be an absolute path
     328 *                which get resolved relatively to base; it must be a
     329 *                NULL-terminated string. Example: If /foo is parent
     330 *                and path is "/bar/baz", the result would be /foo/bar/baz.
     331 *                Just "bar/baz" is not valid.
    329332 * @param lflag   Flags to be used during lookup.
    330333 * @param result  Empty structure where the lookup result will be stored.
Note: See TracChangeset for help on using the changeset viewer.