exfat: add EXFAT_IOC_COMBINE to append a file's clusters to another
Subsystems (4)
PATCH v7 1/1 exfat: add EXFAT_IOC_COMBINE to append a file's clusters to another
Cameras and dashcams recording to exFAT SD cards often write the video stream and auxiliary data (e.g. IMU samples) to separate files and merge them when recording stops. Doing that with read()/write() or copy_file_range() copies all the data of the source, which takes time proportional to its size on such media, wears the flash and needs free space for a second copy.
Filesystems supporting reflink can already avoid the copy by cloning the source to the end of the destination with FICLONERANGE and then unlinking it. exFAT cannot share clusters between files, so it needs an operation that moves them instead. Its semantics follow from the exFAT on-disk format (cluster granularity, a single valid_size per file), so it is added as an exfat ioctl rather than a VFS interface; fallocate() does not fit either, as it only takes a single file.
Add an ioctl that moves the cluster chain of a source file to the end of a destination file and then unlinks the source, so that only metadata changes: the FAT, the stream extension entry of the destination and the entry set of the source:
struct exfat_combine_args args = { .src_fd = src_fd };
ioctl(dst_fd, EXFAT_IOC_COMBINE, &args);The source is unlinked as unlink(2) does it: start_removing_dentry() revalidates the dentry of the open file and locks its parent, and security_path_unlink() and vfs_unlink() check permissions and security modules, break leases and delegations, and handle mount points; vfs_unlink() calls exfat_unlink(), which deletes the entry set. Since the in-memory inode no longer owns the clusters, evicting it frees nothing. The checks that can be made without unlinking are made before anything is changed, and an already unlinked source is accepted. An unlinked destination is refused with -ENOENT, as its entry is no longer written and the data of the source would be lost with it.
The source must be open for reading and writing, as it is emptied and its data becomes readable through the destination, and the destination for writing; both must be regular files on the same mount. Files whose allocation, chain layout or valid_size are inconsistent, as after a failed truncate or on a corrupt volume, or that are found to share clusters, are refused with -EIO before anything is changed.
exFAT has a single size and valid_size per file, so clusters can only be appended at a cluster boundary of a fully initialized file. The destination is therefore first zero-filled up to the end of its last cluster with exfat_extend_valid_size(), leaving a zero-filled gap between the original and the appended data when its size is not cluster aligned. This is documented in the uapi header, and keeps stale on-disk data out of the file.
exFAT has no journal, so the data and the FAT, then the destination entry, then the deletion of the source entry set are written and flushed to the device in that order, as recommended by section 8.1 of the exFAT specification; the allocation bitmap is not touched. A crash at any point leaves all data reachable from at least one entry. In the worst case both entries share the appended clusters; fsck.exfat keeps them in the file it checks first and truncates the other one, so either the combine has completed or the source still holds its data. On a volume that was not cleanly unmounted, the call fails with -EUCLEAN until fsck.exfat has run, so that it never works on clusters that two files may already share or that may already be linked. Once the volume is in an emergency state, nothing more is written, which leaves what a crash at that point would. If the call fails
before the clusters are moved, the padding is removed again; what was already written back is kept initialized, as exfat_extend_valid_size() does on failure. s_lock is only held while updating the FAT and the entries, not while waiting for the device, so that writers to other files on the volume are not stalled.
No file data is copied, so the cost depends on the number of clusters (when a FAT chain has to be built for a contiguous file) rather than on the amount of data.
The ioctl number is taken from the 'r' range next to the FAT ioctls. A user space tool for exfatprogs (exfatcombine) and a test for fstests (exfat/002) are posted separately.
This patch was written with the help of an AI coding assistant (Claude Code, Opus 5.5); I have reviewed and tested the result.
---
Notes:
Changes in v7, following the Sashiko review of v6 [1]:
- When flushing the metadata, after Step 1 and after unlinking the source, also check the errseq of the block device mapping, not only the return value of sync_blockdev(): its error flags go to whoever checks them first, an fsync() of any file on the volume included. On a volume mounted with -o sync, a failed write of the FAT in Step 1 is only recorded there, so v6 could write the entry of the destination over a chain that never reached the disk. This also catches a failed write of the dirty flag at the start of Step 1, which exfat_set_volume_dirty() does not report, and without which a crash during the call would not lead to -EUCLEAN. The errseq is advanced, so that an error nobody had seen before the call fails one call only.
This applies to linux-next (tested on next-20261118). It uses exfat_emergency_state(), which comes with "exfat: don't set SB_RDONLY after filesystem errors" in the vfs tree (vfs-7.5.super.ro), so it does not build on the exfat dev branch until that is merged there. I can rebase it onto exfat dev then.
Testing (linux-next 20261118 + this patch, arm64):
- Reproduced on v6 and checked on v7 with fail_make_request and a test-only delay between Step 1 and its flush: on a volume mounted with -o sync, the write of the FAT sector holding the chain of the source fails and an fsync() of another file takes the error. v6 reported success and unlinked the source, leaving the destination with a broken chain (exfat set the volume read-only when reading it, fsck.exfat truncates it); v7 fails with -EIO and leaves both files unchanged. The same when the write of the dirty flag fails instead:
v6 combined the files with the volume still marked clean on disk.
- All tests reported for v6 were rerun and pass, including the cases that use test-only knobs, and fstests exfat/001 and exfat/002.
- Builds without warnings with W=1 for arm64 (gcc, clang), arm and i386, built-in and as a module; no new sparse warnings.
- Not rerun for v7: the long-running tests reported for v2.
- Known limits, as for v6: a source chain running through the destination is not found if the volume has enough other clusters in use; after a forced shutdown, unmounting still clears the dirty flag (an existing exfat behaviour), so a volume left with only the FAT updated is not refused afterwards.
[1] https://sashiko.dev/#/patchset/20261124212236.830224-1-shaopei_1012%40163.com
v6: https://lore.kernel.org/all/[email protected]/
v5: https://lore.kernel.org/all/[email protected]/
v4: https://lore.kernel.org/all/[email protected]/
v3: https://lore.kernel.org/all/[email protected]/
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/
.../userspace-api/ioctl/ioctl-number.rst | 1 + fs/exfat/file.c | 740 ++++++++++++++++++ include/uapi/linux/exfat.h | 48 ++ 3 files changed, 789 insertions(+)
Documentation/userspace-api/ioctl/ioctl-number.rst +1 -0
@@ -292,6 +292,7 @@ Code Seq# Include File Comments 'q' 80-FF linux/telephony.h Internet PhoneJACK, Internet LineJACK linux/ixjuser.h <http://web.archive.org/web/%2A/http://www.quicknet.net> 'r' 00-1F linux/msdos_fs.h and fs/fat/dir.c +'r' 20-2F linux/exfat.h 's' all linux/cdk.h 't' 00-7F linux/ppp-ioctl.h 't' 80-8F linux/isdn_ppp.h
fs/exfat/file.c +740 -0
760 lines not on this page · raw message
include/uapi/linux/exfat.h +48 -0
58 lines not on this page · raw message
Signature · 1 line
2.50.1 (Apple Git-155)
Namjae Jeon
maintainerQuoted 7 lines · Shaopei Zhu
Cameras and dashcams recording to exFAT SD cards often write the video stream and auxiliary data (e.g. IMU samples) to separate files and merge them when recording stops. Doing that with read()/write() or
copy_file_range()copies all the data of the source, which takes time proportional to its size on such media, wears the flash and needs free space for a second copy.
Is there a specific device or product expected to use this feature, or is it being added as a potentially useful capability without a concrete use case? If there is a target device or workflow, could you share some details?
Quoted 9 lines
Filesystems supporting reflink can already avoid the copy by cloning the source to the end of the destination with FICLONERANGE and then unlinking it. exFAT cannot share clusters between files, so it needs an operation that moves them instead. Its semantics follow from the exFAT on-disk format (cluster granularity, a single
valid_sizeper file), so it is added as an exfat ioctl rather than a VFS interface;fallocate()does not fit either, as it only takes a single file.
Quoted 4 lines
Add an ioctl that moves the cluster chain of a source file to the end of a destination file and then unlinks the source, so that only metadata changes: the FAT, the stream extension entry of the destination and the entry set of the source:
I suggest changing EXFAT_IOC_COMBINE to transfer only the source’s cluster chain to the destination, leaving the source linked as an empty file. Userspace can unlink it afterward if desired.
Thanks for the patch.
Quoted 4 lines · Namjae Jeon
Is there a specific device or product expected to use this feature, or is it being added as a potentially useful capability without a concrete use case? If there is a target device or workflow, could you share some details?
Hi Namjae,
Thanks for the review. Yes, it is going to be used in camera products that record to exFAT SD cards. The open source user is exfatcombine, posted for exfatprogs [1], and a test for fstests (exfat/002) is posted as well.
The workflow: cameras and dashcams keep motion or position data with the video, e.g. gyroscope and accelerometer samples for stabilization, or GPS.
The products on the market keep that data in one of three ways:
- as a timed metadata track inside the MP4, e.g. GoPro's GPMF, muxed while recording, so that the samples are interleaved with the video in the mdat box and indexed in the moov box;
- as a separate sidecar file next to the video, e.g. the GPS logs of dashcams;
- as a trailer appended after the MP4 boxes when recording stops, which players ignore and stabilization tools read.
A sidecar file is lost in practice: users copy, share or import only the video file, and matching the two by name breaks once either is renamed or moved. A track needs the muxer to take the samples in real time along with the video. Where the sensor data comes from another writer, at a few hundred samples per second, it cannot go into the file the muxer is writing, so it is written to a separate file in the same directory during recording and appended as a trailer when recording stops.
That last step is what this ioctl is for. Today the sensor file is copied into the video file, up to tens of MiB per recording, while the user waits for the camera to be ready again, with flash wear and free space needed for the copy. With this ioctl its clusters are appended to the video file instead, and the sensor file is removed.
Quoted 3 lines
I suggest changing
EXFAT_IOC_COMBINEto transfer only the source's cluster chain to the destination, leaving the source linked as an empty file. Userspace can unlink it afterward if desired.
The sensor file is only a temporary part of the recording. With the unlink in the same call, a power loss, e.g. the battery being pulled right after recording stops, leaves one of the two states the recording application already handles: not combined yet, or combined. With the unlink in user space there is a third one, the combined video next to an empty sensor file, which looks like the first one unless every application also checks the size of the file. It would be easy to append the sensor data a second time, or to leave an empty file on a card that users read directly.
Doing it in the same call also refuses the whole call before anything is changed if the source may not be removed, instead of leaving an emptied file that cannot be deleted, and it removes the file that was passed in, not whatever its name refers to by the time user space gets to unlink it. The unlink goes through start_removing_dentry(), security_path_unlink() and vfs_unlink(), so it gets the same checks as unlink(2).
Does this address your concern?
Thanks,
Shaopei
Namjae Jeon
maintainerQuoted 8 lines · Shaopei Zhu
Quoted 4 lines · Namjae Jeon
Is there a specific device or product expected to use this feature, or is it being added as a potentially useful capability without a concrete use case? If there is a target device or workflow, could you share some details?
Hi Namjae,
Hi Shaopei,
Quoted 29 lines
Thanks for the review. Yes, it is going to be used in camera products that record to exFAT SD cards. The open source user is exfatcombine, posted for exfatprogs [1], and a test for fstests (exfat/002) is posted as well.
The workflow: cameras and dashcams keep motion or position data with the video, e.g. gyroscope and accelerometer samples for stabilization, or GPS.
The products on the market keep that data in one of three ways:
- as a timed metadata track inside the MP4, e.g. GoPro's GPMF, muxed while recording, so that the samples are interleaved with the video in the mdat box and indexed in the moov box;
- as a separate sidecar file next to the video, e.g. the GPS logs of dashcams;
- as a trailer appended after the MP4 boxes when recording stops, which players ignore and stabilization tools read.A sidecar file is lost in practice: users copy, share or import only the video file, and matching the two by name breaks once either is renamed or moved. A track needs the muxer to take the samples in real time along with the video. Where the sensor data comes from another writer, at a few hundred samples per second, it cannot go into the file the muxer is writing, so it is written to a separate file in the same directory during recording and appended as a trailer when recording stops.
Quoted 5 lines
That last step is what this ioctl is for. Today the sensor file is copied into the video file, up to tens of MiB per recording, while the user waits for the camera to be ready again, with flash wear and free space needed for the copy. With this ioctl its clusters are appended to the video file instead, and the sensor file is removed.
Okay.
Quoted 23 lines
Quoted 4 lines
I suggest changing
EXFAT_IOC_COMBINEto transfer only the source's cluster chain to the destination, leaving the source linked as an empty file. Userspace can unlink it afterward if desired.The sensor file is only a temporary part of the recording. With the unlink in the same call, a power loss, e.g. the battery being pulled right after recording stops, leaves one of the two states the recording application already handles: not combined yet, or combined. With the unlink in user space there is a third one, the combined video next to an empty sensor file, which looks like the first one unless every application also checks the size of the file. It would be easy to append the sensor data a second time, or to leave an empty file on a card that users read directly.
Doing it in the same call also refuses the whole call before anything is changed if the source may not be removed, instead of leaving an emptied file that cannot be deleted, and it removes the file that was passed in, not whatever its name refers to by the time user space gets to unlink it. The unlink goes through
start_removing_dentry(),security_path_unlink()andvfs_unlink(), so it gets the same checks as unlink(2).
Quoted 1 line
Does this address your concern?
Unlinking in the ioctl does not make the operation atomic against power loss. It only avoids the interval between a successful ioctl and a later userspace unlink. I don't think that is a reason for the kernel to perform the unlink. exfatcombine already has the source path and opens the file to pass its file descriptor to the ioctl. It can unlink the source file after the ioctl succeeds and report an error if that fails. The ioctl should only append the source file's cluster chain to the destination file. Callers must prevent concurrent renames or replacements if they need the pathname to continue referring to the same file.
Quoted 10 lines · Namjae Jeon
Unlinking in the ioctl does not make the operation atomic against power loss. It only avoids the interval between a successful ioctl and a later userspace unlink. I don't think that is a reason for the kernel to perform the unlink. exfatcombine already has the source path and opens the file to pass its file descriptor to the ioctl. It can unlink the source file after the ioctl succeeds and report an error if that fails. The ioctl should only append the source file's cluster chain to the destination file. Callers must prevent concurrent renames or replacements if they need the pathname to continue referring to the same file.
Hi Namjae,
Thank you, that is a fair point and a valuable suggestion. I will rework the interface as you suggest in the next version.
I went through it again. You are right that the unlink does not make the operation atomic: a power loss in the middle can still leave both entries referencing the clusters until fsck.exfat has run, so it only removed the interval after the ioctl. The state user space has to handle instead, an empty source next to a destination that already holds its data, is harmless and easy to recognize. I also looked at the existing interfaces that move or share data between files, FICLONERANGE, copy_file_range(), F2FS_IOC_MOVE_RANGE, EXT4_IOC_MOVE_EXT and XFS_IOC_EXCHANGE_RANGE, and none of them removes the source; that is left to the caller, which already has the path and the permission checks of unlink(2).
So in v8 the ioctl only appends the cluster chain of the source and leaves it as an empty file, written to disk after the destination. The unlink code in the kernel goes away, and with it the bind mount, dead parent and failed-unlink handling it needed. exfatcombine unlinks the source after the ioctl succeeds and reports an error if that fails, and the uapi header documents that the caller unlinks the source and has to prevent concurrent renames if it relies on the name. The fstests case and the exfatprogs PR will be updated to match.
Thanks again for the review.
Shaopei
Hello,
This is Davo coming from exfatprogs. I noticed the PR in GH which brought me here.
On 11/26/26 07:52, Shaopei Zhu wrote:
[...]
Quoted 14 lines
The workflow: cameras and dashcams keep motion or position data with the video, e.g. gyroscope and accelerometer samples for stabilization, or GPS.
The products on the market keep that data in one of three ways:
- as a timed metadata track inside the MP4, e.g. GoPro's GPMF, muxed while recording, so that the samples are interleaved with the video in the mdat box and indexed in the moov box;
- as a separate sidecar file next to the video, e.g. the GPS logs of dashcams;
- as a trailer appended after the MP4 boxes when recording stops, which players ignore and stabilization tools read.
Quoted 3 lines
A sidecar file is lost in practice: users copy, share or import only the video file, and matching the two by name breaks once either is renamed or moved.
I think I understand the the problem being addressed here, but adding something to the kernel to solve that particular user error sounds like a lot of trouble to go through...
Also, there's issue of block alignment: Windows formats exfat volumes up to 32MB cluster size(I myself unsure of this MS's decision, but it is what it is). The release of 4TB SDUC cards are just around the corner. At most 2MB of space lost just to padding, just to append a few MB of metadata to a monolithic file to idiotproof the product.
I think most of the products on the market today just use multiple files for multiple streams at different rate(LRV and WAV - fs/exfat have long supported preallocation to alleviate the classical fragmentation issue inherent in linked-list based filesystems). GPX and gyro data is certainly not that big - most implementations including Gopros just interleave that in a single MP4 file with audio and video streams. But sensor data in industrial use may see a huge amount of data, but then again, not a consumer product. Something you don't really need to idiotproof. I think, if the metadata stream gets that big, we're no longer in the realm of consumer products.
I have no share in the in-kernel fs/exfat implementaion so you don't have to sell it to me. I'm just a dude curious about all this. However, if you don't mind elaborating, I'd like to see some actual implementations in the wild that may benefit from the ioctl. I also have a bunch of ideas I'd share with the kernel devs, but I just keep them all to myself because the kernel development is hard and the ideas are, most of the times, not worth the trouble of maintaining it in the long run. I don't think it's not fair for the maintainers who have to stay behind for years to maintain things.
And, tbh with you, fs/exfat is not really the coolest part of the Linux kernel so expect more push backs :) Just speaking from my experience. Nothing personal. Thank you for reading my unsolicited two cents.
Davo
Hi Davo,
Thanks for taking a look, both here and at the exfatprogs pull request.
Quoted 6 lines · David Timber
Quoted 3 lines
A sidecar file is lost in practice: users copy, share or import only the video file, and matching the two by name breaks once either is renamed or moved.
I think I understand the the problem being addressed here, but adding something to the kernel to solve that particular user error sounds like a lot of trouble to go through...
The remark about sidecar files in my previous mail was part of the discussion with Namjae about whether the kernel or user space should unlink the source: it explained why the sensor file should not be left next to the video. Following Namjae's suggestion, v8 [1] leaves the unlink to user space, so that point is settled, and it was never the reason for the ioctl itself.
The reason for merging is that the camera records more than the video:
custom data such as GPS and per-frame exposure data, which is used in post-processing. It is written to separate files while recording, but the product has to hand the user a single file, so when recording stops these files are merged into the main MP4 file. They grow with the length of the recording, from tens to hundreds of MiB.
On an SD card, merging them by copying takes time proportional to their size. With the write speed dropping to around 10 MB/s under jitter, a few hundred MiB take tens of seconds, which users waiting for the camera do not accept. Relinking the clusters makes the time depend on the length of the FAT chain instead of the amount of data. Measured on a disk throttled to SD card speeds (30 MiB/s write), appending to a 300 MiB file with 128 KiB clusters:
source EXFAT_IOC_COMBINE copy_file_range() + fsync()
50 MiB 13.7 ms 2.2 s 500 MiB 14.3 ms 22.3 s 1 GiB 13.6 ms 45.7 s
The ioctl stays at 12 to 15 ms whatever the size; the time to build a FAT chain for a contiguous file grows with its number of clusters, but stays far below that of copying the data.
Quoted 5 lines
Also, there's issue of block alignment: Windows formats exfat volumes up to 32MB cluster
size(I myself unsure of this MS's decision, but it is what it is). The release of 4TB SDUC cards are just around the corner. At most 2MB of space lost just to padding, just to append a few MB of metadata to a monolithic file to idiotproof the product.
On the padding: it does not take any extra space on the volume, but it is worth explaining why it is there at all.
Clusters can only be moved whole. The data of the source starts at the beginning of its first cluster on disk, so once that cluster is linked after the last cluster of the destination, the appended data starts at the next cluster boundary of the destination, i.e. at round_up(old size, cluster size). If the size of the destination is not a multiple of the cluster size, the unused tail of its last cluster ends up in the middle of the combined file.
That tail has never been written by the destination and may still hold stale data, e.g. from a file deleted earlier, so it must not become readable. exFAT can only mark a range as uninitialized at the end of a
file: each file has a single valid_size, and everything below it is read from the disk. A gap in the middle cannot be described, so the only way to keep the stale data out is to write zeroes into it. For the same reason, any range of the destination below its size that was never written, e.g. after fallocate(), is zeroed as well before the clusters are appended.
The zeroes go into the tail of the last cluster, which is already allocated to the destination. No cluster is allocated or freed, so the combined file occupies exactly the clusters the two files occupied before, whatever the cluster size.
What the padding does cost is that the gap becomes part of the file: up to one cluster less one byte of zeroes is written, and the file format has to skip it. A trailer located from the end of the file is not affected. A writer that prefers its own padding, e.g. an MP4 'free' box, can pad the destination up to the cluster boundary itself before the call, and then nothing is zeroed. The cluster size is reported in st_blksize.
Quoted 4 lines
I think most of the products on the market today just use multiple files for multiple streams at different rate(LRV and WAV - fs/exfat have long supported preallocation to alleviate the classical fragmentation issue inherent in linked-list based filesystems).
[...]
Quoted 3 lines
However,
if you don't mind elaborating, I'd like to see some actual implementations in the wild that may benefit from the ioctl.
On implementations in the wild: a similar implementation, though not this version, is already used in mature camera products. I would rather not name the vendor for now, as that involves other matters, but the use is real. The open source user is exfatcombine in the exfatprogs pull request.
Products that deliver several files, like LRV proxies or separate audio, do not need this, and preallocation already serves them well. The ioctl is for the case where data written to separate files during recording has to end up in one file, and where it is too large to copy quickly, as described above.
Quoted 6 lines
I also have
a bunch of ideas I'd share with the kernel devs, but I just keep them all to myself because the kernel development is hard and the ideas are, most of the times, not worth the trouble of maintaining it in the long run. I don't think it's not fair for the maintainers who have to stay behind for years to maintain things.
On the maintenance burden: that is a fair concern, and it is the maintainers' call to make. To keep it small, the change is self-contained in fs/exfat/file.c: it touches neither the VFS nor the on-disk format, and only uses structures exFAT already has. The interface is a single ioctl with an 8-byte argument, whose flags field is reserved for later extensions. v8 dropped the unlink from the kernel, as Namjae suggested, which removed about 170 lines. It is covered by a test for fstests (exfat/002), and exfatcombine exercises it from user space.
Thanks for taking the time to write this; the feedback is welcome, and I don't take it personally.
Shaopei
Hi Davo,
Thanks for taking a look, both here and at the exfatprogs pull request.
Quoted 6 lines · David Timber
Quoted 3 lines
A sidecar file is lost in practice: users copy, share or import only the video file, and matching the two by name breaks once either is renamed or moved.
I think I understand the the problem being addressed here, but adding something to the kernel to solve that particular user error sounds like a lot of trouble to go through...
The remark about sidecar files in my previous mail gave the wrong impression, so let me explain the case properly. It was meant to say why the data has to end up in the video file rather than next to it, not to have the kernel make up for a user error.
The camera records more than the video: custom data such as GPS and per-frame exposure data, which is used in post-processing. While recording, that data comes from other writers than the muxer and is written to separate files; when recording stops, these files are merged into the main MP4 file. They grow with the length of the recording, from tens to hundreds of MiB.
Keeping the recording as a single file is part of the product
definition: the companion app that plays and edits the recordings, and the later processing, all work on that one file. That lets the product define its own data alongside the video; it is more robust, as there is no second file that can get out of step with the video; and the custom data stays inside the recording rather than lying around as separate files. Whether to have one file is the product's decision, not the ioctl's; the ioctl is for the merge that follows from it.
That merge is where the cost lies. Copying the data takes time proportional to its size, and on an SD card, whose write speed drops to around 10 MB/s under jitter, a few hundred MiB take tens of seconds, during which the user waits for the camera. Relinking the clusters instead makes the time depend on the length of the FAT chain rather than on the amount of data. Measured on a disk throttled to SD card speeds (30 MiB/s write), appending to a 300 MiB file with 128 KiB clusters:
source EXFAT_IOC_COMBINE copy_file_range() + fsync()
50 MiB 12.3 ms 2.2 s 500 MiB 13.3 ms 22.3 s 1 GiB 13.0 ms 45.7 s
The ioctl stays at 12 to 16 ms whatever the size; building a FAT chain for a contiguous file takes time that grows with its number of clusters, but far less than copying the data.
The time matters for more than the wait. A camera runs on a battery and records to a removable card, so a copy that takes tens of seconds is also a window in which the card can be pulled or the battery can run out, leaving the video file with a partial trailer. The ioctl takes a few milliseconds, and its updates are written in an order that leaves all data reachable from one of the two files if it is interrupted at any point.
Quoted 5 lines
Also, there's issue of block alignment: Windows formats exfat volumes up to 32MB cluster
size(I myself unsure of this MS's decision, but it is what it is). The release of 4TB SDUC cards are just around the corner. At most 2MB of space lost just to padding, just to append a few MB of metadata to a monolithic file to idiotproof the product.
On the padding: it does not take any extra space on the volume, but it is worth explaining why it is there at all.
Clusters can only be moved whole. The data of the source starts at the beginning of its first cluster on disk, so once that cluster is linked after the last cluster of the destination, the appended data starts at the next cluster boundary of the destination, i.e. at round_up(old size, cluster size). If the size of the destination is not a multiple of the cluster size, the unused tail of its last cluster ends up in the middle of the combined file.
That tail has never been written by the destination and may still hold stale data, e.g. from a file deleted earlier, so it must not become readable. exFAT can only mark a range as uninitialized at the end of a
file: each file has a single valid_size, and everything below it is read from the disk. A gap in the middle cannot be described, so the only way to keep the stale data out is to write zeroes into it. For the same reason, any range of the destination below its size that was never written, e.g. after fallocate(), is zeroed as well before the clusters are appended.
The zeroes go into the tail of the last cluster, which is already allocated to the destination. No cluster is allocated or freed, so the combined file occupies exactly the clusters the two files occupied before, whatever the cluster size.
What the padding does cost is that the gap becomes part of the file: up to one cluster less one byte of zeroes is written, and the file format has to skip it. A trailer located from the end of the file is not affected. A writer that prefers its own padding, e.g. an MP4 'free' box, can pad the destination up to the cluster boundary itself before the call, and then nothing is zeroed. The cluster size is reported in st_blksize.
Quoted 4 lines
I think most of the products on the market today just use multiple files for multiple streams at different rate(LRV and WAV - fs/exfat have long supported preallocation to alleviate the classical fragmentation issue inherent in linked-list based filesystems).
[...]
Quoted 3 lines
However,
if you don't mind elaborating, I'd like to see some actual implementations in the wild that may benefit from the ioctl.
On implementations in the wild: a similar implementation, though not this version, is already used in mature camera products. I would rather not name the vendor for now, as that involves other matters, but the use is real. The open source user is exfatcombine in the exfatprogs pull request.
Products that deliver several files, like LRV proxies or separate audio, do not need this, and preallocation already serves them well. The ioctl is for the case where data written to separate files during recording has to end up in one file, and where it is too large to copy quickly, as described above.
Quoted 6 lines
I also have
a bunch of ideas I'd share with the kernel devs, but I just keep them all to myself because the kernel development is hard and the ideas are, most of the times, not worth the trouble of maintaining it in the long run. I don't think it's not fair for the maintainers who have to stay behind for years to maintain things.
On the maintenance burden: that is a fair concern, and it is the maintainers' call to make. To keep it small, the change is self-contained in fs/exfat/file.c: it touches neither the VFS nor the on-disk format, and only uses structures exFAT already has. The interface is a single ioctl with an 8-byte argument, whose flags field is reserved for later extensions. v8 [1] dropped the unlink from the kernel, as Namjae suggested, which removed about 170 lines. It is covered by a test for fstests (exfat/002), and exfatcombine exercises it from user space.
Thanks for taking the time to write this; the feedback is welcome, and I don't take it personally.
Shaopei
Quoted 5 lines · Shaopei Zhu
On implementations in the wild: a similar implementation, though not this version, is already used in mature camera products. I would rather not name the vendor for now, as that involves other matters, but the use is real. The open source user is exfatcombine in the exfatprogs pull request.
See, this is a typical defensive LLM response.
You lost me when you replied with 80% of generated text. There are actual people taking their time. I suggest you respect that.
Hi David,
You are right, and I am sorry.
I do take your time and your comments seriously. My English is not good, so I used a tool to turn my answers into English, and the result was much too long. The facts and the decisions in them are my own.
I am a developer and much of my work is on exfat, which is why I would like to contribute some of my ideas to it. Your comments, and those of the other kernel developers, matter a lot to me. I will think more carefully about my replies, and I am sorry for the trouble.
Thanks for telling me directly.
Shaopei