[go: up one dir, main page]

JP2008059228A - File system - Google Patents

File system Download PDF

Info

Publication number
JP2008059228A
JP2008059228A JP2006234738A JP2006234738A JP2008059228A JP 2008059228 A JP2008059228 A JP 2008059228A JP 2006234738 A JP2006234738 A JP 2006234738A JP 2006234738 A JP2006234738 A JP 2006234738A JP 2008059228 A JP2008059228 A JP 2008059228A
Authority
JP
Japan
Prior art keywords
file
block
blocks
writing
information
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
JP2006234738A
Other languages
Japanese (ja)
Inventor
Keiji Fukumoto
圭司 福本
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.)
Sharp Corp
Original Assignee
Sharp Corp
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 Sharp Corp filed Critical Sharp Corp
Priority to JP2006234738A priority Critical patent/JP2008059228A/en
Priority to US12/439,429 priority patent/US20090265403A1/en
Priority to CN200780038992.5A priority patent/CN101529395B/en
Priority to PCT/JP2007/066113 priority patent/WO2008026466A1/en
Publication of JP2008059228A publication Critical patent/JP2008059228A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

【課題】初期化処理を高速に行えるファイルシステムを提供する。
【解決手段】フラッシュメモリ上のファイルシステムであって、ファイルに付与されるファイルシステムで一意のファイルIDと、ファイル内のブロックの接続の順番を示すブロック番号と、を含むブロック情報を、ブロックに対して付加するブロック情報付加手段と、ブロック情報に基づいてファイル構成を表すファイル構成情報を再構築するファイル構成情報再構築手段とを有する。
【選択図】図7
A file system capable of performing initialization processing at high speed is provided.
A file system on a flash memory, block information including a file ID unique to the file system assigned to the file and a block number indicating the connection order of the blocks in the file is stored in the block. Block information adding means for adding the file structure information, and file structure information reconstructing means for reconstructing the file structure information representing the file structure based on the block information.
[Selection] Figure 7

Description

本発明は、ファイルシステムの技術に関し、特に、NAND型フラッシュメモリのファイルシステムの技術に関する。   The present invention relates to a file system technique, and more particularly to a NAND flash memory file system technique.

近年、情報機器の発達により、その情報記録媒体として、フラッシュメモリが注目されている。その理由として、小型化が可能になること、駆動装置が不要なため信頼性が増すことなどがあげられる。特に、大容量化が容易なNAND型フラッシュメモリが、情報記録媒体として急速に広がりつつある。NAND型フラッシュメモリは、フラッシュメモリの一種であり、高速な消去と書き込みができることが特徴である。   In recent years, with the development of information equipment, flash memory has attracted attention as an information recording medium. The reason is that it is possible to reduce the size, and the reliability is increased because the driving device is unnecessary. In particular, NAND flash memories that can be easily increased in capacity are rapidly spreading as information recording media. A NAND flash memory is a kind of flash memory, and is characterized by high-speed erasing and writing.

一般に、フラッシュメモリへ書き込みを行うには、書き込みに先立って消去を行っておく必要がある。NAND型フラッシュメモリは、複数のブロックから構成され、ブロックは複数のページから構成される。消去はブロック単位で行われ、書き込みはページ単位で行われる。また、ページはデータを格納する部分と、エラー訂正符号などの冗長データを格納する部分に分けて使用されるのが一般的である。   In general, in order to write to a flash memory, it is necessary to erase before writing. The NAND flash memory is composed of a plurality of blocks, and the blocks are composed of a plurality of pages. Erasing is performed in units of blocks, and writing is performed in units of pages. In general, a page is divided into a part for storing data and a part for storing redundant data such as an error correction code.

図22は、磁気記憶装置のファイルシステムのイメージを示す図である。磁気記憶装置では、物理的な読み書きはセクタ単位である。また、論理的な読み書き単位はクラスタ単位(セクタを複数まとめたものをクラスタとする)である。   FIG. 22 is a diagram showing an image of the file system of the magnetic storage device. In the magnetic storage device, physical read / write is performed in units of sectors. The logical read / write unit is a cluster unit (a cluster of a plurality of sectors).

クラスタは、システム領域とデータ領域とにわけられ、ファイルはデータ領域に割り当てられた複数のクラスタに分割されて保存される。ファイルに割り当てられたクラスタの情報やファイル自身の情報(ファイル構成情報)はシステム領域に保存される。そのため、ファイルの更新が行われると、この領域も書き換えられる。どのクラスタが使用中で、どのクラスタが空いているかという情報も、システム領域に保存される。そのため、ファイルの更新が行われると、この領域も書き換えられる。   A cluster is divided into a system area and a data area, and a file is divided into a plurality of clusters assigned to the data area and stored. Information on the cluster assigned to the file and information on the file itself (file configuration information) are stored in the system area. Therefore, when the file is updated, this area is also rewritten. Information about which clusters are in use and which are free is also stored in the system area. Therefore, when the file is updated, this area is also rewritten.

しかしながら、フラッシュメモリはその電気的特性上、データの消去と書き込みに回数制限があり、書き込み回数に実質制限がない磁気記憶装置に対するファイルシステムの手法をそのまま適用することはできない。なぜなら、書き込み回数に制限がない手法では、たとえば、FAT(File Allocation Table)に代表されるようなファイル構成情報が、記憶装置のある特定の場所に格納されており、ファイルの書き込み等により構成情報が変更されると、この場所の内容もそれにしたがって更新されるようになっている。すなわち、ファイルの書き込みを行うと、実際にファイルを書き込んだ場所だけでなく、ファイル構成情報も書き換えられる。   However, because of the electrical characteristics of flash memory, there are limits on the number of times data can be erased and written, and it is not possible to apply the file system method for a magnetic storage device that has no substantial limit on the number of times of writing. This is because the file configuration information represented by, for example, FAT (File Allocation Table) is stored in a specific location in the storage device, and the configuration information is written by writing the file or the like. If is changed, the contents of this location will be updated accordingly. That is, when a file is written, not only the location where the file is actually written but also the file configuration information is rewritten.

図23は、フラッシュメモリのファイルシステムのイメージを示す図である。フラッシュメモリでは、物理的な消去はブロック単位、書き込みはページ単位である。論理的な読み書き単位はブロック単位(ブロックは複数のページから構成されている)であり、ブロックはすべてデータ領域として使用する。ファイルは複数のブロックに分割されて保存される。このとき、ブロックの先頭にヘッダ情報を付加して保存する。ファイルに割り当てられたブロックの情報やファイル自身の情報(ファイル構成情報)はフラッシュメモリには保存されないようになっている。すなわち、ブロックのヘッダ情報を解析することでファイルシステムの初期化時に再構成可能であり、その情報自体は利用する電子機器のRAMなど別のメモリに記憶しておくことになる。また、どのブロックが使用中で、どのブロックが空いている(再利用可能なブロックか)というブロック利用情報も、フラッシュメモリには保存されない。その代わりに、ブロックのヘッダ情報を解析することでファイルシステムの初期化時に検出可能であり、その情報自体はRAMに記憶しておくことになる。   FIG. 23 is a diagram showing an image of the file system of the flash memory. In the flash memory, physical erasure is in units of blocks and writing is in units of pages. The logical read / write unit is a block unit (a block is composed of a plurality of pages), and all the blocks are used as a data area. The file is divided into a plurality of blocks and stored. At this time, header information is added to the head of the block and saved. Block information assigned to the file and information of the file itself (file configuration information) are not stored in the flash memory. In other words, by analyzing the header information of the block, it can be reconfigured when the file system is initialized, and the information itself is stored in another memory such as a RAM of the electronic device to be used. Also, block usage information indicating which blocks are in use and which blocks are free (reusable blocks) is not stored in the flash memory. Instead, it can be detected at the time of initialization of the file system by analyzing the header information of the block, and the information itself is stored in the RAM.

なぜなら、磁気記憶装置と同様のファイルシステムの手法をフラッシュメモリに適用すると、特定のブロックだけ頻繁に書き換えがおこるため、そのブロックはすぐに書き込み回数の制限を越えて使用不能となり、結果として、フラッシュメモリ全体が利用できなくなるからである。   This is because when a file system method similar to that of a magnetic storage device is applied to flash memory, only a specific block is frequently rewritten, so that the block immediately exceeds the limit of the number of writes and becomes unusable. This is because the entire memory becomes unavailable.

このような問題を回避するために、Linux OS(Operating System)ではjffs2(Journaling FlashFile System version 2)と呼ばれるファイルシステムが米レッドハット社により開発されている。これは、データの書き込みが、特定のブロックにかたよらないようにすることで、フラッシュメモリの書き込み回数の制限を領域全体に分散化させ、フラッシュメモリ全体の長寿命化を図ることを目的としている。   In order to avoid such a problem, a file system called jffs2 (Journaling FlashFile System version 2) has been developed by Red Hat Corporation in the Linux OS (Operating System). This is intended to extend the life of the entire flash memory by distributing the restriction on the number of times of writing to the flash memory over the entire area by preventing data writing from depending on a specific block.

http://sources.redhat.com/jffs2/http: // sources. redhat. com / jffs2 /

しかしながら、上記jffs2は、その初期化処理において、ファイルの整合性チェックと空き領域のチェックのために、ファイルの書き込まれた領域をスキャンし、書き込まれたデータを解析する必要があり、この処理に時間がかかる。特に、ファイルが多数存在する場合、ファイルの書き込み時に装置の電源断があった場合には、その影響が顕著に現れるという問題がある。   However, in the initialization process, the jffs2 needs to scan the written area of the file and analyze the written data for the file consistency check and the free area check. take time. In particular, when there are a large number of files, there is a problem that the influence appears remarkably when the power of the apparatus is interrupted when the file is written.

例えば、家庭用電子機器(液晶テレビ、レコーダなど)のように、電源投入操作後、できるだけ早く利用者にその操作に対するリアクションをフィードバックさせる必要のある場合には、不向きである。   For example, it is not suitable when it is necessary for the user to feed back the reaction to the operation as soon as possible after the power-on operation, such as a home electronic device (liquid crystal television, recorder, etc.).

本発明の目的は、初期化処理を高速に行えるファイルシステムを提供することである。   An object of the present invention is to provide a file system capable of performing initialization processing at high speed.

本発明の一観点によれば、メモリ領域が複数のブロックに分割されており、メモリ領域に書き込まれたデータの消去をブロック単位で行い、ブロックが複数のページに分割されており、メモリ領域へのデータの書き込みはページ単位で行うフラッシュメモリ上のファイルシステムであって、少なくとも、ファイルに付与されるファイルシステムで一意のファイルIDと、ファイル内のブロックの接続の順番を示すブロック番号と、を含むブロック情報を、ブロックに対して付加するブロック情報付加手段と、前記ブロック情報に基づいてファイル構成を表すファイル構成情報を再構築するファイル構成情報再構築手段と、を有することを特徴とするファイルシステムが提供される。上記ブロック情報に基づいて、正しくファイルを再構成することができる。   According to one aspect of the present invention, a memory area is divided into a plurality of blocks, data written in the memory area is erased in units of blocks, and the blocks are divided into a plurality of pages. The writing of the data is a file system on the flash memory that is performed in units of pages, and at least a file ID that is unique to the file system assigned to the file and a block number that indicates the connection order of the blocks in the file. A file comprising block information adding means for adding block information to a block, and file structure information reconstructing means for reconstructing file structure information representing a file structure based on the block information A system is provided. Based on the block information, the file can be correctly reconstructed.

ブロックへのデータの書き込み時に各ブロックの先頭ページと先頭以外のページにマジックナンバーを付加するマジックナンバー付加手段と、先頭ページから順番にデータを書き込んでいきページにデータを書き込むたびにデータのベリファイを行うページベリファイ手段と、各ブロックの先頭ページと先頭以外のページにマジックナンバーが付加されているか否かに基づいてブロックの有効性のチェックするブロックチェック手段と、を有するようにしても良い。   Magic number adding means to add magic numbers to the first page and non-first page of each block when data is written to the block, and data is written in order from the first page and verified each time data is written to the page. You may make it have the page verification means to perform, and the block check means which checks the validity of a block based on whether the magic number is added to the head page of each block, and a page other than the head.

ブロックに前記マジックナンバーを書き込むための少なくとも第1及び第2のマジックナンバー領域を、データを書き込むためのデータ領域を挟んで設けても良い。前記第1のマジックナンバー領域よりも前の部分にブロック情報を書き込む領域を設けるようにしても良い。   At least first and second magic number areas for writing the magic number in the block may be provided across a data area for writing data. An area for writing block information may be provided in a portion before the first magic number area.

本発明の他の観点によれば、上記ファイルシステムを用いたファイル構成情報の再構築方法であって、ブロックを取り出し、有効なブロックの前記ブロック情報を読み出すステップと、前記ブロック情報内のファイルIDの異同に基づいて、同じファイルIDを有するブロックを前記ブロック番号の順番につなげるステップと、を有することを特徴とするファイル構成情報の再構築方法が提供される。また、上記ファイルシステムを用いたブロックの有効性判定方法であって、前記第1及び第2のマジックナンバーを読み込み、読み込んだ内容に基づいて、マジックナンバーの有効・無効によりブロックにおけるデータの有効性を判定するステップを有することを特徴とするブロックの有効性判定方法が提供される。   According to another aspect of the present invention, there is provided a method for reconstructing file configuration information using the above file system, the step of taking out a block and reading out the block information of a valid block, and a file ID in the block information And a step of linking blocks having the same file ID in the order of the block numbers based on the difference between the file numbers. A method for determining the validity of a block using the file system, wherein the first and second magic numbers are read, and the validity of the data in the block is determined by the validity / invalidity of the magic number based on the read contents. A method for determining the validity of a block is provided.

本発明によれば、初期化処理等を高速に行えるファイルシステムを提供できる。   According to the present invention, a file system capable of performing initialization processing and the like at high speed can be provided.

以下に、本発明の実施の形態によるフラッシュメモリのファイルシステムについて図面を参照しながら説明を行う。図1は、本発明の第1の実施の形態によるファイルシステムを適用可能な機器の一例として示す電子機器の一構成例を示す機能ブロック図である。図1に示すように、本実施の形態による電子機器Aは、全体を制御する制御装置(CPU)1と、機器を制御するためのプログラムやデータファイルなどを格納する不揮発性のフラッシュメモリ3と、RAMなどの揮発性のメモリ5と、データの入出力が行われるデータ入出力手段15と、ユーザが入力を行う入力手段7と、入力されたデータが処理されて出力されるその出力に基づく情報を表示する表示手段11と、を有している。   Hereinafter, a file system of a flash memory according to an embodiment of the present invention will be described with reference to the drawings. FIG. 1 is a functional block diagram showing a configuration example of an electronic device shown as an example of a device to which the file system according to the first embodiment of the present invention can be applied. As shown in FIG. 1, an electronic device A according to the present embodiment includes a control device (CPU) 1 that controls the whole, a non-volatile flash memory 3 that stores programs and data files for controlling the device, and the like. A volatile memory 5 such as a RAM, a data input / output means 15 for inputting / outputting data, an input means 7 for inputting by a user, and an output obtained by processing input data Display means 11 for displaying information.

