The Android Open Source Project | 34d6eab | 2009-03-03 19:30:45 -0800 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <string.h> |
| 4 | #include <sys/types.h> |
| 5 | #include <stdint.h> |
| 6 | |
| 7 | #include <asm/ioctl.h> |
| 8 | #include <linux/types.h> |
| 9 | |
| 10 | #include "ioctldefs.h" |
| 11 | #include <linux/atmioc.h> |
| 12 | |
| 13 | struct ioctlent { |
| 14 | const char* header; |
| 15 | const char* name; |
| 16 | unsigned long code; |
| 17 | }; |
| 18 | |
| 19 | struct ioctlent ioctls[] = { |
| 20 | #include "ioctls.h" |
| 21 | }; |
| 22 | |
| 23 | int nioctls = sizeof(ioctls) / sizeof(ioctls[0]); |
| 24 | |
The Android Open Source Project | 34d6eab | 2009-03-03 19:30:45 -0800 | [diff] [blame] | 25 | int compare(const void* a, const void* b) { |
| 26 | unsigned long code1 = ((struct ioctlent *) a)->code; |
| 27 | unsigned long code2 = ((struct ioctlent *) b)->code; |
| 28 | const char *name1 = ((struct ioctlent *) a)->name; |
| 29 | const char *name2 = ((struct ioctlent *) b)->name; |
Elliott Hughes | bb0c2d5 | 2014-01-07 17:34:14 -0800 | [diff] [blame] | 30 | return (code1 > code2) ? 1 : (code1 < code2) ? -1 : strcmp(name1, name2); |
The Android Open Source Project | 34d6eab | 2009-03-03 19:30:45 -0800 | [diff] [blame] | 31 | } |
| 32 | |
The Android Open Source Project | 34d6eab | 2009-03-03 19:30:45 -0800 | [diff] [blame] | 33 | int main(int argc, char** argv) { |
| 34 | int i; |
| 35 | |
Jeff Brown | f76f96e | 2012-03-02 16:23:23 -0800 | [diff] [blame] | 36 | /* ioctl_lookup() only looks at the NR and TYPE bits atm. */ |
The Android Open Source Project | 34d6eab | 2009-03-03 19:30:45 -0800 | [diff] [blame] | 37 | for (i = 0; i < nioctls; i++) |
Jeff Brown | f76f96e | 2012-03-02 16:23:23 -0800 | [diff] [blame] | 38 | ioctls[i].code &= (_IOC_NRMASK << _IOC_NRSHIFT) | |
| 39 | (_IOC_TYPEMASK << _IOC_TYPESHIFT); |
The Android Open Source Project | 34d6eab | 2009-03-03 19:30:45 -0800 | [diff] [blame] | 40 | |
| 41 | qsort(ioctls, nioctls, sizeof(ioctls[0]), compare); |
Elliott Hughes | bb0c2d5 | 2014-01-07 17:34:14 -0800 | [diff] [blame] | 42 | puts("\t/* Generated by ioctlsort */"); |
The Android Open Source Project | 34d6eab | 2009-03-03 19:30:45 -0800 | [diff] [blame] | 43 | for (i = 0; i < nioctls; i++) |
| 44 | if (i == 0 || ioctls[i].code != ioctls[i-1].code || |
Elliott Hughes | bb0c2d5 | 2014-01-07 17:34:14 -0800 | [diff] [blame] | 45 | strcmp(ioctls[i].name, ioctls[i-1].name)) |
Jeff Brown | f76f96e | 2012-03-02 16:23:23 -0800 | [diff] [blame] | 46 | printf("\t{\"%s\",\t\"%s\",\t%#06lx},\n", |
The Android Open Source Project | 34d6eab | 2009-03-03 19:30:45 -0800 | [diff] [blame] | 47 | ioctls[i].header, ioctls[i].name, ioctls[i].code); |
| 48 | |
| 49 | return 0; |
| 50 | } |