Skip to content

Commit

Permalink
libzfs: constify zfs_strip_partition(), zfs_strip_path()
Browse files Browse the repository at this point in the history
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Closes openzfs#13413
  • Loading branch information
nabijaczleweli authored and nicman23 committed Aug 22, 2022
1 parent f98937b commit cfb6779
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
4 changes: 2 additions & 2 deletions include/libzutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ _LIBZUTIL_H int zfs_append_partition(char *path, size_t max_len);
_LIBZUTIL_H int zfs_resolve_shortname(const char *name, char *path,
size_t pathlen);

_LIBZUTIL_H char *zfs_strip_partition(char *);
_LIBZUTIL_H char *zfs_strip_path(char *);
_LIBZUTIL_H char *zfs_strip_partition(const char *);
_LIBZUTIL_H const char *zfs_strip_path(const char *);

_LIBZUTIL_H int zfs_strcmp_pathname(const char *, const char *, int);

Expand Down
6 changes: 3 additions & 3 deletions lib/libzfs/libzfs.abi
Original file line number Diff line number Diff line change
Expand Up @@ -5588,12 +5588,12 @@
<return type-id='95e97e5e'/>
</function-decl>
<function-decl name='zfs_strip_partition' mangled-name='zfs_strip_partition' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='zfs_strip_partition'>
<parameter type-id='26a90f95' name='path'/>
<parameter type-id='80f4b756' name='path'/>
<return type-id='26a90f95'/>
</function-decl>
<function-decl name='zfs_strip_path' mangled-name='zfs_strip_path' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='zfs_strip_path'>
<parameter type-id='26a90f95' name='path'/>
<return type-id='26a90f95'/>
<parameter type-id='80f4b756' name='path'/>
<return type-id='80f4b756'/>
</function-decl>
<function-decl name='zfs_get_enclosure_sysfs_path' mangled-name='zfs_get_enclosure_sysfs_path' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='zfs_get_enclosure_sysfs_path'>
<parameter type-id='80f4b756' name='dev_name'/>
Expand Down
7 changes: 5 additions & 2 deletions lib/libzfs/libzfs_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -4122,7 +4122,8 @@ char *
zpool_vdev_name(libzfs_handle_t *hdl, zpool_handle_t *zhp, nvlist_t *nv,
int name_flags)
{
char *path, *type;
char *type, *tpath;
const char *path;
uint64_t value;
char buf[PATH_BUF_LEN];
char tmpbuf[PATH_BUF_LEN * 2];
Expand All @@ -4147,7 +4148,9 @@ zpool_vdev_name(libzfs_handle_t *hdl, zpool_handle_t *zhp, nvlist_t *nv,
(void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID, &value);
(void) snprintf(buf, sizeof (buf), "%llu", (u_longlong_t)value);
path = buf;
} else if (nvlist_lookup_string(nv, ZPOOL_CONFIG_PATH, &path) == 0) {
} else if (nvlist_lookup_string(nv, ZPOOL_CONFIG_PATH, &tpath) == 0) {
path = tpath;

if (name_flags & VDEV_NAME_FOLLOW_LINKS) {
char *rp = realpath(path, NULL);
if (rp) {
Expand Down
6 changes: 3 additions & 3 deletions lib/libzutil/os/freebsd/zutil_device_path_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* Note: The caller must free the returned string.
*/
char *
zfs_strip_partition(char *dev)
zfs_strip_partition(const char *dev)
{
return (strdup(dev));
}
Expand All @@ -56,8 +56,8 @@ zfs_append_partition(char *path, size_t max_len)
* On FreeBSD we only want to remove "/dev/" from the beginning of
* paths if present.
*/
char *
zfs_strip_path(char *path)
const char *
zfs_strip_path(const char *path)
{
if (strncmp(path, _PATH_DEV, sizeof (_PATH_DEV) - 1) == 0)
return (path + sizeof (_PATH_DEV) - 1);
Expand Down
8 changes: 4 additions & 4 deletions lib/libzutil/os/linux/zutil_device_path_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ zfs_append_partition(char *path, size_t max_len)
* caller must free the returned string
*/
char *
zfs_strip_partition(char *path)
zfs_strip_partition(const char *path)
{
char *tmp = strdup(path);
char *part = NULL, *d = NULL;
Expand Down Expand Up @@ -117,7 +117,7 @@ zfs_strip_partition(char *path)
* Returned string must be freed.
*/
static char *
zfs_strip_partition_path(char *path)
zfs_strip_partition_path(const char *path)
{
char *newpath = strdup(path);
char *sd_offset;
Expand Down Expand Up @@ -148,8 +148,8 @@ zfs_strip_partition_path(char *path)
/*
* Strip the unwanted portion of a device path.
*/
char *
zfs_strip_path(char *path)
const char *
zfs_strip_path(const char *path)
{
return (strrchr(path, '/') + 1);
}
Expand Down

0 comments on commit cfb6779

Please sign in to comment.