예제 #1
0
파일: pvfsapi.c 프로젝트: yorkhellen/cache
int generic_cleanup(file_object *src, file_object *dest,
                           PVFS_credentials *credentials)
{
    /* preserve permissions doing a pvfs2 => unix copy */
    if ((src->fs_type == PVFS2_FILE) &&
        ((dest->fs_type == UNIX_FILE) && (dest->u.ufs.fd != -1)))
    {
        fchmod(dest->u.ufs.fd,
               convert_pvfs2_perms_to_mode(src->u.pvfs2.perms));
    }

    /* preserve permissions doing a unix => unix copy */
    if ((src->fs_type == UNIX_FILE) &&
        ((dest->fs_type == UNIX_FILE) && (dest->u.ufs.fd != -1)))
    {
        fchmod(dest->u.ufs.fd, src->u.ufs.mode);
    }

    /* preserve permissions doing a pvfs2 => pvfs2 copy */
    if ((src->fs_type == PVFS2_FILE) && (dest->fs_type == PVFS2_FILE))
    {
        PVFS_sys_setattr(dest->u.pvfs2.ref, src->u.pvfs2.attr, credentials, hints);
    }

    if ((src->fs_type == UNIX_FILE) && (src->u.ufs.fd != -1))
    {
        close(src->u.ufs.fd);
    }

    if ((dest->fs_type == UNIX_FILE) && (dest->u.ufs.fd != -1))
    {
        close(dest->u.ufs.fd);
    }
    return 0;
}
예제 #2
0
/**
 * pvfsios_chown: does the actual work of chown/lchown
 *
 * @param fsid the fsid we are talking to
 * @param path the path of the file/dir to change
 * @param owner the uid of the new owner
 * @param group the gid of the new group
 * @param flag follow/nofollow flag
 * @return 0 or -err
 */
static int pvfsios_chown(PVFS_fs_id *fsidp, const char *path,
                         uid_t owner, gid_t group, int flag) {
    PVFS_object_ref ref;
    PVFS_credentials creds;
    int nev, pev;
    PVFS_sys_attr nat;

    nev = pvfsios_get_object(*fsidp, (char *)path, &ref, &creds, flag);
    if (nev < 0) {
        return(nev);
    }
    
    nat.mask = 0;
    if (owner != (uid_t)-1) {
        nat.owner = owner;
        nat.mask |= PVFS_ATTR_SYS_UID;
    }
    if (group != (gid_t)-1) {
        nat.group = group;
        nat.mask |= PVFS_ATTR_SYS_GID;
    }
    if (!nat.mask) {
        return(0);           /* a noop? */
    }

    pev = PVFS_sys_setattr(ref, nat, &creds);
    return(get_err(pev));
}
예제 #3
0
파일: test-misc.c 프로젝트: Goon83/SALB
static int test_get_set_attr_empty(int testcase)
{
    int fs_id, ret;
    PVFS_credentials credentials;
    PVFS_object_ref pinode_refn;
    PVFS_sysresp_lookup resp_lookup;
    PVFS_sys_attr attr;
    PVFS_sysresp_getattr resp;
    uint32_t attrmask;
    char *name;

    ret = -2;
    name = (char *) malloc(sizeof(char) * 100);
    name = strcpy(name, "nofileyea");

    if (initialize_sysint() < 0)
    {
        debug_printf("ERROR UNABLE TO INIT SYSTEM INTERFACE\n");
        return -1;
    }
    fs_id = pvfs_helper.fs_id;

    PVFS_util_gen_credentials(&credentials);
    if ((ret = PVFS_sys_lookup(
             fs_id, name, &credentials,
             &resp_lookup, PVFS2_LOOKUP_LINK_NO_FOLLOW)) < 0)
    {
        fprintf(stderr, "lookup failed which it should but keep going\n");
	
       /* return ret; */
    }

    pinode_refn = resp_lookup.ref;
    attr.mask = PVFS_ATTR_SYS_ALL_NOSIZE;
    attr.owner = credentials.uid;
    attr.group = credentials.gid;
    attr.perms = 1877;
    attr.atime = attr.mtime = attr.ctime = 0xdeadbeef;
    attr.objtype = PVFS_TYPE_METAFILE;

    attrmask = PVFS_ATTR_SYS_ALL_NOSIZE;

    switch(testcase){
	case 0:
	    ret = PVFS_sys_setattr(pinode_refn, attr, &credentials);
	    break;
	case 1:
	    ret = PVFS_sys_getattr(pinode_refn, attrmask, &credentials, &resp);
	    break;
    }

    return ret;
}
예제 #4
0
/**
 * PVFSIOStore::Utime: set file times
 *
 * @param filename the file to change
 * @param times the times to set
 * @return PLFS_SUCCESS or PLFS_E* on error
 */
plfs_error_t PVFSIOStore::Utime(const char* filename, const struct utimbuf *times) {
    char *cpath;
    PVFS_object_ref ref;
    PVFS_credentials creds;
    int nev, pev;
    struct utimbuf now;
    PVFS_sys_attr attr;

    cpath = pvfsios_dedup_slash(filename);
    if (cpath) {
        nev = pvfsios_get_object(this->fsid, cpath, &ref, &creds,
                                 PVFS2_LOOKUP_LINK_FOLLOW);
        free(cpath);
    } else {
        nev = -ENOMEM;
    }
        
    if (nev < 0) {
        return errno_to_plfs_error(-nev);
    }

    if (times == NULL) {          /* this is allowed, means use current time */
        now.modtime = time(NULL);
        now.actime = now.modtime;
        times = &now;
    }

    attr.atime = times->actime;
    attr.mtime = times->modtime;
    attr.mask = PVFS_ATTR_SYS_ATIME | PVFS_ATTR_SYS_MTIME;

    pev = PVFS_sys_setattr(ref, attr, &creds);
    nev = get_err(pev);

    return errno_to_plfs_error(-nev);
}
예제 #5
0
/**
 * PVFSIOStore::Chmod: chmod protection
 *
 * @param path the path of the file/dir to change
 * @param mode the mode to change it to
 * @return PLFS_SUCCESS or PLFS_E* on error
 */
plfs_error_t PVFSIOStore::Chmod(const char* path, mode_t mode) {
    char *cpath;
    PVFS_object_ref ref;
    PVFS_credentials creds;
    int nev, pev;
    PVFS_sys_attr nat;

    cpath = pvfsios_dedup_slash(path);
    if (cpath) {
        nev = pvfsios_get_object(this->fsid, cpath, &ref, &creds,
                                 PVFS2_LOOKUP_LINK_FOLLOW);
        free(cpath);
    } else {
        nev = -ENOMEM;
    }
    if (nev < 0) {
        return errno_to_plfs_error(-nev);
    }

    nat.perms = mode & 07777;
    nat.mask = PVFS_ATTR_SYS_PERM;
    pev = PVFS_sys_setattr(ref, nat, &creds);
    return errno_to_plfs_error(-get_err(pev));
}
예제 #6
0
파일: test-misc.c 프로젝트: Goon83/SALB
static int test_meta_fields(int testcase){
    int fs_id, ret;
    PVFS_credentials credentials;
    PVFS_object_ref pinode_refn;
    PVFS_sysresp_lookup resp_lookup;
    PVFS_sys_attr attr;
    char *name;

    ret = -2;
    name = (char *) malloc(sizeof(char) * 100);
    name = strcpy(name, "name");

    if (initialize_sysint() < 0)
    {
        debug_printf("ERROR UNABLE TO INIT SYSTEM INTERFACE\n");
        return -1;
    }
    fs_id = pvfs_helper.fs_id;

    PVFS_util_gen_credentials(&credentials);
    if ((ret = PVFS_sys_lookup(
             fs_id, name, &credentials,
             &resp_lookup, PVFS2_LOOKUP_LINK_NO_FOLLOW)) < 0)
    {
        fprintf(stderr, "lookup failed %d\n", ret);
        return ret;
    }

    pinode_refn = resp_lookup.ref;
    attr.mask = PVFS_ATTR_SYS_ALL_NOSIZE;
    attr.owner = credentials.uid;
    attr.group = credentials.gid;
    attr.perms = 1877;
    attr.atime = attr.mtime = attr.ctime = 0xdeadbeef;
    attr.objtype = PVFS_TYPE_METAFILE;

    switch(testcase){
	case 0:
	    attr.owner = 555;
	    ret = PVFS_sys_setattr(pinode_refn, attr, &credentials);
	    break;
	case 1:
	    attr.group = 555;
	    ret = PVFS_sys_setattr(pinode_refn, attr, &credentials);
	    break;
	case 2:
	    attr.perms = 888;
	    ret = PVFS_sys_setattr(pinode_refn, attr, &credentials);
	    break;
	case 3:
	    attr.atime = 555;
	    ret = PVFS_sys_setattr(pinode_refn, attr, &credentials);
	    break;
	case 4:
	    attr.mtime = 555;
	    ret = PVFS_sys_setattr(pinode_refn, attr, &credentials);
	    break;
	case 5:
	    attr.ctime = 555;
	    ret = PVFS_sys_setattr(pinode_refn, attr, &credentials);
	    break;
	case 6:
	    attr.mask = 2003;
	    ret = PVFS_sys_setattr(pinode_refn, attr, &credentials);
	    break;
    }
/*     finalize_sysint(); */
    return ret;
}