上記電子機器におけるファイルシステムでは、ファイルがフラッシュメモリの領域のどこを使用しているかというファイル構成情報を、フラッシュメモリの特定の領域に記憶するのではなく、マウント処理(ファイルシステムの初期化処理)時にファイル構成情報をメモリ5上に再構成するようにするものであり、これをNAND型フラッシュメモリに適用する場合の実施例について以下に詳細に説明する。図2は、NAND型フラッシュメモリの領域構成例を示す図である。図2に示すように、ファイルXは、一つ以上のブロックYからなり、ブロックYは、ページZから構成されている。このように、NAND型フラッシュメモリは、複数のブロックからなり、また、ブロックは複数のページからなる。図3は、ブロック情報のバリエーションを示す図である。例えば、ファイルXがブロックA、B、C(Y)から構成されるとして、データ23に付加されるブロック情報25・27・31・33は、図3(A)のように各ブロックA、B、Cで同じものを保持しておいても、図3(B)に示すようにブロックによって異なるものを保持しておいてもよい。図3(B)の場合では、ファイルを構成する先頭ブロック(ブロックA’:矢印の一番元に存在するブロック、矢印はアクセス順を示す)にのみ、ファイル名とファイルサイズとからなるブロック情報21を持つようになっている。   In the file system in the electronic device, the file configuration information indicating where the file is used in the flash memory area is not stored in a specific area of the flash memory, but mounted (file system initialization process). In some cases, the file configuration information is reconfigured on the memory 5 and applied to a NAND flash memory. FIG. 2 is a diagram showing an example of the area configuration of the NAND flash memory. As shown in FIG. 2, the file X is composed of one or more blocks Y, and the blocks Y are composed of pages Z. Thus, the NAND flash memory is composed of a plurality of blocks, and the block is composed of a plurality of pages. FIG. 3 is a diagram illustrating variations of block information. For example, assuming that the file X is composed of blocks A, B, and C (Y), the block information 25, 27, 31, and 33 added to the data 23 are the blocks A, B as shown in FIG. , C may hold the same one, or may hold different ones depending on the block as shown in FIG. In the case of FIG. 3B, block information including the file name and file size only in the first block constituting the file (block A ′: the block existing at the beginning of the arrow, the arrow indicates the access order). 21 to have.

データの書き込みの際には、それに先立ち消去を行う必要がある。消去はブロック単位で行われ、書き込みはページ単位で行われる。また、ページは、通常のデータを書き込むデータ領域と、冗長データを書き込むOOB(Out Of Band)領域にわけられるのが一般的である。OOB領域には、データ領域に書かれたデータの誤りを訂正する誤り訂正符号を格納する領域と、そのブロックがバッドブロックであるかどうかを示す領域などを有している。   When writing data, it is necessary to erase it before that. Erasing is performed in units of blocks, and writing is performed in units of pages. Further, the page is generally divided into a data area for writing normal data and an OOB (Out Of Band) area for writing redundant data. The OOB area includes an area for storing an error correction code for correcting an error in data written in the data area, an area indicating whether or not the block is a bad block, and the like.

これは、NAND型フラッシュメモリの特性上、書き込み時に誤ったデータを書いてしまうことがあり、このままでは、次にそれを読み出した場合、誤ったデータが読み出されてしまうため、その誤りを訂正するための訂正符号を格納する領域が備わっているためである。訂正符号だけでは訂正しきれない程度の誤りが発生する場合には、それが発生するページを含むブロックをバッドブロックとして扱う。バッドブロックは、その先頭ページのOOB領域でバッドブロックであることが記されている。バッドブロックは、製造工程によって最初からバッドブロックになっているものと、消去と書き込みを繰り返すことで劣化が進み、後天的にバッドブロックになるものがある。   This is because, due to the characteristics of NAND flash memory, incorrect data may be written at the time of writing, and if it is read as it is, the incorrect data will be read out next time, so the error is corrected. This is because there is an area for storing a correction code. When an error that cannot be corrected with just the correction code occurs, the block including the page in which the error occurs is treated as a bad block. The bad block is marked as a bad block in the OOB area of the first page. Some bad blocks are initially bad blocks depending on the manufacturing process, and some bad blocks are deteriorated by repeating erasing and writing, and later become bad blocks.

以下に、本明細書において使用される用語についての定義を示す。
1)フリーブロック:消去済みのブロック。この状態でデータの書き込みが行えるブロックである。
2)妥当ブロック:本ファイルシステムにより書き込まれたデータを保持しているブロック。ファイルを構成するブロックと成りえる。
3)無効ブロック:フリーブロックでも妥当ブロックでもないブロック。消去が必要なブロックである。ブロックへの書き込み中に電源断されたか、もしくは、本ファイルシステムにおいて、消去が必要と判断して明示的に無効ブロックとしたかのいずれかである。
4)バッドブロック:物理的に使用不可能なブロックである。出荷時から存在する初期バッドブロックと、書き込みを繰り返しているうちに発生する後天的なバッドブロックがある。いずれも、OOBのある部分にその情報がマークされており、正常なブロックとの判別は可能である。なお、上記3つのブロックは正常なブロックに関してのことである。
5)フリーブロックリスト:フリーブロックを格納しているリストであり、RAM上に存在するリストである。
6)チェックブロックリスト:妥当ブロックを格納しているリストであり、RAM上に存在するリストである。
7)イレースブロックリスト:無効ブロック、および、妥当ブロックの中でも消去可能なブロックを格納しているリストであり、RAM上に存在するリストである。
8)バッドブロックリスト:バッドブロックを格納しているリストであり、RAM上に存在するリストである。
9)妥当ファイル/妥当ファイル候補:必要十分な妥当ブロックから構成され、本ファイルシステムのデータ構造に従ったファイルと判断されるファイルである。同名のファイルも存在する。妥当ファイル候補は、ブロックは揃っているが一部データが不足している可能性があるファイルである。妥当ファイルは妥当ファイル候補のサブセットとなる。
10)不完全ファイル:本ファイルシステムのデータ構造に従っていない異常なファイルと判断されるファイルである。構成ブロックが不足しているファイル、必要なデータが書き込まれていないファイルなどが該当する。
11)有効ファイル:妥当ファイルの一つであり、妥当ファイルの中に同名のファイルが存在する場合、最後に正常に書き込まれたファイルを指す。同名のファイルが存在しない場合は、そのファイル自身である。ただし、「消去を示すファイル」ではないものとする。
12)無効ファイル:妥当ファイルのうちでも、有効ファイルではないファイルである。これより新しい同名のファイルが存在しているか、もしくは「消去を示すファイル」である。
13)ファイルID:ファイルの書き込み時にファイルに付与される、本ファイルシステム内でユニークなIDである。再利用されない。例えば、次に付与するファイルID = 過去に付与した最大ファイルID + 1などとする。
14)ブロックID:ブロックを識別するための通し番号。
15)ブロック番号:ファイル内のブロックの通し番号。
次に、マウント処理について図面を参照しながら説明する。
The definitions of terms used in the present specification are shown below.
1) Free block: An erased block. In this state, the data can be written.
2) Valid block: A block holding data written by this file system. It can be a block that constitutes a file.
3) Invalid block: A block that is neither a free block nor a valid block. It is a block that needs to be erased. Either the power was cut off during writing to the block, or in this file system, it was determined that erasure was necessary and the block was explicitly invalidated.
4) Bad block: This block is physically unusable. There is an initial bad block that exists from the time of shipment, and an acquired bad block that occurs while writing is repeated. In any case, the information is marked in a portion where the OOB is present, so that it can be distinguished from a normal block. The above three blocks relate to normal blocks.
5) Free block list: a list storing free blocks, which is a list existing on the RAM.
6) Check block list: A list that stores valid blocks and is a list that exists on the RAM.
7) Erase block list: a list that stores invalid blocks and erasable blocks among valid blocks, and is a list that exists on the RAM.
8) Bad block list: A list storing bad blocks, which is a list existing in the RAM.
9) Valid file / Valid file candidate: A file that is composed of necessary and sufficient valid blocks and is determined to be a file according to the data structure of the file system. There is also a file with the same name. A valid file candidate is a file that has blocks but may have some data missing. Valid files are a subset of valid file candidates.
10) Incomplete file: A file that is determined to be an abnormal file that does not conform to the data structure of this file system. This includes files with missing building blocks, files that do not contain necessary data, and so on.
11) Valid file: One of valid files. When a file with the same name exists in a valid file, it indicates the file that was normally written last. If a file with the same name does not exist, it is the file itself. However, it is not a “file indicating deletion”.
12) Invalid file: A file that is not a valid file among valid files. There is a newer file with the same name, or “file indicating deletion”.
13) File ID: A unique ID in the file system assigned to the file when the file is written. Not reused. For example, the file ID to be assigned next = the maximum file ID assigned in the past + 1.
14) Block ID: A serial number for identifying a block.
15) Block number: A serial number of a block in the file.
Next, the mounting process will be described with reference to the drawings.

本実施の形態によるファイルシステムは、ファイル構成情報を特定のブロックに記録せず、各ブロックに対して、ブロック情報付加手段によりブロック情報を付加し、このブロック情報を記録しておくことで、マウント時にブロック情報からファイル構成情報再構築手段によりファイル構成情報を構築することを特徴とする。すなわち、マウント処理において、すべての有効なブロックのブロック情報を読み込み、同一のファイルIDを持つブロックを集める。そして、正しくファイルが再構成できるブロックから、ファイル構成情報を生成する。   The file system according to the present embodiment does not record file configuration information in a specific block, but adds block information to each block by block information adding means, and records this block information to mount the block. The file structure information is sometimes constructed from the block information by the file structure information reconstruction means. That is, in the mount process, block information of all valid blocks is read, and blocks having the same file ID are collected. Then, file configuration information is generated from a block in which the file can be correctly reconstructed.

尚、ブロック情報付加手段は、ブロックへの書き込みデータの生成時に、該当するブロックに対してブロックに関する情報を付加する手段であり、一般的にはプログラムにより制御装置が行うのが一般的だが、専用のハードウエアにより付加するようにしても良い。図3に示すブロックの構成例では、既にブロック情報が付加された後の状態が示されている。   The block information adding means is means for adding information related to the block to the corresponding block at the time of generating the write data to the block. The hardware may be added. The block configuration example shown in FIG. 3 shows a state after block information has already been added.

ファイル構成情報再構築手段は、マウント時に、上記ブロック情報に基づいてファイル構成情報を再構成する手段であり、一般的にはプログラムにより制御装置が行うことになるが、専用のハードウエアにより再構成するようにしても良い。図7に示すフローチャートでは、ブロックを取り出してから再構成が終了するまでのプログラムが示されている。この処理がファイル再構成手段による処理に相当する。   The file configuration information reconstruction means is means for reconstructing the file configuration information based on the block information at the time of mounting, and is generally performed by a control device by a program, but is reconfigured by dedicated hardware. You may make it do. The flowchart shown in FIG. 7 shows a program from the extraction of a block to the end of reconstruction. This process corresponds to the process by the file reconstruction unit.

ファイルIDは、ファイルID付与手段により、付与される。ファイルID付与手段は、ファイル書き込み時に、ファイルを識別するためのシステム内でユニークなファイルIDを付与する手段である。なお、ファイルIDは、ブロック情報付加手段により、ブロック情報の一つとして、ブロックに書き込まれる。   The file ID is assigned by file ID assigning means. The file ID assigning means is a means for assigning a unique file ID in the system for identifying the file when writing the file. The file ID is written into the block as one piece of block information by the block information adding means.

マウントの第一段階では、領域内の全てのブロックをスキャンし、フリーブロック、妥当ブロック、無効ブロック、バッドブロックを判断して、それぞれのリストにブロックをつなぐ。   In the first stage of mounting, all blocks in the area are scanned, free blocks, valid blocks, invalid blocks, and bad blocks are determined, and the blocks are connected to the respective lists.

より具体的には、各ブロックの先頭ページのOOB領域にバッドブロックであることが記録されているか、記録されていない場合、ブロックに所定のマジックナンバーが書き込まれているかどうかで判断する。マジックナンバーが書き込まれるのはデータ領域でもOOB領域でもどちらでもよいが、ブロックがバッドブロックであるかどうかを判断するためにはOOB領域を読み込む必要があるため、マジックナンバーもOOB領域に書き込んでおけば同時に判断でき処理が簡単になる。したがって、各ブロックの先頭ページと最終使用ページのOOB領域にマジックナンバーが書かれているかどうかで判断する。ブロックチェック手段は、ブロックの有効性を判断するために、このような判断を行う手段であり、一般的にはプログラムにより制御装置が行うことになるが、専用のハードウエアによってチェックするようにしてもよい。このような判断を行えるようにするために、ブロックへのデータの書き込みを行う際に、マジックナンバー付加手段により、マジックナンバーとそのブロックの使用ページ数がOOB領域に書き込まれる。マジックナンバー付加手段は、一般的にはプログラムにより制御装置が行うことになるが、専用のハードウエアにより付加するようにしてもよい。また、消去済みのブロックは、通常、ビットが全て1となる(マジックナンバーとしては、それが16ビットであれば0xffffとなる)。このとき、判断基準は次の表1に示すようになる。   More specifically, if a bad block is recorded in the OOB area of the first page of each block, or if it is not recorded, a determination is made based on whether a predetermined magic number is written in the block. The magic number can be written in either the data area or the OOB area. However, since it is necessary to read the OOB area to determine whether the block is a bad block, the magic number can also be written to the OOB area. Can be judged at the same time. Therefore, the determination is made based on whether or not the magic number is written in the OOB area of the first page and the last used page of each block. The block check means is a means for making such a determination in order to determine the validity of the block, and is generally performed by the control device by a program, but it is to be checked by dedicated hardware. Also good. In order to make such a determination, when writing data to a block, the magic number adding means writes the magic number and the number of used pages of the block in the OOB area. The magic number adding means is generally performed by the control device by a program, but may be added by dedicated hardware. In addition, an erased block usually has all 1 bits (the magic number is 0xffff if it is 16 bits). At this time, the judgment criteria are as shown in Table 1 below.

Figure 2008059228
Figure 2008059228

ここで、以下のようにすることで、マウント時のブロックの有効性の判断を高速化することができる。図8を参照しながら説明を行う。高速化の一手法は、ブロックの2カ所以上に上述のマジックナンバーを書き込むためのマジックナンバー領域を設けることで達成できる。すなわち、ブロックの有効性を判断するには、データが正しく書き込まれたかどうかを確認すればよい。ブロック全体を読み込んでデータの整合性をチェックするのは時間がかかるため、データがブロックの先頭から順番に書き込まれていくのであれば、先頭付近と最後付近で正しいデータが書き込まれているか確認するだけでよいことになる。そこで、ブロックの先頭付近と最後付近にマジックナンバーを記載する領域を設けておく。このマジックナンバーだけを読むことで、ブロックの有効性を高速に判断することができる。さらに、ブロック書き込み中の電源断の有無の判断も容易となる。   Here, by performing the following, it is possible to speed up the determination of the validity of the block at the time of mounting. This will be described with reference to FIG. One method of speeding up can be achieved by providing magic number areas for writing the above-described magic number at two or more locations in the block. That is, in order to determine the validity of a block, it is only necessary to confirm whether data has been written correctly. Since it takes time to read the entire block and check the data consistency, if the data is written sequentially from the beginning of the block, check that the correct data is written near the beginning and near the end. Just be good. Therefore, an area for describing the magic number is provided near the beginning and end of the block. By reading only this magic number, the validity of the block can be determined at high speed. Furthermore, it becomes easy to determine whether or not the power is cut off during block writing.

図8(A)は、上記手法を実現するためのブロック構成例を示す図である。図8(A)に示すように、ブロックYは、データ1領域73aと、マジックナンバー1領域71aと、データ2領域73bと、マジックナンバー2領域71bと、データ3領域73cとのページ順で構成されている。マジックナンバーはデータ領域にあってもOOB領域にあってもよいので、図ではデータ領域とOOB領域の区別はしていない。しかし、マジックナンバーはOOB領域にあるほうが望ましいので、OOB領域に書き込まれているものとする。また、マジックナンバー1領域71aはブロックの先頭ページに、マジックナンバー2領域71bはブロックの先頭以外のページに、それぞれ存在するとする。上記表1に記載した判断基準に基づいて、各ブロックの先頭ページのOOB領域にバッドブロックであることが記録されているか、記録されていない場合、各ブロックの先頭ページと最終使用ページのOOB領域にマジックナンバーが書かれているかどうかでブロックの有効性のチェックを行う。   FIG. 8A is a diagram illustrating a block configuration example for realizing the above technique. As shown in FIG. 8A, the block Y is configured in the page order of the data 1 area 73a, the magic number 1 area 71a, the data 2 area 73b, the magic number 2 area 71b, and the data 3 area 73c. Has been. Since the magic number may be in the data area or the OOB area, the data area and the OOB area are not distinguished in the figure. However, since the magic number is preferably in the OOB area, it is assumed that the magic number is written in the OOB area. Further, it is assumed that the magic number 1 area 71a exists on the first page of the block and the magic number 2 area 71b exists on a page other than the top of the block. Based on the criteria described in Table 1 above, if the bad block is recorded in the OOB area of the first page of each block, or if it is not recorded, the first page of each block and the OOB area of the last used page The validity of the block is checked based on whether or not the magic number is written.

図8(B)は、4種類のブロック1〜4までについての構成例を示す図である。ブロック1〜4までには、図8(A)のように、ブロックの2カ所以上に上述のマジックナンバーを書き込むためのマジックナンバー領域を設けている。ここでは、有効なマジックナンバーを0x1234として説明する。ブロック1では、マジックナンバー1領域71aと、マジックナンバー2領域71bと、に、有効を示すマジックナンバーが記載されている。従って、ブロック1は有効ブロックと判断することができる。ブロック2においては、マジックナンバー1領域71aに有効を示すマジックナンバーが記載されているが、マジックナンバー2領域71bは0xffffが記載されている。このブロックは、ブロックの書き込み中に電源断が生じたと考えられる。従って、ブロック2は無効ブロックと判断することができる。ブロック3においては、マジックナンバー1領域71aと、マジックナンバー2領域71bとの両方に、0xffffが記載されており、フリーブロックであると判断することができる。ブロック4においては、マジックナンバー2領域71bに有効を示すマジックナンバーが記載されているが、マジックナンバー1領域71aは0x0000が記載されている。このブロックは、ファイルシステムが明示的にブロックを無効化したものと考えられる。従って、ブロック4は無効ブロックと判断することができる。   FIG. 8B is a diagram illustrating a configuration example of four types of blocks 1 to 4. As shown in FIG. 8A, the blocks 1 to 4 are provided with magic number areas for writing the above-described magic numbers at two or more locations in the block. Here, description will be made assuming that the effective magic number is 0x1234. In block 1, magic numbers indicating validity are described in magic number 1 area 71a and magic number 2 area 71b. Therefore, block 1 can be determined as a valid block. In block 2, a magic number indicating validity is described in the magic number 1 area 71a, but 0xffff is described in the magic number 2 area 71b. This block is considered to have lost power during the writing of the block. Therefore, block 2 can be determined as an invalid block. In block 3, 0xffff is written in both the magic number 1 area 71a and the magic number 2 area 71b, and it can be determined that the block is a free block. In block 4, a magic number indicating validity is described in the magic number 2 area 71b, but 0x0000 is described in the magic number 1 area 71a. This block is considered that the file system explicitly invalidated the block. Therefore, the block 4 can be determined as an invalid block.

尚、先頭ページと最終使用ページとの2箇所で判断を行うのは、ブロックへの書き込みはページ単位で行われるため、一箇所のマジックナンバーを確認するだけでは、ブロック書き込み中の電源断を検出できないからである。データがブロックの先頭ページにだけしか書き込まれていないブロックに関しては、先頭ページと最終使用ページとが等しくなるので、先頭ページ以外のページにもマジックナンバーを書き込むようにして、それを、最終使用ページのマジックナンバーの代わりに用いて判断する。   It should be noted that the reason for making a decision at two locations, the first page and the last used page, is that writing to the block is performed on a page-by-page basis, so simply checking the magic number at one location will detect a power failure during block writing It is not possible. For blocks in which data is written only on the first page of the block, the first page and the last used page are the same, so the magic number is written on pages other than the first page, and the last used page Judging by using instead of the magic number.

また、このように、2つのページのマジックナンバーを判断することにより、少なくとも、先頭ページのデータは正しいデータであることが保証される。その理由は、ブロック内に複数のページを連続して書き込む場合に、先頭ページから順番に書き込んで行き、ページを書き込むたびに書き込んだデータが正しいかベリファイを行っていれば、先頭ページが正しく書き込めない限り、以降のページに書き込みに行くことはないからである。すなわち、データ2、またはデータ3の書き込み時に電源断が生じたとしても、マジックナンバー領域71aとマジックナンバー領域71bが有効であることが判定できれば、マジックナンバー領域71aの前にあるデータ1は有効であることが保証される。データ1の領域に重要な情報を記憶させておけば、少なくともこの情報は正常なデータとして利用することができる。なお、ページのベリファイはページベリファイ手段により行われる。ページベリファイ手段は、ページへのデータの書き込み時に、書き込んだデータが正しく書き込めているかのベリファイを行う手段であり、一般的にはプログラムにより制御装置が行うことになるが、専用のハードウエアによってベリファイするようにしてもよい。   In addition, by determining the magic numbers of the two pages in this way, it is ensured that at least the data of the first page is correct data. The reason for this is that when writing multiple pages in a block in succession, if the data written is written in order from the first page and the written data is verified each time the page is written, the first page can be written correctly. This is because there is no going to write to the following pages unless it is. That is, even if the power is cut off when writing data 2 or data 3, if it can be determined that magic number area 71a and magic number area 71b are valid, data 1 in front of magic number area 71a is valid. Guaranteed to be. If important information is stored in the area of data 1, at least this information can be used as normal data. Note that page verification is performed by page verification means. The page verify means is means for verifying whether the written data is correctly written at the time of writing data to the page. Generally, the control apparatus performs it by a program, but it is verified by dedicated hardware. You may make it do.

マウントの第二段階では、チェックブロックリスト内の妥当ブロックを解析し、妥当ファイル候補、もしくは、不完全ファイルを再構成する。基本的に妥当ブロックは、妥当ファイル候補か不完全ファイルかどちらかの構成要素となるはずである。   In the second stage of mounting, valid blocks in the check block list are analyzed, and valid file candidates or incomplete files are reconstructed. Basically, a valid block should be a component of either a valid file candidate or an incomplete file.

具体的にファイルを再構成するには、各ブロックの先頭ページに、以下の表2に示すようなブロック情報を付加してデータを書き込んでおく。上述したように、妥当ブロックの先頭ページはデータが正しいことが保証されているので、ブロック情報が正しいかどうかのチェックは省いてもよい。   To reconstruct the file specifically, data is written by adding block information as shown in Table 2 below to the first page of each block. As described above, since the data of the first page of the valid block is guaranteed to be correct, the check of whether the block information is correct may be omitted.

Figure 2008059228
Figure 2008059228

尚、ファイル名とファイルサイズに関しては、ブロック情報において必須ではなく含めなくてもよい。その場合は、データの先頭にこれらを付加しておけばよい(図3のブロック情報のバリエーションを参照)。   The file name and file size are not essential in the block information and need not be included. In that case, these may be added to the head of the data (see the block information variation in FIG. 3).

より具体的なファイル構成情報の生成例について図面を参照しながら説明を行う。図4は、本実施の形態によるファイルシステムにおけるブロックの一構成例を示す図である。図4に示すように、ブロックYは、太線で囲まれたブロック情報領域と、それ以外のデータ領域53とを含んでいる。ブロック情報41は、ファイル名43とファイルサイズ45とファイルシステムが付与する一意のファイルID47とファイルにおけるブロックのつながりの順番を示すブロック番号51とを含んでいる。尚、このうち、ブロック情報41の必須項目41aは、ファイルIDとブロック番号とであり、これにより、ブロックがどこに属するかについての構成を知ることができる。   A more specific example of generating file configuration information will be described with reference to the drawings. FIG. 4 is a diagram showing a configuration example of a block in the file system according to the present embodiment. As shown in FIG. 4, the block Y includes a block information area surrounded by a bold line and a data area 53 other than that. The block information 41 includes a file name 43, a file size 45, a unique file ID 47 assigned by the file system, and a block number 51 indicating the connection order of blocks in the file. Of these, the essential items 41a of the block information 41 are a file ID and a block number, so that the configuration of where the block belongs can be known.

図5は、例として示したブロック1から6までに関するブロック構成例を示す図である。ブロック1は、ファイルID47が“456”であり、ブロック番号51が2/2である。2/2は、2つあるブロックのうちの2番目であることを示す。ブロック2は、ファイルID47が“123”であり、ブロック番号51が1/3である。ブロック3は、ファイルID47が“789”であり、ブロック番号51が2/4である。ブロック4は、ファイルID47が“123”であり、ブロック番号51が3/3である。ブロック5は、ファイルID47が“123”であり、ブロック番号51が2/3である。ブロック6は、ファイルID47が“456”であり、ブロック番号51が1/2である。   FIG. 5 is a diagram illustrating a block configuration example related to blocks 1 to 6 shown as examples. In the block 1, the file ID 47 is “456” and the block number 51 is 2/2. 2/2 indicates the second of two blocks. In the block 2, the file ID 47 is “123” and the block number 51 is 1/3. In the block 3, the file ID 47 is “789”, and the block number 51 is 2/4. In the block 4, the file ID 47 is “123”, and the block number 51 is 3/3. In the block 5, the file ID 47 is “123”, and the block number 51 is 2/3. In the block 6, the file ID 47 is “456” and the block number 51 is ½.

図6は、ファイル構成情報の構成例と、ファイル構成情報から再生成できるファイルの構成例を示す図である。図6(A)に示すように、ファイル構成情報61は、ファイルID45と、ブロックリスト57とを有している。図6(B)に示すように、ファイルID=123のファイル1のブロックリストは、矢印AR1、2、3の順番で繋がれているブロック2、ブロック5、ブロック4により構成されていることがわかる。一方、ファイルID=456のファイル2は、矢印AR11、12の順番で繋がれているブロック6、ブロック1により構成されていることがわかる。   FIG. 6 is a diagram illustrating a configuration example of file configuration information and a configuration example of a file that can be regenerated from the file configuration information. As shown in FIG. 6A, the file configuration information 61 has a file ID 45 and a block list 57. As shown in FIG. 6B, the block list of file 1 with file ID = 123 is composed of block 2, block 5 and block 4 connected in the order of arrows AR1, 2, and 3. Recognize. On the other hand, it can be seen that the file 2 with the file ID = 456 is composed of the blocks 6 and 1 connected in the order of the arrows AR11 and AR12.

次に、ファイル構成情報再構築の処理の流れを図7(A)、(B)を参照しながら説明する。ステップS1においてファイル再構成を開始する。ステップS2において、ブロックを取り出し、ステップS3において、取り出したブロックが有効なブロックであるか否かを、ブロックチェック手段を用いて判定する。有効なブロックでない場合には(N)、ステップS8に進む。有効のブロックである場合には(Y)ステップS4に進み、ブロック情報を読み込む。ステップS5において読み込んだブロック情報に記載されているファイルIDが新規なファイルIDであるか否かを判定する。新規ファイルIDである場合には(Y)、ステップS6においてファイルIDを登録し、ステップS7に進む。新規ファイルIDでない場合にも(N)ステップS7に進み、該当ファイルIDにこのブロックを追加する。次いで、ステップS8において全ブロックの処理が完了したか否かを判定する。全ブロックの処理が完了していない場合には(N)ステップS2に戻る。全ブロックの処理が完了した場合には(Y)、ファイルの構成情報の生成処理を終了する。これらの情報は、RAMのファイル構成情報格納領域に登録する。この時点で登録されるファイルは、不完全ファイル、もしくは、妥当ファイル候補となっている。   Next, the flow of processing for reconstructing file configuration information will be described with reference to FIGS. 7 (A) and 7 (B). In step S1, file reconstruction is started. In step S2, the block is extracted, and in step S3, it is determined using the block check means whether or not the extracted block is a valid block. If it is not a valid block (N), the process proceeds to step S8. If it is a valid block (Y), the process proceeds to step S4 to read block information. It is determined whether or not the file ID described in the block information read in step S5 is a new file ID. If it is a new file ID (Y), the file ID is registered in step S6, and the process proceeds to step S7. Even if it is not a new file ID (N), the process proceeds to step S7, and this block is added to the corresponding file ID. Next, in step S8, it is determined whether or not all blocks have been processed. If all the blocks have not been processed (N), the process returns to step S2. If all blocks have been processed (Y), the file configuration information generation process is terminated. These pieces of information are registered in the RAM file configuration information storage area. The file registered at this time is an incomplete file or a valid file candidate.

