main() { cd_t cds[NO_CDS]; int count = 0; /* how many CDs are being tracked */ int i; /* loop counter */ puts("Welcome to the CD database."); printf("You can store a maximum of %d CDs.\n", sizeof cds / sizeof cds); /* * Loop until they no longer wish to enter any more CDs */ for (;;) /* forever loops are convenient for this sort of thing */ { /* * Ask them if they want to enter another CD */ if (!yesno("\nHave you any more CDs to enter")) break; printf("\nPlease enter the details of CD %d...\n\n", count+1); /* * Read all the CD details */ read_cd(&cds[count]); /* * Check if we have filled up the array */ if (++count == NO_CDS) /* note the increment happens before the test */ { enter("You have reached the limits of this program\n" "Press ENTER to continue: "); break; } } /* * Output the CD details */ for (i = 0; i < count; i++) { printf("\nThe details of CD %d are:\n", i+1); print_cd(&cds[i]); if (i < count - 1) /* only do this if there are more CDs to see */ enter("\nPress ENTER to see the next set of details: "); } /* * Exit the program */ enter("\nPress ENTER to exit the program: "); }
int read_audio_through_read_cd(cd_device *dev, uint_t start_lba, uint_t nblks, uchar_t *buf) { int retry; int ret; for (retry = 0; retry < 3; retry++) { ret = read_cd(dev->d_fd, (uint32_t)start_lba, (uint16_t)nblks, 1, buf, (uint32_t)(nblks * 2352)); if (ret) break; } return (ret); }
int main() { int count = 0; // How many CDs are being tracked int i; // Loop counter puts("Welcome to the CD database"); printf("You can store a maximum of %d CDs\n\n", sizeof cds / sizeof cds[0]); // Loop until user no longer wish to enter any more CDs for (;;) { // Ask the user if they want to enter another CD if (!yesno("\nDo you have any more CDs to enter")) break; printf("Please enter the details of CD %d...\n", count+1); // Read all the CD details read_cd(&cds[count]); // Check if array has been filled up if (++count == MAX_CDS) // Note increment happens before the test { enter("You have reached the limits of this program\n" "Press ENTER to exit the program"); break; } } // Output the details of the CD for (i = 0; i < count; i++) { printf("\nThe details of CD %d are:\n", i+1); print_cd(&cds[i]); // Only do this if there are more CDs to see if (i < count - 1) { // User-friendly way to progress to the next CD enter("\nPress ENTER to see the next set of details: "); } } // User-friendly way to exit the program enter("\nPress ENTER to exit the program "); }
static status_t cd_ioctl(void* cookie, uint32 op, void* buffer, size_t length) { cd_handle* handle = (cd_handle*)cookie; cd_driver_info *info = handle->info; TRACE("ioctl(op = %lu)\n", op); switch (op) { case B_GET_DEVICE_SIZE: { status_t status = update_capacity(info); if (status != B_OK) return status; size_t size = info->capacity * info->block_size; return user_memcpy(buffer, &size, sizeof(size_t)); } case B_GET_GEOMETRY: { if (buffer == NULL /*|| length != sizeof(device_geometry)*/) return B_BAD_VALUE; device_geometry geometry; status_t status = get_geometry(handle, &geometry); if (status != B_OK) return status; return user_memcpy(buffer, &geometry, sizeof(device_geometry)); } case B_GET_ICON_NAME: return user_strlcpy((char*)buffer, "devices/drive-optical", B_FILE_NAME_LENGTH); case B_GET_VECTOR_ICON: { device_icon iconData; if (length != sizeof(device_icon)) return B_BAD_VALUE; if (user_memcpy(&iconData, buffer, sizeof(device_icon)) != B_OK) return B_BAD_ADDRESS; if (iconData.icon_size >= (int32)sizeof(kCDIcon)) { if (user_memcpy(iconData.icon_data, kCDIcon, sizeof(kCDIcon)) != B_OK) return B_BAD_ADDRESS; } iconData.icon_size = sizeof(kCDIcon); return user_memcpy(buffer, &iconData, sizeof(device_icon)); } case B_SCSI_GET_TOC: // TODO: we pass a user buffer here! return get_toc(info, (scsi_toc *)buffer); case B_EJECT_DEVICE: case B_SCSI_EJECT: return load_eject(info, false); case B_LOAD_MEDIA: return load_eject(info, true); case B_SCSI_GET_POSITION: { if (buffer == NULL) return B_BAD_VALUE; scsi_position position; status_t status = get_position(info, &position); if (status != B_OK) return status; return user_memcpy(buffer, &position, sizeof(scsi_position)); } case B_SCSI_GET_VOLUME: // TODO: we pass a user buffer here! return get_set_volume(info, (scsi_volume *)buffer, false); case B_SCSI_SET_VOLUME: // TODO: we pass a user buffer here! return get_set_volume(info, (scsi_volume *)buffer, true); case B_SCSI_PLAY_TRACK: { scsi_play_track track; if (user_memcpy(&track, buffer, sizeof(scsi_play_track)) != B_OK) return B_BAD_ADDRESS; return play_track_index(info, &track); } case B_SCSI_PLAY_POSITION: { scsi_play_position position; if (user_memcpy(&position, buffer, sizeof(scsi_play_position)) != B_OK) return B_BAD_ADDRESS; return play_msf(info, &position); } case B_SCSI_STOP_AUDIO: return stop_audio(info); case B_SCSI_PAUSE_AUDIO: return pause_resume(info, false); case B_SCSI_RESUME_AUDIO: return pause_resume(info, true); case B_SCSI_SCAN: { scsi_scan scanBuffer; if (user_memcpy(&scanBuffer, buffer, sizeof(scsi_scan)) != B_OK) return B_BAD_ADDRESS; return scan(info, &scanBuffer); } case B_SCSI_READ_CD: // TODO: we pass a user buffer here! return read_cd(info, (scsi_read_cd *)buffer); default: return sSCSIPeripheral->ioctl(handle->scsi_periph_handle, op, buffer, length); } }