Esempio n. 1
0
int
cmd_ecache_flush(int cpuid)
{
	int fd;

	if ((fd = open(cmd.cmd_ecache_dev, O_RDONLY)) < 0) {
		if (errno != ENOENT)
			return (-1); /* errno is set for us */

		/*
		 * A DR may have occurred, thus rendering our path invalid.
		 * Try once to find another one.
		 */
		if (cmd_ecache_init() < 0 ||
		    (fd = open(cmd.cmd_ecache_dev, O_RDONLY)) < 0)
			return (-1); /* errno is set for us */
	}

	if (ioctl(fd, MCIOC_ECFLUSH, cpuid) < 0) {
		int oserr = errno;
		(void) close(fd);
		return (cmd_set_errno(oserr));
	}

	(void) close(fd);
	return (0);
}
Esempio n. 2
0
void *
cmd_buf_read(fmd_hdl_t *hdl, fmd_case_t *cp, const char *bufname, size_t bufsz)
{
	void *buf;
	size_t sz;

	if ((sz = fmd_buf_size(hdl, cp, bufname)) == 0) {
		(void) cmd_set_errno(ENOENT);
		return (NULL);
	} else if (sz != bufsz) {
		(void) cmd_set_errno(EINVAL);
		return (NULL);
	}

	buf = fmd_hdl_alloc(hdl, bufsz, FMD_SLEEP);
	fmd_buf_read(hdl, cp, bufname, buf, bufsz);

	return (buf);
}
Esempio n. 3
0
static int
ecache_scan_dir(const char *dir, const char *pref, char *buf, size_t bufsz)
{
	struct dirent *dp;
	char path[MAXPATHLEN];
	DIR *mcdir;

	if ((mcdir = opendir(dir)) == NULL)
		return (-1); /* errno is set for us */

	while ((dp = readdir(mcdir)) != NULL) {
		struct mc_ctrlconf mcc;
		int fd;

		if (strncmp(dp->d_name, pref, strlen(pref)) != 0)
			continue;

		(void) snprintf(path, sizeof (path), "%s/%s", dir, dp->d_name);

		if ((fd = open(path, O_RDONLY)) < 0)
			continue;

		mcc.nmcs = 0;
		if (ioctl(fd, MCIOC_CTRLCONF, &mcc) >= 0 || errno != EINVAL ||
		    mcc.nmcs == 0) {
			(void) close(fd);
			continue;
		}

		(void) close(fd);
		(void) closedir(mcdir);

		if (strlen(path) >= bufsz)
			return (cmd_set_errno(ENOSPC));
		(void) strcpy(buf, path);
		return (0);
	}

	(void) closedir(mcdir);
	return (cmd_set_errno(ENOENT));
}