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.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
stdio.hstdlib.hdirent.herrno.hfcntl.hsignal.hstring.hunistd.hsys/stat.hinit.hos.h
Detected Declarations
function make_uml_dirfunction anythingfunction is_umdir_usedfunction umdir_take_if_deadfunction create_pid_filefunction set_umidfunction make_umidfunction make_umid_initfunction umid_file_namefunction set_uml_dirfunction remove_umid_dir
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
- Immediate include surface: `stdio.h`, `stdlib.h`, `dirent.h`, `errno.h`, `fcntl.h`, `signal.h`, `string.h`, `unistd.h`.
- Detected declarations: `function make_uml_dir`, `function anything`, `function is_umdir_used`, `function umdir_take_if_dead`, `function create_pid_file`, `function set_umid`, `function make_umid`, `function make_umid_init`, `function umid_file_name`, `function set_uml_dir`.
- Atlas domain: Architecture Layer / arch/um.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.