// load a volume for computation void emotionRoiProcessing::loadVolume(studyParams &vdb, volume<float> &v, int index) { char processedFile[200], prefix[BUFF_SIZE], tempVolume[BUFF_SIZE]; if (0) { // gets the motion corrected and gaussian file vdb.getMCGVolumeName(processedFile, index); read_volume(v, string(processedFile)); } else { // making the activation volume for viewing vdb.getFinalVolumeFormat(prefix); vdb.setActivationFile(index); estimateActivation(index, index, vdb.slidingWindowSize, prefix, vdb.maskFile, vdb.activationFile); // gets the motion corrected and gaussian file and calculates the mean with the last n volumes (n = sliding window size) sprintf(tempVolume, "%s%s", vdb.outputDir, "temp.nii"); vdb.getMCGVolumeFormat(prefix); estimateActivation(index, index, vdb.slidingWindowSize, prefix, tempVolume); read_volume(v, string(tempVolume)); if (fileExists(tempVolume)) remove(tempVolume); } }
void initialize_channels(void) { channels[0].id = SOUND_MIXER_VOLUME; channels[0].value = read_volume(0); channels[1].id = SOUND_MIXER_SYNTH; channels[1].value = read_volume(1); channels[2].id = SOUND_MIXER_PCM; channels[2].value = read_volume(2); channels[3].id = SOUND_MIXER_LINE; channels[3].value = read_volume(3); }
/* callback_function to update the volumes with a timer */ static void update_volumes_callback(void *data) { channels[0].value = read_volume(0); channels[1].value = read_volume(1); channels[2].value = read_volume(2); channels[3].value = read_volume(3); Epplet_gadget_data_changed(vs_master); Epplet_gadget_data_changed(vs_pcm); Epplet_gadget_data_changed(vs_lin); Epplet_gadget_data_changed(vs_cda); Epplet_timer(update_volumes_callback, NULL, 0.5, "TIMER"); }
int main(int argc, char* argv[]) { int fd = -1; char name[256] = "Unknown"; struct input_event event; int volume = read_volume(); char *dev = "/dev/input/event10"; if ((fd = open(dev, O_RDONLY)) < 0) { perror("evdev open"); exit(EVDEV_FAIL); } if(ioctl(fd, EVIOCGNAME(sizeof(name)), name) < 0) { perror("evdev ioctl"); } while (1) { read(fd, &event, sizeof(struct input_event)); if (DEBUG) { printf("Event type is %d\n", event.type); printf("Event code is %d\n", event.code); printf("Event value is %d\n", event.value); } // Event type and code is defined above (differs for different hardware) if (event.type == JACK_EVENT_TYPE && event.code == JACK_EVENT_CODE) { if (event.value == 1) { char str[512]; memset(str, '\0', sizeof(512)); sprintf(str, "./setvol.sh %d", volume); // Restore volume system(str); } else if (event.value == 0) { if (DEBUG) { printf("Disconnected\n"); } // Save current volume volume = read_volume(); // Mute system("./setvol.sh 0"); } } } close(fd); return SUCCESS; }
static void make_fat_index(struct mfs_volume* volume, struct mfs_sb_info* sb, u32_t index, u64_t size) { u8_t first_sector[BYTES_PER_SECTOR] = {0, }; u32_t start_position = 0; u32_t end_position = 0; u128 index_position = 0; if(volume == NULL) { printf("ERROR: Volume is empty!\n"); exit(1); } seek_volume(volume, 0, SEEK_SET); read_volume(volume, first_sector, sizeof(u8_t), sizeof(first_sector)); start_position = (sb->fat_sector * sb->bytes_per_sector); end_position = (sb->fat_sector + (sb->sectors_of_fat * sb->copies_of_fat)) * sb->bytes_per_sector; // Volume에 적을 위치를 계산한다. FAT Begin Address + FAT Index Address(Index - 2는 Index 0,1은 쓰이지 않기 때문이다. 시작이 2부터이다.) index_position = start_position + (sb->fat_index_size * (index - 2)); if (index_position > end_position) { printf("ERROR: Can't create a file allocation table index!\n"); exit(1); } seek_volume(volume, index_position, SEEK_SET); write_volume(volume, &size, sizeof(u32_t), 1); }
u32_t read_fat_index(struct mfs_volume* volume, u128 index) { struct mfs_sb_info sb; read_sb(volume, &sb); u32_t start_position = 0; u32_t end_position = 0; u128 read_position = 0; u32_t value = 0; start_position = (sb.fat_sector * sb.bytes_per_sector); end_position = (sb.fat_sector + (sb.sectors_of_fat * sb.copies_of_fat)) * sb.bytes_per_sector; // Volume에서 읽을 위치를 계산한다. FAT Begin Address + FAT Index Address(Index - 2는 Index 0,1은 쓰이지 않기 때문이다. 시작이 2부터이다.) read_position = start_position + (sb.fat_index_size * (index - 2)); if(read_position > end_position) return FALSE; #ifdef __KERNEL__ seek_volume(volume, read_position); #else seek_volume(volume, read_position, SEEK_SET); #endif read_volume(volume, &value, sizeof(u8_t), sb.fat_index_size); return value; }
BOOL composite_long_file_name(struct mfs_volume* volume, u128 dir_cluster_number, u32_t long_file_entry_number, ps16_t composited_file_name) { u8_t cluster[CLUSTER_SIZE] = {0, }; const u32_t entry_per_data_cluster = CLUSTER_SIZE / sizeof(struct mfs_dirent); u128 read_position = 0; u128 current_cluster_number = dir_cluster_number; u32_t current_entry_number = long_file_entry_number; struct mfs_dirent* dentry = (struct mfs_dirent *)&cluster[current_entry_number * sizeof(struct mfs_dirent)]; struct mfs_LFN_entry* current_long_file_name_entry = NULL; u128 end_cluster = get_end_cluster(volume); u128 bad_cluster = get_bad_cluster(volume); // 조합할 엔트리가 LongFileName이 맞는지 검증한다. if(is_long_file_name(dentry->attribute) == FALSE) { return FALSE; } strcpy(composited_file_name, dentry->name); ++current_entry_number; // 조합할 엔트리가 다음 클러스터까지 연속되어질 경우를 대비한다. while(current_cluster_number != end_cluster) { read_position = read_cluster(volume, current_cluster_number); #ifdef __KERNEL__ seek_volume(volume, read_position); #else seek_volume(volume, read_position, SEEK_SET); #endif read_volume(volume, cluster, sizeof(u8_t), CLUSTER_SIZE); // 현재 클러스터를 순환하며 조합한다. while(current_entry_number < entry_per_data_cluster) { current_long_file_name_entry = (struct mfs_LFN_entry *)&cluster[current_entry_number * sizeof(struct mfs_LFN_entry)]; strcat(composited_file_name, current_long_file_name_entry->name); if(current_long_file_name_entry->id == 0x40) return TRUE; ++current_entry_number; } // 다음 클러스터까지 LongFileName이 이어진다. current_cluster_number = read_fat_index(volume, current_cluster_number); if(current_cluster_number == bad_cluster) { return FALSE; } } return FALSE; }
void read_sb(struct mfs_volume* volume, struct mfs_sb_info* sb) { #ifdef __KERNEL__ seek_volume(volume, 0); #else seek_volume(volume, 0, SEEK_SET); #endif read_volume(volume, sb, sizeof(u8_t), sizeof(struct mfs_sb_info)); }
int main(int argc, char *argv[]) { int i; char buf[128]; char devname[128]; fd_set fds, tmp; int max; for (i = 0; drums_strings[i] != NULL; i++) { sprintf(buf, "/dev/drums/%s", drums_strings[i]); sprintf(devname, "drum%s", drums_strings[i]); if (fusd_register(buf, "drums", devname, 0666, drums_strings[i], &drums_fops) < 0) fprintf(stderr, "%s register failed: %m\n", drums_strings[i]); } /* print the initial prompt to the user */ read_volume(-1); /* EXAMPLE START drums3.c */ /* initialize the set */ FD_ZERO(&fds); /* add stdin to the set */ FD_SET(STDIN_FILENO, &fds); max = STDIN_FILENO; /* add all FUSD fds to the set */ fusd_fdset_add(&fds, &max); while (1) { tmp = fds; if (select(max+1, &tmp, NULL, NULL, NULL) < 0) perror("selecting"); else { /* if stdin is readable, read the user's response */ if (FD_ISSET(STDIN_FILENO, &tmp)) read_volume(STDIN_FILENO); /* call any FUSD callbacks that have messages waiting */ fusd_dispatch_fdset(&tmp); } } /* EXAMPLE STOP drums3.c */ }
static void initialize_volume(const char *fname, unsigned char iso) { read_volume(fname); isovalue = iso; if (epsilon > 0) printf("Iso-value = %d (+/- %d)\n", isovalue, epsilon); else printf("Iso-value = %d\n", isovalue); // Initial distance from camera position to center of volume camDistance = 2.0 * nx * sizex; }
int main(int argc, char *argv[] ) { float *input; int sizes[5]; image_metadata *meta; if (argc<3){ fprintf(stderr,"Usage: minc2nifti <input.mnc> <output.nii>\n"); return 0; } meta = read_volume(argv[1], &input, sizes); if (meta != NULL) write_volume_generic(argv[2], input, meta,FALSE); return 0; }
int pre_selection(float *subject, float *mask, char **images, int *sizes, int librarysize, int num_selected, int *selection, char *outfile, BOOLEAN verbose){ int i; int volumesize; float *imagedata; ssd_t *ssd; FILE *fd; fprintf(stderr,"Performing pre-selection "); volumesize=sizes[0]*sizes[1]*sizes[2]; ssd = (ssd_t *)malloc(librarysize*sizeof(*ssd)); fprintf(stderr,"(%ld MB/subject)",volumesize*sizeof(*imagedata)/(1024*1024)); for (i=0;i<librarysize;i++){ fprintf(stderr,"."); read_volume(images[i], &imagedata, sizes); ssd[i].index=i; ssd[i].ssd=get_ssd(subject,imagedata,mask,sizes); free(imagedata); } qsort(ssd,librarysize,sizeof(ssd_t),cmp_ssd); fprintf(stderr,"done\n"); if (outfile!=NULL) fd=fopen(outfile,"a"); else fd = stderr; for (i=0;i<num_selected;i++){ selection[i] = ssd[i].index; if ((verbose) || (outfile!=NULL)) fprintf(fd,"%s\n",images[selection[i]]); } if (outfile!=NULL) fclose(fd); return STATUS_OK; }
u32_t find_empty_fat_index(struct mfs_volume* volume) { u8_t sector[BYTES_PER_SECTOR] = {0, }; u32_t start_position = 0; u32_t end_position = 0; u32_t read_position = 0; u32_t fat_index_value = 0; u32_t index = 0; struct mfs_sb_info sb; read_sb(volume, &sb); u32_t fat_index_size = sb.fat_index_size; start_position = (sb.fat_sector * sb.bytes_per_sector); end_position = (sb.fat_sector + (sb.sectors_of_fat * sb.copies_of_fat)) * sb.bytes_per_sector; for(read_position = start_position; read_position < end_position; read_position += BYTES_PER_SECTOR) { #ifdef __KERNEL__ seek_volume(volume, read_position); #else seek_volume(volume, read_position, SEEK_SET); #endif read_volume(volume, §or, sizeof(u8_t), sizeof(sector)); for(index = 0; index < BYTES_PER_SECTOR; index += fat_index_size) { fat_index_value = *((u32_t *)(sector + index)); if (fat_index_value == 0) { return (((read_position - start_position) / fat_index_size) + (index / fat_index_size) + 2); } } } // FAT안에 비어있는 Index가 존재하지 않는다. return FALSE; }
void __mfs_readdir(const ps16_t route, struct file *file, struct dir_context *ctx) { u8_t cluster[CLUSTER_SIZE] = {0, }; const u32_t entry_per_data_cluster = CLUSTER_SIZE / sizeof(struct mfs_dirent); s16_t composited_file_name[128] = {0, }; BOOL has_long_file_name_entry = FALSE; u128 current_cluster_number = 0; u32_t current_entry_number = 0; u128 read_position = 0; struct mfs_dirent* current_dirent = NULL; static s16_t path[1024]={0}; struct dentry *de = file->f_dentry; struct mfs_volume* volume = de->d_sb->s_fs_info; u128 end_cluster = get_end_cluster(volume); strncpy(path, route, 1024); current_cluster_number = get_cluster_number(volume, path); if(current_cluster_number == 0) { return ; } printk("__mfs_readdir\n"); // 볼륨이 무효하다. if(volume == NULL) return ; read_position = read_cluster(volume, current_cluster_number); #ifdef __KERNEL__ seek_volume(volume, read_position); #else seek_volume(volume, read_position, SEEK_SET); #endif read_volume(volume, cluster, sizeof(u8_t), CLUSTER_SIZE); printk("current cluster number before : %d\n", current_cluster_number); while(current_cluster_number != end_cluster) { // 클러스터의 첫 엔트리를 얻는다. current_dirent = get_first_entry(cluster, ¤t_entry_number, has_long_file_name_entry); printk("current dentry : %x\n", current_dirent); // 클러스터의 모든 엔트리를 검사한다. while(current_entry_number != entry_per_data_cluster) { printk("current cluster number after : %d\n", current_cluster_number); // if(current_dirent->size != 0) { // printk("current_dentry size is NOT 0\n"); // 얻은 엔트리가 LongFileName인지 여부 검사 if(is_long_file_name(current_dirent->attribute) == TRUE) { // LongFileName일 경우 LongFileName을 조합한다. composite_long_file_name(volume, current_cluster_number, current_entry_number, composited_file_name); } else { // 일반 FileName일 경우 복사 strcpy(composited_file_name, current_dirent->name); } if(is_normal_dir(current_dirent->attribute) == TRUE) { static char buf[1024]=""; int len; buf[0]='\0'; strcat(buf,path); len=strlen(path); if(len > 0){ if(path[len-1] != '/') strcat(buf,"/"); } strcat(buf, composited_file_name); if(!dir_emit(ctx, composited_file_name, strlen(composited_file_name), 2, DT_DIR)) { printk("WARNING %s %d", __FILE__, __LINE__); return ; } ctx->pos++; strcat(buf, "*<DIR>\n"); printk(buf); } else if(is_normal_file(current_dirent->attribute) == TRUE) { static char buf[1024]=""; buf[0]='\0'; if(!dir_emit(ctx, composited_file_name, strlen(composited_file_name), 2, DT_REG)) { printk("WARNING %s %d", __FILE__, __LINE__); return ; } ctx->pos++; strcat(buf, composited_file_name); strcat(buf, "*<FILE>\n"); printk(buf); } // } // 다음 엔트리를 얻는다. current_dirent = get_next_entry(cluster, ¤t_entry_number, &has_long_file_name_entry); } current_cluster_number = read_fat_index(volume, current_cluster_number); // 지정된 번호의 클러스터를 읽는다. read_position = read_cluster(volume, current_cluster_number); #ifdef __KERNEL__ seek_volume(volume, read_position); #else seek_volume(volume, read_position, SEEK_SET); #endif read_volume(volume, cluster, sizeof(u8_t), CLUSTER_SIZE); } return ; }
int __mfs_lookup(struct mfs_volume* volume, const ps16_t route, const ps16_t file_name) { u8_t cluster[CLUSTER_SIZE] = {0, }; const u32_t entry_per_data_cluster = CLUSTER_SIZE / sizeof(struct mfs_dirent); s16_t composited_file_name[128] = {0, }; BOOL has_long_file_name_next_entry = FALSE; u128 current_cluster_number = 0; u32_t current_entry_number = 0; u128 read_position = 0; struct mfs_dirent* current_dentry = NULL; static s16_t path[1024]={0}; u128 end_cluster = get_end_cluster(volume); strncpy(path, route, 1024); current_cluster_number = get_cluster_number(volume, route); // if(current_cluster_number == 0) // { // return 0; // } // 볼륨이 무효하다. if(volume == NULL) return 0; read_position = read_cluster(volume, current_cluster_number); #ifdef __KERNEL__ seek_volume(volume, read_position); #else seek_volume(volume, read_position, SEEK_SET); #endif read_volume(volume, cluster, sizeof(u8_t), CLUSTER_SIZE); while(current_cluster_number != end_cluster) { // 클러스터의 첫 엔트리를 얻는다. current_dentry = get_first_entry(cluster, ¤t_entry_number, has_long_file_name_next_entry); // 클러스터의 모든 엔트리를 검사한다. while(current_entry_number != entry_per_data_cluster) { // 얻은 엔트리가 LongFileName인지 여부 검사 if(is_long_file_name(current_dentry->attribute) == TRUE) { // LongFileName일 경우 LongFileName을 조합한다. composite_long_file_name(volume, current_cluster_number, current_entry_number, composited_file_name); } else { // 일반 FileName일 경우 복사 strcpy(composited_file_name, current_dentry->name); } if(strcmp(composited_file_name, file_name) == 0){ if(is_normal_dir(current_dentry->attribute) == TRUE){ return DIR_DENTRY; } else if(is_normal_file(current_dentry->attribute) == TRUE){ return FILE_DENTRY; } } // 다음 엔트리를 얻는다. current_dentry = get_next_entry(cluster, ¤t_entry_number, &has_long_file_name_next_entry); } current_cluster_number = read_fat_index(volume, current_cluster_number); // 지정된 번호의 클러스터를 읽는다. read_position = read_cluster(volume, current_cluster_number); #ifdef __KERNEL__ seek_volume(volume, read_position); #else seek_volume(volume, read_position, SEEK_SET); #endif read_volume(volume, cluster, sizeof(u8_t), CLUSTER_SIZE); } return 0; }
void __mfs_readdir(struct mfs_volume* volume, const ps16_t route, struct printdir *printdir) { u8_t cluster[CLUSTER_SIZE] = {0, }; const u32_t entry_per_data_cluster = CLUSTER_SIZE / sizeof(struct mfs_dirent); s16_t composited_file_name[128] = {0, }; BOOL has_long_file_name_next_entry = FALSE; u128 current_cluster_number = 0; u32_t current_entry_number = 0; u128 read_position = 0; struct mfs_dirent* current_dirent = NULL; static s16_t path[1024]={0}; struct file* filp = printdir->filp; void* dirent = printdir->dirent; filldir_t filldir = printdir->filldir; u128 end_cluster = get_end_cluster(volume); strncpy(path, route, 1024); current_cluster_number = get_cluster_number(volume, path); if(current_cluster_number == 0) { return ; } // 볼륨이 무효하다. if(volume == NULL) return ; read_position = read_cluster(volume, current_cluster_number); seek_volume(volume, read_position); read_volume(volume, cluster, sizeof(u8_t), CLUSTER_SIZE); while(current_cluster_number != end_cluster) { // 클러스터의 첫 엔트리를 얻는다. current_dirent = get_first_entry(cluster, ¤t_entry_number, has_long_file_name_next_entry); // 클러스터의 모든 엔트리를 검사한다. while(current_entry_number != entry_per_data_cluster) { // if(current_dirent->size != 0) // { // 얻은 엔트리가 LongFileName인지 여부 검사 if(is_long_file_name(current_dirent->attribute) == TRUE) { // LongFileName일 경우 LongFileName을 조합한다. composite_long_file_name(volume, current_cluster_number, current_entry_number, composited_file_name); } else { // 일반 FileName일 경우 복사 strcpy(composited_file_name, current_dirent->name); } if(is_normal_dir(current_dirent->attribute) == TRUE) { static char buf[1024] = ""; int len; buf[0] = '\0'; strcat(buf, path); len = strlen(path); if(len > 0){ if(path[len-1] != '/') strcat(buf, "/"); } strcat(buf, composited_file_name); if(filldir(dirent, composited_file_name, strlen(composited_file_name), filp->f_pos++, 2, DT_DIR)){ printk("WARNING %s %d", __FILE__,__LINE__); return ; } strcat(buf, "*<DIR>\n"); printk(buf); } else if(is_normal_file(current_dirent->attribute) == TRUE) { static char buf[1024]=""; buf[0]='\0'; printk("garig %p %p %p %s\n", filp, dirent, filldir, composited_file_name); if(filldir(dirent, composited_file_name, strlen(composited_file_name), filp->f_pos++, 2, DT_REG)){ printk("WARNING %s %d", __FILE__, __LINE__); return ; } strcat(buf, composited_file_name); strcat(buf, "*<FILE>\n"); printk(buf); } // } // 다음 엔트리를 얻는다. current_dirent = get_next_entry(cluster, ¤t_entry_number, &has_long_file_name_next_entry); } current_cluster_number = read_fat_index(volume, current_cluster_number); // 지정된 번호의 클러스터를 읽는다. read_position = read_cluster(volume, current_cluster_number); seek_volume(volume, read_position); read_volume(volume, cluster, sizeof(u8_t), CLUSTER_SIZE); } return ; }
u32_t get_cluster_number(struct mfs_volume* volume, ps16_t path) { u8_t current_cluster[CLUSTER_SIZE] = {0, }; ps16_t seperated_path = strtok(path, "/"); const u32_t entry_per_data_cluster = CLUSTER_SIZE / sizeof(struct mfs_dirent); struct mfs_dirent* current_dir_entry = NULL; s16_t composited_file_name[128] = {0, }; u128 current_cluster_number = 2; // Root Directory의 클러스터 값 u32_t current_entry_number = 0; BOOL is_dir_changed = FALSE; BOOL has_long_file_name_next_entry = FALSE; u128 end_cluster = get_end_cluster(volume); u128 read_position = read_cluster(volume, current_cluster_number); #ifdef __KERNEL__ seek_volume(volume, read_position); #else seek_volume(volume, read_position, SEEK_SET); #endif read_volume(volume, current_cluster, sizeof(u8_t), CLUSTER_SIZE); while(seperated_path != NULL) { is_dir_changed = FALSE; // 클러스터의 첫 엔트리를 얻는다. current_dir_entry = get_first_entry(current_cluster, ¤t_entry_number, has_long_file_name_next_entry); // 클러스터의 모든 엔트리를 검사한다. while(current_entry_number != entry_per_data_cluster) { // 얻은 엔트리가 폴더일 경우 if(is_normal_dir(current_dir_entry->attribute) == TRUE) { // 얻은 엔트리가 LongFileName인지 여부 검사 if(is_long_file_name(current_dir_entry->attribute) == TRUE) { // LongFileName일 경우 LongFileName을 조합한다. composite_long_file_name(volume, current_cluster_number, current_entry_number, composited_file_name); } else { // 일반 FileName일 경우 복사 strcpy(composited_file_name, current_dir_entry->name); } // Name 비교 if(!strcmp(seperated_path, composited_file_name)) { // 일치한다면 다음 route 경로 명을 얻는다. seperated_path = strtok(NULL, "/"); current_cluster_number = current_dir_entry->head_cluster_number; is_dir_changed = TRUE; break; } } // 다음 엔트리를 얻는다. current_dir_entry = get_next_entry(current_cluster, ¤t_entry_number, &has_long_file_name_next_entry); } // 현재 탐색 디렉토리가 변경되지 않았다면 현재 디렉토리의 다음 클러스터를 얻는다. if (is_dir_changed == FALSE) { current_cluster_number = read_fat_index(volume, current_cluster_number); // route 경로가 잘못되었다. if(current_cluster_number == end_cluster) { printf("wrong route\n"); return 0; } } // 지정된 번호의 클러스터를 읽는다. read_position = read_cluster(volume, current_cluster_number); #ifdef __KERNEL__ seek_volume(volume, read_position); #else seek_volume(volume, read_position, SEEK_SET); #endif read_volume(volume, current_cluster, sizeof(u8_t), CLUSTER_SIZE); } return current_cluster_number; }
/* 함수명 : writeDirEntryInDirCluster 하는일 : 디렉토리 클러스터안에 디렉토리 엔트리를 추가한다. 디렉토리의 모든 클러스터를 검사하여, 빈 엔트리를 찾고 그 위치에 디렉토리 엔트리를 추가한다. 인자 : fVolume : 루프백이미지/파일 볼륨의 포인터 nDirClusterNumber : 디렉토리 클러스터 번호 pDirectoryEntry : 디렉토리 엔트리의 포인터 pFileName : 파일 이름의 문자열 포인터 리턴 값 : BOOL */ BOOL alloc_new_dirent(struct mfs_volume* volume, u128 dir_cluster_number, struct mfs_dirent* dirent, ps16_t file_name) { u8_t cluster[CLUSTER_SIZE] = {0, }; const u32_t entry_per_data_cluster = CLUSTER_SIZE / sizeof(struct mfs_dirent); BOOL has_long_file_name_next_entry = FALSE; u128 read_position = 0; u128 wirte_position = 0; u128 current_cluster_number = dir_cluster_number; u128 before_cluster_number = 0; u32_t current_entry_number = 0; struct mfs_dirent* current_dirent = NULL; u128 end_cluster = get_end_cluster(volume); // 디렉토리의 모든 클러스터를 검사한다. while(current_cluster_number != end_cluster) { read_position = read_cluster(volume, current_cluster_number); #ifdef __KERNEL__ seek_volume(volume, read_position); #else seek_volume(volume, read_position, SEEK_SET); #endif read_volume(volume, cluster, sizeof(u8_t), CLUSTER_SIZE); current_dirent = get_first_entry(cluster, ¤t_entry_number, has_long_file_name_next_entry); while(current_entry_number != entry_per_data_cluster) { // if (current_dirent->size == 0) if( is_deleted_file(current_dirent->attribute) || is_deleted_dir(current_dirent->attribute) ) { wirte_position = read_position + (current_entry_number * sizeof(struct mfs_dirent)); #ifdef __KERNEL__ seek_volume(volume, wirte_position); #else seek_volume(volume, wirte_position, SEEK_SET); #endif write_volume(volume, dirent, sizeof(struct mfs_dirent), 1); printf("alloc_new_dirent %d %d\n", current_cluster_number, wirte_position); return TRUE; } // 다음 엔트리를 얻는다. current_dirent = get_next_entry(cluster, ¤t_entry_number, &has_long_file_name_next_entry); } before_cluster_number = current_cluster_number; current_cluster_number = read_fat_index(volume, current_cluster_number); } // 디렉토리 클러스터에 빈 공간이 없다, 클러스터 추가 current_cluster_number = find_empty_fat_index(volume); write_in_fat_index(volume, before_cluster_number, current_cluster_number); write_in_fat_index(volume, current_cluster_number, end_cluster); wirte_position = read_cluster(volume, current_cluster_number); #ifdef __KERNEL__ seek_volume(volume, wirte_position); #else seek_volume(volume, wirte_position, SEEK_SET); #endif write_volume(volume, dirent, sizeof(struct mfs_dirent), 1); printf("alloc_new_dirent %d %d\n", current_cluster_number, wirte_position); return TRUE; }
/* 함수명 : search_fileDirectoryEntryInDirCluster 하는일 : 디렉토리 클러스터 안에 파일 디렉토리 엔트리를 찾는다. 디렉토리가 가지고 있는 모든 클러스터를 순환하여 파일 이름과 같은 엔트리를 찾는다. 인자 : fVolume : 루프백이미지/파일 볼륨의 포인터 nDirClusterNumber : 디렉토리 클러스터 번호 pFileName : 파일이름의 문자열 포인터 pSearchedDirEntry : 검색된 디렉토리 엔트리의 포인터 리턴 값 : BOOL */ BOOL get_dentry(struct mfs_volume* volume, u128 dir_cluster_number, ps16_t file_name, struct mfs_dirent* searched_dir_entry) { u8_t cluster[CLUSTER_SIZE] = {0, }; const u32_t entry_per_data_cluster = CLUSTER_SIZE / sizeof(struct mfs_dirent); s16_t composited_file_name[128] = {0, }; BOOL has_long_file_name_next_entry = FALSE; u128 read_position = 0; u128 current_cluster_number = dir_cluster_number; u32_t current_entry_number = 0; struct mfs_dirent* current_dir_entry = NULL; u128 end_cluster = get_end_cluster(volume); printf("get_dentry: %s\n", file_name); // 디렉토리의 모든 클러스터를 검사한다. while(current_cluster_number != end_cluster) { printf("current_cluster_number: %d\n", current_cluster_number); read_position = read_cluster(volume, current_cluster_number); #ifdef __KERNEL__ seek_volume(volume, read_position); #else seek_volume(volume, read_position, SEEK_SET); #endif read_volume(volume, cluster, sizeof(u8_t), CLUSTER_SIZE); current_dir_entry = get_first_entry(cluster, ¤t_entry_number, has_long_file_name_next_entry); while(current_entry_number != entry_per_data_cluster) { printf("current entry number after : %d\n", current_entry_number); if(is_normal_file(current_dir_entry->attribute) == TRUE) { // 얻은 엔트리가 LongFileName인지 여부 검사 if(is_long_file_name(current_dir_entry->attribute) == TRUE) { // LongFileName일 경우 LongFileName을 조합한다. composite_long_file_name(volume, current_cluster_number, current_entry_number, composited_file_name); } else { // 일반 FileName일 경우 복사 strcpy(composited_file_name, current_dir_entry->name); } // Name 비교 if(!strcmp(file_name, composited_file_name)) { memcpy(searched_dir_entry, current_dir_entry, sizeof(struct mfs_dirent)); return TRUE; } } // 다음 엔트리를 얻는다. current_dir_entry = get_next_entry(cluster, ¤t_entry_number, &has_long_file_name_next_entry); } current_cluster_number = read_fat_index(volume, current_cluster_number); printf("read fat index : %d\n", current_cluster_number); } printf("file not exist\n"); return FALSE; }
static void process_request(cdata_comm_t *com, int sockfd, vol_file_handle_t *v_handle) { ui08 *data_ptr = NULL; /* pointer to data */ cdata_info_t info; cdata_reply_t reply; Glob->time_last_request = time((time_t *) NULL); Glob->n_data_requests++; if(Glob->params.debug) { fprintf(stderr, "Received request\n"); } PMU_auto_register("Processing request"); /* * if plane_heights are requested, request info as well */ if (com->primary_com & GET_PLANE_HEIGHTS) { com->primary_com |= GET_INFO; } /* * Set default values in reply */ initialize_reply(&reply, com); /* * In the case of a request for new data when no realtime file * is available, change the request to GET_MOST_RECENT */ if (com->primary_com & GET_NEW && !Glob->params.use_realtime_file) { com->primary_com &= ~GET_NEW; com->primary_com |= GET_MOST_RECENT; } /* * read in the data volume */ PMU_auto_register("Reading in data volume"); if (read_volume(v_handle, com)) { /* * read failed */ reply.status |= NO_INFO | NO_DATA; } else if (com->data_field >= v_handle->vol_params->nfields) { /* * field number is out of range */ if (Glob->params.debug) { fprintf(stderr, "Field num %ld exceeds max of %ld\n", (long) com->data_field, (long) v_handle->vol_params->nfields); } reply.status |= NO_INFO | NO_DATA; } else { if (com->primary_com & GET_NEW) { reply.status |= NEW_DATA; } copy_vol_params_to_info(v_handle, &info); copy_grid_params_to_info(v_handle, com, &info); copy_field_params_to_info(v_handle, &info, com->data_field); /* * get the data if requested */ if(com->primary_com & GET_DATA) { data_ptr = (ui08 *) NULL; if(Glob->params.debug) { fprintf(stderr, "getting data\n"); } data_ptr = get_grid_data(com, &reply, &info, v_handle); } } /* if (read_volume(v_handle, com)) */ PMU_auto_register("Sending reply"); send_reply(com, &reply, &info, data_ptr, sockfd, v_handle); if(data_ptr != NULL) { ufree((char *) data_ptr); if (Glob->params.free_volume) RfFreeVolPlanes(v_handle, "process_request"); } }