arch/um/os-Linux/umid.c

Source file repositories/reference/linux-study-clean/arch/um/os-Linux/umid.c

File Facts

System
Linux kernel
Corpus path
arch/um/os-Linux/umid.c
Extension
.c
Size
8208 bytes
Lines
410
Domain
Architecture Layer
Bucket
arch/um
Inferred role
Architecture Layer: implementation source
Status
source implementation candidate

Why This File Exists

CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.

Dependency Surface

Detected Declarations

Annotated Snippet

if (home == NULL) {
			printk(UM_KERN_ERR
				"%s: no value in environment for $HOME\n",
				__func__);
			goto err;
		}
		strscpy(dir, home);
		uml_dir++;
	}
	strlcat(dir, uml_dir, sizeof(dir));
	len = strlen(dir);
	if (len > 0 && dir[len - 1] != '/')
		strlcat(dir, "/", sizeof(dir));

	err = -ENOMEM;
	uml_dir = malloc(strlen(dir) + 1);
	if (uml_dir == NULL) {
		printk(UM_KERN_ERR "%s : malloc failed, errno = %d\n",
			__func__, errno);
		goto err;
	}
	strcpy(uml_dir, dir);

	if ((mkdir(uml_dir, 0777) < 0) && (errno != EEXIST)) {
		printk(UM_KERN_ERR "Failed to mkdir '%s': %s\n",
			uml_dir, strerror(errno));
		err = -errno;
		goto err_free;
	}
	return 0;

err_free:
	free(uml_dir);
err:
	uml_dir = NULL;
	return err;
}

/*
 * Unlinks the files contained in @dir and then removes @dir.
 * Doesn't handle directory trees, so it's not like rm -rf, but almost such. We
 * ignore ENOENT errors for anything (they happen, strangely enough - possibly
 * due to races between multiple dying UML threads).
 */
static int remove_files_and_dir(char *dir)
{
	DIR *directory;
	struct dirent *ent;
	int len;
	char file[256];
	int ret;

	directory = opendir(dir);
	if (directory == NULL) {
		if (errno != ENOENT)
			return -errno;
		else
			return 0;
	}

	while ((ent = readdir(directory)) != NULL) {
		if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."))
			continue;
		len = strlen(dir) + strlen("/") + strlen(ent->d_name) + 1;
		if (len > sizeof(file)) {
			ret = -E2BIG;
			goto out;
		}

		sprintf(file, "%s/%s", dir, ent->d_name);
		if (unlink(file) < 0 && errno != ENOENT) {
			ret = -errno;
			goto out;
		}
	}

	if (rmdir(dir) < 0 && errno != ENOENT) {
		ret = -errno;
		goto out;
	}

	ret = 0;
out:
	closedir(directory);
	return ret;
}

/*
 * This says that there isn't already a user of the specified directory even if
 * there are errors during the checking.  This is because if these errors

Annotation

Implementation Notes