split internal.h into defaults.h and util.h
authorKay Sievers <kay@vrfy.org>
Sat, 4 Jan 2014 05:05:04 +0000 (09:05 +0400)
committerKay Sievers <kay@vrfy.org>
Sat, 4 Jan 2014 05:11:33 +0000 (09:11 +0400)
12 files changed:
bus.h
connection.h
defaults.h [new file with mode: 0644]
endpoint.h
internal.h [deleted file]
main.c
memfd.c
memfd.h
message.h
namespace.c
pool.c
util.h [new file with mode: 0644]

diff --git a/bus.h b/bus.h
index 1d58b4587e7f463a3ee8ed942210f11073081bd7..5af1712ba0d2a3694c0faeed2811c49186a62488 100644 (file)
--- a/bus.h
+++ b/bus.h
@@ -16,7 +16,7 @@
 #include <linux/hashtable.h>
 #include <linux/idr.h>
 
-#include "internal.h"
+#include "util.h"
 
 /**
  * struct kdbus_bus - bus in a namespace
index 27babdf17ab02ac100a1ad98963830bd096e936e..7cfcec45246e8aed38d3d8f66114d02b794c3e3a 100644 (file)
@@ -13,7 +13,8 @@
 #ifndef __KDBUS_CONNECTION_H
 #define __KDBUS_CONNECTION_H
 
-#include "internal.h"
+#include "defaults.h"
+#include "util.h"
 #include "metadata.h"
 #include "pool.h"
 
diff --git a/defaults.h b/defaults.h
new file mode 100644 (file)
index 0000000..50a9b6a
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2013 Kay Sievers
+ * Copyright (C) 2013 Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+ * Copyright (C) 2013 Daniel Mack <daniel@zonque.org>
+ * Copyright (C) 2013 Linux Foundation
+ *
+ * kdbus is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ */
+
+#ifndef __KDBUS_DEFAULTS_H
+#define __KDBUS_DEFAULTS_H
+
+/* maximum size of message header and items */
+#define KDBUS_MSG_MAX_SIZE             SZ_8K
+
+/* maximum number of message items */
+#define KDBUS_MSG_MAX_ITEMS            128
+
+/* maximum number of passed file descriptors */
+#define KDBUS_MSG_MAX_FDS              256
+
+/* maximum message payload size */
+#define KDBUS_MSG_MAX_PAYLOAD_VEC_SIZE SZ_2M
+
+/* maximum length of well-known bus name */
+#define KDBUS_NAME_MAX_LEN             255
+
+/* maximum length of bus, ns, ep name */
+#define KDBUS_MAKE_MAX_LEN             63
+
+/* maximum size of make data */
+#define KDBUS_MAKE_MAX_SIZE            SZ_32K
+
+/* maximum size of hello data */
+#define KDBUS_HELLO_MAX_SIZE           SZ_32K
+
+/* maximum size of match data */
+#define KDBUS_MATCH_MAX_SIZE           SZ_32K
+
+/* maximum size of policy data */
+#define KDBUS_POLICY_MAX_SIZE          SZ_32K
+
+/* maximum number of queued messages per connection */
+#define KDBUS_CONN_MAX_MSGS            64
+
+/* maximum number of well-known names */
+#define KDBUS_CONN_MAX_NAMES           64
+
+/* maximum number of queud requests waiting ot a reply */
+#define KDBUS_CONN_MAX_REQUESTS_PENDING        64
+
+#endif
index 0db1bda657b4999bb80a2e336e3ec7cf69c54513..f3a37e2dfc1c7848be5305995366d015c87b8104 100644 (file)
@@ -13,7 +13,8 @@
 #ifndef __KDBUS_EP_H
 #define __KDBUS_EP_H
 
-#include "internal.h"
+#include "defaults.h"
+#include "util.h"
 
 /*
  * struct kdbus_endpoint - enpoint to access a bus
diff --git a/internal.h b/internal.h
deleted file mode 100644 (file)
index 8c1594f..0000000
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * Copyright (C) 2013 Kay Sievers
- * Copyright (C) 2013 Greg Kroah-Hartman <gregkh@linuxfoundation.org>
- * Copyright (C) 2013 Daniel Mack <daniel@zonque.org>
- * Copyright (C) 2013 Linux Foundation
- *
- * kdbus is free software; you can redistribute it and/or modify it under
- * the terms of the GNU Lesser General Public License as published by the
- * Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- */
-
-#ifndef __KDBUS_INTERNAL_H
-#define __KDBUS_INTERNAL_H
-
-#include "kdbus.h"
-
-/* maximum size of message header and items */
-#define KDBUS_MSG_MAX_SIZE             SZ_8K
-
-/* maximum number of message items */
-#define KDBUS_MSG_MAX_ITEMS            128
-
-/* maximum number of passed file descriptors */
-#define KDBUS_MSG_MAX_FDS              256
-
-/* maximum message payload size */
-#define KDBUS_MSG_MAX_PAYLOAD_VEC_SIZE SZ_2M
-
-/* maximum length of well-known bus name */
-#define KDBUS_NAME_MAX_LEN             255
-
-/* maximum length of bus, ns, ep name */
-#define KDBUS_MAKE_MAX_LEN             63
-
-/* maximum size of make data */
-#define KDBUS_MAKE_MAX_SIZE            SZ_32K
-
-/* maximum size of hello data */
-#define KDBUS_HELLO_MAX_SIZE           SZ_32K
-
-/* maximum size of match data */
-#define KDBUS_MATCH_MAX_SIZE           SZ_32K
-
-/* maximum size of policy data */
-#define KDBUS_POLICY_MAX_SIZE          SZ_32K
-
-/* maximum number of queued messages per connection */
-#define KDBUS_CONN_MAX_MSGS            64
-
-/* maximum number of well-known names */
-#define KDBUS_CONN_MAX_NAMES           64
-
-/* maximum number of queud requests waiting ot a reply */
-#define KDBUS_CONN_MAX_REQUESTS_PENDING        64
-
-/* all exported addresses are 64 bit */
-#define KDBUS_PTR(addr) ((void __user *)(uintptr_t)(addr))
-
-/* all exported sizes are 64 bit and data aligned to 64 bit */
-#define KDBUS_ALIGN8(s) ALIGN((s), 8)
-#define KDBUS_IS_ALIGNED8(s) (IS_ALIGNED(s, 8))
-
-/* generic access and iterators over a stream of items */
-#define KDBUS_ITEM_HEADER_SIZE offsetof(struct kdbus_item, data)
-#define KDBUS_ITEM_SIZE(s) KDBUS_ALIGN8(KDBUS_ITEM_HEADER_SIZE + (s))
-#define KDBUS_ITEM_NEXT(item) \
-       (typeof(item))(((u8 *)item) + KDBUS_ALIGN8((item)->size))
-#define KDBUS_ITEM_FOREACH(item, head, first)                          \
-       for (item = (head)->first;                                      \
-            (u8 *)(item) < (u8 *)(head) + (head)->size;                \
-            item = KDBUS_ITEM_NEXT(item))
-#define KDBUS_ITEM_VALID(item, head)                                   \
-       ((item)->size > KDBUS_ITEM_HEADER_SIZE &&                       \
-        (u8 *)(item) + (item)->size <= (u8 *)(head) + (head)->size)
-#define KDBUS_ITEM_END(item, head)                                     \
-       ((u8 *)item == ((u8 *)(head) + KDBUS_ALIGN8((head)->size)))
-
-/**
- * kdbus_size_get_user - read the size variable from user memory
- * @_s:                        Size variable
- * @_b:                        Buffer to read from
- * @_t:                        Structure, "size" is a member of
- *
- * Returns: the result of copy_from_user()
- */
-#define kdbus_size_get_user(_s, _b, _t)                                                \
-({                                                                             \
-       u64 __user *_sz = (void __user *)(_b) + offsetof(typeof(_t), size);     \
-       copy_from_user(_s, _sz, sizeof(__u64));                                 \
-})
-
-/**
- * kdbus_offset_set_user - write the offset variable to user memory
- * @_s:                        Offset variable
- * @_b:                        Buffer to write to
- * @_t:                        Structure, "offset" is a member of
- *
- * Returns: the result of copy_to_user()
- */
-#define kdbus_offset_set_user(_s, _b, _t)                              \
-({                                                                     \
-       u64 __user *_sz = (void __user *)(_b) + offsetof(_t, offset);   \
-       copy_to_user(_sz, _s, sizeof(__u64));                           \
-})
-
-/**
- * kdbus_check_strlen - check length of a string at the end a structure
- * @_p:                        A pointer to a structure that has a size member and
- *                     a variable string at its end
- * @_s:                        The name of the dynamically sized string member
- *
- * Returns: 1 if the string's end marker is withing the struct, or 0 otherwise.
- */
-#define kdbus_check_strlen(_p, _s)                                     \
-({                                                                     \
-       size_t _max = (_p)->size - offsetof(typeof(*(_p)), _s);         \
-       _max == 0 || strnlen((_p)->_s, _max) != _max;                   \
-})
-
-/**
- * kdbus_validate_nul - check the validity of a sized string
- * @s:                 String
- * @l:                 Length of string
- *
- * Validate that a given string matches the given size, and the
- * string is \0 terminated.
- *
- * Returns: true if the given string is valid
- */
-static inline bool kdbus_validate_nul(const char *s, size_t l)
-{
-       return l > 0 && memchr(s, '\0', l) == s + l - 1;
-}
-
-/**
- * kdbus_str_hash - calculate a hash
- * @str:               String
- *
- * Returns: hash value
- */
-static inline unsigned int kdbus_str_hash(const char *str)
-{
-       return full_name_hash(str, strlen(str));
-}
-#endif
diff --git a/main.c b/main.c
index f7f1e53761147e4ce7ade52ee9e8821310483de5..b865d1593cb6384b3e28b75e8222b8e843dc4aa8 100644 (file)
--- a/main.c
+++ b/main.c
@@ -18,7 +18,8 @@
 #include <linux/module.h>
 #include <linux/sched.h>
 
