fpathconf.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /* fpathconf -- adjusted for busybox
  2. Copyright (C) 1991,95,96,98,99,2000,2001 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. #include <errno.h>
  17. #include <unistd.h>
  18. #include <limits.h>
  19. #include <sys/statfs.h>
  20. #include <errno.h>
  21. #include <stddef.h>
  22. #include <limits.h>
  23. #include <fcntl.h>
  24. #include <sys/stat.h>
  25. #include <sys/statfs.h>
  26. //#include <sys/statvfs.h>
  27. //#include "linux_fsinfo.h"
  28. libc_hidden_proto(fstat)
  29. #ifndef __USE_FILE_OFFSET64
  30. extern int fstatfs (int __fildes, struct statfs *__buf)
  31. __THROW __nonnull ((2));
  32. #else
  33. # ifdef __REDIRECT_NTH
  34. extern int __REDIRECT_NTH (fstatfs, (int __fildes, struct statfs *__buf),
  35. fstatfs64) __nonnull ((2));
  36. # else
  37. # define fstatfs fstatfs64
  38. # endif
  39. #endif
  40. extern __typeof(fstatfs) __libc_fstatfs;
  41. libc_hidden_proto(__libc_fstatfs)
  42. /* The Linux kernel headers mention this as a kind of generic value. */
  43. #define LINUX_LINK_MAX 127
  44. /* Get file-specific information about descriptor FD. */
  45. long int fpathconf(int fd, int name)
  46. {
  47. if (fd < 0)
  48. {
  49. __set_errno (EBADF);
  50. return -1;
  51. }
  52. if (name == _PC_LINK_MAX)
  53. {
  54. /* Cut some corners */
  55. #if 0
  56. struct statfs fsbuf;
  57. /* Determine the filesystem type. */
  58. if (__libc_fstatfs (fd, &fsbuf) < 0)
  59. {
  60. if (errno == ENOSYS)
  61. /* not possible, return the default value. */
  62. return LINUX_LINK_MAX;
  63. /* Some error occured. */
  64. return -1;
  65. }
  66. switch (fsbuf.f_type)
  67. {
  68. case EXT2_SUPER_MAGIC:
  69. return EXT2_LINK_MAX;
  70. case MINIX_SUPER_MAGIC:
  71. case MINIX_SUPER_MAGIC2:
  72. return MINIX_LINK_MAX;
  73. case MINIX2_SUPER_MAGIC:
  74. case MINIX2_SUPER_MAGIC2:
  75. return MINIX2_LINK_MAX;
  76. case XENIX_SUPER_MAGIC:
  77. return XENIX_LINK_MAX;
  78. case SYSV4_SUPER_MAGIC:
  79. case SYSV2_SUPER_MAGIC:
  80. return SYSV_LINK_MAX;
  81. case COH_SUPER_MAGIC:
  82. return COH_LINK_MAX;
  83. case UFS_MAGIC:
  84. case UFS_CIGAM:
  85. return UFS_LINK_MAX;
  86. case REISERFS_SUPER_MAGIC:
  87. return REISERFS_LINK_MAX;
  88. default:
  89. return LINUX_LINK_MAX;
  90. }
  91. #else
  92. return LINUX_LINK_MAX;
  93. #endif
  94. }
  95. switch (name)
  96. {
  97. default:
  98. __set_errno (EINVAL);
  99. return -1;
  100. case _PC_MAX_CANON:
  101. #ifdef MAX_CANON
  102. return MAX_CANON;
  103. #else
  104. return -1;
  105. #endif
  106. case _PC_MAX_INPUT:
  107. #ifdef MAX_INPUT
  108. return MAX_INPUT;
  109. #else
  110. return -1;
  111. #endif
  112. case _PC_NAME_MAX:
  113. #ifdef NAME_MAX
  114. {
  115. struct statfs buf;
  116. int save_errno = errno;
  117. if (__libc_fstatfs (fd, &buf) < 0)
  118. {
  119. if (errno == ENOSYS)
  120. {
  121. errno = save_errno;
  122. return NAME_MAX;
  123. }
  124. return -1;
  125. }
  126. else
  127. {
  128. #ifdef _STATFS_F_NAMELEN
  129. return buf.f_namelen;
  130. #else
  131. # ifdef _STATFS_F_NAME_MAX
  132. return buf.f_name_max;
  133. # else
  134. return NAME_MAX;
  135. # endif
  136. #endif
  137. }
  138. }
  139. #else
  140. return -1;
  141. #endif
  142. case _PC_PATH_MAX:
  143. #ifdef PATH_MAX
  144. return PATH_MAX;
  145. #else
  146. return -1;
  147. #endif
  148. case _PC_PIPE_BUF:
  149. #ifdef PIPE_BUF
  150. return PIPE_BUF;
  151. #else
  152. return -1;
  153. #endif
  154. case _PC_CHOWN_RESTRICTED:
  155. #ifdef _POSIX_CHOWN_RESTRICTED
  156. return _POSIX_CHOWN_RESTRICTED;
  157. #else
  158. return -1;
  159. #endif
  160. case _PC_NO_TRUNC:
  161. #ifdef _POSIX_NO_TRUNC
  162. return _POSIX_NO_TRUNC;
  163. #else
  164. return -1;
  165. #endif
  166. case _PC_VDISABLE:
  167. #ifdef _POSIX_VDISABLE
  168. return _POSIX_VDISABLE;
  169. #else
  170. return -1;
  171. #endif
  172. case _PC_SYNC_IO:
  173. #ifdef _POSIX_SYNC_IO
  174. return _POSIX_SYNC_IO;
  175. #else
  176. return -1;
  177. #endif
  178. case _PC_ASYNC_IO:
  179. #if defined _POSIX_ASYNC_IO && defined __UCLIBC_HAS_LFS__
  180. {
  181. /* AIO is only allowed on regular files and block devices. */
  182. struct stat st;
  183. if (fstat (fd, &st) < 0 || (! S_ISREG (st.st_mode) && ! S_ISBLK (st.st_mode)))
  184. return -1;
  185. else
  186. return 1;
  187. }
  188. #else
  189. return -1;
  190. #endif
  191. case _PC_PRIO_IO:
  192. #ifdef _POSIX_PRIO_IO
  193. return _POSIX_PRIO_IO;
  194. #else
  195. return -1;
  196. #endif
  197. case _PC_SOCK_MAXBUF:
  198. #ifdef SOCK_MAXBUF
  199. return SOCK_MAXBUF;
  200. #else
  201. return -1;
  202. #endif
  203. case _PC_FILESIZEBITS:
  204. #ifdef FILESIZEBITS
  205. return FILESIZEBITS;
  206. #else
  207. /* We let platforms with larger file sizes overwrite this value. */
  208. return 32;
  209. #endif
  210. /* Be lazy -- skip these */
  211. case _PC_REC_INCR_XFER_SIZE:
  212. case _PC_REC_MAX_XFER_SIZE:
  213. case _PC_REC_MIN_XFER_SIZE:
  214. case _PC_REC_XFER_ALIGN:
  215. case _PC_ALLOC_SIZE_MIN:
  216. case _PC_SYMLINK_MAX:
  217. return -1;
  218. }
  219. }