From cefeada5db633fd3c37cde66e2e62c73052c18bd Mon Sep 17 00:00:00 2001 From: aleph1 Date: Mon, 20 May 2002 17:41:34 +0000 Subject: [PATCH] Initial revision --- Documentation/sv9349341.gif | Bin 0 -> 4150 bytes Documentation/sv9929930.gif | Bin 0 -> 4870 bytes Documentation/taffs-todo.html | 34 + Documentation/tnode.drawing.sda | Bin 0 -> 33792 bytes Documentation/yaffs-0.3.html | 504 ++++ Documentation/yaffs-notes2.html | 719 ++++++ Documentation/yaffs_report20020211.html | 81 + Documentation/yaffs_report20020304.html | 57 + Makefile | 38 + devextras.h | 257 ++ snMakefile | 79 + utils/Makefile | 34 + utils/mkyaffs | Bin 0 -> 6382 bytes utils/mkyaffs.c | 150 ++ yaffs-header.c | 13 + yaffs_fileem.c | 145 ++ yaffs_fs.c | 879 +++++++ yaffs_guts.c | 3079 +++++++++++++++++++++++ yaffs_guts.h | 431 ++++ yaffs_mtdif.c | 104 + yaffs_mtdif.h | 29 + yaffs_nandemul.h | 34 + yaffs_ramem.c | 291 +++ yaffs_super.c | 401 +++ yaffsdev | Bin 0 -> 93829 bytes yaffsdev.c | 303 +++ yaffsdev.proj | Bin 0 -> 28672 bytes yaffsinterface.h | 23 + yportenv.h | 56 + 29 files changed, 7741 insertions(+) create mode 100644 Documentation/sv9349341.gif create mode 100644 Documentation/sv9929930.gif create mode 100644 Documentation/taffs-todo.html create mode 100644 Documentation/tnode.drawing.sda create mode 100644 Documentation/yaffs-0.3.html create mode 100644 Documentation/yaffs-notes2.html create mode 100644 Documentation/yaffs_report20020211.html create mode 100644 Documentation/yaffs_report20020304.html create mode 100644 Makefile create mode 100644 devextras.h create mode 100644 snMakefile create mode 100644 utils/Makefile create mode 100755 utils/mkyaffs create mode 100644 utils/mkyaffs.c create mode 100644 yaffs-header.c create mode 100644 yaffs_fileem.c create mode 100644 yaffs_fs.c create mode 100644 yaffs_guts.c create mode 100644 yaffs_guts.h create mode 100644 yaffs_mtdif.c create mode 100644 yaffs_mtdif.h create mode 100644 yaffs_nandemul.h create mode 100644 yaffs_ramem.c create mode 100644 yaffs_super.c create mode 100755 yaffsdev create mode 100644 yaffsdev.c create mode 100644 yaffsdev.proj create mode 100644 yaffsinterface.h create mode 100644 yportenv.h diff --git a/Documentation/sv9349341.gif b/Documentation/sv9349341.gif new file mode 100644 index 0000000000000000000000000000000000000000..4e8ea84fb64c598a7f2ccb424cdfc4af9f3960e7 GIT binary patch literal 4150 zcmeH_`9BkmmA-vq28pzB#I@Ql9Fq3OvruZ47rbu+{0#$gw1S@4Y`lpGe?@T zk)yZVSCV7KklVZL`+ol&-_Prp*W>YezJ7W=UV0E+5ZIZ?Da*OV@vqn%Y_{~#DNYU! zZjPJ(1^8WoO~HlUrf&gn8lqEE-dNC-gfCDKpNf-;6b)rPj9ToQd zqU)0_{)>HiXjR2&3e2Oeq`#$hzAFYeHSh$qIrknZqTt{Y;=j=AB?QbjB-guTq)B`G z-Z-jX87frpm@`!OSQ#!et4zDs*2t`_bm`AmY~Eu|-!d7Q8=xFOrdtD;`$p}p+g06} zOpU>IauD);HdgYay=`ykONrmxs1C|O&t%hM_VP(bJDj}m@uF;WXU9KvjL}O`CS9GA zhd(##TZX!#O@66@5m^s!pZzfvbs|%C#hvM<>%<|neCCRWz%x&01Cc3FXG3nmW}-W< z1K>N7+g0qFXLTefUt9XkDk)MnN|l(Lz9BP=2E7q0a!BLUTMR$nl(YDHd;=ho8X8$f zdgK!#dp!fH;&DAmqfHwc3-NMua=kb!wuIdvG$&s?Io+;0ZRa)~%l@zyO zl$O~`*yrKCpZ{K5`1Tl62Fh3~O|q+D7q3;3R42SJ=X{anFLH48{YbT*9-jDWvrpvo=lV`1ssNA%l(Pf2sVx$AI=Rj$?hb1! zm}fU>u&eHb{z-4&9a-Ag75-{oUTN;UZE^@aPBXqA_?0 zB2-hjgmoE&uVg+ERR2+s?m%8f;Elr>6_$hH%*3vm@a3`txd_mY!ny9N0 zKUx+Y+8MoJg0HrAWrV_6)W<`Vog84-%{}Z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%V#G2VPAR%dAa}8S4w_&G4sqs)ly&FJwXkr0ZYInSAr}AoNsI_x5wV#h_zX;YX zYSt}->b{26lBKMoNasDb^Z?rvDk zKo~&`#xG+RwQ@05x4*IEV?BWtdBQldQ*LQI$4x+u^2afoW~k zv+bn8j_ghQhC$jCp0*zwqsU#qJl + + + + + + + + + + + +

YAFFS Todo

+
    +
  1. Locking

    +
  2. Fix statfs. df does not give correct results.

    +
  3. Fix disk full condition. +

    +
  4. ECC and write failure handling.

    +
  5. Add symlinks and links to VFS interface.

    +
  6. Add memory mapping (to allow file execution).

    +
  7. Test with nandemul mtd.

    +
  8. Discuss improved NAND page interface with mtd group.

    +
+

NANDEmul MTD

+
    +
  1. Complete and test.

    +
  2. +

    +
+



+

+ + \ No newline at end of file diff --git a/Documentation/tnode.drawing.sda b/Documentation/tnode.drawing.sda new file mode 100644 index 0000000000000000000000000000000000000000..13f1465c277951dc8b4fa8f9112d0608c268cbe6 GIT binary patch literal 33792 zcmeI534GPXwfN`WJ6Qxg^F<-zx*> zcjum&Ip@ronKNgW-_4F+cYpoX`}_Y%H3`S4nA+FaN#$nXBgBt)zZWVMB`&yqjg5^i zn&^S>zeodn9a*IfHI10#v}Ycl`9LS20O$;K0lEU+fH*)GP~CwZKu@3-&>QFj90c?Q z`T_lcgMmYU0l+|D5Rd={14DqJz@fk};4mNw6aj|=M*t#UF`q{QBY>lTk-#WmG%yAj z3ycHC0~3IWz$D;k;27Xo;5a~Noxta0C+?`=pYmg#s^wojZ81&N@L8uWK`YsZKJ=JO z#br}6(_UngzqLFE_`Pq(tw`|k#FZcuDA729zdP58YFOqJ^ z`NoKCSN^8^H+HCo!{69)zu5nhy7G&wYL*(iUshjUC*Kp}Mu_P(f%#wDfHnsTM}FDZ zSW16c_-#yn?S4{dLxbW~*i-%2A9)pEYX z^<>;rU4dM!WL$O1$Byu=WNa0yRn^Bjrm#u|U*5 zRt}l;+)RRd{mNTD`fTp9!n?nluZAZd_?;M?PXX~m#V=h3h;Ld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anSfYh#f*KPY>PxE}0*$s{Q>Wze*k zIU|vUi3t(-R;#wp5(RM29IP2ELZhN5v5pc}z`IVZR8@fd74AwS&2m2FuW_%mnOb-b zfxnDU9D=OtFZyELWkMN0O1@f^&<2auD%!#FoeB3P;93s}_)Al|I%vIwZ7caHdM=wH0)Y}=nX#QE(amwy?$zQkz0jK3;c$-iuLFA@xFL;H)Y zf0-er#e*v|dS9-}&EH;kHD5 + + + + + + + + + + + +

YAFFS (yet another Flash File System)

+

Version 0.3
Charles Manning (and Wookey), December 2001

+



+

+

Revision History

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

V0.0

+
+

20/12/01

+
+

First draft

+
+

V0.1

+
+

11/01/02

+
+

Minor corrections & + cosmetics.
Change use of data status byte.

+
+

V0.2

+
+

28/01/02

+
+

Added observations about + inodes, file headers and hard links.

+
+

V0.3

+
+

26/02/02

+
+

W:Added some general + observations on compatibility, partitions and bootloading.

+
+



+

+

Scope

+

The purpose of this document is to outline a potential +NAND-friendly file system for Linux.

+

Background

+

There are already various flash-file systems (FFSs) or block +drivers for flash (on top of which a regular FS runs). There are pros +and cons with all of these. +

+

Flash memory has quite a few constraints which will not be +addressed here. Various approaches are available to work around these +constraints to provide a file system. It is important to recognise +that "flash" includes both NOR and NAND flash which have +different sets of constraints. It is easy to be mislead by the +generic term "flash" into thinking that approaches +appropriate for NOR flash are immediately suitable for NAND flash.

+

The NAND block drivers (eg. SmartMedia [currently not available +for Linux] and DiskOnChip NFTL) typically use FAT16 as the file +system. This isn't too robust and nor is it that flash-friendly. +These block drivers provide a logical to physical mapping layer to +emulate rewritable blocks that look like disk sectors. When used with +FAT16, these file systems work reasonably well. They have a low +memory footprint and scale well. Like all FAT based systems they are +prone to corruption ("lost clusters etc").

+

The other approach is to design an entire file system which does +not work through a block driver layer and is flash-friendly. This +allows more scope to work around issues.

+

Currently, two Linux file systems that support NOR flash very well +are JFFS and its derivative JFFS2. Both of these are based on the +principles of journaling (hence the leading J) which significantly +increases robustness - a particularly important feature in embedded +systems. Unfortunately neither of these file systems scale +particularly well in both boot time and RAM usage. Scaling is +particularly relevant when one considers that a 16MB NOR array would +be considered large while a 128MB NAND is available as a single chip.

+

JFFS requires a RAM-based jffs_node structure for each journalling +node in the flash. Each of these nodes is 48 bytes. JFFS2 makes a +significant improvement here by reducing the equivalent structure +(jffs2_raw_node_ref) to 16 bytes. Still, at say an average node-size +of 512 bytes, a 128MB NAND might need 250000 of these ... 4MB!

+

Both JFFS and JFFS2 require scanning the flash array at boot time +to find the journaling nodes and determine the file structures. Since +NAND is large, slow, serially accessed and needs ECC this does not +scale well and will take an unacceptably long boot time for the +target systems. As a thumb-suck, the scanning of a 128MB NAND array +might take approx 25 seconds.

+

The intentions of the design sketched here are:

+
    +
  • Be NAND-flash friendly.

    +
  • Robustness through journaling strategies.

    +
  • Significantly reduce the RAM overheads and boot times + associated with JFFSx.

    +
+

This FS is intended primarily for internal NAND rather than removable NAND +(SM cards). On removable SM cards Smartmedia compatibility is likely to be +important so SM/FAT will normally be used, although of course YAFFS makes a +lot of sense if reliability is more important than compatibility.

+ +

Overview

+

Here follows a simplified overview of YAFFS.

+

YAFFS uses a physical flash format similar to SmartMedia. This is +done for various reasons:

+
    +
  • Some of the formatting, eg placement of bad block markers is + determined by the NAND manufacturers and can't be changed.

    +
  • Potential to reuse code.

    +
  • If it ain't broke don't fix.

    +
+

Some of the fields are obviously different to reflect the +different usage. Despite the similarities YAFFS is not actually compatible +with SM/FAT. SM cards need to be reformatted to switch from using SM/FAT to +YAFFS or vice versa.

+

File data is stored in fixed size "chunks" consistent +with the size of a page (ie. 512 bytes). Each page is marked with a +file id and chunk number. These tags are stored in the "spare +data" region of the flash. The chunk number is determined by +dividing the file position by the chunk size.

+

When data in a file is overwritten, the relevant chunks are +replaced by writing new pages to flash containing the new data but +the same tags. The overwritten data is marked as "discarded". +

+

File "headers" are stored as a single page, marked so as +to be differentiated from data pages.

+

Pages are also marked with a short (2 bit) serial number that +increments each time the page at this position is incremented. The +reason for this is that if power loss/crash/other act of demonic +forces happens before the replaced page is marked as discarded, it is +possible to have two pages with the same tags. The serial number is +used to arbitrate.

+

A block containing only discarded pages (termed a dirty block) +is an obvious candidate for garbage collection. Otherwise valid pages +can be copied off a block thus rendering the whole block discarded +and ready for garbage collection.

+

In theory you don't need to hold the file structure in RAM... you +could just scan the whole flash looking for pages when you need them. +In practice though you'd want better file access times than that! The +mechanism proposed here is to have a list of __u16 page addresses +associated with each file. Since there are 218 pages in a +128MB NAND, a __u16 is insufficient to uniquely identify a page but +is does identify a group of 4 pages - a small enough region to search +exhaustively. This mechanism is clearly expandable to larger NAND +devices - within reason. The RAM overhead with this approach is +approx 2 bytes per page - 512kB of RAM for a whole 128MB NAND.

+

Boot-time scanning to build the file structure lists should +require just one pass reading NAND. Since only the the spare data +needs to be read, this should be relatively fast ( approx 3 seconds +for 128MB). Improvements can be achieved by partitioning the NAND. +ie. mount the critical partition first then mount the data partition +afterwards.

+

Various runtime improvements can be achieved by changing the +"chunk size" to 1024 bytes or more. However this would +likely reduce flash efficiency. As always, life is a compromise....

+



+

+

Spare area details

+

The following table summarizes the layout of the spare area of +each page.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

Byte #

+
+

SmartMedia usage

+
+

YAFFS usage

+
+

0..511

+
+

Data

+
+

Data. either file data or file header depending on tags

+
+

512..515

+
+

Reserved

+
+

Tags

+
+

516

+
+

Data status byte. Not used in SM code from Samsung

+
+

Data status byte. If more than 4 bits are zero, then this page + is discarded.

+
+

517

+
+

Block status byte

+
+

Block status byte

+
+

518..519

+
+

Block address

+
+

Tags

+
+

520..522

+
+

ECC on second 256 bytes part of data

+
+

ECC on second 256 bytes of data

+
+

523..524

+
+

Block address

+
+

Tags

+
+

525..527

+
+

ECC on first 256 bytes part of data

+
+

ECC on first 256 bytes part of data

+
+



+

+

The block status is a reserved value that shows whether the block +is damaged.

+

The data status tracks whether the page is valid. If less than 4 +bits are zero, then the page is valid otherwise it is discarded.

+

There are 8 bytes (64 bits) for use by YAFFS tags. This is +partitioned as follows:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

Number of bits

+
+

Usage

+
+

18

+
+

18-bit file id. ie. Limit of 218 (over 260000) + files. File id 0 is not valid and indicates a deleted page. File + Id 0x3FFFF i is also not valid.

+
+

2

+
+

2-bit serial number.

+
+

20

+
+

20-bit page id within file. Limit of 220 pages per + file. ie. over 500MB file max size. Page id 0 means the file + header for this file.

+
+

10

+
+

10-bit counter of the number of bytes used in the page.

+
+

12

+
+

12-bit ECC on tags.

+
+

2

+
+

Unused. Keep as 1.

+
+

64

+
+

Total

+
+



+

+

A bit of explanation on the usage of some of these fields:

+

file Id is synonymous with inode.

+

The serial number is incremented each time a page with the same +file_id:page_id is rewritten (because of data changes or copy during +garbage collection). When a page is replaced, there is a brief period +during which there are two pages with the same id. The serial number +resolves this. Since there should never be a difference of less than +more than one, a two-bit counter is sufficient to determine which is +the current page.

+

When the page is rewritten, the file id, these data status byte +and the 12-bit ECC are all written to zero.

+

The byte counter indicates how many bytes are valid in this page. +Since the page would not exist if it contains zero bytes, this field +should thus hold 512 for all pages except the last page in the file. +The use of counters means that the file length integrity is preserved +while the file is open without having to constantly update the file +length in the file header. The file header only needs to be refreshed +when the file is closed (rather than whenever it is appended to). +This field is wide enough to allow expansion to 1024-byte "chunks".

+

File "headers" come in two flavours:

+
    +
  • file info ( the mode, ower id, group id, length,...)

    +
  • the hard link(s) that refers to the file.

    +
+

A directory also appears as a file (ie. has an inode and hard +link(s)) but has no data.

+

The 12-bit ECC applies to only the tag data uses a similar +algorithm to the 22-bit ECCs used for file system data. They are kept +independent.

+

RAM data details

+

Block management details are reasonably obvious and, I feel, don't +need to be addressed here apart from stating that there will be a +structure to track block status (eg. number of pages in use, failed +blocks, and which are candidates for garbage collection etc).

+

The files need an indexing structure of sorts to locate and track +the pages in the file. Some sort of tree structure should work rather +well. The look-up needs to be quite efficient in both CPU time and +space.

+

Page allocation and garbage collection

+

Pages are allocated sequentially from the currently selected +block. When all the pages in the block are filled, another clean +block is selected for allocation. At least two or three clean blocks +are reserved for garbage collection purposes. If there are +insufficient clean blocks available, then a dirty block ( ie one +containing only discarded pages) is erased to free it up as a clean +block. If no dirty blocks are available, then the dirtiest block is +selected for garbage collection.

+

Garbage collection is performed by copying the valid data pages +into new data pages thus rendering all the pages in this block dirty +and freeing it up for erasure. I also like the idea of selecting a +block at random some small percentage of the time - thus reducing the +chance of wear differences.

+

Relative to NOR, NAND writes and erases very fast. Therefore +garbage collection might be performed on-demand (eg. during a write) +without significant degradation in performance. Alternatively garbage +collection might be delegated to a kernel tasklet.

+

Relative to JFFSx, the garbage collection presented here is +incredibly simple - thanks mainly to the use of fixed-size pages +instead of journaling nodes.

+

Flash writing

+

As presented here, YAFFS only writes to the page's data area once +and to the spare area twice (once when new page is written and once when it +gets stomped on) before an erasure. This is within the limits of the most +restrictive NAND flashes.

+ +

Wear leveling

+

No wear leveling is explicitly used here. Instead we rely on two +"strategies":

+
    +
  • Reserving some blocks to cater for failure. You need to do + this anyway with NAND. The main purpose behind wear leveling is to + prevent some blocks getting more wear and failing. Since we expect, + and handle, failure this is no longer as important.

    +
  • The infrequent random block selection should prevent low-wear + blocks getting "stuck".

    +
+

Partitioning

+

Partitioning is not included in this spec, but could be added if +required.

+

Bootloading

+

Bootloaders cannot just read files direct from NAND due to the high +probability of bad blocks. Because YAFFS is quite simple it will be +relatively straightforward for bootloaders to read from it (eg reading a +kernel).

+ +

Conclusion

+

YAFFS is very simple. It is also NAND-friendly, is relatively +frugal with resources (especially RAM) and boots quickly. Like JFFSx +it has journaling which makes it far more robust than FAT.

+

While it might seem high-risk to develop YAFFS, it is probably +about the same amount of effort as implementing changes to JFFS to +get it to work effectively within the constraints of NAND. A +resulting JFFSx system would still require significant amounts of RAM +and have long boot times.

+

While YAFFS is indeed a new file system internally, much of the +file system glue code (including inode management, link management +etc) can likely be stolen from JFFSx. +

+



+

+



+

+



+

+



+

+



+

+



+

+



+

+



+

+



+

+ + \ No newline at end of file diff --git a/Documentation/yaffs-notes2.html b/Documentation/yaffs-notes2.html new file mode 100644 index 0000000..a2f2344 --- /dev/null +++ b/Documentation/yaffs-notes2.html @@ -0,0 +1,719 @@ + + + + + + + + + + + + +

YAFFS Development Notes

+



+

+



+

+

Build options

+

Yaffs can be built as either a kernel module (ie. a Linux file +system) or as an application.

+

Of course the goal is to build yaffs as a file system running on +top of real NAND flash, but yaffs can be built to run on a RAM +emulation layer for in-kernel testing without NAND flash in the +system.

+

Building as an application allows the yaffs_guts algorithms to be +tested/debugged in a more friendly debugging environment. The test +harness is in yaffsdev.c

+

Trying it out

+

YAFFS can be built to run with either mtd or RAM emulation, or +both. The file system that interfaces to mtd is called yaffs, +the file system that uses internal ram is called yaffsram. +YAFFS simultaneously supports both if they are enabled.

+
    +
  1. Hack the Makefile and change the KERNELDIR define to your + kernel directory.

    +
  2. If you don't have mtd support in your kernel, then you might + need to turn off USE_MTD otherwise the yaffs module might not load.

    +
  3. Type make clean; make + to build yaffs

    +
  4. Load yaffs as a module by typing /sbin/insmod + yaffs.o (ya gotta be root!).

    +
  5. Create a mount point eg. mkdir + /mnt/y

    +
  6. To mount the RAM emulation version of yaffs, mount + -t yaffsram none /mnt/y

    +
  7. Alternatively, + to mount the mtd version of yaffs, mount -t yaffs + /dev/mtd0 /mnt/y

    +
+



+

+

YAFFS Data structures

+

All data types are defined in yaffs_guts.h

+

Yaffs uses the following major objects:

+
    +
  • yaffs_Object: A yaffs_Object can be a file, directory, + symlink or hardlink. The yaffs_Objects "know" about their + corresponding yaffs_ObjectHeader in NAND and the data for that + object. yaffs_Objects also bind together the directory structure as + follows:

    +
  • parent: pointer to the yaffs_Object that is a parent of this + yaffs_Object in the directory structure.

    +
  • siblings: this field is used to link together a list of all + the yaffs_Objects in the same directory.

    +
  • children: if the object is a directory, then children holds + the head of the list of objects in the directory.

    +
  • yaffs_Tnode: yaffs_Tnodes form a tree structure that speeds + up the search for data chunks in a file. As the file grows in size, + the levels increase. The Tnodes are a constant size (32 bytes). + Level 0 (ie the lowest level) comprise 16 2-byte entries giving an + index used to search for the chunkId. Tnodes at other levels + comprise 8 4-byte pointer entries to other tnodes lower in the tree.

    +
  • yaffs_Device: this holds the device context and is in some + ways analogous to the VFS superblock. It stores the data used to + access the mtd as well as function pointers to access the NAND data.

    +
+

The Tnodes and Objects are allocated in groups to reduce memory +allocation/freeing overheads. Freed up tnodes and objects are kept in +a free list and re-used.

+

yaffs_Object

+



+

+

struct + yaffs_ObjectStruct

+

{

+

__u8 +fake:1; // A fake object has no presence on NAND.

+

__u8 +renameAllowed:1; // Are we allowed to rename it?

+

__u8 +unlinkAllowed:1; // Are we allowed to unlink it?

+

__u8 +dirty:1; // the object needs to be written to flash

+

__u8 +valid:1; // When the file system is being loaded up, this +

+

+ // object might be created before the data

+

+ // is available (ie. file data records appear before the header).

+

__u8 +serial; // serial number of chunk in NAND. Store here so we +don't have to

+

+ // read back the old one to update.

+

__u16 +sum; // sum of the name to speed searching

+

+

struct +yaffs_DeviceStruct *myDev; // The device I'm on

+

+

+

struct +list_head hashLink; // list of objects in this hash bucket

+

+


+

+

struct +list_head hardLinks; // all the equivalent hard linked objects

+

// +live on this list

+

// +directory structure stuff

+

struct +yaffs_ObjectStruct *parent; //my parent directory

+

struct +list_head siblings; // siblings in a directory

+

+// also used for linking up the free list

+

+

// +Where's my data in NAND?

+

int +chunkId; // where it lives

+

+

__u32 +objectId; // the object id value

+

+

+

__u32 +st_mode; // protection

+

__u32 +st_uid; // user ID of owner

+

__u32 +st_gid; // group ID of owner +

+

__u32 +st_atime; // time of last access

+

__u32 +st_mtime; // time of last modification

+

__u32 +st_ctime; // time of last change

+


+

+

+

yaffs_ObjectType +variantType;

+

+

yaffs_ObjectVariant +variant;

+

+

};

+



+

+

Obvious stuff skipped....

+

fake, renameAllowed, unlinkAllowed are special flags for handling +"fake" objects which live in the file system but do not +live on NAND. Currently there are only two such objects: the root +object and the lost+found directory. None of these may be renamed or +unlinked.

+

serial, sum: see yaffs_ObjectHeader.

+

dirty indicates that the object's contents has changed and a new +yaffs_ObjectHeader must be written to flash.

+

valid indicates that the object has been loaded up. This is only +used during scanning (yaffs_Scan()) since we can know of an object's +existance - and thus need to create the object header - before we +encounter the associated yaffs_ObjectHeader.

+

hashlink is a list of Objects in the same hash bucket. +

+

The four variants hold extra info:

+

Files hold the file size and the top level and pointer to the +tnode tree for the file.

+

Directories hold a list of children objects.

+

Symlinks hold a pointer to the alias string. This is probably +inefficient, but that probably does not matter since we don't expect +to see many of these. +

+

Hardlinks hold information to identify the equivalent object.

+



+

+



+

+

File structure (tnodes)

+

File structures are done with a tiered indexing structure

+



+

+




+

+

The file structure is maintained by a tree structure. Depending +where it is in the tree, each tree node (tnode) (the +blue/things) holds either:

+
    +
  • .... if it is at the lowest level, then 16 __u16s which + identify the page.

    +
  • .... if it is at a higher level (ie an internal tnode), then + 8 pointers to lowest-level tnodes.

    +
+

When the file starts out, it is assigned only one low-level tnode. +When the file expands past what a single tnode can hold, then it is +assigned a second tnode and an internal node is added to point to the +two tnodes. As the file grows, more low-level tnodes and high level +tnodes are added.

+

Traversing the tnode tree to find a particular page in a file is +quite simple: each internal tnode is selected from by using 3 bits of +the page offset in the file. The level 0 page resolves 4 bits.

+

