chenall / grub4dos

外部命令和工具源码:https://github.com/chenall/grubutils 下载:
http://grub4dos.chenall.net
GNU General Public License v2.0
646 stars 136 forks source link

USB 4Kbyte sector size #47

Open Nin-ho opened 9 years ago

Nin-ho commented 9 years ago

Grub4DOS 0.4.6a now has its own software 'stack' for EHCI MSD, but - sadly - the impressive USB stuff in asm.S ( by Yaya' ?) /assumes/ sectors are 512 bytes long, whereas many USB storage media have appeared as 4096 bytes per sector forseveral years now.

Are you working on fixing this ? Grub4DOS's internal "disk int 13h" for USB should allow for 4K sectors, and the "boot" command for such a disk should load a full 4,096 bytes sector to memory at absolute address 00007C00 & transfer control there.

In addition of "chainloading" a MBR or boot sector from the UMB device, Grub's int 13 BIOS extension would be usable as a DOS driver substitute when chainloading DOS -for example- from another, regular disk.

yaya2007 commented 9 years ago

硬盘有每扇区4k字节一说。即使硬盘的物理扇区是4k,其逻辑扇区仍然是512字节。只是读数据时,4k边界对齐,会加快读取速度。

u盘是这样读的: 应用程序向usb驱动发指令,读56k; usb驱动向usb主控(在主板)发指令,读20k(最大); usb主控向u盘发指令,读512字节(最大),成功再读512字节,......,直到读完20k; usb驱动向usb主控(在主板)发指令,读20k(最大); usb主控向u盘发指令,读512字节(最大),成功再读512字节,......,直到读完20k; usb驱动向usb主控(在主板)发指令,读16k(最大); usb主控向u盘发指令,读512字节(最大),成功再读512字节,......,直到读完16k;

尽管硬盘制造厂商大力推广4k扇区,想使逻辑扇区=4k字节,谈何容易! 我个人认为,对于使用者,没有必要去过多关注4k扇区的问题。

Nin-ho commented 9 years ago

Hi, Yaya ! Reading your message through Google's automatic translation, so I probably missed more than a few details. However if I grasped well enough, you wrote ; "Even if the hard disk physical sector is 4k, its logical sector is still 512 bytes. " That's what they call "emulation" of 512 byte sectors, I think. BUT when connected through a SATA-to-USB bridge in an external disk enclosure, at least the one I own, there is no "emulation" happening, the computer sees "native" aligned 4,096 byte long sectors ONLY ! The behaviour is as prescribed by Microsoft (for compatibility with Windows XP, so they say). So yes, I'm 100% positive I need Grub4DOS , and DI1000DD.SYS also, to be able to deal with native 4K-sectored disks !

yaya2007 commented 9 years ago

你的 ‘ native 4K-sectored disks ’,是怎样理解 1 扇区长度(每扇区字节)的? 比如:指令是读 LBA(3),1扇区。 那么它是从磁盘的偏移 0x400 读 0x200 字节? 还是从磁盘的偏移 0x2000 读 0x1000 字节?

Nin-ho commented 9 years ago

" Your 'native 4K-sectored disks', how to understand sector length (bytes per sector) ? " Answer :

There is no way to read or write /less than/ 4,096 bytes at a time, thus sector buffers need to be 4 K long. For PC compatibility the boot sector (PBR or MBR) should be read into memory address 00007C00 to 00008BFF and executed starting from 007C00 as usual...

yaya2007 commented 9 years ago

明白了。容我想一想。

yaya2007 commented 9 years ago

"•All sectors are 0x1000 bytes long : •first sector (LBA 0) is bytes 0 to 0x0FFF, •second sector, LBA 1, bytes 0x1000 to 1FFF, and so on... " 是你认为的?还是测试后的? 是在 DOS 下,使用 debug 测试的?还是在 grub4dos 下,使用 cat --hex 测试的? 必须是在 “实模式" 测试!

yaya2007 commented 9 years ago
  1. 在 Windows 命令行执行: Fsutil fsinfo ntfsinfo x: 其中 x:表示您的 ‘ native 4K-sectored disks ’,看看逻辑扇区大小,物理扇区大小。
  2. 如果可以进入 grub4dos,在命令行执行: usb --init ,看看能否获取逻辑扇区大小。要连接您的 ‘ native 4K-sectored disks ’。 使用 usb 测试专用 grldr。 http://bbs.wuyou.net/forum.php?mod=attachment&aid=MjExNjY3fGVjMjlmMzU5fDE0MjY3NDU1ODB8NDIzMjYyfA%3D%3D
yaya2007 commented 9 years ago

‘ native 4K-sectored disks ’: 在 MBR/PBR 中,“55 AA” 是在偏移 0x1fe?还是在偏移 0xffe? 在 PBR 的偏移 0xb 处,2字节内容是 0x200?还是 0x1000?

你要使用 DOS 读 ‘ native 4K-sectored disks ’,BIOS 是否支持 4k 扇区磁盘?

grub4dos 支持原 4k 扇区磁盘困难太大。如果只让 usb 驱动支持,也许也可能。

Nin-ho commented 9 years ago

Ninho : All sectors are 0x1000 bytes • Long Yaya : You think? Or after the test? N. : Tested, of course. Both in Windows XP, and in DOS using ASPI. I even wrote an experimental DOS driver for this disk ! Works perfectly. 4K sectors have been the standard for 1+ Terabyte USB-connected external disks since around year 2004, I think. Immediately after detecting the USB MSD, your driver should issue the proper identify or get capacity commands which will report the sector size it must use.

Y : in the grub4dos, use cat --hex test? Unfortunately, the issue is precisely that Grub4DOS does /not/ mount or see the disk :-(

Y : In the Windows command line: Fsutil fsinfo ntfsinfo x: where x: represents your 'native 4K-sectored disks', a look at the logical sector size, the physical sector size.

N : D:\Program Files\Internet Explorer>Fsutil fsinfo ntfsinfo p: NTFS volume serial number : 0xf2dc983cdc97f955 Version : 3.1 Number of sectors : 0x000000000e87e286 Total number of clusters : 0x000000000e87e286 Free clusters : 0x000000000e6e0319 Total reserved : 0x0000000000000000 Bytes per sector : 4096 Bytes per cluster : 4096 Bytes/file record segment : 4096 Clusters/file record segment : 1

Y : If you can enter grub4dos, at the command line: usb --init, see if you can get the logical sector size.

N : Current Grub4DOS ignores the device after usb --init !

Y : To connect your 'native 4K-sectored disks'. Usb test using dedicated grldr. N : 3 210 2 2049 4350 0 0 3 252 80 4008 FF9F FC00 1000 9500 422 0 200 0 0 0 100 100 400 0 0 0 8f01 0 0 0 0 0 C0C4 0 [repeated x11 times]

4 1803 1005 1000 1000 1000 1201 1002 0 40 9B05 7000 400 102 301 902 2000 101 480 109 400 2 806 5005 705 102 2 7 581 200 200 AA 0 E8E DB5 1000

Y : 'Native 4K-sectored disks':

Y : You have to use the DOS read 'native 4K-sectored disks', BIOS supports 4k sector disks?

N : ROM-BIOS "int 13" does not support 4K sectors. This is the reason I wish Grub4DOS did it !

Regards !

yaya2007 commented 9 years ago

你是想从其他磁盘进入 grub4dos,加载 usb 驱动,然后进入 dos。 在 dos 下读写 ‘ native 4K-sectored disks ‘?

Nin-ho commented 9 years ago

Y : "Do you want to enter from another disk grub4dos, load the usb drive, and then enter the dos. In dos write 'native 4K-sectored disks'?"

N : Ultimately, yes indeed. For the time being, I want Grub4DOS to recognize the drive's reported sector size, and install its BIOS (int 13h) that should read and write 4K-sectors properly.

MS-DOS by itself [but /not/ FreeDOS 1.1] is well able to deal with 4K-byte sectors, though I'll have to patch the MBR and/or MS-DOS boot sector, and the standard disk driver included in IO.SYS, in order to /boot/ from the device.

Alternatively I may also ask Grub4DOS to chainload DOS from a standard 512-bps drive and then use the 4K-drive as a secondary (non-boot) disk.

The required DOS modifications are /my/ part of the work. I am only asking of Grub4DOS that it makes the native 4K USB disk "int 13 accessible" and, optionally, that it loads one 4K MBR or boot sector at the proper place and transfers control as usual... After that point is /my/ problem :=)

yaya2007 commented 9 years ago

谢谢你,让我了对'Native 4K-sectored disks'有了进一步解了。由于我没有'Native 4K-sectored disks',所以需要你提供信息和测试,辛苦了!

请提供 MBR,PBR。16 进制格式(各 1扇区,4k)。 如果'Native 4K-sectored disks'有 NTFS,FAT32 等系统类型,请各提供 PBR。

yaya2007 commented 9 years ago

测试 http://bbs.wuyou.net/forum.php?mod=attachment&aid=MjEyMDAxfGMzNGNiMWFkMmFiOWM2MTUxMjUyOTk3MGUyODIzNDU4fDE0MjY4NDA2NzE%3D&request=yes&_f=.rar

Nin-ho commented 9 years ago

Hi Yaya2007 ! Sorry for delay. Per your request I collected the MBR and 3 PBRs (primary partitions, FAT 16, NTFS & FAT12 !) off the disk in question. This will confirm the structures layout to you, but please do not pay attention to the executable code which was put there by whatever partitionning/formatting tools I used to make the sample partitions, and which may pr may not (actually, certainly not) work for booting an OS without revision ! In particular, the code in the MBR is a lame checkpoint that puts a message to screen and halts, will not even try to load a partition...

You may download (rar) from URL: http://webmail.teaser.fr/tele.cgi/20150328.12681.MMsluK0vvz3q/4K_SECTS.RAR

Nin-ho commented 9 years ago

Just downloaded your latest grldr (4K) and briefly tested : it is almost done !!! :=)

