e12a08434a104d46be8ef10dd788cd8201f49174
[platform/upstream/glibc.git] / sysdeps / unix / sysv / linux / pathconf.c
1 /* Get file-specific information about a file.  Linux version.
2    Copyright (C) 1991,1995,1996,1998-2002,2003 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4
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.
9
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.
14
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.  */
19
20 #include <unistd.h>
21 #include <errno.h>
22 #include "pathconf.h"
23 #include "linux_fsinfo.h"
24
25 static long int posix_pathconf (const char *file, int name);
26
27 /* Define this first, so it can be inlined.  */
28 #define __pathconf static posix_pathconf
29 #include <sysdeps/posix/pathconf.c>
30
31
32 /* Get file-specific information about FILE.  */
33 long int
34 __pathconf (const char *file, int name)
35 {
36   struct statfs fsbuf;
37
38   switch (name)
39     {
40     case _PC_LINK_MAX:
41       return __statfs_link_max (__statfs (file, &fsbuf), &fsbuf);
42
43     case _PC_FILESIZEBITS:
44       return __statfs_filesize_max (__statfs (file, &fsbuf), &fsbuf);
45
46     case _PC_2_SYMLINKS:
47       return __statfs_symlinks (__statfs (file, &fsbuf), &fsbuf);
48
49     default:
50       return posix_pathconf (file, name);
51     }
52 }
53
54
55 /* Used like: return statfs_link_max (__statfs (name, &buf), &buf); */
56 long int
57 __statfs_link_max (int result, const struct statfs *fsbuf)
58 {
59   if (result < 0)
60     {
61       if (errno == ENOSYS)
62         /* Not possible, return the default value.  */
63         return LINUX_LINK_MAX;
64
65       /* Some error occured.  */
66       return -1;
67     }
68
69   switch (fsbuf->f_type)
70     {
71     case EXT2_SUPER_MAGIC:
72       return EXT2_LINK_MAX;
73
74     case MINIX_SUPER_MAGIC:
75     case MINIX_SUPER_MAGIC2:
76       return MINIX_LINK_MAX;
77
78     case MINIX2_SUPER_MAGIC:
79     case MINIX2_SUPER_MAGIC2:
80       return MINIX2_LINK_MAX;
81
82     case XENIX_SUPER_MAGIC:
83       return XENIX_LINK_MAX;
84
85     case SYSV4_SUPER_MAGIC:
86     case SYSV2_SUPER_MAGIC:
87       return SYSV_LINK_MAX;
88
89     case COH_SUPER_MAGIC:
90       return COH_LINK_MAX;
91
92     case UFS_MAGIC:
93     case UFS_CIGAM:
94       return UFS_LINK_MAX;
95
96     case REISERFS_SUPER_MAGIC:
97       return REISERFS_LINK_MAX;
98
99     case XFS_SUPER_MAGIC:
100       return XFS_LINK_MAX;
101
102     default:
103       return LINUX_LINK_MAX;
104     }
105 }
106
107
108 /* Used like: return statfs_filesize_max (__statfs (name, &buf), &buf); */
109 long int
110 __statfs_filesize_max (int result, const struct statfs *fsbuf)
111 {
112   if (result < 0)
113     {
114       if (errno == ENOSYS)
115         /* Not possible, return the default value.  */
116         return 32;
117
118       /* Some error occured.  */
119       return -1;
120     }
121
122   switch (fsbuf->f_type)
123     {
124     case EXT2_SUPER_MAGIC:
125     case UFS_MAGIC:
126     case UFS_CIGAM:
127     case REISERFS_SUPER_MAGIC:
128     case XFS_SUPER_MAGIC:
129     case SMB_SUPER_MAGIC:
130     case NTFS_SUPER_MAGIC:
131     case UDF_SUPER_MAGIC:
132     case JFS_SUPER_MAGIC:
133     case VXFS_SUPER_MAGIC:
134       return 64;
135
136     case MSDOS_SUPER_MAGIC:
137     case JFFS_SUPER_MAGIC:
138     case JFFS2_SUPER_MAGIC:
139     case NCP_SUPER_MAGIC:
140     case ROMFS_SUPER_MAGIC:
141       return 32;
142
143     default:
144       return 32;
145     }
146 }
147
148
149 /* Used like: return statfs_link_max (__statfs (name, &buf), &buf); */
150 long int
151 __statfs_symlinks (int result, const struct statfs *fsbuf)
152 {
153   if (result < 0)
154     {
155       if (errno == ENOSYS)
156         /* Not possible, return the default value.  */
157         return 1;
158
159       /* Some error occured.  */
160       return -1;
161     }
162
163   switch (fsbuf->f_type)
164     {
165     case ADFS_SUPER_MAGIC:
166     case BFS_MAGIC:
167     case CRAMFS_MAGIC:
168     case DEVPTS_SUPER_MAGIC:
169     case EFS_SUPER_MAGIC:
170     case EFS_MAGIC:
171     case MSDOS_SUPER_MAGIC:
172     case NTFS_SUPER_MAGIC:
173     case QNX4_SUPER_MAGIC:
174     case ROMFS_SUPER_MAGIC:
175       /* No symlink support.  */
176       return 0;
177
178     default:
179       return 1;
180     }
181 }