Skip to content

Commit

Permalink
[COMMON] some patches from yaffs pubic git, cleaneye.kim@lge.com
Browse files Browse the repository at this point in the history
	- hopes that these patches mitigate yaffs crash when mount time

Signed-off-by: cleaneye <cleaneye.kim@lge.com>
  • Loading branch information
cleaneye committed Nov 2, 2010
1 parent 9c277a8 commit 0f1fdea
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 6 deletions.
16 changes: 14 additions & 2 deletions fs/yaffs2/yaffs_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2014,22 +2014,27 @@ static struct super_block *yaffs_internal_read_super(int yaffsVersion,
int err;
char *data_str = (char *)data;

int readOnly = 0;

yaffs_options options;

sb->s_magic = YAFFS_MAGIC;
sb->s_op = &yaffs_super_ops;
sb->s_flags |= MS_NOATIME;

readOnly = ((sb->s_flags & MS_RDONLY) != 0);

if (!sb)
printk(KERN_INFO "yaffs: sb is NULL\n");
else if (!sb->s_dev)
printk(KERN_INFO "yaffs: sb->s_dev is NULL\n");
else if (!yaffs_devname(sb, devname_buf))
printk(KERN_INFO "yaffs: devname is NULL\n");
else
printk(KERN_INFO "yaffs: dev is %d name is \"%s\"\n",
printk(KERN_INFO "yaffs: dev is %d name is \"%s\" %s\n",
sb->s_dev,
yaffs_devname(sb, devname_buf));
yaffs_devname(sb, devname_buf),
readOnly ? "ro" : "rw");

if (!data_str)
data_str = "";
Expand Down Expand Up @@ -2176,6 +2181,12 @@ static struct super_block *yaffs_internal_read_super(int yaffsVersion,
* Set the yaffs_Device up for mtd
*/

if (!readOnly && !(mtd->flags & MTD_WRITEABLE)) {
readOnly = 1;
printk(KERN_INFO, "yaffs: mtd is read only, setting superblock read only\n");
sb->s_flags |= MS_RDONLY;
}

#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
sb->s_fs_info = dev = kmalloc(sizeof(yaffs_Device), GFP_KERNEL);
#else
Expand Down Expand Up @@ -2250,6 +2261,7 @@ static struct super_block *yaffs_internal_read_super(int yaffsVersion,
dev->superBlock = (void *)sb;
dev->markSuperBlockDirty = yaffs_MarkSuperBlockDirty;

dev->readOnly = readOnly;

#ifndef CONFIG_YAFFS_DOES_ECC
dev->useNANDECC = 1;
Expand Down
41 changes: 38 additions & 3 deletions fs/yaffs2/yaffs_guts.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ const char *yaffs_guts_c_version =

#define YAFFS_PASSIVE_GC_CHUNKS 2

/*
* Checkpoints are really no benefit on very small partitions.
*
* To save space on small partitions don't bother with checkpoints unless
* the partition is at least this big.
*/
#define YAFFS_CHECKPOINT_MIN_BLOCKS 60

#include "yaffs_ecc.h"


Expand Down Expand Up @@ -2835,12 +2843,20 @@ static int yaffs_FindBlockForAllocation(yaffs_Device *dev)
return -1;
}

static int yaffs_CheckpointRequired(yaffs_Device *dev)
{
int nblocks = dev->internalEndBlock - dev->internalStartBlock + 1;

return dev->isYaffs2 &&
!dev->skipCheckpointWrite &&
(nblocks >= YAFFS_CHECKPOINT_MIN_BLOCKS);
}

static int yaffs_CalcCheckpointBlocksRequired(yaffs_Device *dev)
{
if (!dev->nCheckpointBlocksRequired &&
dev->isYaffs2) {
// dev->isYaffs2) {
yaffs_CheckpointRequired(dev)) {
/* Not a valid value so recalculate */
int nBytes = 0;
int nBlocks;
Expand Down Expand Up @@ -4534,7 +4550,8 @@ static int yaffs_WriteCheckpointData(yaffs_Device *dev)
{
int ok = 1;

if (dev->skipCheckpointWrite || !dev->isYaffs2) {
// if (dev->skipCheckpointWrite || !dev->isYaffs2) {
if (!yaffs_CheckpointRequired(dev)) {
T(YAFFS_TRACE_CHECKPOINT, (TSTR("skipping checkpoint write" TENDSTR)));
ok = 0;
}
Expand Down Expand Up @@ -5167,7 +5184,8 @@ static int yaffs_UnlinkFileIfNeeded(yaffs_Object *in)
int yaffs_DeleteFile(yaffs_Object *in)
{
int retVal = YAFFS_OK;
int deleted = in->deleted;
//int deleted = in->deleted;
int deleted; /* Need to cache value on stack if in is freed */

yaffs_ResizeFile(in, 0);

Expand All @@ -5178,6 +5196,8 @@ int yaffs_DeleteFile(yaffs_Object *in)
if (!in->unlinked)
retVal = yaffs_UnlinkFileIfNeeded(in);

deleted = in->deleted;

if (retVal == YAFFS_OK && in->unlinked && !in->deleted) {
in->deleted = 1;
deleted = 1;
Expand Down Expand Up @@ -5451,6 +5471,9 @@ static void yaffs_StripDeletedObjects(yaffs_Device *dev)
struct ylist_head *n;
yaffs_Object *l;

if (dev->readOnly)
return;

/* Soft delete all the unlinked files */
ylist_for_each_safe(i, n,
&dev->unlinkedDir->variant.directoryVariant.children) {
Expand Down Expand Up @@ -5504,6 +5527,9 @@ static void yaffs_FixHangingObjects(yaffs_Device *dev)
int depthLimit;
int hanging;

if (dev->readOnly)
return;


/* Iterate through the objects in each hash entry,
* looking at each object.
Expand Down Expand Up @@ -6338,6 +6364,15 @@ static int yaffs_ScanBackwards(yaffs_Device *dev)

dev->nFreeChunks++;

} else if (tags.objectId > YAFFS_MAX_OBJECT_ID ||
tags.chunkId > YAFFS_MAX_CHUNK_ID ||
(tags.chunkId > 0 && tags.byteCount > dev->nDataBytesPerChunk)) {
T(YAFFS_TRACE_SCAN,
(TSTR("Chunk (%d:%d) with bad tags:obj = %d, chunkId = %d, byteCount = %d, ignored"TENDSTR),
blk, c, tags.objectId, tags.chunkId, tags.byteCount));

dev->nFreeChunks++;

} else if (tags.chunkId > 0) {
/* chunkId > 0 so it is a data chunk... */
unsigned int endpos;
Expand Down
3 changes: 3 additions & 0 deletions fs/yaffs2/yaffs_guts.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@

#define YAFFS_OBJECT_SPACE 0x40000

#define YAFFS_MAX_OBJECT_ID (YAFFS_OBJECT_SPACE - 1)

#define YAFFS_CHECKPOINT_VERSION 3

#ifdef CONFIG_YAFFS_UNICODE
Expand Down Expand Up @@ -648,6 +650,7 @@ struct yaffs_DeviceStruct {
#endif

int isMounted;
int readOnly;

int isCheckpointed;

Expand Down
12 changes: 11 additions & 1 deletion fs/yaffs2/yportenv.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@

/* KR - added for use in scan so processes aren't blocked indefinitely. */
#define YYIELD() schedule()
#define Y_DUMP_STACK() dump_stack()

#define YAFFS_ROOT_MODE 0666
#define YAFFS_LOSTNFOUND_MODE 0666
Expand Down Expand Up @@ -196,8 +197,17 @@ extern unsigned int yaffs_wr_attempts;

#define T(mask, p) do { if ((mask) & (yaffs_traceMask | YAFFS_TRACE_ALWAYS)) TOUT(p); } while (0)

#ifndef Y_DUMP_STACK
#define Y_DUMP_STACK() do { } while(0)
#endif

#ifndef YBUG
#define YBUG() do {T(YAFFS_TRACE_BUG, (TSTR("==>> yaffs bug: " __FILE__ " %d" TENDSTR), __LINE__)); } while (0)
#define YBUG() do {\
T(YAFFS_TRACE_BUG, \
(TSTR("==>> yaffs bug: " __FILE__ " %d" TENDSTR),\
__LINE__));\
Y_DUMP_STACK();\
} while (0)
#endif

#endif

0 comments on commit 0f1fdea

Please sign in to comment.