I notice that offsets need to be provided in units of 200h bytes even though sectors are 4K bytes, is this your choice, by design ?

Nevertheless, Yaya, this is astoundingly good work in so little time, considering you do not have the disk for testing at home. Can't you get a cheapo SATA to USB adapter or all-in-one enclosure where you live ?

yaya2007 commented 9 years ago

令人欣慰!grub4dos 的 内置 usb 驱动,可以适用于原生4k扇区磁盘。

据我所知,只有 Windows 8 支持原生4k扇区磁盘,而且它是工作在 NTFS 文件系统。你现在让它工作在 FAT12/16 ,大大领先于微软。

我现在只是更新了 usb 驱动,其它未触及。按说应当满足了你的需求。我下一步试一试更新 NTFS 驱动。这样 grub4dos 就可以挂载了。

“I notice that offsets need to be provided in units of 200h bytes even though sectors are 4K bytes,“ 这是 grub4dos 的事,不是我设计的。

我有 ” SATA to USB“ ,但它是 512字节逻辑扇区/4k字节物理扇区,不是原生4k扇区磁盘。

pbatard commented 9 years ago

If it helps, I'm just going to point out that some of the newer SATA → USB 3.0 controllers on the Seagate External HDDs (such as the 4TB one but I believe this is also true on the latest 2TB ones) force 4K sectors regardless of the disk. This means that even if the disk uses 512 byte-sectors, it will report using 4K through USB.

