This is the mail archive of the
ecos-patches@sourceware.org
mailing list for the eCos project.
Re: ftruncate function for eCos FAT filesystem
- From: Gratian Crisan <nelu at iv dot ro>
- To: Andrew Lunn <andrew at lunn dot ch>
- Cc: ecos-patches at ecos dot sourceware dot org
- Date: Mon, 19 Sep 2005 10:47:19 +0300
- Subject: Re: ftruncate function for eCos FAT filesystem
- References: <431C382F.7060404@iv.ro> <20050916154049.GM16074@lunn.ch>
Hi,
Indeed the support for truncate is missing from POSIX layer so right now
I'm calling it directly from a truncate function I've wrote but is
rather hack'is (see the attached file).
-Nelu
Andrew Lunn wrote:
On Mon, Sep 05, 2005 at 03:21:03PM +0300, Gratian Crisan wrote:
Hi,
attached is a patch for a ftruncate function implementation for the eCos
FAT filesystem. If it's useful to anybody please feel free to use it.
How do you call this function? There does not appear to be any support
for ftruncate() or truncate() in the layers above the filesystem.
Thanks
Andrew
#include <cyg/infra/cyg_type.h>
#include <stddef.h> // NULL, size_t
#include <unistd.h>
#include <limits.h>
#include <sys/types.h>
#include <errno.h>
#include <cyg/fileio/fileio.h>
__externC cyg_file *cyg_fp_get( int fd );
__externC void cyg_fp_free( cyg_file *fp );
__externC void cyg_file_lock( cyg_file *fp, cyg_uint32 syncmode );
__externC void cyg_file_unlock( cyg_file *fp, cyg_uint32 syncmode );
int fatfs_fo_ftruncate(struct CYG_FILE_TAG *fp, off_t length);
int ftruncate(int fd, off_t length)
{
cyg_file *fp;
fp = cyg_fp_get(fd);
if( fp == NULL ) {
errno = EBADF;
return -1;
}
cyg_file_lock(fp, fp->f_syncmode);
errno = fatfs_fo_ftruncate(fp, length);
cyg_file_unlock(fp, fp->f_syncmode);
cyg_fp_free( fp );
if (ENOERR == errno) {
return 0;
} else {
return -1;
}
}