pipe: make F_{GET,SET}PIPE_SZ deal with byte sizes
[safe/jmp/linux-2.6] / kernel / sysctl.c
index 4a97620..4c93486 100644 (file)
@@ -52,6 +52,7 @@
 #include <linux/slow-work.h>
 #include <linux/perf_event.h>
 #include <linux/kprobes.h>
+#include <linux/pipe_fs_i.h>
 
 #include <asm/uaccess.h>
 #include <asm/processor.h>
@@ -163,6 +164,27 @@ static int proc_taint(struct ctl_table *table, int write,
                               void __user *buffer, size_t *lenp, loff_t *ppos);
 #endif
 
+#ifdef CONFIG_MAGIC_SYSRQ
+static int __sysrq_enabled; /* Note: sysrq code ises it's own private copy */
+
+static int sysrq_sysctl_handler(ctl_table *table, int write,
+                               void __user *buffer, size_t *lenp,
+                               loff_t *ppos)
+{
+       int error;
+
+       error = proc_dointvec(table, write, buffer, lenp, ppos);
+       if (error)
+               return error;
+
+       if (write)
+               sysrq_toggle_support(__sysrq_enabled);
+
+       return 0;
+}
+
+#endif
+
 static struct ctl_table root_table[];
 static struct ctl_table_root sysctl_table_root;
 static struct ctl_table_header root_table_header = {
@@ -567,7 +589,7 @@ static struct ctl_table kern_table[] = {
                .data           = &__sysrq_enabled,
                .maxlen         = sizeof (int),
                .mode           = 0644,
-               .proc_handler   = proc_dointvec,
+               .proc_handler   = sysrq_sysctl_handler,
        },
 #endif
 #ifdef CONFIG_PROC_SYSCTL
@@ -621,7 +643,7 @@ static struct ctl_table kern_table[] = {
 #endif
        {
                .procname       = "userprocess_debug",
-               .data           = &sysctl_userprocess_debug,
+               .data           = &show_unhandled_signals,
                .maxlen         = sizeof(int),
                .mode           = 0644,
                .proc_handler   = proc_dointvec,
@@ -1423,6 +1445,14 @@ static struct ctl_table fs_table[] = {
                .child          = binfmt_misc_table,
        },
 #endif
+       {
+               .procname       = "pipe-max-pages",
+               .data           = &pipe_max_pages,
+               .maxlen         = sizeof(int),
+               .mode           = 0644,
+               .proc_handler   = &proc_dointvec_minmax,
+               .extra1         = &two,
+       },
 /*
  * NOTE: do not add new entries to this table unless you have read
  * Documentation/sysctl/ctl_unnumbered.txt
@@ -1431,7 +1461,8 @@ static struct ctl_table fs_table[] = {
 };
 
 static struct ctl_table debug_table[] = {
-#if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC)
+#if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
+    defined(CONFIG_S390)
        {
                .procname       = "exception-trace",
                .data           = &show_unhandled_signals,
@@ -2049,22 +2080,32 @@ static size_t proc_skip_spaces(char **buf)
        return ret;
 }
 
+static void proc_skip_char(char **buf, size_t *size, const char v)
+{
+       while (*size) {
+               if (**buf != v)
+                       break;
+               (*size)--;
+               (*buf)++;
+       }
+}
+
 #define TMPBUFLEN 22
 /**
- * proc_get_long - reads an ASCII formated integer from a user buffer
+ * proc_get_long - reads an ASCII formatted integer from a user buffer
  *
- * @buf - a kernel buffer
- * @size - size of the kernel buffer
- * @val - this is where the number will be stored
- * @neg - set to %TRUE if number is negative
- * @perm_tr - a vector which contains the allowed trailers
- * @perm_tr_len - size of the perm_tr vector
- * @tr - pointer to store the trailer character
+ * @buf: a kernel buffer
+ * @size: size of the kernel buffer
+ * @val: this is where the number will be stored
+ * @neg: set to %TRUE if number is negative
+ * @perm_tr: a vector which contains the allowed trailers
+ * @perm_tr_len: size of the perm_tr vector
+ * @tr: pointer to store the trailer character
  *
- * In case of success 0 is returned and buf and size are updated with
- * the amount of bytes read. If tr is non NULL and a trailing
- * character exist (size is non zero after returning from this
- * function) tr is updated with the trailing character.
+ * In case of success %0 is returned and @buf and @size are updated with
+ * the amount of bytes read. If @tr is non-NULL and a trailing
+ * character exists (size is non-zero after returning from this
+ * function), @tr is updated with the trailing character.
  */
 static int proc_get_long(char **buf, size_t *size,
                          unsigned long *val, bool *neg,
@@ -2115,15 +2156,15 @@ static int proc_get_long(char **buf, size_t *size,
 }
 
 /**
- * proc_put_long - coverts an integer to a decimal ASCII formated string
+ * proc_put_long - converts an integer to a decimal ASCII formatted string
  *
- * @buf - the user buffer
- * @size - the size of the user buffer
- * @val - the integer to be converted
- * @neg - sign of the number, %TRUE for negative
+ * @buf: the user buffer
+ * @size: the size of the user buffer
+ * @val: the integer to be converted
+ * @neg: sign of the number, %TRUE for negative
  *
- * In case of success 0 is returned and buf and size are updated with
- * the amount of bytes read.
+ * In case of success %0 is returned and @buf and @size are updated with
+ * the amount of bytes written.
  */
 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
                          bool neg)
@@ -2675,6 +2716,157 @@ static int proc_do_cad_pid(struct ctl_table *table, int write,
        return 0;
 }
 
+/**
+ * proc_do_large_bitmap - read/write from/to a large bitmap
+ * @table: the sysctl table
+ * @write: %TRUE if this is a write to the sysctl file
+ * @buffer: the user buffer
+ * @lenp: the size of the user buffer
+ * @ppos: file position
+ *
+ * The bitmap is stored at table->data and the bitmap length (in bits)
+ * in table->maxlen.
+ *
+ * We use a range comma separated format (e.g. 1,3-4,10-10) so that
+ * large bitmaps may be represented in a compact manner. Writing into
+ * the file will clear the bitmap then update it with the given input.
+ *
+ * Returns 0 on success.
+ */
+int proc_do_large_bitmap(struct ctl_table *table, int write,
+                        void __user *buffer, size_t *lenp, loff_t *ppos)
+{
+       int err = 0;
+       bool first = 1;
+       size_t left = *lenp;
+       unsigned long bitmap_len = table->maxlen;
+       unsigned long *bitmap = (unsigned long *) table->data;
+       unsigned long *tmp_bitmap = NULL;
+       char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
+
+       if (!bitmap_len || !left || (*ppos && !write)) {
+               *lenp = 0;
+               return 0;
+       }
+
+       if (write) {
+               unsigned long page = 0;
+               char *kbuf;
+
+               if (left > PAGE_SIZE - 1)
+                       left = PAGE_SIZE - 1;
+
+               page = __get_free_page(GFP_TEMPORARY);
+               kbuf = (char *) page;
+               if (!kbuf)
+                       return -ENOMEM;
+               if (copy_from_user(kbuf, buffer, left)) {
+                       free_page(page);
+                       return -EFAULT;
+                }
+               kbuf[left] = 0;
+
+               tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
+                                    GFP_KERNEL);
+               if (!tmp_bitmap) {
+                       free_page(page);
+                       return -ENOMEM;
+               }
+               proc_skip_char(&kbuf, &left, '\n');
+               while (!err && left) {
+                       unsigned long val_a, val_b;
+                       bool neg;
+
+                       err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
+                                            sizeof(tr_a), &c);
+                       if (err)
+                               break;
+                       if (val_a >= bitmap_len || neg) {
+                               err = -EINVAL;
+                               break;
+                       }
+
+                       val_b = val_a;
+                       if (left) {
+                               kbuf++;
+                               left--;
+                       }
+
+                       if (c == '-') {
+                               err = proc_get_long(&kbuf, &left, &val_b,
+                                                    &neg, tr_b, sizeof(tr_b),
+                                                    &c);
+                               if (err)
+                                       break;
+                               if (val_b >= bitmap_len || neg ||
+                                   val_a > val_b) {
+                                       err = -EINVAL;
+                                       break;
+                               }
+                               if (left) {
+                                       kbuf++;
+                                       left--;
+                               }
+                       }
+
+                       while (val_a <= val_b)
+                               set_bit(val_a++, tmp_bitmap);
+
+                       first = 0;
+                       proc_skip_char(&kbuf, &left, '\n');
+               }
+               free_page(page);
+       } else {
+               unsigned long bit_a, bit_b = 0;
+
+               while (left) {
+                       bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
+                       if (bit_a >= bitmap_len)
+                               break;
+                       bit_b = find_next_zero_bit(bitmap, bitmap_len,
+                                                  bit_a + 1) - 1;
+
+                       if (!first) {
+                               err = proc_put_char(&buffer, &left, ',');
+                               if (err)
+                                       break;
+                       }
+                       err = proc_put_long(&buffer, &left, bit_a, false);
+                       if (err)
+                               break;
+                       if (bit_a != bit_b) {
+                               err = proc_put_char(&buffer, &left, '-');
+                               if (err)
+                                       break;
+                               err = proc_put_long(&buffer, &left, bit_b, false);
+                               if (err)
+                                       break;
+                       }
+
+                       first = 0; bit_b++;
+               }
+               if (!err)
+                       err = proc_put_char(&buffer, &left, '\n');
+       }
+
+       if (!err) {
+               if (write) {
+                       if (*ppos)
+                               bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
+                       else
+                               memcpy(bitmap, tmp_bitmap,
+                                       BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long));
+               }
+               kfree(tmp_bitmap);
+               *lenp -= left;
+               *ppos += *lenp;
+               return 0;
+       } else {
+               kfree(tmp_bitmap);
+               return err;
+       }
+}
+
 #else /* CONFIG_PROC_FS */
 
 int proc_dostring(struct ctl_table *table, int write,