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. #if !defined __UCLIBC_LINUX_SPECIFIC__
  30. #ifndef __USE_FILE_OFFSET64
  31. extern int fstatfs (int __fildes, struct statfs *__buf)
  32. __THROW __nonnull ((2));
  33. #else
  34. # ifdef __REDIRECT_NTH
  35. extern int __REDIRECT_NTH (fstatfs, (int __fildes, struct statfs *__buf),
  36. fstatfs64) __nonnull ((2));
  37. # else
  38. # define fstatfs fstatfs64
  39. # endif
  40. #endif
  41. #endif
  42. extern __typeof(fstatfs) __libc_fstatfs;
  43. libc_hidden_proto(__libc_fstatfs)
  44. /* The Linux kernel headers mention this as a kind of generic value. */
  45. #define LINUX_LINK_MAX 127
  46. /* Get file-specific information about descriptor FD. */
  47. long int fpathconf(int fd, int name)
  48. {
  49. if (fd < 0)
  50. {
  51. __set_errno (EBADF);
  52. return -1;
  53. }
  54. if (name == _PC_LINK_MAX)
  55. {
  56. /* Cut some corners */
  57. #if 0
  58. struct statfs fsbuf;
  59. /* Determine the filesystem type. */
  60. if (__libc_fstatfs (fd, &fsbuf) < 0)
  61. {
  62. if (errno == ENOSYS)
  63. /* not possible, return the default value. */
  64. return LINUX_LINK_MAX;
  65. /* Some error occured. */
  66. return -1;
  67. }
  68. switch (fsbuf.f_type)
  69. {
  70. case EXT2_SUPER_MAGIC:
  71. return EXT2_LINK_MAX;
  72. case MINIX_SUPER_MAGIC:
  73. case MINIX_SUPER_MAGIC2:
  74. return MINIX_LINK_MAX;
  75. case MINIX2_SUPER_MAGIC:
  76. case MINIX2_SUPER_MAGIC2:
  77. return MINIX2_LINK_MAX;
  78. case XENIX_SUPER_MAGIC:
  79. return XENIX_LINK_MAX;
  80. case SYSV4_SUPER_MAGIC:
  81. case SYSV2_SUPER_MAGIC:
  82. return SYSV_LINK_MAX;
  83. case COH_SUPER_MAGIC:
  84. return COH_LINK_MAX;
  85. case UFS_MAGIC:
  86. case UFS_CIGAM:
  87. return UFS_LINK_MAX;
  88. case REISERFS_SUPER_MAGIC:
  89. return REISERFS_LINK_MAX;
  90. default:
  91. return LINUX_LINK_MAX;
  92. }
  93. #else
  94. return LINUX_LINK_MAX;
  95. #endif
  96. }
  97. switch (name)
  98. {
  99. default:
  100. __set_errno (EINVAL);
  101. return -1;
  102. case _PC_MAX_CANON:
  103. #ifdef MAX_CANON
  104. return MAX_CANON;
  105. #else
  106. return -1;
  107. #endif
  108. case _PC_MAX_INPUT:
  109. #ifdef MAX_INPUT
  110. return MAX_INPUT;
  111. #else
  112. return -1;
  113. #endif
  114. case _PC_NAME_MAX:
  115. #ifdef NAME_MAX
  116. {
  117. struct statfs buf;
  118. int save_errno = errno;
  119. if (__libc_fstatfs (fd, &buf) < 0)
  120. {
  121. if (errno == ENOSYS)
  122. {
  123. errno = save_errno;
  124. return NAME_MAX;
  125. }
  126. return -1;
  127. }
  128. else
  129. {
  130. #ifdef _STATFS_F_NAMELEN
  131. return buf.f_namelen;
  132. #else
  133. # ifdef _STATFS_F_NAME_MAX
  134. return buf.f_name_max;
  135. # else
  136. return NAME_MAX;
  137. # endif
  138. #endif
  139. }
  140. }
  141. #else
  142. return -1;
  143. #endif
  144. case _PC_PATH_MAX:
  145. #ifdef PATH_MAX
  146. return PATH_MAX;
  147. #else
  148. return -1;
  149. #endif
  150. case _PC_PIPE_BUF:
  151. #ifdef PIPE_BUF
  152. return PIPE_BUF;
  153. #else
  154. return -1;
  155. #endif
  156. case _PC_CHOWN_RESTRICTED:
  157. #ifdef _POSIX_CHOWN_RESTRICTED
  158. return _POSIX_CHOWN_RESTRICTED;
  159. #else
  160. return -1;
  161. #endif
  162. case _PC_NO_TRUNC:
  163. #ifdef _POSIX_NO_TRUNC
  164. return _POSIX_NO_TRUNC;
  165. #else
  166. return -1;
  167. #endif
  168. case _PC_VDISABLE:
  169. #ifdef _POSIX_VDISABLE
  170. return _POSIX_VDISABLE;
  171. #else
  172. return -1;
  173. #endif
  174. case _PC_SYNC_IO:
  175. #ifdef _POSIX_SYNC_IO
  176. return _POSIX_SYNC_IO;
  177. #else
  178. return -1;
  179. #endif
  180. case _PC_ASYNC_IO:
  181. #if defined _POSIX_ASYNC_IO && defined __UCLIBC_HAS_LFS__
  182. {
  183. /* AIO is only allowed on regular files and block devices. */
  184. struct stat st;
  185. if (fstat (fd, &st) < 0 || (! S_ISREG (st.st_mode) && ! S_ISBLK (st.st_mode)))
  186. return -1;
  187. else
  188. return 1;
  189. }
  190. #else
  191. return -1;
  192. #endif
  193. case _PC_PRIO_IO:
  194. #ifdef _POSIX_PRIO_IO
  195. return _POSIX_PRIO_IO;
  196. #else
  197. return -1;
  198. #endif
  199. case _PC_SOCK_MAXBUF:
  200. #ifdef SOCK_MAXBUF
  201. return SOCK_MAXBUF;
  202. #else
  203. return -1;
  204. #endif
  205. case _PC_FILESIZEBITS:
  206. #ifdef FILESIZEBITS
  207. return FILESIZEBITS;
  208. #else
  209. /* We let platforms with larger file sizes overwrite this value. */
  210. return 32;
  211. #endif
  212. /* Be lazy -- skip these */
  213. case _PC_REC_INCR_XFER_SIZE:
  214. case _PC_REC_MAX_XFER_SIZE:
  215. case _PC_REC_MIN_XFER_SIZE:
  216. case _PC_REC_XFER_ALIGN:
  217. case _PC_ALLOC_SIZE_MIN:
  218. case _PC_SYMLINK_MAX:
  219. return -1;
  220. }
  221. }