/tests/encryption/

s as published by the Free Software Foundation. */ #include "glfs-internal.h" #include "glfs-mem-types.h" #include "syncop.h" #include "glfs.h" #include #ifdef NAME_MAX #define GF_NAME_MAX NAME_MAX #else #define GF_NAME_MAX 255 #endif #define READDIRBUF_SIZE (sizeof(struct dirent) + GF_NAME_MAX + 1) int glfs_loc_link (loc_t *loc, struct iatt *iatt) { int ret = -1; inode_t *linked_inode = NULL; if (!loc->inode) { errno = EINVAL; return -1; } linked_inode = inode_link (loc->inode, loc->parent, loc->name, iatt); if (linked_inode) { inode_lookup (linked_inode); inode_unref (linked_inode); ret = 0; } else { ret = -1; errno = ENOMEM; } return ret; } void glfs_iatt_to_stat (struct glfs *fs, struct iatt *iatt, struct stat *stat) { iatt_to_stat (iatt, stat); stat->st_dev = fs->dev_id; } int glfs_loc_unlink (loc_t *loc) { inode_unlink (loc->inode, loc->parent, loc->name); return 0; } struct glfs_fd * glfs_open (struct glfs *fs, const char *path, int flags) { int ret = -1; struct glfs_fd *glfd = NULL; xlator_t *subvol = NULL; loc_t loc = {0, }; struct iatt iatt = {0, }; int reval = 0; __glfs_entry_fs (fs); subvol = glfs_active_subvol (fs); if (!subvol) { ret = -1; errno = EIO; goto out; } glfd = glfs_fd_new (fs); if (!glfd) goto out; retry: ret = glfs_resolve (fs, subvol, path, &loc, &iatt, reval); ESTALE_RETRY (ret, errno, reval, &loc, retry); if (ret) goto out; if (IA_ISDIR (iatt.ia_type)) { ret = -1; errno = EISDIR; goto out; } if (!IA_ISREG (iatt.ia_type)) { ret = -1; errno = EINVAL; goto out; } if (glfd->fd) { /* Retry. Safe to touch glfd->fd as we still have not glfs_fd_bind() yet. */ fd_unref (glfd->fd); glfd->fd = NULL; } glfd->fd = fd_create (loc.inode, getpid()); if (!glfd->fd) { ret = -1; errno = ENOMEM; goto out; } ret = syncop_open (subvol, &loc, flags, glfd->fd); DECODE_SYNCOP_ERR (ret); ESTALE_RETRY (ret, errno, reval, &loc, retry); out: loc_wipe (&loc); if (ret && glfd) { glfs_fd_destroy (glfd); glfd = NULL; } else if (glfd) { glfd->fd->flags = flags; fd_bind (glfd->fd); glfs_fd_bind (glfd); } glfs_subvol_done (fs, subvol); return glfd; } int glfs_close (struct glfs_fd *glfd) { xlator_t *subvol = NULL; int ret = -1; fd_t *fd = NULL; struct glfs *fs = NULL; __glfs_entry_fd (glfd); subvol = glfs_active_subvol (glfd->fs); if (!subvol) { ret = -1; errno = EIO; goto out; } fd = glfs_resolve_fd (glfd->fs, subvol, glfd); if (!fd) { ret = -1; errno = EBADFD; goto out; } ret = syncop_flush (subvol, fd); DECODE_SYNCOP_ERR (ret); out: fs = glfd->fs; glfs_fd_destroy (glfd); if (fd) fd_unref (fd); glfs_subvol_done (fs, subvol); return ret; } int glfs_lstat (struct glfs *fs, const char *path, struct stat *stat) { int ret = -1; xlator_t *subvol = NULL; loc_t loc = {0, }; struct iatt iatt = {0, }; int reval = 0; __glfs_entry_fs (fs); subvol = glfs_active_subvol (fs); if (!subvol) { ret = -1; errno = EIO; goto out; } retry: ret = glfs_lresolve (fs, subvol, path, &loc, &iatt, reval); ESTALE_RETRY (ret, errno, reval,