# Patent

## Title
Writing metadata files on a disk

## Abstract

A disk drive comprising a rotatable disk, a head actuated over the disk, and a controller is disclosed. The controller is configured to write data on the disk using the head, to store logical-to-physical mapping information for data already written on the disk in a circular buffer as the data is written on the disk, and to write a plurality of metadata files on the disk using the head, wherein the plurality of metadata files are interspersed with the data on the disk and each of the metadata files includes contents of the circular buffer at a time the metadata file is written on the disk.

## Background
BACKGROUND
Disk drives are commonly used to store data in computers, data bases, digital video recorders, and other devices. A disk drive comprises a rotating magnetic disk and a head actuated over the disk to magnetically write data to and read data from the disk. The disk drive may write data to and read data from the disk in response to write/read commands from a host that uses the disk drive for data storage. Typically, the host addresses data stored in the disk drive using logical addresses. The disk drive maintains a translation table mapping the logical addresses from the host to physical addresses of the corresponding data on the disk. When the host later requests data from the disk drive at certain logical addresses, the disk drive uses the translation table to locate the requested data on the disk.
The disk drive may update the translation table in a buffer as the disk drive writes data to the disk. The disk drive may later write the updated translation table in the buffer to the disk for later use. However, due to an unexpected power loss, the disk drive may be unable to write the updates in the translation table to the disk, in which case the updates may be lost.



BRIEF DESCRIPTION OF THE DRAWINGS
The accompanying drawings, which are included to provide further understanding of the invention and are incorporated in and constitute a part of this specification, illustrate embodiments of the invention and together with the description serve to explain the principles of the invention. In the drawings:
FIG. 1 is a block diagram of a disk drive according to an embodiment of the present invention;
FIGS. 2A-2D show an example of shingle writing according to an embodiment of the present invention;
FIG. 3 illustrates a metadata scheme according to an embodiment of the present invention;
FIG. 4 shows a circular buffer according to an embodiment of the present invention;
FIG. 5 shows an example of tracks including data and metadata file interspersed with the data according to an embodiment of the present invention;
FIG. 6 shows an example of entries in the metadata files shown in FIG. 5 according to an embodiment of the present invention; and
FIG. 7 is a flowchart of a method of writing logical-to-physical mapping information on a disk according to an embodiment of the present invention.



DETAILED DESCRIPTION
In the following detailed description, numerous specific details are set forth to provide a full understanding of the present invention. It will be apparent, however, to one ordinarily skilled in the art that the present invention may be practiced without some of these specific details. In other instances, well-known structures and techniques have not been shown in detail to avoid unnecessarily obscuring the present invention.
FIG. 1 shows a disk drive 100 according to an embodiment of the present invention. The disk drive 100 comprises a controller 10, a rotating magnetic disk 160, an actuator arm 125, a voice coil motor (VCM) 120, and a head 150 attached to the distal end of an actuator arm 125. The actuator arm 125 is rotated about a pivot by the VCM 120 to position the head 150 radially over the disk 160. A spin motor (not shown) rotates the disk 160.
The disk 160 comprises a number of radially spaced, concentric tracks 115. Each track 115 may be further divided into a number of data sectors (not shown) that are spaced circumferentially along the track 115. The data sectors may be used to store user data and/or other information on the disk 160. The disk 160 may also comprise a plurality of angularly spaced servo wedges 1220-122N, each of which may include embedded servo information (e.g., servo bursts) that can be read from the disk 160 by the head 150 to determine the position of the head 150 over the disk 160. The data sectors may be located between the servo wedges 1220-122N.
The controller 10 comprises a disk controller 165, a read/write channel 170, a host interface 162, and a buffer 175 as shown in the example in FIG. 1. The disk controller 165 may be implemented using one or more processors for executing instructions (firmware) stored in memory, such as a volatile or non-volatile memory. The instructions may be executed by the one or more processors to perform the various functions of the disk controller 165 described herein. The one or more processors may include a microcontroller, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA), hard-wired logic, analog circuitry and/or a combination thereof.
The read/write channel 170 is configured to receive data to be written to the disk 160 from the disk controller 165 and process the data into a write signal 126, which is outputted to the head 150. The head 150 converts the write signal 126 into a magnetic field that magnetizes the surface of the disk 160 based on the write signal 126, thereby magnetically writing the data on the disk 60. The read/write channel 170 is also configured to receive a read signal 126 from the head 150 based on the magnetization of the disk surface under the head 150. The read/write channel 170 processes the read signal 126 into data, thereby recovering the data from the disk 160, and outputs the recovered data to the disk controller 165.
The host interface 162 is configured to interface the disk drive 100 with a host (e.g., host processor) that uses the disk drive 100 for data storage. The disk controller 165 receives commands (e.g., read/write commands) and data from the host via the host interface 162. The disk controller 165 also outputs data (e.g., data requested by a host read command) to the host via the host interface 162. The host interface 162 may interface with the host according to the serial advanced technology attachment (SATA) standard or other standard.
During normal write/read operations, the disk controller 165 may write data to and read data from the disk 160 in response to write/read commands from the host. When the disk controller 165 receives a write command via the host interface 162, the disk controller 165 may temporarily hold the corresponding data from the host in the buffer 175 (e.g., DRAM) and transfer the data from the buffer to the read/write channel 170 to write the data on the disk 160. The disk controller 165 may notify the host via the host interface 162 when the write command is completed (e.g., after the data for the write command has been successfully written to the disk 160). Similarly, when the disk controller 165 receives a read command from the host via the host interface 162, the disk controller 165 may read the data requested by the read command from the disk 160 using the read/write channel 170, temporarily hold the read data in the buffer 175 and output the read data from the buffer 175 to the host via the host interface 162.
The host may address data in write/read commands using logical addresses (LBAs), in which each LBA addresses a block of data. The disk controller 165 may maintain a translation table mapping the LBAs from the host to physical addresses of the corresponding data on the disk 160. The translation table may also be referred to as a mapping table. When the disk controller 165 receives a host read command requesting data at certain LBAs, the disk controller 165 uses the translation table to translate the LBAs to the corresponding physical addresses on the disk 160 to locate the requested data on the disk 160. The use of LBAs allows the host to address data stored in the disk drive 100 without having to know the physical locations of the data on the disk 160.
As the disk controller 165 writes data from the host to the disk 160, the disk controller 165 may update the translation table to map the LBAs of the data to the corresponding physical addresses on the disk 160. This allows the disk controller 165 to later locate the data on the disk 160 when the disk controller 160 receives a read command from the host requesting data at the corresponding LBAs. The disk controller 160 may temporarily store the translation table in the buffer 175 and update the translation table in the buffer 175 as the disk controller 165 writes data to the disk 160. The disk controller 165 may write the updated translation table to the disk 160 at regular intervals to store the updates on the disk 160.
To increase the data storage capacity of the disk 160, the disk controller 165 may write data to the disk 160 using shingle writing, in which data is written to sequential tracks 115 on the disk 160 in one direction. The direction may be from the outer diameter (OD) to the inner diameter (ID) of the disk 160 or the opposite direction. As discussed below, shingle writing allows the disk drive 100 to write narrower tracks 115, and hence increase the storage capacity of the disk 160, without reducing the dimensions of the head 150.
An example of shingle writing is illustrated in FIGS. 2A-2D, which shows the progression of a shingle write to the disk 160. In FIG. 2A, the head 150 writes data to the disk 160 in a first circular band 210a. In FIG. 2B, the head 150 is offset by a small amount from its position in FIG. 2A. The head 150 then writes subsequent data to the disk 160 in a second circular band 210b. The second circular band 210b overlaps and overwrites most of the first circular band 210a, leaving a narrow portion of the first circular band 210a that defines a first narrow track 215a. In FIG. 2C, the head 150 is offset again and the head 150 writes subsequent data to a third circular band 210c. The third circular band 210c overlaps and overwrites most of the second circular band 210b, leaving a narrow portion of the second circular band 210b that defines a second narrow track 215b. In FIG. 2D, the head 150 is offset again and the head 150 writes subsequent data to a fourth circular band 210d. The fourth circular band 210d overlaps and overwrites most of the third circular band 210c, leaving a narrow portion of the third circular band 210c that defines a third narrow track 215c. This process may be repeated to write data on the disk 160. Thus, shingle writing allows the disk drive 100 to write narrower tracks for given head dimensions, thereby increasing the storage capacity of the disk 160.
In shingle writing, data is written to the tracks 115 in a sequential manner. As a result, the physical address corresponding to an LBA changes each time the disk drive rewrites data for the LBA. As discussed above, the disk controller 165 may maintain a translation table in the buffer 175 providing logical-to-physical mapping information for data stored on the disk 160, and update the translation table as data is written to the disk 160. The disk controller 165 may write the updates in the translation table to the disk 160 at regular intervals to store the updates on the disk 160. However, if the disk drive 100 experiences an unexpected power loss before the updates are written to the disk 160, then the updates in the translation table may be lost.
To avoid losing updates in the translation table due to an unexpected power loss or other cause, the disk controller 165 may also write metadata files to the disk 160 as data is written to the disk 160. The metadata files may be interspersed or interleaved with the data written on the disk 160. Each metadata file may include logical-to-physical mapping information for data written on the disk 160. Thus, the metadata files provide a redundant copy of logical-to-physical mapping information in the translation table. If the disk drive 100 loses power before updates in the translation table can be written to the disk 160, then, on the next power cycle, the disk controller 110 can read the metadata files from the disk 160 and use the read metadata files to reconstruct the updates in the translation table.
FIG. 3 illustrates a metadata scheme according to an embodiment of the present invention. FIG. 3 shows an example of two tracks 305-1 and 305-2, in which the left hand of each track 305-1 and 305-2 in FIG. 3 corresponds to the beginning of track. In this example, the disk controller 165 may first write data to track 305-1 and then write data to track 305-2 during a shingle write. Data is written on each track 305-1 to 305-2 from left to right in FIG. 3.
As shown in the example in FIG. 3, each track 305-1 and 305-2 includes data and metadata files 310-1 to 310-4 and 320 interspersed or interleaved with the data on the disk 160. For ease of illustration, the servo wedges 1220-122N are not shown in FIG. 3. The metadata files 310-1 to 310-4 and 320 may include two types of metadata files. The first type of metadata files may be referred to as write logs 310-1 to 310-4 and the second type of metadata files 320 may be referred to as footers, both of which are discussed below.
Each write log 310-1 to 310-4 may include logical-to-physical mapping information for data on the disk 160 preceding the write log 310-1 to 310-4. The disk controller 165 may write the write logs 310-1 to 310-4 at regular locations on the tracks. For example, the disk controller 165 may write a write log at the beginning of each track 305-1 and 305-2 and a write log at the middle of each track 305-1 and 305-2, as shown in FIG. 3. Each write log located at the beginning of a track 305-1 and 305-2 may include logical-to-physical mapping information for data in the preceding track. For example, write log 310-3 may include logical-to-physical mapping information for data in preceding track 305-1. Each write log located at the middle of a track 305-1 and 305-2 may include logical-to-physical mapping information for data preceding the write log in the same track and a portion or all of the data in the preceding track. For example, write log 310-4 may include logical-to-physical mapping information for data preceding write log 310-4 in the same track 305-2 (i.e., data to the left of write log 310-4 in track 302-2 in FIG. 3) and a portion or all of the data in preceding track 305-1. In one embodiment, each write log 310-1 to 310-4 may include a duplicate copy of some of the logical-to-physical mapping information in one or more preceding write logs 310-1 to 310-4, as discussed further below.
Each footer 320 may include logical-to-physical mapping information for data on the disk 160 preceding the footer 320. In one embodiment, the disk controller 165 may write a footer when a write command is completed (e.g., a write command from the host). In this embodiment, when the disk controller 165 finishes writing data on the disk 160 for a write command, the disk controller 165 may write a footer 320 at the end of the data for the write command. The footers 320 are not written at fixed, regular locations on the tracks 305-1 and 305-2. Rather, a footer 320 is written on the disk 160 when the disk controller 165 completes a write command, which may occur at various locations on a track. Thus, when a write command is completed, instead of abandoning an unused portion of a track until the next write log location, a footer may be written at the end of the data for the write command to store a metadata file for the data. It is possible to write more than one footer, if necessary, to maintain a minimum level of redundancy.
In one embodiment, the disk controller 165 may only notify the host that a write command is completed when the corresponding footer 320 is written on the disk 160. For example, certain host commands may require that data for a write command be successfully written on the disk 160 (committed to the disk) before the disk controller 165 notifies the host that the write command is completed. In this example, the corresponding footer may also need to be written on the disk 160 before the disk controller 165 notifies the host that the write command is completed.
In one embodiment, the disk controller 165 may maintain a circular buffer that stores logical-to-physical mapping information for data recently written to the disk 160. The circular buffer may have a predetermined length. In this embodiment, as the disk controller 165 writes data to the disk 160, the disk controller 165 writes logical-to-physical mapping information for the data in the circular buffer. When the circular buffer is full, the disk controller 165 may start overwriting the oldest logical-to-physical mapping information in the circular buffer with the logical-to-physical mapping information for the most recent data written to the disk 160. The circular buffer is not to be confused with the buffer 175 in FIG. 1. The circular buffer may reside in the buffer 175 or other memory in the disk drive 100.
In one embodiment, when the disk controller 165 writes a metadata file (e.g., write log or footer) to the disk 165, the disk controller 165 may include the current contents of the circular buffer in the metadata file. Thus, a metadata file on the disk 165 may include the contents of the circular buffer at the time the metadata file is written on the disk 165.
FIG. 4 shows an example of a circular buffer 405 that may be used to store logical-to-physical mapping information according to an embodiment of the present invention. In the example in FIG. 4, the circular buffer 405 includes slots 410-0 to 410-11 for twelve entries. It is to be appreciated that the circular buffer 405 is not limited to twelve slots and may include any number of slots. Each entry may include logical-to-physical mapping information for data corresponding to one or more LBAs. For example, when the data corresponds to a sequence of LBAs mapped to a sequence of physical addresses, the logical-to-physical mapping information for the data may be compressed using run length compression and stored as one entry in the circular buffer 405.
In one embodiment, the disk controller 165 may write entries in the circular buffer 410 starting at slot 410-0. When the circular buffer 405 becomes full, the disk controller 165 may loop back to slot 410-0 and start overwriting the oldest entry with the newest entry, which includes logical-to-physical mapping information for the most recent data written to the disk 160.
The disk controller 165 may maintain a plurality of pointers for the circular buffer 405 including a newest entry pointer, a 1× pointer, a 2× pointer and a track pointer.
The newest entry pointer identifies the newest entry in the circular buffer. The newest entry includes the logical-to-physical mapping for the most recent data written to the disk 160. As writing occurs, the newest entry pointer is advanced as each entry is added.
The 1× pointer identifies the first entry in the circular buffer 405 that is a duplicate copy of logical-to-physical mapping information in the immediately preceding write log. The 1× pointer is advanced to the position of the newest entry pointer each time a write log is written to the disk 160.
The 2× pointer identifies the first entry in the circular buffer 405 that is a duplicate copy of logical-to-physical mapping information in both the last two preceding write logs. Thus, the 2× pointer identifies the first entry that is at least doubly redundant. When a write log is written to the disk 160, the 1× pointer is advanced to the position of the newest entry pointer and the 2× pointer is advanced to the old position of the 1× pointer.
The track pointer points to the first entry in the circular buffer 405 that is included in the write log at the beginning of the track. The track pointer is advanced to the position of the newest entry pointer each time a write log is written at the beginning of a track.
The entries between various pointers may be described as follows. The entries 420 between the newest entry pointer and the 1× pointer include logical-to-physical mapping information for data written after the immediately preceding write log. The entries 425 between the 1× pointer and the 2× pointer include logical-to-physical mapping information for data written between the two most recent preceding write logs. Thus, the entries 425 between the 1× pointer and the 2× pointer include logical-to-physical mapping information that is a duplicate copy of logical-to-physical mapping information in the immediately preceding write log. The entries 435 before the 2× pointer include logical-to-physical mapping information for data written before the second most recent preceding write log. The entries between the newest entry pointer and the track pointer include logical-to-physical mapping information for data written on the current track.
As discussed above, when a metadata file is written to the disk 160, the disk controller 165 may include the current contents of the circular buffer 405 in the metadata file. For example, the metadata file may include a header and a payload. The disk controller 165 may include the pointers in the header of the metadata file and may include the entries in the circular buffer 405 in the payload of the metadata file. The disk controller 165 may also include an identifier in the header identifying the metadata file, as discussed further below.
Referring back to the example in FIG. 3, when the disk controller 165 writes write log 310-4 to the disk 160, the disk controller 165 may include the current contents of the circular buffer 405 in write log 310-4. In this example, the newest entry pointer identifies the newest entry in write log 310-4 that includes the logical-to-physical mapping information for the data immediately preceding write log 310-4. The 1× pointer identifies the first entry in write log 310-4 that includes a duplicate copy of logical-to-physical mapping information in the immediately preceding write log 310-3. In this example, the track pointer is at the same position as the 1× pointer since the immediately preceding write log 310-3 is at the beginning of the track 305-2. The 2× pointer identifies the first entry in write log 310-4 that includes a duplicate copy of logical-to-physical mapping information in the second preceding write log 310-2. Thus, the 2× pointer identifies the first entry in write log 310-4 that is at least doubly redundant on the disk 160.
In one embodiment, when the entries 440 between the newest entry pointer and the 2× pointer fill the circular buffer 405, the disk controller 165 immediately writes the next write log. This may be done to maintain a minimum level of redundancy of logical-to-physical mapping information on the disk 160. In this embodiment, the disk controller 165 may monitor the position of the 2× pointer as data is written to the disk 160. If the entries 440 between the newest entry pointer and the 2× pointer reach the length of the circular buffer 405, then the disk controller 165 may stop writing data, immediately write the next write log, and resume writing data after the next write log. In this example, the portion of the track between the location where the writing stops and the next write log may be left unused.
An example of a metadata file scheme will now be described according to an embodiment of the present invention with references to FIGS. 5 and 6. FIG. 5 shows an example of tracks including data and metadata files (write logs and footers) interspersed with the data, and FIG. 6 shows an example of the entries in the metadata files.
Referring to FIG. 5, each row corresponds to a track with the left hand of FIG. 5 corresponding to the beginning of each track. The capital letters A-Q in the tracks represent sequential extents of user data. FIG. 5 also shows write logs (WL) with numeric labels (1-6) and footers (F) labeled with lowercase letters (a-f).
FIG. 6 shows an example of the contents of each write log and footer shown in FIG. 5. FIG. 6 also shows the locations of the newest entry pointer, the 1× pointer, the 2× pointer, and the track pointer for each write log and footer. In this example, it is assumed that the circular buffer 405 is empty at the beginning of data extent A and the payload of each write log and footer has space for twelve entries.
As shown in FIG. 6, footer (a) includes logical-to-physical mapping information for data extents A-C, which precede footer (a).
Write log (1) includes logical-to-physical mapping information for data extents A-D. Thus, write log (1) includes the logical-to-physical mapping information in footer (a) and adds the logical-to-physical mapping information for data extent D, which is between footer (a) and write log (1).
Footer (b) includes logical-to-physical mapping information for data extents A-G. Thus, in this example, footer (b) includes all of the logical-to-physical mapping information in write log (1) and adds logical-to-physical mapping information for data extents E-G.
Write log (2) includes logical-to-physical mapping information for data extents A-H1. For write log (2), the 1× pointer points to the first entry in write log (2) that includes a duplicate copy of mapping information in the preceding write log (1).
Footer (c) includes logical-to-physical mapping information for data extents A-H2. For footer (c), the 1× pointer points to the entry corresponding to data extent H1 because this is the first entry in footer (c) that includes a duplicate copy of mapping information in the immediately preceding write log (2). The 2× pointer points to the entry corresponding to data extent D because this is the first entry in footer (c) that includes a duplicate copy of mapping information in the second preceding write log (1). The track pointer coincides with the 1× pointer since the immediately preceding write log (2) is located at the beginning of the track. Footer (d) includes logical-to-physical mapping information for data extents A-I.
Write log (3) includes logical-to-physical mapping information for data extents A-J. For write log (3), the 1× pointer points to the entry corresponding to data extent H1 because this is the first entry in write log (3) that includes a duplicate copy of mapping information in the immediately preceding write log (2). The 2× pointer points to the entry corresponding to data extent D because this is the first entry in write log (3) that includes a duplicate copy of mapping information in the second preceding write log (1). Footer (e) includes logical-to-physical mapping information for data extents A-K.
Write log (4) includes logical-to-physical mapping information for data extents B-L. In this example, the entry corresponding to data extent L overwrites the entry corresponding to data extent A. The newest entry pointer points to the entry corresponding to data extent L since data extent L immediately precedes write log (4). For write log (4), the 1× pointer points to the entry corresponding to data extent J because this is the first entry in write log (4) that includes a duplicate copy of mapping information in the immediately preceding write log (3). The 2× pointer points to the entry corresponding to data extend H1 because this is the first entry in write log (4) that includes a duplicate copy of mapping information in the second preceding write log (2).
Write log (5) includes logical-to-physical mapping information for data extents D-N. In this example, the entries corresponding to data extents M and N overwrite the entries corresponding to data extents B and C. The newest entry pointer points to the entry corresponding to data extent N since data extent N immediately precedes write log (5). For write log (5), the 1× pointer points to the entry corresponding to data extent L because this is the first entry in write log (5) that includes a duplicate copy of mapping information in the immediately preceding write log (4). The 2× pointer points to the entry corresponding to data extend J because this is the first entry in write log (5) that includes a duplicate copy of mapping information in the second preceding write log (3). Footer (f) includes logical-to-physical mapping information for data extents F-P.
Write log (6) includes logical-to-physical mapping information for data extents G-Q. The newest entry pointer points to the entry corresponding to data extent Q since data extent Q immediately precedes write log (6). For write log (6), the 1× pointer points to the entry corresponding to data extent N because this is the first entry in write log (6) that includes a duplicate copy of mapping information in the immediately preceding write log (5). The 2× pointer points to the entry corresponding to data extent L because this is the first entry in write log (6) that includes a duplicate copy of mapping information in the second preceding write log (4).
Thus, each write log and footer adds new mapping information and repeats some of the mapping information in preceding write logs and/or footers.
FIG. 7 is a flowchart illustrating a method of writing logical-to-physical mapping information on a disk 160 according to an embodiment of the present invention.
In step 710, data is written on the disk 710. In step 720, logical-to-physical mapping information for data already written on the disk is stored in a circular buffer. In step 730, a plurality of metadata files are written on the disk 160. The metadata files are interspersed with the data on the disk and each metadata file includes the contents of the circular buffer at the time the metadata file is written on the disk. It is to be appreciated that the writing of the metadata in step 730 can be performed in parallel with the writing of the data in step 710.
As discussed above, if updates in the translation are lost due to an unexpected power loss, then, on the next power cycle, the disk controller 165 can read metadata files (e.g., write logs and footers) on the disk to reconstruct the updates in the translation that were lost. This is because the metadata files provide a redundant copy of the logical-to-physical mapping information in the translation table.
In one embodiment, each write log may include an identifier in its header. For example, the identifier may include a sequence number that indicates the order of the write log relative to other write logs on the disk 160. In this example, the sequence number may be incremented for each write log written to the disk 160. This allows the disk controller 165 to identify the last write log written on the disk 160 based on the write log with the highest sequence number. Thus, when the disk controller 165 reads write logs on the disk 160 to reconstruct updates in the translation table, the disk controller 165 can start with the first write log written after the translation table was last saved on the disk 160 and read write logs until the last write log written on the disk 160 is reached. In this embodiment, the translation table last saved on the disk 160 may include the sequence number at the time the translation table was saved on the disk 160. The disk controller 165 may use this sequence number to identify the first write log written on the disk 160 after the translation table was last saved on the disk 160.
The footers may also include identifiers in their headers. For example, each footer may include an identifier indicating the immediately preceding write log. In this example, after reading the last write log, the disk controller 165 can look for any footers written after the last write log. If there is one or more footers written after the last write log, then the disk controller 165 can use the mapping information in the footers to reconstruct the updates in the translation table.
As discussed above, each write log and footer may include a duplicate copy of mapping information in preceding write logs and/or footers. This provides redundancy of the mapping information on the disk 160, allowing the disk controller 160 to obtain the mapping information needed to reconstruct the translation table even when one or more write logs and/or footers are defective. Referring to the example in FIG. 6, if write log (2) is defective, then the disk controller 165 can read write log (3) to obtain the mapping information for data extents E-H1 since write log (3) includes a duplicate copy of the mapping information for data extents E-H1. The disk controller 165 may identify the entries in write log (3) that are duplicate copies of the entries in detective write log (2) based on the location of the 1× pointer in write log (3).
For the purposes of the present specification, it should be appreciated that the terms “processor”, “microprocessor”, and “controller”, etc., refer to any machine or collection of logic that is capable of executing a sequence of instructions and shall be taken to include, but not be limited to, general purpose microprocessors, special purpose microprocessors, central processing units (CPUs), digital signal processors (DSPs), application specific integrated circuits (ASICs), multi-media controllers, signal processors and microcontrollers, etc.
The description of the invention is provided to enable any person skilled in the art to practice the various embodiments described herein. While the present invention has been particularly described with reference to the various figures and embodiments, it should be understood that these are for illustration purposes only and should not be taken as limiting the scope of the invention.
There may be many other ways to implement the invention. Various functions and elements described herein may be partitioned differently from those shown without departing from the spirit and scope of the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and generic principles defined herein may be applied to other embodiments. Thus, many changes and modifications may be made to the invention, by one having ordinary skill in the art, without departing from the spirit and scope of the invention.
A reference to an element in the singular is not intended to mean “one and only one” unless specifically stated, but rather “one or more.” The term “some” refers to one or more. Underlined and/or italicized headings and subheadings are used for convenience only, do not limit the invention, and are not referred to in connection with the interpretation of the description of the invention. All structural and functional equivalents to the elements of the various embodiments of the invention described throughout this disclosure that are known or later come to be known to those of ordinary skill in the art are expressly incorporated herein by reference and intended to be encompassed by the invention. Moreover, nothing disclosed herein is intended to be dedicated to the public regardless of whether such disclosure is explicitly recited in the above description.

