This is the mail archive of the
ecos-patches@sources.redhat.com
mailing list for the eCos project.
Re: [ECOS] Filesystem get/setinfo
- From: Savin Zlobec <savin at elatec dot si>
- To: Nick Garnett <nickg at ecoscentric dot com>
- Cc: ecos-patches at sources dot redhat dot com
- Date: Thu, 23 Oct 2003 14:38:44 +0200
- Subject: Re: [ECOS] Filesystem get/setinfo
- References: <3F93D904.7090204@elatec.si> <m3fzho3qj3.fsf@miso.calivar.com> <20031020182517.3DFE08BA45@www.email.si> <m3y8vd39f6.fsf@miso.calivar.com>
Nick Garnett wrote:
Savin Zlobec <savin.zlobec@email.si> writes:
On Mon, 20 Oct 2003 at 19:07:19, Nick Garnett wrote:
Savin Zlobec <savin@elatec.si> writes:
I need to write some filesystem specific functions.
The get/setinfo calls seem to be the right way to do this,
but I can't find any functions to access them from my application.
The following functions would do the trick for me:
int cyg_fs_getinfo(const char *path, int key, void *buf, int len);
int cyg_fs_setinfo(const char *path, int key, void *buf, int len);
int cyg_fs_fgetinfo(int fd, int key, void *buf, int len);
int cyg_fs_fsetinfo(int fd, int key, void *buf. int len);
Or is there any way to do this already without accessing internal
structures?
For filesystems you should be using ioctl() for these sorts of
out-of-band control operations. That's what it's there for, and more
than likely there is already a code defined for what you want to do.
I could work with ioctl, but if the desired operation is filesystem
oriented (as opposed to file oriented), then I would need to open a
file just to get a file descriptor for use with ioctl.
What do you need these functions for?
Currently I need fs info like total/free/used sectors count,
status flags (if it was cleanly unmounted and if there were any IO errors).
Later I may need some sort of special access to reserved sectors...
I see. Like mount()/umount() POSIX has not defined interface for these
sorts of things. Given that, then the functions you propose are
probably a worthwhile addition.
If you would like to submit a patch I'm sure that it will be accepted.
Here it is
Index: io/fileio/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/io/fileio/current/ChangeLog,v
retrieving revision 1.34
diff -u -5 -r1.34 ChangeLog
--- io/fileio/current/ChangeLog 16 Oct 2003 07:55:31 -0000 1.34
+++ io/fileio/current/ChangeLog 23 Oct 2003 11:09:30 -0000
@@ -1,5 +1,12 @@
+2003-10-23 Savin Zlobec <savin@elatec.si>
+
+ * src/io.cxx: Added cyg_fs_fsetinfo and cyg_fs_fgetinfo functions.
+ * src/file.cxx: Added cyg_fs_setinfo and cyg_fs_getinfo functions.
+ * include/fileio.h: Added cyg_fs_fsetinfo, cyg_fs_fgetinfo,
+ cyg_fs_setinfo and cyg_fs_getinfo function prototypes.
+
2003-10-16 Andrew Lunn <andrew.lunn@ascom.ch>
* src/socket.cxx (bind): Pass a copy of the socket address so the
stack can modify it without changing the users copy. Bug found by
reji@codito.com.
Index: io/fileio/current/include/fileio.h
===================================================================
RCS file: /cvs/ecos/ecos/packages/io/fileio/current/include/fileio.h,v
retrieving revision 1.8
diff -u -5 -r1.8 fileio.h
--- io/fileio/current/include/fileio.h 6 Oct 2003 18:45:22 -0000 1.8
+++ io/fileio/current/include/fileio.h 23 Oct 2003 11:09:30 -0000
@@ -378,10 +378,18 @@
const char *fsname);
__externC int umount( const char *name);
//=============================================================================
+// Get/Set info functions
+
+__externC int cyg_fs_getinfo( const char *path, int key, void *buf, int len );
+__externC int cyg_fs_setinfo( const char *path, int key, void *buf, int len );
+__externC int cyg_fs_fgetinfo( int fd, int key, void *buf, int len );
+__externC int cyg_fs_fsetinfo( int fd, int key, void *buf, int len );
+
+//=============================================================================
// Select support
//-----------------------------------------------------------------------------
// Data structure for embedding in client data structures. A pointer to this
// must be passed to cyg_selrecord() and cyg_selwakeup().
Index: io/fileio/current/src/file.cxx
===================================================================
RCS file: /cvs/ecos/ecos/packages/io/fileio/current/src/file.cxx,v
retrieving revision 1.8
diff -u -5 -r1.8 file.cxx
--- io/fileio/current/src/file.cxx 11 Apr 2003 02:06:11 -0000 1.8
+++ io/fileio/current/src/file.cxx 23 Oct 2003 11:09:31 -0000
@@ -754,7 +754,59 @@
#endif
FILEIO_RETURN_VALUE(buf);
}
+//==========================================================================
+// FS get info.
+
+__externC int cyg_fs_getinfo( const char *path, int key, void *buf, int len )
+{
+ FILEIO_ENTRY();
+
+ int ret = 0;
+ cyg_mtab_entry *mte = cyg_cdir_mtab_entry;
+ cyg_dir dir = cyg_cdir_dir;
+ const char *name = path;
+
+ ret = cyg_mtab_lookup( &dir, &name, &mte );
+
+ if( 0 != ret )
+ FILEIO_RETURN(ENOENT);
+
+ LOCK_FS( mte );
+
+ ret = mte->fs->getinfo( mte, dir, name, key, buf, len );
+
+ UNLOCK_FS( mte );
+
+ FILEIO_RETURN(ret);
+}
+
+//==========================================================================
+// FS set info.
+
+__externC int cyg_fs_setinfo( const char *path, int key, void *buf, int len )
+{
+ FILEIO_ENTRY();
+
+ int ret = 0;
+ cyg_mtab_entry *mte = cyg_cdir_mtab_entry;
+ cyg_dir dir = cyg_cdir_dir;
+ const char *name = path;
+
+ ret = cyg_mtab_lookup( &dir, &name, &mte );
+
+ if( 0 != ret )
+ FILEIO_RETURN(ENOENT);
+
+ LOCK_FS( mte );
+
+ ret = mte->fs->setinfo( mte, dir, name, key, buf, len );
+
+ UNLOCK_FS( mte );
+
+ FILEIO_RETURN(ret);
+}
+
// -------------------------------------------------------------------------
// EOF file.cxx
Index: io/fileio/current/src/io.cxx
===================================================================
RCS file: /cvs/ecos/ecos/packages/io/fileio/current/src/io.cxx,v
retrieving revision 1.7
diff -u -5 -r1.7 io.cxx
--- io/fileio/current/src/io.cxx 3 Nov 2002 19:49:24 -0000 1.7
+++ io/fileio/current/src/io.cxx 23 Oct 2003 11:09:31 -0000
@@ -478,7 +478,59 @@
ret = 1;
FILEIO_RETURN_VALUE(ret);
}
+//==========================================================================
+// File get info.
+
+__externC int cyg_fs_fgetinfo( int fd, int key, void *buf, int len )
+{
+ FILEIO_ENTRY();
+
+ int ret;
+ cyg_file *fp;
+
+ fp = cyg_fp_get( fd );
+
+ if( fp == NULL )
+ FILEIO_RETURN(EBADF);
+
+ LOCK_FILE( fp );
+
+ ret = fp->f_ops->fo_getinfo( fp, key, buf, len );
+
+ UNLOCK_FILE( fp );
+
+ cyg_fp_free( fp );
+
+ FILEIO_RETURN(ret);
+}
+
+//==========================================================================
+// File set info.
+
+__externC int cyg_fs_fsetinfo( int fd, int key, void *buf, int len )
+{
+ FILEIO_ENTRY();
+
+ int ret;
+ cyg_file *fp;
+
+ fp = cyg_fp_get( fd );
+
+ if( fp == NULL )
+ FILEIO_RETURN(EBADF);
+
+ LOCK_FILE( fp );
+
+ ret = fp->f_ops->fo_setinfo( fp, key, buf, len );
+
+ UNLOCK_FILE( fp );
+
+ cyg_fp_free( fp );
+
+ FILEIO_RETURN(ret);
+}
+
// -------------------------------------------------------------------------
// EOF io.cxx