File writing method and device, electronic equipment and storage medium

By applying for adjacent reserved blocks when the file is first written and writing is given priority, the problem of discontinuity of file data block storage is solved, writing efficiency is improved, and continuous storage and efficient writing of data on the medium are realized.

CN119807143APending Publication Date: 2025-04-11BEIJING CO WHEELS TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311315484.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-10-11
Publication Date
2025-04-11

AI Technical Summary

Technical Problem

The storage of data blocks of the same file from the file system to the physical medium is random, resulting in discontinuity of storage, increasing the number of write instructions, and reducing the writing efficiency.

Method used

By determining whether the file to be written is written for the first time, if it is written for the first time, the first data block is written to the physical medium, and a reserved block adjacent to its write area is applied. The remaining data blocks are preferred to write to the reserved block, and the number of reserved blocks is maintained until all files are written.

Benefits of technology

It solves the problem of discontinuous storage of data blocks in the same file, reduces the number of write instructions, improves the writing efficiency, makes the data more concentrated on the medium, and avoids fragmentation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119807143A_ABST
    Figure CN119807143A_ABST
Patent Text Reader

Abstract

The invention discloses a file writing method and device, electronic equipment and a storage medium, and relates to the technical field of computers. The method comprises the steps of judging whether a to-be-written file is written for the first time; under the condition that the file to be written is written for the first time, the first data block of the file to be written is written into a physical medium, and after the first data block is written, a first number of reserved blocks adjacent to a first data block writing area are applied; and preferentially writing other data blocks of the to-be-written file into the reserved blocks, and supplementing the number of the reserved blocks until the to-be-written file is completely written. According to the method, the adjacent space of the write-in area of the first data block is reserved to form the reserved block, the subsequent data blocks are preferentially written into the reserved block, and meanwhile, the number of the reserved blocks is always kept at the first number until all files are written in, so that data are more gathered on a medium and are not fragmented any more. The problem of discontinuous storage when the file blocks of the same file are stored in the physical medium is solved, and the writing efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a file writing method, device, electronic device and storage medium. Background Art

[0002] The storage of file data in the system is logically ordered, and the data blocks that make up the same file are stored adjacently in the system. However, when writing files in the system to physical media, it is necessary to select a free area in the physical media for writing. Due to the repeated access of other files in the physical media, the free areas in the physical media may not be connected, and the storage of data blocks from the file system to the physical media is random, as long as there is a free area, it will be stored, which will cause the data blocks of the same file to be stored discontinuously in the physical media.

[0003] If the free area of ​​a physical medium in which multiple data blocks of a file are stored is not continuous, the driver needs to send multiple write instructions to interact with the physical medium, thereby reducing the write efficiency. Summary of the invention

[0004] In view of this, the present application provides a file writing method, device, electronic device and storage medium, which can solve the current problem of discontinuous storage when data blocks of the same file are stored in physical media, reduce the number of write instructions and improve write efficiency.

[0005] In a first aspect, the present application provides a file writing method, comprising:

[0006] Determine whether the file to be written is written for the first time; wherein the file to be written includes at least one data block;

[0007] When the file to be written is written for the first time, writing the first data block of the file to be written to the physical medium, and after the first data block is written, applying for a first number of reserved blocks adjacent to the writing area of ​​the first data block;

[0008] The remaining data blocks of the file to be written are preferentially written into the reserved blocks, and the number of the reserved blocks is supplemented until the file to be written is completely written.

[0009] Optionally, the remaining data blocks of the file to be written are preferentially written into the reserved blocks, and the number of the reserved blocks is supplemented until the file to be written is completely written, including: when writing the remaining data blocks of the file to be written, write them into the reserved blocks, and apply again for a second number of reserved blocks adjacent to the area where the data blocks are written this time, so that the total number of the reserved blocks is maintained at the first number until the file to be written is completely written; wherein the first number and the second number are positive integers, and the second number is less than the first number.

[0010] Optionally, when writing the remaining data blocks of the file to be written, they are written into the reserved blocks, and a second number of reserved blocks adjacent to the writing area of ​​the current data blocks are applied for again, so that the total number of reserved blocks is maintained at the first number until the file to be written is completely written, including: writing the second data block of the file to be written into the reserved blocks; after writing the second data block, applying for the second number of reserved blocks adjacent to the writing area of ​​the second data block, so that the total number of current reserved blocks is the first number, until all data blocks of the file to be written are written to the physical medium.

[0011] Optionally, the remaining data blocks of the file to be written are preferentially written into the reserved blocks, and the number of the reserved blocks is supplemented until the file to be written is completely written, and the method further includes: after all the data blocks of the file to be written are completely written into the physical medium, the reserved blocks are released.

[0012] Optionally, after all data blocks of the file to be written are written to the physical medium, the reserved blocks are released, including: releasing the reserved blocks of the file to be written this time through memory update processing; the memory update processing includes power off processing, restart processing and update processing by receiving user instructions.

[0013] Optionally, after determining whether the file to be written is being written for the first time, it also includes: if the file to be written is not being written for the first time, searching for the number of free blocks in the physical medium when the file to be written was last written; according to the previous number of free blocks, searching for a free area in the physical medium that is consistent with the previous number of free blocks; and writing the file to be written into the free area.

[0014] Optionally, the application process of the reserved block includes: after the data block is written, sending an application instruction for a storage area adjacent to the physical address of the write area; obtaining the physical address of the adjacent storage area, and using the adjacent storage area as the reserved block; the physical address is used to indicate that the data block is written to the physical medium.

[0015] In a second aspect, the present application provides a file writing device, comprising:

[0016] A judging unit configured to judge whether the file to be written is written for the first time; wherein the file to be written includes at least one data block;

[0017] A first writing unit is configured to, when the file to be written is written for the first time, write a first data block of the file to be written into a physical medium, and after the first data block is written, apply for a first number of reserved blocks adjacent to a writing area of ​​the first data block;

[0018] The second writing unit is configured to preferentially write the remaining data blocks of the file to be written into the reserved blocks, and to supplement the number of the reserved blocks until the file to be written is completely written.

[0019] In a third aspect, the present application provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the file writing method described in the first aspect.

[0020] In a fourth aspect, the present application provides an electronic device, comprising a storage medium, a processor, and a computer program stored on the storage medium and executable on the processor, wherein the processor implements the file writing method described in the first aspect when executing the computer program.

[0021] By means of the above technical scheme, the present application provides a file writing method, device, electronic device and storage medium, which first determines whether the file to be written is written to the physical medium for the first time. If the file to be written is written for the first time, the first data block is written first, and after the first data block is written, a first number of reserved blocks adjacent to the writing area of ​​the first data block are applied; the remaining data blocks of the file to be written are preferentially written into the reserved blocks, and the number of reserved blocks is supplemented until the file to be written is completely written. The present application reserves the adjacent space of the writing area of ​​the first data block to form a reserved block, and preferentially writes subsequent data blocks into the reserved block, while keeping the number of reserved blocks at the first number until the file is completely written, so that the data is more concentrated on the medium and no longer fragmented. The problem of discontinuous storage when the file blocks of the same file are stored in the physical medium is solved, and the writing efficiency is improved.

[0022] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0024] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0025] Figure 1 A schematic diagram of a process of writing a file provided in an embodiment of the present application is shown;

[0026] Figure 2 A schematic diagram showing the logical location of a file in a file system provided by an embodiment of the present application;

[0027] Figure 3 A schematic diagram showing a location where file data is stored in a physical medium provided by an embodiment of the present application;

[0028] Figure 4 A schematic diagram showing a flow chart of another file writing method provided in an embodiment of the present application is shown;

[0029] Figure 5 A schematic diagram showing a location where file data is stored in a physical medium after the file writing method provided by an embodiment of the present application is applied;

[0030] Figure 6 A schematic structural diagram of a file writing device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION

[0031] In order to more clearly understand the above-mentioned purposes, features and advantages of the present application, the scheme of the present application will be further described below. It should be noted that the embodiments of the present application and the features in the embodiments can be combined with each other without conflict.

[0032] In order to solve the problem of discontinuous storage of data blocks of the same file when they are currently stored in physical media, and to improve writing efficiency, this embodiment proposes a file writing method, which reserves the adjacent space of the writing area of ​​the first data block to form a reserved block, and writes subsequent data blocks into the reserved block first, while keeping the number of reserved blocks at the first number until the file is fully written, so that the data is more concentrated on the medium and no longer fragmented. This solves the problem of discontinuous storage of file blocks of the same file when they are stored in physical media, and improves writing efficiency. Figure 1 As shown, the method includes:

