将磁盘块读取为位图
我正在尝试读取包含块位图和索引节点位图的块
我将块读取为无符号字符数组 比我将其转换为二进制如下:
for (i = 0; i < 4096; i++) {
for (j = 8; j <=0 ; j--) {
bits[j] = bitmap[i]%2;
bitmap[i] = bitmap[i]/2;
}
for(t=0; t<8;t++)
printf("%d\t",bits[t]);
printf("\n");
}
当我将“0”放入 char 并打印它时,
printf("%d",'0');
我得到 48 我的位数组包含 00110000 这是可行的,但是当我检查 inode 位图时 它不起作用 例如位图是:
1 1 1 0 0 0 0
但我明白
0 0 0 0 1 1 1
我无法检查块位图是否发生同样的情况。
重复一下,该代码可以正常对话,例如它打印 00110000,即 48,对于字符“0”,它也打印 48。这种交换是通过 inode 位图进行的。 当我更改它时,它将适用于 inode 位图,但我现在如何才能将它适用于块位图。这将修复代码,但逻辑是错误的。
有什么想法吗?
I am trying to read a block which contains block bitmap and inode bitmap
I read a block as a unsigned char array
than I convert it to binary as follows:
for (i = 0; i < 4096; i++) {
for (j = 8; j <=0 ; j--) {
bits[j] = bitmap[i]%2;
bitmap[i] = bitmap[i]/2;
}
for(t=0; t<8;t++)
printf("%d\t",bits[t]);
printf("\n");
}
when I put '0' to char and print it as
printf("%d",'0');
I get 48
and my bits array contains 00110000
That works, however when I check inode bitmap
it does not work
for example a bitmap is:
1 1 1 0 0 0 0
but I get
0 0 0 0 1 1 1
I could not check if same thing happens with block bitmap.
To repeat, the code works normal conversation for example it prints 00110000 which is 48, for char '0' which print 48 also. This swapping occurs with inode bitmap.
When I change for it will work for inode bitmap but how can I now it will work for blok bitmap. This will fix the code but the logic is wrong.
Any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这些行
首先打印位置 0(最低有效位)的位,最后打印位置 7(最高有效位)的位。如果您希望它是相反的,请将循环更改为:
或类似的。
The lines
print the bit at position 0 (the least significant one) first and the bit at position 7 (the most significant) last. As you want it to be the other way around, change the loop to:
or similar.
看起来你的位顺序被交换了
大端与小端。
http://en.wikipedia.org/wiki/Endianness
您可以与
htonl、htons、ntohl、ntohs
系列函数进行交换。尝试man htons
。或者反向运行你的循环。
looks like your bit order is swapped
big-endian vs little endian.
http://en.wikipedia.org/wiki/Endianness
you can swap with
htonl, htons, ntohl, ntohs
family of functions. tryman htons
.or run your loop in reverse.