当前位置: 首页>>代码示例>>C++>>正文


C++ setxattr函数代码示例

本文整理汇总了C++中setxattr函数的典型用法代码示例。如果您正苦于以下问题:C++ setxattr函数的具体用法?C++ setxattr怎么用?C++ setxattr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了setxattr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: spade_setxattr

static int
spade_setxattr(const char *path, const char *name, const char *value,
        size_t size, int flags, uint32_t position) {
    int res;

    if (!strncmp(name, XATTR_APPLE_PREFIX, sizeof (XATTR_APPLE_PREFIX) - 1)) {
        flags &= ~(XATTR_NOSECURITY);
    }

    if (!strcmp(name, A_KAUTH_FILESEC_XATTR)) {

        char new_name[MAXPATHLEN];

        memcpy(new_name, A_KAUTH_FILESEC_XATTR, sizeof (A_KAUTH_FILESEC_XATTR));
        memcpy(new_name, G_PREFIX, sizeof (G_PREFIX) - 1);

        res = setxattr(path, new_name, value, size, position, flags);

    } else {
        res = setxattr(path, name, value, size, position, flags);
    }

    if (res == -1) {
        return -errno;
    }

    return 0;
}
开发者ID:GaloisInc,项目名称:SPADE,代码行数:28,代码来源:libMacFUSE.c

示例2: local_set_xattr

static int local_set_xattr(const char *path, FsCred *credp)
{
    int err;

    if (credp->fc_uid != -1) {
        uint32_t tmp_uid = cpu_to_le32(credp->fc_uid);
        err = setxattr(path, "user.virtfs.uid", &tmp_uid, sizeof(uid_t), 0);
        if (err) {
            return err;
        }
    }
    if (credp->fc_gid != -1) {
        uint32_t tmp_gid = cpu_to_le32(credp->fc_gid);
        err = setxattr(path, "user.virtfs.gid", &tmp_gid, sizeof(gid_t), 0);
        if (err) {
            return err;
        }
    }
    if (credp->fc_mode != -1) {
        uint32_t tmp_mode = cpu_to_le32(credp->fc_mode);
        err = setxattr(path, "user.virtfs.mode", &tmp_mode, sizeof(mode_t), 0);
        if (err) {
            return err;
        }
    }
    if (credp->fc_rdev != -1) {
        uint64_t tmp_rdev = cpu_to_le64(credp->fc_rdev);
        err = setxattr(path, "user.virtfs.rdev", &tmp_rdev, sizeof(dev_t), 0);
        if (err) {
            return err;
        }
    }
    return 0;
}
开发者ID:pbhide,项目名称:qemu-rocker,代码行数:34,代码来源:virtio-9p-local.c

示例3: local_set_xattr

static int local_set_xattr(const char *path, FsCred *credp)
{
    int err;

    if (credp->fc_uid != -1) {
        err = setxattr(path, "user.virtfs.uid", &credp->fc_uid, sizeof(uid_t),
                0);
        if (err) {
            return err;
        }
    }
    if (credp->fc_gid != -1) {
        err = setxattr(path, "user.virtfs.gid", &credp->fc_gid, sizeof(gid_t),
                0);
        if (err) {
            return err;
        }
    }
    if (credp->fc_mode != -1) {
        err = setxattr(path, "user.virtfs.mode", &credp->fc_mode,
                sizeof(mode_t), 0);
        if (err) {
            return err;
        }
    }
    if (credp->fc_rdev != -1) {
        err = setxattr(path, "user.virtfs.rdev", &credp->fc_rdev,
                sizeof(dev_t), 0);
        if (err) {
            return err;
        }
    }
    return 0;
}
开发者ID:01org,项目名称:KVMGT-qemu,代码行数:34,代码来源:virtio-9p-local.c

示例4: chirp_fs_local_setxattr

static INT64_T chirp_fs_local_setxattr(const char *path, const char *name, const void *data, size_t size, int flags)
{
#ifdef CCTOOLS_OPSYS_DARWIN
	return setxattr(path, name, data, size, 0, flags);
#else
	return setxattr(path, name, data, size, flags);
#endif
}
开发者ID:nfillmore,项目名称:cctools,代码行数:8,代码来源:chirp_fs_local.c

示例5: mark_pos

int mark_pos(const char *path, char *pos, const char *ts) {
  if(strlen(pos) == 0) {
    *pos = '0';
  }
  setxattr(path, XATTR_ANALYZER_POS, pos, strlen(pos), 0); 
  setxattr(path, XATTR_ANALYZER_POS_TS, ts, strlen(ts), 0);
  return;
}
开发者ID:stanleyz,项目名称:sniffer,代码行数:8,代码来源:processer.c

