Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 10-17-2009, 03:44 PM   #1
LQ Newbie
Registered: Jul 2008
Distribution: slax
Posts: 11

Rep: Reputation: 0
losetup of a uneven-sized file misses its tail

Can anybody explain this:

bash-3.1# dd if=/dev/zero of=a count=20 bs=1M
20+0 records in
20+0 records out
20971520 bytes (21 MB) copied, 0.11212 s, 187 MB/s
bash-3.1# echo 1 >> a
bash-3.1# losetup -f --show a
bash-3.1# cmp /dev/loop29 a
cmp: EOF on /dev/loop29


I'm using GNU/Linux Slax 6.0.2:

bash-3.1# uname -a
Linux slax #1 SMP Wed Jul 22 07:27:34 AKDT 2009 i686 Intel(R) Pentium(R) 4 CPU 1.80GHz GenuineIntel GNU/Linux
Old 10-17-2009, 05:03 PM   #2
Senior Member
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,994

Rep: Reputation: 76
The reason that you get an EOF is the block size on the device.

Block devices like hard disks treat the device as a series of fixed-size blocks, usually some multiple of 4096 bytes. Any attempt to read or write from the device normally uses the kernel methods read() and write(), which deal in a whole block of data at a time.

After running your example, I get this:
$ sudo blockdev --getsize /dev/loop0 
which shows a 40kiB block size.

i.e. the kernel thinks that the file is made up of 40k chunks. Unfortunately, it isn't, because you ran "echo 1 >> a", which adds an extra *two* bytes to the file.

Since the file size isn't a multiple of 4096 bytes, you can use it as a block device, but the kernel can't read a whole block from the end of the file, hence the error.

There are two options to losetup that let you get around this: add "-o 2" to offset the position of the image being read within the file, or use "--sizelimit 2097152" to limit the size to 2MiB.
Old 10-18-2009, 10:40 AM   #3
LQ Newbie
Registered: Jul 2008
Distribution: slax
Posts: 11

Original Poster
Rep: Reputation: 0
Originally Posted by rjlee View Post
The reason that you get an EOF is the block size on the device.
Thank you!


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Building a distributed storage system from uneven-sized disks dr_dex Linux - Enterprise 0 02-26-2008 10:44 AM
tail file over tcp lloydie-t Linux - Networking 5 05-15-2007 02:18 AM
I need to tail -f just a few colums o a text file ericcarlson Linux - General 3 01-30-2007 03:07 PM
Compress and split a big sized file into smaller files hicham007 Programming 3 07-28-2005 08:56 PM
file misses: ~/linux-2.6.11/drivers/bluetooth/bluecard_cs.c laurentwahl Linux - Software 2 06-22-2005 10:57 AM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:49 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration