fpathconf.c 4.6 KB

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