示例6: chirp_fs_local_setxattr

static INT64_T chirp_fs_local_setxattr(const char *path, const char *name, const void *data, size_t size, int flags)
{
	PREAMBLE("setxattr(`%s', `%s', %p, %zu, %d)", path, name, data, size, flags);
	RESOLVE(path)
#ifdef CCTOOLS_OPSYS_DARWIN
	rc = setxattr(path, name, data, size, 0, flags);
#else
	rc = setxattr(path, name, data, size, flags);
#endif
	PROLOGUE
}
开发者ID:NeilB879,项目名称:cctools,代码行数:11,代码来源:chirp_fs_local.c

示例7: setxattrs

void setxattrs(const std::string &path) {
  setxattr(path.c_str(), kQuarantineKey.c_str(), (void *)kQuarantineValue,
           sizeof(kQuarantineValue), 0, XATTR_NOFOLLOW);
  setxattr(path.c_str(), kMetedataKey.c_str(), (void *)kMetadataWhereFromValue,
           sizeof(kMetadataWhereFromValue), 0, XATTR_NOFOLLOW);
  setxattr(path.c_str(), kFsckKey.c_str(), (void *)kFsckValue,
           sizeof(kFsckValue), 0, XATTR_NOFOLLOW);
  // insert arbitrary xattr
  const std::string key = "foobar";
  const unsigned char val[] = {0x62, 0x61, 0x7A}; // baz
  setxattr(path.c_str(), key.c_str(), (void *)val, sizeof(val), 0,
           XATTR_NOFOLLOW);
}
开发者ID:ArchieBitcoin,项目名称:osquery,代码行数:13,代码来源:extended_attributes_tests.cpp

示例8: xsetxattr

static int
xsetxattr(const char *path, const char *name, const void *value,
          size_t size, int flags, int symlink)
{
#ifdef XATTR_EXTRA_ARGS
    return setxattr(path, name, value, size, 0, flags | symlink ? XATTR_NOFOLLOW : 0);
#else
    switch (symlink) {
    case 0:
        return setxattr(path, name, value, size, flags);
    default:
        return lsetxattr(path, name, value, size, flags);
    }
#endif
}
开发者ID:Jaharmi,项目名称:zsh,代码行数:15,代码来源:attr.c

示例9: nfs4_set_acl

int nfs4_set_acl(struct nfs4_acl *acl, const char *path)
{
	int res = 0;
	char *xdrbuf = NULL;

	res = acl_nfs4_xattr_pack(acl, &xdrbuf);
	if (res <= 0) {
		fprintf(stderr, "Failed to populate xattr from nfs4acl\n");
		goto out_free;
	}

	res = setxattr(path, ACL_NFS4_XATTR, (char *)xdrbuf, res, XATTR_REPLACE);
	if (res < -10000) {
		fprintf(stderr,"An internal NFS server error code (%d) was returned; this should never happen.\n",res);
		goto out_free;
	} else if (res < 0) {
		if (errno == EOPNOTSUPP)
			fprintf(stderr,"Operation to set ACL not supported.\n");
		else if (errno == ENOATTR)
			fprintf(stderr,"ACL Attribute not found on file.\n");
		else if (errno == EREMOTEIO)
			fprintf(stderr,"An NFS server error occurred.\n");
		else
			perror("Failed setxattr operation");
	}

out_free:
	free(xdrbuf);
	return res;
}
开发者ID:Distrotech,项目名称:nfs4-acl-tools,代码行数:30,代码来源:nfs4_set_acl.c

示例10: setup

static void setup(void)
{
	int fd;

	tst_require_root(NULL);

	tst_tmpdir();

	/* Test for xattr support and set attr value */
	fd = creat(TESTFILE, 0644);
	if (fd == -1)
		tst_brkm(TBROK | TERRNO, cleanup, "Create %s failed", TESTFILE);
	close(fd);

	if (setxattr(TESTFILE, XATTR_TEST_KEY, XATTR_TEST_VALUE,
		     XATTR_TEST_VALUE_SIZE, XATTR_CREATE) == -1) {
		if (errno == ENOTSUP)
			tst_brkm(TCONF, cleanup, "No xattr support in fs or "
				 "fs mounted without user_xattr option");
		else
			tst_brkm(TBROK | TERRNO, cleanup, "setxattr %s failed",
				 TESTFILE);
	}

	TEST_PAUSE;
}
开发者ID:Altiscale,项目名称:sig-core-t_ltp,代码行数:26,代码来源:getxattr03.c

