pathconf.c 4.7 KB

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