[0033] S101, determining whether the file to be written is being written for the first time.

[0034] The file to be written includes at least one data block, and the file to be written refers to a file that needs to be stored and written into a physical medium. When a file needs to be written into a physical medium, it is necessary to determine whether the file to be written is written for the first time.

[0035] S102, when the file to be written is written for the first time, write the first data block of the file to be written into the physical medium, and after the first data block is written, apply for a first number of reserved blocks adjacent to the writing area of ​​the first data block.

[0036] Here we first explain several concepts. In this solution, data blocks refer to the way to store files in the file system when the files to be written are not written to the physical medium. For example, Figure 2 The logical location of file data in the file system is shown. A file may include multiple data blocks. Data blocks are written to the physical medium in sequence. It can also be understood that data blocks are the storage concept in the file-based system.

[0037] A reserved block is a storage block (or storage area) with a fixed memory size in a physical medium. There can be several storage blocks in a physical medium, and the storage block reserved for the next write is the reserved block. That is, the reserved block is a storage concept based on the physical medium.

[0038] The write area refers to the storage area where a data block of a file is written to the physical medium. Except for the first data block of the file, the rest generally refer to a block in the reserved block.

[0039] In step S102, when it is determined that the file to be written is written to the physical medium for the first time, the first data block of the file to be written is first written into a storage area of ​​the physical medium, and after writing, a first number of reserved blocks adjacent to the writing area are applied. In combination with the above concept, the adjacent here means that after writing the data block into a storage area of ​​the physical medium, a first number of reserved block addresses adjacent to the physical address of the writing area are applied. Then, when writing subsequently, writing is also performed according to the address of the reserved block.

[0040] S103, writing the remaining data blocks of the file to be written into the reserved blocks first, and replenishing the number of reserved blocks until the file to be written is completely written.

[0041] The second data block of the file to be written is written into the reserved block just applied for. Since one of the reserved blocks is used, the number of reserved blocks needs to be supplemented. This step is repeated until the file to be written is completely written.

[0042] The process of writing a file first needs to determine the target address and storage space (for example, the address of the reserved block obtained) corresponding to the file being written into the physical medium. In actual scenarios, this step can be exemplified by converting the write address length of the file into the address length of the physical medium through a file system process (usually also called an FS process) based on the data arrangement of the file in the current file system and the current free space in the physical medium. In this way, the target address and storage space corresponding to the file to be written into the physical medium are determined. This process is relatively general, so it will not be described in detail here.

[0043] In this embodiment, it is first determined whether the file to be written is being written to the physical medium for the first time. If the file to be written is being written for the first time, the first data block is written first, and after the first data block is written, a first number of reserved blocks adjacent to the writing area of ​​the first data block is applied for; the remaining data blocks of the file to be written are preferentially written into the reserved blocks, and the number of reserved blocks is supplemented until the file to be written is completely written. In this embodiment, the adjacent space of the writing area of ​​the first data block is reserved to form a reserved block, and subsequent data blocks are preferentially written into the reserved block, while the number of reserved blocks is always maintained at the first number until the file is completely written, so that the data is more concentrated on the medium and no longer fragmented. This solves the problem of discontinuous storage when the file blocks of the same file are stored in the physical medium, and improves the writing efficiency.

[0044] In addition, the solution proposed in this embodiment improves the writing efficiency by reducing the number of writing requests. Here, the storage process needs to be specifically introduced. First, Figure 2 The figure shows the logical location of files in the file system, including file 1 and file 2. File 1 includes four data blocks from 1-1 to 1-4; file 2 also includes four data blocks from 2-1 to 2-4. That is, the data arrangement of files in the current file system is basically in a certain logical order, but when writing to the medium, it is stored according to whether there is free storage space in the physical address, which is prone to disorder. For example Figure 3 , is the location where the file is stored in the physical medium, where "#" indicates that the address is occupied by other files. Because the logic of storing each data block in the physical medium is to store it in a free area, the order of file storage is disordered. Furthermore, if the data blocks to be stored are not adjacent (1-1 and 2-1 are adjacent, 1-1 and 1-2 are not adjacent), a write request needs to be sent each time a data block is stored; if Figure 3 For the same storage location, multiple write requests need to be sent, which increases the signaling overhead and greatly reduces the efficiency of writing files. However, the solution mentioned in the above embodiment can greatly solve the problem of non-adjacent stored data blocks by reserving blocks, thereby improving writing efficiency.