Here's an example from the same 100GB HDD using a regular SATA -> USB adapter:

Found USB 3.0 device 'Initio INIC-3609 USB Device' (13FD:3940)
1 device found
Disk type: Fixed, Sector Size: 512 bytes
Cylinders: 12161, TracksPerCylinder: 255, SectorsPerTrack: 63

And the same disk using the Seagate Expansion disk adapter:

Found UAS (USB 3.0) device 'Seagate Expansion Desk SCSI Disk Device' (0BC2:3312)
1 device found
No volume information for drive 0x85
Disk type: Fixed, Sector Size: 4096 bytes
Cylinders: 1520, TracksPerCylinder: 255, SectorsPerTrack: 63

The weird thing is that, in both these controllers, the chip is an Initio INIC-3609, so I suspect Seagate have a specific firmware that forces 4K (and UAS).

Nin-ho commented 9 years ago

Bonjour, Pete !... Undoubtably the bridge's settings such as sector size translation, encyption (if applicable), and so on, are firmware-controlled and programmable through the USB interface itself - unfortunately manufacturers won't disclose the programming application notes to end consumers. At least I have been unable to obtain the "cheat sheets" for my IOMega enclosure either from Iomega or from the bridge maker (Oxbridge, as the case was IIRC).

Nin-ho commented 9 years ago

@Yaya2007 : Again, I'm /very happy/ with the work you have done for 4-K-sector support on USB, your extended int 13 BIOS keeps working well even after chainloading DOS ! What comes next ? Is this going to be committed to chenall 0.4.6.a at github ? Meanwhile, as a service, would you be so kind as to upload an updated compiled version of the "grub.exe" including this 4K fix ? Currently being obliged to 'chainload' grlde_4k from the regular grub is a (slight) inconvenience...

Now, what do you think : shall we mark this issue #47 resolved and closed ?

yaya2007 commented 9 years ago

"grub.exe" 包含 grldr 主体,即 0x2000 后的内容。

下一步,我想更新 ntfs,fat 文件系统,使其可以挂载。如 root (hd2,0),ls 等。 进一步,看看其他命令有没有问题。最后解决 4k 扇区仿真。

这些改进需要大量测试,我没有条件。况且 4k 扇区问题并不着急,影响面也不大,我不知这样做有没有意义。

如果可以访问这里
http://bbs.wuyou.net/forum.php?mod=viewthread&tid=327458&extra=page%3D1&page=96 就可以关闭issue #47 ,否则暂时不要关闭。

Nin-ho commented 9 years ago

Yaya2007: - "Grub.exe" contains grldr, namely the content of 0x2000 and after... Nin-ho - Got it ! Thanks...

yaya2007 commented 9 years ago

对不起,官网的 grub.exe 没有包含更改的内容。我尽快上传官网。

yaya2007 commented 9 years ago
  1. From the other disk into the grub4dos, load the USB driver, 'Native 4K-sectored disks' can not be able to mount NTFS,FAT. Execution: root,ls,...
  2. In 'Native 4K-sectored disks' ,installation "grldr.mbr",copy grldr,can not boot from USB?
  3. If you can, In 'Native 4K-sectored disks' ,create exFAT partition. Replication of the 0-24 sector, upload http://bbs.znpc.net/forum.php?mod=viewthread&tid=17037&page=1&extra=#pid88060