## Claims

1. A disk drive, comprising:
a rotatable disk;
a head actuated over the disk; and
a controller configured to write data on the disk using the head, to store logical-to-physical mapping information in a circular buffer, and to write a plurality of metadata files on the disk using the head, wherein the plurality of metadata files are interspersed with the data on the disk and each of the metadata files includes the entire contents of the circular buffer at a time the metadata file is written on the disk,
wherein the plurality of metadata files includes a first metadata file and a second metadata file with the second metadata file following the first metadata file on the disk, and wherein the second metadata file includes a duplicate copy of logical-to-physical mapping information included in the first metadata file and logical-to-physical mapping information for data on the disk between the first and second metadata files.

2. The disk drive of claim 1, wherein each metadata file includes a newest entry pointer identifying logical-to-physical mapping information for data on the disk immediately preceding the metadata file.

3. The disk drive of claim 2, wherein at least one of the metadata files includes a first pointer identifying logical-to-physical mapping information in the metadata file that is a duplicate copy of logical-to-physical mapping information stored in a preceding metadata file on the disk.

4. The disk drive of claim 1, wherein the controller is configured to overwrite oldest logical-to-physical mapping information in the circular buffer with new logical-to-physical mapping information when the circular buffer is full.

5. The disk drive of claim 1, wherein when there are less than three copies of an oldest logical-to-physical mapping information on the disk, the controller is configured to immediately write one of the metadata files on the disk before writing the remaining data on the disk.

6. The disk drive of claim 1, wherein the controller is configured to read a translation table from the disk, to read one or more of the metadata files from the disk, and to update the translation table based on the read one or more metadata files.

7. The disk drive of claim 1, wherein the plurality of metadata files comprises a plurality of write logs, and the controller is configured to periodically write the write logs on the disk as the data is written on the disk.

8. The disk drive of claim 7, wherein the controller is configured to write at least one of the write logs at a beginning of a track on the disk, the write log including logical-to-physical mapping information for data in a preceding track.

9. The disk drive of claim 8, wherein the controller is configured to write at least one of the write logs at approximately a middle of a track, the metadata file including logical-to-physical mapping information for data preceding the write log on the track.

10. The disk drive of claim 7, wherein at least one of the write logs includes a first pointer identifying logical-to-physical mapping information in the write log that is a duplicate copy of logical-to-physical mapping information stored in an immediately preceding write log on the disk.

11. The disk drive of claim 10, wherein the at least one write log includes a second pointer identifying logical-to-physical mapping information in the write log that is a duplicate copy of logical-to-physical mapping information stored in a second preceding write log on the disk.

12. The disk drive of claim 7, wherein the plurality of metadata files comprises at least one footer, and the controller is configured to write the footer on the disk at an end of data for a write command.

13. The disk drive of claim 12, wherein the write command is from a host, and the controller is configured to report completion of the write command to the host after the footer is written on the disk.

14. The disk drive of claim 1, wherein the controller is configured to write the data on the disk using shingle writing.

15. The disk drive of claim 1, wherein the controller is configured to write multiple metadata files interspersed with data within a single track.

16. A method of writing logical-to-physical mapping information on a disk, comprising:
writing data on the disk;
storing logical-to-physical mapping information in a circular buffer; and
writing a plurality of metadata files on the disk, wherein the plurality of metadata files are interspersed with the data on the disk and each of the metadata files includes the entire contents of the circular buffer at a time the metadata file is written on the disk,
wherein the plurality of metadata files includes a first metadata file and a second metadata file with the second metadata file following the first metadata file on the disk, and wherein the second metadata file includes a duplicate copy of logical-to-physical mapping information included in the first metadata file and logical-to-physical mapping information for data on the disk between the first and second metadata files.

17. The method of claim 16, wherein each metadata file includes a newest entry pointer identifying logical-to-physical mapping information for data on the disk immediately preceding the metadata file.

18. The method of claim 17, wherein at least one of the metadata files includes a first pointer identifying logical-to-physical mapping information in the metadata file that is a duplicate copy of logical-to-physical mapping information stored in a preceding metadata file on the disk.

