kernels/linux-2.4.0/drivers/acpi/driver.c
/*
 * Output important ACPI tables to proc
 */
Output important ACPI tables to proc
Output important ACPI tables to proc
static int 
acpi_do_table(ctl_table * ctl,
	      int write,
	      struct file *file,
	      void *buffer,
	      size_t * len)
{
	u32 table_type;
	size_t size;
	ACPI_BUFFER buf;
	u8* data;
	table_type = (u32) ctl->data;
	size = 0;
	buf.length = 0;
	buf.pointer = NULL;
	if (acpi_get_table(table_type, 1, &buf) != AE_BUFFER_OVERFLOW) {
		*len = 0;
		return 0;
	}
	buf.pointer = kmalloc(buf.length, GFP_KERNEL);
	if (!buf.pointer) {
		return -ENOMEM;
	}
	if (!ACPI_SUCCESS(acpi_get_table(table_type, 1, &buf))) {
		kfree(buf.pointer);
		*len = 0;
		return 0;
	}
	if (file->f_pos < buf.length) {
		data = buf.pointer + file->f_pos;
		size = buf.length - file->f_pos;
		if (size > *len)
			size = *len;
		if (copy_to_user(buffer, data, size))
			return -EFAULT;
	}
	kfree(buf.pointer);
	*len = size;
	file->f_pos += size;
	return 0;
}
static int acpi_do_table ( ctl_table * ctl , int write , struct file * file , void * buffer , size_t * len ) { u32 table_type ; size_t size ; ACPI_BUFFER buf ; u8 * data ; table_type = ( u32 ) ctl -> data ; size = 0 ; buf . length = 0 ; buf . pointer = NULL ; if ( acpi_get_table ( table_type , 1 , & buf ) != AE_BUFFER_OVERFLOW ) { * len = 0 ; return 0 ; } buf . pointer = kmalloc ( buf . length , GFP_KERNEL ) ; if ( ! buf . pointer ) { return - ENOMEM ; } if ( ! ACPI_SUCCESS ( acpi_get_table ( table_type , 1 , & buf ) ) ) { kfree ( buf . pointer ) ; * len = 0 ; return 0 ; } if ( file -> f_pos < buf . length ) { data = buf . pointer + file -> f_pos ; size = buf . length - file -> f_pos ; if ( size > * len ) size = * len ; if ( copy_to_user ( buffer , data , size ) ) return - EFAULT ; } kfree ( buf . pointer ) ; * len = size ; file -> f_pos += size ; return 0 ; }
Output important ACPI tables to proc
Output important ACPI tables to proc
/* determine what buffer size we will need */ /* get the table for real */