Skip to content

libblkid: tag: allow case-insensitive matching of specific tags #2558

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

a1batross
Copy link

Textual representation of UUID and PARTUUID is a hexadecimal values.

The letters case in hex doesn't affect the value it represent, therefore let's do case-insensitive string comparison of such tags.

This patch makes it more convenient to match UUID and PARTUUID tags using blkid utility. For example, before this patch:

root@rk3568-ag:~# blkid -t PARTUUID=1C7EE182-861E-4850-8F4C-0D6638F8797A -o device -l
root@rk3568-ag:~# blkid -t PARTUUID=1c7ee182-861e-4850-8f4c-0d6638f8797a -o device -l
/dev/mmcblk1p2

And after:

root@rk3568-ag:~# blkid -t PARTUUID=1c7ee182-861e-4850-8f4c-0d6638f8797a -o device -l
/dev/mmcblk1p2
root@rk3568-ag:~# blkid -t PARTUUID=1C7EE182-861E-4850-8F4C-0D6638F8797A -o device -l
/dev/mmcblk1p2

Textual representation of UUID and PARTUUID is a hexadecimal values.

The letters case in hex doesn't affect the value it represent, therefore
let's do case-insensitive string comparison of such tags.

Signed-off-by: Alibek Omarov <a1ba.omarov@gmail.com>
@a1batross
Copy link
Author

a1batross commented Oct 23, 2023

@karelzak could you review this please?

@karelzak
Copy link
Collaborator

karelzak commented Oct 23, 2023

There was a discussion about it years ago: https://www.spinics.net/lists/util-linux-ng/msg16750.html (probably my mistake that it was not resolved).

  • strcasecmp() is locale-sensitive, but we do not need locales in this case (hex codes). It would probably be better to use include/cctype.h:c_strncasecmp(), which always works with ASCII
  • libmount/src/cache.c:cache_find_tag() may also compare tags
  • libblkid/src/evaluate.c:evaluate_by_udev() generates a symlink path to use udevd to verify the tag. It seems we need to try lower-case and upper-case path
  • libblkid/src/evaluate.c:verify_tag() may also compare the tag (the code is not used by default, but it should be probably nice to improve it too)

@karelzak
Copy link
Collaborator

karelzak commented Oct 23, 2023

Maybe you can add to include/strutils.c a new function ul_hexcmp() to compare two hex strings in locales and case-independent way.

@a1batross
Copy link
Author

Generic function, just to compare hex values sounds better than strcasecmp, I agree.

The UUID string format isn't just hex, like it also includes dashes, so if we compare UUID strings here, it shall be ul_uuidcmp, which would accept only [0-9a-f-] set of characters?

Thank you for listing other functions that does compare tags, I'm not very familiar with this code. I will send a v2 later then, thank you!

@karelzak
Copy link
Collaborator

Ah, good point. You're right; it's not about hex only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants