CN117312246A - Method for preventing data damage caused by power failure when writing data into hard disk - Google Patents

Method for preventing data damage caused by power failure when writing data into hard disk Download PDF

Info

Publication number
CN117312246A
CN117312246A CN202311062735.2A CN202311062735A CN117312246A CN 117312246 A CN117312246 A CN 117312246A CN 202311062735 A CN202311062735 A CN 202311062735A CN 117312246 A CN117312246 A CN 117312246A
Authority
CN
China
Prior art keywords
hard disk
data
writing
temporary file
file area
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202311062735.2A
Other languages
Chinese (zh)
Inventor
王二生
徐斌
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
China Standard Software Co Ltd
Original Assignee
China Standard Software Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by China Standard Software Co Ltd filed Critical China Standard Software Co Ltd
Priority to CN202311062735.2A priority Critical patent/CN117312246A/en
Publication of CN117312246A publication Critical patent/CN117312246A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/16File or folder operations, e.g. details of user interfaces specifically adapted to file systems
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/16File or folder operations, e.g. details of user interfaces specifically adapted to file systems
    • G06F16/162Delete operations
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/17Details of further file system functions
    • G06F16/172Caching, prefetching or hoarding of files
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Human Computer Interaction (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
  • Memory System Of A Hierarchy Structure (AREA)

Abstract

The invention relates to a method for preventing data damage caused by power failure when a hard disk writes data, which is applied to a Linux operating system and comprises the following steps: s1: the Linux operating system generates a cache dirty page and sends a request for writing data into a hard disk; s2: the Linux operating system creates a temporary file area on the blank area of the hard disk and initializes the temporary file area; s3: the Linux operating system writes the target data in the cache dirty page into the temporary file area and modifies the state of the temporary file area; s4: the Linux operating system writes target data in the temporary file area into the hard disk target area and modifies the state of the temporary file area; s5: the writing ends. The invention mainly aims to solve the problem that the self-checking time is too long due to the overlarge capacity of a hard disk in a Linux operating system when the hard disk is powered down and the data writing is incomplete and the situation that damaged data appear on the hard disk after the hard disk is powered up again.

Description

Method for preventing data damage caused by power failure when writing data into hard disk
Technical Field
The invention relates to the field of electric digital processing, in particular to a method for preventing data damage caused by power failure when data is written in a hard disk.
Background
Computer hard disk is the most important data storage device of computer, and its main function is to store operating system, application program and user data. In the operation process of the Linux operating system, temporary files generated by an application program, copied program data or data such as a system log and the like need to be stored on a hard disk. In general, when a Linux operating system needs to write data into a hard disk, the data on the hard disk is mapped into a cache page of a memory, when the Linux operating system modifies the data, the data is modified in the cache page, and a dirty page mark is added to the cache page, the Linux operating system writes the cache page data with the dirty page mark onto the hard disk, after the writing is finished, the dirty page mark is removed from the cache page, and in the process, if a host is powered off, the data is incompletely written into the hard disk, which leads to damaged data on the hard disk. In order to avoid damaged data on a hard disk, a Linux operating system is provided with a file system repairing mechanism, and the method for processing the damaged data caused by power failure comprises the following steps: in the next boot process of the Linux operating system, a hard disk self-checking program is operated, the whole partition data of the hard disk is detected, and the following five types of data damage are repaired:
1. unreferenced inodes; 2. a super-large number of links; 3. unused data blocks not recorded in the hard disk block mapping table; 4. the listed free data blocks are also used in a certain context; 5. incorrect summary information in the superblock. And finally, repairing the incomplete data to ensure that no missing damaged data exists on the hard disk. The flow chart is shown in fig. 1 below.
The self-contained file system repairing mechanism of the Linux operating system triggers a hard disk self-checking program only when the machine is restarted, and if the hard disk is reinserted into the system or the hard disk is electrified again, the operating system is not restarted, the hard disk self-checking program is not triggered at this time, and damaged data in the hard disk cannot be processed.
The file system repairing mechanism of the Linux operating system cannot quickly locate the position where damaged data exists, the whole operating system partition needs to be subjected to full-disk scanning inspection, and for the large-capacity partition, the hard disk self-inspection needs to last for a long time, and the hard disk self-inspection is blocked in the starting stage of the Linux system for a long time, so that the starting speed of the Linux system is affected.
Disclosure of Invention
The invention mainly aims to solve the problem that the self-checking time is too long because of the overlarge capacity of a hard disk and avoid the problem that the self-checking of the hard disk cannot be triggered because the operating system is not restarted after the hard disk is electrified again when the data writing of the hard disk is incomplete because of the power failure in the Linux operating system.
In order to achieve the above object, the present invention provides a method for preventing data damage caused by power failure when writing data into a hard disk, the method is applied to a Linux operating system, and includes the following steps:
s1: the Linux operating system generates a cache dirty page and sends a request for writing data into a hard disk;
s2: the Linux operating system creates a temporary file area on the blank area of the hard disk and initializes the temporary file area;
s3: the Linux operating system writes the target data in the cache dirty page into the temporary file area and modifies the state of the temporary file area;
s4: the Linux operating system writes the target data in the temporary file area into the hard disk file system and modifies the state of the temporary file area;
s5: the writing ends.
Preferably, in step S2, the process of initializing the temporary file area is as follows:
formatting the temporary file area, and clearing the data in the temporary file area;
setting a writing/erasing flag bit, and marking the writing/erasing flag bit as a writing data flag;
setting a block writing completion zone bit, and marking the block writing completion zone bit as no;
setting a completion flag bit of writing target data into the hard disk, and marking the completion flag bit of writing target data into the hard disk as no;
the temporary file area acquires the position information of the blank area through the hard disk file system, and records and writes the position information into the target data position information of the temporary file area.
Further preferably, in step S3, after the target data is written in the temporary file area, the following operations are performed:
the modified block writing completion flag bit flag is yes;
and the completion flag bit of the modification target data written into the hard disk is marked as yes.
Still further preferably, when the hard disk is powered down and restarted, the Linux operating system performs the following operations:
the Linux operating system firstly detects whether a temporary file area exists, if not, the operation is ended, and if so, the hard disk self-checking program continues to detect the mark of the block writing completion mark bit of the temporary file area;
if the mark of the block writing completion mark bit is no, deleting the hard disk temporary file area and ending the operation;
if the mark of the block writing completion mark bit is yes, continuing to detect that the target data is written into the hard disk completion mark bit;
if it is detected that the writing of the target data into the hard disk is completed, the hard disk temporary file area is deleted, and the operation is ended,
if the completion flag bit of writing the target data into the hard disk is detected to be no, the operation of writing the data from the temporary file area into the hard disk is continued to be executed.
The beneficial effects of the invention are as follows:
according to the invention, the temporary file area is divided on the hard disk, and the flag bit is set, so that when data is written, the data of the cache dirty pages cannot be directly written into the hard disk file system, and the flag bit of the temporary file area is normal, so that the data of the temporary file area is not damaged. The invention divides the operation of writing into the hard disk into two phases: the first stage is to store the data of the buffer dirty page in the temporary file area, and the second stage is to write the data from the temporary file area into the hard disk block. If the hard disk is powered off in the first stage, directly discarding the data of the temporary file area after the hard disk is powered on; if the hard disk is powered off in the second stage, the writing operation in the second stage can be continuously finished when the flag bit of the temporary file area is detected to be normal after the hard disk is powered on. Therefore, the hard disk power failure can not cause the damage phenomenon of the hard disk file system data.
According to the method, the hard disk is powered on again after power failure, the operating system is not required to restart, the self-checking operation is not required to be carried out on the hard disk, the Linux operating system only needs to detect the flag bit of the temporary file area of the hard disk, then the data is selected to be written into the hard disk file system continuously or the data of the temporary file area of the hard disk is discarded, the normal state of the hard disk can be recovered conveniently and quickly, the problem that the self-checking time is too long due to the fact that the capacity of the magnetic disk is too large is solved, and the problem that the self-checking of the magnetic disk cannot be triggered due to the fact that the operating system is not restarted is avoided.
Drawings
The invention will be described in further detail with reference to the drawings and the detailed description.
FIG. 1 is a flow chart of a prior art method for writing data into a hard disk in a dirty page of a cache;
FIG. 2 is a flow chart of the present invention for writing data in a cached dirty page to a hard disk.
Detailed Description
The technical solutions in the embodiments of the present invention are clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. In the following description, numerous specific details are set forth in order to provide a thorough understanding of the present invention, but the present invention may be practiced in other ways other than those described herein, and persons skilled in the art will readily appreciate that the present invention is not limited to the specific embodiments disclosed below.
As shown in fig. 2, the present embodiment provides a method for preventing data damage caused by power failure when writing data into a hard disk, which is applied to a Linux operating system, and includes the following steps:
s1: the Linux operating system presents a cache dirty page and sends a request for writing data into a hard disk.
S2: the Linux operating system creates a temporary file area on the blank area of the hard disk and initializes the temporary file area. The temporary file area is a section of storage space divided on the hard disk so as to store the following five parts of contents: writing/erasing flag bits, target data blocks, block writing completion flag bits, target data position information, and target data writing completion flag bits. The write/erase flag bit is used to flag whether the operation is writing data or erasing data, and since the modification of the hard disk data is divided into two operations, i.e., writing data to the hard disk and erasing data to the hard disk, the present embodiment is directed only to the operation of writing data to the hard disk, and erasing data to the hard disk is another data changing operation of the hard disk, and the present embodiment does not involve erasing data to the hard disk, the write/erase flag bit in the present embodiment is a write flag. The target data block is used for storing data of the cache dirty pages, and the block writing completion flag bit is used for marking the state of the target data block of the temporary file area of the hard disk when the data of the cache dirty pages is written into. The target data location information is the location information of a blank hard disk area of the same capacity as the target data block obtained from the file system of the hard disk, and the information is written into the target data location information of the temporary file area. The target data writing completion flag bit is a flag for marking completion of writing of the target data block content into the hard disk file system.
Thus, according to the above, in this step, the process of initializing the temporary file area is as follows:
formatting the temporary file area, and clearing the data in the temporary file area; it should be noted that, the blank area of the hard disk is not all binary data of 0 or 1, but only the operating system marks that the block of hard disk is blank, not occupied, and can write data, but the block of storage area still has data information. Therefore, when a temporary file area is created in this block of storage area, this block of area needs to be completely emptied when it is reused in order to prevent data interference, i.e., the disk data of this block of area is completely reset to "0" from a binary point of view.
Setting a writing/erasing flag bit, and marking the writing/erasing flag bit as a writing data flag;
setting a block writing completion zone bit, and marking the block writing completion zone bit as no;
setting a completion flag bit of writing target data into the hard disk, and marking the completion flag bit of writing target data into the hard disk as no;
the temporary file area acquires the position information of the blank area through the hard disk file system, and records and writes the position information into the target data position information of the temporary file area.
S3: and the Linux operating system writes the target data in the cache dirty page into the temporary file area and modifies the state of the temporary file area.
Specifically, in this step, after target data is written into the temporary file area from the cached dirty page, the following operations are performed:
the modified block write complete flag bit flag is yes.
S4: and the Linux operating system writes the target data in the temporary file area into the hard disk file system and modifies the state of the temporary file area.
Specifically, in this step, after target data is written from the temporary file area to the hard disk, the following operations are performed: and the completion flag bit of the modification target data written into the hard disk is marked as yes.
When writing data into a disk file system from a temporary file area, firstly checking a writing/erasing flag bit in the temporary file area of the disk, confirming writing operation, then checking a block writing completion flag bit, confirming the file integrity of the temporary file area, finally reading target data position information, copying the data of a target data block of the temporary file area of the disk into a blank storage space of the disk file system, setting the writing completion flag bit of the target data into the disk as yes after copying, and finishing the writing operation of the target data into the disk file system from the temporary file area of the disk.
S5: the writing ends.
Through the operation, after the hard disk is powered down and restarted, the Linux operating system executes the following operations:
firstly, whether a temporary file area exists is detected, if the temporary file area does not exist, the situation that data is not written in before the hard disk is powered down is indicated, and also, damaged data does not exist, if the temporary file area exists, a block writing completion flag bit is continuously detected, and because the block writing completion flag bit is used for marking the state of caching target data blocks of the temporary file area of dirty page data, the preset default value is no, the block writing completion flag bit is marked as yes after the writing is completed, therefore, if the block writing completion flag bit is detected as no, the situation that the target data blocks of the temporary file area are not written in completely before the hard disk is powered down is indicated, the temporary file area of the hard disk is deleted, and the operation is ended. If the detected block writing completion flag bit is yes, the fact that the target data block of the temporary file area is written in before the hard disk is powered down is indicated, the fact that the target data is written in the hard disk completion flag bit is continuously detected, the target data writing into the hard disk completion flag bit is used for marking a flag for writing the content of the target data block into a hard disk file system to be completed, a default value is preset to be no, and the writing completion is marked to be yes. If the completion flag bit of the target data written into the hard disk is detected to be yes, the temporary file area data is indicated to be written into the hard disk file system, the hard disk temporary file area is deleted, and the operation is finished, if the completion flag bit of the target data written into the hard disk is detected to be no, the data of the temporary file area is indicated to be not completely written into the hard disk file system, and the operation of writing the data into the hard disk file system from the target data block of the temporary file area is continuously executed.
It will be apparent that the described embodiments are only some, but not all, embodiments of the invention. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.

Claims (5)

1. The method for preventing the data damage caused by the power failure when the hard disk writes the data is characterized by being applied to a Linux operating system and comprising the following steps of:
s1: the Linux operating system generates a cache dirty page and sends a request for writing data into a hard disk;
s2: the Linux operating system creates a temporary file area on the blank area of the hard disk and initializes the temporary file area;
s3: the Linux operating system writes the target data in the cache dirty page into the temporary file area and modifies the state of the temporary file area;
s4: the Linux operating system writes the target data in the temporary file area into the hard disk file system and modifies the state of the temporary file area;
s5: the writing ends.
2. The method for preventing data corruption due to the loss of electrical conduction when writing data to a hard disk according to claim 1, wherein in step S2, the process of initializing the temporary file area is as follows:
formatting the temporary file area, and clearing the data in the temporary file area;
setting a writing/erasing flag bit, and marking the writing/erasing flag bit as a writing data flag;
setting a block writing completion zone bit, and marking the block writing completion zone bit as no;
setting a completion flag bit of writing target data into the hard disk, and marking the completion flag bit of writing target data into the hard disk as no;
the temporary file area acquires the position information of the blank area through the hard disk file system, and records and writes the position information into the target data position information of the temporary file area.
3. The method for preventing damage to data caused by dropping electricity when writing data to a hard disk according to claim 2, wherein in step S3, after the target data is written to the temporary file area, the following operations are performed:
the modified block write complete flag bit flag is yes.
4. A method of preventing corruption of data due to a loss of electrical conduction when writing data to a hard disk as recited in claim 3 wherein, in step S4, after the target data is written to the hard disk, the following operations are performed:
and the completion flag bit of the modification target data written into the hard disk is marked as yes.
5. The method for preventing data corruption due to power-down when writing data to a hard disk of claim 4, wherein the Linux operating system performs the following operations after the hard disk is powered down and restarted:
the Linux operating system firstly detects whether a temporary file area exists, if not, the operation is ended, and if so, the hard disk self-checking program continues to detect the mark of the block writing completion mark bit of the temporary file area;
if the mark of the block writing completion mark bit is no, deleting the hard disk temporary file area and ending the operation;
if the mark of the block writing completion mark bit is yes, continuing to detect that the target data is written into the hard disk completion mark bit;
if it is detected that the writing of the target data into the hard disk is completed, the hard disk temporary file area is deleted, and the operation is ended,
if the completion flag bit of writing the target data into the hard disk is detected to be no, the operation of writing the data from the temporary file area into the hard disk is continued to be executed.
CN202311062735.2A 2023-08-22 2023-08-22 Method for preventing data damage caused by power failure when writing data into hard disk Pending CN117312246A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311062735.2A CN117312246A (en) 2023-08-22 2023-08-22 Method for preventing data damage caused by power failure when writing data into hard disk

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311062735.2A CN117312246A (en) 2023-08-22 2023-08-22 Method for preventing data damage caused by power failure when writing data into hard disk

Publications (1)

Publication Number Publication Date
CN117312246A true CN117312246A (en) 2023-12-29

Family

ID=89254318

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311062735.2A Pending CN117312246A (en) 2023-08-22 2023-08-22 Method for preventing data damage caused by power failure when writing data into hard disk

Country Status (1)

Country Link
CN (1) CN117312246A (en)

Similar Documents

Publication Publication Date Title
US11068391B2 (en) Mapping table updating method for data storage device
KR100644602B1 (en) Method for driving remapping for flash memory and flash memory architecture thereto
CN107818269B (en) File storage method and system based on Flash
US7558904B2 (en) Controller, data memory system, data rewriting method, and computer program product
US5734816A (en) Nonvolatile memory with flash erase capability
JP4164118B1 (en) Storage device using flash memory
JP2005115857A (en) File storage device
JP2009199625A (en) Memory card, and method for controlling memory card and method for controlling nonvolatile semiconductor memory
JP2009116601A (en) Memory device, memory management method, and program
CN104050056A (en) File system backup of multi-storage-medium device
CN105468544B (en) Method and device for realizing power-down prevention file system and power-down prevention file system
CN114237984A (en) Recovery method and system of Trim data under abnormal power failure and solid state disk
TWI381386B (en) Method for managing data and storage apparatus thereof and controller thereof
CN109325005B (en) Data processing method and electronic equipment
CN117312246A (en) Method for preventing data damage caused by power failure when writing data into hard disk
CN111949212B (en) File system and file management method based on self-defined open channel SSD
JP4419415B2 (en) Recording method
JP2005506632A (en) Security device for mass storage devices
JP6864228B2 (en) Storage device and data management method for storage device
JP2008123104A (en) Data-access device
CN114880277B (en) Block device snapshot method, system and storage medium
CN109739683B (en) LKJ file writing method based on power failure protection medium and storage medium
JP2007133535A (en) File system inside storage device
JP5751488B2 (en) File management device
JP4502689B2 (en) Data storage device and initialization method thereof

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination