MCPcopy Create free account
hub / github.com/F-Stack/f-stack / make_dev_physpath_alias

Function make_dev_physpath_alias

freebsd/kern/kern_conf.c:1032–1092  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1030}
1031
1032int
1033make_dev_physpath_alias(int flags, struct cdev **cdev, struct cdev *pdev,
1034 struct cdev *old_alias, const char *physpath)
1035{
1036 char *devfspath;
1037 int physpath_len;
1038 int max_parentpath_len;
1039 int parentpath_len;
1040 int devfspathbuf_len;
1041 int mflags;
1042 int ret;
1043
1044 *cdev = NULL;
1045 devfspath = NULL;
1046 physpath_len = strlen(physpath);
1047 ret = EINVAL;
1048 if (physpath_len == 0)
1049 goto out;
1050
1051 if (strncmp("id1,", physpath, 4) == 0) {
1052 physpath += 4;
1053 physpath_len -= 4;
1054 if (physpath_len == 0)
1055 goto out;
1056 }
1057
1058 max_parentpath_len = SPECNAMELEN - physpath_len - /*/*/1;
1059 parentpath_len = strlen(pdev->si_name);
1060 if (max_parentpath_len < parentpath_len) {
1061 if (bootverbose)
1062 printf("WARNING: Unable to alias %s "
1063 "to %s/%s - path too long\n",
1064 pdev->si_name, physpath, pdev->si_name);
1065 ret = ENAMETOOLONG;
1066 goto out;
1067 }
1068
1069 mflags = (flags & MAKEDEV_NOWAIT) ? M_NOWAIT : M_WAITOK;
1070 devfspathbuf_len = physpath_len + /*/*/1 + parentpath_len + /*NUL*/1;
1071 devfspath = malloc(devfspathbuf_len, M_DEVBUF, mflags);
1072 if (devfspath == NULL) {
1073 ret = ENOMEM;
1074 goto out;
1075 }
1076
1077 sprintf(devfspath, "%s/%s", physpath, pdev->si_name);
1078 if (old_alias != NULL && strcmp(old_alias->si_name, devfspath) == 0) {
1079 /* Retain the existing alias. */
1080 *cdev = old_alias;
1081 old_alias = NULL;
1082 ret = 0;
1083 } else {
1084 ret = make_dev_alias_p(flags, cdev, pdev, "%s", devfspath);
1085 }
1086out:
1087 if (old_alias != NULL)
1088 destroy_dev(old_alias);
1089 if (devfspath != NULL)

Callers

nothing calls this directly

Calls 8

strncmpFunction · 0.85
mallocFunction · 0.85
sprintfFunction · 0.85
strcmpFunction · 0.85
make_dev_alias_pFunction · 0.85
destroy_devFunction · 0.85
printfFunction · 0.70
freeFunction · 0.70

Tested by

no test coverage detected