- Kai Germaschewski: ISDN update (including Makefiles)
[davej-history.git] / include / linux / highuid.h
blobd5a9ff5d09e4af914e92ea935dcd70084f86a641
1 #ifndef _LINUX_HIGHUID_H
2 #define _LINUX_HIGHUID_H
4 #include <linux/config.h>
5 #include <linux/types.h>
7 /*
8 * general notes:
10 * CONFIG_UID16 is defined if the given architecture needs to
11 * support backwards compatibility for old system calls.
13 * kernel code should use uid_t and gid_t at all times when dealing with
14 * kernel-private data.
16 * old_uid_t and old_gid_t should only be different if CONFIG_UID16 is
17 * defined, else the platform should provide dummy typedefs for them
18 * such that they are equivalent to __kernel_{u,g}id_t.
20 * uid16_t and gid16_t are used on all architectures. (when dealing
21 * with structures hard coded to 16 bits, such as in filesystems)
26 * This is the "overflow" UID and GID. They are used to signify uid/gid
27 * overflow to old programs when they request uid/gid information but are
28 * using the old 16 bit interfaces.
29 * When you run a libc5 program, it will think that all highuid files or
30 * processes are owned by this uid/gid.
31 * The idea is that it's better to do so than possibly return 0 in lieu of
32 * 65536, etc.
35 extern int overflowuid;
36 extern int overflowgid;
38 #define DEFAULT_OVERFLOWUID 65534
39 #define DEFAULT_OVERFLOWGID 65534
41 #ifdef CONFIG_UID16
43 /* prevent uid mod 65536 effect by returning a default value for high UIDs */
44 #define high2lowuid(uid) ((uid) > 65535 ? (old_uid_t)overflowuid : (old_uid_t)(uid))
45 #define high2lowgid(gid) ((gid) > 65535 ? (old_gid_t)overflowgid : (old_gid_t)(gid))
47 * -1 is different in 16 bits than it is in 32 bits
48 * these macros are used by chown(), setreuid(), ...,
50 #define low2highuid(uid) ((uid) == (old_uid_t)-1 ? (uid_t)-1 : (uid_t)(uid))
51 #define low2highgid(gid) ((gid) == (old_gid_t)-1 ? (gid_t)-1 : (gid_t)(gid))
53 /* Avoid extra ifdefs with these macros */
55 #define SET_UID16(var, uid) var = high2lowuid(uid)
56 #define SET_GID16(var, gid) var = high2lowgid(gid)
57 #define NEW_TO_OLD_UID(uid) high2lowuid(uid)
58 #define NEW_TO_OLD_GID(gid) high2lowgid(gid)
60 /* specific to fs/stat.c */
61 #define SET_OLDSTAT_UID(stat, uid) (stat).st_uid = high2lowuid(uid)
62 #define SET_OLDSTAT_GID(stat, gid) (stat).st_gid = high2lowgid(gid)
63 #define SET_STAT_UID(stat, uid) (stat).st_uid = high2lowuid(uid)
64 #define SET_STAT_GID(stat, gid) (stat).st_gid = high2lowgid(gid)
66 #else
68 #define SET_UID16(var, uid) do { ; } while (0)
69 #define SET_GID16(var, gid) do { ; } while (0)
70 #define NEW_TO_OLD_UID(uid) (uid)
71 #define NEW_TO_OLD_GID(gid) (gid)
73 #define SET_OLDSTAT_UID(stat, uid) (stat).st_uid = (uid)
74 #define SET_OLDSTAT_GID(stat, gid) (stat).st_gid = (gid)
75 #define SET_STAT_UID(stat, uid) (stat).st_uid = (uid)
76 #define SET_STAT_GID(stat, gid) (stat).st_gid = (gid)
78 #endif /* CONFIG_UID16 */
82 * Everything below this line is needed on all architectures, to deal with
83 * filesystems that only store 16 bits of the UID/GID, etc.
87 * This is the UID and GID that will get written to disk if a filesystem
88 * only supports 16-bit UIDs and the kernel has a high UID/GID to write
90 extern int fs_overflowuid;
91 extern int fs_overflowgid;
93 #define DEFAULT_FS_OVERFLOWUID 65534
94 #define DEFAULT_FS_OVERFLOWGID 65534
97 * Since these macros are used in architectures that only need limited
98 * 16-bit UID back compatibility, we won't use old_uid_t and old_gid_t
100 #define fs_high2lowuid(uid) ((uid) > 65535 ? (uid16_t)fs_overflowuid : (uid16_t)(uid))
101 #define fs_high2lowgid(gid) ((gid) > 65535 ? (gid16_t)fs_overflowgid : (gid16_t)(gid))
103 #define low_16_bits(x) ((x) & 0xFFFF)
104 #define high_16_bits(x) (((x) & 0xFFFF0000) >> 16)
106 #endif /* _LINUX_HIGHUID_H */