]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
hash-funcs: tweak odering in devt_compare_func()
authorLennart Poettering <lennart@poettering.net>
Fri, 1 Apr 2022 12:21:44 +0000 (14:21 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 4 Apr 2022 15:04:14 +0000 (17:04 +0200)
Let's order dev_t's by their major first, minor secondary. The binary
encoding of the two fields is weirdly interleaved and different in
kernel and glibc, hence let's focus on the generic part that works like
users would expect it.

So far the function is only used to compare for equality, not for
sorting, hence this has no immediate effect.

src/basic/hash-funcs.c
src/basic/hash-funcs.h

index 084ed0c0a2afb9e8efb86d06a5bb36dcd5c39a38..6addb76f1b2d52cd18df19794bcbef922db99b77 100644 (file)
@@ -102,10 +102,16 @@ DEFINE_HASH_OPS(uint64_hash_ops, uint64_t, uint64_hash_func, uint64_compare_func
 void devt_hash_func(const dev_t *p, struct siphash *state) {
         siphash24_compress(p, sizeof(dev_t), state);
 }
+#endif
 
 int devt_compare_func(const dev_t *a, const dev_t *b) {
-        return CMP(*a, *b);
+        int r;
+
+        r = CMP(major(*a), major(*b));
+        if (r != 0)
+                return r;
+
+        return CMP(minor(*a), minor(*b));
 }
 
 DEFINE_HASH_OPS(devt_hash_ops, dev_t, devt_hash_func, devt_compare_func);
-#endif
index 023cfdf5307d25908034685b3859646e3e0929ce..c537c6af7e8cc2a9f8761cf15e53aeb72524ee15 100644 (file)
@@ -102,10 +102,9 @@ extern const struct hash_ops uint64_hash_ops;
  * 64bit archs. Yuck! */
 #if SIZEOF_DEV_T != 8
 void devt_hash_func(const dev_t *p, struct siphash *state) _pure_;
-int devt_compare_func(const dev_t *a, const dev_t *b) _pure_;
-extern const struct hash_ops devt_hash_ops;
 #else
 #define devt_hash_func uint64_hash_func
-#define devt_compare_func uint64_compare_func
-#define devt_hash_ops uint64_hash_ops
 #endif
+
+int devt_compare_func(const dev_t *a, const dev_t *b) _pure_;
+extern const struct hash_ops devt_hash_ops;