Header file cleanup

tytso@mit.edu
Mon, 24 Nov 1997 08:31:29 -0500


Hi Linus,

The following patches (versus 2.1.65) clean up the header files
a bit to avoid warning messages when compiling user programs with -Wall
-ansi. I also added #ifdef __KERNEL__ around list.h and dcache.h, to
avoid contaminating the namespace when programs like e2fsprogs need to
#include <linux/fs.h>.

- Ted

Patch generated: on Mon Nov 24 06:57:11 EST 1997 by tytso@rsts-11
against Linux version 2.1.65

===================================================================
RCS file: include/linux/RCS/list.h,v
retrieving revision 1.1
diff -u -r1.1 include/linux/list.h
--- include/linux/list.h 1997/11/19 06:49:21 1.1
+++ include/linux/list.h 1997/11/24 01:19:29
@@ -1,6 +1,8 @@
#ifndef _LINUX_LIST_H
#define _LINUX_LIST_H

+#ifdef __KERNEL__
+
/*
* Simple doubly linked list implementation.
*
@@ -28,7 +30,7 @@
* This is only for internal list manipulation where we know
* the prev/next entries already!
*/
-static inline void __list_add(struct list_head * new,
+static __inline__ void __list_add(struct list_head * new,
struct list_head * prev,
struct list_head * next)
{
@@ -41,7 +43,7 @@
/*
* Insert a new entry after the specified head..
*/
-static inline void list_add(struct list_head *new, struct list_head *head)
+static __inline__ void list_add(struct list_head *new, struct list_head *head)
{
__list_add(new, head, head->next);
}
@@ -53,18 +55,19 @@
* This is only for internal list manipulation where we know
* the prev/next entries already!
*/
-static inline void __list_del(struct list_head * prev, struct list_head * next)
+static __inline__ void __list_del(struct list_head * prev,
+ struct list_head * next)
{
next->prev = prev;
prev->next = next;
}

-static inline void list_del(struct list_head *entry)
+static __inline__ void list_del(struct list_head *entry)
{
__list_del(entry->prev, entry->next);
}

-static inline int list_empty(struct list_head *head)
+static __inline__ int list_empty(struct list_head *head)
{
return head->next == head;
}
@@ -72,7 +75,7 @@
/*
* Splice in "list" into "head"
*/
-static inline void list_splice(struct list_head *list, struct list_head *head)
+static __inline__ void list_splice(struct list_head *list, struct list_head *head)
{
struct list_head *first = list->next;

@@ -90,5 +93,7 @@

#define list_entry(ptr, type, member) \
((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
+
+#endif /* __KERNEL__ */

#endif
===================================================================
RCS file: include/linux/RCS/dcache.h,v
retrieving revision 1.1
diff -u -r1.1 include/linux/dcache.h
--- include/linux/dcache.h 1997/11/19 21:10:54 1.1
+++ include/linux/dcache.h 1997/11/24 01:19:16
@@ -1,6 +1,8 @@
#ifndef __LINUX_DCACHE_H
#define __LINUX_DCACHE_H

+#ifdef __KERNEL__
+
/*
* linux/include/linux/dcache.h
*
@@ -25,14 +27,14 @@
#define init_name_hash() 0

/* partial hash update function. Assume roughly 4 bits per character */
-static inline unsigned long partial_name_hash(unsigned char c, unsigned long prevhash)
+static __inline__ unsigned long partial_name_hash(unsigned char c, unsigned long prevhash)
{
prevhash = (prevhash << 4) | (prevhash >> (8*sizeof(unsigned long)-4));
return prevhash ^ c;
}

/* Finally: cut down the number of bits to a int value (and try to avoid losing bits) */
-static inline unsigned long end_name_hash(unsigned long hash)
+static __inline__ unsigned long end_name_hash(unsigned long hash)
{
if (sizeof(hash) > sizeof(unsigned int))
hash += hash >> 4*sizeof(hash);
@@ -40,7 +42,7 @@
}

/* Compute the hash for a name string. */
-static inline unsigned int full_name_hash(const char * name, unsigned int len)
+static __inline__ unsigned int full_name_hash(const char * name, unsigned int len)
{
unsigned long hash = init_name_hash();
while (len--)
@@ -102,7 +104,7 @@
* to invalidate a dentry for some reason (NFS
* timeouts or autofs deletes).
*/
-static inline void d_drop(struct dentry * dentry)
+static __inline__ void d_drop(struct dentry * dentry)
{
list_del(&dentry->d_hash);
INIT_LIST_HEAD(&dentry->d_hash);
@@ -152,7 +154,7 @@
extern char * d_path(struct dentry * entry, char * buf, int buflen);

/* Allocation counts.. */
-static inline struct dentry * dget(struct dentry *dentry)
+static __inline__ struct dentry * dget(struct dentry *dentry)
{
if (dentry)
dentry->d_count++;
@@ -160,5 +162,7 @@
}

extern void dput(struct dentry *);
+
+#endif /* __KERNEL__ */

#endif /* __LINUX_DCACHE_H */
===================================================================
RCS file: include/asm-i386/RCS/atomic.h,v
retrieving revision 1.1
diff -u -r1.1 include/asm-i386/atomic.h
--- include/asm-i386/atomic.h 1997/11/19 06:49:21 1.1
+++ include/asm-i386/atomic.h 1997/11/19 06:49:24
@@ -17,7 +17,7 @@
* on us. We need to use _exactly_ the address the user gave us,
* not some alias that contains the same information.
*/
-#define __atomic_fool_gcc(x) (*(struct { int a[100]; } *)x)
+#define __atomic_fool_gcc(x) (*(volatile struct { int a[100]; } *)x)

#ifdef __SMP__
typedef struct { volatile int counter; } atomic_t;
===================================================================
RCS file: include/asm-i386/RCS/bitops.h,v
retrieving revision 1.1
diff -u -r1.1 include/asm-i386/bitops.h
--- include/asm-i386/bitops.h 1997/11/19 06:49:21 1.1
+++ include/asm-i386/bitops.h 1997/11/19 06:49:24
@@ -20,11 +20,26 @@
#endif

/*
+ * Function prototypes to keep gcc -Wall happy
+ */
+extern void set_bit(int nr, volatile void * addr);
+extern void clear_bit(int nr, volatile void * addr);
+extern void change_bit(int nr, volatile void * addr);
+extern int test_and_set_bit(int nr, volatile void * addr);
+extern int test_and_clear_bit(int nr, volatile void * addr);
+extern int test_and_change_bit(int nr, volatile void * addr);
+extern int __constant_test_bit(int nr, const volatile void * addr);
+extern int __test_bit(int nr, volatile void * addr);
+extern int find_first_zero_bit(void * addr, unsigned size);
+extern int find_next_zero_bit (void * addr, int size, int offset);
+extern unsigned long ffz(unsigned long word);
+
+/*
* Some hacks to defeat gcc over-optimizations..
*/
struct __dummy { unsigned long a[100]; };
-#define ADDR (*(struct __dummy *) addr)
-#define CONST_ADDR (*(const struct __dummy *) addr)
+#define ADDR (*(volatile struct __dummy *) addr)
+#define CONST_ADDR (*(volatile const struct __dummy *) addr)

extern __inline__ void set_bit(int nr, volatile void * addr)
{