Receive available and used space from JFFS2

[email protected] 17 Jun 2004 10:07:15 UT
Newsgroups gmane.os.ecos.patches,gmane.linux.file-systems.jffs
Message-ID <[email protected]>
Hi,

this adds support for information about used and available space in JFFS2 (ecos). This information is received via cyg_fs_getinfo(). The keys for cyg_fs_getinfo() are FS_INFO_FREESIZE and FS_INFO_USEDSIZE.

Regards,
Dirk



To: [email protected]
Cc: [email protected]
jffs2_getfreespace.patch (application/octet-stream, 3.4 KB)
Index: packages/fs/jffs2/current/src/fs-ecos.c
===================================================================
RCS file: /var/work/cvs/ecos/packages/fs/jffs2/current/src/fs-ecos.c,v
retrieving revision 1.4
diff -u -p -r1.4 fs-ecos.c
--- packages/fs/jffs2/current/src/fs-ecos.c	26 Apr 2004 12:43:13 -0000	1.4
+++ packages/fs/jffs2/current/src/fs-ecos.c	17 Jun 2004 08:22:16 -0000
@@ -1168,10 +1168,34 @@ static int jffs2_getinfo(cyg_mtab_entry 
 	if (err != ENOERR)
 		return err;
 
+	struct super_block *sb = (CYG_ADDRWORD)mte->data;
+	
 	switch (key) {
 	case FS_INFO_CONF:
 		err = jffs2_pathconf(ds.node, (struct cyg_pathconf_info *) buf);
 		break;
+
+	case FS_INFO_FREESIZE: {
+		struct jffs2_sb_info *c;
+		c = JFFS2_SB_INFO(sb);
+		cyg_uint32 avail;
+		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;
+		*(cyg_uint32*)buf = avail;
+		err = ENOERR;
+		break;
+	}
+
+	case FS_INFO_USEDSIZE: {
+		struct jffs2_sb_info *c;
+		c = JFFS2_SB_INFO(sb);
+		*(cyg_uint32*)buf = c->used_size;
+		err = ENOERR;
+		break;
+	}
 
 	default:
 		err = EINVAL;
Index: packages/fs/jffs2/current/src/nodelist.h
===================================================================
RCS file: /var/work/cvs/ecos/packages/fs/jffs2/current/src/nodelist.h,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 nodelist.h
--- packages/fs/jffs2/current/src/nodelist.h	6 Feb 2004 12:43:51 -0000	1.1.1.1
+++ packages/fs/jffs2/current/src/nodelist.h	17 Jun 2004 08:22:16 -0000
@@ -322,6 +322,13 @@ static inline uint32_t ref_totlen(struct
 #define ALLOC_GC	2	/* Space requested for GC. Give it or die */
 #define ALLOC_NORETRY	3	/* For jffs2_write_dnode: On failure, return -EAGAIN instead of retrying */
 
+#define JFFS2_RESERVED_BLOCKS_BASE 3						/* Number of free blocks there must be before we... */
+#define JFFS2_RESERVED_BLOCKS_WRITE (JFFS2_RESERVED_BLOCKS_BASE + 2)		/* ... allow a normal filesystem write */
+#define JFFS2_RESERVED_BLOCKS_DELETION (JFFS2_RESERVED_BLOCKS_BASE + 1)		/* ... allow a normal filesystem deletion */
+#define JFFS2_RESERVED_BLOCKS_GCTRIGGER (JFFS2_RESERVED_BLOCKS_BASE + 3)	/* ... wake up the GC thread */
+#define JFFS2_RESERVED_BLOCKS_GCBAD (JFFS2_RESERVED_BLOCKS_BASE + 1)		/* ... pick a block from the bad_list to GC */
+#define JFFS2_RESERVED_BLOCKS_GCMERGE (JFFS2_RESERVED_BLOCKS_BASE)		/* ... merge pages when garbage collecting */
+
 /* How much dirty space before it goes on the very_dirty_list */
 #define VERYDIRTY(c, size) ((size) >= ((c)->sector_size / 2))
 
Index: packages/io/fileio/current/include/fileio.h
===================================================================
RCS file: /var/work/cvs/ecos/packages/io/fileio/current/include/fileio.h,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 fileio.h
--- packages/io/fileio/current/include/fileio.h	6 Feb 2004 12:44:24 -0000	1.1.1.1
+++ packages/io/fileio/current/include/fileio.h	17 Jun 2004 08:22:16 -0000
@@ -154,6 +154,8 @@ struct cyg_fstab_entry
 #define FS_INFO_CONF            1       /* pathconf() */
 #define FS_INFO_ACCESS          2       /* access() */
 #define FS_INFO_GETCWD          3       /* getcwd() */
+#define FS_INFO_FREESIZE	4
+#define FS_INFO_USEDSIZE	5
 
 //-----------------------------------------------------------------------------
 // Types for link()