?? sysctl.c
字號:
if (!isspace(c)) break; left--; ((char *) buffer)++; } if (!left) break; neg = 0; len = left; if (len > TMPBUFLEN-1) len = TMPBUFLEN-1; if(copy_from_user(buf, buffer, len)) return -EFAULT; buf[len] = 0; p = buf; if (*p == '-' && left > 1) { neg = 1; left--, p++; } if (*p < '0' || *p > '9') break; val = simple_strtoul(p, &p, 0); len = p-buf; if ((len < left) && *p && !isspace(*p)) break; if (neg) val = -val; buffer += len; left -= len; if (min && val < *min++) continue; if (max && val > *max++) continue; *i = val; } else { p = buf; if (!first) *p++ = '\t'; sprintf(p, "%d", *i); len = strlen(buf); if (len > left) len = left; if(copy_to_user(buffer, buf, len)) return -EFAULT; left -= len; buffer += len; } } if (!write && !first && left) { if(put_user('\n', (char *) buffer)) return -EFAULT; left--, buffer++; } if (write) { p = (char *) buffer; while (left) { char c; if(get_user(c, p++)) return -EFAULT; if (!isspace(c)) break; left--; } } if (write && first) return -EINVAL; *lenp -= left; filp->f_pos += *lenp; return 0;}static int do_proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp, void *buffer, size_t *lenp, unsigned long convmul, unsigned long convdiv){#define TMPBUFLEN 20 unsigned long *i, *min, *max, val; int vleft, first=1, neg; size_t len, left; char buf[TMPBUFLEN], *p; if (!table->data || !table->maxlen || !*lenp || (filp->f_pos && !write)) { *lenp = 0; return 0; } i = (unsigned long *) table->data; min = (unsigned long *) table->extra1; max = (unsigned long *) table->extra2; vleft = table->maxlen / sizeof(unsigned long); left = *lenp; for (; left && vleft--; i++, first=0) { if (write) { while (left) { char c; if(get_user(c, (char *) buffer)) return -EFAULT; if (!isspace(c)) break; left--; ((char *) buffer)++; } if (!left) break; neg = 0; len = left; if (len > TMPBUFLEN-1) len = TMPBUFLEN-1; if(copy_from_user(buf, buffer, len)) return -EFAULT; buf[len] = 0; p = buf; if (*p == '-' && left > 1) { neg = 1; left--, p++; } if (*p < '0' || *p > '9') break; val = simple_strtoul(p, &p, 0) * convmul / convdiv ; len = p-buf; if ((len < left) && *p && !isspace(*p)) break; if (neg) val = -val; buffer += len; left -= len; if(neg) continue; if (min && val < *min++) continue; if (max && val > *max++) continue; *i = val; } else { p = buf; if (!first) *p++ = '\t'; sprintf(p, "%lu", convdiv * (*i) / convmul); len = strlen(buf); if (len > left) len = left; if(copy_to_user(buffer, buf, len)) return -EFAULT; left -= len; buffer += len; } } if (!write && !first && left) { if(put_user('\n', (char *) buffer)) return -EFAULT; left--, buffer++; } if (write) { p = (char *) buffer; while (left) { char c; if(get_user(c, p++)) return -EFAULT; if (!isspace(c)) break; left--; } } if (write && first) return -EINVAL; *lenp -= left; filp->f_pos += *lenp; return 0;#undef TMPBUFLEN}/** * 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 * * 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 *buffer, size_t *lenp){ return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, 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 * * 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 *buffer, size_t *lenp){ return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, HZ, 1000l);}/** * 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 * * 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 *buffer, size_t *lenp){ return do_proc_dointvec(table,write,filp,buffer,lenp,HZ,OP_SET);}#else /* CONFIG_PROC_FS */int proc_dostring(ctl_table *table, int write, struct file *filp, void *buffer, size_t *lenp){ return -ENOSYS;}static int proc_doutsstring(ctl_table *table, int write, struct file *filp, void *buffer, size_t *lenp){ return -ENOSYS;}int proc_dointvec(ctl_table *table, int write, struct file *filp, void *buffer, size_t *lenp){ return -ENOSYS;}int proc_dointvec_bset(ctl_table *table, int write, struct file *filp, void *buffer, size_t *lenp){ return -ENOSYS;}int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp, void *buffer, size_t *lenp){ return -ENOSYS;}int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp, void *buffer, size_t *lenp){ return -ENOSYS;}int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp, void *buffer, size_t *lenp){ return -ENOSYS;}int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write, struct file *filp, void *buffer, size_t *lenp){ return -ENOSYS;}#endif /* CONFIG_PROC_FS *//* * General sysctl support routines *//* The generic string strategy routine: */int sysctl_string(ctl_table *table, int *name, int nlen, void *oldval, size_t *oldlenp, void *newval, size_t newlen, void **context){ size_t l, len; if (!table->data || !table->maxlen) return -ENOTDIR; if (oldval && oldlenp) { if(get_user(len, oldlenp)) return -EFAULT; if (len) { l = strlen(table->data); if (len > l) len = l; if (len >= table->maxlen) len = table->maxlen; if(copy_to_user(oldval, table->data, len)) return -EFAULT; if(put_user(0, ((char *) oldval) + len)) return -EFAULT; if(put_user(len, oldlenp)) return -EFAULT; } } if (newval && newlen) { 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 0;}/* * 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 *name, int nlen, void *oldval, size_t *oldlenp, void *newval, size_t newlen, void **context){ int i, *vec, *min, *max; size_t length; if (newval && newlen) { 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); vec = (int *) newval; min = (int *) table->extra1; max = (int *) table->extra2; for (i = 0; i < length; i++) { int value; get_user(value, vec + i); 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 *name, int nlen, void *oldval, size_t *oldlenp, void *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 *)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 *)newval)) return -EFAULT; *(int *)(table->data) = new*HZ; } return 1;}#else /* CONFIG_SYSCTL */extern asmlinkage long sys_sysctl(struct __sysctl_args *args){ return -ENOSYS;}int sysctl_string(ctl_table *table, int *name, int nlen, void *oldval, size_t *oldlenp, void *newval, size_t newlen, void **context){ return -ENOSYS;}int sysctl_intvec(ctl_table *table, int *name, int nlen, void *oldval, size_t *oldlenp, void *newval, size_t newlen, void **context){ return -ENOSYS;}int sysctl_jiffies(ctl_table *table, int *name, int nlen, void *oldval, size_t *oldlenp, void *newval, size_t newlen, void **context){ return -ENOSYS;}int proc_dostring(ctl_table *table, int write, struct file *filp, void *buffer, size_t *lenp){ return -ENOSYS;}int proc_dointvec(ctl_table *table, int write, struct file *filp, void *buffer, size_t *lenp){ return -ENOSYS;}int proc_dointvec_bset(ctl_table *table, int write, struct file *filp, void *buffer, size_t *lenp){ return -ENOSYS;}int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp, void *buffer, size_t *lenp){ return -ENOSYS;}int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp, void *buffer, size_t *lenp){ return -ENOSYS;}int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp, void *buffer, size_t *lenp){ return -ENOSYS;}int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write, struct file *filp, void *buffer, size_t *lenp){ return -ENOSYS;}struct ctl_table_header * register_sysctl_table(ctl_table * table, int insert_at_head){ return 0;}void unregister_sysctl_table(struct ctl_table_header * table){}#endif /* CONFIG_SYSCTL */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -