Linux Sound subsystem development
 help / color / mirror / Atom feed
* Illegal seek using file_operations write command from kernel
@ 2003-03-21 18:37 Jim Deas
  0 siblings, 0 replies; only message in thread
From: Jim Deas @ 2003-03-21 18:37 UTC (permalink / raw)
  To: linux-sound

I am having trouble linking my driver
to the sound subsystem. I can open the file
correctly but have trouble writing to it.
The open and close sections seem to work
including a test seek command in the open area.
The writeAudioFrame always returns an illegal
seek (-29).

Here is the code:
----------------------------------------------------------------
int OpenAudioDevice(char* AudioDev){

 int speed,format;

//-------------------Open Audio Device ----------------
// if((audio_fd = open(AudioDev, O_WRONLY, 0)) = -1){
//	 printk("ltc -> Error Opening audio Device.\n");
//	 return -1;
// }
	pbuffer = kmalloc(BUF_SIZE,GFP_KERNEL);//Create audio buffer
	fs = get_fs();
	set_fs(KERNEL_DS);//Setup for user space commands

	fd = filp_open(AudioDev, O_WRONLY, 0);
	if(IS_ERR(fd)){
		printk("Failed to open %s.\n",AudioDev);
		return -1;
	}
	if(fd->f_op->llseek(fd,0,SEEK_SET) < 0){
		printk("ltc -> Error seeking to zero.\n");
		filp_close(fd,NULL);
		return -1;
	}
//------------------ Set Number of Channels ---------
--snip
//------------------- Set Data format -----------------
--snip
//------------------Set Sample rate --------------------
--snip
//-----------------------------------------------------------------------
void closeAudioDevice(void){
	fs = get_fs();
	set_fs(KERNEL_DS);//Setup for user space commands
	filp_close(fd,NULL);//Close the file
	fd = NULL;
	set_fs(fs);//Return to kernel space before exit!
	kfree(pbuffer);//return audio buffer
}
//-------------------------------------------------------------------------
int writeAudioFrame(long tc){
int wret;
loff_t pos = 0;

	buildFrameBuffer(&tc,pbuffer);//Creates a waveform size of BUF_SIZE
	fs = get_fs();
	set_fs(KERNEL_DS);//Setup for user space commands
	if(fd){
		if((wret = fd->f_op->write(fd,pbuffer, BUF_SIZE,fd->f_pos)) !BUF_SIZE){
			printk("ltc -> Error writing data to audio device sent %i got
%i.\n",BUF_SIZE,wret);
			return -1;
		}
	}
	set_fs(fs);//Return to kernel space before exit!
	return 1;
}



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-03-21 18:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-03-21 18:37 Illegal seek using file_operations write command from kernel Jim Deas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox