blob: 393b534952ffcfab0f718fcb83643d260761f36c [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
Dmitry V. Levinee7b76e2014-11-03 20:14:31 +000033static int is_not_prefix(const char *s1, const char *s2) {
34 size_t len = strlen(s1);
35
36 if (len > strlen(s2))
37 return 1;
38 return memcmp(s1, s2, len);
39}
40
Wichert Akkermane2613b42001-03-17 17:29:43 +000041int main(int argc, char** argv) {
42 int i;
43
Dmitry V. Levin609b58c2011-02-25 23:29:01 +000044 /* ioctl_lookup() only looks at the NR and TYPE bits atm. */
Roland McGrathbd102452004-07-12 07:04:39 +000045 for (i = 0; i < nioctls; i++)
Dmitry V. Levin609b58c2011-02-25 23:29:01 +000046 ioctls[i].code &= (_IOC_NRMASK << _IOC_NRSHIFT) |
47 (_IOC_TYPEMASK << _IOC_TYPESHIFT);
Roland McGrathbd102452004-07-12 07:04:39 +000048
Wichert Akkermane2613b42001-03-17 17:29:43 +000049 qsort(ioctls, nioctls, sizeof(ioctls[0]), compare);
Denys Vlasenkob63256e2011-06-07 12:13:24 +020050 puts("\t/* Generated by ioctlsort */");
Wichert Akkermane2613b42001-03-17 17:29:43 +000051 for (i = 0; i < nioctls; i++)
Dmitry V. Levinee7b76e2014-11-03 20:14:31 +000052 if (i == 0 || ioctls[i-1].code != ioctls[i].code ||
53 is_not_prefix(ioctls[i-1].name, ioctls[i].name))
Mike Frysingerf72418c2011-02-21 23:52:42 -050054 printf("\t{\"%s\",\t\"%s\",\t%#06lx},\n",
Roland McGrath7166bb02004-10-06 22:31:38 +000055 ioctls[i].header, ioctls[i].name, ioctls[i].code);
Roland McGrathbd102452004-07-12 07:04:39 +000056
Wichert Akkermane2613b42001-03-17 17:29:43 +000057 return 0;
58}