alt_file.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. #ifndef __ALT_FILE_H__
  2. #define __ALT_FILE_H__
  3. /******************************************************************************
  4. * *
  5. * License Agreement *
  6. * *
  7. * Copyright (c) 2004 Altera Corporation, San Jose, California, USA. *
  8. * All rights reserved. *
  9. * *
  10. * Permission is hereby granted, free of charge, to any person obtaining a *
  11. * copy of this software and associated documentation files (the "Software"), *
  12. * to deal in the Software without restriction, including without limitation *
  13. * the rights to use, copy, modify, merge, publish, distribute, sublicense, *
  14. * and/or sell copies of the Software, and to permit persons to whom the *
  15. * Software is furnished to do so, subject to the following conditions: *
  16. * *
  17. * The above copyright notice and this permission notice shall be included in *
  18. * all copies or substantial portions of the Software. *
  19. * *
  20. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
  21. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
  22. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
  23. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
  24. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
  25. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
  26. * DEALINGS IN THE SOFTWARE. *
  27. * *
  28. * This agreement shall be governed in all respects by the laws of the State *
  29. * of California and by the laws of the United States of America. *
  30. * *
  31. * Altera does not recommend, suggest or require that this reference design *
  32. * file be used in conjunction or combination with any other product. *
  33. ******************************************************************************/
  34. /******************************************************************************
  35. * *
  36. * THIS IS A LIBRARY READ-ONLY SOURCE FILE. DO NOT EDIT. *
  37. * *
  38. ******************************************************************************/
  39. #include "sys/alt_dev.h"
  40. #include "sys/alt_llist.h"
  41. #include "os/alt_sem.h"
  42. #include "alt_types.h"
  43. /*
  44. * This header provides the internal defenitions required to control file
  45. * access. These variables and functions are not guaranteed to exist in
  46. * future implementations of the HAL.
  47. */
  48. #ifdef __cplusplus
  49. extern "C"
  50. {
  51. #endif /* __cplusplus */
  52. /*
  53. * The function alt_find_dev() is used to search the device list "list" to
  54. * locate a device named "name". If a match is found, then a pointer to the
  55. * device is returned, otherwise NULL is returned.
  56. */
  57. extern alt_dev* alt_find_dev (const char* name, alt_llist* list);
  58. /*
  59. * alt_find_file() is used to search the list of registered file systems to
  60. * find the filesystem that the file named "name" belongs to. If a match is
  61. * found, then a pointer to the filesystems alt_dev structure is returned,
  62. * otherwise NULL is returned.
  63. *
  64. * Note that a match does not indicate that the file exists, only that a
  65. * filesystem exists that is registered for a partition that could contain
  66. * the file. The filesystems open() function would need to be called in order
  67. * to determine if the file exists.
  68. */
  69. extern alt_dev* alt_find_file (const char* name);
  70. /*
  71. * alt_get_fd() is used to allocate a file descriptor for the device or
  72. * filesystem "dev". A negative return value indicates an error, otherwise the
  73. * return value is the index of the file descriptor within the file descriptor
  74. * pool.
  75. */
  76. extern int alt_get_fd (alt_dev* dev);
  77. /*
  78. * alt_release_fd() is called to free the file descriptor with index "fd".
  79. */
  80. extern void alt_release_fd (int fd);
  81. /*
  82. * alt_fd_lock() is called by ioctl() to mark the file descriptor "fd" as
  83. * being open for exclusive access. Subsequent calls to open() for the device
  84. * associated with "fd" will fail. A device is unlocked by either calling
  85. * close() for "fd", or by an alternate call to ioctl() (see ioctl.c for
  86. * details).
  87. */
  88. extern int alt_fd_lock (alt_fd* fd);
  89. /*
  90. * alt_fd_unlock() is called by ioctl() to unlock a descriptor previously
  91. * locked by a call to alt_fd_lock().
  92. */
  93. extern int alt_fd_unlock (alt_fd* fd);
  94. /*
  95. * "alt_fd_list" is the pool of file descriptors.
  96. */
  97. extern alt_fd alt_fd_list[];
  98. /*
  99. * flags used by alt_fd.
  100. *
  101. * ALT_FD_EXCL is used to mark a file descriptor as locked for exclusive
  102. * access, i.e. further calls to open() for the associated device should
  103. * fail.
  104. *
  105. * ALT_FD_DEV marks a dile descriptor as belonging to a device as oposed to a
  106. * filesystem.
  107. */
  108. #define ALT_FD_EXCL 0x80000000
  109. #define ALT_FD_DEV 0x40000000
  110. #define ALT_FD_FLAGS_MASK (ALT_FD_EXCL | ALT_FD_DEV)
  111. /*
  112. * "alt_dev_list" is the head of the linked list of registered devices.
  113. */
  114. extern alt_llist alt_dev_list;
  115. /*
  116. * "alt_fs_list" is the head of the linked list of registered filesystems.
  117. */
  118. extern alt_llist alt_fs_list;
  119. /*
  120. * "alt_fd_list_lock" is a semaphore used to ensure that access to the pool
  121. * of file descriptors is thread safe.
  122. */
  123. ALT_EXTERN_SEM(alt_fd_list_lock)
  124. /*
  125. * "alt_max_fd" is a 'high water mark'. It indicates the highest file
  126. * descriptor allocated. Use of this can save searching the entire pool
  127. * for active file descriptors, which helps avoid contention on access
  128. * to the file descriptor pool.
  129. */
  130. extern alt_32 alt_max_fd;
  131. /*
  132. * alt_io_redirect() is called at startup to redirect stdout, stdin, and
  133. * stderr to the devices named in the input arguments. By default these streams
  134. * are directed at /dev/null, and are then redirected using this function once
  135. * all of the devices have been registered within the system.
  136. */
  137. extern void alt_io_redirect(const char* stdout_dev,
  138. const char* stdin_dev,
  139. const char* stderr_dev);
  140. #ifdef __cplusplus
  141. }
  142. #endif
  143. #endif /* __ALT_FILE_H__ */