Changeset 79ea5af in mainline for uspace/lib/c/generic/vfs/vfs.c


Ignore:
Timestamp:
2017-03-30T20:47:53Z (7 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
67e881c
Parents:
ae7bfbbd
Message:

Rename unlink() to vfs_unlink_path() and _vfs_unlink() to vfs_unlink()

  • Also, remove rmdir()
File:
1 edited

Legend:

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

    rae7bfbbd r79ea5af  
    792792}
    793793
    794 static int _vfs_unlink(int parent, const char *path, int expect, int wflag)
     794int vfs_unlink(int parent, const char *child, int expect)
    795795{
    796796        sysarg_t rc;
     
    799799        async_exch_t *exch = vfs_exchange_begin();
    800800       
    801         req = async_send_3(exch, VFS_IN_UNLINK, parent, expect, wflag, NULL);
    802         rc = async_data_write_start(exch, path, str_size(path));
     801        req = async_send_2(exch, VFS_IN_UNLINK, parent, expect, NULL);
     802        rc = async_data_write_start(exch, child, str_size(child));
    803803       
    804804        vfs_exchange_end(exch);
     
    815815 *
    816816 * @param path Path
    817  * @return EOk on success, error code on error
    818  */
    819 int unlink(const char *path)
     817 * @return EOk on success or a negative error code otherwise
     818 */
     819int vfs_unlink_path(const char *path)
    820820{
    821821        size_t pa_size;
    822822        char *pa = vfs_absolutize(path, &pa_size);
    823         if (!pa) {
    824                 errno = ENOMEM;
    825                 return -1;
    826         }
    827        
    828         int root = vfs_root();
    829         if (root < 0) {
     823        if (!pa)
     824                return ENOMEM;
     825
     826        int parent;
     827        int expect = vfs_lookup(path, 0);
     828        if (expect < 0) {
    830829                free(pa);
    831                 errno = ENOENT;
    832                 return -1;
    833         }
    834        
    835         int rc = _vfs_unlink(root, pa, -1, 0);
    836        
    837         if (rc != EOK) {
    838                 errno = rc;
    839                 rc = -1;
    840         }
    841 
     830                return expect;
     831        }
     832
     833        char *slash = str_rchr(pa, L'/');
     834        if (slash != pa) {
     835                *slash = '\0';
     836                parent = vfs_lookup(pa, 0);
     837                *slash = '/';
     838        } else {
     839                parent = vfs_root();
     840        }
     841
     842        if (parent < 0) {
     843                free(pa);
     844                close(expect);
     845                return parent;
     846        }
     847
     848        int rc = vfs_unlink(parent, slash, expect);
     849       
    842850        free(pa);
    843         close(root);
    844         return rc;
    845 }
    846 
    847 /** Remove empty directory.
    848  *
    849  * @param path Path
    850  * @return 0 on success. On error returns -1 and sets errno.
    851  */
    852 int rmdir(const char *path)
    853 {
    854         size_t pa_size;
    855         char *pa = vfs_absolutize(path, &pa_size);
    856         if (!pa) {
    857                 errno = ENOMEM;
    858                 return -1;
    859         }
    860        
    861         int root = vfs_root();
    862         if (root < 0) {
    863                 free(pa);
    864                 errno = ENOENT;
    865                 return -1;
    866         }
    867        
    868         int rc = _vfs_unlink(root, pa, -1, WALK_DIRECTORY);
    869         if (rc != EOK) {
    870                 errno = rc;
    871                 rc = -1;
    872         }
    873        
    874         free(pa);
    875         close(root);
     851        close(parent);
     852        close(expect);
    876853        return rc;
    877854}
Note: See TracChangeset for help on using the changeset viewer.