void test_ramdisk(void) { uint8_t user_input = '2'; struct record_t test; struct record_t local_copy; struct record_t test_t; srand(cph_get_millis()); test.wan_msg.tagMac = 1; test.wan_msg.tagBattery = 2; test.wan_msg.tagRssi = 3; struct record_t test_2; local_copy = test; ramdisk_init(); while(true) { test_2.wan_msg.tagMac = rand(); test_2.wan_msg.tagRssi = rand() % 65535; test_2.wan_msg.tagBattery = rand() % 65535; test_2.next = NULL; if(user_input == '2') ramdisk_write(test_2); else if(user_input =='1') ramdisk_write(test); else if(user_input == 'f') local_copy = *ramdisk_next(ramdisk_find(test.wan_msg.tagMac)); else if(user_input == 'p') print_records(); else if(user_input == 'e') ramdisk_erase(local_copy); else if(user_input == 'r') local_copy = test; else user_input = 'q'; // scanf(" %c", &user_input); if(user_input == 'q') break; } }
int ramdisk_ioctl(rtems_disk_device *dd, uint32_t req, void *argp) { switch (req) { case RTEMS_BLKIO_REQUEST: { rtems_blkdev_request *r = argp; struct ramdisk *rd = rtems_disk_get_driver_data(dd); switch (r->req) { case RTEMS_BLKDEV_REQ_READ: return ramdisk_read(rd, r); case RTEMS_BLKDEV_REQ_WRITE: return ramdisk_write(rd, r); default: errno = EINVAL; return -1; } break; } default: return rtems_blkdev_ioctl (dd, req, argp); break; } errno = EINVAL; return -1; }
/* ramdisk_ioctl -- * IOCTL handler for RAM disk device. * * PARAMETERS: * dev - device number (major, minor number) * req - IOCTL request code * argp - IOCTL argument * * RETURNS: * IOCTL return value */ static int ramdisk_ioctl(dev_t dev, uint32_t req, void *argp) { switch (req) { case BLKIO_REQUEST: { rtems_device_minor_number minor; blkdev_request *r = argp; struct ramdisk *rd; minor = rtems_filesystem_dev_minor_t(dev); if ((minor >= nramdisks) || !ramdisk[minor].initialized) { errno = ENODEV; return -1; } rd = ramdisk + minor; switch (r->req) { case BLKDEV_REQ_READ: return ramdisk_read(rd, r); case BLKDEV_REQ_WRITE: return ramdisk_write(rd, r); default: errno = EBADRQC; return -1; } break; } default: errno = EBADRQC; return -1; } }