Beispiel #1
0
int
solaris_removexattr(const char *path, const char* key)
{
    int ret = -1;
    int attrfd = -1;
    char *mapped_path = NULL;

    ret = solaris_xattr_resolve_path (path, &mapped_path);
    if (!ret) {
        attrfd = attropen (mapped_path, ".", O_RDONLY, 0);
    } else {
        attrfd = attropen (path, ".", O_RDONLY, 0);
    }
    if (attrfd >= 0) {
        ret = unlinkat (attrfd, key, 0);
        close (attrfd);
    } else {
        if (errno == ENOENT)
            errno = ENODATA;
        ret = -1;
    }

    if (mapped_path)
        GF_FREE (mapped_path);

    return ret;
}
Beispiel #2
0
int solaris_unlink (const char *path)
{
    char *mapped_path = NULL;
    struct stat     stbuf = {0, };
    int ret = -1;

    ret = solaris_xattr_resolve_path (path, &mapped_path);


    if (!ret && mapped_path) {
        if (lstat(path, &stbuf)) {
            gf_log (THIS->name, GF_LOG_WARNING, "Stat failed on mapped"
                    " file %s with error %d", mapped_path, errno);
            goto out;
        }
        if (stbuf.st_nlink == 1) {
            if(remove (mapped_path))
                gf_log (THIS->name, GF_LOG_WARNING, "Failed to remove mapped "
                        "file %s. Errno %d", mapped_path, errno);
        }

    }

out:
    if (mapped_path)
        GF_FREE (mapped_path);

    return  unlink (path);
}
Beispiel #3
0
int
solaris_setxattr(const char *path, const char* key, const char *value,
                 size_t size, int flags)
{
    int attrfd = -1;
    int ret = 0;
    char *mapped_path = NULL;

    ret = solaris_xattr_resolve_path (path, &mapped_path);
    if (!ret) {
        attrfd = attropen (mapped_path,  key, flags|O_CREAT|O_WRONLY,
                           0777);
    } else {
        attrfd = attropen (path, key, flags|O_CREAT|O_WRONLY, 0777);
    }
    if (attrfd >= 0) {
        ftruncate (attrfd, 0);
        ret = write (attrfd, value, size);
        close (attrfd);
        ret = 0;
    } else {
        if (errno != ENOENT)
            gf_log ("libglusterfs", GF_LOG_ERROR,
                    "Couldn't set extended attribute for %s (%d)",
                    path, errno);
        ret = -1;
    }
    if (mapped_path)
        GF_FREE (mapped_path);
    return ret;
}
Beispiel #4
0
int solaris_unlink (const char *path)
{
        char *mapped_path = NULL;
        struct stat     stbuf = {0, };
        int ret = -1;

        ret = solaris_xattr_resolve_path (path, &mapped_path);


        if (!ret && mapped_path) {
                if (lstat(path, &stbuf)) {
                        gf_msg (THIS->name, GF_LOG_WARNING, errno,
                                LG_MSG_FILE_OP_FAILED, "Stat failed on "
                                "mapped file %s", mapped_path);
                        goto out;
                }
                if (stbuf.st_nlink == 1) {
                        if(remove (mapped_path))
                                gf_msg (THIS->name, GF_LOG_WARNING, errno,
                                        LG_MSG_FILE_OP_FAILED, "Failed to "
                                        "remove mapped file %s", mapped_path);
                }

        }

out:
        GF_FREE (mapped_path);

        return  unlink (path);
}
Beispiel #5
0
int
solaris_rename (const char *old_path, const char *new_path)
{
    char *mapped_path = NULL;
    int ret = -1;

    ret = solaris_xattr_resolve_path (new_path, &mapped_path);


    if (!ret && mapped_path) {
        if (!remove (mapped_path))
            gf_log (THIS->name, GF_LOG_WARNING, "Failed to remove mapped "
                    "file %s. Errno %d", mapped_path, errno);
        GF_FREE (mapped_path);
    }

    return rename(old_path, new_path);

}
Beispiel #6
0
int
solaris_rename (const char *old_path, const char *new_path)
{
        char *mapped_path = NULL;
        int ret = -1;

        ret = solaris_xattr_resolve_path (new_path, &mapped_path);


        if (!ret && mapped_path) {
                if (!remove (mapped_path))
                        gf_msg (THIS->name, GF_LOG_WARNING, errno,
                                LG_MSG_FILE_OP_FAILED, "Failed to remove "
                                "mapped file %s.", mapped_path);
                GF_FREE (mapped_path);
        }

        return rename(old_path, new_path);

}
Beispiel #7
0
int
solaris_getxattr(const char *path,
                 const char* key,
                 char *value,
                 size_t size)
{
    int attrfd = -1;
    int ret = 0;
    char *mapped_path = NULL;

    ret = solaris_xattr_resolve_path (path, &mapped_path);
    if (!ret) {
        attrfd = attropen (mapped_path, key, O_RDONLY, 0);
    } else {
        attrfd = attropen (path, key, O_RDONLY, 0);
    }

    if (attrfd >= 0) {
        if (size == 0) {
            struct stat buf;
            fstat (attrfd, &buf);
            ret = buf.st_size;
        } else {
            ret = read (attrfd, value, size);
        }
        close (attrfd);
    } else {
        if (errno != ENOENT)
            gf_log ("libglusterfs", GF_LOG_INFO,
                    "Couldn't read extended attribute for the file %s (%s)",
                    path, strerror (errno));
        if (errno == ENOENT)
            errno = ENODATA;
        ret = -1;
    }
    if (mapped_path)
        GF_FREE (mapped_path);
    return ret;
}
Beispiel #8
0
int
solaris_listxattr(const char *path, char *list, size_t size)
{
    int attrdirfd = -1;
    ssize_t len = 0;
    DIR *dirptr = NULL;
    struct dirent *dent = NULL;
    int newfd = -1;
    char *mapped_path = NULL;
    int ret = -1;

    ret = solaris_xattr_resolve_path (path, &mapped_path);
    if (!ret) {
        attrdirfd = attropen (mapped_path, ".", O_RDONLY, 0);
    } else {
        attrdirfd = attropen (path, ".", O_RDONLY, 0);
    }
    if (attrdirfd >= 0) {
        newfd = dup(attrdirfd);
        dirptr = fdopendir(newfd);
        if (dirptr) {
            while ((dent = readdir(dirptr))) {
                size_t listlen = strlen(dent->d_name);
                if (!strcmp(dent->d_name, ".") ||
                        !strcmp(dent->d_name, "..")) {
                    /* we don't want "." and ".." here */
                    continue;
                }
                if (size == 0) {
                    /* return the current size of the list
                       of extended attribute names*/
                    len += listlen + 1;
                } else {
                    /* check size and copy entry + null
                       into list. */
                    if ((len + listlen + 1) > size) {
                        errno = ERANGE;
                        len = -1;
                        break;
                    } else {
                        strncpy(list + len, dent->d_name, listlen);
                        len += listlen;
                        list[len] = '\0';
                        ++len;
                    }
                }
            }

            if (closedir(dirptr) == -1) {
                close (attrdirfd);
                len = -1;
                goto out;
            }
        } else {
            close (attrdirfd);
            len = -1;
            goto out;
        }
        close (attrdirfd);
    }
out:
    if (mapped_path)
        GF_FREE (mapped_path);
    return len;
}