tools/hv/hv_fcopy_uio_daemon.c

Source file repositories/reference/linux-study-clean/tools/hv/hv_fcopy_uio_daemon.c

File Facts

System
Linux kernel
Corpus path
tools/hv/hv_fcopy_uio_daemon.c
Extension
.c
Size
13663 bytes
Lines
560
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

if (!dir) {
			syslog(LOG_ERR, "Failed to open channels directory: %s", strerror(errno));
			return 0;
		}
	}

retry_once:
	while ((entry = readdir(dir)) != NULL) {
		if (entry->d_type == DT_DIR && strcmp(entry->d_name, ".") != 0 &&
		    strcmp(entry->d_name, "..") != 0) {
			snprintf(ring_path, sizeof(ring_path), "%s/%s/ring",
				 FCOPY_CHANNELS_PATH, entry->d_name);

			if (stat(ring_path, &st) == 0) {
				/*
				 * stat returns size of Tx, Rx rings combined,
				 * so take half of it for individual ring size.
				 */
				ring_size = (uint32_t)st.st_size / 2;
				syslog(LOG_INFO, "Ring buffer size from %s: %u bytes",
				       ring_path, ring_size);
				break;
			}
		}
	}

	if (!ring_size && retry_count == 0) {
		retry_count = 1;
		rewinddir(dir);
		usleep(100 * 1000); /* Wait 100ms and retry once */
		goto retry_once;
	}

	closedir(dir);

	if (!ring_size)
		syslog(LOG_ERR, "Could not determine ring size");

	return ring_size;
}

static unsigned char *desc;

static int target_fd;
static char target_fname[PATH_MAX];
static unsigned long long filesize;

static int hv_fcopy_create_file(char *file_name, char *path_name, __u32 flags)
{
	int error = HV_E_FAIL;
	char *q, *p;

	filesize = 0;
	p = path_name;
	if (snprintf(target_fname, sizeof(target_fname), "%s/%s",
		     path_name, file_name) >= sizeof(target_fname)) {
		syslog(LOG_ERR, "target file name is too long: %s/%s", path_name, file_name);
		goto done;
	}

	/*
	 * Check to see if the path is already in place; if not,
	 * create if required.
	 */
	while ((q = strchr(p, '/')) != NULL) {
		if (q == p) {
			p++;
			continue;
		}
		*q = '\0';
		if (access(path_name, F_OK)) {
			if (flags & CREATE_PATH) {
				if (mkdir(path_name, 0755)) {
					syslog(LOG_ERR, "Failed to create %s",
					       path_name);
					goto done;
				}
			} else {
				syslog(LOG_ERR, "Invalid path: %s", path_name);
				goto done;
			}
		}
		p = q + 1;
		*q = '/';
	}

	if (!access(target_fname, F_OK)) {
		syslog(LOG_INFO, "File: %s exists", target_fname);
		if (!(flags & OVER_WRITE)) {
			error = HV_ERROR_ALREADY_EXISTS;

Annotation

Implementation Notes