/* * given current profile, use the best method for determining * disc capacity (in bytes) */ boolean_t get_disc_capacity_for_profile(int fd, int profile, uint64_t *capacity) { struct dk_minfo mi; disc_info_t di; boolean_t ret = B_FALSE; switch (profile) { case 0x08: /* CD-ROM */ case 0x10: /* DVD-ROM */ if (get_media_info(fd, &mi) && (mi.dki_capacity > 1)) { *capacity = mi.dki_capacity * mi.dki_lbsize; ret = B_TRUE; } break; default: if (read_format_capacity(fd, capacity) && (*capacity > 0)) { ret = B_TRUE; } else if (get_disc_info(fd, &di) && (di.capacity > 0)) { if (get_media_info(fd, &mi)) { *capacity = di.capacity * mi.dki_lbsize; ret = B_TRUE; } } } return (ret); }
int main(int argc,char **argv) { unsigned char* fbp; if(usb() != 0) { fprintf(stdout,"Faile to mount USB.\n"); exit(1); } if(get_media_info(&my_usb_info) != 0) { fprintf(stdout,"%s:%d:Faled to get usb device information.\n ",__FILE__,__LINE__); exit(1); } if((fbp =init_framebuff(&vinfo,&finfo)) ==NULL) { fprintf(stdout,"Failed to init framebuff.\n"); exit(1); } int code; pthread_t pthread_key_ctr; if((code = pthread_create(&pthread_key_ctr,NULL,key_ctr,NULL)) < 0) { fprintf(stderr,"Create thread failed:%s\n",strerror(errno)); exit(1); } chdir("./mountPos"); //int i; //fprintf(stdout,"counter_p =%d\n",my_usb_info.counter_p); //fprintf(stdout,"buff_media_picture[1] =%s\n",my_usb_info.buff_media_picture[1]); while(1) { if(picture_mode == 1) { int i; for(i = 0;i < my_usb_info.counter_p;i++) { memset(buffer,0,screensize); picture_to_memory_copy(my_usb_info.buff_media_picture[i]); //int line_size = vinfo.xres *vinfo.bits_per_pixel/8; //for(j = 0;j <= vinfo.yres;j++) //{ // memcpy(fbp + j * line_size,buffer,line_size); // usleep(100); //} memset(fbp,0,screensize); memcpy(fbp,buffer,screensize); memset(buffer,0,screensize); sleep(1); if(quit_flag == 1) { break; } if(back_menu == 1) { back_menu = 0; picture_mode = 0; break; } } } else if(picture_mode == 2) { if(selects_flag == 1) { //fprintf(stdout,"%s:%d:Can'i go here?\n",__FILE__,__LINE__); //fflush(stdout); memset(buffer,0,screensize); picture_to_memory_copy(my_usb_info.buff_media_picture[selects]); //fprintf(stdout,"%s:%d:Can'i go here?\n",__FILE__,__LINE__); //fflush(stdout); //memset(fbp,0,screensize); memcpy(fbp,buffer,screensize); memset(buffer,0,screensize); selects_flag = 0; key_down_flag = 0; while(1) { if(un_selects_flag == 1) { un_selects_flag = 0; key_down_flag = 0; break; } if(back_menu == 1) { back_menu = 0; key_down_flag = 0; break; } if(quit_flag == 1) { break; } } } show_pictures(); while(!key_down_flag) { un_selects_flag = 0; } if(back_menu == 1) { back_menu = 0; picture_mode = 0; continue; } if(quit_flag == 1) { break; } } if(quit_flag == 1) { quit_flag = 0; break; } } chdir(".."); umount("./mountPos"); system("rm -r mountPos"); return 0; }
/* * This is an ON Consolidation Private interface. * * Forks off rmmount and (in essence) returns the result * * a return value of 0 (FALSE) means failure, non-zero (TRUE) means success */ int _dev_unmount(char *path) { char *bn = NULL; /* block name */ char *mtype = NULL; /* media type */ char *spcl = NULL; /* special dev. path */ char *spcl_failed = NULL; /* spcl that failed */ int ret_val = FALSE; /* what we return */ char *vr; /* volmgt root dir */ int media_info_gotten = 0; int mnum = 0; int volume_is_not_managed; char *pathbuf, *absname; if ((bn = (char *)volmgt_getfullblkname(path)) == NULL) { goto dun; } if ((pathbuf = malloc(PATH_MAX+1)) == NULL) goto dun; absname = bn; if (realpath(bn, pathbuf) != NULL) absname = pathbuf; volume_is_not_managed = !volmgt_running() || (!volmgt_ownspath(absname) && volmgt_symname(bn) == NULL); free(pathbuf); /* decide of we should use rmmount to unmount the media */ if (!volume_is_not_managed) { int use_rmm = FALSE; /* use rmmount?? */ /* at least volmgt is running */ vr = (char *)volmgt_root(); if (strncmp(bn, vr, strlen(vr)) == 0) { /* the block path is rooted in /vol */ use_rmm = TRUE; } /* try to get info about media */ media_info_gotten = get_media_info(bn, &mtype, &mnum, &spcl); ret_val = call_unmount_prog(media_info_gotten, use_rmm, mtype, mnum, spcl, bn); } else { /* volmgt is *not* running */ if (get_media_info(bn, &mtype, &mnum, &spcl)) { /* * volmgt is off and get_media_info() has returned * info on the media -- soo (this is kinda' a hack) * ... we iterate, looking for multiple slices * of (say) a floppy being mounted * * note: if an unmount fails we don't want to try * to unmount the same device on the next try, so * we try to watch for that */ do { /* * don't call the unmount program is we're just * trying to unmount the same device that * failed last time -- if that's the case, * then bail */ if (spcl_failed != NULL) { if (strcmp(spcl, spcl_failed) == 0) { break; } } ret_val = call_unmount_prog(TRUE, FALSE, mtype, mnum, spcl, bn); if (!ret_val) { /* save spcl device name that failed */ spcl_failed = strdup(spcl); } else { /* * unmount succeeded, so clean up */ if (spcl_failed != NULL) { free(spcl_failed); spcl_failed = NULL; } } } while (get_media_info(bn, &mtype, &mnum, &spcl)); } else { /* just do the unmmount cycle once */ ret_val = call_unmount_prog(FALSE, FALSE, NULL, 0, NULL, bn); } } if (mtype != NULL) { free(mtype); } if (spcl != NULL) { free(spcl); } if (spcl_failed != NULL) { free(spcl_failed); } if (bn != NULL) { free(bn); } dun: return (ret_val); }