Wichert Akkerman | e2613b4 | 2001-03-17 17:29:43 +0000 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
Roland McGrath | 3dfd799 | 2004-06-04 02:03:05 +0000 | [diff] [blame] | 3 | #include <string.h> |
Roland McGrath | bd10245 | 2004-07-12 07:04:39 +0000 | [diff] [blame] | 4 | #include <sys/types.h> |
| 5 | #include <stdint.h> |
Wichert Akkerman | e2613b4 | 2001-03-17 17:29:43 +0000 | [diff] [blame] | 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 | |
| 25 | |
| 26 | int compare(const void* a, const void* b) { |
| 27 | unsigned long code1 = ((struct ioctlent *) a)->code; |
| 28 | unsigned long code2 = ((struct ioctlent *) b)->code; |
Roland McGrath | 3dfd799 | 2004-06-04 02:03:05 +0000 | [diff] [blame] | 29 | const char *name1 = ((struct ioctlent *) a)->name; |
| 30 | const char *name2 = ((struct ioctlent *) b)->name; |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 31 | return (code1 > code2) ? 1 : (code1 < code2) ? -1 : strcmp(name1, name2); |
Wichert Akkerman | e2613b4 | 2001-03-17 17:29:43 +0000 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | |
| 35 | int main(int argc, char** argv) { |
| 36 | int i; |
| 37 | |
Dmitry V. Levin | 609b58c | 2011-02-25 23:29:01 +0000 | [diff] [blame] | 38 | /* ioctl_lookup() only looks at the NR and TYPE bits atm. */ |
Roland McGrath | bd10245 | 2004-07-12 07:04:39 +0000 | [diff] [blame] | 39 | for (i = 0; i < nioctls; i++) |
Dmitry V. Levin | 609b58c | 2011-02-25 23:29:01 +0000 | [diff] [blame] | 40 | ioctls[i].code &= (_IOC_NRMASK << _IOC_NRSHIFT) | |
| 41 | (_IOC_TYPEMASK << _IOC_TYPESHIFT); |
Roland McGrath | bd10245 | 2004-07-12 07:04:39 +0000 | [diff] [blame] | 42 | |
Wichert Akkerman | e2613b4 | 2001-03-17 17:29:43 +0000 | [diff] [blame] | 43 | qsort(ioctls, nioctls, sizeof(ioctls[0]), compare); |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 44 | puts("\t/* Generated by ioctlsort */"); |
Wichert Akkerman | e2613b4 | 2001-03-17 17:29:43 +0000 | [diff] [blame] | 45 | for (i = 0; i < nioctls; i++) |
Roland McGrath | 7166bb0 | 2004-10-06 22:31:38 +0000 | [diff] [blame] | 46 | if (i == 0 || ioctls[i].code != ioctls[i-1].code || |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 47 | strcmp(ioctls[i].name, ioctls[i-1].name)) |
Mike Frysinger | f72418c | 2011-02-21 23:52:42 -0500 | [diff] [blame] | 48 | printf("\t{\"%s\",\t\"%s\",\t%#06lx},\n", |
Roland McGrath | 7166bb0 | 2004-10-06 22:31:38 +0000 | [diff] [blame] | 49 | ioctls[i].header, ioctls[i].name, ioctls[i].code); |
Roland McGrath | bd10245 | 2004-07-12 07:04:39 +0000 | [diff] [blame] | 50 | |
Wichert Akkerman | e2613b4 | 2001-03-17 17:29:43 +0000 | [diff] [blame] | 51 | return 0; |
| 52 | } |