[0045] against Figure 3 , here is a little extra explanation. Storage on physical media is not exactly like this in reality. Figure 3 The 4x4 square grid shown in the figure has horizontal and vertical adjacencies, but in fact, the "adjacent reserved blocks" proposed in this embodiment are based on physical addresses, that is, Figure 3 It is only a schematic diagram of the physical address of the file data in the medium. In reality, there is no horizontal or vertical contiguity. When obtaining adjacent reserved blocks, the adjacent area is searched based on the physical address.

[0046] Optionally, the remaining data blocks of the file to be written are preferentially written into the reserved blocks, and the number of reserved blocks is supplemented until the file to be written is completely written, including: when writing the remaining data blocks of the file to be written, they are written into the reserved blocks, and a second number of reserved blocks adjacent to the area where the data blocks are written this time are applied again, so that the total number of reserved blocks is maintained at the first number until the file to be written is completely written; wherein the first number and the second number are positive integers, and the second number is less than the first number.

[0047] In this embodiment, how to supplement the number of reserved blocks is described. When writing other data blocks of the file to be written, the reserved blocks just applied for are written first, and after writing, the second number of reserved blocks are applied for again, so that the total number of reserved blocks is maintained at the first number until the file is completely written. By means of reserved blocks, the problem of non-adjacent stored data blocks can be solved in most cases, and the writing efficiency can be improved.

[0048] Optionally, when writing the remaining data blocks of the file to be written, they are written into the reserved blocks, and a second number of reserved blocks adjacent to the writing area of ​​the current data blocks are applied for again, so that the total number of reserved blocks is maintained at the first number until all the data blocks of the file to be written are written, including: writing the second data block of the file to be written into the reserved blocks; after writing the second data block, applying for a second number of reserved blocks adjacent to the writing area of ​​the second data block, so that the total number of current reserved blocks is the first number, until all the data blocks of the file to be written are written to the physical medium.

[0049] In this embodiment, taking file 1 as an example, the first number is 2 blocks, and the second number is 1 block. After the data block 1-1 is written for the first time, 2 reserved blocks will be applied for the next writing; when the file 1-2 is written to the next time and one reserved block is used up, another reserved block will be applied, so that the number of reserved blocks is always maintained at two. It should be noted that the first number and the second number are only examples, and more than one data block can be written at a time. By means of reserved blocks, the problem of non-adjacent stored data blocks can be greatly solved, thereby improving writing efficiency.

[0050] Optionally, the remaining data blocks of the file to be written are preferentially written into the reserved blocks, and the number of the reserved blocks is supplemented until the file to be written is completely written, and the method further includes: after all the data blocks of the file to be written are completely written into the physical medium, the reserved blocks are released.

[0051] In this embodiment, after all the data blocks of the file to be written are written, some reserved blocks are actually occupied. It seems that more space resources are occupied by the reserved blocks, but in fact, the reserved blocks are for each file. That is to say, when the file 1 is written to the physical medium, the space of the reserved blocks corresponding to the file 1 will be released. Therefore, the problem of non-adjacent stored data blocks is solved without occupying space resources.

[0052] Optionally, after all data blocks of the file to be written are written to the physical medium, the reserved blocks are released, including: releasing the reserved blocks of the file to be written this time through memory update processing; the memory update processing includes power off processing, restart processing and update processing by receiving user instructions.

[0053] In this embodiment, the release method may include restart processing, power-off processing, and receiving user's memory refresh processing. In fact, in actual use, after writing file 1, file 2 will also be written. Therefore, before writing file 2, it will be judged whether file 1 has been written. If so, the space of the reserved block applied for file 1 will be released, and no space resources will be occupied.

[0054] Optionally, the above-mentioned file writing method also includes: when the file to be written is not written for the first time, searching for the number of free blocks in the physical medium when the file to be written was last written; according to the previous number of free blocks, searching for a free area in the physical medium that is consistent with the previous number of free blocks; and writing the file to be written into the free area.

[0055] In this embodiment, if the file to be written is not written for the first time, it can be written by finding the number of free blocks occupied when the file was last written. The free blocks here refer to the free areas in the physical medium. For the convenience of understanding, the concept of "block" is used for explanation. A block is a free area divided according to a fixed memory size. This can also solve the problem of non-adjacent stored data blocks.

[0056] Optionally, the application process of the reserved block includes: after the data block is written, sending an application instruction for a storage area adjacent to the physical address of the write area; obtaining the physical address of the adjacent storage area, and using the adjacent storage area as a reserved block; the physical address is used to indicate that the data block is written to the physical medium.

[0057] In this embodiment, the term "adjacent" here means that after writing a data block to a storage area of ​​a physical medium, a first number of reserved block addresses adjacent to the physical address of the write area are applied for, and subsequent writing is also performed according to the reserved block addresses.

[0058] Figure 4 A schematic diagram showing a flow chart of another file writing method provided in an embodiment of the present application is shown; Figure 5 is a schematic diagram of the location of file data stored in a physical medium after the file writing method provided by the embodiment of the present application is applied, wherein "#" indicates that the address is occupied by other files; Figure 4 and Figure 5 , the file writing method proposed in this embodiment is described. In this embodiment, the first number is set to 2 and the second number is set to 1. The method includes:

[0059] S201, determine whether the file to be written is written for the first time. If not, proceed to S2021; if so, proceed to S2022.

[0060] S2021, determine the number of free blocks required to store the file to be written, and write it.

[0061] Before writing the file to be written into the physical medium, it is necessary to determine whether the file is being written for the first time; if not, determine how much memory space is required for the file to be written (the number of free blocks required for storage can be determined by querying the previous storage record), and then search the physical medium for the corresponding number of free blocks for storage.

[0062] S2022, write the first data block of the file to be written into the physical medium, and apply for 2 blocks and a reserved block after the physical address of the write area of ​​the first data block.

[0063] Combination Figure 5 , when putting file 1 first, you need to put data block 1-1 of file 1 first. After writing 1-1, apply for two reserved blocks after the physical address of 1-1, that is, 1-2 and 1-3. At this moment, 1-2 and 1-3 have been marked as reserved blocks and can only be used to store data blocks of file 1.

[0064] S203, writing the next data block to be written into the file into one of the reserved blocks, and applying for another reserved block after the written reserved block.

[0065] Write 1-2 to the position of one of the two reserved blocks just applied for, and apply for another reserved block after 1-2 (since position 1-3 has been applied for, the applied position is 1-4). At this time, data blocks 1-1 and 1-2 have been written, and two reserved blocks are still maintained. Then write all data blocks 1-3 and 1-4.

[0066] S204, determine whether all the files to be written have been written. If yes, then end; if no, then execute S203.

[0067] By repeating S203, all data blocks 1-1 to 1-4 of file 1 are written to the physical medium. After it is determined that all the files to be written are written, the writing of file 1 is completed and it is necessary to write file 2. However, before writing file 2, the last two reserved blocks of file 1 are released.

[0068] Through the above method, the data of file 1 is stored in a continuous position in the physical medium, which solves the problem of discontinuous storage when the file blocks of the same file are stored in the physical medium. At the same time, since 1-1 to 1-4 are continuous in the physical medium, the number of writes can be reduced in the write request queue by merging write requests, thereby reducing interactions and improving write efficiency.

[0069] In the process of writing file 2, some special cases are also introduced. For example, after the data block 2-2 of file 2 is written, the area that should be used as the reserved block is occupied. In this case, two free positions 2-3 and 2-4 are selected as reserved blocks (the data blocks of 2-3 and 2-4 have not been put in at this moment). Then, when writing 2-3 and 2-4, two reserved blocks P1 and P2 are applied. That is, when storing file 2, due to the memory occupation, the data blocks of file 2 cannot be stored continuously, but the data blocks of file 2 are made continuous in the physical medium to the greatest extent, which can also solve the problem of discontinuous storage when the file blocks are stored in the physical medium, and improve the writing efficiency. After the writing of file 2 is completed, P1 and P2 will be released before manual refresh or the writing of the next file, which will not cause waste of resources.

