sysctl.c (7ae9fb1b7ecbb5d85d07857943f677fd1a559b18) | sysctl.c (f1aa2eb5ea05ccd1fd92d235346e60e90a1ed949) |
---|---|
1// SPDX-License-Identifier: GPL-2.0-only 2/* 3 * sysctl.c: General linux system control interface 4 * 5 * Begun 24 March 1995, Stephen Tweedie 6 * Added /proc support, Dec 1995 7 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas. 8 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver. --- 411 unchanged lines hidden (view full) --- 420 **buffer = c; 421 422 (*size)--; 423 (*buffer)++; 424 *buf = *buffer; 425 } 426} 427 | 1// SPDX-License-Identifier: GPL-2.0-only 2/* 3 * sysctl.c: General linux system control interface 4 * 5 * Begun 24 March 1995, Stephen Tweedie 6 * Added /proc support, Dec 1995 7 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas. 8 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver. --- 411 unchanged lines hidden (view full) --- 420 **buffer = c; 421 422 (*size)--; 423 (*buffer)++; 424 *buf = *buffer; 425 } 426} 427 |
428static int do_proc_dobool_conv(bool *negp, unsigned long *lvalp, 429 int *valp, 430 int write, void *data) 431{ 432 if (write) { 433 *(bool *)valp = *lvalp; 434 } else { 435 int val = *(bool *)valp; 436 437 *lvalp = (unsigned long)val; 438 *negp = false; 439 } 440 return 0; 441} 442 | |
443static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp, 444 int *valp, 445 int write, void *data) 446{ 447 if (write) { 448 if (*negp) { 449 if (*lvalp > (unsigned long) INT_MAX + 1) 450 return -EINVAL; --- 254 unchanged lines hidden (view full) --- 705/** 706 * proc_dobool - read/write a bool 707 * @table: the sysctl table 708 * @write: %TRUE if this is a write to the sysctl file 709 * @buffer: the user buffer 710 * @lenp: the size of the user buffer 711 * @ppos: file position 712 * | 428static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp, 429 int *valp, 430 int write, void *data) 431{ 432 if (write) { 433 if (*negp) { 434 if (*lvalp > (unsigned long) INT_MAX + 1) 435 return -EINVAL; --- 254 unchanged lines hidden (view full) --- 690/** 691 * proc_dobool - read/write a bool 692 * @table: the sysctl table 693 * @write: %TRUE if this is a write to the sysctl file 694 * @buffer: the user buffer 695 * @lenp: the size of the user buffer 696 * @ppos: file position 697 * |
713 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 714 * values from/to the user buffer, treated as an ASCII string. | 698 * Reads/writes one integer value from/to the user buffer, 699 * treated as an ASCII string. |
715 * | 700 * |
701 * table->data must point to a bool variable and table->maxlen must 702 * be sizeof(bool). 703 * |
|
716 * Returns 0 on success. 717 */ 718int proc_dobool(struct ctl_table *table, int write, void *buffer, 719 size_t *lenp, loff_t *ppos) 720{ | 704 * Returns 0 on success. 705 */ 706int proc_dobool(struct ctl_table *table, int write, void *buffer, 707 size_t *lenp, loff_t *ppos) 708{ |
721 return do_proc_dointvec(table, write, buffer, lenp, ppos, 722 do_proc_dobool_conv, NULL); | 709 struct ctl_table tmp; 710 bool *data = table->data; 711 int res, val; 712 713 /* Do not support arrays yet. */ 714 if (table->maxlen != sizeof(bool)) 715 return -EINVAL; 716 717 tmp = *table; 718 tmp.maxlen = sizeof(val); 719 tmp.data = &val; 720 721 val = READ_ONCE(*data); 722 res = proc_dointvec(&tmp, write, buffer, lenp, ppos); 723 if (res) 724 return res; 725 if (write) 726 WRITE_ONCE(*data, val); 727 return 0; |
723} 724 725/** 726 * proc_dointvec - read a vector of integers 727 * @table: the sysctl table 728 * @write: %TRUE if this is a write to the sysctl file 729 * @buffer: the user buffer 730 * @lenp: the size of the user buffer --- 1768 unchanged lines hidden --- | 728} 729 730/** 731 * proc_dointvec - read a vector of integers 732 * @table: the sysctl table 733 * @write: %TRUE if this is a write to the sysctl file 734 * @buffer: the user buffer 735 * @lenp: the size of the user buffer --- 1768 unchanged lines hidden --- |