-#include "internal.h"
+#include "defaults.h"
+#include "util.h"
 #include "namespace.h"
 
 static int __init kdbus_init(void)
diff --git a/memfd.c b/memfd.c
index 2c0889171266dff607edc30e5750d8eeeda9d367..2af6291c13b457659727a9c26628b773e85eef66 100644 (file)
--- a/memfd.c
+++ b/memfd.c
@@ -25,6 +25,7 @@
 #include <linux/uaccess.h>
 
 #include "memfd.h"
+#include "util.h"
 
 static const struct file_operations kdbus_memfd_fops;
 
diff --git a/memfd.h b/memfd.h
index 7fc327a5dc3c2c52a0c4c29bf54e14d6755f4fd5..3a7b21310549a68203d634d6e25a977fe33ebf3c 100644 (file)
--- a/memfd.h
+++ b/memfd.h
@@ -13,8 +13,6 @@
 #ifndef __KDBUS_MEMFD_H
 #define __KDBUS_MEMFD_H
 
-#include "internal.h"
-
 bool kdbus_is_memfd(const struct file *fp);
 bool kdbus_is_memfd_sealed(const struct file *fp);
 u64 kdbus_memfd_size(const struct file *fp);
index 1fc6f2efa05671f8ab7562e0edca73f12c2178a0..55fa6cff73518479a6a5b191948a47cb6f71a4fe 100644 (file)
--- a/message.h
+++ b/message.h
@@ -13,7 +13,7 @@
 #ifndef __KDBUS_MESSAGE_H
 #define __KDBUS_MESSAGE_H
 
-#include "internal.h"
+#include "util.h"
 #include "metadata.h"
 
 /**
index a9aa379a3f5b255a54a2f19500437ec0158e30cc..836e96f76ae0749889f90b6c96e8e4bb5ca0c1b2 100644 (file)
 #include <linux/slab.h>
 #include <linux/uaccess.h>
 
+#include "defaults.h"
+#include "util.h"
 #include "bus.h"
 #include "handle.h"
-#include "internal.h"
 #include "namespace.h"
 
 /* map of majors to namespaces */
diff --git a/pool.c b/pool.c
index 3f5ae36f76f42094fefa477a1c940646e261fde1..5f7339e6f06e487ba9d5b387373e1d93ed848864 100644 (file)
--- a/pool.c
+++ b/pool.c
@@ -25,7 +25,7 @@
 #include <linux/slab.h>
 #include <linux/uaccess.h>
 
-#include "internal.h"
+#include "util.h"
 #include "pool.h"
 
 /**
diff --git a/util.h b/util.h
new file mode 100644 (file)
index 0000000..bee27ab
--- /dev/null
+++ b/util.h
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2013 Kay Sievers
+ * Copyright (C) 2013 Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+ * Copyright (C) 2013 Daniel Mack <daniel@zonque.org>
+ * Copyright (C) 2013 Linux Foundation
+ *
+ * kdbus is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ */
+
+#ifndef __KDBUS_UTIL_H
+#define __KDBUS_UTIL_H
+
+#include "kdbus.h"
+
+/* all exported addresses are 64 bit */
+#define KDBUS_PTR(addr) ((void __user *)(uintptr_t)(addr))
+
+/* all exported sizes are 64 bit and data aligned to 64 bit */
+#define KDBUS_ALIGN8(s) ALIGN((s), 8)
+#define KDBUS_IS_ALIGNED8(s) (IS_ALIGNED(s, 8))
+
+/* generic access and iterators over a stream of items */
+#define KDBUS_ITEM_HEADER_SIZE offsetof(struct kdbus_item, data)
+#define KDBUS_ITEM_SIZE(s) KDBUS_ALIGN8(KDBUS_ITEM_HEADER_SIZE + (s))
+#define KDBUS_ITEM_NEXT(item) \
+       (typeof(item))(((u8 *)item) + KDBUS_ALIGN8((item)->size))
+#define KDBUS_ITEM_FOREACH(item, head, first)                          \
+       for (item = (head)->first;                                      \
+            (u8 *)(item) < (u8 *)(head) + (head)->size;                \
+            item = KDBUS_ITEM_NEXT(item))
+#define KDBUS_ITEM_VALID(item, head)                                   \
+       ((item)->size > KDBUS_ITEM_HEADER_SIZE &&                       \
+        (u8 *)(item) + (item)->size <= (u8 *)(head) + (head)->size)
+#define KDBUS_ITEM_END(item, head)                                     \
+       ((u8 *)item == ((u8 *)(head) + KDBUS_ALIGN8((head)->size)))
+
+/**
+ * kdbus_size_get_user - read the size variable from user memory
+ * @_s:                        Size variable
+ * @_b:                        Buffer to read from
+ * @_t:                        Structure, "size" is a member of
+ *
+ * Returns: the result of copy_from_user()
+ */
+#define kdbus_size_get_user(_s, _b, _t)                                                \
+({                                                                             \
+       u64 __user *_sz = (void __user *)(_b) + offsetof(typeof(_t), size);     \
+       copy_from_user(_s, _sz, sizeof(__u64));                                 \
+})
+
+/**
+ * kdbus_offset_set_user - write the offset variable to user memory
+ * @_s:                        Offset variable
+ * @_b:                        Buffer to write to
+ * @_t:                        Structure, "offset" is a member of
+ *
+ * Returns: the result of copy_to_user()
+ */
+#define kdbus_offset_set_user(_s, _b, _t)                              \
+({                                                                     \
+       u64 __user *_sz = (void __user *)(_b) + offsetof(_t, offset);   \
+       copy_to_user(_sz, _s, sizeof(__u64));                           \
+})
+
+/**
+ * kdbus_check_strlen - check length of a string at the end a structure
+ * @_p:                        A pointer to a structure that has a size member and
+ *                     a variable string at its end
+ * @_s:                        The name of the dynamically sized string member
+ *
+ * Returns: 1 if the string's end marker is withing the struct, or 0 otherwise.
+ */
+#define kdbus_check_strlen(_p, _s)                                     \
+({                                                                     \
+       size_t _max = (_p)->size - offsetof(typeof(*(_p)), _s);         \
+       _max == 0 || strnlen((_p)->_s, _max) != _max;                   \
+})
+
+/**
+ * kdbus_validate_nul - check the validity of a sized string
+ * @s:                 String
+ * @l:                 Length of string
+ *
+ * Validate that a given string matches the given size, and the
+ * string is \0 terminated.
+ *
+ * Returns: true if the given string is valid
+ */
+static inline bool kdbus_validate_nul(const char *s, size_t l)
+{
+       return l > 0 && memchr(s, '\0', l) == s + l - 1;
+}
+
+/**
+ * kdbus_str_hash - calculate a hash
+ * @str:               String
+ *
+ * Returns: hash value
+ */
+static inline unsigned int kdbus_str_hash(const char *str)
+{
+       return full_name_hash(str, strlen(str));
+}
+#endif