| 1030 | } |
| 1031 | |
| 1032 | int |
| 1033 | make_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 | } |
| 1086 | out: |
| 1087 | if (old_alias != NULL) |
| 1088 | destroy_dev(old_alias); |
| 1089 | if (devfspath != NULL) |
nothing calls this directly
no test coverage detected