blob: dab30f1265c7c0fb223251c8fa1d5966ef632fec [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
Wichert Akkermane2613b42001-03-17 17:29:43 +000025int compare(const void* a, const void* b) {
26 unsigned long code1 = ((struct ioctlent *) a)->code;
27 unsigned long code2 = ((struct ioctlent *) b)->code;
Roland McGrath3dfd7992004-06-04 02:03:05 +000028 const char *name1 = ((struct ioctlent *) a)->name;
29 const char *name2 = ((struct ioctlent *) b)->name;
Denys Vlasenkob63256e2011-06-07 12:13:24 +020030 return (code1 > code2) ? 1 : (code1 < code2) ? -1 : strcmp(name1, name2);
Wichert Akkermane2613b42001-03-17 17:29:43 +000031}
32
Wichert Akkermane2613b42001-03-17 17:29:43 +000033int main(int argc, char** argv) {
34 int i;
35
Dmitry V. Levin609b58c2011-02-25 23:29:01 +000036 /* ioctl_lookup() only looks at the NR and TYPE bits atm. */
Roland McGrathbd102452004-07-12 07:04:39 +000037 for (i = 0; i < nioctls; i++)
Dmitry V. Levin609b58c2011-02-25 23:29:01 +000038 ioctls[i].code &= (_IOC_NRMASK << _IOC_NRSHIFT) |
39 (_IOC_TYPEMASK << _IOC_TYPESHIFT);
Roland McGrathbd102452004-07-12 07:04:39 +000040
Wichert Akkermane2613b42001-03-17 17:29:43 +000041 qsort(ioctls, nioctls, sizeof(ioctls[0]), compare);
Denys Vlasenkob63256e2011-06-07 12:13:24 +020042 puts("\t/* Generated by ioctlsort */");
Wichert Akkermane2613b42001-03-17 17:29:43 +000043 for (i = 0; i < nioctls; i++)
Roland McGrath7166bb02004-10-06 22:31:38 +000044 if (i == 0 || ioctls[i].code != ioctls[i-1].code ||
Denys Vlasenkob63256e2011-06-07 12:13:24 +020045 strcmp(ioctls[i].name, ioctls[i-1].name))
Mike Frysingerf72418c2011-02-21 23:52:42 -050046 printf("\t{\"%s\",\t\"%s\",\t%#06lx},\n",
Roland McGrath7166bb02004-10-06 22:31:38 +000047 ioctls[i].header, ioctls[i].name, ioctls[i].code);
Roland McGrathbd102452004-07-12 07:04:39 +000048
Wichert Akkermane2613b42001-03-17 17:29:43 +000049 return 0;
50}