by Vo Duc Dien
The last few weeks I have posted the solutions to the international mathematical problems and I thought you may have been bored enough. So I am switching subject this week. Let’s talk about the disk drive and how it is designed internally from a computer user’s non-technical viewpoint.
The name hard disk reflects the actual device that comprises of many disk platters made of rigid material thus the name hard. Shown roughly above is the top view of a disk in many disks in a hard drive with four different parts colored black, yellow, blue and red with the arm and the read/ write head in the magenta color. The Vietnamese duped this device “O Cung” to reflect its structure which has the housing – like a box – called O and Cung for hard. O Dia Cung is actually a better name.
The disk drive is designed to hold your data. Besides the circuit board and the arm that has the read/write head at its tip and the housing, the disks are the part of the hard drive that holds your data. The entire area of the disk is coated with the magnetic particles that are non-polarized until the read/ write head magnetizes every particle with the N-S poles with a current that passes through the head or S-N with a current in the reverse direction to represent a bit of either 0 or 1 in the digital format.
The black colored area of the disks is used for the disk’s own data. The manufacturer uses this area to load the microcode / firmware when power is applied to the disk. The structure of the code of the design is copied onto this area such as the number of cylinders, heads and sectors, how defect is being mapped, drive identify information, etc…. To protect the integrity of the design, it is made into multiple copies onto this area. In case a copy is bad, other copies can be used to boot the disk up and to identify itself to the motherboard BIOS (Basic Input-Output) thus you see the disk information on the computer screen during the first seconds when your computer is booted up.
From a design standpoint this black area is called the physical area with physical cylinder zero starting at the outermost edge of the disk. A cylinder zero is comprised of the same tracks zero on every disk on the same vertical stack. Head zero is the first head, and head 1 is the second head for the same disk that is on the bottom surface, and head number increment will continue down with each platter added. A sector zero is a part of a track zero on a single platter. If a single particular copy of design information is damaged on all copies on this black area, the disk is no longer recognized when booted up, and thus it will be like a piece of hard iron and will not be ‘seen’ by the motherboard. In such a case, it has to be returned to the manufacturer for microcode / firmware to be uploaded to it again. The disk is designed so that this area is protected from everyone including Microsoft. Only the manufacturer can access this area to load the firmware. To write information to this area one needs to know the command code to enable the physical mode and its feature register. These two items are represented by two digital bytes which technically can be anywhere between 00 to FF in hex. From a user’s point of view, these are like passwords or PIN numbers, if you will, that you have to know in order to crack the disk and to damage it by writing junk code onto this design data such as a virus to render the disk useless.
The yellow area is used to store the user’s data. This area is called the logical area. Logical sector zero starts from the outer edge of the yellow area. When Microsoft operating system is loaded to your disk, it mostly loads onto the yellow area from the outer edge inward. If a virus is written onto sector zero, it will most likely overwrite the Microsoft operating system data and will cause the computer to not boot up into Windows. Microsoft can learn the design technique of the disk drives by making multiple copies of their vital information so that when sector zero is damaged, other sectors with the exact same data can be copied onto sector zero again so that their Windows operating can boot up in such a mishap. Of course the operating system is huge and to make multiple copies will be difficult and takes a lot of disk space. Therefore, the user should make backup of their hard drive frequently.
In the past your data was written sequentially and continuously on the disk. Software was also loaded sequentially until recently when the manufacturer realized that such a recording technique slows down the performance of the disk. To make the seek time faster they proposed a recording technique called serpentine recording which is to record your data spirally from the top disk down to the bottom instead of from left to right on any single disk. Recording your data in such a snaking way allows the heads / arms to not move as much and reduces the seek time and boots the performance of the disk. Technically, depending on the size of the data or the software it may reside on many disk cylinders that are vertical for faster access. When reading your disk the head not only reads the data that you intend to get, it also reads the data in the adjacent area and loads to the Random Access Memory (RAM) because chances are that the data on the adjacent area is related to the data you’re getting. This way the extra read command is not required, and the extra data you need is already loaded in RAM for faster access, and thus gives consumer the feeling of super performance by the computer, and in this case it’s the hard disk that helps contribute to it. This phenomenon is called Read Cache or Read Look Ahead. The higher the cache memory on a disk the better and the more expensive the hard disk drive. To increase the performance of the disk, it is also made to spin / rotate faster. The speed it runs is called Revolution Per Minute (RPM) which is the number of complete circles it can spin around the spindle in a minute. One can find a disk’s RPM by doing a read on the same sector with read cache disabled to make the head swing to the same sector and do a read for every revolution. Typical disk speed is 10000 RPM.
Your data when written onto the yellow disk area is always being protected with the additional data called Error Correction Code (ECC). For every sector that is written to the disk, there’s always ECC data which is the encrypted of the raw data being written. The write command writes not only your own data but also its ECC. The way and how well the ECC is encrypted is different from design to design and is handled by the chip on the circuit board. The ECC data can be accessed by the Read Long command. To illustrate this example let’s assume that the surface of your disk is somehow damaged with scratches and your data is then must be corrected. When the head reads the data in this damaged area it will compared to the ECC code which is another copy of the data encrypted, and if there is a difference that the ECC is capable of correcting, the same sector will still continue to hold your data even though damaged. Your original data will be corrected and sent out to you. Such sector sustains the so-called Correctable Data Error, and the error is transparent to the computer user. If the ECC is not capable of correcting your data because the damage is beyond its capacity, another sector in the blue area will be used to replace the damaged sector. The error in this case is called Uncorrectable Data Error. The sector in the blue area that has replaced the damaged one is then logged into the defect map that is lying in the black area. The defect map is always loaded when the disk is booted up so that any bad disk area is recognized. Unlike the CD or DVD disk when a scratch on the disk is beyond correction and the damage is permanent, the disk drive has the capacity to replace the bad area with the good one in the reserved area.
The red area is the spindle that holds all the disks together. It is the axis that the platters rotate around by the RPM speed.
Ổ đĩa cứng của máy vi tính
Vo Duc Dien
Vài tuần qua tôi viết các bài giải cho các bài toán thi quốc tế, và tôi nghĩ đến nay các bạn có thể đã bị chán ngấy về toán. Vì vậy, tôi chuyển đổi chủ đề trong tuần này. Tôi nói chuyện về ổ đĩa cứng của máy vi tính để biết nó được cấu tạo như thế nào. Nội dung bài này không thiên về phần kỹ thuật mà chỉ về phần cấu tạo.
Tên ổ đĩa cứng phản ánh thực tế của sản phẩm bao gồm nhiều đĩa (platter) làm bằng vật liệu cứng nhắc. Hình trên cho ta thấy cấu tạo của phần mặt đĩa của nhiều đĩa trong một ổ đĩa cứng. Nó có bốn phần khác nhau với màu đen, vàng, xanh và đỏ, cánh tay và đầu dùng để đọc và viết.
Các ổ đĩa cứng được thiết kế để giữ dữ liệu của bạn. Ngoài phần mạch điện và các ‘cánh tay’ có đầu dùng để đọc và viết, đĩa là phần chính để giữ dữ liệu. Toàn bộ diện tích của đĩa được tráng với từ tính không cực cho đến khi được viết để trở thành N-S với một dòng điện chạy qua đầu hoặc S-N với một dòng điện khác chạy ngược lại để thành một bit là 0 hoặc 1 trong hệ thống kỹ thuật digital được sử dụng cho các máy vi tính.
Vùng đĩa màu đen được công ty chế tạo dùng để chứa những dữ liệu riêng của đĩa. Những micro-code được tải lên khu vực này khi điện được áp dụng vào đĩa. Cấu trúc của đĩa được sao chép vào khu vực này như: số lượng cylinders, số đầu đọc và viết, bảng để giữ phần đĩa xấu (defect map), và xác định đĩa có sức chứa bao nhiêu, hảng nào làm, v..v …. Để bảo vệ đĩa, các cấu trúc của đĩa được sao chép thành nhiều bản vào vùng này. Trong trường hợp một bản sao bị xấu, bản sao khác có thể được sử dụng để BIOS (cơ bản đầu vào-đầu ra) của phần mạch điện mẹ (motherboard) nhận dạng nó. Như vậy làm cho bạn thấy được cấu trúc của ổ đĩa cứng trên màn hình khi máy vi tính bắt đầu mở lên.
Vùng đĩa màu đen này còn được gọi là physical area. Cylinder số không bắt đầu tại cạnh ngoài của vùng đĩa này. Đầu đọc và viết số không là đầu mà bạn đang thấy; đầu 1 là đầu thứ hai cho cùng một đĩa ở vào bên dưới bề mặt của đĩa này, và tiếp tục số đầu đọc và viết tăng lên theo từng đĩa phía dưới. Track số không là track đầu tiên của cylinder số không trên đĩa này. Nếu một bản thiết kế của đĩa bị hư hỏng trên tất cả các bản sao trên khu vực đen này, đĩa sẽ không còn được nhận ra khi mở máy, và như vậy nó sẽ giống như một mảnh sắt cứng và sẽ không hoạt động nữa. Trong trường hợp này, nó phải được trả lại cho nhà sản xuất để cho microcode được tải lên lại. Đĩa được cấu tạo để cho khu vực này được bảo vệ từ Microsoft và tất cả những người khác, trừ nhà sản xuất. Để viết vào khu vực này bạn cần biết những mã lệnh (command code) để đưa đĩa vào physical mode. Mã lệnh và feature register từ 00 đến FF hex là những mật khẩu bạn cần phải biết để phá đĩa bằng cách viết bậy vào vùng đĩa màu đen này với virus (vi-rút).
Khu vực màu vàng được sử dụng để lưu trữ dữ liệu của người dùng. Khu vực này được gọi là logical area. Logical sector số không bắt đầu từ bên ngoài cạnh của các khu vực màu vàng. Khi hệ điều hành của Microsoft được nạp vào đĩa, hầu hết nó tải lên bắt đầu từ những logical sectors đầu tiên bên cạnh ngoài của khu vực màu vàng này và từ từ đi vào trong. Nếu một vi-rút được viết vào sector zero nó sẽ xoá hệ điều hành Microsoft và vì vậy sẽ làm cho máy tính không còn vào Windows được nữa. Microsoft có thể bắt chước cách thiết kế kỹ thuật của ổ đĩa bằng cách làm nhiều bản sao để khi hệ điều hành bị hư hỏng thì các bản sao khác có thể được sao chép lại vào logical sector zero để hệ điều hành Windows có thể khởi động lại một khi vấn đề này xảy ra. Tất nhiên hệ điều hành rất lớn và copy ra nhiều bản sao sẽ rất khó khăn. Vì vậy, người sử dụng nên sao lưu dự phòng dữ liệu của ổ cứng thường xuyên.
Trong quá khứ dữ liệu của bạn đã được viết theo tuần tự và liên tục trên đĩa. Phần mềm cũng được nạp theo tuần tự cho đến thời gian gần đây khi các nhà sản xuất khám phá ra một kỹ thuật ghi chép có hiệu quả hơn. Để đĩa chạy nhanh hơn họ đề xuất một kỹ thuật ghi chép theo kiểu rắn (serpentine) khi dữ liệu được viết theo kiểu xoáy tròn như con ốc từ trên xuống dưới thay vì từ trái sang phải trên một đĩa. Ghi chép dữ liệu theo kiểu này làm cho ‘cánh tay’ không phải di chuyển nhiều và như vậy làm giảm thời gian seek (seek time) và hiệu suất của đĩa tăng lên. Như vậy một dữ liệu phần mềm tùy thuộc vào kích cỡ có thể nằm trên nhiều đĩa cylinders thẳng đứng để được truy cập nhanh hơn.
Khi đọc dữ liệu của bạn từ đĩa đầu đọc và viết không chỉ đọc những dữ liệu mà bạn muốn nhận được, nó còn đọc thêm dữ liệu lưu trữ bên cạnh và tải vào bộ nhớ Random Access Memory (RAM), vì xác suất mà bạn cần những dữ liệu bên cạnh cho công việc của bạn rất cao. Thời gian truy cập của RAM nhanh hơn, vì vậy các dữ liệu đã được nạp vào bộ nhớ RAM sẽ giúp máy tính của bạn làm việc nhanh hơn mà bạn không cần phải đọc thêm một lần nữa những dữ liệu mà bạn sẽ cần sau khi nhận được phần mềm trong lần đầu tiên đọc. Điều này được gọi là Read Cache hay Read Look Ahead / Đọc và Nhìn Trước. Đĩa có cache memory nhiều hơn thì nhanh hơn và đắt hơn. Cũng để tăng hiệu suất hoạt động của đĩa, nó được chế để xoay nhanh hơn. Tốc độ nó chạy được gọi là Revolution Per Minute (RPM) hay là số vòng quay trong một phút. Ta có thể tìm RPM của một đĩa bằng cách cho mệnh lệnh đọc một sector với bộ cache bị vô hiệu hoá. Tốc độ trung bình của các đĩa được bán trên thị trường hiện nay là mười nghìn vòng quay trong một phút.
Dữ liệu của bạn khi viết lên đĩa luôn luôn được bảo vệ bởi các dữ liệu bổ sung được gọi là Error Correction Code (ECC). ECC là dữ liệu encrypted của dữ liệu đang được viết. Mệnh lệnh viết không chỉ viết riêng dữ liệu của bạn mà còn viết dữ liệu ECC của nó. ECC được thiết kế trên chip nằm trên circuit board. ECC có thể đọc được bằng cách dùng mệnh lệnh đọc dài Read Long. Để ví dụ chúng ta giả sử rằng bề mặt của đĩa bị hư hỏng và dữ liệu của bạn phải được sửa chữa. Khi đầu đọc dữ liệu, nó sẽ so sánh với mã ECC và nếu có sự khác biệt mà ECC có khả năng điều chỉnh thì sector đó sẽ vẫn được tiếp tục giữ dữ liệu của bạn ngay cả khi bị hư hỏng; dữ liệu ban đầu sẽ được sửa chữa và gửi ra cho bạn. Những sectors này được gọi là bị Correctable Data Error (Lỗi Sửa Được) và người tiêu thụ không nhìn thấy được khi dùng máy. Nếu ECC không có khả năng điều chỉnh dữ liệu của bạn bởi vì những thiệt hại của nó là ngoài khả năng của ECC thì những sectors ở khu vực màu xanh sẽ được sử dụng để thay thế các sectors bị hư hỏng. Các sectors bị hư hỏng đó được gọi là bị Uncorrectable Data Error (Lỗi Không Sửa Được). Các sectors trong khu vực màu xanh thay thế các sectors bị hư hỏng sau đó sẽ được đăng nhập vào bảng lỗi (defect map) nằm trong khu vực màu đen. Bảng lỗi luôn luôn được tải lên khi đĩa được cho điện vào để những sectors xấu luôn luôn được công nhận.
Khu vực màu đỏ là con quay để giữ tất cả các đĩa lại với nhau. Đây là trục xoay của đĩa.