How to find the location of the file on hard drive in the terms of sector - Embedded
This is a discussion on How to find the location of the file on hard drive in the terms of sector - Embedded ; Hello to all,
Can anyone please help me out.........
Suppose i create one file and store that file on the hard drive. Is it
possible to find the location of the file on hard drive in the terms of
sector. ...
-
How to find the location of the file on hard drive in the terms of sector
Hello to all,
Can anyone please help me out.........
Suppose i create one file and store that file on the hard drive. Is it
possible to find the location of the file on hard drive in the terms of
sector. Like the file is stored at the sectors 33,34 ...
PLEASE HELP ME...
Thanks and Regards,
Nutty
-
Re: How to find the location of the file on hard drive in the terms of sector
2006-11-7, 05:15(-08), Nutty:
> Hello to all,
>
> Can anyone please help me out.........
>
> Suppose i create one file and store that file on the hard drive. Is it
> possible to find the location of the file on hard drive in the terms of
> sector. Like the file is stored at the sectors 33,34 ...
[...]
If the filesystem is ext2/ext3, see the debugfs command.
You can then issue a stat /path/to/file
That will give you the block numbers.
That will give you an offset from the start of the partition in
blocks (stats command to get the block size).
You can use fdisk to find out about where the partition starts
and the (at least logical) geometry of the disk.
~$ sudo env PAGER=cat debugfs /dev/hda7
debugfs 1.40-WIP (02-Oct-2006)
debugfs: stat /etc/passwd
[...]
BLOCKS:
(0):751206
TOTAL: 1
debugfs: stats
[...]
Block size: 4096
[...]
~$ sudo dd if=/dev/hda7 bs=4096 skip=751206 count=1 | od -c | head -3
1+0 records in
1+0 records out
4096 bytes (4.1 kB) copied, 7.8941e-05 seconds, 51.9 MB/s
0000000 r o o t : x : 0 : 0 : r o o t :
0000020 / r o o t : / b i n / b a s h \n
0000040 d a e m o n : x : 1 : 1 : d a e
~$ sudo fdisk -lu /dev/hda | grep hda7
/dev/hda7 17543043 31214294 6835626 83 Linux
~$ sudo dd if=/dev/hda bs=512 skip=$((751206*8+17543043)) count=8 | od -c | head -3
8+0 records in
8+0 records out
4096 bytes (4.1 kB) copied, 0.00174803 seconds, 2.3 MB/s
0000000 r o o t : x : 0 : 0 : r o o t :
0000020 / r o o t : / b i n / b a s h \n
0000040 d a e m o n : x : 1 : 1 : d a e
--
Stéphane
-
Re: How to find the location of the file on hard drive in the termsof sector
Nutty wrote:
> Hello to all,
>
> Can anyone please help me out.........
>
> Suppose i create one file and store that file on the hard drive. Is it
> possible to find the location of the file on hard drive in the terms of
> sector. Like the file is stored at the sectors 33,34 ...
>
> PLEASE HELP ME...
>
> Thanks and Regards,
> Nutty
>
Before you proceed with the questions for the Linux internals,
please DO GET a book of the general organization of the kernel,
read and understand it.
My favourite for starters:
Daniel Pierre Bovet, Marco Cesati, Understanding the Linux Kernel, 3rd
ed, O'Reilly, ISBN 0-596-00565-2.
This book explains also the file system general organization. The
exact response to your question depends on the partitioning of the
disk and the file system type and parameters.
--
Tauno Voipio
tauno voipio (at) iki fi
-
Re: How to find the location of the file on hard drive in the termsof sector
You can't tell unless you know the file system used.
There are many file systems Linux can use. Some are even compressed and
maybe a file can start in the middle of a sector. Moreover even if you
know where a file starts it can get very complicated to find where it
continues, as with nearly all file systems files can get segmented.
-Michael
-
Re: How to find the location of the file on hard drive in the terms of sector
Nutty wrote:
> Hello to all,
>
> Can anyone please help me out.........
>
> Suppose i create one file and store that file on the hard drive. Is it
> possible to find the location of the file on hard drive in the terms of
> sector. Like the file is stored at the sectors 33,34 ...
>
> PLEASE HELP ME...
>
> Thanks and Regards,
> Nutty
You may want to look at the source code of 'LILO'. When
invoked, Lilo finds out the list of blocks (sectors) which
correspond to the kernel image.
It supports a lot of filesystems.
Kind regards,
Iwo