Method, device and computer program product for managing metadata of file system
This disclosure provides a method, device and a computer program product for managing metadata of a file system. The method may include: determining a data structure of the metadata based on a type of the file system; deriving a reference value for a first field of the metadata based on the data structure of the metadata and a protocol of the file system; and overwriting the first field of the metadata with the reference value in response to an actual value of the first field of the metadata being not equal to the reference value and there being no backup for the metadata.
1 . A method for managing metadata of a file system comprising:
determining a data structure of the metadata based on a type of the file system, wherein the type of the file system comprises a new technology file system (NTFS) or a File Allocation Table 32 (FAT32);
deriving a reference value for a first field of the metadata based on the data structure of the metadata and a protocol of the file system, wherein the protocol of the file system defines predefined values or value ranges for fields of the data structure;
overwriting the first field of the metadata stored on a disk with the reference value in response to an actual value of the first field of the metadata being not equal to the reference value and there being no backup for the metadata, so as to recover the metadata; and
wherein overwriting comprises, in response to an actual value of the first field of the metadata being not equal to the reference value and there being a backup for the metadata, overwriting the metadata with the backup, wherein overwriting the metadata with the backup comprises:
in response to a value of a first field of the backup being not equal to the reference value, overwriting the first field of the metadata with the reference value and overwriting the other fields of the metadata with the backup.
2 . The method of claim 1 , wherein overwriting the metadata with the backup comprises:
overwriting all fields of the metadata with the backup in response to a value of a first field of the backup being equal to the reference value.
3 . The method of claim 1 , wherein overwriting the metadata with the backup comprises:
overwriting all fields of the metadata with the backup; and
in response to a value of a first field of the backup being not equal to the reference value, overwriting the first field of the metadata with the reference value.
4 . The method of claim 1 , further comprising:
deriving a reference value range for a second field of the metadata based on the data structure of the metadata and the protocol of the file system; and
in response to an actual value of the second field of the metadata not falling within the reference value range and there being a backup for the metadata, overwriting the metadata with the backup.
5 . The method of claim 1 , wherein the file system is the NTFS, the data structure of the metadata comprises a record header and a record body, the record body comprises one or more attributes, and each attribute comprises an attribute header and an attribute body.
6 . A device for managing metadata of a file system comprising:
one or more processors;
a memory coupled to at least one of the processors; and
a set of computer program instructions stored in the memory, which, in response to execution by at least one of the processors, perform actions of:
determining a data structure of the metadata based on a type of the file system, wherein the type of the file system comprises a new technology file system (NTFS) or a File Allocation Table 32 (FAT32);
deriving a reference value for a first field of the metadata based on the data structure of the metadata and a protocol of the file system, wherein the protocol of the file system defines predefined values or value ranges for fields of the data structure;
overwriting the first field of the metadata stored on a disk with the reference value in response to an actual value of the first field of the metadata being not equal to the reference value and there being no backup for the metadata, so as to recover the metadata; and
wherein overwriting comprises overwriting, in response to an actual value of the first field of the metadata being not equal to the reference value and there being a backup for the metadata, the metadata with the backup,
wherein overwriting the metadata with the backup comprises, in response to a value of a first field of the backup being not equal to the reference value, overwriting the first field of the metadata with the reference value and overwriting the other fields of the metadata with the backup.
7 . The device of claim 6 , wherein overwriting the metadata with the backup comprises:
overwriting all fields of the metadata with the backup in response to a value of a first field of the backup being equal to the reference value.
8 . The device of claim 6 , wherein overwriting the metadata with the backup comprises:
overwriting all fields of the metadata with the backup; and
in response to a value of a first field of the backup being not equal to the reference value, overwriting the first field of the metadata with the reference value.
9 . The device of claim 6 , wherein the set of computer program instructions, when executed by at least one of the processors, are further configured to perform actions of:
deriving a reference value range for a second field of the metadata based on the data structure of the metadata and the protocol of the file system; and
in response to an actual value of the second field of the metadata not falling within the reference value range and there being a backup for the metadata, overwriting the metadata with the backup.
10 . The device of claim 6 , wherein the file system is the NTFS, the data structure of the metadata comprises a record header and a record body, the record body comprises one or more attributes, and each attribute comprises an attribute header and an attribute body.
11 . A computer program product for managing metadata of a file system, the computer program product comprising a non-transitory computer readable storage medium having program instructions embodied therewith, the program instructions, in response to execution by a processor, are configured to cause the processor to:
determine a data structure of the metadata based on a type of the file system, wherein the type of the file system comprises a new technology file system (NTFS) or a File Allocation Table 32 (FAT32);
derive a reference value for a first field of the metadata based on the data structure of the metadata and a protocol of the file system, wherein the protocol of the file system defines predefined values or value ranges for fields of the data structure;
overwrite the first field of the metadata stored on a disk with the reference value in response to an actual value of the first field of the metadata being not equal to the reference value and there being no backup for the metadata, so as to recover the metadata; and
wherein overwriting comprises overwriting, in response to an actual value of the first field of the metadata being not equal to the reference value and there being a backup for the metadata, the metadata with the backup,
wherein overwriting the metadata with the backup comprises, in response to a value of a first field of the backup being not equal to the reference value, overwriting the first field of the metadata with the reference value and overwriting the other fields of the metadata with the backup.
12 . The computer program product of claim 11 , wherein overwriting the metadata with the backup comprises:
overwriting all fields of the metadata with the backup in response to a value of a first field of the backup being equal to the reference value.
13 . The computer program product of claim 11 , wherein overwriting the metadata with the backup comprises:
overwriting all fields of the metadata with the backup; and
in response to a value of a first field of the backup being not equal to the reference value, overwriting the first field of the metadata with the reference value.
14 . The computer program product of claim 11 , wherein the program instructions further cause the processor to:
derive a reference value range for a second field of the metadata based on the data structure of the metadata and the protocol of the file system; and
in response to an actual value of the second field of the metadata not falling within the reference value range and there being a backup for the metadata, overwrite the metadata with the backup.