For example, finding page 0x235 (ie. the one starting at file +position 0x46800 would proceed as follows:

+

0x235 is 0000001000110101, partitioned as follows. +000.000.100.011.0101

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

Level

+
+

Bits

+
+

Selected value

+
+

3 or more if they exist

+
+

>= 10

+
+

Zero

+
+

2

+
+

9 to 7

+
+

100 binary = 4

+
+

1

+
+

6 to 4

+
+

011 binary = 3

+
+

0

+
+

3 to 0

+
+

0101 binary = 5

+
+



+

+

Free tnodes are stored in a list. When the list is exhausted, more +are allocated.

+

Each tnode takes 32 bytes. Each file needs at least one level 0 +tnode. How many do we need? A full 16MB file system needs at least +16MB/512/16 = 2000 level zero tnodes. More for internal tnodes. More +for files smaller than optimal.

+

The tree grows as required. When the file is resized to a smaller +size then it is pruned.

+



+

+

NAND data

+

Data is stored on NAND in "chunks". Currently each chunk +is the same size as a NAND flash page (ie. 512 bytes + 16 byte +spare). In the future we might decide to allow for different chunk +sizes. Chunks can hold either:

+
    +
  • A yaffs_ObjectHeader. This is the way a yaffs_Object gets + stored on NAND.

    +
  • A chunk of file data.

    +
+

The 16 byte spare area contains:

+
    +
  • 8 bytes of tags,

    +
  • 6 bytes of ECC data

    +
  • 1 byte block status (used to identify damaged blocks)

    +
  • 1 byte data status (currently unused).

    +
+

The tags are made up as follows:

+

typedef +struct

+

{

+

+ unsigned chunkId:20; //chunk number in file

+

+ unsigned serialNumber:2; //serial number for chunk

+

+ unsigned byteCount:10; //number of bytes of data used in this +chunk

+

+ unsigned objectId:18; //the object id that this chunk belongs +to. +

+

+ unsigned ecc:12; //ECC on tags

+

+ unsigned unusedStuff:2; //unused

+

} +yaffs_Tags;

+


+

+

A chunkId of zero indicates that this chunk holds a +yaffs_ObjectHeader. A non zero value indicates that this is a data +chunk and the position of the chunk in the file (ie. the first chunk +- at offset 0 - has chunkId 1). See yaffs_guts.c:yaffs_Scan () to see +how this is done.

+

When a chunk is repalced (eg. file details changed or a part of a +file was overwritten), the new chunk is written before the old chunk +is deleted. This means that we don't lose data if there is a power +loss after the new chunk is created but before the old one is +discarded, but it does mean that we can encounter the situation where +we find both the old and the new chunks in flash. The serialNumber is +incremented each time the chunk is written. 2 bits is sufficient to +resolve any ambiguity.

+

bytecount applies only to data chunks and tells how many of the +data bytes are valid.

+

objectId says which object this chunk belongs to.

+

ecc is used to perform error correction on the tags. Another ecc +field is used to error correct the data.

+



+

+

yaffs_ObjectHeader

+

typedef +struct

+

{

+

yaffs_ObjectType +type;

+


+

+

// +Apply to everything

+

int + parentObjectId;

+

__u16 +sum; // checksum of name

+

char + name[YAFFS_MAX_NAME_LENGTH + 1];

+


+

+

// +Thes following apply to directories, files, symlinks - not hard links

+

__u32 +st_mode; // protection

+

__u32 +st_uid; // user ID of owner

+

__u32 +st_gid; // group ID of owner +

+

__u32 +st_atime; // time of last access

+

__u32 +st_mtime; // time of last modification

+

__u32 +st_ctime; // time of last change

+

+

// +File size applies to files only

+

int +fileSize; +

+

+

// +Equivalent object id applies to hard links only.

+

int + equivalentObjectId;

+

+ // alias only applies to symlinks

+

char +alias[YAFFS_MAX_ALIAS_LENGTH + 1];

+

+

+

} +yaffs_ObjectHeader;

+


+

+

A yaffs_ObjectHeader is stored in NAND for every yaffs_Object.

+

type holds the type of yaffs_Object (file,directory,hardlink or +symlink).

+

parentObject is the objectId of this object's parent. name holds +the object's name. Together these form the directory structure of the +file system. Also worth mention is sum. This is a "checksum" +on the name which speeds directory searching (ie. when searching the +directory we only compare the name for those entries where sum +matches).

+

Obvious stuff skipped....

+

equivalentObjectId is used by hardlinks. A hardlink to an object +uses this field to specify the object that this links to. This way of +doing things is a bit different than the normal Linux way of doing +things (ie. keeping the links distinct from the inode) but is simpler +and uses less space except for a few corner cases with hardlinks.

+

alias is used by symlinks to hold the symlink alias string. This +limits the size of the symlink alias. In future we should expand +YAFFS to use data chunks to store aliases too long to fit into the +yaffs_ObjectHeader.

+



+

+

NAND Interface

+

All NAND access is performed via four functions pointed to by +yaffs_Device. At the moment a chunk is a page.

+
    +
  • int + WriteChunkToNAND(struct yaffs_DeviceStruct *dev,int chunkInNAND, + const __u8 *data, yaffs_Spare *spare)

    +
  • int + ReadChunkFromNAND(struct yaffs_DeviceStruct *dev,int chunkInNAND, + __u8 *data, yaffs_Spare *spare);

    +
  • int + EraseBlockInNAND(struct yaffs_DeviceStruct *dev,int blockInNAND);

    +
  • int + InitialiseNAND(struct yaffs_DeviceStruct *dev);

    +
+

In the Readxxx and Writexxx functions, the data and/or spare +pointers may be NULL in which case these data transfers are ignored.

+

A quick note about NAND:

+
    +
  • NAND is not random access, but page oriented. Thus, we do all + reads & writes in pages.

    +
  • Each NAND page holds 512 bytes of data and 16 "spare" + bytes. Yaffs structures the spare area with tags used to identify + what is stored in the data area. There are 32 such pages to a block.

    +
  • NAND writes will only change 1 bits to 0. eg. if a byte holds + 10110011 and you write 11011010 to it you will get the logical and + of the two values: 10010010. The only way to get 1s again is to + erase the entire block. +

    +
  • You may only write to a page a few times before erasing the + entire block. Yaffs lives within these limitations. Each page only + gets written to twice (once when written and once when discarded).

    +
  • ECC is normally used with NAND to correct for single bit + errors. YAFFS applies the ECC itself, so the MTD should not do this.

    +
  • The current mtd interfaces are not particularly well suited + to YAFFS and we will address the issue with the mtd group. (The mtd + interface does not support page-oriented read/write which YAFFS + would prefer).

    +
+



+

+

mkyaffs

+

mkyaffs is the tool to format a NAND mtd to be used for YAFFS. +This is quite simple, just erase all the undamaged blocks. YAFFS +treats erased blocks as free (empty) space.

+



+

+

Expected performance

+

The following numbers should give an indication of the performance +we should expect from YAFFS.

+

As an example, I'll use the following numbers. Since the hardware +is capable of 50ns read/write, these numbers allow for some other +ovberheads. Clearly though, the performance can be degraded in +various ways.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

Seek

+
+

10uS/page

+
+

Read

+
+

100nS/byte

+
+

Write

+
+

100nS/byte

+
+

Program

+
+

200uS/page

+
+

Erase

+
+

2mS/block

+
+



+

+

From this we can derive some higher-level numbers:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

Operation

+
+

Time

+
+

Calculation

+
+

Read spare

+
+

12uS

+
+

seek + 16 * read

+
+

Read page

+
+

63 uS

+
+

seek + 528 * read

+
+

Write page

+
+

326 uS

+
+

seek + 528 * write + program + read page (for verification)

+
+

Discard page

+
+

212 uS

+
+

seek + 16 * write + program

+
+

Overwrite page

+
+

538 uS

+
+

write page + discard page

+
+

Erase overhead per page

+
+

63uS

+
+

erase/32

+
+



+

+

From this we can infer the following flash access times:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

Operation

+
+

Time

+
+

Calculation

+
+

Read 1MB file

+
+

0.13s (about 7.5 MB/s)

+
+

2000 * read page

+
+

Write 1MB (clean system)

+
+

0.53s (about 1.8 MB/s)

+
+

2000 * write page

+
+

Overwrite 1MB file (no gc)

+
+

1.08s (about 0.9MB/s)

+
+

2000 * overwrite page

+
+

Overwrite 1MB with 50% gc

+
+

2.4s (about 0.4 MB/s)

+
+

2000 * overwrite page + 2000 * page copy (== overwrite page) + + 4000 * erase overhead

+
+

Delete 1MB file

+
+

0.43s (about 2.2 MB/s)

+
+

2000 * discard page

+
+

Delete 1MB file with 50% gc

+
+

0.49s (about 2.0MB/s)

+
+

2000 * discard page + 1000 * erase overhead

+
+



+

+



+

+



+

+ + \ No newline at end of file diff --git a/Documentation/yaffs_report20020211.html b/Documentation/yaffs_report20020211.html new file mode 100644 index 0000000..212eb88 --- /dev/null +++ b/Documentation/yaffs_report20020211.html @@ -0,0 +1,81 @@ + + + + + + + + + + + + +

YAFFS Progress 11 Feb 2002

+

Approach

+

C. A. R. Hoare, in his 1980 ACM Turing Award lecture, told of +two ways of constructing a software design: "One way is to make +it so simple that there are obviously no deficiencies and the other +way is to make it so complicated that there are no obvious +deficiencies."

+

The approach I'm taking with Yaffs is to design and make notes up +front as much as possible. I find this helps make the coding/debug +phase go way faster and more predictably.

+

Although obviously the code ends up in the kernel, I'm abstracting +out kernel services so that I develop/debug in user space using +vanilla dev tools. I like to use Source Navigator because it has a +nice xref capability though a few quirks too). Thus, yaffs code will +be tested in application space wrapped in a test harness which calls +the yaffs functions. and sits on top of a NAND emulation layer (just +two big disk files). I can then do things like force ecc failures +etc at will to test recovery logic and check booting etc. This +general approach has served me well in the past and I expect it will +this time too.

+

Design

+

At this stage all the major design work is done. Basically there +are 3 in RAM management "objects":

+
    +
  • inodes: An inode maps to the normal file system concept of + an inode. It is thus either a file or a directory.
    A file type + inode points to a tnode tree which is a layered tree that is used to + quickly find the pages of data in NAND.
    A directory type inode + has a list of children links (ie. the links in that directory).
    An + inode knows which hard links are associated with it.
    inode + look-up uses a hashing table.

    +
  • links: Links are hard or soft links. All links have a parent + inode (ie. the directory they're in).
    Hard links point to an + inode.
    Soft links are just alias strings.
    Instead of storing + the link name in RAM (big and wasteful and variable size), the + location in NAND is stored instead and a u16 "checksum" + value is stored in RAM to help in quickly scanning links [ie. say + the checksum for "freddies_file" is 123 then when I go + search for it I don't need to go look at every link in NAND (slow), + just those that match checksum 123]. +

    +
  • tnodes: Tnodes are a tiered tree system to rapidly get from + inodes to their data pages in RAM.

    +
+

There is a need for speed in certain areas, such as rapidly +locating inodes, links data pages during certain scenarios (eg. +garbage collection). These have been identified and suitable look-up +structures are in place.

+

All dynamic data structures are allocated from pools rather than +one at a time. This is more efficient time-wise and simplifies +clean-up.

+

Code

+

Much of the code for the management layers is already in place, as +is some of the tag management code. Some of the code has already been +tested.

+

I have started with coding the management layer since this is the +most critical part to get right. Every now and then I have coded up +some other section to verify that what I have will work.

+

Time

+

So far I've logged 65 hours on yaffs (though it chews up +significant null cycles too :-)). I believe this is comfortably +within budget. I was not able to make much progress through Christmas +and the week of January, but am able to give a lot more effort now.

+



+

+



+

+ + \ No newline at end of file diff --git a/Documentation/yaffs_report20020304.html b/Documentation/yaffs_report20020304.html new file mode 100644 index 0000000..afc7569 --- /dev/null +++ b/Documentation/yaffs_report20020304.html @@ -0,0 +1,57 @@ + + + + + + + + + + + + +

YAFFS Progress 4 March 2002

+



+

+

Design

+

A few of the design areas needed to be tweaked slightly without +significant impact.

+

The only real significance is that what is termed a yaffs_Inode +really becomes an object Id. Where an 'object' is a file, directory, +symlink or hard link. This differs from the *nix concept of an inode +in that a hard link is not an inode. yaffs_Inode should really be +renamed to yaffs_Object to reflect this.

+

Rge reason for introducing the object is to provide identifiers +for the objects stored on NAND. For example, each hardlink (which +does not have a distinct inode) needs an object Id for storage on +

+

Code

+

Pretty much all the guts of the code is there except for:

+
    +
  • symlink handling (a doddle)

    +
  • hard link handling.

    +
  • some of start-up scanning

    +
  • ECC on tags

    +
  • superblock handling (ie hook-up to mtd and the Linux VFS). + Some of this code to be pinched from JFFS2.

    +
+

Some of the code has already been tested.

+

I will now be testing out the guts on a NAND emulation layer in an +application. This provides better debugging. I hope to have this +running by 11/03/2002. +

+

Once the guts looks solid on the NAND emulation, I will graft it +on to the VFS and mtd - at which point it becomes a real file +system.

+

Time

+

So far I've logged 90 hours on yaffs. I will not be charging for +approx 15 hours I have spent swotting up on the Linux VFS. I still +believe this is on budget.

+



+

+



+

+



+

+ + \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a0d8138 --- /dev/null +++ b/Makefile @@ -0,0 +1,38 @@ +#Makefile for YAFFS as a module +# +# NB this is not yet suitable for putting into the kernel tree. +# YAFFS: Yet another FFS. A NAND-flash specific file system. +# +# Copyright (C) 2002 Aleph One Ltd. +# for Toby Churchill Ltd and Brightstar Engineering +# +# Created by Charles Manning +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. + +## Change or override KERNELDIR to your kernel +## comment out USE_xxxx if you don't want these features. + +KERNELDIR = /usr/src/kernel-headers-2.4.18 +USE_RAM_FOR_TEST = -DYAFFS_RAM_ENABLED +USE_MTD = -DYAFFS_MTD_ENABLED + + +CFLAGS = -D__KERNEL__ -DMODULE $(USE_RAM_FOR_TEST) $(USE_MTD) -I$(KERNELDIR)/include -O2 -Wall + + +OBJS = yaffs_fs.o yaffs_guts.o yaffs_ramem.o yaffs_mtdif.o + + +all: yaffs.o + +$(OBJS): %.o: %.c + gcc -c $(CFLAGS) $< -o $@ + +yaffs.o: $(OBJS) + ld -r $(OBJS) -o $@ + +clean: + rm -f $(OBJS) core diff --git a/devextras.h b/devextras.h new file mode 100644 index 0000000..a28135f --- /dev/null +++ b/devextras.h @@ -0,0 +1,257 @@ +/* + * YAFFS: Yet another FFS. A NAND-flash specific file system. + * devextras.h + * + * Copyright (C) 2002 Aleph One Ltd. + * for Toby Churchill Ltd and Brightstar Engineering + * + * Created by Charles Manning + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This file is just holds extra declarations used during development. + * Most of these are from kernel includes placed here so we can use them in + * applications. + * + */ + +#ifndef __EXTRAS_H__ +#define __EXTRAS_H__ + +#ifndef __KERNEL__ + +// User space defines + +typedef unsigned char __u8; +typedef unsigned short __u16; +typedef unsigned __u32; + + +/* + * Simple doubly linked list implementation. + * + * Some of the internal functions ("__xxx") are useful when + * manipulating whole lists rather than single entries, as + * sometimes we already know the next/prev entries and we can + * generate better code by using them directly rather than + * using the generic single-entry routines. + */ + + #define prefetch(x) 1 + + +struct list_head { + struct list_head *next, *prev; +}; + +#define LIST_HEAD_INIT(name) { &(name), &(name) } + +#define LIST_HEAD(name) \ + struct list_head name = LIST_HEAD_INIT(name) + +#define INIT_LIST_HEAD(ptr) do { \ + (ptr)->next = (ptr); (ptr)->prev = (ptr); \ +} while (0) + +/* + * Insert a new entry between two known consecutive entries. + * + * This is only for internal list manipulation where we know + * the prev/next entries already! + */ +static __inline__ void __list_add(struct list_head * new, + struct list_head * prev, + struct list_head * next) +{ + next->prev = new; + new->next = next; + new->prev = prev; + prev->next = new; +} + +/** + * list_add - add a new entry + * @new: new entry to be added + * @head: list head to add it after + * + * Insert a new entry after the specified head. + * This is good for implementing stacks. + */ +static __inline__ void list_add(struct list_head *new, struct list_head *head) +{ + __list_add(new, head, head->next); +} + +/** + * list_add_tail - add a new entry + * @new: new entry to be added + * @head: list head to add it before + * + * Insert a new entry before the specified head. + * This is useful for implementing queues. + */ +static __inline__ void list_add_tail(struct list_head *new, struct list_head *head) +{ + __list_add(new, head->prev, head); +} + +/* + * Delete a list entry by making the prev/next entries + * point to each other. + * + * This is only for internal list manipulation where we know + * the prev/next entries already! + */ +static __inline__ void __list_del(struct list_head * prev, + struct list_head * next) +{ + next->prev = prev; + prev->next = next; +} + +/** + * list_del - deletes entry from list. + * @entry: the element to delete from the list. + * Note: list_empty on entry does not return true after this, the entry is in an undefined state. + */ +static __inline__ void list_del(struct list_head *entry) +{ + __list_del(entry->prev, entry->next); +} + +/** + * list_del_init - deletes entry from list and reinitialize it. + * @entry: the element to delete from the list. + */ +static __inline__ void list_del_init(struct list_head *entry) +{ + __list_del(entry->prev, entry->next); + INIT_LIST_HEAD(entry); +} + +/** + * list_empty - tests whether a list is empty + * @head: the list to test. + */ +static __inline__ int list_empty(struct list_head *head) +{ + return head->next == head; +} + +/** + * list_splice - join two lists + * @list: the new list to add. + * @head: the place to add it in the first list. + */ +static __inline__ void list_splice(struct list_head *list, struct list_head *head) +{ + struct list_head *first = list->next; + + if (first != list) { + struct list_head *last = list->prev; + struct list_head *at = head->next; + + first->prev = head; + head->next = first; + + last->next = at; + at->prev = last; + } +} + +/** + * list_entry - get the struct for this entry + * @ptr: the &struct list_head pointer. + * @type: the type of the struct this is embedded in. + * @member: the name of the list_struct within the struct. + */ +#define list_entry(ptr, type, member) \ + ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member))) + +/** + * list_for_each - iterate over a list + * @pos: the &struct list_head to use as a loop counter. + * @head: the head for your list. + */ +#define list_for_each(pos, head) \ + for (pos = (head)->next, prefetch(pos->next); pos != (head); \ + pos = pos->next, prefetch(pos->next)) + +/** + * list_for_each_safe - iterate over a list safe against removal of list entry + * @pos: the &struct list_head to use as a loop counter. + * @n: another &struct list_head to use as temporary storage + * @head: the head for your list. + */ +#define list_for_each_safe(pos, n, head) \ + for (pos = (head)->next, n = pos->next; pos != (head); \ + pos = n, n = pos->next) + + + +#define CURRENT_TIME 0 + + +/* + * File types + */ +#define DT_UNKNOWN 0 +#define DT_FIFO 1 +#define DT_CHR 2 +#define DT_DIR 4 +#define DT_BLK 6 +#define DT_REG 8 +#define DT_LNK 10 +#define DT_SOCK 12 +#define DT_WHT 14 + +#include + +/* + * Attribute flags. These should be or-ed together to figure out what + * has been changed! + */ +#define ATTR_MODE 1 +#define ATTR_UID 2 +#define ATTR_GID 4 +#define ATTR_SIZE 8 +#define ATTR_ATIME 16 +#define ATTR_MTIME 32 +#define ATTR_CTIME 64 +#define ATTR_ATIME_SET 128 +#define ATTR_MTIME_SET 256 +#define ATTR_FORCE 512 /* Not a change, but a change it */ +#define ATTR_ATTR_FLAG 1024 + + +struct iattr { + unsigned int ia_valid; + unsigned ia_mode; + unsigned ia_uid; + unsigned ia_gid; + unsigned ia_size; + unsigned ia_atime; + unsigned ia_mtime; + unsigned ia_ctime; + unsigned int ia_attr_flags; +}; + +#define KERN_DEBUG + + +#else +#include +#include +#include +#include + + +#endif + + + + +#endif + diff --git a/snMakefile b/snMakefile new file mode 100644 index 0000000..4557fa5 --- /dev/null +++ b/snMakefile @@ -0,0 +1,79 @@ +######################################################### +# Makefile auto generated by Cygnus Source Navigator. +# Target: yaffsdev_RAM Date: May 03 2002 Time: 07:11:35 PM +# + + +.SUFFIXES: .cc .class .java .cxx .C .cpp .o .c .l .y + + +VPATH = /opt/aleph1/yaffs/. + + +YACC = bison +LEX = flex +JAVA = gcj +CC = gcc +CPP = g++ +YACC_FLAGS = +LEX_FLAGS = +JAVA_FLAGS = +CC_FLAGS = -g -Wall +CPP_FLAGS = +YACC_INCLUDES = +LEX_INCLUDES = +JAVA_INCLUDES = +CC_INCLUDES = +CPP_INCLUDES = +YACC_DEFINES = +LEX_DEFINES = +JAVA_DEFINES = +CC_DEFINES = +CPP_DEFINES = +yaffsdev_RAM_LIBS = +LINKER = gcc +LINKER_FLAGS = +LINKER_ENTRY = +yaffsdev_RAM_OBJECTS = yaffs_guts.o yaffs_ramem.o yaffsdev.o + +all: yaffsdev + +yaffsdev: $(yaffsdev_RAM_OBJECTS) + $(LINKER) -o yaffsdev $(LINKER_ENTRY) $(LINKER_FLAGS) $(yaffsdev_RAM_OBJECTS) $(yaffsdev_RAM_LIBS) + +.y.c: + $(YACC) $< $(YACC_FLAGS) $(YACC_DEFINES) $(YACC_INCLUDES) + + +.l.c: + $(LEX) -t $< > $@ $(LEX_FLAGS) $(LEX_DEFINES) $(LEX_INCLUDES) + + +.java.o: + $(JAVA) -c $< $(JAVA_FLAGS) $(JAVA_DEFINES) $(JAVA_INCLUDES) +.class: + $(JAVA) -c $< $(JAVA_FLAGS) $(JAVA_DEFINES) $(JAVA_INCLUDES) + + +.c.o: + $(CC) -c $< $(CC_FLAGS) $(CC_DEFINES) $(CC_INCLUDES) + + +.cpp.o: + $(CPP) -c $< $(CPP_FLAGS) $(CPP_DEFINES) $(CPP_INCLUDES) +.C.o: + $(CPP) -c $< $(CPP_FLAGS) $(CPP_DEFINES) $(CPP_INCLUDES) +.cc.o: + $(CPP) -c $< $(CPP_FLAGS) $(CPP_DEFINES) $(CPP_INCLUDES) +.cxx.o: + $(CPP) -c $< $(CPP_FLAGS) $(CPP_DEFINES) $(CPP_INCLUDES) + + +yaffs_guts.o: /opt/aleph1/yaffs/yaffs_guts.h /opt/aleph1/yaffs/yaffsinterface.h /opt/aleph1/yaffs/yportenv.h +yaffs_ramem.o: yaffs_nandemul.h /opt/aleph1/yaffs/devextras.h /opt/aleph1/yaffs/yaffs_guts.h /opt/aleph1/yaffs/yaffsinterface.h /opt/aleph1/yaffs/yportenv.h +yaffsdev.o: yaffs_nandemul.h /usr/include/stdio.h /usr/include/stdlib.h /usr/include/string.h /opt/aleph1/yaffs/yaffs_guts.h /opt/aleph1/yaffs/yaffsinterface.h + +clean: + rm -f *.o + rm -f yaffsdev + diff --git a/utils/Makefile b/utils/Makefile new file mode 100644 index 0000000..fdc64a3 --- /dev/null +++ b/utils/Makefile @@ -0,0 +1,34 @@ +#Makefile for mkyaffs +# +# NB this is not yet suitable for putting into the kernel tree. +# YAFFS: Yet another FFS. A NAND-flash specific file system. +# +# Copyright (C) 2002 Aleph One Ltd. +# for Toby Churchill Ltd and Brightstar Engineering +# +# Created by Charles Manning +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. + +## Change or override KERNELDIR to your kernel + +KERNELDIR = /usr/src/kernel-headers-2.4.18 + +CFLAGS = -I$(KERNELDIR)/include -O2 -Wall + + +OBJS = mkyaffs.o + + +all: mkyaffs + +$(OBJS): %.o: %.c + gcc -c $(CFLAGS) $< -o $@ + +mkyaffs: $(OBJS) + gcc -o $@ $(OBJS) + +clean: + rm -f $(OBJS) core diff --git a/utils/mkyaffs b/utils/mkyaffs new file mode 100755 index 0000000000000000000000000000000000000000..27e3a086d46a85f525a1695a96617c9ac95d9968 GIT binary patch literal 6382 zcmcgwYiwM_6`px3`aV^TP{|T4q=E!(JHPMSAYva zS;qu)Kr_gb8bD!C2sB56jC3jTB+6)ep*6?^=+H$%kXT=|D7h^AE@U7B6}E!dF6BY6 zW6(ba8R>Ok66I`z6oGzZUpPWCfJs_*W7ZkHF`K?2>*UMh(UKc&S2CEEed`(6ft+fG z{PQ4=iBr)GLet_iAb(1%SsaML4F%J^|ydJfG^ZB z#})UgqkW-ym2&f(3%aZ_Ga6pBvX%ZP$iEV@NunyK-mnQ`*T ztn;u1n6`@6m{ansqM0csbC&7kGp?}49Z#6OgJ#J~J9)EQveM9{X_O?3o|#KJdEpkU zJc>WeKq~8&Xnri`=Id2V(bL!4z1eJ!wne|RkdL9uLEkS_&vWep$dhv)FqN)xu+$;( z9P%t{aU5)cpg2My(kst~BaPS)-vM8NiqDZ_BOD^fVjm{Q#2q2WMtGha8{;TBHpMY= zv~Zjp8)V1SpDTY|v%N~&JNKQK`>YVvv&dIX7_Sy#ap&n1z_ptWqDF1qx9|@rYU|ho zo7r<`Ye?(Z6PvPgXC!8iY!2bvjKu7j&8>CrsKo4{Z4e)lm_4;yi4RK59^0I{a}yG? z=k`Y8g2Wtw-AQ~uF!(}h``dj}Z&haB85-VZ4`CnK2e5g+I%0P|5sp+VP@bE5Z`ru# zFB4*ag{?g?;{|JHFzBiG4%U;@jZ|)X9)2&%x4*smhewc`9tuxg#>{?EJ0nXf8%25c zI6VbMF0P!MvyVbt4WPwS4Xn(CK7Hb#vUmD~;>YQVsIa}yIxfGR$Iy!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9(b`o zEponjuA&&JS;#<80r;MpU%nBjqGoXs7K~R!E?fZbP?v%q*7FryDGXq}-&SG2Z2;zF zp5we0bSLne!2Eu4_w5Acc}-8_yVfZ1EaY$1|6Ok*u)jZd0Be6+g~)#gaMjn}dx7IVd%J=C?|=^j z>;AT&zfS?{WH8fb$?$9}m1;K;V-=jNm5z#3GMn{1(uq{jD|zKiCYlljywaIwe0Xr1 z+1I;$*fa&JWnm^A?SLfhnqygaG?_JJ3}+_G<0wsRHMeZ*>Q9*6iJsm8RAM-2rpvk9 z9^sBYV5PihTboc%jjEKfV_gCFwUlLgt|_BN)7&R!ur3kEu=pe1SeGcuM^)jvqod^vdVoM!J(>#n&ia9uSAShjRb5#<_42+Yx z|LD6Y=Q}Lla2HEr^5xf$O-rpsPv2m7SD!h!Wy|)&usPh--Iu_GTluuQurH~y{N32s J#bqzT{|0 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * Acknowledgement: + * This file is crafted from nandtest.c by Miguel Freitas (miguel@cetuc.puc-rio.br) + * and Steven J. Hill (sjhill@cotw.com) + * + * Overview: + * Formatting a YAFFS device is very simple. Just erase all undamaged blocks. + * NB Don't erase blocks maked as damaged. + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +// countBits is a quick way of counting the number of bits in a byte. +// ie. countBits[n] holds the number of 1 bits in a byte with the value n. + +static const char countBits[256] = +{ +0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4, +1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5, +1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5, +2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6, +1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5, +2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6, +2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6, +3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7, +1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5, +2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6, +2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6, +3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7, +2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6, +3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7, +3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7, +4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8 +}; + +/* + * Buffer arrays used for running tests + */ + +unsigned char oobbuf[16]; + + +/* + * Main program + */ +int main(int argc, char **argv) +{ + unsigned long addr; + int bs, fd, i; + struct mtd_oob_buf oob = {0, 16, (unsigned char *) &oobbuf}; + mtd_info_t meminfo; + erase_info_t erase; + + /* Make sure a device was specified */ + if(argc < 2) { + printf("usage: %s \n", argv[0]); + exit(1); + } + + /* Open the device */ + if((fd = open(argv[1], O_RDWR)) == -1) { + perror("open flash"); + exit(1); + } + + /* Fill in MTD device capability structure */ + if(ioctl(fd, MEMGETINFO, &meminfo) != 0) { + perror("MEMGETINFO"); + close(fd); + exit(1); + } + + /* Make sure device page sizes are valid */ + if( !(meminfo.oobsize == 16 && meminfo.oobblock == 512)) + { + printf("Unknown flash (not normal NAND)\n"); + close(fd); + exit(1); + } + + + for(addr = 0; addr < meminfo.size; addr += meminfo.erasesize) + { + /* Read the OOB data to determine if the block is valid. + * If the block is damaged, then byte 5 of the OOB data will + * have at least 2 zero bits. + */ + oob.start = addr; + oob.length = 16; + oob.ptr = oobbuf; + if (ioctl(fd, MEMREADOOB, &oob) != 0) + { + perror("ioctl(MEMREADOOB)"); + close(fd); + exit(1); + } + + if(countBits[oobbuf[5]] < 7) + { + printf("Block at 0x08%lx is damaged and is not being formatted\n",addr); + } + else + { + /* Erase this block */ + erase.start = addr; + erase.length = meminfo.erasesize; + printf("Erasing block at 0x08%lx\n",addr); + if(ioctl(fd, MEMERASE, &erase) != 0) + { + perror("\nMTD Erase failure\n"); + close(fd); + exit(1); + } + + } + + } + + + /* All the tests succeeded */ + printf("OK\n"); + close(fd); + return 0; +} + diff --git a/yaffs-header.c b/yaffs-header.c new file mode 100644 index 0000000..7cb71e0 --- /dev/null +++ b/yaffs-header.c @@ -0,0 +1,13 @@ +/* + * YAFFS: Yet another FFS. A NAND-flash specific file system. + * + * Copyright (C) 2002 Aleph One Ltd. + * for Toby Churchill Ltd and Brightstar Engineering + * + * Created by Charles Manning + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + */ diff --git a/yaffs_fileem.c b/yaffs_fileem.c new file mode 100644 index 0000000..a137fb4 --- /dev/null +++ b/yaffs_fileem.c @@ -0,0 +1,145 @@ +/* + * YAFFS: Yet another FFS. A NAND-flash specific file system. + * yaffs_fileem.c NAND emulation on top of files + * + * Copyright (C) 2002 Aleph One Ltd. + * for Toby Churchill Ltd and Brightstar Engineering + * + * Created by Charles Manning + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + */ + //yaffs_fileem.c + +#include "yaffs_nandif.h" +#include "yaffs_guts.h" +#include "yaffsinterface.h" + +#include +#include +#include +#include +#include +#include +#include + +#define FILE_SIZE_IN_MEG 2 + +#define BLOCK_SIZE (32 * 528) +#define BLOCKS_PER_MEG ((1024*1024)/(32 * 512)) +#define FILE_SIZE_IN_BLOCKS (FILE_SIZE_IN_MEG * BLOCKS_PER_MEG) +#define FILE_SIZE_IN_BYTES (FILE_SIZE_IN_BLOCKS * BLOCK_SIZE) + + +static int h; +static __u8 ffChunk[528]; + + + +static void CheckInit(void) +{ + static int initialised = 0; + + int length; + + + if(!initialised) + { + memset(ffChunk,0xFF,528); + + h = open("yaffs-em-file" , O_RDWR | O_CREAT, S_IREAD | S_IWRITE); + if(h < 0) + { + perror("Fatal error opening yaffs emulation file"); + exit(1); + } + initialised = 1; + + length = lseek(h,0,SEEK_END); + if(length != FILE_SIZE_IN_BYTES) + { + // Create file contents + int i; + + printf("Creating emulation file...\n"); + for(i = 0; i < FILE_SIZE_IN_BLOCKS; i++) + { + yaffs_EraseBlockInNAND(i); + } + } + } +} + +int yaffs_WriteChunkToNAND(int chunkInNAND,__u8 *data, yaffs_Spare *spare) +{ + int pos; + + pos = chunkInNAND * 528; + + CheckInit(); + + + if(data) + { + lseek(h,pos,SEEK_SET); + write(h,data,512); + } + + pos += 512; + + if(spare) + { + lseek(h,pos,SEEK_SET); + write(h,spare,16); + } + + return YAFFS_OK; +} + + +int yaffs_ReadChunkFromNAND(int chunkInNAND, __u8 *data, yaffs_Spare *spare) +{ + int pos; + + pos = chunkInNAND * 528; + + + CheckInit(); + + if(data) + { + lseek(h,pos,SEEK_SET); + read(h,data,512); + } + + pos += 512; + + if(spare) + { + lseek(h,pos,SEEK_SET); + read(h,spare,16); + } + + return YAFFS_OK; +} + + +int yaffs_EraseBlockInNAND(int blockInNAND) +{ + int i; + + CheckInit(); + + printf("Erasing block %d\n",blockInNAND); + + lseek(h,blockInNAND * BLOCK_SIZE,SEEK_SET); + for(i = 0; i < 32; i++) + { + write(h,ffChunk,528); + } + return YAFFS_OK; +} + diff --git a/yaffs_fs.c b/yaffs_fs.c new file mode 100644 index 0000000..a0ada39 --- /dev/null +++ b/yaffs_fs.c @@ -0,0 +1,879 @@ +/* + * YAFFS: Yet another FFS. A NAND-flash specific file system. + * yaffs_fs.c + * + * Copyright (C) 2002 Aleph One Ltd. + * for Toby Churchill Ltd and Brightstar Engineering + * + * Created by Charles Manning + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This is the file system front-end to YAFFS that hooks it up to + * the VFS. + * + * Special notes: + * >> sb->u.generic_sbp points to the yaffs_Device associated with this superblock + * >> inode->u.generic_ip points to the associated yaffs_Object. + */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "yaffs_guts.h" + +#ifdef YAFFS_RAM_ENABLED +#include "yaffs_nandemul.h" +// 2 MB of RAM for emulation +#define YAFFS_RAM_EMULATION_SIZE 0x200000 +#endif // YAFFS_RAM_ENABLED + +#ifdef YAFFS_MTD_ENABLED +#include +#include "yaffs_mtdif.h" +#endif //YAFFS_MTD_ENABLED + +#define T(x) printk x + + + +#define yaffs_InodeToObject(iptr) ((yaffs_Object *)((iptr)->u.generic_ip)) +#define yaffs_DentryToObject(dptr) yaffs_InodeToObject((dptr)->d_inode) +#define yaffs_SuperToDevice(sb) ((yaffs_Device *)sb->u.generic_sbp) + + + +static ssize_t yaffs_file_read(struct file *f, char *buf, size_t n, loff_t *pos); +static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n, loff_t *pos); + +static int yaffs_sync_object(struct file * file, struct dentry *dentry, int datasync); + +static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir); + +static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode); +static struct dentry * yaffs_lookup(struct inode *dir, struct dentry *dentry); +static int yaffs_link(struct dentry *old_dentry, struct inode * dir, struct dentry * dentry); +static int yaffs_unlink(struct inode * dir, struct dentry *dentry); +static int yaffs_symlink(struct inode * dir, struct dentry *dentry, const char * symname); +static int yaffs_mkdir(struct inode * dir, struct dentry * dentry, int mode); +static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, int dev); +static int yaffs_rename(struct inode * old_dir, struct dentry *old_dentry, struct inode * new_dir,struct dentry *new_dentry); +static int yaffs_setattr(struct dentry *dentry, struct iattr *attr); + +static int yaffs_statfs(struct super_block *sb, struct statfs *buf); +static void yaffs_read_inode (struct inode *inode); +static struct super_block *yaffs_read_super(struct super_block * sb, void * data, int silent); +static void yaffs_put_inode (struct inode *inode); + +//static int yaffs_readpage(struct file*,struct page * + +static struct address_space_operations yaffs_address_ops = { +// readpage: yaffs_readpage, +// prepare_write: yaffs_prepare_write, +// commit_write: yaffs_commit_write +}; + + +static struct file_operations yaffs_file_operations = { + read: yaffs_file_read, + write: yaffs_file_write, +// mmap: generic_file_mmap, + fsync: yaffs_sync_object, +}; + + +static struct inode_operations yaffs_file_inode_operations = { + setattr: yaffs_setattr, +}; + + + +static struct file_operations yaffs_dir_operations = { + read: generic_read_dir, + readdir: yaffs_readdir, + fsync: yaffs_sync_object, +}; + +static struct inode_operations yaffs_dir_inode_operations = { + create: yaffs_create, + lookup: yaffs_lookup, + link: yaffs_link, + unlink: yaffs_unlink, + symlink: yaffs_symlink, + mkdir: yaffs_mkdir, + rmdir: yaffs_unlink, + mknod: yaffs_mknod, + rename: yaffs_rename, + setattr: yaffs_setattr, +}; + +static struct super_operations yaffs_super_ops = { + statfs: yaffs_statfs, + read_inode: yaffs_read_inode, + put_inode: yaffs_put_inode, +// read_inode: +// remount_fs: +// clear_inode: +}; + + +struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,yaffs_Object *obj); + +/* + * Lookup is used to find objects in the fs + */ +static struct dentry * yaffs_lookup(struct inode *dir, struct dentry *dentry) +{ + yaffs_Object *obj; + struct inode *inode; + + + T((KERN_DEBUG"yaffs_lookup for %d:%s\n",yaffs_InodeToObject(dir)->objectId,dentry->d_name.name)); + + obj = yaffs_FindObjectByName(yaffs_InodeToObject(dir),dentry->d_name.name); + + if(obj) + { + T((KERN_DEBUG"yaffs_lookup found %d\n",obj->objectId)); + + inode = yaffs_get_inode(dir->i_sb, obj->st_mode,0,obj); + + if(inode) + { + T((KERN_DEBUG"yaffs_loookup looks good\n")); + dget(dentry); // try to solve directory bug + d_add(dentry,inode); + return dentry; + } + + } + else + { + T((KERN_DEBUG"yaffs_lookup not found\n")); + + } + return NULL; + +} + +// For now put inode is just for debugging +static void yaffs_put_inode(struct inode *inode) +{ + T(("yaffs_put_inode: ino %d, count %d\n",(int)inode->i_ino, atomic_read(&inode->i_count))); +} + +#ifdef YAFFS_ADDRESS_OPS +static int yaffs_readpage(struct file *file, struct page * page) +{ + T((KERN_DEBUG"yaffs_readpage\n")); + + // TODO + return 0; +} + +static int yaffs_prepare_write(struct file *file, struct page *page, unsigned offset, unsigned to) +{ + T((KERN_DEBUG"yaffs_prepare_write\n")); + + //TODO + return 0; +} + +static int yaffs_commit_write(struct file *file, struct page *page, unsigned offset, unsigned to) +{ + + struct inode *inode = page->mapping->host; + loff_t pos = ((loff_t)page->index << PAGE_CACHE_SHIFT) + to; + + T((KERN_DEBUG"yaffs_commit_write\n")); + + return 0; +} + +#endif //YAFFS_ADDRESS_OPS + + +static void yaffs_FillInodeFromObject(struct inode *inode, yaffs_Object *obj) +{ + if (inode && obj) + { + inode->i_ino = obj->objectId; + inode->i_mode = obj->st_mode; + inode->i_uid = obj->st_uid; + inode->i_gid = obj->st_gid; + inode->i_blksize = YAFFS_BYTES_PER_CHUNK; + inode->i_blocks = 0; + inode->i_rdev = NODEV; + inode->i_mapping->a_ops = &yaffs_address_ops; + inode->i_atime = obj->st_atime; + inode->i_mtime = obj->st_mtime; + inode->i_ctime = obj->st_ctime; + inode->i_size = yaffs_GetObjectFileLength(obj); + inode->i_nlink = yaffs_GetObjectLinkCount(obj); + + T((KERN_DEBUG"yaffs_FillInode mode %x uid %d gid %d size %d count %d\n", + inode->i_mode, inode->i_uid, inode->i_gid, (int)inode->i_size, atomic_read(&inode->i_count))); + + switch (obj->st_mode & S_IFMT) + { + default: + // init_special_inode(inode, mode, dev); + break; + case S_IFREG: // file + inode->i_op = &yaffs_file_inode_operations; + inode->i_fop = &yaffs_file_operations; + break; + case S_IFDIR: // directory + inode->i_op = &yaffs_dir_inode_operations; + inode->i_fop = &yaffs_dir_operations; + break; + case S_IFLNK: // symlink + inode->i_op = &page_symlink_inode_operations; + break; + } + + + inode->u.generic_ip = obj; + + } + else + { + T((KERN_DEBUG"yaffs_FileInode invalid parameters\n")); + } + +} + +struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,yaffs_Object *obj) +{ + struct inode * inode; + + T((KERN_DEBUG"yaffs_get_inode for object %d\n",obj->objectId)); + + inode = iget(sb,obj->objectId); + + // No need to call this since iget calls it via the read_inode callback + // yaffs_FillInodeFromObject(inode,obj); + + return inode; +} + +static ssize_t yaffs_file_read(struct file *f, char *buf, size_t n, loff_t *pos) +{ + yaffs_Object *obj; + int nRead,ipos; + struct inode *inode; + + T((KERN_DEBUG"yaffs_file_read\n")); + + obj = yaffs_DentryToObject(f->f_dentry); + inode = f->f_dentry->d_inode; + + if (*pos < inode->i_size) + { + if (*pos + n > inode->i_size) + { + n = inode->i_size - *pos; + } + } + else + { + n = 0; + } + + nRead = yaffs_ReadDataFromFile(obj,buf,*pos,n); + if(nRead > 0) + { + f->f_pos += nRead; + } + ipos = *pos; + T((KERN_DEBUG"yaffs_file_read read %d bytes, %d read at %d\n",n,nRead,ipos)); + return nRead; + +} + +static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n, loff_t *pos) +{ + yaffs_Object *obj; + int nWritten,ipos; + struct inode *inode; + + obj = yaffs_DentryToObject(f->f_dentry); + inode = f->f_dentry->d_inode; + nWritten = yaffs_WriteDataToFile(obj,buf,*pos,n); + ipos = *pos; + T((KERN_DEBUG"yaffs_file_write writing %d bytes, %d written at %d\n",n,nWritten,ipos)); + if(nWritten > 0) + { + *pos += nWritten; + ipos = *pos; + if(*pos > inode->i_size) + { + inode->i_size = *pos; + T((KERN_DEBUG"yaffs_file_write size updated to %d\n",ipos)); + } + + } + return nWritten; +} + + +static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir) +{ + yaffs_Object *obj; + struct inode *inode = f->f_dentry->d_inode; + unsigned long offset, curoffs; + struct list_head *i; + yaffs_Object *l; + + char name[YAFFS_MAX_NAME_LENGTH +1]; + + obj = yaffs_DentryToObject(f->f_dentry); + + offset = f->f_pos; + + T(("yaffs_readdir: starting at %d\n",(int)offset)); + + if(offset == 0) + { + T((KERN_DEBUG"yaffs_readdir: entry . ino %d \n",(int)inode->i_ino)); + if(filldir(dirent,".",1,offset,inode->i_ino,DT_DIR) < 0) + { + goto out; + } + offset++; + f->f_pos++; + } + if(offset == 1) + { + T((KERN_DEBUG"yaffs_readdir: entry .. ino %d \n",(int)f->f_dentry->d_parent->d_inode->i_ino)); + if(filldir(dirent,"..",2,offset,f->f_dentry->d_parent->d_inode->i_ino,DT_DIR) < 0) + { + goto out; + } + offset++; + f->f_pos++; + } + + curoffs = 1; + + //down(&obj->sem); + + + list_for_each(i,&obj->variant.directoryVariant.children) + { + curoffs++; + if(curoffs >= offset) + { + l = list_entry(i, yaffs_Object,siblings); + + yaffs_GetObjectName(l,name,YAFFS_MAX_NAME_LENGTH+1); + T((KERN_DEBUG"yaffs_readdir: %s inode %d\n",name,yaffs_GetObjectInode(l))); + + if(filldir(dirent, + name, + strlen(name), + offset, + yaffs_GetObjectInode(l), + yaffs_GetObjectType(l)) + < 0) + { + goto up_and_out; + } + + offset++; + f->f_pos++; + } + } + + up_and_out: + + //up(&obj->sem); + + out: + return 0; +} + + +/* + * File creation. Allocate an inode, and we're done.. + */ +static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, int dev) +{ + struct inode *inode; + + yaffs_Object *obj = NULL; + yaffs_Object *parent = yaffs_InodeToObject(dir); + + int error = -ENOSPC; + + if(parent) + { + T((KERN_DEBUG"yaffs_mknod: parent object %d type %d\n", + parent->objectId,parent->variantType)); + } + else + { + T((KERN_DEBUG"yaffs_mknod: could not get parent object\n")); + return -EPERM; + } + + T(("yaffs_mknod: making oject for %s, mode %x\n", + dentry->d_name.name, mode)); + + switch (mode & S_IFMT) + { + default: + + break; + case S_IFREG: // file + T((KERN_DEBUG"yaffs_mknod: making file\n")); + obj = yaffs_MknodFile(parent,dentry->d_name.name,mode,current->uid, current->gid); + break; + case S_IFDIR: // directory + T((KERN_DEBUG"yaffs_mknod: making directory\n")); + obj = yaffs_MknodDirectory(parent,dentry->d_name.name,mode,current->uid, current->gid); + break; + case S_IFLNK: // symlink + T((KERN_DEBUG"yaffs_mknod: making file\n")); + obj = NULL; // Todo + break; + } + + if(obj) + { + inode = yaffs_get_inode(dir->i_sb, mode, dev, obj); + +// did not fix dir bug if((mode & S_IFMT) == S_IFDIR) atomic_inc(&inode->i_count); + + d_instantiate(dentry, inode); + T((KERN_DEBUG"yaffs_mknod created object %d count = %d\n",obj->objectId,atomic_read(&inode->i_count))); + error = 0; + } + else + { + T((KERN_DEBUG"yaffs_mknod failed making object\n")); + error = -ENOMEM; + } + + + return error; +} + +static int yaffs_mkdir(struct inode * dir, struct dentry * dentry, int mode) +{ + int retVal; + T((KERN_DEBUG"yaffs_mkdir\n")); + retVal = yaffs_mknod(dir, dentry, mode | S_IFDIR, 0); +#if 0 + // attempt to fix dir bug - didn't work + if(!retVal) + { + dget(dentry); + } +#endif + return retVal; +} + +static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode) +{ + T((KERN_DEBUG"yaffs_create\n")); + return yaffs_mknod(dir, dentry, mode | S_IFREG, 0); +} + + +static int yaffs_unlink(struct inode * dir, struct dentry *dentry) +{ + + T((KERN_DEBUG"yaffs_unlink\n")); + + if(yaffs_Unlink(yaffs_InodeToObject(dir),dentry->d_name.name) == YAFFS_OK) + { + return 0; + } + else + { + return -ENOTEMPTY; + } +} + + +/* + * Link a file.. + */ +static int yaffs_link(struct dentry *old_dentry, struct inode * dir, struct dentry * dentry) +{ + struct inode *inode = old_dentry->d_inode; + + T((KERN_DEBUG"yaffs_link\n")); + + return -EPERM; //Todo + + + if (S_ISDIR(inode->i_mode)) + return -EPERM; + + + return 0; +} + + +static int yaffs_symlink(struct inode * dir, struct dentry *dentry, const char * symname) +{ + int error; + + T((KERN_DEBUG"yaffs_symlink\n")); + + + return -ENOMEM; //Todo + + error = yaffs_mknod(dir, dentry, S_IFLNK | S_IRWXUGO, 0); + return error; +} + +static int yaffs_sync_object(struct file * file, struct dentry *dentry, int datasync) +{ + + T((KERN_DEBUG"yaffs_sync_object\n")); + yaffs_FlushFile(yaffs_DentryToObject(dentry)); + return 0; +} + +/* + * The VFS layer already does all the dentry stuff for rename. + */ +static int yaffs_rename(struct inode * old_dir, struct dentry *old_dentry, struct inode * new_dir,struct dentry *new_dentry) +{ + + + if( yaffs_RenameObject(yaffs_InodeToObject(old_dir),old_dentry->d_name.name, + yaffs_InodeToObject(new_dir),new_dentry->d_name.name) == YAFFS_OK) + { + return 0; + } + else + { + return -ENOTEMPTY; + } + + +} + +static int yaffs_setattr(struct dentry *dentry, struct iattr *attr) +{ + struct inode *inode = dentry->d_inode; + int error; + + T((KERN_DEBUG"yaffs_setattr\n")); + + if((error = inode_change_ok(inode,attr)) == 0) + { + + if(yaffs_SetAttributes(yaffs_InodeToObject(inode),attr) == YAFFS_OK) + { + error = 0; + } + else + { + error = -EPERM; + } + + inode_setattr(inode,attr); + } + return error; +} + +static int yaffs_statfs(struct super_block *sb, struct statfs *buf) +{ + T((KERN_DEBUG"yaffs_statfs\n")); + + buf->f_type = YAFFS_MAGIC; + buf->f_bsize = YAFFS_BYTES_PER_CHUNK; + buf->f_namelen = 255; + buf->f_blocks = yaffs_SuperToDevice(sb)->nBlocks * YAFFS_CHUNKS_PER_BLOCK; + buf->f_files = 0; + buf->f_ffree = 0; + buf->f_bavail = yaffs_GetNumberOfFreeChunks(yaffs_SuperToDevice(sb)); + return 0; +} + +static void yaffs_read_inode (struct inode *inode) +{ + + yaffs_Object *obj ; + + T((KERN_DEBUG"yaffs_read_inode for %d\n",(int)inode->i_ino)); + + obj = yaffs_FindObjectByNumber(yaffs_SuperToDevice(inode->i_sb),inode->i_ino); + + yaffs_FillInodeFromObject(inode,obj); +} + + +static struct super_block *yaffs_internal_read_super(int useRam, struct super_block * sb, void * data, int silent) +{ + struct inode * inode; + struct dentry * root; + yaffs_Device *dev; + + + T(("yaffs_read_super:\n")); + sb->s_blocksize = YAFFS_BYTES_PER_CHUNK; + sb->s_blocksize_bits = YAFFS_CHUNK_SIZE_SHIFT; + sb->s_magic = YAFFS_MAGIC; + sb->s_op = &yaffs_super_ops; + + if(!sb) + printk(KERN_INFO"sb is NULL\n"); + else if(!sb->s_dev) + printk(KERN_INFO"sb->s_dev is NULL\n"); + else if(! kdevname(sb->s_dev)) + printk(KERN_INFO"kdevname is NULL\n"); + else + printk(KERN_INFO"dev is %d name is \"%s\"\n", sb->s_dev, kdevname(sb->s_dev)); + + + if(useRam) + { + +#if YAFFS_RAM_ENABLED + // Set the yaffs_Device up for ram emulation + + sb->u.generic_sbp = dev = kmalloc(sizeof(yaffs_Device),GFP_KERNEL); + if(!dev) + { + // Deep shit could not allocate device structure + printk(KERN_DEBUG"yaffs_read_super: Failed trying to allocate yaffs_Device. Terminating debug.\n"); + return NULL; + } + + memset(dev,0,sizeof(yaffs_Device)); + dev->genericDevice = NULL; // Not used for RAM emulation. + + dev->nBlocks = YAFFS_RAM_EMULATION_SIZE / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK); + dev->startBlock = 1; // Don't use block 0 + dev->endBlock = dev->nBlocks - 1; + + dev->writeChunkToNAND = nandemul_WriteChunkToNAND; + dev->readChunkFromNAND = nandemul_ReadChunkFromNAND; + dev->eraseBlockInNAND = nandemul_EraseBlockInNAND; + dev->initialiseNAND = nandemul_InitialiseNAND; +#endif + + } + else + { +#ifdef YAFFS_MTD_ENABLED + struct mtd_info *mtd; + + // Hope it's a NAND mtd + mtd = get_mtd_device(NULL, MINOR(sb->s_dev)); + if (!mtd) + { + printk(KERN_DEBUG "yaffs: MTD device #%u doesn't appear to exist\n", MINOR(sb->s_dev)); + return NULL; + } + if(mtd->type != MTD_NANDFLASH) + { + printk(KERN_DEBUG "yaffs: MTD device is not NAND it's type %d\n", mtd->type); + return NULL; + } + + if(!mtd->erase || + !mtd->read || + !mtd->write || + !mtd->read_oob || + !mtd->write_oob) + { + printk(KERN_DEBUG "yaffs: MTD device does not support required functions\n"); + return NULL; + } + + if(mtd->oobblock != YAFFS_BYTES_PER_CHUNK || + mtd->oobsize != YAFFS_BYTES_PER_SPARE) + { + printk(KERN_DEBUG "yaffs: MTD device does not support have the right page sizes\n"); + return NULL; + } + + + // OK, so if we got here, we have an MTD that's NAND and looks + // like it has the right capabilities + // Set the yaffs_Device up for ram emulation + + sb->u.generic_sbp = dev = kmalloc(sizeof(yaffs_Device),GFP_KERNEL); + if(!dev) + { + // Deep shit could not allocate device structure + printk(KERN_DEBUG"yaffs_read_super: Failed trying to allocate yaffs_Device. Terminating debug.\n"); + return NULL; + } + + memset(dev,0,sizeof(yaffs_Device)); + dev->genericDevice = mtd; + + // Set up the memory size parameters.... + + dev->nBlocks = mtd->size / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK); + dev->startBlock = 1; // Don't use block 0 + dev->endBlock = dev->nBlocks - 1; + + // ... and the functions. + dev->writeChunkToNAND = nandmtd_WriteChunkToNAND; + dev->readChunkFromNAND = nandmtd_ReadChunkFromNAND; + dev->eraseBlockInNAND = nandmtd_EraseBlockInNAND; + dev->initialiseNAND = nandmtd_InitialiseNAND; + +#endif + } + + + + yaffs_GutsInitialise(yaffs_SuperToDevice(sb)); + T(("yaffs_read_super: guts initialised\n")); + + // Create root inode + inode = yaffs_get_inode(sb, S_IFDIR | 0755, 0,yaffs_Root(yaffs_SuperToDevice(sb))); + if (!inode) + return NULL; + + T(("yaffs_read_super: got root inode\n")); + + + root = d_alloc_root(inode); + + T(("yaffs_read_super: d_alloc_root done\n")); + + if (!root) { + iput(inode); + return NULL; + } + sb->s_root = root; + + T(("yaffs_read_super: done\n")); + return sb; +} + +#ifdef YAFFS_MTD_ENABLED +static struct super_block *yaffs_read_super(struct super_block * sb, void * data, int silent) +{ + return yaffs_internal_read_super(0,sb,data,silent); +} + +static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super, FS_REQUIRES_DEV); +#endif + +#ifdef YAFFS_RAM_ENABLED + +static struct super_block *yaffs_ram_read_super(struct super_block * sb, void * data, int silent) +{ + return yaffs_internal_read_super(1,sb,data,silent); +} + +static DECLARE_FSTYPE(yaffs_ram_fs_type, "yaffsram", yaffs_ram_read_super, FS_SINGLE); +#endif // YAFFS_RAM_ENABLED + + +static struct proc_dir_entry *my_proc_entry; + + +static int yaffs_proc_read( + char *page, + char **start, + off_t offset, + int count, + int *eof, + void *data + ) +{ + + static char my_buffer[1000]; + + if (offset > 0) return 0; + + /* Fill the buffer and get its length */ + sprintf( my_buffer, + "YAFFS built:"__DATE__ " "__TIME__"\n" + + ); + + strcpy(page,my_buffer); + return strlen(my_buffer); +} + +static int __init init_yaffs_fs(void) +{ + int error = 0; + + printk(KERN_DEBUG "yaffs " __DATE__ " " __TIME__ " Initialisation\n"); + /* Install the proc_fs entry */ + my_proc_entry = create_proc_read_entry("yaffs", + S_IRUGO | S_IFREG, + &proc_root, + yaffs_proc_read, + NULL); + if(!my_proc_entry) + { + return -ENOMEM; + } + +#ifdef YAFFS_RAM_ENABLED + + error = register_filesystem(&yaffs_ram_fs_type); + if(error) + { + return error; + } +#endif //YAFFS_RAM_ENABLED + +#ifdef YAFFS_MTD_ENABLED + error = register_filesystem(&yaffs_fs_type); + if(error) + { +#ifdef YAFFS_RAM_ENABLED + unregister_filesystem(&yaffs_ram_fs_type); +#endif //YAFFS_RAM_ENABLED + } +#endif // YAFFS_MTD_ENABLED + + return error; +} + +static void __exit exit_yaffs_fs(void) +{ + printk(KERN_DEBUG "yaffs " __DATE__ " " __TIME__ " Clean up\n"); + + remove_proc_entry("yaffs",&proc_root); + +#ifdef YAFFS_RAM_ENABLED + unregister_filesystem(&yaffs_ram_fs_type); +#endif +#ifdef YAFFS_MTD_ENABLED + unregister_filesystem(&yaffs_fs_type); +#endif + +} + +module_init(init_yaffs_fs) +module_exit(exit_yaffs_fs) + +MODULE_DESCRIPTION("YAFFS - a NAND specific flash file system"); +MODULE_AUTHOR("Charles Manning, Aleph One Ltd., 2002"); +MODULE_LICENSE("GPL"); + diff --git a/yaffs_guts.c b/yaffs_guts.c new file mode 100644 index 0000000..6bc6136 --- /dev/null +++ b/yaffs_guts.c @@ -0,0 +1,3079 @@ +/* + * YAFFS: Yet another FFS. A NAND-flash specific file system. + * yaffs_guts.c The main guts of YAFFS + * + * Copyright (C) 2002 Aleph One Ltd. + * for Toby Churchill Ltd and Brightstar Engineering + * + * Created by Charles Manning + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + */ + //yaffs_guts.c + +#include "yportenv.h" + +#include "yaffsinterface.h" +#include "yaffs_guts.h" + + +#if 0 +#define T(x) printf x +#else +#define T(x) +#endif + + +// countBits is a quick way of counting the number of bits in a byte. +// ie. countBits[n] holds the number of 1 bits in a byte with the value n. + +static const char yaffs_countBits[256] = +{ +0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4, +1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5, +1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5, +2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6, +1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5, +2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6, +2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6, +3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7, +1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5, +2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6, +2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6, +3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7, +2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6, +3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7, +3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7, +4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8 +}; + + + +// Device info +//static yaffs_Device *yaffs_device; +//yaffs_Object *yaffs_rootDir; +//yaffs_Object *yaffs_lostNFound; + + + +// Local prototypes +static int yaffs_CheckObjectHashSanity(yaffs_Device *dev); +static void yaffs_LoadTagsIntoSpare(yaffs_Spare *sparePtr, yaffs_Tags *tagsPtr); +static void yaffs_GetTagsFromSpare(yaffs_Spare *sparePtr,yaffs_Tags *tagsPtr); +static int yaffs_PutChunkIntoFile(yaffs_Object *in,int chunkInInode, int chunkInNAND); + +static yaffs_Object *yaffs_CreateNewObject(yaffs_Device *dev,int number,yaffs_ObjectType type); +static void yaffs_AddObjectToDirectory(yaffs_Object *directory, yaffs_Object *obj); +static int yaffs_UpdateObjectHeader(yaffs_Object *in,const char *name); +static void yaffs_DeleteChunk(yaffs_Device *dev,int chunkId); +static void yaffs_RemoveObjectFromDirectory(yaffs_Object *obj); +static int yaffs_CheckStructures(void); +static yaffs_Object *yaffs_GetEquivalentObject(yaffs_Object *obj); + +loff_t yaffs_GetFileSize(yaffs_Object *obj); + + +static int yaffs_AllocateChunk(yaffs_Device *dev,int useReserve); + +#if YAFFS_PARANOID +static int yaffs_CheckFileSanity(yaffs_Object *in) +#else +#define yaffs_CheckFileSanity(in) +#endif + +static int __inline__ yaffs_HashFunction(int n) +{ + return (n % YAFFS_NOBJECT_BUCKETS); +} + + +yaffs_Object *yaffs_Root(yaffs_Device *dev) +{ + return dev->rootDir; +} + +yaffs_Object *yaffs_LostNFound(yaffs_Device *dev) +{ + return dev->lostNFoundDir; +} + + +static int yaffs_WriteChunkToNAND(struct yaffs_DeviceStruct *dev,int chunkInNAND, const __u8 *data, yaffs_Spare *spare) +{ + return dev->writeChunkToNAND(dev,chunkInNAND,data,spare); +} + +int yaffs_ReadChunkFromNAND(struct yaffs_DeviceStruct *dev,int chunkInNAND, __u8 *data, yaffs_Spare *spare) +{ + return dev->readChunkFromNAND(dev,chunkInNAND,data,spare); +} + +int yaffs_EraseBlockInNAND(struct yaffs_DeviceStruct *dev,int blockInNAND) +{ + return dev->eraseBlockInNAND(dev,blockInNAND); +} + +int yaffs_InitialiseNAND(struct yaffs_DeviceStruct *dev) +{ + return dev->initialiseNAND(dev); +} + +static int yaffs_WriteNewChunkToNAND(struct yaffs_DeviceStruct *dev, const __u8 *data, yaffs_Spare *spare,int useReserve) +{ + int chunk; + + int writeOk = 0; + + do{ + chunk = yaffs_AllocateChunk(dev,useReserve); + + if(chunk >= 0) + { + writeOk = yaffs_WriteChunkToNAND(dev,chunk,data,spare); + if(writeOk) + { + //Todo read-back and verify + // If verify fails, then delete this chunk and try again + } + } + } while(chunk >= 0 && ! writeOk); + + return chunk; +} + + + + +///////////////////////// Object management ////////////////// +// List of spare objects +// The list is hooked together using the first pointer +// in the object + +// static yaffs_Object *yaffs_freeObjects = NULL; + +// static int yaffs_nFreeObjects; + +// static yaffs_ObjectList *yaffs_allocatedObjectList = NULL; + +// static yaffs_ObjectBucket yaffs_objectBucket[YAFFS_NOBJECT_BUCKETS]; + + +static __u16 yaffs_CalcNameSum(const char *name) +{ + __u16 sum = 0; + __u16 i = 1; + + __u8 *bname = (__u8 *)name; + + while (*bname) + { + sum += (*bname) * i; + i++; + bname++; + } + return sum; +} + + +void yaffs_CalcECC(const __u8 *buffer, yaffs_Spare *spare) +{ + + // Todo do nothing now. Need to put in ecc + spare->ecc1[0] = spare->ecc1[1] = spare->ecc1[2] = 0xFF; + spare->ecc2[0] = spare->ecc2[1] = spare->ecc2[2] = 0xFF; +} + +void yaffs_CalcTagsECC(yaffs_Tags *tags) +{ + // Todo don't do anything yet. Need to calculate ecc + tags->ecc = 0xFFFFFFFF; +} + + + +///////////////////////// TNODES /////////////////////// + +// List of spare tnodes +// The list is hooked together using the first pointer +// in the tnode. + +//static yaffs_Tnode *yaffs_freeTnodes = NULL; + +// static int yaffs_nFreeTnodes; + +//static yaffs_TnodeList *yaffs_allocatedTnodeList = NULL; + + + +// yaffs_CreateTnodes creates a bunch more tnodes and +// adds them to the tnode free list. +// Don't use this function directly + +static int yaffs_CreateTnodes(yaffs_Device *dev,int nTnodes) +{ + int i; + yaffs_Tnode *newTnodes; + yaffs_TnodeList *tnl; + + if(nTnodes < 1) return YAFFS_OK; + + // make these things + + newTnodes = YMALLOC(nTnodes * sizeof(yaffs_Tnode)); + + if (!newTnodes) + { + YALERT("Could not malloc tnodes"); + return YAFFS_FAIL; + } + + // Hook them into the free list + for(i = 0; i < nTnodes - 1; i++) + { + newTnodes[i].internal[0] = &newTnodes[i+1]; + } + + newTnodes[nTnodes - 1].internal[0] = dev->freeTnodes; + dev->freeTnodes = newTnodes; + dev->nFreeTnodes+= nTnodes; + dev->nTnodesCreated += nTnodes; + + // Now add this bunch of tnodes to a list for freeing up. + + tnl = YMALLOC(sizeof(yaffs_TnodeList)); + if(!tnl) + { + YALERT("Could not add tnodes to management list"); + } + else + { + tnl->tnodes = newTnodes; + tnl->next = dev->allocatedTnodeList; + dev->allocatedTnodeList = tnl; + } + + + YINFO("Tnodes created"); + + + return YAFFS_OK; +} + + +// GetTnode gets us a clean tnode. Tries to make allocate more if we run out +static yaffs_Tnode *yaffs_GetTnode(yaffs_Device *dev) +{ + yaffs_Tnode *tn = NULL; + + // If there are none left make more + if(!dev->freeTnodes) + { + yaffs_CreateTnodes(dev,YAFFS_ALLOCATION_NTNODES); + } + + if(dev->freeTnodes) + { + tn = dev->freeTnodes; + dev->freeTnodes = dev->freeTnodes->internal[0]; + dev->nFreeTnodes--; + // zero out + memset(tn,0,sizeof(yaffs_Tnode)); + } + + + return tn; +} + + +// FreeTnode frees up a tnode and puts it back on the free list +static void yaffs_FreeTnode(yaffs_Device*dev, yaffs_Tnode *tn) +{ + tn->internal[0] = dev->freeTnodes; + dev->freeTnodes = tn; + dev->nFreeTnodes++; +} + + +static void yaffs_DeinitialiseTnodes(yaffs_Device*dev) +{ + // Free the list of allocated tnodes + + while(dev->allocatedTnodeList) + { + YFREE(dev->allocatedTnodeList->tnodes); + dev->allocatedTnodeList = dev->allocatedTnodeList->next; + } + + dev->freeTnodes = NULL; + dev->nFreeTnodes = 0; +} + +static void yaffs_InitialiseTnodes(yaffs_Device*dev) +{ + dev->allocatedTnodeList = NULL; + dev->freeTnodes = NULL; + dev->nFreeTnodes = 0; + dev->nTnodesCreated = 0; + +} + +void yaffs_TnodeTest(yaffs_Device *dev) +{ + + int i; + int j; + yaffs_Tnode *tn[1000]; + + YINFO("Testing TNodes"); + + for(j = 0; j < 50; j++) + { + for(i = 0; i < 1000; i++) + { + tn[i] = yaffs_GetTnode(dev); + if(!tn[i]) + { + YALERT("Getting tnode failed"); + } + } + for(i = 0; i < 1000; i+=3) + { + yaffs_FreeTnode(dev,tn[i]); + tn[i] = NULL; + } + + } +} + +////////////////// END OF TNODE MANIPULATION /////////////////////////// + +/////////////// Functions to manipulate the look-up tree (made up of tnodes) +// The look up tree is represented by the top tnode and the number of topLevel +// in the tree. 0 means only the level 0 tnode is in the tree. + + +// FindLevel0Tnode finds the level 0 tnode, if one exists. +// Used when reading..... +static yaffs_Tnode *yaffs_FindLevel0Tnode(yaffs_Device *dev,yaffs_FileStructure *fStruct, __u32 chunkId) +{ + + yaffs_Tnode *tn = fStruct->top; + __u32 i; + int requiredTallness; + int level = fStruct->topLevel; + + // Check sane level and chunk Id + if(level < 0 || level > YAFFS_TNODES_MAX_LEVEL) + { + char str[50]; + sprintf(str,"Bad level %d",level); + YALERT(str); + return NULL; + } + if(chunkId > YAFFS_MAX_CHUNK_ID) + { + char str[50]; + sprintf(str,"Bad chunkId %d",chunkId); + YALERT(str); + return NULL; + } + + // First check we're tall enough (ie enough topLevel) + + i = chunkId >> (dev->chunkGroupBits + YAFFS_TNODES_LEVEL0_BITS); + requiredTallness = 0; + while(i) + { + i >>= YAFFS_TNODES_INTERNAL_BITS; + requiredTallness++; + } + + + if(requiredTallness > fStruct->topLevel) + { + // Not tall enough, so we can't find it, return NULL. + return NULL; + } + + + // Traverse down to level 0 + while (level > 0 && tn) + { + tn = tn->internal[(chunkId >>(dev->chunkGroupBits + YAFFS_TNODES_LEVEL0_BITS + (level-1) * YAFFS_TNODES_INTERNAL_BITS)) & + YAFFS_TNODES_INTERNAL_MASK]; + level--; + + } + + return tn; +} + +// AddOrFindLevel0Tnode finds the level 0 tnode if it exists, otherwise first expands the tree. +// This happens in two steps: +// 1. If the tree isn't tall enough, then make it taller. +// 2. Scan down the tree towards the level 0 tnode adding tnodes if required. +// +// Used when modifying the tree. +// +static yaffs_Tnode *yaffs_AddOrFindLevel0Tnode(yaffs_Device *dev, yaffs_FileStructure *fStruct, __u32 chunkId) +{ + + yaffs_Tnode *tn; + + int requiredTallness; + + __u32 i; + __u32 l; + + + T(("AddOrFind topLevel=%d, chunk=%d",fStruct->topLevel,chunkId)); + + // Check sane level and page Id + if(fStruct->topLevel < 0 || fStruct->topLevel > YAFFS_TNODES_MAX_LEVEL) + { + char str[50]; + sprintf(str,"Bad level %d",fStruct->topLevel); + YALERT(str); + return NULL; + } + + if(chunkId > YAFFS_MAX_CHUNK_ID) + { + char str[50]; + sprintf(str,"Bad chunkId %d",chunkId); + YALERT(str); + return NULL; + } + + // First check we're tall enough (ie enough topLevel) + + i = chunkId >> (dev->chunkGroupBits + YAFFS_TNODES_LEVEL0_BITS); + requiredTallness = 0; + while(i) + { + i >>= YAFFS_TNODES_INTERNAL_BITS; + requiredTallness++; + } + + T((" required=%d",requiredTallness)); + + + if(requiredTallness > fStruct->topLevel) + { + // Not tall enough,gotta make the tree taller + for(i = fStruct->topLevel; i < requiredTallness; i++) + { + T((" add new top")); + + tn = yaffs_GetTnode(dev); + + if(tn) + { + tn->internal[0] = fStruct->top; + fStruct->top = tn; + } + else + { + YALERT("No more tnodes"); + } + } + + fStruct->topLevel = requiredTallness; + } + + + // Traverse down to level 0, adding anything we need + + l = fStruct->topLevel; + tn = fStruct->top; + while (l > 0 && tn) + { + i = (chunkId >> (dev->chunkGroupBits +YAFFS_TNODES_LEVEL0_BITS + (l-1) * YAFFS_TNODES_INTERNAL_BITS)) & + YAFFS_TNODES_INTERNAL_MASK; + + T((" [%d:%d]",l,i)); + + if(!tn->internal[i]) + { + T((" added")); + + tn->internal[i] = yaffs_GetTnode(dev); + } + + tn = tn->internal[i]; + l--; + + } + + T(("\n")); + + return tn; +} + + +// Pruning removes any part of the file structure tree that is beyond the +// bounds of the file. +// A file should only get pruned when its size is reduced. +// +// Before pruning, the chunks must be pulled from the tree and the +// level 0 tnode entries must be zeroed out. +// Could also use this for file deletion, but that's probably better handled +// by a special case. + +// yaffs_PruneWorker should only be called by yaffs_PruneFileStructure() + +static yaffs_Tnode *yaffs_PruneWorker(yaffs_Device *dev, yaffs_Tnode *tn, __u32 level, int del0) +{ + int i; + int hasData; + + if(tn) + { + hasData = 0; + + for(i = 0; i < YAFFS_NTNODES_INTERNAL; i++) + { + if(tn->internal[i] && level > 0) + { + tn->internal[i] = yaffs_PruneWorker(dev,tn->internal[i],level - 1, ( i == 0) ? del0 : 1); + } + + if(tn->internal[i]) + { + hasData++; + } + } + + if(hasData == 0 && del0) + { + // Free and return NULL + + yaffs_FreeTnode(dev,tn); + tn = NULL; + } + + } + + return tn; + +} + +static int yaffs_PruneFileStructure(yaffs_Device *dev, yaffs_FileStructure *fStruct) +{ + int i; + int hasData; + int done = 0; + yaffs_Tnode *tn; + + if(fStruct->topLevel > 0) + { + fStruct->top = yaffs_PruneWorker(dev,fStruct->top, fStruct->topLevel,0); + + // Now we have a tree with all the non-zero branches NULL but the height + // is the same as it was. + // Let's see if we can trim internal tnodes to shorten the tree. + // We can do this if only the 0th element in the tnode is in use + // (ie all the non-zero are NULL) + + while(fStruct->topLevel && !done) + { + tn = fStruct->top; + + hasData = 0; + for(i = 1; i internal[i]) + { + hasData++; + } + } + + if(!hasData) + { + fStruct->top = tn->internal[0]; + fStruct->topLevel--; + yaffs_FreeTnode(dev,tn); + } + else + { + done = 1; + } + } + } + + return YAFFS_OK; +} + + + + +/////////////////////// End of File Structure functions. ///////////////// + +// yaffs_CreateFreeObjects creates a bunch more objects and +// adds them to the object free list. +static int yaffs_CreateFreeObjects(yaffs_Device *dev, int nObjects) +{ + int i; + yaffs_Object *newObjects; + yaffs_ObjectList *list; + + if(nObjects < 1) return YAFFS_OK; + + // make these things + + newObjects = YMALLOC(nObjects * sizeof(yaffs_Object)); + + if (!newObjects) + { + YALERT("Could not allocate more objects"); + return YAFFS_FAIL; + } + + // Hook them into the free list + for(i = 0; i < nObjects - 1; i++) + { + (yaffs_Object *)newObjects[i].siblings.next = &newObjects[i+1]; + } + + newObjects[nObjects - 1].siblings.next = (void *)dev->freeObjects; + dev->freeObjects = newObjects; + dev->nFreeObjects+= nObjects; + dev->nObjectsCreated+= nObjects; + + // Now add this bunch of Objects to a list for freeing up. + + list = YMALLOC(sizeof(yaffs_ObjectList)); + if(!list) + { + YALERT("Could not add Objects to management list"); + } + else + { + list->objects = newObjects; + list->next = dev->allocatedObjectList; + dev->allocatedObjectList = list; + } + + + YINFO("Objects created"); + + + return YAFFS_OK; +} + + +// AllocateEmptyObject gets us a clean Object. Tries to make allocate more if we run out +static yaffs_Object *yaffs_AllocateEmptyObject(yaffs_Device *dev) +{ + yaffs_Object *tn = NULL; + + // If there are none left make more + if(!dev->freeObjects) + { + yaffs_CreateFreeObjects(dev,YAFFS_ALLOCATION_NOBJECTS); + } + + if(dev->freeObjects) + { + tn = dev->freeObjects; + dev->freeObjects = (yaffs_Object *)(dev->freeObjects->siblings.next); + dev->nFreeObjects--; + + // Now sweeten it up... + + memset(tn,0,sizeof(yaffs_Object)); + tn->chunkId = -1; + tn->variantType = YAFFS_OBJECT_TYPE_UNKNOWN; + INIT_LIST_HEAD(&(tn->hardLinks)); + INIT_LIST_HEAD(&(tn->hashLink)); + INIT_LIST_HEAD(&tn->siblings); + + // Add it to the lost and found directory. + // NB Can't put root or lostNFound in lostNFound so + // check if lostNFound exists first + if(dev->lostNFoundDir) + { + yaffs_AddObjectToDirectory(dev->lostNFoundDir,tn); + } + } + + + return tn; +} + +static yaffs_Object *yaffs_CreateFakeDirectory(yaffs_Device *dev,int number,__u32 mode) +{ + + yaffs_Object *obj = yaffs_CreateNewObject(dev,number,YAFFS_OBJECT_TYPE_DIRECTORY); + if(obj) + { + obj->fake = 1; // it is fake so it has no NAND presence... + obj->renameAllowed= 0; // ... and we're not allowed to rename it... + obj->unlinkAllowed= 0; // ... or unlink it + obj->st_mode = mode; + obj->myDev = dev; + obj->chunkId = 0; // Not a valid chunk. + } + + return obj; + +} + + +static void yaffs_UnhashObject(yaffs_Object *tn) +{ + int bucket; + yaffs_Device *dev = tn->myDev; + + + // If it is still linked into the bucket list, free from the list + if(!list_empty(&tn->hashLink)) + { + list_del_init(&tn->hashLink); + bucket = yaffs_HashFunction(tn->objectId); + dev->objectBucket[bucket].count--; + } + +} + + +// FreeObject frees up a Object and puts it back on the free list +static void yaffs_FreeObject(yaffs_Object *tn) +{ + + yaffs_Device *dev = tn->myDev; + + yaffs_UnhashObject(tn); + + // Link into the free list. + (yaffs_Object *)(tn->siblings.next) = dev->freeObjects; + dev->freeObjects = tn; + dev->nFreeObjects++; +} + + + + +static void yaffs_DeinitialiseObjects(yaffs_Device *dev) +{ + // Free the list of allocated Objects + + while( dev->allocatedObjectList) + { + YFREE(dev->allocatedObjectList->objects); + dev->allocatedObjectList = dev->allocatedObjectList->next; + } + + dev->freeObjects = NULL; + dev->nFreeObjects = 0; +} + +static void yaffs_InitialiseObjects(yaffs_Device *dev) +{ + int i; + + dev->allocatedObjectList = NULL; + dev->freeObjects = NULL; + dev->nFreeObjects = 0; + + for(i = 0; i < YAFFS_NOBJECT_BUCKETS; i++) + { + INIT_LIST_HEAD(&dev->objectBucket[i].list); + dev->objectBucket[i].count = 0; + } + +} + + + + + + +int yaffs_FindNiceObjectBucket(yaffs_Device *dev) +{ + static int x = 0; + int i; + int l = 999; + int lowest = 999999; + + + // First let's see if we can find one that's empty. + + for(i = 0; i < 10 && lowest > 0; i++) + { + x++; + x %= YAFFS_NOBJECT_BUCKETS; + if(dev->objectBucket[x].count < lowest) + { + lowest = dev->objectBucket[x].count; + l = x; + } + + } + + // If we didn't find an empty list, then try + // looking a bit further for a short one + + for(i = 0; i < 10 && lowest > 3; i++) + { + x++; + x %= YAFFS_NOBJECT_BUCKETS; + if(dev->objectBucket[x].count < lowest) + { + lowest = dev->objectBucket[x].count; + l = x; + } + + } + + return l; +} + +static int yaffs_CreateNewObjectNumber(yaffs_Device *dev) +{ + int bucket = yaffs_FindNiceObjectBucket(dev); + + // Now find an object value that has not already been taken + // by scanning the list. + + int found = 0; + struct list_head *i; + + int n = bucket; + + //yaffs_CheckObjectHashSanity(); + + while(!found) + { + found = 1; + n += YAFFS_NOBJECT_BUCKETS; + if(1 ||dev->objectBucket[bucket].count > 0) + { + list_for_each(i,&dev->objectBucket[bucket].list) + { + // If there is already one in the list + if(list_entry(i, yaffs_Object,hashLink)->objectId == n) + { + found = 0; + } + } + } + } + + //T(("bucket %d count %d inode %d\n",bucket,yaffs_objectBucket[bucket].count,n); + + return n; +} + +void yaffs_HashObject(yaffs_Object *in) +{ + int bucket = yaffs_HashFunction(in->objectId); + yaffs_Device *dev = in->myDev; + + if(!list_empty(&in->hashLink)) + { + YINFO("!!!"); + } + + + list_add(&in->hashLink,&dev->objectBucket[bucket].list); + dev->objectBucket[bucket].count++; + +} + +yaffs_Object *yaffs_FindObjectByNumber(yaffs_Device *dev,int number) +{ + int bucket = yaffs_HashFunction(number); + struct list_head *i; + yaffs_Object *in; + + list_for_each(i,&dev->objectBucket[bucket].list) + { + // Lookm if it is in the list + in = list_entry(i, yaffs_Object,hashLink); + if(in->objectId == number) + { + return in; + } + } + + return NULL; +} + + + +yaffs_Object *yaffs_CreateNewObject(yaffs_Device *dev,int number,yaffs_ObjectType type) +{ + + yaffs_Object *theObject; + + if(number < 0) + { + number = yaffs_CreateNewObjectNumber(dev); + } + + theObject = yaffs_AllocateEmptyObject(dev); + + if(theObject) + { + theObject->fake = 0; + theObject->renameAllowed = 1; + theObject->unlinkAllowed = 1; + theObject->objectId = number; + theObject->myDev = dev; + yaffs_HashObject(theObject); + theObject->variantType = type; + theObject->st_atime = theObject->st_mtime = theObject->st_ctime = CURRENT_TIME; + + switch(type) + { + case YAFFS_OBJECT_TYPE_FILE: + theObject->variant.fileVariant.fileSize = 0; + theObject->variant.fileVariant.topLevel = 0; + theObject->variant.fileVariant.top = yaffs_GetTnode(dev); + break; + case YAFFS_OBJECT_TYPE_DIRECTORY: + INIT_LIST_HEAD(&theObject->variant.directoryVariant.children); + break; + case YAFFS_OBJECT_TYPE_SYMLINK: + break; + case YAFFS_OBJECT_TYPE_HARDLINK: + break; + case YAFFS_OBJECT_TYPE_UNKNOWN: + // todo this should not happen + } + } + + return theObject; +} + +yaffs_Object *yaffs_FindOrCreateObjectByNumber(yaffs_Device *dev, int number,yaffs_ObjectType type) +{ + yaffs_Object *theObject = NULL; + + if(number >= 0) + { + theObject = yaffs_FindObjectByNumber(dev,number); + } + + if(!theObject) + { + theObject = yaffs_CreateNewObject(dev,number,type); + } + + return theObject; + +} + +char *yaffs_CloneString(const char *str) +{ + char *newStr = NULL; + + if(str && *str) + { + newStr = YMALLOC(strlen(str) + 1); + strcpy(newStr,str); + } + + return newStr; + +} + +// +// Mknod (create) a new object. +// equivalentObject only has meaning for a hard link; +// aliasString only has meaning for a sumlink. +yaffs_Object *yaffs_MknodObject( yaffs_ObjectType type, + yaffs_Object *parent, + const char *name, + __u32 mode, + __u32 uid, + __u32 gid, + yaffs_Object *equivalentObject, + const char *aliasString) +{ + yaffs_Object *in; + + yaffs_Device *dev = parent->myDev; + + in = yaffs_CreateNewObject(dev,-1,type); + + if(in) + { + in->chunkId = -1; + in->valid = 1; + in->variantType = type; + + in->st_mode = mode; + in->st_uid = uid; + in->st_gid = gid; + in->st_atime = in->st_mtime = in->st_ctime = CURRENT_TIME; + + in->sum = yaffs_CalcNameSum(name); + in->dirty = 1; + + yaffs_AddObjectToDirectory(parent,in); + + in->myDev = parent->myDev; + + + switch(type) + { + case YAFFS_OBJECT_TYPE_SYMLINK: + in->variant.symLinkVariant.alias = yaffs_CloneString(aliasString); + break; + case YAFFS_OBJECT_TYPE_HARDLINK: + in->variant.hardLinkVariant.equivalentObject = equivalentObject; + in->variant.hardLinkVariant.equivalentObjectId = equivalentObject->objectId; + list_add(&in->hardLinks,&equivalentObject->hardLinks); + break; + case YAFFS_OBJECT_TYPE_FILE: // do nothing + case YAFFS_OBJECT_TYPE_DIRECTORY: // do nothing + case YAFFS_OBJECT_TYPE_UNKNOWN: + } + + yaffs_UpdateObjectHeader(in,name); + + } + + return in; +} + +yaffs_Object *yaffs_MknodFile(yaffs_Object *parent,const char *name, __u32 mode, __u32 uid, __u32 gid) +{ + return yaffs_MknodObject(YAFFS_OBJECT_TYPE_FILE,parent,name,mode,uid,gid,NULL,NULL); +} + +yaffs_Object *yaffs_MknodDirectory(yaffs_Object *parent,const char *name, __u32 mode, __u32 uid, __u32 gid) +{ + return yaffs_MknodObject(YAFFS_OBJECT_TYPE_DIRECTORY,parent,name,mode,uid,gid,NULL,NULL); +} + +yaffs_Object *yaffs_MknodSymLink(yaffs_Object *parent,const char *name, __u32 mode, __u32 uid, __u32 gid,const char *alias) +{ + return yaffs_MknodObject(YAFFS_OBJECT_TYPE_SYMLINK,parent,name,mode,uid,gid,NULL,alias); +} + +// NB yaffs_Link returns the object id of the equivalent object. +yaffs_Object *yaffs_Link(yaffs_Object *parent, const char *name, yaffs_Object *equivalentObject) +{ + // Get the real object in case we were fed a hard link as an equivalent object + equivalentObject = yaffs_GetEquivalentObject(equivalentObject); + + if(yaffs_MknodObject(YAFFS_OBJECT_TYPE_HARDLINK,parent,name,0,0,0,equivalentObject,NULL)) + { + return equivalentObject; + } + else + { + return NULL; + } + +} + + +static int yaffs_ChangeObjectName(yaffs_Object *obj, yaffs_Object *newDir, const char *newName) +{ + //yaffs_Device *dev = obj->myDev; + + if(newDir == NULL) + { + newDir = obj->parent; // use the old directory + } + + // Only proceed if the new name does not exist and + // if we're putting it into a directory. + if(!yaffs_FindObjectByName(newDir,newName) && + newDir->variantType == YAFFS_OBJECT_TYPE_DIRECTORY) + { + obj->sum = yaffs_CalcNameSum(newName); + obj->dirty = 1; + yaffs_AddObjectToDirectory(newDir,obj); + + return yaffs_UpdateObjectHeader(obj,newName); + } + + return YAFFS_FAIL; +} + +int yaffs_RenameObject(yaffs_Object *oldDir, const char *oldName, yaffs_Object *newDir, const char *newName) +{ + yaffs_Object *obj; + + obj = yaffs_FindObjectByName(oldDir,oldName); + if(obj && obj->renameAllowed) + { + return yaffs_ChangeObjectName(obj,newDir,newName); + } + return YAFFS_FAIL; +} + + + +static int yaffs_CheckObjectHashSanity(yaffs_Device *dev) +{ + // Scan the buckets and check that the lists + // have as many members as the count says there are + int bucket; + int countEm; + struct list_head *j; + int ok = YAFFS_OK; + + for(bucket = 0; bucket < YAFFS_NOBJECT_BUCKETS; bucket++) + { + countEm = 0; + + list_for_each(j,&dev->objectBucket[bucket].list) + { + countEm++; + } + + if(countEm != dev->objectBucket[bucket].count) + { + YALERT("Inode hash inconsistency"); + ok = YAFFS_FAIL; + } + } + + return ok; +} + +void yaffs_ObjectTest(yaffs_Device *dev) +{ + yaffs_Object *in[1000]; + int inNo[1000]; + yaffs_Object *inold[1000]; + int i; + int j; + + memset(in,0,1000*sizeof(yaffs_Object *)); + memset(inold,0,1000*sizeof(yaffs_Object *)); + + yaffs_CheckObjectHashSanity(dev); + + for(j = 0; j < 10; j++) + { + T(("%d\n",j)); + + for(i = 0; i < 1000; i++) + { + in[i] = yaffs_CreateNewObject(dev,-1,YAFFS_OBJECT_TYPE_FILE); + if(!in[i]) + { + YINFO("No more inodes"); + } + else + { + inNo[i] = in[i]->objectId; + } + } + + for(i = 0; i < 1000; i++) + { + if(yaffs_FindObjectByNumber(dev,inNo[i]) != in[i]) + { + T(("Differnce in look up test\n")); + } + else + { + // T(("Look up ok\n")); + } + } + + yaffs_CheckObjectHashSanity(dev); + + for(i = 0; i < 1000; i+=3) + { + yaffs_FreeObject(in[i]); + in[i] = NULL; + } + + + yaffs_CheckObjectHashSanity(dev); + } + +} + + + +/////////////////////////// Block Management and Page Allocation /////////////////// + + +static void yaffs_InitialiseBlocks(yaffs_Device *dev) +{ + dev->blockInfo = YMALLOC(dev->nBlocks * sizeof(yaffs_BlockInfo)); + memset(dev->blockInfo,0,dev->nBlocks * sizeof(yaffs_BlockInfo)); + dev->allocationBlock = -1; // force it to get a new one +} + +static void yaffs_DeinitialiseBlocks(yaffs_Device *dev) +{ + YFREE(dev->blockInfo); +} + +// FindDiretiestBlock is used to select the dirtiest block (or close enough) +// for garbage collection. + +static int yaffs_FindDirtiestBlock(yaffs_Device *dev) +{ + + int b = dev->currentDirtyChecker; + + int i; + int dirtiest = -1; + int pagesInUse = 100; // silly big number + + for(i = dev->startBlock; i <= dev->endBlock && pagesInUse > 2 ; i++) + { + b++; + if (b > dev->endBlock) + { + b = dev->startBlock; + } + + if(dev->blockInfo[b].blockState == YAFFS_BLOCK_STATE_FULL && + (dev->blockInfo)[b].pagesInUse < pagesInUse) + { + dirtiest = b; + pagesInUse = (dev->blockInfo)[b].pagesInUse; + } + } + + dev->currentDirtyChecker = b; + + return dirtiest; +} + + +static int yaffs_FindBlockForAllocation(yaffs_Device *dev,int useReserve) +{ + int i; + + if(useReserve && dev->nErasedBlocks < 1) + { + // Hoosterman we've got a problem. + // Can't get space to gc + return -1; + } + else if(!useReserve && dev->nErasedBlocks <= YAFFS_RESERVED_BLOCKS) + { + // We are not in GC, so we hold some in reserve so we can get + // a gc done. + } + + // Find an empty block. + + for(i = dev->startBlock; i <= dev->endBlock; i++) + { + + if(dev->blockInfo[i].blockState == YAFFS_BLOCK_STATE_EMPTY) + { + dev->blockInfo[i].blockState = YAFFS_BLOCK_STATE_ALLOCATING; + dev->nErasedBlocks--; + if(dev->nErasedBlocks <= YAFFS_RESERVED_BLOCKS) + { + dev->garbageCollectionRequired = 1; + } + + return i; + } + } + + return -1; +} + + +static void yaffs_BlockBecameDirty(yaffs_Device *dev,int blockNo) +{ + yaffs_BlockInfo *bi = &dev->blockInfo[blockNo]; + + // Mark as dirty, erase it and mark as clean. + bi->blockState = YAFFS_BLOCK_STATE_DIRTY; + yaffs_EraseBlockInNAND(dev,blockNo); + bi->blockState = YAFFS_BLOCK_STATE_EMPTY; + dev->nErasedBlocks++; + bi->pagesInUse = 0; + bi->pageBits = 0; + + T(("Erased block %d\n",blockNo)); +} + + +static int yaffs_AllocateChunk(yaffs_Device *dev,int useReserve) +{ + int retVal; + + if(dev->allocationBlock < 0) + { + // Get next block to allocate off + dev->allocationBlock = yaffs_FindBlockForAllocation(dev,useReserve); + dev->allocationPage = 0; + } + + // Next page please.... + if(dev->allocationBlock >= 0) + { + retVal = (dev->allocationBlock * YAFFS_CHUNKS_PER_BLOCK) + + dev->allocationPage; + dev->blockInfo[dev->allocationBlock].pagesInUse++; + dev->blockInfo[dev->allocationBlock].pageBits |= + (1 << (dev->allocationPage)); + + dev->allocationPage++; + + dev->nFreeChunks--; + + // If the block is full set the state to full + if(dev->allocationPage >= YAFFS_CHUNKS_PER_BLOCK) + { + dev->blockInfo[dev->allocationBlock].blockState = YAFFS_BLOCK_STATE_FULL; + dev->allocationBlock = -1; + } + +#ifdef YAFFS_PARANOID + if(yaffs_CheckChunkErased(retVal) == YAFFS_FAIL) + { + T(("..................Trying to allocate non-erased page %d\n",retVal)); + } +#endif + return retVal; + + } + T(("!!!!!!!!! Allocator out !!!!!!!!!!!!!!!!!\n")); + + return -1; +} + + +int yaffs_GarbageCollectBlock(yaffs_Device *dev,int block) +{ + int oldChunk; + int newChunk; + __u32 mask; + + + yaffs_Spare spare; + yaffs_Tags tags; + __u8 buffer[YAFFS_BYTES_PER_CHUNK]; + + yaffs_BlockInfo *bi = &dev->blockInfo[block]; + + yaffs_Object *object; + + T(("Collecting block %d n %d bits %x\n",block, bi->pagesInUse, bi->pageBits)); + + for(mask = 1,oldChunk = block * YAFFS_CHUNKS_PER_BLOCK; + mask && bi->pageBits; + mask <<= 1, oldChunk++ ) + { + if(bi->pageBits & mask) + { + + // This page is in use and needs to be copied off + + T(("copying page %x from %d to %d\n",mask,oldChunk,newChunk)); + + yaffs_ReadChunkFromNAND(dev,oldChunk,buffer, &spare); + + yaffs_GetTagsFromSpare(&spare,&tags); + tags.serialNumber++; + yaffs_LoadTagsIntoSpare(&spare,&tags); + +#if 0 + newChunk = yaffs_AllocatePage(dev,1); + if(newChunk < 0) + { + return YAFFS_FAIL; + } + + yaffs_WriteChunkToNAND(dev,newChunk, buffer, &spare); + +#else + newChunk = yaffs_WriteNewChunkToNAND(dev, buffer, &spare,1); +#endif + if(newChunk < 0) + { + return YAFFS_FAIL; + } + + object = yaffs_FindObjectByNumber(dev,tags.objectId); + + // Ok, now fix up the Tnodes etc. + + if(tags.chunkId == 0) + { + // It's a header + object->chunkId = newChunk; + } + else + { + // It's a data chunk + yaffs_PutChunkIntoFile(object, tags.chunkId, newChunk); + + } + + yaffs_DeleteChunk(dev,oldChunk); + + } + } + + return YAFFS_OK; +} + +int yaffs_CheckGarbageCollection(yaffs_Device *dev) +{ + int block; + + if(dev->garbageCollectionRequired) + { + dev->garbageCollectionRequired = 0; + block = yaffs_FindDirtiestBlock(dev); + if(block >= 0) + { + return yaffs_GarbageCollectBlock(dev,block); + } + else + { + return YAFFS_FAIL; + } + } + + return YAFFS_OK; +} + + +//////////////////////////// TAGS /////////////////////////////////////// + +static void yaffs_LoadTagsIntoSpare(yaffs_Spare *sparePtr, yaffs_Tags *tagsPtr) +{ + yaffs_TagsUnion *tu = (yaffs_TagsUnion *)tagsPtr; + + yaffs_CalcTagsECC(tagsPtr); + + sparePtr->tagByte0 = tu->asBytes[0]; + sparePtr->tagByte1 = tu->asBytes[1]; + sparePtr->tagByte2 = tu->asBytes[2]; + sparePtr->tagByte3 = tu->asBytes[3]; + sparePtr->tagByte4 = tu->asBytes[4]; + sparePtr->tagByte5 = tu->asBytes[5]; + sparePtr->tagByte6 = tu->asBytes[6]; + sparePtr->tagByte7 = tu->asBytes[7]; +} + +static void yaffs_GetTagsFromSpare(yaffs_Spare *sparePtr,yaffs_Tags *tagsPtr) +{ + yaffs_TagsUnion *tu = (yaffs_TagsUnion *)tagsPtr; + + tu->asBytes[0]= sparePtr->tagByte0; + tu->asBytes[1]= sparePtr->tagByte1; + tu->asBytes[2]= sparePtr->tagByte2; + tu->asBytes[3]= sparePtr->tagByte3; + tu->asBytes[4]= sparePtr->tagByte4; + tu->asBytes[5]= sparePtr->tagByte5; + tu->asBytes[6]= sparePtr->tagByte6; + tu->asBytes[7]= sparePtr->tagByte7; + + // Todo Check ECC on tags +} + +static void yaffs_SpareInitialise(yaffs_Spare *spare) +{ + memset(spare,0xFF,sizeof(yaffs_Spare)); +} + +static int yaffs_ReadChunkTagsFromNAND(yaffs_Device *dev,int chunkInNAND, yaffs_Tags *tags) +{ + if(tags) + { + yaffs_Spare spare; + if(yaffs_ReadChunkFromNAND(dev,chunkInNAND,NULL,&spare) == YAFFS_OK) + { + yaffs_GetTagsFromSpare(&spare,tags); + return YAFFS_OK; + } + else + { + return YAFFS_FAIL; + } + } + + return YAFFS_OK; +} + +static int yaffs_WriteChunkWithTagsToNAND(yaffs_Device *dev,int chunkInNAND, const __u8 *buffer, yaffs_Tags *tags) +{ + // NB There must be tags, data is optional + // If there is data, then an ECC is calculated on it. + + yaffs_Spare spare; + + if(!tags) + { + return YAFFS_FAIL; + } + + yaffs_SpareInitialise(&spare); + + + if(buffer) + { + yaffs_CalcECC(buffer,&spare); + } + + yaffs_LoadTagsIntoSpare(&spare,tags); + + return yaffs_WriteChunkToNAND(dev,chunkInNAND,buffer,&spare); + +} + +static int yaffs_WriteNewChunkWithTagsToNAND(yaffs_Device *dev, const __u8 *buffer, yaffs_Tags *tags, int useReserve) +{ + // NB There must be tags, data is optional + // If there is data, then an ECC is calculated on it. + + yaffs_Spare spare; + + if(!tags) + { + return YAFFS_FAIL; + } + + yaffs_SpareInitialise(&spare); + + + if(buffer) + { + yaffs_CalcECC(buffer,&spare); + } + + yaffs_LoadTagsIntoSpare(&spare,tags); + + return yaffs_WriteNewChunkToNAND(dev,buffer,&spare,useReserve); + +} + + + + +int yaffs_FindChunkInFile(yaffs_Object *in,int chunkInInode,yaffs_Tags *tags) +{ + //Get the Tnode, then get the level 0 offset chunk offset + yaffs_Tnode *tn; + int theChunk = -1; + yaffs_Tags localTags; + int i; + int found = 0; + yaffs_Device *dev = in->myDev; + + + if(!tags) + { + // Passed a NULL, so use our own tags space + tags = &localTags; + } + + tn = yaffs_FindLevel0Tnode(dev,&in->variant.fileVariant, chunkInInode); + + if(tn) + { + theChunk = tn->level0[chunkInInode & YAFFS_TNODES_LEVEL0_MASK] << dev->chunkGroupBits; + + // Now we need to do the shifting etc and search for it + for(i = 0,found = 0; i < dev->chunkGroupSize && !found; i++) + { + yaffs_ReadChunkTagsFromNAND(dev,theChunk,tags); + if(tags->chunkId == chunkInInode && + tags->objectId == in->objectId) + { + // found it; + found = 1; + } + else + { + theChunk++; + } + } + } + return found ? theChunk : -1; +} + +int yaffs_FindAndDeleteChunkInFile(yaffs_Object *in,int chunkInInode,yaffs_Tags *tags) +{ + //Get the Tnode, then get the level 0 offset chunk offset + yaffs_Tnode *tn; + int theChunk = -1; + yaffs_Tags localTags; + int i; + int found = 0; + yaffs_Device *dev = in->myDev; + + if(!tags) + { + // Passed a NULL, so use our own tags space + tags = &localTags; + } + + tn = yaffs_FindLevel0Tnode(dev,&in->variant.fileVariant, chunkInInode); + + if(tn) + { + + theChunk = tn->level0[chunkInInode & YAFFS_TNODES_LEVEL0_MASK] << dev->chunkGroupBits; + + // Now we need to do the shifting etc and search for it + for(i = 0,found = 0; i < dev->chunkGroupSize && !found; i++) + { + yaffs_ReadChunkTagsFromNAND(dev,theChunk,tags); + if(tags->chunkId == chunkInInode && + tags->objectId == in->objectId) + { + // found it; + found = 1; + } + else + { + theChunk++; + } + } + + // Delete the entry in the filestructure + if(found) + { + tn->level0[chunkInInode & YAFFS_TNODES_LEVEL0_MASK] = 0; + } + } + else + { + T(("No level 0 found for %d\n", chunkInInode)); + } + + if(!found) + { + T(("Could not find %d to delete\n",chunkInInode)); + } + return found ? theChunk : -1; +} + + +#if YAFFS_PARANOID + +static int yaffs_CheckFileSanity(yaffs_Object *in) +{ + int chunk; + int nChunks; + int fSize; + int failed = 0; + int objId; + yaffs_Tnode *tn; + yaffs_Tags localTags; + yaffs_Tags *tags = &localTags; + int theChunk; + + + if(in->variantType != YAFFS_OBJECT_TYPE_FILE) + { + T(("Object not a file\n")); + return YAFFS_FAIL; + } + + objId = in->objectId; + fSize = in->variant.fileVariant.fileSize; + nChunks = (fSize + YAFFS_BYTES_PER_CHUNK -1)/YAFFS_BYTES_PER_CHUNK; + + for(chunk = 1; chunk <= nChunks; chunk++) + { + tn = yaffs_FindLevel0Tnode(&in->variant.fileVariant, chunk); + + if(tn) + { + + theChunk = tn->level0[chunk & YAFFS_TNODES_LEVEL0_MASK] << dev->chunkGroupBits; + + + yaffs_ReadChunkTagsFromNAND(theChunk,tags); + if(tags->chunkId == chunk && + tags->objectId == in->objectId) + { + // found it; + + } + else + { + //T(("File problem file [%d,%d] NAND %d tags[%d,%d]\n", + // objId,chunk,theChunk,tags->chunkId,tags->objectId); + + failed = 1; + + } + + } + else + { + T(("No level 0 found for %d\n", chunk)); + } + } + + return failed ? YAFFS_FAIL : YAFFS_OK; +} + +#endif + +static int yaffs_PutChunkIntoFile(yaffs_Object *in,int chunkInInode, int chunkInNAND) +{ + yaffs_Tnode *tn; + yaffs_Device *dev = in->myDev; + + tn = yaffs_AddOrFindLevel0Tnode(dev,&in->variant.fileVariant, chunkInInode); + tn->level0[chunkInInode & YAFFS_TNODES_LEVEL0_MASK] = chunkInNAND; + return YAFFS_OK; +} + + + +int yaffs_ReadChunkDataFromObject(yaffs_Object *in,int chunkInInode, __u8 *buffer) +{ + int chunkInNAND = yaffs_FindChunkInFile(in,chunkInInode,NULL); + + if(chunkInNAND >= 0) + { + return yaffs_ReadChunkFromNAND(in->myDev,chunkInNAND,buffer,NULL); + } + else + { + return 0; + } + +} + + +static void yaffs_DeleteChunk(yaffs_Device *dev,int chunkId) +{ + int block = chunkId / YAFFS_CHUNKS_PER_BLOCK; + int page = chunkId % YAFFS_CHUNKS_PER_BLOCK; + yaffs_Tags tags; + + // Mark the deleted NAND page as deleted + tags.chunkId = 0; + tags.objectId = 0; + tags.byteCount = 0; + tags.ecc = 0; + + yaffs_WriteChunkWithTagsToNAND(dev,chunkId,NULL,&tags); + + + // Pull out of the management area. + if( dev->blockInfo[block].blockState == YAFFS_BLOCK_STATE_ALLOCATING || + dev->blockInfo[block].blockState == YAFFS_BLOCK_STATE_FULL) + { + dev->nFreeChunks++; + + dev->blockInfo[block].pageBits &= ~(1 << page); + dev->blockInfo[block].pagesInUse--; + + if( dev->blockInfo[block].pagesInUse == 0 && + dev->blockInfo[block].blockState == YAFFS_BLOCK_STATE_FULL) + { + yaffs_BlockBecameDirty(dev,block); + } + + } + else + { + T(("Bad news deteing chunk %d\n",chunkId)); + } + +} + + + + +int yaffs_WriteChunkDataToObject(yaffs_Object *in,int chunkInInode, const __u8 *buffer,int nBytes,int useReserve) +{ + // Find old chunk Need to do this to get serial number + // Write new one and patch into tree. + // Invalidate old tags. + + int prevChunkId; + yaffs_Tags prevTags; + + int newChunkId; + yaffs_Tags newTags; + + yaffs_Device *dev = in->myDev; + + yaffs_CheckGarbageCollection(dev); + + // Get the previous chunk at this location in the file if it exists + prevChunkId = yaffs_FindChunkInFile(in,chunkInInode,&prevTags); + + // Set up new tags + newTags.chunkId = chunkInInode; + newTags.objectId = in->objectId; + newTags.serialNumber = (prevChunkId >= 0) ? prevTags.serialNumber + 1 : 1; + newTags.byteCount = nBytes; + newTags.unusedStuff = 0xFFFFFFFF; + + yaffs_CalcTagsECC(&newTags); + + + #if 0 + // Create new chunk in NAND + newChunkId = yaffs_AllocatePage(dev,useReserve); + + + if(newChunkId >= 0) + { + + + yaffs_WriteChunkWithTagsToNAND(dev,newChunkId,buffer,&newTags); + + yaffs_PutChunkIntoFile(in,chunkInInode,newChunkId); + + + if(prevChunkId >= 0) + { + yaffs_DeleteChunk(dev,prevChunkId); + + } + + yaffs_CheckFileSanity(in); + + return newChunkId; + } + + + return -1; +#else + + newChunkId = yaffs_WriteNewChunkWithTagsToNAND(dev,buffer,&newTags,useReserve); + if(newChunkId >= 0) + { + yaffs_PutChunkIntoFile(in,chunkInInode,newChunkId); + + + if(prevChunkId >= 0) + { + yaffs_DeleteChunk(dev,prevChunkId); + + } + + yaffs_CheckFileSanity(in); + } + return newChunkId; + +#endif + + + +} + + +// UpdateObjectHeader updates the header on NAND for an object. +// If name is not NULL, then that new name is used. +// +int yaffs_UpdateObjectHeader(yaffs_Object *in,const char *name) +{ + + yaffs_Device *dev = in->myDev; + + int prevChunkId; + + int newChunkId; + yaffs_Tags newTags; + __u8 bufferNew[YAFFS_BYTES_PER_CHUNK]; + __u8 bufferOld[YAFFS_BYTES_PER_CHUNK]; + + yaffs_ObjectHeader *oh = (yaffs_ObjectHeader *)bufferNew; + yaffs_ObjectHeader *ohOld = (yaffs_ObjectHeader *)bufferOld; + + if(!in->fake) + { + + yaffs_CheckGarbageCollection(dev); + + memset(bufferNew,0xFF,YAFFS_BYTES_PER_CHUNK); + + prevChunkId = in->chunkId; + + if(prevChunkId >= 0) + { + yaffs_ReadChunkFromNAND(dev,prevChunkId,bufferOld,NULL); + } + + // Header data + oh->type = in->variantType; + + oh->st_mode = in->st_mode; + oh->st_uid = in->st_uid; + oh->st_gid = in->st_gid; + oh->st_atime = in->st_atime; + oh->st_mtime = in->st_mtime; + oh->st_ctime = in->st_ctime; + + oh->parentObjectId = in->parent->objectId; + oh->sum = in->sum; + if(name && *name) + { + memset(oh->name,0,YAFFS_MAX_NAME_LENGTH + 1); + strncpy(oh->name,name,YAFFS_MAX_NAME_LENGTH); + } + else + { + memcpy(oh->name, ohOld->name,YAFFS_MAX_NAME_LENGTH + 1); + } + + switch(in->variantType) + { + case YAFFS_OBJECT_TYPE_UNKNOWN: // Todo got a problem + break; + case YAFFS_OBJECT_TYPE_FILE: + oh->fileSize = in->variant.fileVariant.fileSize; + break; + case YAFFS_OBJECT_TYPE_HARDLINK: + oh->equivalentObjectId = in->variant.hardLinkVariant.equivalentObjectId; + break; + case YAFFS_OBJECT_TYPE_DIRECTORY: // Do nothing + break; + case YAFFS_OBJECT_TYPE_SYMLINK: + strncpy(oh->alias,in->variant.symLinkVariant.alias,YAFFS_MAX_ALIAS_LENGTH); + oh->alias[YAFFS_MAX_ALIAS_LENGTH] = 0; + break; + } + + // Tags + in->serial++; + newTags.chunkId = 0; + newTags.objectId = in->objectId; + newTags.serialNumber = in->serial; + newTags.byteCount = 0xFFFFFFFF; + newTags.unusedStuff = 0xFFFFFFFF; + + yaffs_CalcTagsECC(&newTags); + + + +#if 0 + // Create new chunk in NAND + newChunkId = yaffs_AllocatePage(dev,1); + + if(newChunkId >= 0) + { + + yaffs_WriteChunkWithTagsToNAND(dev,newChunkId,bufferNew,&newTags); + + in->chunkId = newChunkId; + + if(prevChunkId >= 0) + { + yaffs_DeleteChunk(dev,prevChunkId); + } + + in->dirty = 0; + return newChunkId; + } + + return -1; +#else + // Create new chunk in NAND + newChunkId = yaffs_WriteNewChunkWithTagsToNAND(dev,bufferNew,&newTags,1); + + if(newChunkId >= 0) + { + + in->chunkId = newChunkId; + + if(prevChunkId >= 0) + { + yaffs_DeleteChunk(dev,prevChunkId); + } + + in->dirty = 0; + } + + return newChunkId; + +#endif + } + return 0; +} + + + +///////////////////////// File read/write /////////////////////////////// +// Read and write have very similar structures. +// In general the read/write has three parts to it +// * An incomplete chunk to start with (if the read/write is not chunk-aligned) +// * Some complete chunks +// * An incomplete chunk to end off with +// +// Curve-balls: the first chunk might also be the last chunk. + +int yaffs_ReadDataFromFile(yaffs_Object *in, __u8 * buffer, __u32 offset, int nBytes) +{ + +// yaffs_Device *dev = in->myDev; + + __u8 localBuffer[YAFFS_BYTES_PER_CHUNK]; + + int chunk; + int start; + int nToCopy; + int n = nBytes; + int nDone = 0; + + while(n > 0) + { + chunk = offset / YAFFS_BYTES_PER_CHUNK + 1; // The first chunk is 1 + start = offset % YAFFS_BYTES_PER_CHUNK; + + // OK now check for the curveball where the start and end are in + // the same chunk. + if( (start + n) < YAFFS_BYTES_PER_CHUNK) + { + nToCopy = n; + } + else + { + nToCopy = YAFFS_BYTES_PER_CHUNK - start; + } + + if(nToCopy != YAFFS_BYTES_PER_CHUNK) + { + // An incomplete start or end chunk (or maybe both start and end chunk) + // Read into the local buffer then copy... + + yaffs_ReadChunkDataFromObject(in,chunk,localBuffer); + memcpy(buffer,&localBuffer[start],nToCopy); + } + else + { + // A full chunk. Read directly into the supplied buffer. + yaffs_ReadChunkDataFromObject(in,chunk,buffer); + } + + n -= nToCopy; + offset += nToCopy; + buffer += nToCopy; + nDone += nToCopy; + + } + + return nDone; +} + + +int yaffs_WriteDataToFile(yaffs_Object *in,const __u8 * buffer, __u32 offset, int nBytes) +{ + __u8 localBuffer[YAFFS_BYTES_PER_CHUNK]; + + int chunk; + int start; + int nToCopy; + int n = nBytes; + int nDone = 0; + int nToWriteBack; + int endOfWrite = offset+nBytes; + int chunkWritten = 0; + + while(n > 0 && chunkWritten >= 0) + { + chunk = offset / YAFFS_BYTES_PER_CHUNK + 1; + start = offset % YAFFS_BYTES_PER_CHUNK; + + + // OK now check for the curveball where the start and end are in + // the same chunk. + if( (start + n) < YAFFS_BYTES_PER_CHUNK) + { + nToCopy = n; + nToWriteBack = (start + n); + } + else + { + nToCopy = YAFFS_BYTES_PER_CHUNK - start; + nToWriteBack = YAFFS_BYTES_PER_CHUNK; + } + + if(nToCopy != YAFFS_BYTES_PER_CHUNK) + { + // An incomplete start or end chunk (or maybe both start and end chunk) + // Read into the local buffer then copy, then copy over and write back. + + yaffs_ReadChunkDataFromObject(in,chunk,localBuffer); + + memcpy(&localBuffer[start],buffer,nToCopy); + + chunkWritten = yaffs_WriteChunkDataToObject(in,chunk,localBuffer,nToWriteBack,0); + + T(("Write with readback to chunk %d %d\n",chunk,chunkWritten)); + + } + else + { + // A full chunk. Write directly from the supplied buffer. + chunkWritten = yaffs_WriteChunkDataToObject(in,chunk,buffer,YAFFS_BYTES_PER_CHUNK,0); + T(("Write to chunk %d %d\n",chunk,chunkWritten)); + } + + if(chunkWritten >= 0) + { + n -= nToCopy; + offset += nToCopy; + buffer += nToCopy; + nDone += nToCopy; + } + + } + + // Update file object + + if(endOfWrite > in->variant.fileVariant.fileSize) + { + in->variant.fileVariant.fileSize = endOfWrite; + } + + in->dirty = 1; + in->st_mtime = CURRENT_TIME; + + return nDone; +} + + +int yaffs_ResizeFile(yaffs_Object *in, int newSize) +{ + int i; + int chunkId; + int oldFileSize = in->variant.fileVariant.fileSize; + int sizeOfLastChunk = newSize % YAFFS_BYTES_PER_CHUNK; + + yaffs_Device *dev = in->myDev; + + __u8 localBuffer[YAFFS_BYTES_PER_CHUNK]; + + if(in->variantType != YAFFS_OBJECT_TYPE_FILE) + { + return yaffs_GetFileSize(in); + } + + if(newSize < oldFileSize) + { + + int lastDel = 1 + oldFileSize/YAFFS_BYTES_PER_CHUNK; + + int startDel = 1 + (newSize + YAFFS_BYTES_PER_CHUNK - 1)/ + YAFFS_BYTES_PER_CHUNK; + + for(i = startDel; i <= lastDel; i++) + { + // NB this could be optimised somewhat, + // eg. could retrieve the tags and write them without + // using yaffs_DeleteChunk + chunkId = yaffs_FindAndDeleteChunkInFile(in,i,NULL); + if(chunkId < 0 || chunkId >= (dev->endBlock * 32)) + { + T(("Found daft chunkId %d for %d\n",chunkId,i)); + } + else + { + yaffs_DeleteChunk(dev,chunkId); + } + } + + + if(sizeOfLastChunk != 0) + { + int lastChunk = 1+ newSize/YAFFS_BYTES_PER_CHUNK; + + // Got to read and rewrite the last chunk with its new size. + yaffs_ReadChunkDataFromObject(in,lastChunk,localBuffer); + + yaffs_WriteChunkDataToObject(in,lastChunk,localBuffer,sizeOfLastChunk,1); + + } + + in->variant.fileVariant.fileSize = newSize; + + yaffs_PruneFileStructure(dev,&in->variant.fileVariant); + + return newSize; + + } + else + { + return oldFileSize; + } +} + + +loff_t yaffs_GetFileSize(yaffs_Object *obj) +{ + obj = yaffs_GetEquivalentObject(obj); + + switch(obj->variantType) + { + case YAFFS_OBJECT_TYPE_FILE: + return obj->variant.fileVariant.fileSize; + case YAFFS_OBJECT_TYPE_SYMLINK: + return strlen(obj->variant.symLinkVariant.alias); + default: + return 0; + } +} + + + +// yaffs_FlushFile() updates the file's +// objectId in NAND + +int yaffs_FlushFile(yaffs_Object *in) +{ + int retVal; + if(in->dirty) + { + retVal = yaffs_UpdateObjectHeader(in,NULL); + } + else + { + retVal = YAFFS_OK; + } + + return retVal; + +} + + +static int yaffs_DoGenericObjectDeletion(yaffs_Object *in) +{ + yaffs_RemoveObjectFromDirectory(in); + yaffs_DeleteChunk(in->myDev,in->chunkId); + yaffs_FreeObject(in); + return YAFFS_OK; + +} + +// yaffs_DeleteFile deletes the whole file data +// and the inode associated with the file. +// It does not delete the links associated with the file. +static int yaffs_DeleteFile(yaffs_Object *in) +{ + // Delete the file data & tnodes + yaffs_ResizeFile(in,0); + yaffs_FreeTnode(in->myDev,in->variant.fileVariant.top); + + return yaffs_DoGenericObjectDeletion(in); +} + +static int yaffs_DeleteDirectory(yaffs_Object *in) +{ + //First check that the directory is empty. + if(list_empty(&in->variant.directoryVariant.children)) + { + return yaffs_DoGenericObjectDeletion(in); + } + + return YAFFS_FAIL; + +} + +static int yaffs_DeleteSymLink(yaffs_Object *in) +{ + YFREE(in->variant.symLinkVariant.alias); + + return yaffs_DoGenericObjectDeletion(in); +} + +static int yaffs_DeleteHardLink(yaffs_Object *in) +{ + // remove this hardlink from the list assocaited with the equivalent + // object + list_del(&in->hardLinks); + return yaffs_DoGenericObjectDeletion(in); +} + + +static int yaffs_UnlinkWorker(yaffs_Object *obj) +{ + + + if(obj->variantType == YAFFS_OBJECT_TYPE_HARDLINK) + { + return yaffs_DeleteHardLink(obj); + } + else if(!list_empty(&obj->hardLinks)) + { +#if 0 + // Curve ball: We're unlinking an object that has a hardlink. + // Therefore we can't really delete the object. + // Instead, we do the following: + // - Select a hardlink. + // - Re-type a hardlink as the equivalent object and populate the fields, including the + // objectId. Updating the object id is important so that all the hardlinks do not need + // to be rewritten. + // - Update the equivalet object pointers. + // - Delete all object. + + yaffs_Object *hl; + struct list_head *i; + + + yaffs_RemoveObjectFromDirectory(obj); + + + + hl = list_entry(obj->hardLinks.next, yaffs_Object,hardLinks); + + hl->dirty = 1; + hl->st_mode = obj->st_mode; + hl->st_uid = obj->st_uid; + hl->st_gid = obj->st_gid; + hl->st_atime = obj->st_atime; + hl->st_mtime = obj->st_mtime; + hl->st_ctime = obj->st_ctime; + + hl->variantType = obj->variantType; + + switch(hl->variantType) + { + case YAFFS_OBJECT_TYPE_FILE: + case YAFFS_OBJECT_TYPE_SYMLINK: + // These types are OK to just copy across. + hl->variant = obj->variant; + break; + case YAFFS_OBJECT_TYPE_DIRECTORY: + // Fix the list up + list_add(&hl->variant.directoryVariant.children, + &obj->variant.directoryVariant.children); + list_del(&obj->variant.directoryVariant.children); + + // Now change all the directory children to point to the new parent. + list_for_each(i,&hl->variant.directoryVariant.children) + { + list_entry(i,yaffs_Object,siblings)->parent = hl; + } + break; + + case YAFFS_OBJECT_TYPE_HARDLINK: + case YAFFS_OBJECT_TYPE_UNKNOWN: + // Should not be either of these types. + } + + // Now fix up the hardlink chain + list_del(&obj->hardLinks); + + list_for_each(i,&hl->hardLinks) + { + list_entry(i,yaffs_Object,hardLinks)->variant.hardLinkVariant.equivalentObject = hl; + list_entry(i,yaffs_Object,hardLinks)->variant.hardLinkVariant.equivalentObjectId = hl->objectId; + } + + // Now fix up the hash links. + yaffs_UnhashObject(hl); + hl->objectId = obj->objectId; + yaffs_HashObject(hl); + + // Update the hardlink which has become an object + yaffs_UpdateObjectHeader(hl,NULL); + + // Finally throw away the deleted object + yaffs_DeleteChunk(obj->myDev,obj->chunkId); + yaffs_FreeObject(obj); + + return YAFFS_OK; +#else + // Curve ball: We're unlinking an object that has a hardlink. + // + // This problem arises because we are not strictly following + // The Linux link/inode model. + // + // We can't really delete the object. + // Instead, we do the following: + // - Select a hardlink. + // - Unhook it from the hard links + // - Unhook it from its parent directory (so that the rename can work) + // - Rename the object to the hardlink's name. + // - Delete the hardlink + + + yaffs_Object *hl; + int retVal; + char name[YAFFS_MAX_NAME_LENGTH+1]; + + hl = list_entry(obj->hardLinks.next,yaffs_Object,hardLinks); + list_del_init(&hl->hardLinks); + list_del_init(&hl->siblings); + + yaffs_GetObjectName(hl,name,YAFFS_MAX_NAME_LENGTH+1); + + retVal = yaffs_ChangeObjectName(obj, hl->parent, name); + if(retVal == YAFFS_OK) + { + retVal = yaffs_DoGenericObjectDeletion(hl); + } + return retVal; + +#endif + + + } + else + { + switch(obj->variantType) + { + case YAFFS_OBJECT_TYPE_FILE: + return yaffs_DeleteFile(obj); + break; + case YAFFS_OBJECT_TYPE_DIRECTORY: + return yaffs_DeleteDirectory(obj); + break; + case YAFFS_OBJECT_TYPE_SYMLINK: + return yaffs_DeleteSymLink(obj); + break; + case YAFFS_OBJECT_TYPE_HARDLINK: + case YAFFS_OBJECT_TYPE_UNKNOWN: + default: + return YAFFS_FAIL; + } + } +} + +int yaffs_Unlink(yaffs_Object *dir, const char *name) +{ + yaffs_Object *obj; + + obj = yaffs_FindObjectByName(dir,name); + + if(obj && obj->unlinkAllowed) + { + return yaffs_UnlinkWorker(obj); + } + + return YAFFS_FAIL; + +} + +//////////////// Initialisation Scanning ///////////////// + + +static int yaffs_Scan(yaffs_Device *dev) +{ + yaffs_Spare spare; + yaffs_Tags tags; + int blk; + int chunk; + int c; + int deleted; + int inuse; + yaffs_BlockState state; + yaffs_Object *hardList = NULL; + yaffs_Object *hl; + + __u32 pageBits; + + yaffs_ObjectHeader *oh; + yaffs_Object *in; + yaffs_Object *parent; + + __u8 chunkData[YAFFS_BYTES_PER_CHUNK]; + + for(blk = dev->startBlock; blk <= dev->endBlock; blk++) + { + deleted = 0; + pageBits = 0; + inuse = 0; + state = YAFFS_BLOCK_STATE_UNKNOWN; + + for(c = 0; c < YAFFS_CHUNKS_PER_BLOCK && + state == YAFFS_BLOCK_STATE_UNKNOWN; c++) + { + // Read the spare area and decide what to do + chunk = blk * YAFFS_CHUNKS_PER_BLOCK + c; + yaffs_ReadChunkFromNAND(dev,chunk,NULL,&spare); + + + // Is this a valid block? + if(yaffs_countBits[spare.blockStatus] >= 7) + { + // This block looks ok, now what's in this chunk? + yaffs_GetTagsFromSpare(&spare,&tags); + + if(tags.objectId == YAFFS_UNUSED_OBJECT_ID) + { + // An unassigned chunk in the block + // This means that either the block is empty or + // this is the one being allocated from + + if(c == 0) + { + // the block is unused + state = YAFFS_BLOCK_STATE_EMPTY; + dev->nErasedBlocks++; + } + else + { + // this is the block being allocated from + T((" allocating %d %d\n",blk,c)); + state = YAFFS_BLOCK_STATE_ALLOCATING; + dev->allocationBlock = blk; + dev->allocationPage = c; + } + + dev->nFreeChunks += (YAFFS_CHUNKS_PER_BLOCK - c); + } + else if(tags.objectId == 0) + { + // A deleted chunk + deleted++; + dev->nFreeChunks ++; + T((" %d %d deleted\n",blk,c)); + } + else if(tags.chunkId > 0) + { + // A data chunk. + inuse++; + pageBits |= ( 1 <type); + if(in->valid) + { + // todo we have already filled this one. We have + // a duplicate. Need to fix + } + + // we don't have a duplicate... + + in->valid = 1; + in->variantType = oh->type; + + in->st_mode = oh->st_mode; + in->st_uid = oh->st_uid; + in->st_gid = oh->st_gid; + in->st_atime = oh->st_atime; + in->st_mtime = oh->st_mtime; + in->st_ctime = oh->st_ctime; + in->chunkId = chunk; + + in->sum = oh->sum; + in->dirty = 0; + + // directory stuff... + // hook up to parent + + parent = yaffs_FindOrCreateObjectByNumber(dev,oh->parentObjectId,YAFFS_OBJECT_TYPE_DIRECTORY); + if(parent->variantType == YAFFS_OBJECT_TYPE_UNKNOWN) + { + // Set up as a directory + parent->variantType = YAFFS_OBJECT_TYPE_DIRECTORY; + INIT_LIST_HEAD(&parent->variant.directoryVariant.children); + } + else if(parent->variantType != YAFFS_OBJECT_TYPE_DIRECTORY) + { + // Hoosterman, another problem.... + // We're trying to use a non-directory as a directory + // Todo ... handle + } + + yaffs_AddObjectToDirectory(parent,in); + + // Note re hardlinks. + // Since we might scan a hardlink before its equivalent object is scanned + // we put them all in a list. + // After scanning is complete, we should have all the objects, so we run through this + // list and fix up all the chains. + + switch(in->variantType) + { + case YAFFS_OBJECT_TYPE_UNKNOWN: // Todo got a problem + break; + case YAFFS_OBJECT_TYPE_FILE: + in->variant.fileVariant.fileSize = oh->fileSize; + break; + case YAFFS_OBJECT_TYPE_HARDLINK: + in->variant.hardLinkVariant.equivalentObjectId = oh->equivalentObjectId; + (yaffs_Object *)(in->hardLinks.next) = hardList; + hardList = in; + break; + case YAFFS_OBJECT_TYPE_DIRECTORY: // Do nothing + break; + case YAFFS_OBJECT_TYPE_SYMLINK: // Do nothing + in->variant.symLinkVariant.alias = yaffs_CloneString(oh->alias); + break; + } + T((" %d %d header %d \"%s\" type %d\n",blk,c,tags.objectId,oh->name,in->variantType)); + } + } + else + { + // it's a bad block + state = YAFFS_BLOCK_STATE_DEAD; + } + } + + if(state == YAFFS_BLOCK_STATE_UNKNOWN) + { + // If we got this far, then the block is fully allocated. + // ie. Full or Dirty + state = (inuse) ? YAFFS_BLOCK_STATE_FULL : YAFFS_BLOCK_STATE_DIRTY; + + } + + dev->blockInfo[blk].pageBits = pageBits; + dev->blockInfo[blk].pagesInUse = inuse; + dev->blockInfo[blk].blockState = state; + + } + + // Todo fix up the hard link chains + while(hardList) + { + hl = hardList; + hardList = (yaffs_Object *)(hardList->hardLinks.next); + + in = yaffs_FindObjectByNumber(dev,hl->variant.hardLinkVariant.equivalentObjectId); + + if(in) + { + hl->variant.hardLinkVariant.equivalentObject=in; + list_add(&hl->hardLinks,&in->hardLinks); + } + else + { + //Todo Need to report this better. + hl->variant.hardLinkVariant.equivalentObject=NULL; + INIT_LIST_HEAD(&hl->hardLinks); + + } + + } + + + + return YAFFS_OK; +} + + +////////////////////////// Directory Functions ///////////////////////// + + +static void yaffs_AddObjectToDirectory(yaffs_Object *directory, yaffs_Object *obj) +{ + + if(obj->siblings.prev == NULL) + { + // Not initialised + INIT_LIST_HEAD(&obj->siblings); + + } + else if(!list_empty(&obj->siblings)) + { + // If it is holed up somewhere else, un hook it + list_del_init(&obj->siblings); + } + // Now add it + list_add(&obj->siblings,&directory->variant.directoryVariant.children); + obj->parent = directory; +} + +static void yaffs_RemoveObjectFromDirectory(yaffs_Object *obj) +{ + list_del_init(&obj->siblings); + obj->parent = NULL; +} + +yaffs_Object *yaffs_FindObjectByName(yaffs_Object *directory,const char *name) +{ + int sum; + + struct list_head *i; + __u8 buffer[YAFFS_BYTES_PER_CHUNK]; + yaffs_ObjectHeader *oh = (yaffs_ObjectHeader *)buffer; + + yaffs_Object *l; + + sum = yaffs_CalcNameSum(name); + + list_for_each(i,&directory->variant.directoryVariant.children) + { + l = list_entry(i, yaffs_Object,siblings); + + // Special case for lost-n-found + if(l->objectId == YAFFS_OBJECTID_LOSTNFOUND) + { + if(strcmp(name,YAFFS_LOSTNFOUND_NAME) == 0) + { + return l; + } + } + else if(l->sum == sum) + { + // Do a real check + yaffs_ReadChunkFromNAND(l->myDev,l->chunkId,buffer,NULL); + if(strcmp(name,oh->name) == 0) + { + return l; + } + + + } + } + + return NULL; +} + + +int yaffs_ApplyToDirectoryChildren(yaffs_Object *theDir,int (*fn)(yaffs_Object *)) +{ + struct list_head *i; + yaffs_Object *l; + + + list_for_each(i,&theDir->variant.directoryVariant.children) + { + l = list_entry(i, yaffs_Object,siblings); + if(!fn(l)) + { + return YAFFS_FAIL; + } + } + + return YAFFS_OK; + +} + + +// GetEquivalentObject dereferences any hard links to get to the +// actual object. + +static yaffs_Object *yaffs_GetEquivalentObject(yaffs_Object *obj) +{ + if(obj && obj->variantType == YAFFS_OBJECT_TYPE_HARDLINK) + { + // We want the object id of the equivalent object, not this one + obj = obj->variant.hardLinkVariant.equivalentObject; + } + return obj; + +} + +int yaffs_GetObjectName(yaffs_Object *obj,char *name,int buffSize) +{ + memset(name,0,buffSize); + + if(obj->objectId == YAFFS_OBJECTID_LOSTNFOUND) + { + strncpy(name,YAFFS_LOSTNFOUND_NAME,buffSize - 1); + } + else + { + __u8 buffer[YAFFS_BYTES_PER_CHUNK]; + yaffs_ObjectHeader *oh = (yaffs_ObjectHeader *)buffer; + + memset(buffer,0,YAFFS_BYTES_PER_CHUNK); + + if(obj->chunkId >= 0) + { + yaffs_ReadChunkFromNAND(obj->myDev,obj->chunkId,buffer,NULL); + } + strncpy(name,oh->name,buffSize - 1); + } + + return strlen(name); +} + +int yaffs_GetObjectFileLength(yaffs_Object *obj) +{ + + // Dereference any hard linking + obj = yaffs_GetEquivalentObject(obj); + + if(obj->variantType == YAFFS_OBJECT_TYPE_FILE) + { + return obj->variant.fileVariant.fileSize; + } + if(obj->variantType == YAFFS_OBJECT_TYPE_SYMLINK) + { + return strlen(obj->variant.symLinkVariant.alias); + } + else + { + // Only a directory should drop through to here + return YAFFS_BYTES_PER_CHUNK; + } +} + +int yaffs_GetObjectLinkCount(yaffs_Object *obj) +{ + int count = 1; // the object itself + struct list_head *i; + + list_for_each(i,&obj->hardLinks) + { + count++; + } + return count; + +} + + +int yaffs_GetObjectInode(yaffs_Object *obj) +{ + obj = yaffs_GetEquivalentObject(obj); + + return obj->objectId; +} + +unsigned yaffs_GetObjectType(yaffs_Object *obj) +{ + obj = yaffs_GetEquivalentObject(obj); + + switch(obj->variantType) + { + case YAFFS_OBJECT_TYPE_FILE: return DT_REG; break; + case YAFFS_OBJECT_TYPE_DIRECTORY: return DT_DIR; break; + case YAFFS_OBJECT_TYPE_SYMLINK: return DT_LNK; break; + case YAFFS_OBJECT_TYPE_HARDLINK: return DT_REG; break; + default: return DT_REG; break; + } +} + +char *yaffs_GetSymlinkAlias(yaffs_Object *obj) +{ + obj = yaffs_GetEquivalentObject(obj); + if(obj->variantType == YAFFS_OBJECT_TYPE_SYMLINK) + { + return yaffs_CloneString(obj->variant.symLinkVariant.alias); + } + else + { + return yaffs_CloneString(""); + } +} + + +int yaffs_SetAttributes(yaffs_Object *obj, struct iattr *attr) +{ + unsigned int valid = attr->ia_valid; + + if(valid & ATTR_MODE) obj->st_mode = attr->ia_mode; + if(valid & ATTR_UID) obj->st_uid = attr->ia_uid; + if(valid & ATTR_GID) obj->st_gid = attr->ia_gid; + + if(valid & ATTR_ATIME) obj->st_atime = attr->ia_atime; + if(valid & ATTR_CTIME) obj->st_ctime = attr->ia_ctime; + if(valid & ATTR_MTIME) obj->st_mtime = attr->ia_mtime; + + if(valid & ATTR_SIZE) yaffs_ResizeFile(obj,attr->ia_size); + + yaffs_UpdateObjectHeader(obj,NULL); + + return YAFFS_OK; + +} +int yaffs_GetAttributes(yaffs_Object *obj, struct iattr *attr) +{ + unsigned int valid = 0; + + attr->ia_mode = obj->st_mode; valid |= ATTR_MODE; + attr->ia_uid = obj->st_uid; valid |= ATTR_UID; + attr->ia_gid = obj->st_gid; valid |= ATTR_GID; + + attr->ia_atime = obj->st_atime; valid |= ATTR_ATIME; + attr->ia_ctime = obj->st_ctime; valid |= ATTR_CTIME; + attr->ia_mtime = obj->st_mtime; valid |= ATTR_MTIME; + + attr->ia_size = yaffs_GetFileSize(obj); valid |= ATTR_SIZE; + + attr->ia_valid = valid; + + return YAFFS_OK; + +} + + + +int yaffs_DumpObject(yaffs_Object *obj) +{ + __u8 buffer[YAFFS_BYTES_PER_CHUNK]; + char name[256]; +// yaffs_ObjectHeader *oh = (yaffs_ObjectHeader *)buffer; + + memset(buffer,0,YAFFS_BYTES_PER_CHUNK); + + if(obj->chunkId >= 0) + { + yaffs_ReadChunkFromNAND(obj->myDev,obj->chunkId,buffer,NULL); + } + + yaffs_GetObjectName(obj,name,256); + + YPRINTF(("Object %d \"%s\"\n dirty %d valid %d serial %d sum %d chunk %d type %d size %d\n", + yaffs_GetObjectInode(obj), name, obj->dirty, obj->valid, obj->serial, + obj->sum, obj->chunkId, yaffs_GetObjectType(obj), yaffs_GetObjectFileLength(obj))); + +#if 0 + YPRINTF(("Object %d \"%s\"\n dirty %d valid %d serial %d sum %d chunk %d\n", + obj->objectId, oh->name, obj->dirty, obj->valid, obj->serial, + obj->sum, obj->chunkId)); + switch(obj->variantType) + { + case YAFFS_OBJECT_TYPE_FILE: + YPRINTF((" FILE length %d\n",obj->variant.fileVariant.fileSize)); + break; + case YAFFS_OBJECT_TYPE_DIRECTORY: + YPRINTF((" DIRECTORY\n")); + break; + case YAFFS_OBJECT_TYPE_HARDLINK: //todo + case YAFFS_OBJECT_TYPE_SYMLINK: + case YAFFS_OBJECT_TYPE_UNKNOWN: + default: + } +#endif + + return YAFFS_OK; +} + + +///////////////////////// Initialisation code /////////////////////////// + + + +int yaffs_GutsInitialise(yaffs_Device *dev) +{ + unsigned nChunks,x; + int bits; + + + dev = dev; + + if(!yaffs_CheckStructures()) + { + return YAFFS_FAIL; + } + + + // OK now calculate a few things for the device + // Calculate chunkGroupBits. + // If there are 64k or less chunks then this is 1 + // Else it is log2(nChunks) - 16 + // + x = nChunks = YAFFS_CHUNKS_PER_BLOCK * dev->nBlocks; + + for(bits = 0, x = nChunks; (x & 1) == 0; bits++) + { + x >>= 1; + } + + if( x != 1) + { + // Not a power of 2 + YPRINTF(("nBlocks should be a power of 2 but is %u\n", + dev->nBlocks)); + return YAFFS_FAIL; + } + + if(bits <= 16) + { + dev->chunkGroupBits = 0; + dev->chunkGroupSize = 1; + } + else + { + dev->chunkGroupBits = bits - 16; + dev->chunkGroupSize = nChunks/0x10000; + } + + // More device initialisation + dev->garbageCollectionRequired = 0; + dev->currentDirtyChecker = 0; + + yaffs_InitialiseBlocks(dev); + + yaffs_InitialiseTnodes(dev); + + yaffs_InitialiseObjects(dev); + + + // Initialise the root and lost and found directories + dev->lostNFoundDir = dev->rootDir = NULL; + dev->rootDir = yaffs_CreateFakeDirectory(dev,YAFFS_OBJECTID_ROOT,YAFFS_ROOT_MODE | S_IFDIR); + dev->lostNFoundDir = yaffs_CreateFakeDirectory(dev,YAFFS_OBJECTID_LOSTNFOUND,YAFFS_ROOT_MODE | S_IFDIR); + yaffs_AddObjectToDirectory(dev->rootDir,dev->lostNFoundDir); + + // Now scan the flash. + yaffs_Scan(dev); + + + return YAFFS_OK; + +} + +void yaffs_Deinitialise(yaffs_Device *dev) +{ + yaffs_DeinitialiseBlocks(dev); + yaffs_DeinitialiseTnodes(dev); + yaffs_DeinitialiseObjects(dev); + +} + +int yaffs_GetNumberOfFreeChunks(yaffs_Device *dev) +{ + int nFree = dev->nFreeChunks - (YAFFS_CHUNKS_PER_BLOCK * YAFFS_RESERVED_BLOCKS); + + return (nFree < 0) ? 0 : nFree; + +} + + +/////////////////// YAFFS test code ////////////////////////////////// + +#define yaffs_CheckStruct(structure,syze, name) \ + if(sizeof(structure) != syze) \ + { YPRINTF(("%s should be %d but is %d\n",name,syze,sizeof(structure))); \ + return YAFFS_FAIL; \ + } + + +static int yaffs_CheckStructures(void) +{ + yaffs_CheckStruct(yaffs_Tags,8,"yaffs_Tags") + yaffs_CheckStruct(yaffs_TagsUnion,8,"yaffs_TagsUnion") + yaffs_CheckStruct(yaffs_Spare,16,"yaffs_Spare") + yaffs_CheckStruct(yaffs_Tnode,2* YAFFS_NTNODES_LEVEL0,"yaffs_Tnode") + yaffs_CheckStruct(yaffs_ObjectHeader,512,"yaffs_ObjectHeader") + + + return YAFFS_OK; +} + +void yaffs_GutsTest(yaffs_Device *dev) +{ + + if(yaffs_CheckStructures() != YAFFS_OK) + { + YPRINTF(("One or more structures malformed-- aborting\n")); + } + else + { + YPRINTF(("Structures OK\n")); + } + + yaffs_TnodeTest(dev); + yaffs_ObjectTest(dev); +} + + diff --git a/yaffs_guts.h b/yaffs_guts.h new file mode 100644 index 0000000..d1e2973 --- /dev/null +++ b/yaffs_guts.h @@ -0,0 +1,431 @@ +/* + * YAFFS: Yet another FFS. A NAND-flash specific file system. + * yaffs_guts.h: Configuration etc for yaffs_guts + * + * Copyright (C) 2002 Aleph One Ltd. + * for Toby Churchill Ltd and Brightstar Engineering + * + * Created by Charles Manning + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + */ + +#ifndef __YAFFS_GUTS_H__ +#define __YAFFS_GUTS_H__ + +#include "devextras.h" + + +#define YAFFS_OK 1 +#define YAFFS_FAIL 0 + +// Y=0x59, A=0x41, S=0x53 +#define YAFFS_MAGIC 0x5941FF53 + +#define YAFFS_NTNODES_LEVEL0 16 +#define YAFFS_TNODES_LEVEL0_BITS 4 +#define YAFFS_TNODES_LEVEL0_MASK 0xf + +#define YAFFS_NTNODES_INTERNAL (YAFFS_NTNODES_LEVEL0 / 2) +#define YAFFS_TNODES_INTERNAL_BITS (YAFFS_TNODES_LEVEL0_BITS - 1) +#define YAFFS_TNODES_INTERNAL_MASK 0x7 +#define YAFFS_TNODES_MAX_LEVEL 6 + +#define YAFFS_BYTES_PER_CHUNK 512 +#define YAFFS_CHUNK_SIZE_SHIFT 9 + +#define YAFFS_BYTES_PER_SPARE 16 + +#define YAFFS_CHUNKS_PER_BLOCK 32 +#define YAFFS_BYTES_PER_BLOCK (YAFFS_CHUNKS_PER_BLOCK*YAFFS_BYTES_PER_CHUNK) + +#define YAFFS_MAX_CHUNK_ID 0x000FFFFF + +#define YAFFS_UNUSED_OBJECT_ID 0x0003FFFF + +#define YAFFS_ALLOCATION_NOBJECTS 100 +#define YAFFS_ALLOCATION_NTNODES 100 +#define YAFFS_ALLOCATION_NLINKS 100 + +#define YAFFS_NOBJECT_BUCKETS 256 + + +#define YAFFS_RESERVED_BLOCKS 5 + +#define YAFFS_OBJECT_SPACE 0x40000 +#define YAFFS_MAX_NAME_LENGTH 255 + +#define YAFFS_MAX_ALIAS_LENGTH 211 + +#define YAFFS_OBJECTID_ROOT 1 +#define YAFFS_ROOT_MODE 0666 +#define YAFFS_OBJECTID_LOSTNFOUND 2 +#define YAFFS_LOSTNFOUND_NAME "lost+found" + +// Tags structures in RAM +// NB This uses bitfield. Bitfields should not stradle a u32 boundary otherwise +// the structure size will get blown out. + +typedef struct +{ + unsigned chunkId:20; + unsigned serialNumber:2; + unsigned byteCount:10; + unsigned objectId:18; + unsigned ecc:12; + unsigned unusedStuff:2; +} yaffs_Tags; + +typedef union +{ + yaffs_Tags asTags; + __u8 asBytes[8]; +} yaffs_TagsUnion; + + +// Spare structure +typedef struct +{ + __u8 tagByte0; + __u8 tagByte1; + __u8 tagByte2; + __u8 tagByte3; + __u8 pageStatus; + __u8 blockStatus; + __u8 tagByte4; + __u8 tagByte5; + __u8 ecc1[3]; + __u8 tagByte6; + __u8 tagByte7; + __u8 ecc2[3]; +} yaffs_Spare; + +// Block data in RAM + +typedef enum { + YAFFS_BLOCK_STATE_UNKNOWN = 0, + + YAFFS_BLOCK_STATE_EMPTY, // This block is empty + + YAFFS_BLOCK_STATE_ALLOCATING, // This block is partially allocated. + // This is the one currently being used for page + // allocation. Should never be more than one of these + + + YAFFS_BLOCK_STATE_FULL, // All the pages in this block have been allocated. + // At least one page holds valid data. + + YAFFS_BLOCK_STATE_DIRTY, // All pages have been allocated and deleted. + // Erase me, reuse me. + + YAFFS_BLOCK_STATE_DEAD = 0x99 // This block has failed and is not in use + +} yaffs_BlockState; + + + + +typedef struct +{ + __u32 pageBits; // bitmap of pages in use + __u8 blockState; // One of the above block states + __u8 pagesInUse; // number of pages in use +} yaffs_BlockInfo; + + +//////////////////// Object structure /////////////////////////// +// This is the object structure as stored on NAND + +typedef enum +{ + YAFFS_OBJECT_TYPE_UNKNOWN, + YAFFS_OBJECT_TYPE_FILE, + YAFFS_OBJECT_TYPE_SYMLINK, + YAFFS_OBJECT_TYPE_DIRECTORY, + YAFFS_OBJECT_TYPE_HARDLINK +} yaffs_ObjectType; + +typedef struct +{ + yaffs_ObjectType type; + + // Apply to everything + int parentObjectId; + __u16 sum; // checksum of name + char name[YAFFS_MAX_NAME_LENGTH + 1]; + + // Thes following apply to directories, files, symlinks - not hard links + __u32 st_mode; // protection + __u32 st_uid; // user ID of owner + __u32 st_gid; // group ID of owner + __u32 st_atime; // time of last access + __u32 st_mtime; // time of last modification + __u32 st_ctime; // time of last change + + // File size applies to files only + int fileSize; + + // Equivalent object id applies to hard links only. + int equivalentObjectId; + char alias[YAFFS_MAX_ALIAS_LENGTH + 1]; + + +} yaffs_ObjectHeader; + + + +//////////////////// Tnode /////////////////////////// + +union yaffs_Tnode_union +{ + union yaffs_Tnode_union *internal[YAFFS_NTNODES_INTERNAL]; + __u16 level0[YAFFS_NTNODES_LEVEL0]; + +}; + +typedef union yaffs_Tnode_union yaffs_Tnode; + +struct yaffs_TnodeList_struct +{ + struct yaffs_TnodeList_struct *next; + yaffs_Tnode *tnodes; +}; + +typedef struct yaffs_TnodeList_struct yaffs_TnodeList; + + + +/////////////////// Object //////////////////////////////// +// An object can be one of: +// - a directory (no data, has children links +// - a regular file (data.... not prunes :->). +// - a symlink [symbolic link] (the alias). +// - a hard link + + +typedef struct +{ + __u32 fileSize; + __u32 topLevel; + yaffs_Tnode *top; +} yaffs_FileStructure; + +typedef struct +{ + struct list_head children; // list of child links +} yaffs_DirectoryStructure; + +typedef struct +{ + char *alias; +} yaffs_SymLinkStructure; + +typedef struct +{ + struct yaffs_ObjectStruct *equivalentObject; + __u32 equivalentObjectId; +} yaffs_HardLinkStructure; + +typedef union +{ + yaffs_FileStructure fileVariant; + yaffs_DirectoryStructure directoryVariant; + yaffs_SymLinkStructure symLinkVariant; + yaffs_HardLinkStructure hardLinkVariant; +} yaffs_ObjectVariant; + + +struct yaffs_ObjectStruct +{ + __u8 fake:1; // A fake object has no presence on NAND. + __u8 renameAllowed:1; + __u8 unlinkAllowed:1; + __u8 dirty:1; // the object needs to be written to flash + __u8 valid:1; // When the file system is being loaded up, this + // object might be created before the data + // is available (ie. file data records appear before the header). + __u8 serial; // serial number of chunk in NAND. Store here so we don't have to + // read back the old one to update. + __u16 sum; // sum of the name to speed searching + + struct yaffs_DeviceStruct *myDev; // The device I'm on + + + struct list_head hashLink; // list of objects in this hash bucket + + + struct list_head hardLinks; // all the equivalent hard linked objects + // live on this list + // directory structure stuff + struct yaffs_ObjectStruct *parent; //my parent directory + struct list_head siblings; // siblings in a directory + // also used for linking up the free list + + // Where's my data in NAND? + int chunkId; // where it lives + + __u32 objectId; // the object id value + + + __u32 st_mode; // protection + __u32 st_uid; // user ID of owner + __u32 st_gid; // group ID of owner + __u32 st_atime; // time of last access + __u32 st_mtime; // time of last modification + __u32 st_ctime; // time of last change + + + yaffs_ObjectType variantType; + + yaffs_ObjectVariant variant; + +}; + + + +typedef struct yaffs_ObjectStruct yaffs_Object; + + +struct yaffs_ObjectList_struct +{ + yaffs_Object *objects; + struct yaffs_ObjectList_struct *next; +}; + +typedef struct yaffs_ObjectList_struct yaffs_ObjectList; + +typedef struct +{ + struct list_head list; + __u32 count; +} yaffs_ObjectBucket; + + +//////////////////// Device //////////////////////////////// + +struct yaffs_DeviceStruct +{ + // Entry parameters set up way early. Yaffs sets up the rest. + __u32 nBlocks; // Size of whole device in blocks + __u32 startBlock; // Start block we're allowed to use + __u32 endBlock; // End block we're allowed to use + __u16 chunkGroupBits; // 0 for devices <= 32MB. else log2(nchunks) - 16 + __u16 chunkGroupSize; // == 2^^chunkGroupBits + + + void *genericDevice; // Pointer to device context + // On an mtd this holds the mtd pointer. + struct semaphore sem;// Semaphore for waiting on erasure. + + + // NAND access functions (Must be set before calling YAFFS) + + int (*writeChunkToNAND)(struct yaffs_DeviceStruct *dev,int chunkInNAND, const __u8 *data, yaffs_Spare *spare); + int (*readChunkFromNAND)(struct yaffs_DeviceStruct *dev,int chunkInNAND, __u8 *data, yaffs_Spare *spare); + int (*eraseBlockInNAND)(struct yaffs_DeviceStruct *dev,int blockInNAND); + int (*initialiseNAND)(struct yaffs_DeviceStruct *dev); + + + + // Runtime parameters. + yaffs_BlockInfo *blockInfo; + int nErasedBlocks; + int allocationBlock; + __u32 allocationPage; + + // Runtime state + int nTnodesCreated; + yaffs_Tnode *freeTnodes; + int nFreeTnodes; + yaffs_TnodeList *allocatedTnodeList; + + + int nObjectsCreated; + yaffs_Object *freeObjects; + int nFreeObjects; + + yaffs_ObjectList *allocatedObjectList; + + yaffs_ObjectBucket objectBucket[YAFFS_NOBJECT_BUCKETS]; + + int nFreeChunks; + + int currentDirtyChecker; // Used to find current dirtiest block + + int garbageCollectionRequired; + + yaffs_Object *rootDir; + yaffs_Object *lostNFoundDir; + + +}; + + typedef struct yaffs_DeviceStruct yaffs_Device; + + + +//////////// YAFFS Functions ////////////////// + +int yaffs_GutsInitialise(yaffs_Device *dev); +void yaffs_Deinitialise(yaffs_Device *dev); + +int yaffs_GetNumberOfFreeChunks(yaffs_Device *dev); + + +// Rename +int yaffs_RenameObject(yaffs_Object *oldDir, const char *oldName, yaffs_Object *newDir, const char *newName); + +// generic Object functions +int yaffs_Unlink(yaffs_Object *dir, const char *name); + +// Object access functions. +int yaffs_GetObjectName(yaffs_Object *obj,char *name,int buffSize); +int yaffs_GetObjectFileLength(yaffs_Object *obj); +int yaffs_GetObjectInode(yaffs_Object *obj); +unsigned yaffs_GetObjectType(yaffs_Object *obj); +int yaffs_GetObjectLinkCount(yaffs_Object *obj); + +// Change inode attributes +int yaffs_SetAttributes(yaffs_Object *obj, struct iattr *attr); +int yaffs_GetAttributes(yaffs_Object *obj, struct iattr *attr); + +// File operations +int yaffs_ReadDataFromFile(yaffs_Object *obj, __u8 *buffer, __u32 offset, int nBytes); +int yaffs_WriteDataToFile(yaffs_Object *obj, const __u8 *buffer, __u32 offset, int nBytes); +int yaffs_ResizeFile(yaffs_Object *obj, int newSize); + +yaffs_Object *yaffs_MknodFile(yaffs_Object *parent,const char *name, __u32 mode, __u32 uid, __u32 gid); +int yaffs_FlushFile(yaffs_Object *obj); + + +// Directory operations +yaffs_Object *yaffs_MknodDirectory(yaffs_Object *parent,const char *name, __u32 mode, __u32 uid, __u32 gid); +yaffs_Object *yaffs_FindObjectByName(yaffs_Object *theDir,const char *name); +int yaffs_ApplyToDirectoryChildren(yaffs_Object *theDir,int (*fn)(yaffs_Object *)); + +yaffs_Object *yaffs_FindObjectByNumber(yaffs_Device *dev,int number); + +// Link operations +yaffs_Object *yaffs_Link(yaffs_Object *parent, const char *name, yaffs_Object *equivalentObject); + +// Symlink operations +yaffs_Object *yaffs_MknodSymLink(yaffs_Object *parent, const char *name, __u32 mode, __u32 uid, __u32 gid, const char *alias); +char *yaffs_GetSymlinkAlias(yaffs_Object *obj); + + +// Special directories +yaffs_Object *yaffs_Root(yaffs_Device *dev); +yaffs_Object *yaffs_LostNFound(yaffs_Device *dev); + + +// Debug dump +int yaffs_DumpObject(yaffs_Object *obj); + + +void yaffs_GutsTest(yaffs_Device *dev); + + +#endif diff --git a/yaffs_mtdif.c b/yaffs_mtdif.c new file mode 100644 index 0000000..3f1e924 --- /dev/null +++ b/yaffs_mtdif.c @@ -0,0 +1,104 @@ +/* + * YAFFS: Yet another FFS. A NAND-flash specific file system. + * yaffs_mtdif.c NAND mtd wrapper functions. + * + * Copyright (C) 2002 Aleph One Ltd. + * for Toby Churchill Ltd and Brightstar Engineering + * + * Created by Charles Manning + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + */ + #ifdef YAFFS_MTD_ENABLED + +#include "yportenv.h" + +#include "yaffs_mtdif.h" + +#include "linux/mtd/mtd.h" +#include "linux/types.h" + + +int nandmtd_WriteChunkToNAND(yaffs_Device *dev,int chunkInNAND,const __u8 *data, yaffs_Spare *spare) +{ + struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice); + size_t dummy; + + loff_t addr = ((loff_t)chunkInNAND) * YAFFS_BYTES_PER_CHUNK; + + + __u8 *spareAsBytes = (__u8 *)spare; + + if(data) + mtd->write(mtd,addr,YAFFS_BYTES_PER_CHUNK,&dummy,data); + if(spare) + mtd->write_oob(mtd,addr,YAFFS_BYTES_PER_SPARE,&dummy,spareAsBytes); + + return YAFFS_OK; +} + + +int nandmtd_ReadChunkFromNAND(yaffs_Device *dev,int chunkInNAND, __u8 *data, yaffs_Spare *spare) +{ + struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice); + size_t dummy; + + loff_t addr = ((loff_t)chunkInNAND) * YAFFS_BYTES_PER_CHUNK; + + __u8 *spareAsBytes = (__u8 *)spare; + + if(data) + mtd->read(mtd,addr,YAFFS_BYTES_PER_CHUNK,&dummy,data); + if(spare) + mtd->read_oob(mtd,addr,YAFFS_BYTES_PER_SPARE,&dummy,spareAsBytes); + + return YAFFS_OK; +} + + +static void nandmtd_EraseCallback(struct erase_info *ei) +{ + yaffs_Device *dev = (yaffs_Device *)ei->priv; + up(&dev->sem); +} + + +int nandmtd_EraseBlockInNAND(yaffs_Device *dev, int blockNumber) +{ + + struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice); + __u32 addr = ((loff_t) blockNumber) * YAFFS_BYTES_PER_BLOCK; + struct erase_info ei; + + ei.mtd = mtd; + ei.addr = addr; + ei.len = YAFFS_BYTES_PER_BLOCK; + ei.time = 1000; + ei.retries = 2; + ei.callback = nandmtd_EraseCallback; + ei.priv = (u_long)dev; + + // Todo finish off the ei if required + + sema_init(&dev->sem,0); + + mtd->erase(mtd,&ei); + + + down(&dev->sem); // Wait for the erasure to complete + + //Todo, check result of erasure + + return YAFFS_OK; +} + +int nandmtd_InitialiseNAND(yaffs_Device *dev) +{ + return YAFFS_OK; +} + +#endif // YAFFS_MTD_ENABLED + diff --git a/yaffs_mtdif.h b/yaffs_mtdif.h new file mode 100644 index 0000000..6dc2e1b --- /dev/null +++ b/yaffs_mtdif.h @@ -0,0 +1,29 @@ +/* + * YAFFS: Yet another FFS. A NAND-flash specific file system. + * yaffs_mtdif.h NAND mtd interface wrappers + * + * Copyright (C) 2002 Aleph One Ltd. + * for Toby Churchill Ltd and Brightstar Engineering + * + * Created by Charles Manning + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + */ + +#ifndef __YAFFS_MTDIF_H__ +#define __YAFFS_MTDIF_H__ + +#include "yaffs_guts.h" + +int nandmtd_WriteChunkToNAND(yaffs_Device *dev,int chunkInNAND,const __u8 *data, yaffs_Spare *spare); +int nandmtd_ReadChunkFromNAND(yaffs_Device *dev,int chunkInNAND, __u8 *data, yaffs_Spare *spare); +int nandmtd_EraseBlockInNAND(yaffs_Device *dev, int blockNumber); +int nandmtd_InitialiseNAND(yaffs_Device *dev); +#endif + + + + diff --git a/yaffs_nandemul.h b/yaffs_nandemul.h new file mode 100644 index 0000000..f233408 --- /dev/null +++ b/yaffs_nandemul.h @@ -0,0 +1,34 @@ +/* + * YAFFS: Yet another FFS. A NAND-flash specific file system. + * + * Copyright (C) 2002 Aleph One Ltd. + * for Toby Churchill Ltd and Brightstar Engineering + * + * Created by Charles Manning + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * yaffs_nandemul.h: Interface to emulated NAND functions + * + */ + +#ifndef __YAFFS_NANDEMUL_H__ +#define __YAFFS_NANDEMUL_H__ + +#include "yaffs_guts.h" + + +/* WriteChunkToNAND and ReadChunkFromNAND are used with two pointers. + * If either of these pointers are null, then that field will not be + * transferred. + */ + +int nandemul_WriteChunkToNAND(struct yaffs_DeviceStruct *dev,int chunkInNAND, const __u8 *data, yaffs_Spare *spare); +int nandemul_ReadChunkFromNAND(struct yaffs_DeviceStruct *dev,int chunkInNAND, __u8 *data, yaffs_Spare *spare); +int nandemul_EraseBlockInNAND(struct yaffs_DeviceStruct *dev,int blockInNAND); +int nandemul_InitialiseNAND(struct yaffs_DeviceStruct *dev); + +#endif + diff --git a/yaffs_ramem.c b/yaffs_ramem.c new file mode 100644 index 0000000..7143dff --- /dev/null +++ b/yaffs_ramem.c @@ -0,0 +1,291 @@ +/* + * YAFFS: Yet another FFS. A NAND-flash specific file system. + * yaffs_ramem.c NAND emulation on top of a chunk of RAM + * + * Copyright (C) 2002 Aleph One Ltd. + * for Toby Churchill Ltd and Brightstar Engineering + * + * Created by Charles Manning + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + */ + //yaffs_ramem.c + // Since this creates the RAM block at start up it is pretty useless for testing the scanner. + +#ifdef YAFFS_RAM_ENABLED + +#include "yportenv.h" + +#include "yaffs_nandemul.h" +#include "yaffs_guts.h" +#include "yaffsinterface.h" +#include "devextras.h" + + +#define EM_SIZE_IN_MEG 2 + +#define BLOCK_SIZE (32 * 528) +#define BLOCKS_PER_MEG ((1024*1024)/(32 * 512)) +#define FILE_SIZE_IN_BLOCKS (FILE_SIZE_IN_MEG * BLOCKS_PER_MEG) +#define FILE_SIZE_IN_BYTES (FILE_SIZE_IN_BLOCKS * BLOCK_SIZE) + +#define T(x) YPRINTF(x) + +#define DEFAULT_SIZE_IN_MB 2 + +typedef struct +{ + __u8 data[528]; // Data + spare + int count[3]; // The programming count for each area of + // the page (0..255,256..511,512..527 + int empty; // is this empty? +} nandemul_Page; + +typedef struct +{ + nandemul_Page page[32]; // The pages in the block + __u8 damaged; // Is the block damaged? + +} nandemul_Block; + + + +typedef struct +{ + nandemul_Block **block; + int nBlocks; +} nandemul_Device; + +static nandemul_Device ned; + +int sizeInMB = DEFAULT_SIZE_IN_MB; + + +static void nandemul_ReallyEraseBlock(int blockNumber) +{ + int i; + + nandemul_Block *theBlock = ned.block[blockNumber]; + + for(i = 0; i < 32; i++) + { + memset(theBlock->page[i].data,0xff,528); + theBlock->page[i].count[0] = 0; + theBlock->page[i].count[1] = 0; + theBlock->page[i].count[2] = 0; + theBlock->page[i].empty = 1; + } + +} + + +int nandemul_CalcNBlocks(void) +{ + switch(sizeInMB) + { + case 8: + case 16: + case 32: + case 64: + case 128: + case 256: + case 512: + break; + default: + sizeInMB = DEFAULT_SIZE_IN_MB; + } + return sizeInMB * 64; +} + + + +static int CheckInit(void) +{ + static int initialised = 0; + + int i; + int fail = 0; + int nBlocks; + int nAllocated = 0; + + if(initialised) + { + return YAFFS_OK; + } + + + nBlocks = nandemul_CalcNBlocks(); + + ned.block = YMALLOC(sizeof(nandemul_Block *) * nBlocks); + + if(!ned.block) return 0; + + for(i=0; i damaged = 0; + nAllocated++; + } + } + + if(fail) + { + for(i = 0; i < nAllocated; i++) + { + YFREE(ned.block[i]); + } + YFREE(ned.block); + + T(("Allocation failed, could only allocate %dMB of %dMB requested.\n", + nAllocated/64,sizeInMB)); + return 0; + } + + ned.nBlocks = nBlocks; + + initialised = 1; + + return 1; +} + +int nandemul_WriteChunkToNAND(yaffs_Device *dev,int chunkInNAND,const __u8 *data, yaffs_Spare *spare) +{ + int blk; + int pg; + int i; + + __u8 *x; + + __u8 *spareAsBytes = (__u8 *)spare; + + + CheckInit(); + + blk = chunkInNAND/32; + pg = chunkInNAND%32; + + + if(data) + { + x = ned.block[blk]->page[pg].data; + + for(i = 0; i < 512; i++) + { + x[i] &=data[i]; + } + + ned.block[blk]->page[pg].count[0]++; + ned.block[blk]->page[pg].count[1]++; + ned.block[blk]->page[pg].empty = 0; + } + + + if(spare) + { + x = &ned.block[blk]->page[pg].data[512]; + + for(i = 0; i < 16; i++) + { + x[i] &=spareAsBytes[i]; + } + ned.block[blk]->page[pg].count[2]++; + } + + return YAFFS_OK; +} + + +int nandemul_ReadChunkFromNAND(yaffs_Device *dev,int chunkInNAND, __u8 *data, yaffs_Spare *spare) +{ + int blk; + int pg; + + + CheckInit(); + + blk = chunkInNAND/32; + pg = chunkInNAND%32; + + + if(data) + { + memcpy(data,ned.block[blk]->page[pg].data,512); + } + + + if(spare) + { + memcpy(spare,&ned.block[blk]->page[pg].data[512],16); + } + + return YAFFS_OK; +} + + +int nandemul_CheckChunkErased(yaffs_Device *dev,int chunkInNAND) +{ + int blk; + int pg; + int i; + + + CheckInit(); + + blk = chunkInNAND/32; + pg = chunkInNAND%32; + + + for(i = 0; i < 528; i++) + { + if(ned.block[blk]->page[pg].data[i] != 0xFF) + { + return YAFFS_FAIL; + } + } + + return YAFFS_OK; + +} + +int nandemul_EraseBlockInNAND(yaffs_Device *dev, int blockNumber) +{ + + CheckInit(); + + if(blockNumber < 0 || blockNumber >= ned.nBlocks) + { + T(("Attempt to erase non-existant block %d\n",blockNumber)); + } + else if(ned.block[blockNumber]->damaged) + { + T(("Attempt to erase damaged block %d\n",blockNumber)); + } + else + { + nandemul_ReallyEraseBlock(blockNumber); + } + + return YAFFS_OK; +} + +int nandemul_InitialiseNAND(yaffs_Device *dev) +{ + return YAFFS_OK; +} + +#endif //YAFFS_RAM_ENABLED + diff --git a/yaffs_super.c b/yaffs_super.c new file mode 100644 index 0000000..04dc17e --- /dev/null +++ b/yaffs_super.c @@ -0,0 +1,401 @@ +/* + * JFFS2 -- Journalling Flash File System, Version 2. + * + * Copyright (C) 2001 Red Hat, Inc. + * + * Created by David Woodhouse + * + * The original JFFS, from which the design for JFFS2 was derived, + * was designed and implemented by Axis Communications AB. + * + * The contents of this file are subject to the Red Hat eCos Public + * License Version 1.1 (the "Licence"); you may not use this file + * except in compliance with the Licence. You may obtain a copy of + * the Licence at http://www.redhat.com/ + * + * Software distributed under the Licence is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. + * See the Licence for the specific language governing rights and + * limitations under the Licence. + * + * The Original Code is JFFS2 - Journalling Flash File System, version 2 + * + * Alternatively, the contents of this file may be used under the + * terms of the GNU General Public License version 2 (the "GPL"), in + * which case the provisions of the GPL are applicable instead of the + * above. If you wish to allow the use of your version of this file + * only under the terms of the GPL and not to allow others to use your + * version of this file under the RHEPL, indicate your decision by + * deleting the provisions above and replace them with the notice and + * other provisions required by the GPL. If you do not delete the + * provisions above, a recipient may use your version of this file + * under either the RHEPL or the GPL. + * + * $Id: yaffs_super.c,v 1.1 2002-05-20 17:42:08 aleph1 Exp $ + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "nodelist.h" + +#ifndef MTD_BLOCK_MAJOR +#define MTD_BLOCK_MAJOR 31 +#endif + +extern void jffs2_read_inode (struct inode *); +void jffs2_put_super (struct super_block *); +void jffs2_write_super (struct super_block *); +static int jffs2_statfs (struct super_block *, struct statfs *); +int jffs2_remount_fs (struct super_block *, int *, char *); +extern void jffs2_clear_inode (struct inode *); + +static struct super_operations jffs2_super_operations = +{ + read_inode: jffs2_read_inode, +// delete_inode: jffs2_delete_inode, + put_super: jffs2_put_super, + write_super: jffs2_write_super, + statfs: jffs2_statfs, + remount_fs: jffs2_remount_fs, + clear_inode: jffs2_clear_inode +}; + +static int jffs2_statfs(struct super_block *sb, struct statfs *buf) +{ + struct jffs2_sb_info *c = JFFS2_SB_INFO(sb); + unsigned long avail; + + buf->f_type = JFFS2_SUPER_MAGIC; + buf->f_bsize = 1 << PAGE_SHIFT; + buf->f_blocks = c->flash_size >> PAGE_SHIFT; + buf->f_files = 0; + buf->f_ffree = 0; + buf->f_namelen = JFFS2_MAX_NAME_LEN; + + spin_lock_bh(&c->erase_completion_lock); + + avail = c->dirty_size + c->free_size; + if (avail > c->sector_size * JFFS2_RESERVED_BLOCKS_WRITE) + avail -= c->sector_size * JFFS2_RESERVED_BLOCKS_WRITE; + else + avail = 0; + + buf->f_bavail = buf->f_bfree = avail >> PAGE_SHIFT; + +#if CONFIG_JFFS2_FS_DEBUG > 0 + printk(KERN_DEBUG "STATFS:\n"); + printk(KERN_DEBUG "flash_size: %08x\n", c->flash_size); + printk(KERN_DEBUG "used_size: %08x\n", c->used_size); + printk(KERN_DEBUG "dirty_size: %08x\n", c->dirty_size); + printk(KERN_DEBUG "free_size: %08x\n", c->free_size); + printk(KERN_DEBUG "erasing_size: %08x\n", c->erasing_size); + printk(KERN_DEBUG "bad_size: %08x\n", c->bad_size); + printk(KERN_DEBUG "sector_size: %08x\n", c->sector_size); + + if (c->nextblock) { + printk(KERN_DEBUG "nextblock: 0x%08x\n", c->nextblock->offset); + } else { + printk(KERN_DEBUG "nextblock: NULL\n"); + } + if (c->gcblock) { + printk(KERN_DEBUG "gcblock: 0x%08x\n", c->gcblock->offset); + } else { + printk(KERN_DEBUG "gcblock: NULL\n"); + } + if (list_empty(&c->clean_list)) { + printk(KERN_DEBUG "clean_list: empty\n"); + } else { + struct list_head *this; + + list_for_each(this, &c->clean_list) { + struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list); + printk(KERN_DEBUG "clean_list: %08x\n", jeb->offset); + } + } + if (list_empty(&c->dirty_list)) { + printk(KERN_DEBUG "dirty_list: empty\n"); + } else { + struct list_head *this; + + list_for_each(this, &c->dirty_list) { + struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list); + printk(KERN_DEBUG "dirty_list: %08x\n", jeb->offset); + } + } + if (list_empty(&c->erasing_list)) { + printk(KERN_DEBUG "erasing_list: empty\n"); + } else { + struct list_head *this; + + list_for_each(this, &c->erasing_list) { + struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list); + printk(KERN_DEBUG "erasing_list: %08x\n", jeb->offset); + } + } + if (list_empty(&c->erase_pending_list)) { + printk(KERN_DEBUG "erase_pending_list: empty\n"); + } else { + struct list_head *this; + + list_for_each(this, &c->erase_pending_list) { + struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list); + printk(KERN_DEBUG "erase_pending_list: %08x\n", jeb->offset); + } + } + if (list_empty(&c->free_list)) { + printk(KERN_DEBUG "free_list: empty\n"); + } else { + struct list_head *this; + + list_for_each(this, &c->free_list) { + struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list); + printk(KERN_DEBUG "free_list: %08x\n", jeb->offset); + } + } + if (list_empty(&c->bad_list)) { + printk(KERN_DEBUG "bad_list: empty\n"); + } else { + struct list_head *this; + + list_for_each(this, &c->bad_list) { + struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list); + printk(KERN_DEBUG "bad_list: %08x\n", jeb->offset); + } + } + if (list_empty(&c->bad_used_list)) { + printk(KERN_DEBUG "bad_used_list: empty\n"); + } else { + struct list_head *this; + + list_for_each(this, &c->bad_used_list) { + struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list); + printk(KERN_DEBUG "bad_used_list: %08x\n", jeb->offset); + } + } +#endif /* CONFIG_JFFS2_FS_DEBUG */ + + spin_unlock_bh(&c->erase_completion_lock); + + + return 0; +} + +static struct super_block *jffs2_read_super(struct super_block *sb, void *data, int silent) +{ + struct jffs2_sb_info *c; + struct inode *root_i; + int i; + + D1(printk(KERN_DEBUG "jffs2: read_super for device %s\n", kdevname(sb->s_dev))); + + if (MAJOR(sb->s_dev) != MTD_BLOCK_MAJOR) { + if (!silent) + printk(KERN_DEBUG "jffs2: attempt to mount non-MTD device %s\n", kdevname(sb->s_dev)); + return NULL; + } + + c = JFFS2_SB_INFO(sb); + memset(c, 0, sizeof(*c)); + + c->mtd = get_mtd_device(NULL, MINOR(sb->s_dev)); + if (!c->mtd) { + D1(printk(KERN_DEBUG "jffs2: MTD device #%u doesn't appear to exist\n", MINOR(sb->s_dev))); + return NULL; + } + c->sector_size = c->mtd->erasesize; + c->free_size = c->flash_size = c->mtd->size; + c->nr_blocks = c->mtd->size / c->mtd->erasesize; + c->blocks = kmalloc(sizeof(struct jffs2_eraseblock) * c->nr_blocks, GFP_KERNEL); + if (!c->blocks) + goto out_mtd; + for (i=0; inr_blocks; i++) { + INIT_LIST_HEAD(&c->blocks[i].list); + c->blocks[i].offset = i * c->sector_size; + c->blocks[i].free_size = c->sector_size; + c->blocks[i].dirty_size = 0; + c->blocks[i].used_size = 0; + c->blocks[i].first_node = NULL; + c->blocks[i].last_node = NULL; + } + + spin_lock_init(&c->nodelist_lock); + init_MUTEX(&c->alloc_sem); + init_waitqueue_head(&c->erase_wait); + spin_lock_init(&c->erase_completion_lock); + spin_lock_init(&c->inocache_lock); + + INIT_LIST_HEAD(&c->clean_list); + INIT_LIST_HEAD(&c->dirty_list); + INIT_LIST_HEAD(&c->erasing_list); + INIT_LIST_HEAD(&c->erase_pending_list); + INIT_LIST_HEAD(&c->erase_complete_list); + INIT_LIST_HEAD(&c->free_list); + INIT_LIST_HEAD(&c->bad_list); + INIT_LIST_HEAD(&c->bad_used_list); + c->highest_ino = 1; + + if (jffs2_build_filesystem(c)) { + D1(printk(KERN_DEBUG "build_fs failed\n")); + goto out_nodes; + } + sb->s_op = &jffs2_super_operations; + + D1(printk(KERN_DEBUG "jffs2_read_super(): Getting root inode\n")); + root_i = iget(sb, 1); + if (is_bad_inode(root_i)) { + D1(printk(KERN_WARNING "get root inode failed\n")); + goto out_nodes; + } + + D1(printk(KERN_DEBUG "jffs2_read_super(): d_alloc_root()\n")); + sb->s_root = d_alloc_root(root_i); + if (!sb->s_root) + goto out_root_i; + +#if LINUX_VERSION_CODE >= 0x20403 + sb->s_maxbytes = 0xFFFFFFFF; +#endif + sb->s_blocksize = PAGE_CACHE_SIZE; + sb->s_blocksize_bits = PAGE_CACHE_SHIFT; + sb->s_magic = JFFS2_SUPER_MAGIC; + if (!(sb->s_flags & MS_RDONLY)) + jffs2_start_garbage_collect_thread(c); + return sb; + + out_root_i: + iput(root_i); + out_nodes: + jffs2_free_ino_caches(c); + jffs2_free_raw_node_refs(c); + kfree(c->blocks); + out_mtd: + put_mtd_device(c->mtd); + return NULL; +} + +void jffs2_put_super (struct super_block *sb) +{ + struct jffs2_sb_info *c = JFFS2_SB_INFO(sb); + + D2(printk(KERN_DEBUG "jffs2: jffs2_put_super()\n")); + + if (!(sb->s_flags & MS_RDONLY)) + jffs2_stop_garbage_collect_thread(c); + jffs2_free_ino_caches(c); + jffs2_free_raw_node_refs(c); + kfree(c->blocks); + if (c->mtd->sync) + c->mtd->sync(c->mtd); + put_mtd_device(c->mtd); + + D1(printk(KERN_DEBUG "jffs2_put_super returning\n")); +} + +int jffs2_remount_fs (struct super_block *sb, int *flags, char *data) +{ + struct jffs2_sb_info *c = JFFS2_SB_INFO(sb); + + if (c->flags & JFFS2_SB_FLAG_RO && !(sb->s_flags & MS_RDONLY)) + return -EROFS; + + /* We stop if it was running, then restart if it needs to. + This also catches the case where it was stopped and this + is just a remount to restart it */ + if (!(sb->s_flags & MS_RDONLY)) + jffs2_stop_garbage_collect_thread(c); + + if (!(*flags & MS_RDONLY)) + jffs2_start_garbage_collect_thread(c); + + sb->s_flags = (sb->s_flags & ~MS_RDONLY)|(*flags & MS_RDONLY); + + return 0; +} + +void jffs2_write_super (struct super_block *sb) +{ + struct jffs2_sb_info *c = JFFS2_SB_INFO(sb); + sb->s_dirt = 0; + + if (sb->s_flags & MS_RDONLY) + return; + + jffs2_garbage_collect_trigger(c); + jffs2_erase_pending_blocks(c); + jffs2_mark_erased_blocks(c); +} + + +static DECLARE_FSTYPE_DEV(jffs2_fs_type, "jffs2", jffs2_read_super); + +static int __init init_jffs2_fs(void) +{ + int ret; + + printk(KERN_NOTICE "JFFS2 version 2.1. (C) 2001 Red Hat, Inc., designed by Axis Communications AB.\n"); + +#ifdef JFFS2_OUT_OF_KERNEL + /* sanity checks. Could we do these at compile time? */ + if (sizeof(struct jffs2_sb_info) > sizeof (((struct super_block *)NULL)->u)) { + printk(KERN_ERR "JFFS2 error: struct jffs2_sb_info (%d bytes) doesn't fit in the super_block union (%d bytes)\n", + sizeof(struct jffs2_sb_info), sizeof (((struct super_block *)NULL)->u)); + return -EIO; + } + + if (sizeof(struct jffs2_inode_info) > sizeof (((struct inode *)NULL)->u)) { + printk(KERN_ERR "JFFS2 error: struct jffs2_inode_info (%d bytes) doesn't fit in the inode union (%d bytes)\n", + sizeof(struct jffs2_inode_info), sizeof (((struct inode *)NULL)->u)); + return -EIO; + } +#endif + + ret = jffs2_create_slab_caches(); + if (ret) { + printk(KERN_ERR "JFFS2 error: Failed to initialise slab caches\n"); + return ret; + } + ret = register_filesystem(&jffs2_fs_type); + if (ret) { + printk(KERN_ERR "JFFS2 error: Failed to register filesystem\n"); + jffs2_destroy_slab_caches(); + } + return ret; +} + +static void __exit exit_jffs2_fs(void) +{ + jffs2_destroy_slab_caches(); + unregister_filesystem(&jffs2_fs_type); +} + +module_init(init_jffs2_fs); +module_exit(exit_jffs2_fs); + +MODULE_DESCRIPTION("The Journalling Flash File System, v2"); +MODULE_AUTHOR("Red Hat, Inc."); +MODULE_LICENSE("GPL"); // Actually dual-licensed, but it doesn't matter for + // the sake of this tag. It's Free Software. +/* + * YAFFS: Yet another FFS. A NAND-flash specific file system. + * + * Copyright (C) 2002 Aleph One Ltd. + * for Toby Churchill Ltd and Brightstar Engineering + * + * Created by Charles Manning + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + */ diff --git a/yaffsdev b/yaffsdev new file mode 100755 index 0000000000000000000000000000000000000000..6e51051b859dcc7fdd205bf6b372f0915281d490 GIT binary patch literal 93829 zcmd?Sdtekr_BLEI(=*dE6HP==Zc5akxPl_0f`EoFBT+yj5XCFkz=TUcGU2Atfe>Yg z(df#q_lRW{x@U4@Wc2wimrK~mEj)s*)>IniK%5&cmiGpVY~d4q#Id3W&O*?=fpPHQ zNCMO0#bMy^;Ao)(_vknhm=3x}(xgNH+@mA+Y9Z*L{31)Ic@f|ezS{9$`+kkI``B8@*YI9 zZX+)$1d`=YS)|tyI6C2=6u?2UD6!5sLp?6v#F^@siGvd5JDd?$%|acY$aV*&APA&K z1`fYf> z!I|#ghQoj#yl!0|hjV9K53sKL;GBc&ldS90a2|;3`*9|D*Wn1`+6#k_yq9o{$Mt`3 zrt2ac({Me)x<-?V7_RTLuH!iGd(SY*)l;uJ8{21&U9Z) zoH%37+>(i`!t>5uxscHCtgcu zl)Qn?nL=!$GdfCP;){wVGc^oF*QDOXXX;-CLcF%M{mkpZ(cU|bPtvo!H)$9p*x1mH z)SEPo(!Iudz9x;MRQ1LrUz6t1u5`VIuc-#nY`U)HYpO}K4_(*rHPtBEpRVJ4O*M-S zqU(8lO*M?>()A?1rkY0c>AHZgsm4+0E*f+Bnra@MK-c~Gnk*2VMAzATO_qpKg&MQ? znk*8XN7n+^IIDE}H`gToU9qpZVEowV8uX3mE$Fb9TpDfOWtgcmz}%Af8Fn03kfJPC zF5P<13?Zs2NVm#l%-vpJb#>coTN6LmSgEk8%V-qFmalxL?1HK;`M9idgSmTk>_kzW zXFNod_DNNUSPFpf-csR zM$l~o#V9m1@^`^08vhp6U?C?+A;eu%y_Uk(q4HNn%&Pb#_)#Kx^;XE^>uJt4WP;RQ z*15ebtGz6vz09o2?c81u?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KLE`s(P(MApQ{!qfQFxRwc-fZ$XyYpgTxP+fD6XuLRFpnBq@Aj%w z`?&(uXp~Y?!DFKCm!$E-GrP%XO(mC#3=w#uG?H7dy}5y7b4Jwi$`Gvk%LywFIVE?U zIJ|iLMcfgq#$RR(1h1R9D{w^Sbz4N-m2adkZJ zHWqZ+``M9C8tJ{3AoF~oq}Aimc-3|KDr(VdiYP~MQuNkxB0Ob=x6^uYa+}Q~*WR7C z94n8T3x?nnqQ&MkDr3Y=6ixi3rL!2144&49(@oq=Dm7PQypC9pc<~6v<3*Ohm4VAD z33;x6z}k&|1Y;P{9sR|w{ldpGpfhXlp}ETOYA2}}es6{BTamQ`F*P%{2X8W+!{dl1 z@jRWeJu{PVba96*T}R!!2g09U3(#vkc`&BbUh{{u*5Y{bOCYLseO)P`C*ra}CRQx| zU5lZ_Q=|ztm_CK+ARqY0hvVsc?kqob^^iZZ#Z3!btXVsN;-jZjJ$6H^w&W+ih6t7| ST&;vwC%X_h@ifwDo%o;HDSl4? literal 0 HcmV?d00001 diff --git a/yaffsdev.c b/yaffsdev.c new file mode 100644 index 0000000..64368f4 --- /dev/null +++ b/yaffsdev.c @@ -0,0 +1,303 @@ +/* + * YAFFS: Yet another FFS. A NAND-flash specific file system. + * yaffsdev.c + * + * Copyright (C) 2002 Aleph One Ltd. + * for Toby Churchill Ltd and Brightstar Engineering + * + * Created by Charles Manning + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + */ + +#include "yaffsinterface.h" +#include "yaffs_nandemul.h" +#include "yaffs_guts.h" +#include + +#include +#include + + + + + +yaffs_Device device; + + + + + + + +char *testStr = "this is a test string"; + +char *testStr2 = "abcdefghijklmnopqrstuvwxyz1234567890"; + +void TestTimexxx(yaffs_Device *dev) +{ + yaffs_Object *f; + int x; + + + printf("Start\n"); + + + f = yaffs_FindObjectByName(yaffs_Root(dev),"Name1"); + if(f) + { + printf("Found\n"); + } + else + { + f = yaffs_MknodFile(yaffs_Root(dev),"Name1",0,0,0); + printf("Created\n"); + } + + + x = yaffs_RenameObject(yaffs_Root(dev),"Name1",NULL,"Rename"); + +} + + +void TestTimeasasas(yaffs_Device *dev) +{ + yaffs_Object *f; + int x; + int i; + int b; + char data[200]; + int written; + + + printf("Start\n"); + + + f = yaffs_FindObjectByName(yaffs_Root(dev),"Name1"); + if(f) + { + printf("Found\n"); + } + else + { + f = yaffs_MknodFile(yaffs_Root(dev),"Name1",0,0,0); + printf("Created\n"); + } + + + x = yaffs_RenameObject(yaffs_Root(dev),"Name1",NULL,"Rename"); + + + + for(i = 0; i < 10000; i+=20) + { + + b++; + if(b & 1) + written = yaffs_WriteDataToFile(f,testStr,i,strlen(testStr)); + else + written = yaffs_WriteDataToFile(f,testStr2,i,strlen(testStr2)); + } + + + yaffs_ApplyToDirectoryChildren(yaffs_Root(dev),yaffs_DumpObject); + + printf("Flush\n"); + + yaffs_FlushFile(f); + + yaffs_ApplyToDirectoryChildren(yaffs_Root(dev),yaffs_DumpObject); + + yaffs_ReadDataFromFile(f,data,1000,50); + data[50] = 0; + + printf("Read data is \"%s\"\n",data); + + yaffs_DumpObject(f); + + printf("Resize\n"); + yaffs_ResizeFile(f,2000); + + yaffs_DumpObject(f); + + yaffs_FlushFile(f); + + + + +} + +void TestTime(yaffs_Device *dev) +{ + yaffs_Object *f; + yaffs_Object *sl; + yaffs_Object *lnf; + + yaffs_Object *hl1; + yaffs_Object *hl2; + yaffs_Object *hl3; + yaffs_Object *d, *df; + + int x; + int i; + int b; + char data[200]; + + char * alias; + int written; + + + printf("Start\n"); + + + f = yaffs_FindObjectByName(yaffs_Root(dev),"Name1"); + if(f) + { + printf("Found\n"); + } + else + { + f = yaffs_MknodFile(yaffs_Root(dev),"Name1",0,0,0); + printf("Created\n"); + } + + + x = yaffs_RenameObject(yaffs_Root(dev),"Name1",NULL,"Rename"); + + for(i = 0; i < 100000; i+=20) + { + + b++; + if(b & 1) + written = yaffs_WriteDataToFile(f,testStr,i,strlen(testStr)); + else + written = yaffs_WriteDataToFile(f,testStr2,i,strlen(testStr2)); + } + + yaffs_ApplyToDirectoryChildren(yaffs_Root(dev),yaffs_DumpObject); + + printf("Flush\n"); + + yaffs_FlushFile(f); + + printf("File length is %d\n",yaffs_GetObjectFileLength(f)); + + sl = yaffs_MknodSymLink(yaffs_Root(dev),"sym-link",0,0,0,"/tmp/alias"); + + + yaffs_ApplyToDirectoryChildren(yaffs_Root(dev),yaffs_DumpObject); + + printf("\n\nsymlink alias is \"%s\"\n",alias = yaffs_GetSymlinkAlias(sl)); + + free(alias); + + printf("Unlink symlink %d\n",yaffs_Unlink(yaffs_Root(dev),"sym-link")); + + + yaffs_ReadDataFromFile(f,data,1000,50); + data[50] = 0; + + printf("Read data is \"%s\"\n",data); + + yaffs_DumpObject(f); + + printf("Resize\n"); + yaffs_ResizeFile(f,2000); + + yaffs_DumpObject(f); + + lnf = yaffs_FindObjectByName(yaffs_Root(dev),YAFFS_LOSTNFOUND_NAME); + + + + yaffs_FlushFile(f); + + + printf("Unlink file: %d\n",yaffs_Unlink(yaffs_Root(dev),"Rename")); + + yaffs_ApplyToDirectoryChildren(yaffs_Root(dev),yaffs_DumpObject); + + // Create a directory and play with it + + + printf("Create directory and play with it\n"); + + d = yaffs_MknodDirectory(yaffs_Root(dev),"direct",0,0,0); + yaffs_ApplyToDirectoryChildren(yaffs_Root(dev),yaffs_DumpObject); + yaffs_ApplyToDirectoryChildren(d,yaffs_DumpObject); + + printf("Make file in directory\n"); + + df = yaffs_MknodFile(d,"file-in-directory",0,0,0); + yaffs_ApplyToDirectoryChildren(d,yaffs_DumpObject); + + + // Do some stuff with hardlinks + // + // NB Deleting hardlinked objects can mess up pointers to hardlinks. + // The mechanism is as follows: + // * If you unlink a file,softlink or directory that has one or more hardlinks, + // then the object is renamed to one of the hardlinks and that hardlink is unlinked. + // This means that a pointer to a hardlink so deleted will point to an invalid address. + // Thus, make sure that pointers to hardlinks are immediately dereferenced. + + + printf("Hard link tests\n"); + + f = yaffs_MknodFile(yaffs_Root(dev),"Name1",0,0,0); + hl1 = yaffs_Link(yaffs_Root(dev),"HardLink 1",f); + hl2 = yaffs_Link(yaffs_Root(dev),"HardLink 2",f); + hl3 = yaffs_Link(yaffs_Root(dev),"HardLink 3",hl2); + + printf("\n\nHard links created\n"); + yaffs_ApplyToDirectoryChildren(yaffs_Root(dev),yaffs_DumpObject); + + yaffs_Unlink(yaffs_Root(dev),"HardLink 1"); + printf("\n\nHard link deleted\n"); + yaffs_ApplyToDirectoryChildren(yaffs_Root(dev),yaffs_DumpObject); + + yaffs_Unlink(yaffs_Root(dev),"Name1"); + printf("\n\nHard linked file deleted\n"); + yaffs_ApplyToDirectoryChildren(yaffs_Root(dev),yaffs_DumpObject); + + yaffs_Unlink(yaffs_Root(dev),"HardLink 2"); + printf("\n\nHard link 2 deleted\n"); + yaffs_ApplyToDirectoryChildren(yaffs_Root(dev),yaffs_DumpObject); + + yaffs_Unlink(yaffs_Root(dev),"HardLink 3"); + + printf("\n\nHard link 3 deleted\n"); + yaffs_ApplyToDirectoryChildren(yaffs_Root(dev),yaffs_DumpObject); + + // NB We don't allow unlinking or rename of the root or lost+found + // We allow setting attributes, but these must not be written to + // NAND since they are not real objects. + + printf("Attempt to rename lost+found - should have failed\n"); + x = yaffs_RenameObject(yaffs_Root(dev),YAFFS_LOSTNFOUND_NAME,NULL,"Renamed"); + yaffs_ApplyToDirectoryChildren(yaffs_Root(dev),yaffs_DumpObject); + +} + +int main(int argc,char *argv[]) +{ + device.nBlocks = (2 * 1024 * 1024) / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK); + device.startBlock = 1; // Don't use block 0 + device.endBlock = device.nBlocks - 1; + + device.writeChunkToNAND = nandemul_WriteChunkToNAND; + device.readChunkFromNAND = nandemul_ReadChunkFromNAND; + device.eraseBlockInNAND = nandemul_EraseBlockInNAND; + device.initialiseNAND = nandemul_InitialiseNAND; + + yaffs_GutsInitialise(&device); + + // yaffs_GutsTest(); + + TestTime(&device); + + exit(0); +} diff --git a/yaffsdev.proj b/yaffsdev.proj new file mode 100644 index 0000000000000000000000000000000000000000..233551187effaeeb5015185a415ac0c2bbd4a863 GIT binary patch literal 28672 zcmeG_3y>Veb*Nq<*v2+hjv)gA=OlD{yZ6(b0Eg3_bUGy6sdOg`a9qpW?%eI_ zc4sy-v!^@O2O%z3r3m0ptbj~xh;gWL2qbnYj?2b4PNfo3=1+_v0Vg4$Ac?EMrd*X2 zPL%h$d%iojJ1Y@VN%qQOr@LRj_xkng-+TSqWb6A>LWn>}&ohL)3qDDTkS*|o|Hygp z56WmF0l)YU3obu%=4bT#l)mwgkj6iR!+-Di-+7ePcbsgOU{?ZN33MgUl|WYlT?uq0 z(3L<}0$mAoCD4^XR|5ZQB#re$P@AhCcTD2XZYr>Qqn z&!>JhWv9$k3jSqNcf;?EsTYz5Qx7J$r*2CATk^u>-N~Q!olHL2cP#mpzTxCeeW~P; zzL)zh>-$#U*1miDp4z7OeRbP>-|gFm`@YwAy6?8W+%^I15x1Y0+tymVt&9-c3E55- z4ZF0fU}}vuQ(ICRjjF0#H@ScRe13Ljc5Z54e($l|!F>z!N@GJ=SC^Ko{Bqs4(j_GW zf5W5cOlBO5;D3-98sC6ViYN+4e^uSFp;&qzA@a+HZCLBoMWf=>X*3EIPGmt{wjxPp zhk#_3lgv(}vo1x(9aiiwRNBzNMjkmjGrO>#5~&%ct?8@0Rhbdms+w8WZIH-@GLp`Y zx@360P1{0BWy?0qb=pYMDA=Z^1sWB~paLmWRLjDG4YxY2NNA&q+A5iu+ILu8(Qzc`rOu8h)g}Gdy2yi;paz~B?iVmv<)0onhKvK;p{e>ZvAlj9Ex^1o>F+ibQlKPNNyA(zmQB)VOjat&5-QV%vU7uIYg(ahtBVyaudUfIRUmN9 zG?q=ZN(POZJ*ZZ+S}Du4ic~>82SAT)#5GvA%)v72041%Y3I86jDDMLRqZMG7lr@W3 z^{PV0dj&>LUZMXjTgsGH(QH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o;18> zW0y~YJIFXWFp}06!8HZ{UBWP)G$KsbR9!2wPf7r5!X&BL=mG6Z<4%rww2R7V^3%Ma~3SQ@dhan>#P2d7#2QJ@#o1RTzfON8?c$|k5@BxN*@+}6K zhSR|aaGKL1;NJIGQL8tN+{cYP^v-if=>njSiH1rj;xz~-HXjr#PxtWDP~*lhqYD&t z$oIZP5RiF7HVvPzsy=H_#>Z;p^Gt(4&5hJ|tw`*B(M?IXj-YtlqpO}au?^>d7R3y& zOXb6lKDfexLU;$mmCt7I9a4f2@yeoFScyf(0d7Zw`wl}Kv%NjfY@w>IlAy&7>}gII zeS~%}h>qBCyWG!Ci>E5w=N{PD=Xa+Zo~YG4gwhY#?!gBxsVFoouZ5hHb@%;TchI;w zE$aE@iw}0T5io+plyGwoVNMHHIvS%mUIACTI_>5jce{>91AhDpbf-JSn1)2aw-bjW zVP+fVcG94+P|5ncK18xby||=(4>-8}OEoG)$_E!0bqnrVl4?=!tVnYcYOB5rkYwYrh;V(yzS|M-+2X}+$^r9wMnAC~3E=A% + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + */ + +#ifndef __YAFFSINTERFACE_H__ +#define __YAFFSINTERFACE_H__ + + +int yaffs_Initialise(unsigned nBlocks); + +#endif + diff --git a/yportenv.h b/yportenv.h new file mode 100644 index 0000000..fc84fc5 --- /dev/null +++ b/yportenv.h @@ -0,0 +1,56 @@ +/* + * YAFFS: Yet another FFS. A NAND-flash specific file system. + * yportenv.h: Portable services used by yaffs. This is done to allow + * simple migration from kernel space into app space for testing. + * + * Copyright (C) 2002 Aleph One Ltd. + * for Toby Churchill Ltd and Brightstar Engineering + * + * Created by Charles Manning + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + */ + +#ifndef __PORTENV_H__ +#define __PORTENV_H__ + +#ifndef __KERNEL__ + +#include "stdlib.h" +#include "stdio.h" +#include "string.h" + +#define YPRINTF(x) printf x +#define YMALLOC(x) malloc(x) +#define YFREE(x) free(x) + + +#define YINFO(s) YPRINTF(( __FILE__ " %d %s\n",__LINE__,s)) +#define YALERT(s) YINFO(s) + +#else + +#include "linux/kernel.h" +#include "linux/mm.h" +#include "linux/string.h" +#include "linux/slab.h" + +#define YPRINTF(x) printk x +#define YMALLOC(x) kmalloc(x,GFP_KERNEL) +#define YFREE(x) kfree(x) + +#endif + + + +#define YINFO(s) YPRINTF((KERN_DEBUG __FILE__ " %d %s\n",__LINE__,s)) +#define YALERT(s) YINFO(s) + +#endif + + + + -- 2.30.2