Changeset 73c09b3b in rtems
- Timestamp:
- 05/30/12 11:40:34 (11 years ago)
- Branches:
- 4.11, 5, master
- Children:
- f164ae75
- Parents:
- 2c6cc3c
- git-author:
- Sebastian Huber <sebastian.huber@…> (05/30/12 11:40:34)
- git-committer:
- Sebastian Huber <sebastian.huber@…> (05/31/12 09:05:48)
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
cpukit/libblock/Makefile.am
r2c6cc3c r73c09b3b 9 9 src/blkdev-ops.c \ 10 10 src/diskdevs.c \ 11 src/diskdevs-init.c \ 11 12 src/flashdisk.c \ 12 13 src/ramdisk-driver.c \ -
cpukit/libblock/include/rtems/bdbuf.h
r2c6cc3c r73c09b3b 142 142 * to another requester until released back to the cache. The same goes to a 143 143 * buffer in the transfer state. The transfer state means being read or 144 * written. If the file system has modif ed the block and releases it as144 * written. If the file system has modified the block and releases it as 145 145 * modified it placed on the cache's modified list and a hold timer 146 146 * initialised. The buffer is held for the hold time before being written to … … 463 463 /** 464 464 * Get block buffer for data to be written into. The buffers is set to the 465 * access or modif ed access state. If the buffer is in the cache and modified465 * access or modified access state. If the buffer is in the cache and modified 466 466 * the state is access modified else the state is access. This buffer contents 467 467 * are not initialised if the buffer is not already in the cache. If the block … … 499 499 * Get the block buffer and if not already in the cache read from the disk. If 500 500 * specified block already cached return. The buffer is set to the access or 501 * modif ed access state. If the buffer is in the cache and modified the state501 * modified access state. If the buffer is in the cache and modified the state 502 502 * is access modified else the state is access. If block is already being read 503 503 * from disk for being written to disk this call blocks. If the buffer is … … 602 602 * Synchronize all modified buffers for this device with the disk and wait 603 603 * until the transfers have completed. The sync mutex for the cache is locked 604 * stopping the addition of any further modif ed buffers. It is only the604 * stopping the addition of any further modified buffers. It is only the 605 605 * currently modified buffers that are written. 606 606 * … … 636 636 * @brief Sets the block size of a disk device. 637 637 * 638 * This will also change the block_to_media_block_shift and bds_per_group 639 * fields of the disk device. 638 * This will set the block size derived fields of the disk device. 640 639 * 641 640 * Before you can use this function, the rtems_bdbuf_init() routine must be -
cpukit/libblock/include/rtems/diskdevs.h
r2c6cc3c r73c09b3b 93 93 94 94 /** 95 * @brief Start block number.96 * 97 * Equals zero for physical devices. It is a block offset to the related98 * physical device for logical device.95 * @brief Start media block number. 96 * 97 * Equals zero for physical devices. It is a media block offset to the 98 * related physical device for logical device. 99 99 */ 100 100 rtems_blkdev_bnum start; 101 101 102 102 /** 103 * @brief Size of the physical or logical disk in blocks.103 * @brief Size of the physical or logical disk in media blocks. 104 104 */ 105 105 rtems_blkdev_bnum size; 106 106 107 107 /** 108 * @brief Device block size in bytes. 109 * 110 * This is the minimum transfer unit. It must be positive. 108 * @brief Media block size in bytes. 109 * 110 * This is the media transfer unit the hardware defaults to. 111 */ 112 uint32_t media_block_size; 113 114 /** 115 * @brief Block size in bytes. 116 * 117 * This is the minimum transfer unit. It may be a multiple of the media 118 * block size. It must be positive. 111 119 * 112 120 * @see rtems_bdbuf_set_block_size(). … … 115 123 116 124 /** 117 * @brief Device media block size in bytes. 118 * 119 * This is the media transfer unit the hardware defaults to. 120 */ 121 uint32_t media_block_size; 125 * @brief Block count. 126 * 127 * @see rtems_bdbuf_set_block_size(). 128 */ 129 rtems_blkdev_bnum block_count; 130 131 /** 132 * @brief Media blocks per device blocks. 133 * 134 * @see rtems_bdbuf_set_block_size(). 135 */ 136 uint32_t media_blocks_per_block; 122 137 123 138 /** … … 260 275 * A logical disk manages a subset of consecutive blocks contained in the 261 276 * physical disk with identifier @a phys. The start block index of the logical 262 * disk device is @a b egin_block. The block count of the logcal disk will be277 * disk device is @a block_begin. The block count of the logcal disk will be 263 278 * @a block_count. The blocks must be within the range of blocks managed by 264 279 * the associated physical disk device. A device node will be registered in … … 279 294 dev_t dev, 280 295 dev_t phys, 281 rtems_blkdev_bnum b egin_block,296 rtems_blkdev_bnum block_begin, 282 297 rtems_blkdev_bnum block_count, 283 298 const char *name … … 374 389 rtems_disk_device *rtems_disk_next(dev_t dev); 375 390 391 /* Internal function, do not use */ 392 rtems_status_code rtems_disk_init_phys( 393 rtems_disk_device *dd, 394 uint32_t block_size, 395 rtems_blkdev_bnum block_count, 396 rtems_block_device_ioctl handler, 397 void *driver_data 398 ); 399 400 /* Internal function, do not use */ 401 rtems_status_code rtems_disk_init_log( 402 rtems_disk_device *dd, 403 rtems_disk_device *phys_dd, 404 rtems_blkdev_bnum block_begin, 405 rtems_blkdev_bnum block_count 406 ); 407 376 408 #ifdef __cplusplus 377 409 } -
cpukit/libblock/src/bdbuf.c
r2c6cc3c r73c09b3b 1755 1755 rtems_blkdev_bnum *media_block_ptr) 1756 1756 { 1757 /* 1758 * Compute the media block number. Drivers work with media block number not 1759 * the block number a BD may have as this depends on the block size set by 1760 * the user. 1761 */ 1762 rtems_blkdev_bnum mb = rtems_bdbuf_media_block (dd, block); 1763 if (mb >= dd->size) 1764 { 1765 return RTEMS_INVALID_ID; 1766 } 1767 1768 *media_block_ptr = mb + dd->start; 1769 1770 return RTEMS_SUCCESSFUL; 1757 rtems_status_code sc = RTEMS_SUCCESSFUL; 1758 1759 if (block < dd->block_count) 1760 { 1761 /* 1762 * Compute the media block number. Drivers work with media block number not 1763 * the block number a BD may have as this depends on the block size set by 1764 * the user. 1765 */ 1766 *media_block_ptr = rtems_bdbuf_media_block (dd, block) + dd->start; 1767 } 1768 else 1769 { 1770 sc = RTEMS_INVALID_ID; 1771 } 1772 1773 return sc; 1771 1774 } 1772 1775 … … 2910 2913 2911 2914 dd->block_size = block_size; 2915 dd->block_count = dd->size / media_blocks_per_block; 2916 dd->media_blocks_per_block = media_blocks_per_block; 2912 2917 dd->block_to_media_block_shift = block_to_media_block_shift; 2913 2918 dd->bds_per_group = bds_per_group; -
cpukit/libblock/src/blkdev-imfs.c
r2c6cc3c r73c09b3b 270 270 { 271 271 rtems_status_code sc = RTEMS_SUCCESSFUL; 272 273 if (block_count > 0) { 274 rtems_blkdev_imfs_context *ctx = calloc(1, sizeof(*ctx)); 275 276 if (ctx != NULL) { 277 rtems_disk_device *dd = &ctx->dd; 278 279 ctx->fd = -1; 280 281 dd->phys_dev = dd; 282 dd->size = block_count; 283 dd->media_block_size = block_size; 284 dd->ioctl = handler; 285 dd->driver_data = driver_data; 286 287 if ((*handler)(dd, RTEMS_BLKIO_CAPABILITIES, &dd->capabilities) != 0) { 288 dd->capabilities = 0; 289 } 290 291 sc = rtems_bdbuf_set_block_size(dd, block_size); 292 if (sc == RTEMS_SUCCESSFUL) { 293 int rv = IMFS_make_generic_node( 294 device, 295 S_IFBLK | S_IRWXU | S_IRWXG | S_IRWXO, 296 &rtems_blkdev_imfs_control, 297 ctx 298 ); 299 300 if (rv != 0) { 301 free(ctx); 302 sc = RTEMS_UNSATISFIED; 303 } 304 } else { 272 rtems_blkdev_imfs_context *ctx = malloc(sizeof(*ctx)); 273 274 if (ctx != NULL) { 275 sc = rtems_disk_init_phys( 276 &ctx->dd, 277 block_size, 278 block_count, 279 handler, 280 driver_data 281 ); 282 283 ctx->fd = -1; 284 285 if (sc == RTEMS_SUCCESSFUL) { 286 int rv = IMFS_make_generic_node( 287 device, 288 S_IFBLK | S_IRWXU | S_IRWXG | S_IRWXO, 289 &rtems_blkdev_imfs_control, 290 ctx 291 ); 292 293 if (rv != 0) { 305 294 free(ctx); 306 } 307 } else { 308 sc = RTEMS_NO_MEMORY; 309 } 310 } else { 311 sc = RTEMS_INVALID_NUMBER; 295 sc = RTEMS_UNSATISFIED; 296 } 297 } else { 298 free(ctx); 299 } 300 } else { 301 sc = RTEMS_NO_MEMORY; 312 302 } 313 303 … … 331 321 rv = fstat(fd, &st); 332 322 if (rv == 0 && S_ISBLK(st.st_mode)) { 333 rtems_disk_device * dd;334 335 rv = rtems_disk_fd_get_disk_device(fd, & dd);323 rtems_disk_device *phys_dd; 324 325 rv = rtems_disk_fd_get_disk_device(fd, &phys_dd); 336 326 if (rv == 0) { 337 rtems_blkdev_bnum device_block_count = rtems_disk_get_block_count(dd); 338 339 if ( 340 block_begin < device_block_count 341 && block_count > 0 342 && block_count <= device_block_count - block_begin 343 ) { 344 rtems_blkdev_imfs_context *ctx = malloc(sizeof(*ctx)); 345 346 if (ctx != NULL) { 347 memcpy(&ctx->dd, dd, sizeof(ctx->dd)); 348 349 ctx->dd.start = block_begin; 350 ctx->dd.size = block_count; 327 rtems_blkdev_imfs_context *ctx = malloc(sizeof(*ctx)); 328 329 if (ctx != NULL) { 330 sc = rtems_disk_init_log( 331 &ctx->dd, 332 phys_dd, 333 block_begin, 334 block_count 335 ); 336 337 if (sc == RTEMS_SUCCESSFUL) { 351 338 ctx->fd = fd; 352 339 … … 363 350 } 364 351 } else { 365 sc = RTEMS_NO_MEMORY;352 free(ctx); 366 353 } 367 354 } else { 368 sc = RTEMS_ INVALID_NUMBER;355 sc = RTEMS_NO_MEMORY; 369 356 } 370 357 } else { -
cpukit/libblock/src/diskdevs.c
r2c6cc3c r73c09b3b 11 11 * Author: Victor V. Vengerov <vvv@oktet.ru> 12 12 * 13 * Copyright (c) 2009 embedded brains GmbH.13 * Copyright (c) 2009-2012 embedded brains GmbH. 14 14 */ 15 15 … … 171 171 172 172 static rtems_status_code 173 create_disk(dev_t dev, const char *name, rtems_disk_device **dd_ptr) 173 create_disk( 174 dev_t dev, 175 const char *name, 176 rtems_disk_device **dd_ptr, 177 char **alloc_name_ptr 178 ) 174 179 { 175 180 rtems_disk_device **dd_entry = create_disk_table_entry(dev); … … 208 213 } 209 214 210 dd->dev = dev;211 dd->name = alloc_name;212 dd->uses = 0;213 dd->deleted = false;214 215 215 *dd_entry = dd; 216 216 *dd_ptr = dd; 217 *alloc_name_ptr = alloc_name; 217 218 218 219 return RTEMS_SUCCESSFUL; … … 239 240 rtems_disk_device *dd = NULL; 240 241 rtems_status_code sc = RTEMS_SUCCESSFUL; 242 char *alloc_name = NULL; 241 243 242 244 if (handler == NULL) { … … 249 251 } 250 252 251 sc = create_disk(dev, name, &dd );253 sc = create_disk(dev, name, &dd, &alloc_name); 252 254 if (sc != RTEMS_SUCCESSFUL) { 253 255 disk_unlock(); … … 256 258 } 257 259 258 dd->phys_dev = dd; 259 dd->start = 0; 260 dd->size = block_count; 261 dd->media_block_size = block_size; 262 dd->ioctl = handler; 263 dd->driver_data = driver_data; 264 265 if ((*handler)(dd, RTEMS_BLKIO_CAPABILITIES, &dd->capabilities) < 0) { 266 dd->capabilities = 0; 267 } 268 269 sc = rtems_bdbuf_set_block_size(dd, block_size); 260 sc = rtems_disk_init_phys( 261 dd, 262 block_size, 263 block_count, 264 handler, 265 driver_data 266 ); 267 268 dd->dev = dev; 269 dd->name = alloc_name; 270 270 271 if (sc != RTEMS_SUCCESSFUL) { 271 272 dd->ioctl = null_handler; … … 290 291 dev_t dev, 291 292 dev_t phys, 292 rtems_blkdev_bnum b egin_block,293 rtems_blkdev_bnum block_begin, 293 294 rtems_blkdev_bnum block_count, 294 295 const char *name … … 296 297 { 297 298 rtems_status_code sc = RTEMS_SUCCESSFUL; 298 rtems_disk_device *phys ical_disk= NULL;299 rtems_disk_device *phys_dd = NULL; 299 300 rtems_disk_device *dd = NULL; 300 rtems_blkdev_bnum end_block = begin_block + block_count;301 char *alloc_name = NULL; 301 302 302 303 sc = disk_lock(); … … 305 306 } 306 307 307 phys ical_disk= get_disk_entry(phys, true);308 if (phys ical_disk == NULL || !is_physical_disk(physical_disk)) {308 phys_dd = get_disk_entry(phys, true); 309 if (phys_dd == NULL) { 309 310 disk_unlock(); 310 311 … … 312 313 } 313 314 314 if ( 315 begin_block >= physical_disk->size 316 || end_block <= begin_block 317 || end_block > physical_disk->size 318 ) { 315 sc = create_disk(dev, name, &dd, &alloc_name); 316 if (sc != RTEMS_SUCCESSFUL) { 319 317 disk_unlock(); 320 318 321 return RTEMS_INVALID_NUMBER; 322 } 323 324 sc = create_disk(dev, name, &dd); 325 if (sc != RTEMS_SUCCESSFUL) { 319 return sc; 320 } 321 322 sc = rtems_disk_init_log( 323 dd, 324 phys_dd, 325 block_begin, 326 block_count 327 ); 328 329 dd->dev = dev; 330 dd->name = alloc_name; 331 332 ++phys_dd->uses; 333 334 if (sc != RTEMS_SUCCESSFUL) { 335 dd->ioctl = null_handler; 336 rtems_disk_delete(dev); 326 337 disk_unlock(); 327 338 328 339 return sc; 329 340 } 330 331 dd->phys_dev = physical_disk;332 dd->start = begin_block;333 dd->size = block_count;334 dd->block_size = physical_disk->block_size;335 dd->media_block_size = physical_disk->media_block_size;336 dd->block_to_media_block_shift = physical_disk->block_to_media_block_shift;337 dd->bds_per_group = physical_disk->bds_per_group;338 dd->ioctl = physical_disk->ioctl;339 dd->driver_data = physical_disk->driver_data;340 341 ++physical_disk->uses;342 341 343 342 disk_unlock(); -
testsuites/libtests/block01/init.c
r2c6cc3c r73c09b3b 184 184 ASSERT_SC_EQ(sc, RTEMS_RESOURCE_IN_USE); 185 185 186 sc = rtems_disk_create_log(logical_2_dev, logical_dev, 0, 1, "/dev/rda 1");186 sc = rtems_disk_create_log(logical_2_dev, logical_dev, 0, 1, "/dev/rda2"); 187 187 ASSERT_SC_EQ(sc, RTEMS_INVALID_ID); 188 188
Note: See TracChangeset
for help on using the changeset viewer.