Disclosure of Invention
The embodiment of the invention provides a file storage method and device and a file deletion method and device, which are used for finding disk resources occupied by files without traversing the files in a directory when the directory is deleted and deleting the directory and the files. Therefore, the system resources occupied when the whole directory is deleted can be effectively reduced.
According to an aspect of the present invention, there is provided a file storage method, the method including:
adding three attribute files for each directory, which are respectively:
the data block pointer list is used for recording data blocks used by all application files in the directory and data blocks used by the directory;
list of directory nodes: the index node information of the subdirectory under the directory is recorded, the disk resources occupied by the files under the subdirectory are searched, and the directory is also saved as the position of the index node of the subdirectory in the index node list of the father directory;
the file node list is used for recording index node information used by all application files in the directory, and the index node information comprises index node information of the directory;
adding an offset position list for each application file, wherein the offset position list is used for recording the position of a data block number occupied by the application file in a data block pointer list of a directory to which the application file belongs, and simultaneously storing the position of index node information of the application file in the directory node list;
storing directory data, file data of application files in the directory and file index node information in a data block; storing a data block pointer to the data block; storing directory index node information of the directory and file index node information of the application file; and storing the position information of the data block pointer of the file data of the application file and the position information of the file index node information of the application file.
According to another aspect of the present invention, there is also provided a file deleting method, including:
adding three attribute files for each directory, which are respectively:
the data block pointer list is used for recording data blocks used by all application files in the directory and data blocks used by the directory;
list of directory nodes: the index node information of the subdirectory under the directory is recorded, the disk resources occupied by the files under the subdirectory are searched, and the directory is also saved as the position of the index node of the subdirectory in the index node list of the father directory;
the file node list is used for recording index node information used by all application files in the directory, and the index node information comprises index node information of the directory;
adding an offset position list for each application file, wherein the offset position list is used for recording the position of a data block number occupied by the application file in a data block pointer list of a directory to which the application file belongs, and simultaneously storing the position of index node information of the application file in the directory node list;
acquiring a data block pointer set pointing to a data block storing directory data, file data of an application file under the directory and file index node information from a data block pointer list; acquiring directory index node information of the directory and file index node information of the application file from a directory node list and a file node list; acquiring the position information of a data block pointer of the file data of the application file and the position information of file index node information of the application file from an offset position list; acquiring a data block pointer corresponding to the application file to be deleted from the data block pointer set according to the position information of the data block pointer of the file data of the application file, and releasing the file data of the application file in the data block pointed by the data block pointer; and releasing the file index node information corresponding to the application file to be deleted according to the position information of the file index node information of the application file.
According to another aspect of the present invention, there is also provided a file storage apparatus, the apparatus including:
the directory processing unit is used for adding three attribute files for each directory, and the three attribute files are respectively as follows:
the data block pointer list is used for recording data blocks used by all application files in the directory and data blocks used by the directory;
list of directory nodes: the index node information of the subdirectory under the directory is recorded, the disk resources occupied by the files under the subdirectory are searched, and the directory is also saved as the position of the index node of the subdirectory in the index node list of the father directory;
the file node list is used for recording index node information used by all application files in the directory, and the index node information comprises index node information of the directory;
the file processing unit is used for adding an offset position list for each application file, recording the position of a data block number occupied by the application file in a data block pointer list of a directory to which the application file belongs, and simultaneously storing the position of index node information of the application file in the directory node list;
the file data storage unit is used for storing directory data and file index node information of application files in the directory by taking a data block as a unit; a data block pointer storage unit for storing a data block pointer pointing to the data block; a directory node storage unit for storing directory index node information of the directory; the file node storage unit is used for storing file index node information of the application file; and the position information storage unit is used for storing the position information of the data block pointer of the file data of the application file in the data block pointer storage unit and the position information of the file index node of the application file in the file node storage unit.
According to another aspect of the present invention, there is also provided a file deleting apparatus, the apparatus including:
the directory processing unit is used for adding three attribute files for each directory, and the three attribute files are respectively as follows:
the data block pointer list is used for recording data blocks used by all application files in the directory and data blocks used by the directory;
list of directory nodes: the index node information of the subdirectory under the directory is recorded, the disk resources occupied by the files under the subdirectory are searched, and the directory is also saved as the position of the index node of the subdirectory in the index node list of the father directory;
the file node list is used for recording index node information used by all application files in the directory, and the index node information comprises index node information of the directory;
the file processing unit is used for adding an offset position list for each application file, recording the position of a data block number occupied by the application file in a data block pointer list of a directory to which the application file belongs, and simultaneously storing the position of index node information of the application file in the directory node list;
a data block pointer acquisition unit, configured to acquire, from a data block pointer list, a data block pointer set pointing to a data block in which directory data and file data of an application file under the directory and file index node information are stored; a directory node acquisition unit, configured to acquire directory index node information of the directory and file index node information of the application file from a directory node list and a file node list; a file node acquisition unit configured to acquire, from an offset position list, position information of a data block pointer of file data of the application file and position information of file index node information of the application file; the data release unit is used for acquiring a data block pointer corresponding to the application file to be deleted from the data block pointer set according to the position information of the data block pointer of the file data of the application file, and releasing the file data of the application file in the data block pointed by the data block pointer; and releasing the file index node information corresponding to the application file to be deleted according to the position information of the file index node information of the application file.
By the technical scheme provided by the embodiment of the invention, when the directory is deleted, the disk resources occupied by the files can be found without traversing the files in the directory, and the directory and the files thereof are deleted. The system resources occupied when the whole directory is deleted are effectively reduced.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
In order to find the disk resources occupied by all files under a directory without traversing the files under the directory, and simultaneously, in order to improve the efficiency of deleting the directory, the storage structure of the files is changed, and three attribute files are added to each directory:
list of data block pointers: for recording the data blocks used by all application files under the directory and the data blocks used by the directory itself.
(II) list of directory nodes: the index node information of the subdirectory under the directory is recorded, the disk resources occupied by the files under the subdirectory are mainly searched, and the directory is also saved as the position of the index node of the subdirectory in the index node list of the parent directory.
(III) file node list: and the index node information used for recording all the application files under the directory, including the index node information of the directory itself.
Adding a property file for each application file:
list of offset positions: the directory node list is used for recording the position of the data block number occupied by the application file in the data block pointer list of the directory to which the application file belongs, and simultaneously storing the position of the index node information of the application file in the directory node list.
Example one
As shown in fig. 1, the file storage apparatus 100 of the present embodiment includes: the file data storage unit 101 is configured to store directory data and application file data in the directory in units of data blocks; the data block pointer storage unit 102 is configured to store a data block pointer pointing to the data block; the directory node storage unit 103 is configured to store directory index node information of the directory; the file node storage unit 104 is configured to store the directory index node information and the application file index node information; the location information storage unit 105 is configured to store application file data block pointer location information of the application file in the data block pointer storage unit, and application file index node location information of the application file in the file node storage unit.
As shown in fig. 2, the file storage method flow of this embodiment includes: storing directory data and application file data under the directory in a data block of a nonvolatile memory (step S101); a data block pointer pointing to the data block is stored, directory index node information of the directory and file index node information of the application file are stored, and location information of the application file and the data block pointer and location information of the application file and the file index node information are stored (step S102).
As shown in fig. 3, a root directory 1000 and its subdirectory 2000 are created, and an application file 3000 is stored under the root directory 1000, where the inode number (inode information) of the root directory 1000 is 1000, the inode number of the subdirectory 2000 is 2000, and the inode number of the application file 3000 is 3000. An application file 3100, an application file 3200, an application file 3300, an application file 3400, and an application file 3500 are stored under the subdirectory 2000, wherein the inode numbers of the five application files of the subdirectory 2000 are 3100, 3200, 3300, 3400, and 3500 in this order.
As shown in fig. 4, three attribute files are created for the root directory 1000: a data block pointer list 1001, a directory node list 1002 and a file node list 1003, and the inode numbers of the three attribute files are 1001, 1002 and 1003 in sequence. And creates an offset location list 3001 for the application file 3000.
The data block pointer list 1001 records: pointers 421, 422, 423, 424 and pointers 500-504. The pointers point to different data blocks of the nonvolatile memory respectively, wherein the pointer 421 points to a data block storing root directory data, the pointer 422 points to a data block storing a pointer list of the root directory data block, the pointer 423 points to a data block storing root directory index node information, the pointer 424 points to a data block storing root directory file index node information, and the pointers 500-504 point to data blocks storing application file data under the root directory.
The directory node list 1002 records: root directory inode number 1000.
The file node list 1003 records: root directory inode number 1000, data block pointer list inode number 1001, directory node list inode number 1002, file node list inode number 1003, and application file inode number 3000.
The offset position list 3001 records: file node list offset pointer 5 and data block pointer list offset pointers 5, 6, 7, 8, 9. Where the meaning of file node list offset pointer 5 is: file inode number 5 pointing to the file node list 3000; the meaning of the data block pointer list offset pointers 5, 6, 7, 8, 9 is: a 5 th data block pointer 500, a 6 th data block pointer 501, a 7 th data block pointer 502, an 8 th data block pointer 503, and a 9 th data block pointer 504, which point to the data block pointer list in this order.
The method has the advantages that in order to find the disk resources occupied by all the files in the directory without traversing the files in the directory, and simultaneously in order to improve the efficiency of deleting the directory, the storage structure of the files is changed, and a data block pointer list, a directory node list and a file node list are added to each directory; an offset location list is added to the application file. Therefore, when the directory is deleted, the data block pointers of all the files to be deleted in the data block pointer list are obtained according to the offset position list, the data of the data blocks pointed by the pointers are released, and the directory node list and the index node information of the directories to be deleted and the application files in the file node list are deleted. The method and the device realize that the disk resources occupied by the files can be found without traversing the files under the directory, and establish the basis of data storage of the directory and the application files convenient for directory deletion.
Example two
The directory inode number 2000 of the subdirectory 2000 is added to the directory node list 1002 as shown in figure 4.
As shown in FIG. 5, three property files are created for subdirectory 2000: a data block pointer list 2001, a directory node list 2002 and a file node list 2003, and inode numbers of the three attribute files are 2001, 2002 and 2003 in this order.
Offset location list 3101 is created for application file 3100, offset location list 3201 is created for application file 3200, offset location list 3301 is created for application file 3300, offset location list 3401 is created for application file 3400, and offset location list 3501 is created for application file 3500.
The data block pointer list 2001 as a data block pointer set records: pointers 621, 622, 623, 624 and pointers 700-704. The pointers point to different data blocks of the nonvolatile memory respectively, wherein the pointer 621 points to a data block storing subdirectory data, the pointer 622 points to a data block storing a subdirectory data block pointer list, the pointer 623 points to a data block storing subdirectory index node information, the pointer 624 points to a data block storing root directory file index node information, and the pointers 700-704 point to data blocks storing application file data under subdirectories.
The directory node list 2002 records: offset location pointer 2 of subdirectory 2000 in directory node list 1002.
The file node list 2003 records: subdirectory inode number 2000, data block pointer list inode number 2001, directory node list inode number 2002, file node list inode number 2003, and application file inode numbers 3100, 3200, 3300, 3400, and 3500.
The offset position list 3101 has recorded therein: file node list offset pointer 5 and data block pointer list offset pointer 5. Where the meaning of file node list offset pointer 5 is: the 5 th file inode number 3100 that points to the file node list; the meaning of data block pointer list offset pointer 5 is: a 5 th data block pointer 700 to a list of data block pointers.
The offset position list 3201 records: file node list offset pointer 6 and data block pointer list offset pointer 6. Where the meaning of file node list offset pointer 6 is: the 6 th file inode number 3200, which points to the file node list; the meaning of data block pointer list offset pointer 6 is: a 6 th data block pointer 701 pointing to a list of data block pointers.
The offset position list 3301 records: file node list offset pointer 7 and data block pointer list offset pointer 7. Where the meaning of file node list offset pointer 7 is: file inode number 7 pointing to file node list 3300; the meaning of data block pointer list offset pointer 7 is: a 7 th data block pointer 702 to the data block pointer list.
The offset position list 3401 records: file node list offset pointer 8 and data block pointer list offset pointer 8. Where the meaning of file node list offset pointer 8 is: file inode number 8 pointing to the file node list 3400; the meaning of data block pointer list offset pointer 8 is: an 8 th data block pointer 703 pointing to the data block pointer list.
The offset position list 3501 records: file node list offset pointer 9 and data block pointer list offset pointer 9. Where the meaning of file node list offset pointer 9 is: file inode number 9 pointing to the file node list 3500; the meaning of data block pointer list offset pointer 9 is: a 9 th data block pointer 704 to a list of data block pointers.
In order to find the disk resources occupied by all files under a directory without traversing the files under the directory, and simultaneously, in order to improve the efficiency of deleting the directory, the storage structure of the files is changed, and a data block pointer list, a directory node list and a file node list are added to each directory; an offset location list is added to the application file. Therefore, when the directory is deleted, the data block pointers of all the files to be deleted in the data block pointer list are obtained according to the offset position list, the data of the data blocks pointed by the pointers are released, and the directory node list and the index node information of the directories to be deleted and the application files in the file node list are deleted. The method and the device realize that the disk resources occupied by the files can be found without traversing the files under the directory, and establish the basis of data storage of the directory and the application files convenient for directory deletion.
EXAMPLE III
As shown in fig. 6, the file deleting apparatus of the present embodiment includes: the data block pointer acquiring unit 201 is configured to acquire a data block pointer set pointing to a data block in which directory data and application file data under the directory are stored; the directory node obtaining unit 202 is configured to obtain directory index node information of the directory and file index node information of the application file; the file node obtaining unit 203 is configured to obtain location information of the application file and the data block pointer, and location information of the application file and the file index node information; the data releasing unit 204 is configured to obtain, from the data block pointer set of the data block pointer obtaining unit 201, a data block pointer corresponding to an application file to be deleted according to the location information of the application file and the data block pointer obtained by the file node obtaining unit 203, and release application file data in a data block pointed by the data block pointer; and according to the application file of the file node obtaining unit 203 and the position information of the file index node information, releasing the file index node information corresponding to the application file to be deleted.
As shown in fig. 7, the file deletion method flow of this embodiment includes: acquiring a data block pointer set pointing to a data block storing directory data and application file data under the directory, acquiring directory index node information of the directory and file index node information of the application file, and acquiring location information of the application file and the data block pointer and location information of the application file and the file index node information (step S201); acquiring a data block pointer corresponding to the application file to be deleted from the data block pointer set according to the position information of the application file and the data block pointer, and releasing application file data in a data block pointed by the data block pointer; and releasing the file index node information corresponding to the application file to be deleted according to the application file and the position information of the file index node information (step S202).
To illustrate an embodiment of how a file is deleted, it is illustrated in fig. 3 and 4. As shown in fig. 3, the inode number (inode information) of the root directory 1000 is 1000, the inode number of the subdirectory 2000 is 2000, and the inode number of the application file 3000 is 3000. If the application file 3000 is to be deleted, the following steps are performed:
as shown in fig. 4, three attribute files of the root directory 1000 are obtained: a data block pointer list 1001, a directory node list 1002, and a file node list 1003; the application file offset position list 3001 is acquired.
From the offset position list 3001, it can be known that: file node list offset pointer 5 points to the 5 th file inode number 3000 of the file node list; the data block pointer list offset pointers 5, 6, 7, 8, 9 point to the 5 th data block pointer 500, the 6 th data block pointer 501, the 7 th data block pointer 502, the 8 th data block pointer 503, and the 9 th data block pointer 504 of the data block pointer list in sequence.
The data stored in the nonvolatile memory data blocks indicated by the data block pointers 500, 501, 502, 503, and 504 are released, and the 5 th file inode number 3000 in the file node list is released, so that the application file 3000 in the root directory 1000 can be deleted.
In order to find the disk resources occupied by all files under a directory without traversing the files under the directory, and simultaneously, in order to improve the efficiency of deleting the directory, the storage structure of the files is changed, and a data block pointer list, a directory node list and a file node list are added to each directory; adding a list of offset locations to the application file. Therefore, when the directory is deleted, the data block pointers of all the files to be deleted in the data block pointer list are obtained according to the offset position list, the data of the data blocks pointed by the pointers are released, and the directory node list and the index node information of the directories to be deleted and the application files in the file node list are deleted. The method and the device realize that the disk resources occupied by the files can be released without traversing the files in the directory.
Example four
To illustrate an embodiment of how a file is deleted, it is described with reference to fig. 3, 4, and 5. As shown in fig. 3, the inode number (inode information) of the root directory 1000 is 1000, the inode number of the subdirectory 2000 is 2000, and the inode number of the application file 3000 is 3000. An application file 3100, an application file 3200, an application file 3300, an application file 3400 and an application file 3500 are stored under the subdirectory 2000, wherein the inode numbers of the application files of the five subdirectories are 3100, 3200, 3300, 3400 and 3500 in sequence.
The directory inode number 2000 of the subdirectory 2000 is added to the directory node list 1002 shown in fig. 4. If the subdirectory 2000 and its five application files are to be deleted, the following steps are performed:
as shown in fig. 5, three property files of the subdirectory 2000 are acquired: a data block pointer list 2001, a directory node list 2002, and a file node list 2003. Offset location list 3101 of application file 3100, offset location list 3201 of application file 3200, offset location list 3301 of application file 3300, offset location list 3401 of application file 3400, and offset location list 3501 of application file 3500 are acquired.
As seen from the offset position list 3101: file node list offset pointer 5 points to the 5 th file inode number 3100 for the file node list; data block pointer list offset pointer 5 points to the 5 th data block pointer 700 of the data block pointer list.
As can be seen from offset position list 3201: file node list offset pointer 6 points to the 6 th file inode number 3200 of the file node list; data block pointer list offset pointer 6 points to the 6 th data block pointer 701 of the data block pointer list.
As can be seen from the offset location list 3301: file node list offset pointer 7 points to the 7 th file inode number 3300 of the file node list; data block pointer list offset pointer 7 points to the 7 th data block pointer 702 of the data block pointer list.
As can be seen from the offset position list 3401: file node list offset pointer 8 points to the 8 th file inode number 3400 of the file node list; data block pointer list offset pointer 8 points to the 8 th data block pointer 703 of the data block pointer list.
As can be seen from the offset location list 3501: file node list offset pointer 9 points to the 9 th file inode number 3500 of the file node list; data block pointer list offset pointer 9 points to the 9 th data block pointer 704 of the data block pointer list.
From the list of directory nodes 2002: offset location pointer 2 in directory node list 2002 points to directory inode number 2000 in directory node list 1002.
Releasing the data stored on the nonvolatile memory data blocks pointed by the data block pointers 700, 701, 702, 703 and 704; releasing file inode numbers 3100, 3200, 3300, 3400, 3500 corresponding to bits 5, 6, 7, 8, 9 of the file node list 2003; a data block pointer corresponding to the subdirectory 2000 is 621, a data block pointer corresponding to the data block pointer list 2001 is 622, a data block pointer corresponding to the directory node list 2002 is 623, and a data block pointer corresponding to the file node list 2003 is 624, and data stored in nonvolatile memory data blocks corresponding to the data block pointers 621, 622, 623 and 624 are released; and releases the directory inode number 2000 of the subdirectory 2000 in the directory node list 1002. The deletion of the sub-directory 2000 and its five application files can be realized.
In video file applications such as video surveillance, the number of directories and the number of levels are generally small, and a large number of files exist in the directories. In such applications, deleting information also often takes the form of deleting an entire directory.
In order to find the disk resources occupied by all files under a directory without traversing the files under the directory, and simultaneously, in order to improve the efficiency of deleting the directory, the storage structure of the files is changed, and a data block pointer list, a directory node list and a file node list are added to each directory; adding a list of offset locations to the application file. Therefore, when the directory is deleted, the data block pointers of all the files to be deleted in the data block pointer list are obtained according to the offset position list, the data of the data blocks pointed by the pointers are released, and the directory node list and the index node information of the directories to be deleted and the application files in the file node list are deleted. The method and the device realize that the disk resources occupied by the files can be released without traversing the files in the directory.
The above specific embodiments are merely illustrative of the present invention and are not intended to limit the present invention.