blob: 9b18d290a47a8c21c680b1d6050bbe51cabedc34 [file] [log] [blame]
Wichert Akkermane2613b42001-03-17 17:29:43 +00001#include <stdio.h>
2#include <stdlib.h>
Roland McGrath3dfd7992004-06-04 02:03:05 +00003#include <string.h>
Roland McGrathbd102452004-07-12 07:04:39 +00004#include <sys/types.h>
5#include <stdint.h>
Wichert Akkermane2613b42001-03-17 17:29:43 +00006
7#include <asm/ioctl.h>
8#include <linux/types.h>
9
10#include "ioctldefs.h"
11#include <linux/atmioc.h>
12
13struct ioctlent {
14 const char* header;
15 const char* name;
16 unsigned long code;
17};
18
19struct ioctlent ioctls[] = {
20#include "ioctls.h"
21};
22
23int nioctls = sizeof(ioctls) / sizeof(ioctls[0]);
24
25
26int compare(const void* a, const void* b) {
27 unsigned long code1 = ((struct ioctlent *) a)->code;
28 unsigned long code2 = ((struct ioctlent *) b)->code;
Roland McGrath3dfd7992004-06-04 02:03:05 +000029 const char *name1 = ((struct ioctlent *) a)->name;
30 const char *name2 = ((struct ioctlent *) b)->name;
Denys Vlasenkob63256e2011-06-07 12:13:24 +020031 return (code1 > code2) ? 1 : (code1 < code2) ? -1 : strcmp(name1, name2);
Wichert Akkermane2613b42001-03-17 17:29:43 +000032}
33
34
35int main(int argc, char** argv) {
36 int i;
37
Dmitry V. Levin609b58c2011-02-25 23:29:01 +000038 /* ioctl_lookup() only looks at the NR and TYPE bits atm. */
Roland McGrathbd102452004-07-12 07:04:39 +000039 for (i = 0; i < nioctls; i++)
Dmitry V. Levin609b58c2011-02-25 23:29:01 +000040 ioctls[i].code &= (_IOC_NRMASK << _IOC_NRSHIFT) |
41 (_IOC_TYPEMASK << _IOC_TYPESHIFT);
Roland McGrathbd102452004-07-12 07:04:39 +000042
Wichert Akkermane2613b42001-03-17 17:29:43 +000043 qsort(ioctls, nioctls, sizeof(ioctls[0]), compare);
Denys Vlasenkob63256e2011-06-07 12:13:24 +020044 puts("\t/* Generated by ioctlsort */");
Wichert Akkermane2613b42001-03-17 17:29:43 +000045 for (i = 0; i < nioctls; i++)
Roland McGrath7166bb02004-10-06 22:31:38 +000046 if (i == 0 || ioctls[i].code != ioctls[i-1].code ||
Denys Vlasenkob63256e2011-06-07 12:13:24 +020047 strcmp(ioctls[i].name, ioctls[i-1].name))
Mike Frysingerf72418c2011-02-21 23:52:42 -050048 printf("\t{\"%s\",\t\"%s\",\t%#06lx},\n",
Roland McGrath7166bb02004-10-06 22:31:38 +000049 ioctls[i].header, ioctls[i].name, ioctls[i].code);
Roland McGrathbd102452004-07-12 07:04:39 +000050
Wichert Akkermane2613b42001-03-17 17:29:43 +000051 return 0;
52}