19. The method of claim 16, further comprising:
reading a translation table from the disk;
reading one or more of the metadata files from the disk; and
updating the translation table based on the read one or more metadata files.

20. The method of claim 16, wherein the plurality of metadata files comprises a plurality of write logs, and the writing the plurality of metadata files comprises periodically writing the write logs on the disk as the data is written on the disk.

21. The method of claim 20, wherein the writing the plurality of metadata files comprises writing at least one of the write logs at a beginning of a track, the write log including logical-to-physical mapping information for data in a preceding track.

22. The method of claim 21, wherein the writing the plurality of metadata files comprises writing at least one of the write logs at approximately a middle of a track, the metadata file including logical-to-physical mapping information for data preceding the write log on the track.

23. The method of claim 20, wherein at least one of the write logs includes a first pointer identifying logical-to-physical mapping information in the write log that is a duplicate copy of logical-to-physical mapping information stored in an immediately preceding write log on the disk.

24. The method of claim 23, wherein the at least one write log includes a second pointer identifying logical-to-physical mapping information in the write logs that is a duplicate copy of logical-to-physical mapping information stored in a second preceding write log on the disk.

25. The method of claim 20, wherein the plurality of metadata files comprises at least one footer, and the writing the plurality of metadata files comprises writing the footer on the disk at an end of data for a write command.

26. The method of claim 16, wherein the writing the data on the disk comprises shingle writing.

27. The method of claim 16, wherein the writing the plurality of metadata files comprises writing multiple metadata files interspersed with data within a single track.