2519 lines · 58.8 KB · C
RawDownload
 * proc_doulongvec_minmax - read a vector of long integers with min/max values * @table: the sysctl table * @write: %TRUE if this is a write to the sysctl file * @filp: the file structure * @buffer: the user buffer * @lenp: the size of the user buffer * @ppos: file position * * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long * values from/to the user buffer, treated as an ASCII string. * * This routine will ensure the values are within the range specified by * table->extra1 (min) and table->extra2 (max). * * Returns 0 on success. */int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,			   void __user *buffer, size_t *lenp, loff_t *ppos){    return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);} /** * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values * @table: the sysctl table * @write: %TRUE if this is a write to the sysctl file * @filp: the file structure * @buffer: the user buffer * @lenp: the size of the user buffer * @ppos: file position * * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long * values from/to the user buffer, treated as an ASCII string. The values * are treated as milliseconds, and converted to jiffies when they are stored. * * This routine will ensure the values are within the range specified by * table->extra1 (min) and table->extra2 (max). * * Returns 0 on success. */int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,				      struct file *filp,				      void __user *buffer,				      size_t *lenp, loff_t *ppos){    return do_proc_doulongvec_minmax(table, write, filp, buffer,				     lenp, ppos, HZ, 1000l);}  static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,					 int *valp,					 int write, void *data){	if (write) {		if (*lvalp > LONG_MAX / HZ)			return 1;		*valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);	} else {		int val = *valp;		unsigned long lval;		if (val < 0) {			*negp = -1;			lval = (unsigned long)-val;		} else {			*negp = 0;			lval = (unsigned long)val;		}		*lvalp = lval / HZ;	}	return 0;} static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,						int *valp,						int write, void *data){	if (write) {		if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)			return 1;		*valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);	} else {		int val = *valp;		unsigned long lval;		if (val < 0) {			*negp = -1;			lval = (unsigned long)-val;		} else {			*negp = 0;			lval = (unsigned long)val;		}		*lvalp = jiffies_to_clock_t(lval);	}	return 0;} static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,					    int *valp,					    int write, void *data){	if (write) {		*valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);	} else {		int val = *valp;		unsigned long lval;		if (val < 0) {			*negp = -1;			lval = (unsigned long)-val;		} else {			*negp = 0;			lval = (unsigned long)val;		}		*lvalp = jiffies_to_msecs(lval);	}	return 0;} /** * proc_dointvec_jiffies - read a vector of integers as seconds * @table: the sysctl table * @write: %TRUE if this is a write to the sysctl file * @filp: the file structure * @buffer: the user buffer * @lenp: the size of the user buffer * @ppos: file position * * Reads/writes up to table->maxlen/sizeof(unsigned int) integer * values from/to the user buffer, treated as an ASCII string.  * The values read are assumed to be in seconds, and are converted into * jiffies. * * Returns 0 on success. */int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,			  void __user *buffer, size_t *lenp, loff_t *ppos){    return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,		    	    do_proc_dointvec_jiffies_conv,NULL);} /** * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds * @table: the sysctl table * @write: %TRUE if this is a write to the sysctl file * @filp: the file structure * @buffer: the user buffer * @lenp: the size of the user buffer * @ppos: pointer to the file position * * Reads/writes up to table->maxlen/sizeof(unsigned int) integer * values from/to the user buffer, treated as an ASCII string.  * The values read are assumed to be in 1/USER_HZ seconds, and  * are converted into jiffies. * * Returns 0 on success. */int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,				 void __user *buffer, size_t *lenp, loff_t *ppos){    return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,		    	    do_proc_dointvec_userhz_jiffies_conv,NULL);} /** * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds * @table: the sysctl table * @write: %TRUE if this is a write to the sysctl file * @filp: the file structure * @buffer: the user buffer * @lenp: the size of the user buffer * @ppos: file position * @ppos: the current position in the file * * Reads/writes up to table->maxlen/sizeof(unsigned int) integer * values from/to the user buffer, treated as an ASCII string.  * The values read are assumed to be in 1/1000 seconds, and  * are converted into jiffies. * * Returns 0 on success. */int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,			     void __user *buffer, size_t *lenp, loff_t *ppos){	return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,				do_proc_dointvec_ms_jiffies_conv, NULL);} #else /* CONFIG_PROC_FS */ int proc_dostring(ctl_table *table, int write, struct file *filp,		  void __user *buffer, size_t *lenp, loff_t *ppos){	return -ENOSYS;} static int proc_doutsstring(ctl_table *table, int write, struct file *filp,			    void __user *buffer, size_t *lenp, loff_t *ppos){	return -ENOSYS;} int proc_dointvec(ctl_table *table, int write, struct file *filp,		  void __user *buffer, size_t *lenp, loff_t *ppos){	return -ENOSYS;} int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,			void __user *buffer, size_t *lenp, loff_t *ppos){	return -ENOSYS;} int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,		    void __user *buffer, size_t *lenp, loff_t *ppos){	return -ENOSYS;} int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,		    void __user *buffer, size_t *lenp, loff_t *ppos){	return -ENOSYS;} int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,		    void __user *buffer, size_t *lenp, loff_t *ppos){	return -ENOSYS;} int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,			     void __user *buffer, size_t *lenp, loff_t *ppos){	return -ENOSYS;} int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,		    void __user *buffer, size_t *lenp, loff_t *ppos){	return -ENOSYS;} int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,				      struct file *filp,				      void __user *buffer,				      size_t *lenp, loff_t *ppos){    return -ENOSYS;}  #endif /* CONFIG_PROC_FS */  /* * General sysctl support routines  */ /* The generic string strategy routine: */int sysctl_string(ctl_table *table, int __user *name, int nlen,		  void __user *oldval, size_t __user *oldlenp,		  void __user *newval, size_t newlen, void **context){	if (!table->data || !table->maxlen) 		return -ENOTDIR;		if (oldval && oldlenp) {		size_t bufsize;		if (get_user(bufsize, oldlenp))			return -EFAULT;		if (bufsize) {			size_t len = strlen(table->data), copied; 			/* This shouldn't trigger for a well-formed sysctl */			if (len > table->maxlen)				len = table->maxlen; 			/* Copy up to a max of bufsize-1 bytes of the string */			copied = (len >= bufsize) ? bufsize - 1 : len; 			if (copy_to_user(oldval, table->data, copied) ||			    put_user(0, (char __user *)(oldval + copied)))				return -EFAULT;			if (put_user(len, oldlenp))				return -EFAULT;		}	}	if (newval && newlen) {		size_t len = newlen;		if (len > table->maxlen)			len = table->maxlen;		if(copy_from_user(table->data, newval, len))			return -EFAULT;		if (len == table->maxlen)			len--;		((char *) table->data)[len] = 0;	}	return 1;} /* * This function makes sure that all of the integers in the vector * are between the minimum and maximum values given in the arrays * table->extra1 and table->extra2, respectively. */int sysctl_intvec(ctl_table *table, int __user *name, int nlen,		void __user *oldval, size_t __user *oldlenp,		void __user *newval, size_t newlen, void **context){ 	if (newval && newlen) {		int __user *vec = (int __user *) newval;		int *min = (int *) table->extra1;		int *max = (int *) table->extra2;		size_t length;		int i; 		if (newlen % sizeof(int) != 0)			return -EINVAL; 		if (!table->extra1 && !table->extra2)			return 0; 		if (newlen > table->maxlen)			newlen = table->maxlen;		length = newlen / sizeof(int); 		for (i = 0; i < length; i++) {			int value;			if (get_user(value, vec + i))				return -EFAULT;			if (min && value < min[i])				return -EINVAL;			if (max && value > max[i])				return -EINVAL;		}	}	return 0;} /* Strategy function to convert jiffies to seconds */ int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,		void __user *oldval, size_t __user *oldlenp,		void __user *newval, size_t newlen, void **context){	if (oldval) {		size_t olen;		if (oldlenp) { 			if (get_user(olen, oldlenp))				return -EFAULT;			if (olen!=sizeof(int))				return -EINVAL; 		}		if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||		    (oldlenp && put_user(sizeof(int),oldlenp)))			return -EFAULT;	}	if (newval && newlen) { 		int new;		if (newlen != sizeof(int))			return -EINVAL; 		if (get_user(new, (int __user *)newval))			return -EFAULT;		*(int *)(table->data) = new*HZ; 	}	return 1;} /* Strategy function to convert jiffies to seconds */ int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,		void __user *oldval, size_t __user *oldlenp,		void __user *newval, size_t newlen, void **context){	if (oldval) {		size_t olen;		if (oldlenp) { 			if (get_user(olen, oldlenp))				return -EFAULT;			if (olen!=sizeof(int))				return -EINVAL; 		}		if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||		    (oldlenp && put_user(sizeof(int),oldlenp)))			return -EFAULT;	}	if (newval && newlen) { 		int new;		if (newlen != sizeof(int))			return -EINVAL; 		if (get_user(new, (int __user *)newval))			return -EFAULT;		*(int *)(table->data) = msecs_to_jiffies(new);	}	return 1;} #else /* CONFIG_SYSCTL */  asmlinkage long sys_sysctl(struct __sysctl_args __user *args){	return -ENOSYS;} int sysctl_string(ctl_table *table, int __user *name, int nlen,		  void __user *oldval, size_t __user *oldlenp,		  void __user *newval, size_t newlen, void **context){	return -ENOSYS;} int sysctl_intvec(ctl_table *table, int __user *name, int nlen,		void __user *oldval, size_t __user *oldlenp,		void __user *newval, size_t newlen, void **context){	return -ENOSYS;} int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,		void __user *oldval, size_t __user *oldlenp,		void __user *newval, size_t newlen, void **context){	return -ENOSYS;} int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,		void __user *oldval, size_t __user *oldlenp,		void __user *newval, size_t newlen, void **context){	return -ENOSYS;} int proc_dostring(ctl_table *table, int write, struct file *filp,		  void __user *buffer, size_t *lenp, loff_t *ppos){	return -ENOSYS;} int proc_dointvec(ctl_table *table, int write, struct file *filp,		  void __user *buffer, size_t *lenp, loff_t *ppos){	return -ENOSYS;} int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,			void __user *buffer, size_t *lenp, loff_t *ppos){	return -ENOSYS;} int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,		    void __user *buffer, size_t *lenp, loff_t *ppos){	return -ENOSYS;} int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,			  void __user *buffer, size_t *lenp, loff_t *ppos){	return -ENOSYS;} int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,			  void __user *buffer, size_t *lenp, loff_t *ppos){	return -ENOSYS;} int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,			     void __user *buffer, size_t *lenp, loff_t *ppos){	return -ENOSYS;} int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,		    void __user *buffer, size_t *lenp, loff_t *ppos){	return -ENOSYS;} int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,				      struct file *filp,				      void __user *buffer,				      size_t *lenp, loff_t *ppos){    return -ENOSYS;} struct ctl_table_header * register_sysctl_table(ctl_table * table, 						int insert_at_head){	return NULL;} void unregister_sysctl_table(struct ctl_table_header * table){} #endif /* CONFIG_SYSCTL */

Lines 2001–2500 of 2519. Previous lines