[0070] Further, as Figures 1 to 5 The specific implementation of the method shown in the embodiment provides a file writing device, such as Figure 6 As shown, the device includes: a judgment unit 601, a first writing unit 602 and a second writing unit 603.

[0071] The judging unit 601 is configured to judge whether the file to be written is written for the first time; wherein the file to be written includes at least one data block;

[0072] The first writing unit 602 is configured to write the first data block of the file to be written into the physical medium when the file to be written is written for the first time, and apply for a first number of reserved blocks adjacent to the writing area of ​​the first data block after the first data block is written;

[0073] The second writing unit 603 is configured to preferentially write the remaining data blocks of the file to be written into the reserved blocks, and replenish the number of the reserved blocks until the file to be written is completely written.

[0074] In a specific application scenario, the second writing unit 603 is specifically configured to write into the reserved block when writing the remaining data blocks of the file to be written, and to apply again for a second number of reserved blocks adjacent to the current data block writing area, so that the total number of the reserved blocks is maintained at the first number until the file to be written is completely written; wherein the first number and the second number are positive integers, and the second number is less than the first number.

[0075] In a specific application scenario, the second writing unit 603 is further configured to write the second data block of the file to be written into the reserved block; after writing the second data block, apply for the second number of reserved blocks adjacent to the writing area of ​​the second data block, so that the total number of current reserved blocks is the first number, until all data blocks of the file to be written are written into the physical medium.

[0076] In a specific application scenario, the judgment unit 601 is further configured to release the reserved block after all data blocks of the file to be written are written into the physical medium.

[0077] In a specific application scenario, the judgment unit 601 is further configured to release the reserved block of the file to be written this time through memory update processing; the memory update processing includes power off processing, restart processing and update processing by receiving user instructions.

[0078] In a specific application scenario, the judgment unit 601 is further configured to search for the number of free blocks in the physical medium when the file to be written was last written when the file to be written is not written for the first time; search for a free area in the physical medium that is consistent with the number of free blocks last time according to the last number of free blocks; and write the file to be written into the free area.

[0079] In a specific application scenario, the first writing unit 602 is also specifically configured to send an application instruction for a storage area adjacent to the physical address of the writing area after the data block is written; obtain the physical address of the adjacent storage area, and use the adjacent storage area as the reserved block; the physical address is used to indicate that the data block is written to the physical medium.

[0080] It should be noted that for other corresponding descriptions of the functional units involved in the file writing device provided in this embodiment, reference can be made to Figures 1 to 5The corresponding description in will not be repeated here.

[0081] Based on the above Figures 1 to 5 The method shown in the embodiment also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the above-mentioned Figures 1 to 5 The method shown.

[0082] Based on this understanding, the technical solution of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, USB flash drive, mobile hard disk, etc.), including a number of instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to execute the methods of various implementation scenarios of the present application.

[0083] Based on the above Figures 1 to 5 The method shown, and Figure 6 In order to achieve the above-mentioned purpose, the embodiment of the present application further provides an electronic device, which can be configured on a computer side or a vehicle side, etc. The device includes a storage medium and a processor; the storage medium is used to store a computer program; the processor is used to execute the computer program to achieve the above-mentioned Figures 1 to 5 The method shown.

[0084] Optionally, the above-mentioned physical device may also include a user interface, a network interface, a camera, a radio frequency (RF) circuit, a sensor, an audio circuit, a WI-FI module, etc. The user interface may include a display, an input unit such as a keyboard, etc., and the optional user interface may also include a USB interface, a card reader interface, etc. The network interface may optionally include a standard wired interface, a wireless interface (such as a WI-FI interface), etc.

[0085] Those skilled in the art will appreciate that the above-mentioned physical device structure provided in this embodiment does not constitute a limitation on the physical device, and may include more or fewer components, or a combination of certain components, or different arrangements of components.

[0086] The storage medium may also include an operating system and a network communication module. The operating system is a program that manages the hardware and software resources of the above-mentioned physical device, and supports the operation of the information processing program and other software and / or programs. The network communication module is used to realize the communication between the components inside the storage medium, and the communication with other hardware and software in the information processing physical device.

