Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-ports-kde
Path: blob/main/filesystems/libblkid/files/patch-libblkid_src_probe.c
17780 views
1
--- libblkid/src/probe.c.orig 2025-06-24 07:55:28 UTC
2
+++ libblkid/src/probe.c
3
@@ -594,7 +594,18 @@ static struct blkid_bufinfo *read_buffer(blkid_probe p
4
DBG(LOWPROBE, ul_debug("\tread: off=%"PRIu64" len=%"PRIu64"",
5
real_off, len));
6
7
- ret = read(pr->fd, bf->data, len);
8
+ /* on FreeBSD, devices are unbuffered so we need to align to full I/O blocks by ourselves */
9
+ if (len % pr->io_size) {
10
+ unsigned rawlen = len + (pr->io_size - len % pr->io_size);
11
+ char buf[rawlen];
12
+ ret = read(pr->fd, buf, rawlen);
13
+ if (ret < 0 || ret < len)
14
+ return NULL;
15
+ memcpy(bf->data, buf, len);
16
+ ret = len;
17
+ } else {
18
+ ret = read(pr->fd, bf->data, len);
19
+ }
20
if (ret != (ssize_t) len) {
21
DBG(LOWPROBE, ul_debug("\tread failed: %m"));
22
remove_buffer(bf);
23
@@ -718,7 +729,7 @@ const unsigned char *blkid_probe_get_buffer(blkid_prob
24
struct blkid_bufinfo *bf = NULL;
25
uint64_t real_off, bias, len_align;
26
27
- bias = off % pr->io_size;
28
+ bias = off % /* pr->io_size */ 4096;
29
off -= bias;
30
len += bias;
31
32
@@ -1106,6 +1117,7 @@ int blkid_probe_set_device(blkid_probe pr, int fd,
33
goto err;
34
}
35
} else if (S_ISCHR(sb.st_mode)) {
36
+#ifdef __linux__
37
char buf[PATH_MAX];
38
39
if (!sysfs_chrdev_devno_to_devname(sb.st_rdev, buf, sizeof(buf))
40
@@ -1114,6 +1126,9 @@ int blkid_probe_set_device(blkid_probe pr, int fd,
41
errno = EINVAL;
42
goto err;
43
}
44
+#else
45
+ /* no-op, FreeBSD maps block devices as character */
46
+#endif
47
devsiz = 1; /* UBI devices are char... */
48
} else if (S_ISREG(sb.st_mode))
49
devsiz = sb.st_size; /* regular file */
50
51