Changeset 945884fe in rtems for cpukit/libblock
- Timestamp:
- 08/06/09 03:58:09 (15 years ago)
- Branches:
- 4.10, 4.11, 5, master
- Children:
- b9ff10f3
- Parents:
- 14d9ae4
- Location:
- cpukit/libblock
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
cpukit/libblock/include/rtems/blkdev.h
r14d9ae4 r945884fe 49 49 */ 50 50 typedef enum rtems_blkdev_request_op { 51 RTEMS_BLKDEV_REQ_READ, 52 RTEMS_BLKDEV_REQ_WRITE, 53 RTEMS_BLKDEV_CAPABILITIES 51 RTEMS_BLKDEV_REQ_READ, /**< Read the requested blocks of data. */ 52 RTEMS_BLKDEV_REQ_WRITE, /**< Write the requested blocks of data. */ 53 RTEMS_BLKDEV_CAPABILITIES /**< Return the driver capabilities set. */ 54 54 } rtems_blkdev_request_op; 55 55 … … 161 161 */ 162 162 163 #define RTEMS_BLKIO_REQUEST _IOWR('B', 1, rtems_blkdev_request) 164 #define RTEMS_BLKIO_GETBLKSIZE _IO('B', 2) 165 #define RTEMS_BLKIO_GETSIZE _IO('B', 3) 166 #define RTEMS_BLKIO_SYNCDEV _IO('B', 4) 163 #define RTEMS_BLKIO_REQUEST _IOWR('B', 1, rtems_blkdev_request) 164 #define RTEMS_BLKIO_GETMEDIABLKSIZE _IO('B', 2) 165 #define RTEMS_BLKIO_GETBLKSIZE _IO('B', 3) 166 #define RTEMS_BLKIO_SETBLKSIZE _IO('B', 4) 167 #define RTEMS_BLKIO_GETSIZE _IO('B', 5) 168 #define RTEMS_BLKIO_SYNCDEV _IO('B', 6) 167 169 168 170 /** @} */ … … 243 245 ); 244 246 247 /** 248 * Common IO control primitive. 249 * 250 * Use this in all block devices to handle the common set of ioctl requests. 251 */ 252 int 253 rtems_blkdev_ioctl(dev_t dev, uint32_t req, void *argp); 254 245 255 /** @} */ 246 256 -
cpukit/libblock/src/bdbuf.c
r14d9ae4 r945884fe 135 135 (((uint32_t)'B' << 24) | ((uint32_t)(n) & (uint32_t)0x00FFFFFF)) 136 136 137 #define RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY RTEMS_BLKDEV_FATAL_ERROR(1) 138 #define RTEMS_BLKDEV_FATAL_BDBUF_SWAPOUT RTEMS_BLKDEV_FATAL_ERROR(2) 139 #define RTEMS_BLKDEV_FATAL_BDBUF_SYNC_LOCK RTEMS_BLKDEV_FATAL_ERROR(3) 140 #define RTEMS_BLKDEV_FATAL_BDBUF_SYNC_UNLOCK RTEMS_BLKDEV_FATAL_ERROR(4) 141 #define RTEMS_BLKDEV_FATAL_BDBUF_CACHE_LOCK RTEMS_BLKDEV_FATAL_ERROR(5) 142 #define RTEMS_BLKDEV_FATAL_BDBUF_CACHE_UNLOCK RTEMS_BLKDEV_FATAL_ERROR(6) 143 #define RTEMS_BLKDEV_FATAL_BDBUF_CACHE_WAIT_1 RTEMS_BLKDEV_FATAL_ERROR(7) 144 #define RTEMS_BLKDEV_FATAL_BDBUF_CACHE_WAIT_2 RTEMS_BLKDEV_FATAL_ERROR(8) 145 #define RTEMS_BLKDEV_FATAL_BDBUF_CACHE_WAIT_3 RTEMS_BLKDEV_FATAL_ERROR(9) 146 #define RTEMS_BLKDEV_FATAL_BDBUF_CACHE_WAKE RTEMS_BLKDEV_FATAL_ERROR(10) 147 #define RTEMS_BLKDEV_FATAL_BDBUF_SO_WAKE RTEMS_BLKDEV_FATAL_ERROR(11) 148 #define RTEMS_BLKDEV_FATAL_BDBUF_SO_NOMEM RTEMS_BLKDEV_FATAL_ERROR(12) 149 #define RTEMS_BLKDEV_FATAL_BDBUF_SO_WK_CREATE RTEMS_BLKDEV_FATAL_ERROR(13) 150 #define RTEMS_BLKDEV_FATAL_BDBUF_SO_WK_START RTEMS_BLKDEV_FATAL_ERROR(14) 151 #define BLKDEV_FATAL_BDBUF_SWAPOUT_RE RTEMS_BLKDEV_FATAL_ERROR(15) 152 #define BLKDEV_FATAL_BDBUF_SWAPOUT_TS RTEMS_BLKDEV_FATAL_ERROR(16) 137 #define RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY_1 RTEMS_BLKDEV_FATAL_ERROR(1) 138 #define RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY_2 RTEMS_BLKDEV_FATAL_ERROR(2) 139 #define RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY_3 RTEMS_BLKDEV_FATAL_ERROR(3) 140 #define RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY_4 RTEMS_BLKDEV_FATAL_ERROR(4) 141 #define RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY_5 RTEMS_BLKDEV_FATAL_ERROR(5) 142 #define RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY_6 RTEMS_BLKDEV_FATAL_ERROR(6) 143 #define RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY_7 RTEMS_BLKDEV_FATAL_ERROR(7) 144 #define RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY_8 RTEMS_BLKDEV_FATAL_ERROR(8) 145 #define RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY_9 RTEMS_BLKDEV_FATAL_ERROR(9) 146 #define RTEMS_BLKDEV_FATAL_BDBUF_SWAPOUT RTEMS_BLKDEV_FATAL_ERROR(10) 147 #define RTEMS_BLKDEV_FATAL_BDBUF_SYNC_LOCK RTEMS_BLKDEV_FATAL_ERROR(11) 148 #define RTEMS_BLKDEV_FATAL_BDBUF_SYNC_UNLOCK RTEMS_BLKDEV_FATAL_ERROR(12) 149 #define RTEMS_BLKDEV_FATAL_BDBUF_CACHE_LOCK RTEMS_BLKDEV_FATAL_ERROR(13) 150 #define RTEMS_BLKDEV_FATAL_BDBUF_CACHE_UNLOCK RTEMS_BLKDEV_FATAL_ERROR(14) 151 #define RTEMS_BLKDEV_FATAL_BDBUF_CACHE_WAIT_1 RTEMS_BLKDEV_FATAL_ERROR(15) 152 #define RTEMS_BLKDEV_FATAL_BDBUF_CACHE_WAIT_2 RTEMS_BLKDEV_FATAL_ERROR(16) 153 #define RTEMS_BLKDEV_FATAL_BDBUF_CACHE_WAIT_3 RTEMS_BLKDEV_FATAL_ERROR(17) 154 #define RTEMS_BLKDEV_FATAL_BDBUF_CACHE_WAKE RTEMS_BLKDEV_FATAL_ERROR(18) 155 #define RTEMS_BLKDEV_FATAL_BDBUF_SO_WAKE RTEMS_BLKDEV_FATAL_ERROR(19) 156 #define RTEMS_BLKDEV_FATAL_BDBUF_SO_NOMEM RTEMS_BLKDEV_FATAL_ERROR(20) 157 #define RTEMS_BLKDEV_FATAL_BDBUF_SO_WK_CREATE RTEMS_BLKDEV_FATAL_ERROR(21) 158 #define RTEMS_BLKDEV_FATAL_BDBUF_SO_WK_START RTEMS_BLKDEV_FATAL_ERROR(22) 159 #define BLKDEV_FATAL_BDBUF_SWAPOUT_RE RTEMS_BLKDEV_FATAL_ERROR(23) 160 #define BLKDEV_FATAL_BDBUF_SWAPOUT_TS RTEMS_BLKDEV_FATAL_ERROR(24) 153 161 154 162 /** … … 877 885 * time. 878 886 * 879 * and you must 880 * hold the sync lock. The sync lock is used to block writes while a sync is 881 * active. 887 * @note Do not lower the group user count as the modified list is a user of 888 * the buffer. 882 889 * 883 890 * @param bd The bd to queue to the cache's modified list. … … 962 969 b++, bd += bufs_per_bd) 963 970 { 971 if ((bd->state == RTEMS_BDBUF_STATE_MODIFIED) || 972 (bd->state == RTEMS_BDBUF_STATE_ACCESS) || 973 (bd->state == RTEMS_BDBUF_STATE_ACCESS_MODIFIED) || 974 (bd->state == RTEMS_BDBUF_STATE_SYNC) || 975 (bd->state == RTEMS_BDBUF_STATE_TRANSFER)) 976 rtems_fatal_error_occurred ((bd->state << 16) | 977 RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY_8); 978 964 979 if ((bd->state == RTEMS_BDBUF_STATE_CACHED) || 965 (bd->state == RTEMS_BDBUF_STATE_MODIFIED) ||966 980 (bd->state == RTEMS_BDBUF_STATE_READ_AHEAD)) 967 981 { 968 982 if (rtems_bdbuf_avl_remove (&bdbuf_cache.tree, bd) != 0) 969 rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY); 970 rtems_chain_extract (&bd->link); 971 } 983 rtems_fatal_error_occurred ((bd->state << 16) | 984 RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY_1); 985 } 986 987 rtems_chain_extract (&bd->link); 972 988 } 973 989 … … 978 994 b < group->bds_per_group; 979 995 b++, bd += bufs_per_bd) 996 { 997 bd->state = RTEMS_BDBUF_STATE_EMPTY; 980 998 rtems_chain_prepend (&bdbuf_cache.ready, &bd->link); 999 } 981 1000 } 982 1001 … … 1005 1024 { 1006 1025 rtems_chain_extract (node); 1007 bd->group->users++;1008 1026 return bd; 1009 1027 } … … 1430 1448 */ 1431 1449 if (rtems_bdbuf_avl_remove (&bdbuf_cache.tree, bd) != 0) 1432 rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY );1450 rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY_2); 1433 1451 } 1434 1452 else … … 1472 1490 if ((bd->state != RTEMS_BDBUF_STATE_EMPTY) && 1473 1491 (bd->state != RTEMS_BDBUF_STATE_READ_AHEAD)) 1474 rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY );1492 rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY_3); 1475 1493 1476 1494 if (bd->state == RTEMS_BDBUF_STATE_READ_AHEAD) 1477 1495 { 1478 1496 if (rtems_bdbuf_avl_remove (&bdbuf_cache.tree, bd) != 0) 1479 rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY );1497 rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY_4); 1480 1498 } 1481 1499 } … … 1492 1510 1493 1511 if (rtems_bdbuf_avl_insert (&bdbuf_cache.tree, bd) != 0) 1494 rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY );1512 rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY_5); 1495 1513 1496 1514 return bd; … … 1553 1571 1554 1572 default: 1555 rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY );1573 rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY_6); 1556 1574 } 1557 1575 } … … 1611 1629 bd->state = RTEMS_BDBUF_STATE_ACCESS; 1612 1630 1631 /* 1632 * Indicate a buffer in this group is being used. 1633 */ 1634 bd->group->users++; 1635 1613 1636 rtems_bdbuf_unlock_cache (); 1614 1637 … … 1735 1758 bd->error = 0; 1736 1759 1760 /* 1761 * The buffer will be passed to the driver so this buffer has a user. 1762 */ 1763 bd->group->users++; 1764 1737 1765 /* 1738 1766 * @todo The use of these req blocks is not a great design. The req is a … … 1817 1845 bd->error = req->error; 1818 1846 bd->state = RTEMS_BDBUF_STATE_READ_AHEAD; 1819 rtems_bdbuf_release (bd); 1847 bd->group->users--; 1848 rtems_chain_prepend (&bdbuf_cache.ready, &bd->link); 1849 1850 /* 1851 * If there is an error remove the BD from the AVL tree as it does is 1852 * invalid, then wake any threads that may be waiting. A thread may have 1853 * been waiting for this block and assumed it was in the tree. 1854 */ 1855 if (bd->error) 1856 { 1857 bd->state = RTEMS_BDBUF_STATE_EMPTY; 1858 if (rtems_bdbuf_avl_remove (&bdbuf_cache.tree, bd) != 0) 1859 rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY_9); 1860 } 1861 1862 if (bd->waiters) 1863 rtems_bdbuf_wake (bdbuf_cache.access, &bdbuf_cache.access_waiters); 1864 else 1865 { 1866 if (rtems_chain_has_only_one_node (&bdbuf_cache.ready)) 1867 rtems_bdbuf_wake (bdbuf_cache.waiting, &bdbuf_cache.wait_waiters); 1868 } 1820 1869 } 1821 1870 1822 1871 bd = req->bufs[0].user; 1872 1873 /* 1874 * One less user. We do this here then increment again so the case of the 1875 * buffer in the the cache and no read leaves the user counts at the 1876 * correct level. 1877 */ 1878 bd->group->users--; 1823 1879 } 1824 1880 … … 1829 1885 bd->state = RTEMS_BDBUF_STATE_ACCESS_MODIFIED; 1830 1886 else 1887 { 1888 /* 1889 * The file system is a user of the buffer. 1890 */ 1891 bd->group->users++; 1831 1892 bd->state = RTEMS_BDBUF_STATE_ACCESS; 1893 } 1832 1894 1833 1895 rtems_bdbuf_unlock_cache (); … … 1970 2032 case RTEMS_BDBUF_STATE_TRANSFER: 1971 2033 bd->waiters++; 1972 rtems_bdbuf_wait (&bdbuf_cache.transfer, &bdbuf_cache.transfer_waiters); 2034 rtems_bdbuf_wait (&bdbuf_cache.transfer, 2035 &bdbuf_cache.transfer_waiters); 1973 2036 bd->waiters--; 1974 2037 break; 1975 2038 1976 2039 default: 1977 rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY );2040 rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY_7); 1978 2041 } 1979 2042 } … … 2212 2275 bd->state = RTEMS_BDBUF_STATE_CACHED; 2213 2276 bd->error = 0; 2277 2278 /* 2279 * The buffer is now not modified so lower the user count for the group. 2280 */ 2214 2281 bd->group->users--; 2215 2282 -
cpukit/libblock/src/blkdev.c
r14d9ae4 r945884fe 18 18 #endif 19 19 20 #include <errno.h> 20 21 #include <string.h> 21 22 … … 219 220 switch (args->command) 220 221 { 222 case RTEMS_BLKIO_GETMEDIABLKSIZE: 223 args->ioctl_return = dd->media_block_size; 224 break; 225 221 226 case RTEMS_BLKIO_GETBLKSIZE: 222 227 args->ioctl_return = dd->block_size; 228 break; 229 230 case RTEMS_BLKIO_SETBLKSIZE: 231 dd->block_size = *((size_t*) args->buffer); 223 232 break; 224 233 … … 249 258 return RTEMS_SUCCESSFUL; 250 259 } 260 261 int 262 rtems_blkdev_ioctl(dev_t dev, uint32_t req, void *argp) 263 { 264 rtems_disk_device *dd; 265 size_t *arg_size = argp; 266 267 dd = rtems_disk_obtain(dev); 268 if (dd == NULL) 269 { 270 errno = ENODEV; 271 return -1; 272 } 273 274 switch (req) 275 { 276 case RTEMS_BLKIO_GETMEDIABLKSIZE: 277 *arg_size = dd->media_block_size; 278 break; 279 280 case RTEMS_BLKIO_GETBLKSIZE: 281 *arg_size = dd->block_size; 282 break; 283 284 case RTEMS_BLKIO_SETBLKSIZE: 285 dd->block_size = *arg_size; 286 break; 287 288 case RTEMS_BLKIO_GETSIZE: 289 *arg_size = dd->size; 290 break; 291 292 default: 293 errno = EINVAL; 294 return -1; 295 break; 296 } 297 298 rtems_disk_release(dd); 299 300 return 0; 301 } -
cpukit/libblock/src/flashdisk.c
r14d9ae4 r945884fe 2411 2411 2412 2412 default: 2413 errno = EINVAL;2413 return rtems_blkdev_ioctl (dev, req, argp); 2414 2414 break; 2415 2415 } -
cpukit/libblock/src/nvdisk.c
r14d9ae4 r945884fe 745 745 746 746 default: 747 errno = EINVAL;747 return rtems_blkdev_ioctl (dev, req, argp); 748 748 break; 749 749 } -
cpukit/libblock/src/ramdisk.c
r14d9ae4 r945884fe 207 207 break; 208 208 } 209 209 210 210 default: 211 errno = EINVAL; 212 return -1; 213 } 211 return rtems_blkdev_ioctl (dev, req, argp); 212 break; 213 } 214 215 errno = EINVAL; 216 return -1; 214 217 } 215 218
Note: See TracChangeset
for help on using the changeset viewer.