[0087] Through the description of the above implementation methods, those skilled in the art can clearly understand that the present application can be implemented by means of software plus necessary general hardware platforms, or by hardware. Compared with the related art, the embodiment of the present application reserves the adjacent space of the writing area of ​​the first data block to form a reserved block, and writes the subsequent data blocks into the reserved block first, while keeping the number of reserved blocks at the first number until all the files are written, so that the data is more aggregated on the medium and no longer fragmented. The problem of discontinuous storage when the file blocks of the same file are stored in the physical medium is solved, and the writing efficiency is improved.

[0088] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the term "comprises" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.

[0089] The above is only a specific implementation of the present application, so that those skilled in the art can understand or implement the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments described herein, but will conform to the widest scope consistent with the principles and novel features applied for herein.

Claims

1. A file writing method, characterized in that: include: Determine whether the file to be written is written for the first time; wherein the file to be written includes at least one data block; When the file to be written is written for the first time, writing the first data block of the file to be written to the physical medium, and after the first data block is written, applying for a first number of reserved blocks adjacent to the writing area of ​​the first data block; The remaining data blocks of the file to be written are preferentially written into the reserved blocks, and the number of the reserved blocks is supplemented until the file to be written is completely written.

2. The method according to claim 1, characterized in that The step of preferentially writing the remaining data blocks of the file to be written into the reserved blocks and supplementing the number of the reserved blocks until all the file to be written is written comprises: When writing the remaining data blocks of the file to be written, write them into the reserved blocks, and apply again for a second number of reserved blocks adjacent to the area where the data blocks are written this time, so that the total number of the reserved blocks remains at the first number until the file to be written is completely written; The first number and the second number are positive integers, and the second number is smaller than the first number.

3. The method according to claim 2, characterized in that When writing the remaining data blocks of the file to be written, writing them into the reserved blocks, and applying again for a second number of reserved blocks adjacent to the current data block writing area, so that the total number of the reserved blocks is maintained at the first number, until the file to be written is completely written, comprising: Writing the second data block of the file to be written into the reserved block; After writing the second data block, apply for the second number of reserved blocks adjacent to the writing area of ​​the second data block, so that the total number of current reserved blocks is the first number, until all data blocks of the file to be written are written to the physical medium.

4. The method according to claim 1, characterized in that: The remaining data blocks of the file to be written are preferentially written into the reserved blocks, and the number of the reserved blocks is supplemented until the file to be written is completely written, further comprising: After all the data blocks of the file to be written are written into the physical medium, the reserved blocks are released.

5. The method according to claim 4, characterized in that After all the data blocks of the file to be written are written into the physical medium, releasing the reserved block includes: By means of memory update processing, the reserved block of the file to be written this time is released; The memory update process includes a power-off process, a restart process, and an update process by receiving a user instruction.

6. The method according to claim 1, characterized in that After determining whether the file to be written is being written for the first time, the method further includes: If the file to be written is not written for the first time, searching for the number of free blocks in the physical medium where the file to be written was last written; According to the previous number of free blocks, searching the physical medium for a free area having a number consistent with the previous number of free blocks; The file to be written is written into the free area.

7. The method according to any one of claims 1 to 6, characterized in that The application process of the reserved block includes: After the data block is written, a request instruction for a storage area adjacent to the physical address of the write area is sent; The physical address of the adjacent storage area is obtained, and the adjacent storage area is used as the reserved block; the physical address is used to indicate that the data block is written into the physical medium.

8. A file writing device, characterized in that: include: A judging unit configured to judge whether the file to be written is written for the first time; wherein the file to be written includes at least one data block; A first writing unit is configured to, when the file to be written is written for the first time, write a first data block of the file to be written into a physical medium, and after the first data block is written, apply for a first number of reserved blocks adjacent to a writing area of ​​the first data block; The second writing unit is configured to preferentially write the remaining data blocks of the file to be written into the reserved blocks, and to supplement the number of the reserved blocks until the file to be written is completely written.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.

10. An electronic device comprising a storage medium, a processor, and a computer program stored in the storage medium and executable on the processor, characterized in that: When the processor executes the computer program, the method according to any one of claims 1 to 7 is implemented.