示例11: put_sha1_file

static int put_sha1_file(char *name)
{
	uint32_t count;

	if (getxattr(name, CNAME, &count, CSIZE) < 0) {
		if (errno == ENOENT) {
			dprintf("sha1 file doesn't exist\n");
			return -1;
		} else {
			panic("%m\n");
		}
	}

	count--;
	if (count == 0) {
		if (unlink(name) < 0) {
			dprintf("%m\n");
			return -1;
		}
		dprintf("%s deleted\n", name);
	} else {
		if (setxattr(name, CNAME, &count, CSIZE, 0) < 0)
			panic("%m\n");
	}
	return 0;
}
开发者ID:yamt,项目名称:sheepdog,代码行数:26,代码来源:sha1_file.c

示例12: get_sha1_file

static void get_sha1_file(char *name)
{
	uint32_t count;
	if (getxattr(name, CNAME, &count, CSIZE) < 0) {
		if (errno == ENODATA) {
			count = 1;
			if (setxattr(name, CNAME, &count, CSIZE, 0) < 0)
				panic("%m\n");
			return;
		} else
			panic("%m\n");
	}
	count++;
	if (setxattr(name, CNAME, &count, CSIZE, 0) < 0)
			panic("%m\n");
}
开发者ID:yamt,项目名称:sheepdog,代码行数:16,代码来源:sha1_file.c

示例13: acl_set_file

/* 23.4.22 */
int
acl_set_file(const char *path_p, acl_type_t type, acl_t acl)
{
	acl_obj *acl_obj_p = ext2int(acl, acl);
	char *ext_acl_p;
	const char *name;
	size_t size;
	int error;

	if (!acl_obj_p)
		return -1;
	switch (type) {
		case ACL_TYPE_ACCESS:
			name = ACL_EA_ACCESS;
			break;
		case ACL_TYPE_DEFAULT:
			name = ACL_EA_DEFAULT;
			break;
		default:
			errno = EINVAL;
			return -1;
	}

	ext_acl_p = __acl_to_xattr(acl_obj_p, &size);
	if (!ext_acl_p)
		return -1;
	error = setxattr(path_p, name, (char *)ext_acl_p, size, 0);
	free(ext_acl_p);
	return error;
}
开发者ID:Distrotech,项目名称:acl,代码行数:31,代码来源:acl_set_file.c

示例14: xmp_create

static int xmp_create(const char* path, mode_t mode, struct fuse_file_info* fi) {
	char fpath[PATH_MAX];
	xmp_getfullpath(fpath, path);
	
    (void) fi;
    (void) mode;

	FILE *fd = fopen(fpath, "wb+");

	fprintf(stderr, "CREATE: fpath: %s\n", fpath);

	if(!do_crypt(fd, fd, ENCRYPT, ENCFS_DATA->passkey)){
		fprintf(stderr, "Create: do_crypt failed\n");
    }

	fprintf(stderr, "Create: encryption done correctly\n");

	fclose(fd);

	if(setxattr(fpath, XATRR_ENCRYPTED_FLAG, "true", 4, 0)){
    	fprintf(stderr, "error setting xattr of file %s\n", fpath);
    	return -errno;
   	}
   	fprintf(stderr, "Create: file xatrr correctly set %s\n", fpath);
   
    return 0;
}
开发者ID:kevinjpickard,项目名称:CSCI-3753,代码行数:27,代码来源:pa5-encfs.c

示例15: enc_create

static int enc_create(const char* path, mode_t mode, struct fuse_file_info* fi) {


  char fpath[PATH_MAX];
  enc_fullpath(fpath, path);


  (void) fi;
  (void) mode;

  FILE *f = fopen(fpath, "wb+");

  fprintf(stderr, "CREATE: fpath: %s\n", fpath);

  /* It is okay to encrypt a file into itself as long as it's empty
   *	otherwise the contents of the file would be erased.
   */

  if(!do_crypt(f, f, ENCRYPT, ENC_DATA->password)){
    fprintf(stderr, "Create: do_crypt failed\n");
  }

  fprintf(stderr, "Create: encryption done correctly\n");

  fclose(f);

  if(setxattr(fpath, XATRR_ENCRYPTED_FLAG, ENCRYPTED, 4, 0)){
    fprintf(stderr, "error setting xattr of file %s\n", fpath);
    return -errno;
  }
  fprintf(stderr, "Create: file xatrr correctly set %s\n", fpath);


  return 0;
}
开发者ID:danvn,项目名称:Operating-Systems,代码行数:35,代码来源:pa5-encfs.c


注:本文中的setxattr函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。