0

I am trying to copy the x.file data into virtual volume of size 32 KB and trying to read again 32 KB from the same volume to y.file. It shows expected output when using cat y.file but whenever I am using vim/vi to see the content it shows appended character "^@".

Command to write data in virtual volume.

dd if=/tmp/x.file of=/dev/vv/<vv_id> seek=0 bs=16K count=2

Command to read the data from virtual volume.

dd of=/tmp/y.file if=/dev/vv/<vv_id> seek=0 bs=16K count=2

x.file contains series of pattern and size of 24 KB.
For eg:

if x.file PATTERN PATTERN PATTERN

then y.file PATTERN PATTERN PATTERN^@^@^@^@

EDIT:

Now, I know what was the reason of showing "^@" character. My input file size was less than 32 KB. But still have doubt why "^@" gets filled as it could be any other value ? Any specific reason ?

5
  • 2
    Does cat -A show anything strange? Apr 2, 2018 at 12:04
  • @HaukeLaging Yes using cat -A shows the same output what I see using vim.
    – Rocoder
    Apr 2, 2018 at 12:19
  • 2
    Does you x.file file contain exactly 32768 bytes (not less)?
    – Kusalananda
    Apr 2, 2018 at 13:51
  • 1
    What is the output of cmp x.file y.file ? Apr 2, 2018 at 16:19
  • @Kusalananda it was mistake from my side. Size of the x.file is less than 32K. I had many files all were greater size than 32K except x.file.
    – Rocoder
    Apr 3, 2018 at 4:50

1 Answer 1

1

From comments, it is clear that the file x.file is less than 32768 bytes (32 KiB). This means that when dd is asked to write 32 KiB to /dev/vv/<vv_id>, it won't be able to copy it all from the file and the last bit of the 32 KiB will remain unwritten.

This uninitialized data will then be copied to y.file with the second dd operation, and this is what you see when you open that file in an editor.

The ^@ is the editor's way of showing a nul byte. From reading the dd manual, it's unclear to me whether this is what's written to the device by the first dd, or if it's junk data that were already present on the device before the first dd invocation.

1
  • "it's unclear to me whether this is what's written to the device by the first dd" -- The first dd should show you 32768 bytes (33 kB) copied
    – phemmer
    Apr 5, 2018 at 11:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .