powerpc: POWER7 optimizations
[glibc.git] / sysdeps / unix / sysv / linux / pathconf.c
blobdb03529fe87f7b6f03cc1147af7024ceb8bbb7e1
1 /* Get file-specific information about a file. Linux version.
2 Copyright (C) 1991,1995,1996,1998-2003,2008 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #include <unistd.h>
21 #include <errno.h>
23 #include "pathconf.h"
24 #include "linux_fsinfo.h"
25 #include <not-cancel.h>
27 static long int posix_pathconf (const char *file, int name);
29 /* Define this first, so it can be inlined. */
30 #define __pathconf static posix_pathconf
31 #include <sysdeps/posix/pathconf.c>
34 /* Get file-specific information about FILE. */
35 long int
36 __pathconf (const char *file, int name)
38 struct statfs fsbuf;
40 switch (name)
42 case _PC_LINK_MAX:
43 return __statfs_link_max (__statfs (file, &fsbuf), &fsbuf);
45 case _PC_FILESIZEBITS:
46 return __statfs_filesize_max (__statfs (file, &fsbuf), &fsbuf);
48 case _PC_2_SYMLINKS:
49 return __statfs_symlinks (__statfs (file, &fsbuf), &fsbuf);
51 case _PC_CHOWN_RESTRICTED:
52 return __statfs_chown_restricted (__statfs (file, &fsbuf), &fsbuf);
54 default:
55 return posix_pathconf (file, name);
60 /* Used like: return statfs_link_max (__statfs (name, &buf), &buf); */
61 long int
62 __statfs_link_max (int result, const struct statfs *fsbuf)
64 if (result < 0)
66 if (errno == ENOSYS)
67 /* Not possible, return the default value. */
68 return LINUX_LINK_MAX;
70 /* Some error occured. */
71 return -1;
74 switch (fsbuf->f_type)
76 case EXT2_SUPER_MAGIC:
77 return EXT2_LINK_MAX;
79 case MINIX_SUPER_MAGIC:
80 case MINIX_SUPER_MAGIC2:
81 return MINIX_LINK_MAX;
83 case MINIX2_SUPER_MAGIC:
84 case MINIX2_SUPER_MAGIC2:
85 return MINIX2_LINK_MAX;
87 case XENIX_SUPER_MAGIC:
88 return XENIX_LINK_MAX;
90 case SYSV4_SUPER_MAGIC:
91 case SYSV2_SUPER_MAGIC:
92 return SYSV_LINK_MAX;
94 case COH_SUPER_MAGIC:
95 return COH_LINK_MAX;
97 case UFS_MAGIC:
98 case UFS_CIGAM:
99 return UFS_LINK_MAX;
101 case REISERFS_SUPER_MAGIC:
102 return REISERFS_LINK_MAX;
104 case XFS_SUPER_MAGIC:
105 return XFS_LINK_MAX;
107 default:
108 return LINUX_LINK_MAX;
113 /* Used like: return statfs_filesize_max (__statfs (name, &buf), &buf); */
114 long int
115 __statfs_filesize_max (int result, const struct statfs *fsbuf)
117 if (result < 0)
119 if (errno == ENOSYS)
120 /* Not possible, return the default value. */
121 return 32;
123 /* Some error occured. */
124 return -1;
127 switch (fsbuf->f_type)
129 case EXT2_SUPER_MAGIC:
130 case UFS_MAGIC:
131 case UFS_CIGAM:
132 case REISERFS_SUPER_MAGIC:
133 case XFS_SUPER_MAGIC:
134 case SMB_SUPER_MAGIC:
135 case NTFS_SUPER_MAGIC:
136 case UDF_SUPER_MAGIC:
137 case JFS_SUPER_MAGIC:
138 case VXFS_SUPER_MAGIC:
139 return 64;
141 case MSDOS_SUPER_MAGIC:
142 case JFFS_SUPER_MAGIC:
143 case JFFS2_SUPER_MAGIC:
144 case NCP_SUPER_MAGIC:
145 case ROMFS_SUPER_MAGIC:
146 return 32;
148 default:
149 return 32;
154 /* Used like: return statfs_link_max (__statfs (name, &buf), &buf); */
155 long int
156 __statfs_symlinks (int result, const struct statfs *fsbuf)
158 if (result < 0)
160 if (errno == ENOSYS)
161 /* Not possible, return the default value. */
162 return 1;
164 /* Some error occured. */
165 return -1;
168 switch (fsbuf->f_type)
170 case ADFS_SUPER_MAGIC:
171 case BFS_MAGIC:
172 case CRAMFS_MAGIC:
173 case DEVPTS_SUPER_MAGIC:
174 case EFS_SUPER_MAGIC:
175 case EFS_MAGIC:
176 case MSDOS_SUPER_MAGIC:
177 case NTFS_SUPER_MAGIC:
178 case QNX4_SUPER_MAGIC:
179 case ROMFS_SUPER_MAGIC:
180 /* No symlink support. */
181 return 0;
183 default:
184 return 1;
189 /* Used like: return __statfs_chown_restricted (__statfs (name, &buf), &buf);*/
190 long int
191 __statfs_chown_restricted (int result, const struct statfs *fsbuf)
193 if (result < 0)
195 if (errno == ENOSYS)
196 /* Not possible, return the default value. */
197 return 1;
199 /* Some error occured. */
200 return -1;
203 int fd;
204 long int retval = 1;
205 switch (fsbuf->f_type)
207 case XFS_SUPER_MAGIC:
208 /* Read the value from /proc/sys/fs/xfs/restrict_chown. If we cannot
209 read it default to assume the restriction is in place. */
210 fd = open_not_cancel_2 ("/proc/sys/fs/xfs/restrict_chown", O_RDONLY);
211 if (fd != -1)
213 char buf[2];
214 if (TEMP_FAILURE_RETRY (read_not_cancel (fd, buf, 2)) == 2
215 && buf[0] >= '0' && buf[0] <= '1')
216 retval = buf[0] - '0';
218 close_not_cancel_no_status (fd);
220 break;
222 default:
223 break;
226 return retval;