This is the mail archive of the mailing list for the eCos project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: ftruncate function for eCos FAT filesystem


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).


Andrew Lunn wrote:

On Mon, Sep 05, 2005 at 03:21:03PM +0300, Gratian Crisan wrote:


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.


#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;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]