English 中文(简体)
如何将 blocks块从与行业的fl中 read成?子?
原标题:How to read blocks from a floppy with sectors?

I need to read a floppy from a pre OS state and I have a function to read, but it cannot seem to read past the 4th sector...

void get_block(blk, buf) int blk; char buf[]
{
   int cyl, head, sector;

   cyl = ((blk*2) / 18) / 2;
   head = ((blk*2) / 18) % 2;
   sector = (blk*2) % 18;

   // Read first sector <<Dies here if blk > 2>>
   diskr(cyl, head, sector, buf);

   // Increment
   if ((sector = (++sector % 18)) == 0)
      if ((head = (++head % 2)) == 0)
         cyl++;

   // Read second sector <<Dies here if blk == 2>>
   diskr(cyl, head, sector, buf+512);
}

任何想法为什么? 我是否错误地将区块改成区?

问题回答

如以下方案所示,假定磁盘为1.44M“氟”(80个气温器、2个头/圆筒、18个区/头、512个用药/部门)。

#include <stdio.h>
int main (void) {
    int blk, cyl, head, sector;
    for (blk = 0; blk <= 18; blk++) {
        cyl = ((blk*2) / 18) / 2;
        head = ((blk*2) / 18) % 2;
        sector = (blk*2) % 18;
        printf ("%2d (a) -> %2d %2d %2d", blk, cyl, head, sector);
        if ((sector = (++sector % 18)) == 0)
            if ((head = (++head % 2)) == 0)
                cyl++;
        printf (" (b) -> %2d %2d %2d
", cyl, head, sector);
    }
    return 0;
}

the output of which is:

 0 (a) ->  0  0  0 (b) ->  0  0  1
 1 (a) ->  0  0  2 (b) ->  0  0  3
 2 (a) ->  0  0  4 (b) ->  0  0  5
 3 (a) ->  0  0  6 (b) ->  0  0  7
 4 (a) ->  0  0  8 (b) ->  0  0  9
 5 (a) ->  0  0 10 (b) ->  0  0 11
 6 (a) ->  0  0 12 (b) ->  0  0 13
 7 (a) ->  0  0 14 (b) ->  0  0 15
 8 (a) ->  0  0 16 (b) ->  0  0 17
 9 (a) ->  0  1  0 (b) ->  0  1  1
10 (a) ->  0  1  2 (b) ->  0  1  3
11 (a) ->  0  1  4 (b) ->  0  1  5
12 (a) ->  0  1  6 (b) ->  0  1  7
13 (a) ->  0  1  8 (b) ->  0  1  9
14 (a) ->  0  1 10 (b) ->  0  1 11
15 (a) ->  0  1 12 (b) ->  0  1 13
16 (a) ->  0  1 14 (b) ->  0  1 15
17 (a) ->  0  1 16 (b) ->  0  1 17
18 (a) ->  1  0  0 (b) ->  1  0  1

I m a little 关切下列行为的不确定性质:

if ((sector = (++sector % 18)) == 0)

2. 建设,更喜欢:

if ((sector = (sector + 1) % 18)) == 0)

但是,如果给你以正确的价值观,那就应当是oka。 但是,你需要检查它does。 给你适当的数值。 在我版本的<代码>gcc中这样做。 并不意味着你会这样做。

或者,你只能使用上文所建议的表格,其中界定了is

你的失败点是,你在头脑或气瓶之间交接的距离很近,因此,我不认为这是一个总结问题,但是,如果可能的话,你就应当勾画环境中的价值观。

When you say you "can t read past the 4th sector", you should specify exactly what that means? Does the machine freeze, do you get a disk error, does it return what you think is rubbish?

软磁盘可能无法正确格式,或者它有错,也有可能仅仅掌握你预期看到的数据。 也许值得与监督事务司/Windows/whatever进行脱硫,并检查贵方案的内容。





相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签