Find the answer to your Linux question:
Page 1 of 5 1 2 3 4 5 LastLast
Results 1 to 10 of 45
hi, you know command filefrag can get the block numbers of a file, but how to get the sector numbers of a file ? thanks !...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined! bitzsk's Avatar
    Join Date
    Apr 2009
    Location
    Far, Far, Away on the earth
    Posts
    25

    how to get the sector numbers of a file ?


    hi,

    you know command filefrag can get the block numbers of a file, but how to get the sector numbers of a file ?

    thanks !

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,662
    I think you have to compute that yourself. If you know the starting sector of a block, and the number of sectors it encompasses, then you can determine the sectors it covers. Also, I think that in most Linux file systems, each block is a contiguous number of disc sectors. The standard Linux file systems, such as ext2/ext3 are not extent-based file systems. Sorry that I don't know enough to be more specific than this.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined! bitzsk's Avatar
    Join Date
    Apr 2009
    Location
    Far, Far, Away on the earth
    Posts
    25

    Thumbs up

    Thank you!

    maybe the sector number can get from this formula:

    multiply the block number with the block_size divide by sector_size.

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,763

    Smile

    Quote Originally Posted by bitzsk View Post
    hi,

    you know command filefrag can get the block numbers of a file, but how to get the sector numbers of a file ?

    thanks !
    A sector is 512 bytes and If your block size is 4096 bytes (4KB) and,Then If you are accessing say block number 1 . Then you can divide each block into 8 sectors.
    (So sector 0 to 7 will represent block number 1)

    Sector 8-15 will represent block 2 and so on.


    multiply the block number with the block_size divide by sector_size
    Yes,you will get the end sector of each block ,but not entire block .
    First they ignore you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -----
    FOSS India Award winning ext3fs Undelete tool www.giis.co.in. Online Linux Terminal http://www.webminal.org

  6. #5
    Just Joined! bitzsk's Avatar
    Join Date
    Apr 2009
    Location
    Far, Far, Away on the earth
    Posts
    25
    thank you , Lakshmipathi

    you gave me a very exact answer!

  7. #6
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,662
    Quote Originally Posted by bitzsk View Post
    Thank you!

    maybe the sector number can get from this formula:

    multiply the block number with the block_size divide by sector_size.
    IE:

    sector_num = block_num * sectors_per_block
    sectors_per_block = block_size / sector_size

    or

    sector_num = block_num * (block_size / sector_size)

    FWIW, most drives use a 512 byte sector size, or at least they used to.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  8. #7
    Just Joined! bitzsk's Avatar
    Join Date
    Apr 2009
    Location
    Far, Far, Away on the earth
    Posts
    25
    Hi,

    i want to get the exact match between block number and sector number of a file in domU of xen. so i do follows .


    root@feisty:~# ls -l
    total 1
    -rw-r--r-- 1 root root 4 Jun 9 08:16 a

    root@feisty:~# filefrag -v a
    Checking a
    Filesystem type is: ef53
    Filesystem cylinder groups is approximately 122
    Blocksize of file a is 1024
    File size of a is 2 (1 blocks)
    First block: 247208
    Last block: 247208
    a: 1 extent found

    the file has one block and block size is 247208, so the secoter size is 247208 *2 +1 == 78B51 and 247208*2 +2 == 78B52 (block number count begin from 0 , sector number count begin from 1).

    root@feisty:~# echo "a" >> a

    command above is a write to a file

    root@feisty:~# tail /var/log/messages
    Jun 9 08:15:54 feisty kernel: do_blk_req cf9d1de8: cmd cf9d1e64, sec ae85e, (2/2) buffer:cf7a1800 [write]
    Jun 9 08:16:14 feisty kernel: do_blk_req cf9d152c: cmd cf9d15a8, sec ae7c6, (2/2) buffer:ce81ec00 [write]
    Jun 9 08:16:19 feisty kernel: do_blk_req cf9d152c: cmd cf9d15a8, sec 2, (2/2) buffer:d06ee400 [write]
    Jun 9 08:16:19 feisty kernel: do_blk_req cf9d1f40: cmd cf9d1fbc, sec 6, (2/2) buffer:d06eec00 [write]
    Jun 9 08:16:19 feisty kernel: do_blk_req cf9d1e94: cmd cf9d1f10, sec 880d0, (2/2) buffer:d0392000 [write]
    Jun 9 08:16:19 feisty kernel: do_blk_req cf9d1de8: cmd cf9d1e64, sec 880d4, (2/2) buffer:d0392800 [write]
    Jun 9 08:16:19 feisty kernel: do_blk_req cf9d11d0: cmd cf9d124c, sec 880d8, (2/2) buffer:cecdf000 [write]
    Jun 9 08:16:19 feisty kernel: do_blk_req cf9d127c: cmd cf9d12f8, sec ac002, (2/2) buffer:cf1e4400 [write]
    Jun 9 08:16:19 feisty kernel: do_blk_req cf9d1124: cmd cf9d11a0, sec ae25a, (2/2) buffer:cf652400 [write]
    Jun 9 08:16:19 feisty kernel: do_blk_req cf9d1b38: cmd cf9d1bb4, sec ae67c, (2/2) buffer:ce6d1800 [write]

    and then to show sector number i had written, i expect to see 78B51 or 78B52 sector number. but none of then display, can you tell me why?

    --
    Regards,

  9. #8
    Just Joined! bitzsk's Avatar
    Join Date
    Apr 2009
    Location
    Far, Far, Away on the earth
    Posts
    25
    Hi,

    i want to get the exact match between block number and sector number of a file in domU of xen. so i do follows .


    root@feisty:~# ls -l
    total 1
    -rw-r--r-- 1 root root 4 Jun 9 08:16 a

    root@feisty:~# filefrag -v a
    Checking a
    Filesystem type is: ef53
    Filesystem cylinder groups is approximately 122
    Blocksize of file a is 1024
    File size of a is 2 (1 blocks)
    First block: 247208
    Last block: 247208
    a: 1 extent found

    the file has one block and block size is 247208, so the secoter size is 247208 *2 +1 == 78B51 and 247208*2 +2 == 78B52 (block number count begin from 0 , sector number count begin from 1).

    root@feisty:~# echo "a" >> a

    command above is a write to a file

    root@feisty:~# tail /var/log/messages
    Jun 9 08:15:54 feisty kernel: do_blk_req cf9d1de8: cmd cf9d1e64, sec ae85e, (2/2) buffer:cf7a1800 [write]
    Jun 9 08:16:14 feisty kernel: do_blk_req cf9d152c: cmd cf9d15a8, sec ae7c6, (2/2) buffer:ce81ec00 [write]
    Jun 9 08:16:19 feisty kernel: do_blk_req cf9d152c: cmd cf9d15a8, sec 2, (2/2) buffer:d06ee400 [write]
    Jun 9 08:16:19 feisty kernel: do_blk_req cf9d1f40: cmd cf9d1fbc, sec 6, (2/2) buffer:d06eec00 [write]
    Jun 9 08:16:19 feisty kernel: do_blk_req cf9d1e94: cmd cf9d1f10, sec 880d0, (2/2) buffer:d0392000 [write]
    Jun 9 08:16:19 feisty kernel: do_blk_req cf9d1de8: cmd cf9d1e64, sec 880d4, (2/2) buffer:d0392800 [write]
    Jun 9 08:16:19 feisty kernel: do_blk_req cf9d11d0: cmd cf9d124c, sec 880d8, (2/2) buffer:cecdf000 [write]
    Jun 9 08:16:19 feisty kernel: do_blk_req cf9d127c: cmd cf9d12f8, sec ac002, (2/2) buffer:cf1e4400 [write]
    Jun 9 08:16:19 feisty kernel: do_blk_req cf9d1124: cmd cf9d11a0, sec ae25a, (2/2) buffer:cf652400 [write]
    Jun 9 08:16:19 feisty kernel: do_blk_req cf9d1b38: cmd cf9d1bb4, sec ae67c, (2/2) buffer:ce6d1800 [write]

    and then to show sector number i had written, i expect to see 78B51 or 78B52 sector number. but none of then display, can you tell me why?

    --
    Regards,

  10. #9
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,763
    Remember one thing,when append data to a file,It'll use a new data block.
    Check your block number again with filefrag command.
    Inode also changed when appending data,though it mainly based on the way how the application (vi ,gedit etc) open the file.
    First they ignore you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -----
    FOSS India Award winning ext3fs Undelete tool www.giis.co.in. Online Linux Terminal http://www.webminal.org

  11. #10
    Just Joined! bitzsk's Avatar
    Join Date
    Apr 2009
    Location
    Far, Far, Away on the earth
    Posts
    25
    Thank you for quite reply

    i am sorry i forget this fact!

    so what is the best command to read a file and read all the sectors of the file? is that more command or another?

Page 1 of 5 1 2 3 4 5 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •