Bug 252488 - bsdtar fails to work with 128k blocksize
Summary: bsdtar fails to work with 128k blocksize
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 11.4-STABLE
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-01-07 09:25 UTC by Andre Albsmeier
Modified: 2021-01-08 06:55 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andre Albsmeier 2021-01-07 09:25:28 UTC
Prerequisites: tape written with 128k block size, mt blocksize 131072

bsdtar -tf /dev/sa0 -b 256

gives

sa0: request ptr 0x2888ed80 is not on a page boundary; cannot split request
bsdtar: Error opening archive: Error reading '/dev/sa0'

This seems to be an alignment problem. The problem goes away after aligning
the buffer in archive_read_open_filename.c:

--- archive_read_open_filename.c.ORI   2020-03-13 08:22:53.000000000 +0100
+++ archive_read_open_filename.c       2021-01-06 10:37:34.176333000 +0100
@@ -359,12 +359,17 @@
                        new_block_size *= 2;
                mine->block_size = new_block_size;
        }
+#if 0
        buffer = malloc(mine->block_size);
+#else
+       buffer = malloc(mine->block_size + 4096);
+#endif
        if (buffer == NULL) {
                archive_set_error(a, ENOMEM, "No memory");
                goto fail;
        }
        mine->buffer = buffer;
+       mine->buffer = (void*)(((u_int32_t)buffer + 4096) & ~4095);
        mine->fd = fd;
        /* Remember mode so close can decide whether to flush. */
        mine->st_mode = st.st_mode;


This is NO patch to fix the issue -- it's just to show the origin of the problem . A proper patch will probably use PAGESIZE and distinguish between malloc start and aligned buffer (so it can bee free()ed).
Comment 1 Conrad Meyer freebsd_committer freebsd_triage 2021-01-08 00:52:14 UTC
See aligned_alloc(3).

But it is bizarre that a device driver does not support reads into unaligned user addresses.
Comment 2 Andre Albsmeier 2021-01-08 06:55:54 UTC
Thanks for aligned_alloc(), didn't know that.

Maybe sa(4) would allow this with kern.cam.sa.allow_io_split but if I read the comments correctly, this will go away (or should have been gone already).