jackhab
jackhab

Reputation: 17718

concatenate files without copying their contents

(In C/C++/Linux)

Is there a way to concatenate file A and file B (or actually append one A's content to that of B) only by altering the file system without the overhead of data copying? File A then can be discarded.

Thanks

Upvotes: 7

Views: 1019

Answers (2)

anon
anon

Reputation:

If the files were block-structured, and if the OS supported block-structured files (as some do) then (in principle) yes. But as you are asking about Linux, I assume you are talking about a byte-stream oriented file system, where a disk block may not be completely used. In this case, some copying is inevitable and in practice you have to copy the whole file.

Upvotes: 7

AndiDog
AndiDog

Reputation: 70238

You could write your own file system (e.g. with FUSE) that provides pseudo files for cheap concatenation. But I guess that would be overkill (for any use case), as you have to care about references and stuff.

Upvotes: 2

Related Questions