libgeom: Remove redundant and duplicated code
In g_open(), g_device_path_open(). No functional change. Sponsored by: Dell EMC Isilon
This commit is contained in:
parent
985f4b3eb5
commit
b906c1a02a
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=323316
@ -56,8 +56,6 @@ g_open(const char *name, int dowrite)
|
||||
path = g_device_path_open(name, &fd, dowrite);
|
||||
if (path != NULL)
|
||||
free(path);
|
||||
if (fd == -1)
|
||||
return (-1);
|
||||
return (fd);
|
||||
}
|
||||
|
||||
@ -281,33 +279,21 @@ g_device_path_open(const char *devpath, int *fdp, int dowrite)
|
||||
/* Make sure that we can fail. */
|
||||
if (fdp != NULL)
|
||||
*fdp = -1;
|
||||
|
||||
/* Use the device node if we're able to open it. */
|
||||
do {
|
||||
fd = open(devpath, dowrite ? O_RDWR : O_RDONLY);
|
||||
if (fd == -1)
|
||||
break;
|
||||
/*
|
||||
* Let try to get sectorsize, which will prove it is a GEOM
|
||||
* provider.
|
||||
*/
|
||||
if (g_sectorsize(fd) == -1) {
|
||||
close(fd);
|
||||
errno = EFTYPE;
|
||||
return (NULL);
|
||||
}
|
||||
if (fd != -1) {
|
||||
if ((path = strdup(devpath)) == NULL) {
|
||||
close(fd);
|
||||
return (NULL);
|
||||
}
|
||||
if (fdp != NULL)
|
||||
*fdp = fd;
|
||||
else
|
||||
close(fd);
|
||||
return (path);
|
||||
} while (0);
|
||||
goto fd_ok;
|
||||
}
|
||||
|
||||
/* If we're not given an absolute path, assume /dev/ prefix. */
|
||||
if (*devpath != '/') {
|
||||
if (*devpath == '/')
|
||||
return (NULL);
|
||||
|
||||
asprintf(&path, "%s%s", _PATH_DEV, devpath);
|
||||
if (path == NULL)
|
||||
return (NULL);
|
||||
@ -316,9 +302,10 @@ g_device_path_open(const char *devpath, int *fdp, int dowrite)
|
||||
free(path);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
fd_ok:
|
||||
/*
|
||||
* Let try to get sectorsize, which will prove it is a GEOM
|
||||
* provider.
|
||||
* Let try to get sectorsize, which will prove it is a GEOM provider.
|
||||
*/
|
||||
if (g_sectorsize(fd) == -1) {
|
||||
free(path);
|
||||
@ -331,8 +318,6 @@ g_device_path_open(const char *devpath, int *fdp, int dowrite)
|
||||
else
|
||||
close(fd);
|
||||
return (path);
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
char *
|
||||
|
Loading…
Reference in New Issue
Block a user