Appending functionality in Character Device Driver

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I want to provide a appending functionality in a
character device driver and I have done the following
thing in a device_open function.

if (pfile->f_flags & O_APPEND)
{
	// Opening a device file in Append Mode.
	printk("<1> Append Flag has been Used\n");
		pfile->f_pos = pdevice_data->size;
}
else if ((pfile->f_flags & O_ACCMODE) == O_WRONLY)
{
       // Opening a device file in Write Mode
	if (pdevice_data->data)
	{
		kfree(pdevice_data->data);
		pdevice_data->data = NULL;
		pdevice_data->size = 0;
	}
}
 
In this , pdevice_data is a pointer to Device_Data
structure which is defined as follows:

typedef struct Device_Data {

	void * data;
        unsigned long size;
	unsigned long max_size;
	}Device_Data;

Is my approach fine and is it fine If I modify on my
own pfile->f_pos in the device_open ?

Is there any way by which Kernel takes cares of this
on its own and set the file position at the end of the
file when I use the following commmand

cat >> /dev/CharDev0


Regards
Dinesh



________________________________________________________________________
Yahoo! India Matrimony: Find your life partner online
Go to: http://yahoo.shaadi.com/india-matrimony

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux