This is the mail archive of the
ecos-patches@sources.redhat.com
mailing list for the eCos project.
fatfs and io disk misc patches
- From: Savin Zlobec <savin at elatec dot si>
- To: ecos-patches at sources dot redhat dot com
- Date: Thu, 24 Jun 2004 11:14:11 +0200
- Subject: fatfs and io disk misc patches
Hi,
a patch for disk.c which replaces malloc with predefined arrays
and a new fatfs function fatfs_get_disk_usage which can be used
by getinfo interface once the proper keys are defined.
savin
Index: devs/disk/synth/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/devs/disk/synth/current/ChangeLog,v
retrieving revision 1.1
diff -u -w -r1.1 ChangeLog
--- devs/disk/synth/current/ChangeLog 19 Jan 2004 14:35:01 -0000 1.1
+++ devs/disk/synth/current/ChangeLog 24 Jun 2004 08:38:43 -0000
@@ -1,3 +1,9 @@
+2004-06-24 Savin Zlobec <savin@elatec.si>
+
+ * src/synthdisk.c:
+ Removed static keyword before DISK_CHANNEL macro (which
+ has changed).
+
2004-01-15 Nick Garnett <nickg@calivar.com>
* cdl/synthdisk.cdl:
Index: devs/disk/synth/current/src/synthdisk.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/devs/disk/synth/current/src/synthdisk.c,v
retrieving revision 1.1
diff -u -w -r1.1 synthdisk.c
--- devs/disk/synth/current/src/synthdisk.c 19 Jan 2004 14:35:01 -0000 1.1
+++ devs/disk/synth/current/src/synthdisk.c 24 Jun 2004 08:38:44 -0000
@@ -123,7 +123,7 @@
filefd: -1, \
filename: CYGDAT_IO_DISK_ECOSYNTH_DISK##_number_##_FILENAME \
}; \
-static DISK_CHANNEL(synth_disk_channel##_number_, \
+DISK_CHANNEL(synth_disk_channel##_number_, \
synth_disk_funs, \
synth_disk_info##_number_, \
_mbr_supp_ \
Index: io/disk/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/io/disk/current/ChangeLog,v
retrieving revision 1.1
diff -u -w -r1.1 ChangeLog
--- io/disk/current/ChangeLog 19 Jan 2004 14:35:02 -0000 1.1
+++ io/disk/current/ChangeLog 24 Jun 2004 08:38:57 -0000
@@ -1,3 +1,11 @@
+2004-06-24 Savin Zlobec <savin@elatec.si>
+
+ * src/disk.c:
+ * include/disk.h:
+ * include/diskio.h:
+ Use predefined arrays for partition devices and info
+ radher than malloc.
+
2004-01-15 Nick Garnett <nickg@calivar.com>
* src/disk.c:
Index: io/disk/current/include/disk.h
===================================================================
RCS file: /cvs/ecos/ecos/packages/io/disk/current/include/disk.h,v
retrieving revision 1.1
diff -u -w -r1.1 disk.h
--- io/disk/current/include/disk.h 19 Jan 2004 14:35:03 -0000 1.1
+++ io/disk/current/include/disk.h 24 Jun 2004 08:38:57 -0000
@@ -106,6 +106,8 @@
void *dev_priv; // device private data
cyg_disk_info_t *info; // disk info
cyg_disk_partition_t *partition; // partition data
+ struct cyg_devtab_entry *pdevs_dev; // partition devs devtab ents
+ disk_channel *pdevs_chan; // partition devs disk chans
cyg_bool mbr_support; // true if disk has MBR
cyg_bool valid; // true if device valid
cyg_bool init; // true if initialized
@@ -116,13 +118,17 @@
_funs, \
_dev_priv, \
_mbr_supp) \
-cyg_disk_info_t _l##_disk_info; \
-disk_channel _l = { \
+static struct cyg_devtab_entry _l##_part_dev[CYG_DISK_MAX_PART_NUM]; \
+static disk_channel _l##_part_chan[CYG_DISK_MAX_PART_NUM]; \
+static cyg_disk_info_t _l##_disk_info; \
+static disk_channel _l = { \
&(_funs), \
&cyg_io_disk_callbacks, \
&(_dev_priv), \
&(_l##_disk_info), \
NULL, \
+ _l##_part_dev, \
+ _l##_part_chan, \
_mbr_supp, \
false, \
false \
Index: io/disk/current/include/diskio.h
===================================================================
RCS file: /cvs/ecos/ecos/packages/io/disk/current/include/diskio.h,v
retrieving revision 1.1
diff -u -w -r1.1 diskio.h
--- io/disk/current/include/diskio.h 19 Jan 2004 14:35:03 -0000 1.1
+++ io/disk/current/include/diskio.h 24 Jun 2004 08:38:57 -0000
@@ -59,6 +59,8 @@
extern "C" {
#endif
+#define CYG_DISK_MAX_PART_NUM 4
+
typedef struct {
char serial[20+1]; // serial number
char firmware_rev[8+1]; // firmware revision
@@ -79,8 +81,7 @@
typedef struct {
cyg_disk_identify_t ident; // identify data
- cyg_disk_partition_t partitions[4]; // partitions
- cyg_addrword_t devs[4]; // device instances
+ cyg_disk_partition_t partitions[CYG_DISK_MAX_PART_NUM]; // partitions
cyg_uint32 block_size; // block size
cyg_uint32 blocks_num; // number of blocks on disk
cyg_bool connected; // true if device connected
Index: io/disk/current/src/disk.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/io/disk/current/src/disk.c,v
retrieving revision 1.1
diff -u -w -r1.1 disk.c
--- io/disk/current/src/disk.c 19 Jan 2004 14:35:03 -0000 1.1
+++ io/disk/current/src/disk.c 24 Jun 2004 08:38:58 -0000
@@ -56,8 +56,6 @@
#include <cyg/infra/cyg_ass.h> // assertion support
#include <cyg/infra/diag.h> // diagnostic output
-#include <stdlib.h> // malloc
-
// ---------------------------------------------------------------------------
//#define DEBUG 1
@@ -231,13 +229,9 @@
{
info->connected = false;
- // clear devices array (one per partition)
- // and partition data
- for (i = 0; i < MBR_PART_NUM; i++)
- {
- info->devs[i] = (cyg_addrword_t) 0;
+ // clear partition data
+ for (i = 0; i < CYG_DISK_MAX_PART_NUM; i++)
info->partitions[i].type = 0x00;
- }
chan->init = true;
}
@@ -294,22 +288,11 @@
info->connected = false;
chan->valid = false;
- // clear partition data and invalidate
- // any allocated devices
- for (i = 0; i < MBR_PART_NUM; i++)
+ // clear partition data and invalidate partition devices
+ for (i = 0; i < CYG_DISK_MAX_PART_NUM; i++)
{
info->partitions[i].type = 0x00;
-
- if (0 != info->devs[i])
- {
- struct cyg_devtab_entry *dtab;
- disk_channel *dchan;
-
- dtab = (struct cyg_devtab_entry *)info->devs[i];
- dchan = (disk_channel *) dtab->priv;
-
- dchan->valid = false;
- }
+ chan->pdevs_chan[i].valid = false;
}
@@ -347,29 +330,8 @@
return -EINVAL;
}
- if (0 == info->devs[dev_num-1])
- {
- D(("disk creating new devtab entry\n"));
-
- // alloc mem for new device
- new_tab = (struct cyg_devtab_entry *)
- malloc(sizeof(struct cyg_devtab_entry));
- if (NULL == new_tab)
- return -ENOMEM;
-
- // alloc mem for new device private data
- new_chan = (disk_channel *)malloc(sizeof(disk_channel));
- if (NULL == new_chan)
- {
- free(new_tab);
- return -ENOMEM;
- }
- }
- else
- {
- new_tab = (struct cyg_devtab_entry *) info->devs[dev_num-1];
- new_chan = (disk_channel *) new_tab->priv;
- }
+ new_tab = &chan->pdevs_dev[dev_num-1];
+ new_chan = &chan->pdevs_chan[dev_num-1];
// copy device data from parent
*new_tab = **tab;
@@ -377,9 +339,8 @@
new_tab->priv = (void *)new_chan;
- // set partition ptr and put this device into devices array
+ // set partition ptr
new_chan->partition = &info->partitions[dev_num-1];
- chan->info->devs[dev_num-1] = (cyg_addrword_t) new_tab;
// return device tab
*tab = new_tab;
Index: fs/fat/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/fs/fat/current/ChangeLog,v
retrieving revision 1.1
diff -u -w -r1.1 ChangeLog
--- fs/fat/current/ChangeLog 19 Jan 2004 14:35:02 -0000 1.1
+++ fs/fat/current/ChangeLog 24 Jun 2004 08:55:25 -0000
@@ -1,3 +1,10 @@
+2003-06-24 Savin Zlobec <savin@elatec.si>
+
+ * src/fatfs.h:
+ * src/fatfs_supp.c:
+ Implemented fatfs_get_disk_usage function for
+ getting the number of total and free clusters.
+
2004-01-19 Nick Garnett <nickg@calivar.com>
Index: fs/fat/current/src/fatfs.h
===================================================================
RCS file: /cvs/ecos/ecos/packages/fs/fat/current/src/fatfs.h,v
retrieving revision 1.1
diff -u -w -r1.1 fatfs.h
--- fs/fat/current/src/fatfs.h 19 Jan 2004 14:35:02 -0000 1.1
+++ fs/fat/current/src/fatfs.h 24 Jun 2004 08:55:27 -0000
@@ -197,6 +197,10 @@
int fatfs_get_disk_info(fatfs_disk_t *disk);
+int fatfs_get_disk_usage(fatfs_disk_t *disk,
+ cyg_uint32 *total_clu,
+ cyg_uint32 *free_clu);
+
void fatfs_get_root_node(fatfs_disk_t *disk, fatfs_node_t *root);
bool fatfs_is_node_root_node(fatfs_node_t *node);
Index: fs/fat/current/src/fatfs_supp.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/fs/fat/current/src/fatfs_supp.c,v
retrieving revision 1.1
diff -u -w -r1.1 fatfs_supp.c
--- fs/fat/current/src/fatfs_supp.c 19 Jan 2004 14:35:02 -0000 1.1
+++ fs/fat/current/src/fatfs_supp.c 24 Jun 2004 08:55:33 -0000
@@ -1826,6 +1826,35 @@
}
// -------------------------------------------------------------------------
+// fatfs_get_disk_usage()
+// Gets disk space.
+
+int
+fatfs_get_disk_usage(fatfs_disk_t *disk,
+ cyg_uint32 *total_clu,
+ cyg_uint32 *free_clu)
+{
+ cyg_uint32 c, nfree, tentry;
+ int err;
+
+ nfree = 0;
+ for (c = 2; c < disk->fat_tbl_nents; c++)
+ {
+ err = read_tentry(disk, c, &tentry);
+ if (err != ENOERR)
+ return err;
+
+ if (TENTRY_FREE == get_tentry_type(disk, tentry))
+ nfree++;
+ }
+
+ *total_clu = disk->fat_tbl_nents - 2;
+ *free_clu = nfree;
+
+ return ENOERR;
+}
+
+// -------------------------------------------------------------------------
// is_node_root_node()
// Check if the given node is the root dir node