次いで、ファイルの構成情報に基づいてこれらのファイルから妥当ファイル候補を抽出する処理について説明する。ステップS9において、RAMのファイル構成情報格納領域に登録されている情報を読み出してファイルIDを取り出し、このファイルIDを持つファイルにおいて全ブロックが存在するか否かを判定する(ステップS10)。全ブロックが存在する場合には(Y)ステップS11に進み、該当するファイルIDのファイル構成情報を有効にし、全ブロックが存在するのではない場合(N)とともに、ステップS12に進み、全ファイルIDについて処理が完了しているか否かを判断し、NOの場合にはステップS9に戻って同様の処理を繰り返す。全ファイルIDについて処理が完了して場合(Y)には、ステップS13においてファイルの再構成を完了する。尚、ステップS1からステップS8までの処理と、ステップS9からステップS13までの処理は、並行処理としても良い。以上のようにすることで、ファイル構成情報の作成と再構成とを簡単に行うことができる。ファイル構成情報をフラッシュメモリに記憶するのではないため、ブロック情報のみに基づいて、ファイルを再構成する際に、同じ領域における書き込み、読み出しを避けることができる。   Next, processing for extracting valid file candidates from these files based on the file configuration information will be described. In step S9, the information registered in the file configuration information storage area of the RAM is read to extract the file ID, and it is determined whether or not all blocks exist in the file having this file ID (step S10). If all the blocks exist (Y), the process proceeds to step S11, and the file configuration information of the corresponding file ID is validated. If all the blocks do not exist (N), the process proceeds to step S12, and all file IDs Whether or not the process is completed is determined. If NO, the process returns to step S9 to repeat the same process. If the processing is completed for all the file IDs (Y), the file reconstruction is completed in step S13. Note that the processing from step S1 to step S8 and the processing from step S9 to step S13 may be parallel processing. As described above, creation and reconfiguration of file configuration information can be easily performed. Since the file configuration information is not stored in the flash memory, writing and reading in the same area can be avoided when the file is reconstructed based only on the block information.

尚、妥当ファイル候補でないものは不完全ファイルとなる。マウントの第三段階では、再構成された妥当ファイル候補から有効ファイルを選び出す。有効ファイルは、妥当ファイルとなる妥当ファイル候補であり、妥当ファイル中に同名のファイルがなければそのファイルとし、同名のファイルがあれば、最後に書き込まれたファイルとする。また、有効ファイルは、「消去を示すファイル」ではないことも条件となる。なお、同名のファイルが存在すること、同名の最後に書き込まれたファイルを判断すること、および、「消去を示すファイル」に関しては後述する。   A file that is not a valid file candidate is an incomplete file. In the third stage of mounting, a valid file is selected from the reconstructed valid file candidates. A valid file is a valid file candidate to be a valid file. If there is no file with the same name in the valid file, the valid file is assumed to be that file, and if there is a file with the same name, the last file is written. Further, it is also a condition that the valid file is not a “file indicating erasure”. The existence of a file with the same name, determination of the file written at the end of the same name, and “file indicating erasure” will be described later.

ブロックへの書き込みでベリファイが必要な場合、ベリファイ中に電源断があるとそのブロックが本当に正しく書き込めたかどうかがわからないという問題がある。ファイルが複数のブロックから構成されている場合に、最終ブロックで電源断が発生すると、最終ブロックの書き込み正当性が判断できず、ファイル内容が異常になる可能性がある。そこで、本実施の形態によるファイルシステムにおいては、ファイルの書き込みはファイル内のいずれかのブロックに書き込み完了フラグを書くことで完了とすることを特徴とする。ファイル内のどこかのブロックに、ファイル全体の書き込み完了を意味するフラグを書き込む領域を設けておけば、そのフラグをチェックするだけでファイルの書き込みが正常に行われたかどうかを簡単に判断できる。従って、ファイル書き込みの際の電源断による不完全ファイルの検出を容易にすることができる。図9(A)は、このようなブロック構成例を示す図である。図示するように、ブロックYは、データ領域81と、書き込み完了フラグ領域83とを有している。図9(B)は、ブロックAからブロックFまでの6つのブロックの構成例を示す図である。ブロックA〜Cは、ファイル1に含まれるブロックであり、ブロックD〜Fは、ファイル2に含まれるブロックである。ここで、各ファイル1、2の先頭ブロックの最終ページには、書き込み完了を示す書き込み完了フラグを記載するための書き込み完了フラグ領域83aが設けられている。書き込み完了フラグ領域はどこに設けてもよいが、先頭ブロックにあるのが好ましい。図10(A)に示すように、ブロックA、B、Cからなるファイル1は、最終ブロックであるブロックCまで正常に書き込まれており、ブロックAの最終ページに書き込み完了フラグ領域83aに有りと記載されているため、ファイルの書き込みが正常に行われたことがわかる。一方、図10(B)に示すように、ファイル2は、ブロックD、E、Fからなるが、ブロックDの最終ページに設けられた書き込み完了フラグ領域83bにはフラグが記載されておらず、これをもってファイルの書き込みが未完であると判断することができる。すなわち、妥当ファイル候補が妥当ファイルであるか否かを判断するために、ファイルを構成するブロックのうちファイルの先頭ブロックに関しては、そのファイル全体のブロックの書き込みが完了したことを示すデータ(書き込み完了フラグ)を書き込む領域83を別途設けておくことが特徴となる。   When verification is necessary for writing to a block, there is a problem that if the power is cut off during verification, it is not known whether or not the block has been written correctly. If the file is composed of a plurality of blocks and the power is cut off in the final block, the write validity of the final block cannot be determined and the file contents may become abnormal. Therefore, the file system according to this embodiment is characterized in that the file writing is completed by writing a write completion flag in any block in the file. If an area for writing a flag indicating completion of writing of the entire file is provided in some block in the file, it can be easily determined whether or not the file has been written normally only by checking the flag. Therefore, it is possible to easily detect an incomplete file due to a power interruption when writing a file. FIG. 9A shows an example of such a block configuration. As shown in the figure, the block Y has a data area 81 and a write completion flag area 83. FIG. 9B is a diagram illustrating a configuration example of six blocks from block A to block F. Blocks A to C are blocks included in the file 1, and blocks D to F are blocks included in the file 2. Here, the last page of the first block of each file 1 and 2 is provided with a write completion flag area 83a for writing a write completion flag indicating the completion of writing. The write completion flag area may be provided anywhere, but is preferably in the first block. As shown in FIG. 10A, the file 1 composed of the blocks A, B, and C is normally written up to the block C, which is the last block, and the write completion flag area 83a exists in the last page of the block A. Since it is described, it can be seen that the file was written normally. On the other hand, as shown in FIG. 10B, the file 2 is composed of blocks D, E, and F, but no flag is described in the write completion flag area 83b provided on the last page of the block D. With this, it can be determined that the writing of the file is incomplete. That is, in order to determine whether a valid file candidate is a valid file, with respect to the first block of the file among the blocks constituting the file, data indicating that the writing of the entire block of the file has been completed (write complete) A feature is that an area 83 for writing a flag is separately provided.

実装の一例としては、先頭ブロックの最終ページはファイルのデータを書き込むためには使用せずに、この書き込み完了フラグを書き込むために使用する。このようにすることで、あるファイルの先頭のブロックに書き込み完了フラグが書かれているかどうかを調べることにより、そのブロックを先頭ブロックとするファイルの全てのブロックが正常に書き込まれているか否かを判断することができる。この書き込み完了フラグが書き込まれている妥当候補ファイルを妥当ファイルとする。なお、書き込み完了フラグは、完了フラグ書き込み手段により、ファイルの書き込み完了後に、書き込まれる。また、マウント時には、完了フラグ読み込み手段により読み込まれ、ファイルの書き込みが完了したかどうかを判断するために用いられる。これら、書き込みと読み込み、および、判断は、一般的にはプログラムにより制御装置が行うことになるが、専用のハードウエアによってこれらを行うようにしてもよい。   As an example of implementation, the last page of the first block is not used for writing file data, but is used for writing this write completion flag. By doing this, by checking whether the write completion flag is written in the first block of a certain file, it is possible to check whether all the blocks of the file having that block as the first block have been written normally. Judgment can be made. The valid candidate file in which the write completion flag is written is regarded as a valid file. The write completion flag is written after the file writing is completed by the completion flag writing means. Further, at the time of mounting, it is read by a completion flag reading means and used to determine whether or not the writing of the file is completed. These writing, reading, and determination are generally performed by the control device by a program, but these may be performed by dedicated hardware.

有効ファイルを構成するブロックはチェックブロックリストから外す。有効ファイルを構成するブロックとならなかったブロックは、チェックブロックリストから外されイレースブロックリストにつながれる。すなわち、無効ファイルと不完全ファイルを構成するブロックである。これらのブロックは再利用されることになる。なお、イレースブロックリストにつなぐ際には、そのブロックへの書き込みが古く行われたものから順につなぐようにする。   The blocks that make up the valid file are removed from the check block list. Blocks that have not become blocks constituting the valid file are removed from the check block list and connected to the erase block list. That is, it is a block constituting an invalid file and an incomplete file. These blocks will be reused. When connecting to the erase block list, the blocks are connected in order from the oldest.

上記、一連の処理によって、マウント終了後には、フリーブロックはフリーブロックリストに、消去が必要な、もしくは、消去が可能なブロックはイレースブロックリストにつながれていることになる。   According to the above-described series of processing, after completion of mounting, free blocks are connected to the free block list, and blocks that need to be erased or are erasable are connected to the erase block list.

次に、ファイルの書き込み処理について図24を参照しながら説明する。まず、ステップS101において、書き込み処理を開始する。次いで、ステップS102において、ファイルID付与手段を用いて、ファイルIDを取得する。ステップS103において、フリーブロックリストが空か否かを判定する。フリーブロックリストが空であれば(YES)、ステップS104に進み、フリーブロックリストではなくイレースブロックリストからブロックを取り出し、ステップS106においてブロックを消去し、ステップS107においてブロック情報を生成する。ステップS103でNOの場合にはステップS105に進み、フリーブロックリストからブロックを取り出し、ステップS107に進みブロック情報を生成する。   Next, a file writing process will be described with reference to FIG. First, in step S101, a writing process is started. Next, in step S102, the file ID is obtained using the file ID assigning means. In step S103, it is determined whether or not the free block list is empty. If the free block list is empty (YES), the process proceeds to step S104, a block is extracted from the erase block list instead of the free block list, the block is deleted in step S106, and block information is generated in step S107. If NO in step S103, the process proceeds to step S105, a block is extracted from the free block list, and the process proceeds to step S107 to generate block information.

次いで、ステップS108においてブロック情報とデータをブロックへ書き込み、ステップS109において、書き込みデータが残っているか否かを判定する。次いで、ステップS110において、完了フラグ書き込み手段を用いて、書き込み完了フラグを先頭ブロックに書き込み、ステップS111においてファイルIDを更新(ファイルIDを消費したことを、ファイルID付与手段に示す)し、ステップS112において、ファイル構成情報に新ファイルを追加する。ステップS113において、旧ファイルが存在するか否かを判定し、存在すれば(YES)ステップS114に進み旧ファイル構成ブロックをイレースブロックリストに追加し、ステップS115においてファイル構成情報から旧ファイルを削除し、書き込みを終了する(ステップS116)。旧ファイルが存在しない場合には、そのまま処理を終了する(ステップS116)。ここで、ステップS110からステップS115は、後述するファイル更新手段の手順を示している。すなわち、書き込みが完了したファイルと同名の旧ファイルがある場合には、そのファイルを無効とするとともに、新たなファイルを有効とする処理である。旧ファイルがない場合には、新たなファイルが有効になるだけである。ステップS110からステップS115の処理は、一般的には、プログラムにより制御装置が行うことになるが、専用のハードウエアによってこれらを行うようにしてもよい。   Next, in step S108, block information and data are written to the block, and in step S109, it is determined whether or not write data remains. Next, in step S110, the completion flag writing means is used to write the write completion flag to the first block, and in step S111, the file ID is updated (indicating that the file ID has been consumed is indicated to the file ID giving means), and in step S112. To add a new file to the file structure information. In step S113, it is determined whether or not the old file exists. If yes (YES), the process proceeds to step S114, where the old file configuration block is added to the erase block list, and in step S115, the old file is deleted from the file configuration information. The writing is terminated (step S116). If the old file does not exist, the process is terminated as it is (step S116). Here, step S110 to step S115 show the procedure of the file update means described later. In other words, if there is an old file with the same name as the file that has been written, the file is invalidated and the new file is validated. If there is no old file, only the new file is valid. The processing from step S110 to step S115 is generally performed by the control device by a program, but may be performed by dedicated hardware.

以上に説明したように、ファイルの書き込みに使用するブロックは、フリーブロックリストから取り出す。フリーブロックリストにブロックがない場合は、イレースブロックリストからブロックを取り出し、消去を行い、フリーブロックリストに入れた後、フリーブロックリストから取り出す。このような手順にしておけば、フリーブロックリストのブロックが尽きてからイレースブロックリストのブロックを再利用するようになるため、全領域が初期化された状態から、全領域のブロックに書き込みを行うまでの間では、ブロックが再利用されることはない。また、イレースブロックリストにつながれているブロックは、書き込まれた順番でつながれており、つなぐときも書き込まれた順番でつなぐ。したがって、イレースブロックリスト内の特定のブロックが何度も再利用されるというようなことはおこらない。   As described above, the block used for writing the file is extracted from the free block list. If there is no block in the free block list, the block is taken out from the erase block list, erased, put in the free block list, and taken out from the free block list. If this procedure is used, the blocks in the erase block list will be reused after the free block list is exhausted. Therefore, writing to the blocks in all areas is performed after all areas have been initialized. In the meantime, the block is not reused. Further, the blocks connected to the erase block list are connected in the order in which they were written, and when connecting, they are connected in the order in which they were written. Therefore, a specific block in the erase block list is not reused many times.

上記ステップS110において、書き込み完了フラグをファイルの先頭ブロックに書き込んだ時点で、ファイルの書き込みが正常に行われたものとなる。すなわち、ステップS110以前に電源断が発生した場合、書き込んだブロックは不完全ファイルを構成するものとなるか、もしくは、無効ブロックとなるかのどちらかであり、次回のマウント処理において、それらは、イレースブロックリストにつながれることになる。このとき、不完全ファイルにおいても、ファイルIDは付与されているため、このファイルはイレースブロックリストの最後尾につながれる。無効ブロックに関してはイレースブロックリストの先頭につながれる。この場合、書き込みが行われなかったことに等しい。   In step S110, when the write completion flag is written in the first block of the file, the file is normally written. That is, if a power failure occurs before step S110, the written block is either an incomplete file or an invalid block, and in the next mounting process, You will be linked to the erase block list. At this time, since the file ID is also assigned to the incomplete file, this file is connected to the end of the erase block list. An invalid block is linked to the top of the erase block list. In this case, it is equivalent to no writing.

ステップS110以降に電源断が行われた場合、ステップ114およびステップ115の処理は必要があれば次回のマウント処理で必ず行われるため、特に考慮する必要はない。   If the power is turned off after step S110, the processing in step 114 and step 115 is always performed in the next mounting process if necessary, so there is no need to consider it in particular.

次に、ファイルの更新処理について説明する。
一般的なファイルシステムでは、ファイルを更新する場合には、そのファイルが記録されている部分を直接書き換えるか、別名でファイルを作成した後にファイル名を変更するか、といった方法が取られる。しかしながら、これらの方法では、書き換え中に電源断が発生した場合や、ファイル名を変更中に電源断が発生した場合には、データの不整合やファイルの消失といった危険性が伴う。一方、フラッシュメモリは書き換えを行うためにはブロック全体の消去を行う必要があり、一部分だけの書き換えは無駄が多く、また、書き換えの回数にも制限があることから、上述のような方法は向いていない。
Next, file update processing will be described.
In a general file system, when a file is updated, a method of directly rewriting a portion where the file is recorded or changing a file name after creating a file with an alias is taken. However, in these methods, there is a risk of data inconsistency or file loss when a power interruption occurs during rewriting or when a power interruption occurs while changing a file name. On the other hand, in order to rewrite a flash memory, it is necessary to erase the entire block, and rewriting only a part is wasteful and the number of times of rewriting is limited, so the above method is suitable. Not.

そこで、本実施の形態によるファイルシステムにおいては、ファイルシステム内に同名のファイルが存在することを許し、有効なファイルは最後に書き込まれたファイルであるとし、また、新しいファイルの書き込み完了を待ってから古いファイルを無効化することを特徴とする。これにより、ファイル更新の際の電源断に起因する上記のような危険性を排除することができる。これらの処理はファイル更新手段により行われる。   Therefore, in the file system according to the present embodiment, it is allowed that a file with the same name exists in the file system, the valid file is the last written file, and waiting for the completion of writing the new file. It is characterized by invalidating old files. As a result, it is possible to eliminate the above-described danger caused by the power interruption at the time of file update. These processes are performed by the file update means.

次に、図面を参照しながら、より詳細に説明を行う。図11は、ファイル書き込み前のファイル構成情報の例を示す図である。図11に示すように、ファイル1におけるファイル書き込み前の構成情報は、ファイル名が‘AA’であり、このファイル名AAのファイル1は、AR1の矢印とそれに続くAR2の矢印で示すようにブロックAとブロックBとから構成されている。図12に示すファイル書き込み中の構成情報(1)は、図示するように、このファイル1を更新するためにファイル書き込む場合に、ファイル1の他にファイル1と同名のファイル2を作成する。このファイル2に含まれるブロックCは、ファイル書き込みがまだ完了していないため、フラグ領域83bにはフラグが立っていない(無し)。図13に示すファイル書き込み中の構成情報(2)は、図示するように、ファイル2に関して、ブロックCとブロックDとをつなげる。この状態では、ファイル書き込みがまだ完了していないため、フラグ領域83bにはフラグが立っていない。   Next, description will be made in more detail with reference to the drawings. FIG. 11 is a diagram illustrating an example of file configuration information before file writing. As shown in FIG. 11, the configuration information before writing the file in the file 1 has the file name “AA”, and the file 1 with the file name AA is blocked as indicated by the arrow AR1 and the arrow AR2 following it. It consists of A and block B. The configuration information (1) during the file writing shown in FIG. 12 creates a file 2 having the same name as the file 1 in addition to the file 1 when the file is written to update the file 1 as shown. In the block C included in the file 2, since the file writing has not yet been completed, the flag is not set in the flag area 83b (none). The configuration information (2) during file writing shown in FIG. 13 connects the block C and the block D with respect to the file 2 as shown in the figure. In this state, since the file writing has not been completed yet, no flag is set in the flag area 83b.

図14は、ファイル書き込み完了直後の構成情報例を示す図である。図14に示すように、ファイル2において、ブロックDをつなげた後に、矢印AR31で示すように、フラグ書き込み領域83aにフラグを立てる(有りとする)。これ以降であれば、フラグ有りになっているため、電源断が生じた場合でもファイル2が存在する。従って、図15に示すように、ファイル1を無効化処理したとしても、ファイル2を引き続き利用することで、ファイル1からファイル2への更新を行うことができる。この状態でRAMへのファイル構成情報の書き込みを行う。   FIG. 14 is a diagram illustrating an example of configuration information immediately after file writing is completed. As shown in FIG. 14, after the blocks D are connected in the file 2, a flag is set in the flag writing area 83a as shown by an arrow AR31 (present). After this, since the flag is present, the file 2 exists even when the power is cut off. Therefore, as shown in FIG. 15, even if the file 1 is invalidated, the file 1 can be updated from the file 2 by using the file 2 continuously. In this state, file configuration information is written to the RAM.

このように、同名ファイルの存在を許容し同名ファイルで更新することにより、途中で電源断が生じても、更新前のファイルと更新後のファイルの両方のファイルを消失する危険性がなく、安全にファイルの更新を行うことができる。   In this way, by allowing the existence of the same name file and updating with the same name file, there is no risk of losing both the file before update and the file after update even if the power is interrupted in the middle, and it is safe You can update the file.

次に、ファイルの消去処理について説明する。本実施の形態によるファイルシステムにおいては、ファイルの消去は“ファイルを消去したことを示すファイル”を書き込むことで行うことを特徴とする。ファイルを消去するには、ファイル構成情報からそのファイルの構成情報を取り除けばよいが、ファイル構成情報はRAM上に存在するため、その状態で電源断が起こった場合、次回のマウント処理で消去されたはずファイルが復活してしまう。したがって、ファイル構成情報を消去するだけでなく、そのファイルを構成するブロックを消去する必要がある。しかしながら、複数のブロックからなるファイルを消去する場合や、消去に時間がかかるデバイスにとっては、このような処理では時間がかかってしまう。そこで、ファイルを構成するブロックを消去する代わりに、ファイルを消去したことを示すファイルを書き込むことにし、そのファイル、および、そのファイルにより消去されたファイルは利用者に見せないようにする。このようにしておけば、電源断が起こった場合でも、次回のマウント処理で消去されたファイルが復活することはない。ここで、例えば、ファイルを消去したことを示すファイルとして、同名のサイズが0のファイルを書き込むようにすれば、たかだか1ブロック分の書き込みだけですむため、消去を高速に行うことが可能となる。   Next, the file erasing process will be described. In the file system according to the present embodiment, the file is erased by writing “file indicating that the file has been erased”. To delete a file, it is only necessary to remove the file configuration information from the file configuration information. However, since the file configuration information exists in the RAM, if the power is cut off in that state, it will be deleted in the next mount process. The file should have been restored. Therefore, it is necessary not only to erase the file configuration information but also to erase the blocks constituting the file. However, such a process takes time for erasing a file composed of a plurality of blocks or for a device that takes a long time to erase. Therefore, instead of erasing the blocks constituting the file, a file indicating that the file has been erased is written, and the file and the file erased by the file are not shown to the user. By doing so, even if the power is cut off, the file erased by the next mounting process will not be restored. Here, for example, if a file with the same name having a size of 0 is written as a file indicating that the file has been erased, it is only necessary to write for one block, so that erasure can be performed at high speed. .

図16(A)は、消去を示すファイル書き込み前の構成情報の例を示す図である。図16(A)に示すように、消去を示すファイル書き込み前においては、ファイル名‘AA’45を有するファイル1は、矢印AR1、AR2、AR3でそれぞれ順番に繋がれているブロックA、B、Cから構成されていることがわかる。ここで、図16(B)に示すように、複数のブロックからなるファイル1を消去する場合に、ブロックDのみを含むファイル2を生成する。このファイル2は、ファイル消去のファイルであり、サイズが0のファイルである。ファイル2のフラグ書き込み領域83aには、書き込み完了を示すフラグが付される。そして、サイズ0のファイル2でファイル1を上書きすることにより、利用者には見えない形でファイル1が消去できることになる。この場合に、同じ名前‘AA’のファイルがあった場合に、最後に書き込まれたファイル2が有効となる。すなわち、図16(C)に示すように、ファイル1とファイル2とを無効化することにより実質的にファイル1を消去することが簡単に行うことが可能となる。すなわち、ファイル消去の高速化が可能となる。   FIG. 16A is a diagram illustrating an example of configuration information before file writing indicating erasure. As shown in FIG. 16A, before the file writing indicating erasure, the file 1 having the file name “AA” 45 is connected to the blocks A, B, It can be seen that it is composed of C. Here, as shown in FIG. 16B, when erasing the file 1 composed of a plurality of blocks, the file 2 including only the block D is generated. This file 2 is a file erasure file and a file of size 0. A flag indicating completion of writing is attached to the flag writing area 83a of the file 2. Then, by overwriting the file 1 with the file 2 of size 0, the file 1 can be deleted in a form that is not visible to the user. In this case, if there is a file with the same name 'AA', the file 2 written last is valid. That is, as shown in FIG. 16C, it becomes possible to easily delete the file 1 by invalidating the file 1 and the file 2. In other words, file erasing can be speeded up.

このように、ファイルの消去は、「消去を示すファイル」を書き込むことで実現することができる。たとえば、上記では、同名のファイルサイズが0のファイルにその役割をまかせているが、特に限定はしない。但し、「消去を示すファイル」は利用者には見せないほうが好ましい。書き込み手順は、通常のファイルの書き込みとほぼ同じであるが、ファイルの書き込み後に、「消去を示すファイル」を構成するブロックをイレースブロックリストにつなげるという処理が加わる。   As described above, the erasure of the file can be realized by writing “file indicating erasure”. For example, in the above description, the role is assigned to a file having the same file size of 0, but there is no particular limitation. However, it is preferable not to show the “file indicating deletion” to the user. The writing procedure is almost the same as the normal file writing, but after the file writing, a process of connecting the blocks constituting the “file indicating erasure” to the erase block list is added.

図25に、処理のフローチャート図を示す。まず、ステップS121において、消去処理を開始する。次いで、ステップS122においてファイルIDを取得する。ステップS123において、フリーブロックリストが空か否かを判定する。フリーブロックリストが空であれば(YES)、ステップS124に進み、フリーブロックリストではなくイレースブロックリストからブロックを取り出し、ステップS126においてブロックを消去し、ステップS127においてブロック情報を生成する。この時、ファイルサイズは0とする。ステップS123でNOの場合にはステップS125に進み、フリーブロックリストからブロックを取り出し、ステップS127に進みブロック情報を生成する。この時、ファイルサイズは0とする。次いで、ステップS128においてブロック情報とデータをブロックへ書き込み、ステップS129において、書き込みデータが残っているか否かを判定する。次いで、ステップS130において、書き込み完了フラグを先頭ブロックに書き込み、ステップS131においてファイルIDを更新し、ステップS132において、ファイル構成ブロックをイレースブロックリストに追加し、ステップS133において、旧ファイル構成ブロックをイレースブロックリストに追加し、ステップS134においてファイル構成情報から旧ファイルを削除し、書き込みを終了する(ステップS135)。   FIG. 25 shows a flowchart of the process. First, in step S121, an erasing process is started. Next, a file ID is acquired in step S122. In step S123, it is determined whether or not the free block list is empty. If the free block list is empty (YES), the process proceeds to step S124, a block is extracted from the erase block list instead of the free block list, the block is erased in step S126, and block information is generated in step S127. At this time, the file size is set to zero. If NO in step S123, the process proceeds to step S125, a block is extracted from the free block list, and the process proceeds to step S127 to generate block information. At this time, the file size is set to zero. In step S128, block information and data are written to the block. In step S129, it is determined whether or not write data remains. Next, in step S130, the write completion flag is written in the first block, the file ID is updated in step S131, the file configuration block is added to the erase block list in step S132, and the old file configuration block is erased in step S133. In step S134, the old file is deleted from the file configuration information, and writing is terminated (step S135).

尚、上記ステップS130において、書き込み完了フラグをファイルの先頭ブロックに書き込んだ時点で、ファイルの書き込みが正常に行われたものとなる。すなわち、ステップS130以前に電源断が発生した場合、書き込んだブロックは不完全ファイルを構成するものとなるか、もしくは、無効ブロックとなるかのどちらかであり、次回のマウント処理において、それらは、イレースブロックリストにつながれることになる。このとき、不完全ファイルにおいても、ファイルIDは付与されているため、このファイルはイレースブロックリストの最後尾につながれる。無効ブロックに関してはイレースブロックリストの先頭につながれる。この場合、消去は行われなかったことに等しい。   In step S130, when the write completion flag is written in the first block of the file, the file is normally written. That is, if a power interruption occurs before step S130, the written block is either an incomplete file or an invalid block, and in the next mounting process, You will be linked to the erase block list. At this time, since the file ID is also assigned to the incomplete file, this file is connected to the end of the erase block list. An invalid block is linked to the top of the erase block list. In this case, it is equivalent to no erasure.

ステップS130以降に電源断が行われた場合でも、有効なファイルは最後に書き込まれたファイルと決めておく限り、ステップ132からステップ134の処理は必要があれば次回のマウント処理で必ず行われるため、特に考慮する必要はない。   Even if the power is turned off after step S130, as long as the valid file is determined to be the last written file, the processing from step 132 to step 134 is always performed in the next mounting process if necessary. There is no particular need to consider.

次に、ファイルIDの付与方法、ならびに、ブロックの再利用方法について説明する。
マウント時に、ブロックに付与されたファイルIDに基づいて、ファイルを再構成し、有効なファイルを抽出する方法はすでに述べた。また、同名のファイルがある場合、最後に書き込まれたファイルが有効なファイルであるとしておくことで、ファイルの書き込み時や消去時に電源断があっても不具合が発生しない方法を述べた。さらに、有効でないファイルを構成するブロックに関しては、そのファイルが書き込まれた順番で再利用する方法を述べた。
Next, a file ID assigning method and a block reusing method will be described.
The method for reconstructing a file and extracting a valid file based on the file ID assigned to the block at the time of mounting has already been described. In addition, when there is a file with the same name, the last written file is assumed to be a valid file, so that a problem does not occur even if the power is cut off when writing or erasing the file. Furthermore, regarding the blocks that make up a file that is not valid, a method of reusing the file in the order in which the file was written was described.

これらの方法はそれぞれ独立しているが、ユニークなファイルIDに基づいて、ファイルの書き込み順が判断できるようにしておけば、一度に全てを満たすことができる。特に、ファイルIDは再利用することなく、ファイルの書き込みが行われるごとに新たなものを割り当て、さらに、ファイルIDは、単調増加、または、単調減少するものが好ましい。   These methods are independent of each other. However, if the file writing order can be determined based on the unique file ID, all of them can be satisfied at once. In particular, it is preferable that a new file ID is assigned each time a file is written without reusing the file ID, and that the file ID monotonously increase or monotonously decrease.

そこで、本実施の形態によるファイルシステムにおいては、ファイルID付与手段が付与するファイルIDは、過去に割り当てた最大ファイルID+1とし、ファイルIDの大きさに基づいて、ファイルの書き込まれた順番を判断するファイル書き込み順判定手段を設けることを特徴とする。   Therefore, in the file system according to the present embodiment, the file ID assigned by the file ID assigning unit is set to the maximum file ID + 1 assigned in the past, and the order in which the files are written is determined based on the size of the file ID. A file writing order determining means is provided.

ファイル書き込み中の電源断で生成された、あるいは、ファイルの更新や削除により必要がなくなった、無効なファイルを構成するブロックは、そのまま放置しておき、新たな書き込みでブロックが必要となったときに、そのようなブロックを再利用するという方式では、特定のブロックが何度も再利用されることがないようにするのが望ましい。ファイル(ブロック)にファイルIDを割り当てておくと、不要な古いブロックから再利用させることが可能となる。マウント時もそれにならうようにする。これにより、ブロック再利用時に、適切なブロック割り当てが可能となるという利点がある。すなわち、ウエアレベリングが可能となる。   When a block that constitutes an invalid file that was generated due to a power interruption during file writing, or no longer needed due to file update or deletion, is left as it is, and a block is required for new writing In addition, in the method of reusing such a block, it is desirable that a specific block is not reused many times. If a file ID is assigned to a file (block), it can be reused from an unnecessary old block. Follow it when mounting. Thereby, there is an advantage that appropriate block allocation can be performed at the time of block reuse. That is, wear leveling is possible.

図17は、本実施の形態によるファイルシステムにおける、ウエアレベリング対応のファイル書き込み時のブロック接続例を示す図である。図17(A)は、ファイル書き込み前の構成情報の例を示す図である。図17(A)に示すように、イレースブロックリストは、ブロックA(AR1)、ブロックB(AR2)、ブロックC(AR3)、ブロックD(AR4)、ブロックG(AR4)と繋がれているリストとなっている。一方、ファイル1は、ファイル名‘BB’のファイルであって、ブロックE(AR5)、ブロックF(AR6)とつながれて構成されている。ここで、ブロックAからブロックGへとファイルIDが大きくなっている。   FIG. 17 is a diagram showing an example of block connection when writing a file corresponding to wear leveling in the file system according to the present embodiment. FIG. 17A is a diagram illustrating an example of configuration information before file writing. As shown in FIG. 17A, the erase block list is a list connected to block A (AR1), block B (AR2), block C (AR3), block D (AR4), and block G (AR4). It has become. On the other hand, the file 1 is a file having the file name “BB” and is connected to the block E (AR5) and the block F (AR6). Here, the file ID increases from block A to block G.

図17(B)は、ファイル書き込み完了直後のファイル構成情報の例を示す図である。ブロックは、図17(A)のイレースブロックリストにつながれているブロックのうちのファイルIDが小さいブロック(ブロックAからGに向けてファイルIDが大きい)から再利用を行うようにする。ファイル1は図17(A)の構成と同じであり、ファイル2は、ファイル1と同名‘BB’であり、ブロック番号の小さな順番にイレースブロックリストからブロックAとブロックBとを利用する。   FIG. 17B is a diagram illustrating an example of file configuration information immediately after file writing is completed. Of the blocks connected to the erase block list in FIG. 17A, the block is reused from the block with the smaller file ID (the file ID is larger from block A to G). The file 1 has the same configuration as that shown in FIG. 17A, the file 2 has the same name 'BB' as the file 1, and uses the block A and the block B from the erase block list in ascending order of block numbers.

次いで、図17(C)に示すように、ファイル構成情報を更新する。すなわち、ファイル1はファイル情報を消去(無効化)し、それまで含まれていたブロックをイレースブロックリストに挿入する。イレースブロックのリストには、ブロックEとブロックFとは、ファイル書き込み順判定手段により判定されたファイルIDの大きさの順番に基づいてブロックDとブロックGとの間に挿入される。そして、ファイル2は、ブロックAとブロックBとから構成される。   Next, as shown in FIG. 17C, the file configuration information is updated. That is, the file 1 deletes (invalidates) the file information, and inserts the block included up to that point into the erase block list. In the erase block list, the block E and the block F are inserted between the block D and the block G based on the order of the size of the file ID determined by the file writing order determining means. File 2 is composed of block A and block B.

尚、ファイル2をさらに更新すると、ブロックAとブロックBとは、ファイルIDがブロックGよりも大きくなるため、イレースブロックリストにおいてはブロックGの後につながれることになる。   If the file 2 is further updated, the file ID of the block A and the block B becomes larger than that of the block G, so that the block A is connected after the block G in the erase block list.

書き込み処理について、再び図24を参照しながら説明する。まず、ステップS101において、書き込み処理を開始する。次いで、ステップS102においてユニークなファイルIDを取得する。ここで、新たに取得するファイルIDは、ファイルシステムが過去に割り当てた最大ファイルID+1とする。ステップS103において、フリーブロックリストが空か否かを判定する。フリーブロックリストが空であれば(YES)、ステップS104に進み、フリーブロックリストではなくイレースブロックリストからブロックを取り出し、ステップS106においてブロックを消去し、ステップS107においてブロック情報を生成する。ステップS103でNOの場合にはステップS105に進み、フリーブロックリストからブロックを取り出し、ステップS107に進みブロック情報を生成する。   The writing process will be described again with reference to FIG. First, in step S101, a writing process is started. In step S102, a unique file ID is acquired. Here, the newly acquired file ID is assumed to be the maximum file ID + 1 previously assigned by the file system. In step S103, it is determined whether or not the free block list is empty. If the free block list is empty (YES), the process proceeds to step S104, a block is extracted from the erase block list instead of the free block list, the block is deleted in step S106, and block information is generated in step S107. If NO in step S103, the process proceeds to step S105, a block is extracted from the free block list, and the process proceeds to step S107 to generate block information.

次いで、ステップS108においてブロック情報とデータをブロックへ書き込み、ステップS109において、書き込みデータが残っているか否かを判定する。次いで、ステップS110において、書き込み完了フラグを先頭ブロックに書き込み、ステップS111においてファイルIDを更新し、ファイルシステムにファイルIDを消費したことを伝える。ステップS112において、ファイル構成情報に新ファイルを追加する。ステップS113において、旧ファイルが存在するか否かを判定し、存在すれば(YES)ステップS114に進み旧ファイル構成ブロックをイレースブロックリストに追加し、ステップS115においてファイル構成情報から旧ファイルを削除し、書き込みを終了する(ステップS116)。旧ファイルが存在しない場合には、そのまま処理を終了する(ステップS116)。上記ファイルの書き込み処理で説明したように、ファイルを書き込むために使用するブロックは、フリーブロックリストから取得している。フリーブロックリストにブロックがない場合は、イレースブロックリストからブロックを取り出し、ブロックを消去した後、フリーブロックリストにつなげ、フリーブロックリストから取得している。   Next, in step S108, block information and data are written to the block, and in step S109, it is determined whether or not write data remains. Next, in step S110, a write completion flag is written in the first block, and in step S111, the file ID is updated, and the file system is informed that the file ID has been consumed. In step S112, a new file is added to the file configuration information. In step S113, it is determined whether or not the old file exists. If yes (YES), the process proceeds to step S114, where the old file configuration block is added to the erase block list, and in step S115, the old file is deleted from the file configuration information. The writing is terminated (step S116). If the old file does not exist, the process is terminated as it is (step S116). As described in the file writing process, the block used for writing the file is obtained from the free block list. If there is no block in the free block list, the block is extracted from the erase block list, erased, and connected to the free block list to obtain from the free block list.

これが意味するところは、NAND型フラッシュメモリの領域全体を初期化した状態では、全てのブロックがフリーブロックリストにつながれており、それらを使い切った後、初めて、イレースブロックリストにあるブロックが再利用されるということである。また、イレースブロックリストにあるブロックは、ファイルIDの順番でつながれている。ファイルIDが同じブロックに関しては、その中でもブロック番号の順番につながれている。すなわち、再利用されるブロックというのは、消去可能なブロックのうち、最も以前に書き込みが行われたブロックということになる。   This means that in the state where the entire area of the NAND flash memory is initialized, all the blocks are connected to the free block list, and the blocks in the erase block list are not reused until they are used up. That is. Further, the blocks in the erase block list are connected in the order of file ID. Blocks having the same file ID are connected in the order of block numbers. In other words, the block to be reused is the block that has been written most recently among the erasable blocks.

次いで、マウント処理の流れについて図18を参照しながら説明を行う。ステップS61において、ファイルの再構成処理を開始する。次いで、ステップS62においてブロックを取り出し、ステップS63において、取り出したブロックが有効なブロックであるか否かを判定する。有効でない場合には(NO)ステップS69に進む。有効な場合には(YES)、ステップS64においてブロック情報を読み込み、ステップS65において新規ファイルIDであるか否かを判定する。新規ファイルIDでない場合には(NO)、ステップS68に進む。新規ファイルIDであれば(YES)、ステップS66においてファイルIDを登録し、ステップS67においてファイルIDを更新し、ステップS68に進む。ステップS68においては、該当ファイルIDに取り出したブロックを追加する。   Next, the flow of the mounting process will be described with reference to FIG. In step S61, a file reconstruction process is started. Next, a block is extracted in step S62, and in step S63, it is determined whether or not the extracted block is a valid block. If not valid (NO), the process proceeds to step S69. If it is valid (YES), block information is read in step S64, and it is determined whether the file ID is a new file ID in step S65. If it is not a new file ID (NO), the process proceeds to step S68. If it is a new file ID (YES), the file ID is registered in step S66, the file ID is updated in step S67, and the process proceeds to step S68. In step S68, the extracted block is added to the corresponding file ID.

ステップS69においては、全ブロックの処理が完了したかどうかを判定し、NOの場合にはステップS62に戻る。YESの場合には、ステップS70に進み、登録されたファイルIDを大きな順に取り出す。すなわち、ステップS70では、ファイル書き込み順判定手段を用いて、最後に書き込まれたファイルから順に抽出し、以降の処理を続けることになる。ステップS71において、全ブロックが存在するか否かを判定し、YESであればステップS72に進み同名ファイルが存在するか否かを判定する。次いで、ステップS73において該当ファイルIDのファイル構成情報を有効にし、ステップS75に進む。NOであれば、ステップS74に進み、本ファイル構成ブロックをファイルIDの順番にイレースブロックリストに挿入し、ステップS75に進む。ステップS75においては、全ファイルIDの処理が完了したか否かを判定し、NOであればステップS70に戻り、YESであればステップS76において再構成を終了する。   In step S69, it is determined whether or not all blocks have been processed. If NO, the process returns to step S62. If YES, the process proceeds to step S70, and registered file IDs are extracted in descending order. That is, in step S70, the file writing order determination unit is used to sequentially extract the last written file, and the subsequent processing is continued. In step S71, it is determined whether all blocks exist. If YES, the process proceeds to step S72 to determine whether a file with the same name exists. Next, in step S73, the file configuration information of the corresponding file ID is validated, and the process proceeds to step S75. If NO, the process proceeds to step S74, the file configuration blocks are inserted into the erase block list in the order of file IDs, and the process proceeds to step S75. In step S75, it is determined whether or not the processing of all file IDs has been completed. If NO, the process returns to step S70, and if YES, the reconstruction is terminated in step S76.

以上のようにすれば、ファイルの書き込み中に電源断が発生した場合、その書き込みで消費されたブロックは次回のマウント処理時に、イレースブロックリストの最後につながれることになる。なぜなら、イレースブロックリストのブロックはファイルIDの順番でつながれており、電源断が発生した最後の書き込みで使用したファイルIDは、その時点で最大であったからである。これは、それらのブロックが再利用されるのは、ファイル書き込み時点でのイレースブロックリストのブロックを使い切ってからということに他ならない。つまり、特定ブロックだけが何度も再利用されるということを防ぐことができる。   In this way, if a power interruption occurs while writing a file, the block consumed by the writing is connected to the end of the erase block list at the next mount processing. This is because the blocks in the erase block list are connected in the order of the file IDs, and the file ID used in the last writing when the power interruption occurred is the maximum at that time. This is because the blocks are reused after the blocks in the erase block list at the time of file writing are used up. That is, it is possible to prevent only a specific block from being reused many times.

ここまで、バッドブロックの扱いに関して、特に言及しなかったので、ここで簡単に説明する。   Up to this point, no particular mention has been made regarding the handling of bad blocks, so a brief description will be given here.

NAND型フラッシュメモリには、出荷時から存在する初期バッドブロックと、消去や書き込みを繰り返しているうちに磨耗がおきて発生する後天的なバッドブロックがある。これらは、データを正しく読み出すことができない可能性のあるブロックであり、使用を控える必要がある。このようなブロックにはOOB領域に自身がバッドブロックであることが記録されている。このようなバッドブロックはマウント処理時に検出できるので、これらはバッドブロックリストに入れて、以後は使用しないようにすればよい。   The NAND flash memory includes an initial bad block that exists from the time of shipment and an acquired bad block that occurs due to wear during repeated erasing and writing. These are blocks that may not be able to read data correctly, and should not be used. Such a block records that it is a bad block in the OOB area. Since such bad blocks can be detected during the mounting process, these should be put in the bad block list and not used thereafter.

初期バッドブロックは出荷時にバッドブロックであることが記録されているが、後天的なバッドブロックは書き込み時に検出し、記録しなければならない。すなわち、ブロックにデータを書き込んだ後、もう一度同じブロックを読み込み、ベリファイを行えばよい。このとき、書き込みと読み込みは正常に行われたにもかかわらず、ベリファイにおいてエラーが出たものが、後天的なバッドブロックとなる。このようなブロックは、先頭ページのOOB領域にバッドブロックであることを記録しバッドブロックリストに入れるとともに、以後は、使用しないようにすればよい。一旦、OOB領域にバッドブロックであることが記録されると、電源断後のマウント処理においても、そのブロックはバッドブロックであることが検出できるので、使用されることはない。   Although the initial bad block is recorded as a bad block at the time of shipment, the acquired bad block must be detected and recorded at the time of writing. That is, after data is written to a block, the same block is read again and verified. At this time, although the writing and reading are performed normally, an error occurred in the verification becomes an acquired bad block. Such a block may be recorded as a bad block in the OOB area of the first page, put in the bad block list, and not used thereafter. Once it is recorded in the OOB area that it is a bad block, it can be detected that the block is a bad block even in the mounting process after the power is turned off, so that it is not used.

以上に説明したように、本実施の形態によるファイルシステムにおいては、高速なファイル処理を行うことができる。また、ウエアレベリングが可能になる。さらに、ファイル書き込み中に電源断が発生してもファイル情報を再構成可能でありファイルの損失や破壊も生じないという利点がある。   As described above, the file system according to the present embodiment can perform high-speed file processing. Also, wear leveling becomes possible. Furthermore, there is an advantage that the file information can be reconfigured even if the power is cut off during the file writing, and the file is not lost or destroyed.

次に、本発明の第2の実施の形態によるファイルシステムについて説明する。第1の実施の形態では、ファイルの消去に関しては、「消去を示すファイル」を書き込むことで実現しているが、セキュリティの面から、実際に、物理的にデータを消去したいという要求もあることが考えられる。   Next, a file system according to the second embodiment of the present invention will be described. In the first embodiment, file erasure is realized by writing “file indicating erasure”, but there is also a demand for physically erasing data in terms of security. Can be considered.

この場合に、ファイルの消去時には、「消去を示すファイル」を書き込む代わりに、実際にそのファイルが使用しているブロックを消去するという方法もある。しかしながら、ブロックを消去した後に電源断が発生すると、これらのブロックは次回電源投入の際のファイルシステムのマウント処理時にフリーブロックとみなされるため、それらのブロックがすぐに再利用されてしまう。さらに、再利用されたこれらのブロックが構成するファイルが消去された後に電源断が発生すると、再び、これらのブロックがすぐに再利用されることになる。   In this case, at the time of erasing the file, there is a method of erasing a block actually used by the file instead of writing “file indicating erasure”. However, if the power is cut off after the blocks are erased, these blocks are regarded as free blocks when the file system is mounted next time the power is turned on, and these blocks are immediately reused. In addition, if a power failure occurs after the files constituting these reused blocks are erased, these blocks are reused immediately again.

すなわち、ファイルの書き込み、そのファイルの消去、電源断、電源投入、というサイクルを繰り返すと、特定のブロックが何度も繰り返し利用されることになり、書き込み回数に制限があるフラッシュメモリにとっては都合が悪い。   That is, if you repeat the cycle of writing a file, erasing the file, turning off the power, turning on the power, a specific block will be used over and over again, which is convenient for flash memory with a limited number of writes. bad.

そこで、本発明の第2の実施の形態によるファイルシステムにおいては、ファイルの消去は「ファイルを消去したことを示すファイル」を書き込むことで行うとともに、過去のファイルに関してはブロックの消去も行う。このとき、消去されるブロックのブロックIDを前記ファイルにも付加することを特徴とする。すなわち、ファイルの消去は、「消去を示すファイル」を書き込むことと、消去したいファイルが利用しているブロックを実際に消去することと、「消去を示すファイル」の中に、実際に消去されるブロックのブロックIDを付加しておくことで実現する。さらには、消去したブロックと、「消去を示すファイル」を構成するブロックは、イレースブロックリストに順につなぐ。このようにしておけば、消去されたブロックが再利用される前に電源断があった場合でも、次回のマウント処理時には、消去されたブロックをフリーブロックリストではなく、イレースブロックリストの適切な位置につなぐことができる。なぜなら、「消去を示すファイル」を構成するブロックは、マウント処理時にイレースブロックリストにつながれるので、そのようなブロックがあれば、そのファイルに付加されている消去したブロックの情報を取り出し、その直前に挿入することで、電源断時のイレースブロックリストを再構成できるからである。具体的には、図19(A)に示すように、ファイル消去前の構成情報として、イレースブロックリストにブロックAとブロックBとブロックCとブロックDとブロックGとが、AR1〜4までのようにつながっているとする。また、ファイル名45が‘BB’であるファイル1が、ブロックEとブロックFから構成されているとする。   Therefore, in the file system according to the second embodiment of the present invention, the file is erased by writing “file indicating that the file has been erased”, and the block is erased for the past file. At this time, the block ID of the block to be erased is also added to the file. In other words, the file is erased by writing “file indicating erasure”, actually erasing the block used by the file to be erased, and “file indicating erasure”. This is realized by adding a block ID of the block. Further, the erased block and the block constituting the “file indicating erasure” are sequentially connected to the erase block list. In this way, even if the power is cut off before the erased block is reused, the erased block is not located in the free block list at the appropriate position in the erase block list during the next mounting process. Can be connected. Because the blocks that make up the “file indicating erasure” are connected to the erase block list during the mount process, if there is such a block, the information of the erased block added to the file is extracted and immediately before that This is because the erase block list when the power is turned off can be reconfigured by inserting the data into. Specifically, as shown in FIG. 19A, as configuration information before erasing the file, blocks A, B, C, D, and G are included in the erase block list as AR1 to AR4. Suppose that Further, it is assumed that the file 1 whose file name 45 is “BB” is composed of a block E and a block F.

ここで、図19(B)に示すように、ファイル消去中の構成情報として、ファイル1を消去すると、ファイル1を構成していたブロックEとブロックFがイレースブロックリストにつながれ、ブロックAから構成された、「消去を示すファイル」であるファイル2が新たに生成される。このとき、ブロックAはイレースブロックリストの先頭のブロックが取り出されたものである。さらに、ブロックAには、ブロックEとブロックFを消去したという情報を付加しておく。この後、実際に、ブロックEとブロックFを消去する。   Here, as shown in FIG. 19B, when the file 1 is deleted as the configuration information during the file deletion, the block E and the block F constituting the file 1 are connected to the erase block list. The file 2 that is the “file indicating erasure” is newly generated. At this time, the block A is obtained by extracting the head block of the erase block list. Further, information indicating that the block E and the block F are erased is added to the block A. Thereafter, the block E and the block F are actually erased.

最終的には、図19(C)に示すように、ファイル消去後の構成情報として、イレースブロックリストは図19(B)のものにブロックAが加わった状態になる。   Finally, as shown in FIG. 19C, the erase block list is added with the block A in FIG. 19B as the configuration information after erasing the file.

ブロックAには、ブロックEとブロックFとを消去したという情報を格納しておくため、電源断が起こった場合でもイレースブロックリストの再構築は可能になる。   The block A stores information indicating that the block E and the block F have been erased, so that the erase block list can be reconstructed even when the power is cut off.

図26を用いて、消去処理のフローを説明する。まず、ステップS141において、消去処理を開始する。次いで、ステップS142においてファイルIDを取得する。ステップS143において、フリーブロックリストが空か否かを判定する。フリーブロックリストが空であれば(YES)、ステップS144に進み、フリーブロックリストではなくイレースブロックリストからブロックを取り出し、ステップS146においてブロックを消去し、ステップS147においてブロック情報を生成する。この時、ファイルサイズは0とする。ステップS143でNOの場合にはステップS145に進み、フリーブロックリストからブロックを取り出し、ステップS147に進みブロック情報を生成する。この時、ファイルサイズは0とする。次いで、ステップS148においてブロック情報とデータをブロックへ書き込む。このとき、データとして、実際に消去すべきブロックのブロックIDを付加しておく。次にステップS149において、書き込みデータが残っているか否かを判定する。次いで、ステップS150において、書き込み完了フラグを先頭ブロックに書き込み、ステップS151においてファイルIDを更新し、ステップS152において旧ファイル構成ブロックをイレースブロックリストに追加し、ステップS153においてイレースブロックリスト内にある同名のファイルを構成するブロックを消去し、ステップS154において消去したブロックをイレースブロックリストの最後につなぎなおし、ステップS155においてファイル構成ブロックをイレースブロックリストに追加するとともに、ステップS156においてファイル構成情報から旧ファイルを削除し、書き込みを終了する(ステップS157)。   The flow of the erasure process will be described using FIG. First, in step S141, an erasing process is started. Next, a file ID is acquired in step S142. In step S143, it is determined whether or not the free block list is empty. If the free block list is empty (YES), the process proceeds to step S144, a block is extracted from the erase block list instead of the free block list, the block is deleted in step S146, and block information is generated in step S147. At this time, the file size is set to zero. If NO in step S143, the process proceeds to step S145, a block is extracted from the free block list, and the process proceeds to step S147 to generate block information. At this time, the file size is set to zero. Next, in step S148, block information and data are written to the block. At this time, the block ID of the block to be actually erased is added as data. Next, in step S149, it is determined whether write data remains. Next, in step S150, the write completion flag is written to the first block, the file ID is updated in step S151, the old file configuration block is added to the erase block list in step S152, and the same name in the erase block list is added in step S153. The blocks constituting the file are erased, the block erased in step S154 is reconnected to the end of the erase block list, the file configuration block is added to the erase block list in step S155, and the old file is added from the file configuration information in step S156. The data is deleted and the writing is terminated (step S157).

ステップS154において、消去したブロックをイレースブロックリストにつなぎなおす(最後に追加する)ことで、このまま電源断が発生しない限りは、イレースブロックリストに最初からあったブロックを使いつくすまで、これらの消去したブロックが使用されることはない。一方、途中で電源断があった場合は、マウント処理時、次に説明する手順で、これらのブロックをフリーブロックリストからイレースブロックリストにつなぎなおすことができ、イレースブロックリストを電源断が発生した状態に戻すことができる。これにより、ファイルの消去時にブロックの消去を行った場合でも、同一のブロックだけが何度も再利用されることを防ぐことができる。   In step S154, the erased block is reconnected to the erase block list (added to the end), so that the erased block is erased until the first block in the erase block list is used up unless the power is cut off. Blocks are never used. On the other hand, if the power is cut off halfway, during the mounting process, these blocks can be reconnected from the free block list to the erase block list according to the procedure described below. It can be returned to the state. As a result, even when a block is erased when a file is erased, only the same block can be prevented from being reused many times.

次に、マウント処理の流れについて図20を参照しながら説明を行う。まず、ステップS81において再構成を開始し、ステップS82においてブロックを取り出す。ステップS83においてフリーブロックであるか否かを判定する。フリーブロックであれば(YES)、ステップS92に進み、フリーブロックリストに追加しステップS90に進む。フリーブロックでなければ(NO)、ステップS84において、有効なブロックかどうかを判定する。有効なブロックであれば(YES)ステップS85に進み、有効なブロックでなければ(NO)ステップS91においてイレースブロックリストに追加し、ステップS90に進む。ステップS85においては、ブロック情報を読み込み、ステップS86において、新規ファイルIDであるか否かを判定する。新規ファイルIDであればステップS87でファイルIDを登録し、ステップS88で該当ファイルIDにブロックを追加する。次いで、ステップS90において、全ブロックの処理が完了したか否かを判定し、NOであればステップS82に戻り、YESであれば、図21のステップに移行する。   Next, the flow of the mounting process will be described with reference to FIG. First, reconstruction is started in step S81, and a block is taken out in step S82. In step S83, it is determined whether the block is a free block. If it is a free block (YES), the process proceeds to step S92, added to the free block list, and proceeds to step S90. If it is not a free block (NO), it is determined in step S84 whether it is a valid block. If it is a valid block (YES), the process proceeds to step S85. If it is not a valid block (NO), it is added to the erase block list in step S91, and the process proceeds to step S90. In step S85, block information is read. In step S86, it is determined whether the file ID is a new file ID. If it is a new file ID, the file ID is registered in step S87, and a block is added to the corresponding file ID in step S88. Next, in step S90, it is determined whether or not the processing of all blocks has been completed. If NO, the process returns to step S82, and if YES, the process proceeds to the step in FIG.

図21は、図20に続く処理の流れを示すフローチャート図である。ステップS90でYESであれば、ステップS91に進み、登録されたファイルIDを大きな順(新しく作成された順番)で取り出す。ステップS92において、全ブロックが存在するか否かを判定し、NOの場合にはステップS100に進み、ファイル構成ブロックをイレースブロックリストに追加し、ステップS96に移行する。ステップS92においてYESの場合には、ステップS93において同名ファイルが登録済みであるか否かを判定し、NOであれば、ステップS94に進み該当ファイルIDのファイル構成情報を有効にし、ステップS95において、消去ファイルであるか否かを判定し、NOであれば、ステップS96に進む。ステップS93でYESの場合には、ステップS98に進み、消去ファイルであるか否かを判定する。NOの場合にはステップS100に進む。YESの場合には、ステップS99に進み、本ファイルで記録されているブロックをフリーブロックリストから取り出しイレースブロックリストに追加しステップS100に進む。ステップS96において全IDの処理が完了したか否かを判定し、完了していなければ(NO)ステップS91に戻り、完了していれば(YES)、ステップS97において再構成処理を終了する。   FIG. 21 is a flowchart showing the flow of processing following FIG. If “YES” in the step S90, the process proceeds to a step S91, and the registered file IDs are extracted in a descending order (a newly created order). In step S92, it is determined whether or not all blocks exist. If NO, the process proceeds to step S100, the file configuration block is added to the erase block list, and the process proceeds to step S96. In the case of YES in step S92, it is determined whether or not the same name file has been registered in step S93. If NO, the process proceeds to step S94 to validate the file configuration information of the corresponding file ID. In step S95, It is determined whether the file is an erasure file. If NO, the process proceeds to step S96. If “YES” in the step S93, the process proceeds to a step S98 to determine whether or not the file is an erased file. If NO, the process proceeds to step S100. If YES, the process proceeds to step S99, the block recorded in this file is taken out from the free block list and added to the erase block list, and the process proceeds to step S100. In step S96, it is determined whether or not all ID processes have been completed. If not completed (NO), the process returns to step S91. If completed (YES), the reconstruction process is terminated in step S97.

なお、ステップS100にて、イレースブロックリストに追加されるブロックとは、ステップS92から来る、全ブロックが存在しないファイルを構成するブロック、ステップS98から来る、妥当なファイルであるが同名の新しいファイルが存在する場合のそのファイルを構成するブロック、ステップS95から来る、最も新しい消去ファイルを構成するブロックであり、すなわち、全ブロックが存在する有効なファイルであり、かつ、消去ファイルでないファイルを構成するブロック以外のブロックが、イレースブロックリストにつながれることになる。   In step S100, the block added to the erase block list is a block that constitutes a file that does not have all the blocks that come from step S92, and a new file that has the same name but that is a valid file that comes from step S98. The block that constitutes the file if it exists, the block that constitutes the newest erased file coming from step S95, that is, the block that constitutes a file that is a valid file in which all blocks exist and is not an erased file Other blocks are linked to the erase block list.

上述を基本形とすると、これの発展形として、上記ステップS148において、「消去を示すファイル」には消去するブロックのブロックIDだけでなく、そのブロックのファイルIDとブロック番号も付加しておき、また、上記ステップS152において、イレースブロックにつなげるときは、ファイルIDとブロック番号の順番でイレースブロックリストにブロックをつなげ、さらに、上記ステップS154において、ブロックを消去した後、つなぎなおすことはしないという方法も考えられる。この場合は、電源断発生後のマウント時、消去されたブロックをフリーブロックリストからイレースブロックリストにつなぎなおす際には、ブロック番号と一緒に保存されているファイルIDとブロック番号を用いてつなぎなおすことで、やはり、イレースブロックリストを電源断があった状態に戻すことができる。この方法では、ブロックの再利用の順番が、ファイル消去時にブロックを消去しない場合と完全に同じ順番になりわかりやすいというメリットがある反面、実装が少し複雑になるというデメリットがある。   If the above-mentioned is a basic form, as an extension of the above, in step S148, not only the block ID of the block to be erased but also the file ID and block number of the block to be erased are added to the “file indicating erase”. In the above step S152, when connecting to the erase block, the block is connected to the erase block list in the order of the file ID and the block number. Further, in step S154, after the block is erased, the block is not reconnected. Conceivable. In this case, when remounting the erased block from the free block list to the erase block list at the time of mounting after the power failure occurs, reconnect using the file ID and block number stored together with the block number. Thus, the erase block list can be returned to the state where the power is cut off. This method has the advantage that the order of block reuse is completely the same as the case of not erasing blocks when erasing files and is easy to understand, but has the disadvantage that implementation is a little complicated.

基本形でも発展形でも、同一のブロックだけが何度も再利用されるということはないので、目的に合うように、どちらの方法を選択してもよい。   In both the basic form and the advanced form, only the same block is never reused many times, so either method may be selected to suit the purpose.

以上に説明したように、本実施の形態によるファイルシステムにおいては、高速なファイル処理を行うことができる。また、ウエアレベリングが可能になる。さらに、ファイル書き込み中に電源断が発生してもファイル情報を再構成可能でありファイルの損失や破壊も生じない。また、ファイルの消去では実際にデータを消去するため、セキュリティの面でも安心できるという利点がある。   As described above, the file system according to the present embodiment can perform high-speed file processing. Also, wear leveling becomes possible. Furthermore, even if the power is cut off during file writing, the file information can be reconfigured, and the file is not lost or destroyed. Also, erasing a file has the advantage that it can be relieved in terms of security because data is actually erased.

本発明は、電子機器に用いられるフラッシュメモリのファイルシステムに利用可能である。   The present invention can be used for a file system of a flash memory used in an electronic device.

本発明の第1の実施の形態によるファイルシステムを適用可能な機器の一例として示す電子機器の一構成例を示す機能ブロック図である。It is a functional block diagram which shows the example of 1 structure of the electronic device shown as an example of the apparatus which can apply the file system by the 1st Embodiment of this invention. NAND型フラッシュメモリの領域構成例を示す図である。It is a figure which shows the area structural example of a NAND type flash memory. ヘッダ情報のバリエーションを示す図である。It is a figure which shows the variation of header information. 本実施の形態によるファイルシステムにおけるブロックの一構成例を示す図である。It is a figure which shows one structural example of the block in the file system by this Embodiment. 例として示したブロック1から6までに関するブロック構成例を示す図である。It is a figure which shows the block structural example regarding the block 1-6 shown as an example. ファイル構成情報の構成例と、ファイル構成情報から再生成できるファイルの構成例を示す図である。It is a figure which shows the structural example of a file structure information, and the structural example of the file which can be regenerated from file structure information. ファイル構成情報再構築の処理の流れを示すフローチャート図である。It is a flowchart figure which shows the flow of a process of file structure information reconstruction. 図8(A)は、上記手法を実現するためのブロック構成例を示す図である。図8(B)は、4種類のブロック1〜4までについての構成例を示す図である。FIG. 8A is a diagram illustrating a block configuration example for realizing the above technique. FIG. 8B is a diagram illustrating a configuration example of four types of blocks 1 to 4. 図9(A)は、このようなブロック構成例を示す図である。図9(B)は、ブロックAからブロックFまでの6つのブロックの構成例を示す図である。FIG. 9A shows an example of such a block configuration. FIG. 9B is a diagram illustrating a configuration example of six blocks from block A to block F. 図10(A)は、ブロックA、B、Cからなるファイル1の構成例を示す図であり、図10(B)は、ブロックD、E、Fからなるファイル2の構成例を示す図である。10A is a diagram illustrating a configuration example of the file 1 including the blocks A, B, and C, and FIG. 10B is a diagram illustrating a configuration example of the file 2 including the blocks D, E, and F. is there. ファイル書き込み前のファイル構成情報の例を示す図である。It is a figure which shows the example of the file structure information before file writing. ファイル書き込み中の構成情報(1)を示す図である。It is a figure which shows the structure information (1) during file writing. 書き込み中の構成情報(2)を示す図である。It is a figure which shows the structure information (2) in writing. ファイル書き込み完了直後の構成情報例を示す図であるIt is a figure which shows the example of structure information immediately after file writing completion ファイル1を無効化処理し、ファイル2を引き続き利用することで、ファイル1からファイル2への更新を行う様子を示す図である。It is a figure which shows a mode that the update from the file 1 is performed by invalidating the file 1 and using the file 2 continuously. ファイル書き込み処理時の構成情報の例を示す図である。It is a figure which shows the example of the structure information at the time of a file write process. 本実施の形態によるファイルシステムにおける、ウエアレベリング対応のファイル書き込み時のブロック接続例を示す図である。It is a figure which shows the example of a block connection at the time of the file writing corresponding to wear leveling in the file system by this Embodiment. ファイルの更新を考慮した、ファイル構成情報再構築の処理の流れを示すフローチャート図である。It is a flowchart figure which shows the flow of a process of file structure information reconstruction in consideration of the update of a file. ファイル消去処理におけるファイルの構成例を示す図である。It is a figure which shows the structural example of the file in a file deletion process. ファイルの消去を考慮した、ファイル構成情報再構築の処理の流れを示すフローチャート図である。It is a flowchart figure which shows the flow of a process of file structure information reconstruction in consideration of the deletion of a file. 図20に続く処理の流れを示すフローチャート図である。It is a flowchart figure which shows the flow of the process following FIG. 磁気記憶装置のファイルシステムのイメージを示す図である。It is a figure which shows the image of the file system of a magnetic storage apparatus. フラッシュメモリのファイルシステムのイメージを示す図である。It is a figure which shows the image of the file system of flash memory. ファイル書き込み処理の流れを示すフローチャート図である。It is a flowchart figure which shows the flow of a file writing process. ファイル消去処理の流れを示すフローチャート図である。It is a flowchart figure which shows the flow of a file deletion process. ブロックの消去を伴うファイル消去処理の流れを示すフローチャート図である。It is a flowchart figure which shows the flow of the file deletion process accompanied by deletion of a block.

符号の説明Explanation of symbols

A…電子機器、1…制御装置(CPU)、3…フラッシュメモリ、5…RAM(メモリ)、7…入力手段、11…表示手段、15…データ入出力手段。 DESCRIPTION OF SYMBOLS A ... Electronic device, 1 ... Control apparatus (CPU), 3 ... Flash memory, 5 ... RAM (memory), 7 ... Input means, 11 ... Display means, 15 ... Data input / output means.

Claims (6)

メモリ領域が複数のブロックに分割されており、メモリ領域に書き込まれたデータの消去をブロック単位で行い、ブロックが複数のページに分割されており、メモリ領域へのデータの書き込みはページ単位で行うフラッシュメモリ上のファイルシステムであって、
少なくとも、ファイルに付与されるファイルシステムで一意のファイルIDと、ファイル内のブロックの接続の順番を示すブロック番号と、を含むブロック情報を、ブロックに対して付加するブロック情報付加手段と、
前記ブロック情報に基づいてファイル構成を表すファイル構成情報を再構築するファイル構成情報再構築手段と
を有することを特徴とするファイルシステム。
The memory area is divided into a plurality of blocks, the data written in the memory area is erased in units of blocks, the block is divided into a plurality of pages, and data is written in the memory area in units of pages. A file system on flash memory,
Block information adding means for adding to the block block information including at least a file ID unique to the file system assigned to the file and a block number indicating the connection order of the blocks in the file;
A file system comprising: file structure information reconstructing means for reconstructing file structure information representing a file structure based on the block information.
ブロックへのデータの書き込み時に各ブロックの先頭ページと先頭以外のページにマジックナンバーを付加するマジックナンバー付加手段と、
先頭ページから順番にデータを書き込んでいきページにデータを書き込むたびにデータのベリファイを行うページベリファイ手段と、
各ブロックの先頭ページと先頭以外のページにマジックナンバーが付加されているか否かに基づいてブロックの有効性のチェックするブロックチェック手段と
を有することを特徴とする請求項1に記載のファイルシステム。
Magic number adding means for adding a magic number to the first page of each block and pages other than the top when writing data to the block;
A page verifying unit that sequentially writes data from the first page and verifies the data each time data is written to the page;
2. The file system according to claim 1, further comprising block check means for checking the validity of the block based on whether or not a magic number is added to the first page and each page other than the first page of each block.
ブロックに前記マジックナンバーを書き込むための少なくとも第1及び第2のマジックナンバー領域を、データを書き込むためのデータ領域を挟んで設けることを特徴とする請求項1に記載のファイルシステム。   2. The file system according to claim 1, wherein at least first and second magic number areas for writing the magic number in a block are provided across a data area for writing data. 前記第1のマジックナンバー領域よりも前の部分にブロック情報を書き込む領域を設けることを特徴とする請求項3に記載のファイルシステム。   4. The file system according to claim 3, wherein an area for writing block information is provided in a portion before the first magic number area. 請求項1に記載のファイルシステムを用いたファイル構成情報の再構築方法であって、
ブロックを取り出し、有効なブロックの前記ブロック情報を読み出すステップと、
前記ブロック情報内のファイルIDに基づいて、同じファイルIDを有するブロックを前記ブロック番号の順番につなげるステップと
を有することを特徴とするファイル構成情報の再構築方法。
A method for reconstructing file configuration information using the file system according to claim 1,
Retrieving a block and reading the block information of a valid block;
And reconnecting blocks having the same file ID in the order of the block numbers based on the file IDs in the block information.
請求項3に記載のファイルシステムを用いたブロックの有効性判定方法であって、
前記第1及び第2のマジックナンバーを読み込み、読み込んだ内容に基づいて、マジックナンバーの有効・無効によりブロックにおけるデータの有効性を判定するステップを有することを特徴とするブロックの有効性判定方法。
A block validity determination method using the file system according to claim 3,
A block validity determination method comprising the steps of: reading the first and second magic numbers, and determining the validity of data in the block based on the validity / invalidity of the magic number based on the read contents.
JP2006234738A 2006-08-31 2006-08-31 File system Pending JP2008059228A (en)

Priority Applications (4)

Application Number Priority Date Filing Date Title
JP2006234738A JP2008059228A (en) 2006-08-31 2006-08-31 File system
US12/439,429 US20090265403A1 (en) 2006-08-31 2007-08-20 File system
CN200780038992.5A CN101529395B (en) 2006-08-31 2007-08-20 File system
PCT/JP2007/066113 WO2008026466A1 (en) 2006-08-31 2007-08-20 File system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP2006234738A JP2008059228A (en) 2006-08-31 2006-08-31 File system

Publications (1)

Publication Number Publication Date
JP2008059228A true JP2008059228A (en) 2008-03-13

Family

ID=39241898

Family Applications (1)

Application Number Title Priority Date Filing Date
JP2006234738A Pending JP2008059228A (en) 2006-08-31 2006-08-31 File system

Country Status (2)

Country Link
JP (1) JP2008059228A (en)
CN (1) CN101529395B (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2014044490A (en) * 2012-08-24 2014-03-13 Toshiba Corp Host device and memory device
JP2016062319A (en) * 2014-09-18 2016-04-25 カシオ計算機株式会社 Data reading device, program and data reading method

Families Citing this family (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102253938B (en) * 2010-05-18 2015-05-20 深圳市朗科科技股份有限公司 Method and device for writing and restoring file
CN102122236B (en) * 2011-03-21 2013-08-28 华为数字技术(成都)有限公司 Write request processing method and device
CN103064843B (en) * 2011-10-20 2016-03-16 北京中搜网络技术股份有限公司 Data processing equipment and data processing method
CN103092849A (en) * 2011-10-28 2013-05-08 浙江大华技术股份有限公司 File system cluster management method
CN104615546B (en) * 2015-02-13 2018-04-27 小米科技有限责任公司 file data management method and device
CN107615253B (en) * 2015-06-01 2021-03-12 深圳市大疆创新科技有限公司 System and method for memory architecture
CN107908364B (en) * 2017-11-13 2020-10-23 中国电子科技集团公司第三十研究所 Embedded file system based on norflash
CN110659250B (en) * 2018-06-13 2022-02-22 中国电信股份有限公司 File processing method and system
CN110045918B (en) * 2018-12-03 2021-09-03 蚂蚁金服(杭州)网络技术有限公司 Efficient data unit reusing method and system
CN112035294B (en) * 2020-08-25 2023-12-29 华东计算技术研究所(中国电子科技集团公司第三十二研究所) Security log file system and its implementation method and media
CN112380171B (en) * 2020-12-01 2022-07-15 厦门市美亚柏科信息股份有限公司 A YAFFS file system OOB identification method, terminal device and storage medium
JP2022147909A (en) * 2021-03-24 2022-10-06 キオクシア株式会社 memory system
CN113934371B (en) * 2021-10-08 2024-04-12 福建星网视易信息系统有限公司 Memory, data management method thereof and computer storage medium

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2004280752A (en) * 2003-03-19 2004-10-07 Sony Corp Data storage device, management information updating method in data storage device, and computer program

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2014044490A (en) * 2012-08-24 2014-03-13 Toshiba Corp Host device and memory device
JP2016062319A (en) * 2014-09-18 2016-04-25 カシオ計算機株式会社 Data reading device, program and data reading method
US10120791B2 (en) 2014-09-18 2018-11-06 Casio Computer Co., Ltd. Data read apparatus, data read method, and storage medium storing data read program

Also Published As

Publication number Publication date
CN101529395A (en) 2009-09-09
CN101529395B (en) 2012-07-25

Similar Documents

Publication Publication Date Title
CN101529395B (en) File system
WO2008026466A1 (en) File system
EP1739535B1 (en) File system storing transaction records in flash-like media
JP5162535B2 (en) Method and memory system using memory system
US8667029B2 (en) Optimized startup verification of file system integrity
US7809777B2 (en) File system having deferred verification of data integrity
CN104969181B (en) Repair system, method, and storage device for corrupted drive variable logging
EP1739575B1 (en) File system having inverted hierarchical structure
CN103430178A (en) Data updating method, device and product
CN105009096A (en) Data storage device, data storage method, and vehicle-mounted control device
JP2008262574A (en) High reliability file system
CN108614743A (en) Super data block processing method and device based on NAND flash
JP2008033801A (en) Memory data management device
JP3675375B2 (en) Nonvolatile memory and data rewriting method of nonvolatile memory
JP4157575B2 (en) Wear levelable file system
JP4209908B2 (en) High reliability file system
KR100876212B1 (en) How to update software on read-only file system of mobile communication terminal
CN118733330B (en) Flash memory problem source location methods, devices, media and memory
CN111399758B (en) Data storage device, access device and data processing method
JP2007323380A (en) MEMORY MANAGEMENT DEVICE, MEMORY MANAGEMENT METHOD, AND PROGRAM
JP4502689B2 (en) Data storage device and initialization method thereof

Legal Events

Date Code Title Description
A521 Written amendment

Free format text: JAPANESE INTERMEDIATE CODE: A523

Effective date: 20071225

A02 Decision of refusal

Free format text: JAPANESE INTERMEDIATE CODE: A02

Effective date: 20080304