예제 #1
0
파일: dir.c 프로젝트: 44670/Project_CTR
fs_entry* fs_GetEntry(fs_DIR *dp)
{
	// Directory structs
	struct fs_dirent *tmp_entry;
	fs_DIR *tmp_dptr;
	u32 namlen = 0;
	
	//printf("get api dir entry from dir ptr\n");
	tmp_entry = fs_readdir(dp);
	
	//printf("if null, return\n");
	if(!tmp_entry) 
		return NULL;
		
#ifdef _WIN32
	namlen = tmp_entry->d_namlen;
#else
	namlen = strlen(tmp_entry->d_name);
#endif
		
	//printf("allocate memory for entry\n");
	fs_entry *entry  = malloc(sizeof(fs_entry));
	memset(entry,0,sizeof(fs_entry));
	
	//Copy FS compatible Entry name
	entry->fs_name = malloc(sizeof(fs_char)*(namlen+1));
	memset(entry->fs_name,0,sizeof(fs_char)*(namlen+1));
	memcpy(entry->fs_name,tmp_entry->d_name,sizeof(fs_char)*namlen);
	
	// Convert Entry name into RomFS u16 char (windows wchar_t, thanks Nintendo)
#if _WIN32
	str_u16_to_u16(&entry->name,&entry->name_len,tmp_entry->d_name,namlen);
#else
	str_utf8_to_u16(&entry->name,&entry->name_len,(u8*)tmp_entry->d_name,namlen);
#endif
	
	//printf("get dir entry from dir ptr to check if dir\n");
	tmp_dptr = fs_opendir(entry->fs_name);
	if(tmp_dptr)
	{
		//printf("is dir\n");
		fs_closedir(tmp_dptr);
		entry->IsDir = true;
		entry->size = 0;
		entry->fp = NULL;
	}
	else // Open file if it is a file
	{
		entry->IsDir = false;
#ifdef _WIN32
		entry->size = wGetFileSize64(entry->fs_name);
		entry->fp = _wfopen(entry->fs_name,L"rb");
#else
		entry->size = GetFileSize64(entry->fs_name);
		entry->fp = fopen(entry->fs_name,"rb");
#endif
	}
	//printf("fs_GetEntry() return\n");
	return entry;
}
예제 #2
0
	void load() {
		file_t		d;
		dirent_t	*de;
		node_t		*aux;

		total=0;
		d = fs_open(srcdir, O_RDONLY | O_DIR);
		if (!d) {
			printf("Can't open source directory (%s)\n", srcdir);
			ptr->next=NULL;
		} else {
			aux=ptr;
			strcpy(aux->name, "ALL FILES   ");
			aux->size=0;
			aux->next=(node_t *)malloc(sizeof(node_t));
			while ( (de = fs_readdir(d)) ) {
				if ((de->size >= 108) && (strstr(de->name, ".VMS") == NULL)) {
					total++;
					aux=aux->next;
					strcpy(aux->name, de->name);
					aux->size=de->size;
					aux->next=(node_t *)malloc(sizeof(node_t));
				}
			}
			free(aux->next);
			aux->next=NULL;
		}
		fs_close(d);
	}
예제 #3
0
파일: dir.c 프로젝트: WareX97/K2
int sys_readdir(DIR* d) {
	if(!d->fd)
		return -EINVAL;
		
	fs_node_t* node = current_task->fd[d->fd];
	return fs_readdir(node, d->position++);
}
예제 #4
0
파일: platform.c 프로젝트: alkap007/ali3606
static void tr_migrateResume( const char *oldDirectory, const char *newDirectory )
{
	int fd;
	struct dirent * dirp;
	unsigned char *buff = MALLOC(1024);
	
	char oldFile[MAX_PATH_LENGTH];
	char newFile[MAX_PATH_LENGTH];
	
	dirp = (struct dirent *)buff;
	fd  = fs_opendir(oldDirectory);
	if (fd >= 0)
	{
		while(( fs_readdir(fd, dirp)) > 0)
		{
			if ( strncmp( "resume.", dirp->d_name, 7 ) )
			{
				continue;
			}
			snprintf( oldFile, MAX_PATH_LENGTH, "%s/%s",
					  oldDirectory, dirp->d_name );
			snprintf( newFile, MAX_PATH_LENGTH, "%s/%s",
					  newDirectory, dirp->d_name );
			fs_rename( oldFile, newFile );
		}

		fs_closedir( fd );
	}

	FREE(buff);
}
예제 #5
0
파일: fs_main.c 프로젝트: alkap007/ali3606
void ide_fs_unmount(UINT32 param)
{
	int i;
	char mount_name[16];	
	int result;
	struct statvfs sfs;
	int fd;
	
	char dirbuf[sizeof(struct dirent) + 32];	
	struct dirent *dire = (struct dirent *)dirbuf;

	unlink_device("/c", MNT_TYPE_IDE);
	unlink_device("/r", MNT_TYPE_IDE);

	fd = fs_opendir("/mnt");

	while (fs_readdir(fd, dire) > 0)
	{
		fs_get_mount_name(MNT_TYPE_IDE, 0, 0, mount_name);
		if(!MEMCMP(&dire->d_name, &mount_name[5], 3))
		{
			STRCPY(mount_name, "/mnt/");
			strcat(mount_name, dire->d_name);

			FS_PRINTF("unmount: %s ...\n", mount_name);
			result = fs_statvfs(mount_name, &sfs);
			if (result < 0)
			{
				FS_PRINTF("%s is not mounted! err = %d\n", mount_name, result);
				FS_NOTICE_MESSAGE(MP_FS_UNMOUNT, MNT_MSG_PARAM(UNMNT_FAILED, MNT_TYPE_IDE, 0));
//				IDE_MESSAGE(MP_FS_UNMOUNT, UNMNT_FAILED);	
				continue;
			}

			result = fs_unmount(mount_name, 1);
			if (result < 0)
			{
				FS_PRINTF("%s unmounted failed! err = %d\n", mount_name, result);
				FS_NOTICE_MESSAGE(MP_FS_UNMOUNT, MNT_MSG_PARAM(UNMNT_FAILED, MNT_TYPE_IDE, 0));
//				IDE_MESSAGE(MP_FS_UNMOUNT, UNMNT_FAILED);
			}
			else
			{
				FS_PRINTF("%s unmounted successed!\n", mount_name);
			}

	        result = fs_rmdir(mount_name);
			if (result < 0)
			{
	            FS_PRINTF("remove dir %s failed! err = %d\n", mount_name, result);
			}
		}	
	}	

	fs_closedir(fd);
    ide_hdd_cleanup(0);
	FS_NOTICE_MESSAGE(MP_FS_UNMOUNT, MNT_MSG_PARAM(UNMNT_UNMOUNT_OK, MNT_TYPE_IDE, 0));
//	IDE_MESSAGE(MP_FS_UNMOUNT, UNMNT_UNMOUNT_OK);
}
예제 #6
0
파일: plugin.c 프로젝트: pcercuei/dcplaya
static int r_plugin_path_load(char *path, unsigned int level)
{
  dirent_t *de;
  int count = 0;
  int fd = -1;
  char *path_end = 0;

  SDDEBUG(">> %s(%2d,[%s])\n", __FUNCTION__, level, path);
  SDINDENT;

  if (level == 0) {
    goto error;
  }

  fd = fs_open(path, O_RDONLY | O_DIR);
  if (fd<0) {
    count = -1;
    goto error;
  }

  path_end = path + strlen(path);
  path_end[0] = '/';
  path_end[1] = 0;

  while (de = fs_readdir(fd), de) {
    int type;

    type = filetype_get(de->name, de->size);
    /* 	SDDEBUG("[%s] : %04x\n", de->name, type); */

    if (type == filetype_dir) {
      int cnt;
      strcpy(path_end+1, de->name);
      cnt = r_plugin_path_load(path, level-1);
      count += (cnt > 0) ? cnt : 0;
      continue;
    }

    if (type != filetype_lef) {
      continue;
    }

    strcpy(path_end+1, de->name);
    count += plugin_load_and_register(path);
  }

 error:
  if (fd>=0) {
    fs_close(fd);
  }
  if (path_end) {
    *path_end = 0;
  }
  
  SDUNINDENT;
  SDDEBUG("<< %s(%2d,[%s]) = %d\n", __FUNCTION__, level, path, count);

  return count;
}
예제 #7
0
void SystemCall(u32 id, void *param, void *result)
{
	int i;
	struct dirent *node;

	switch (id) {
		case SYS_PUTS:
			tty_puts((char*)param);
			break;

		case SYS_EXEC:
			LoadProcess((char*)param);
			break;

		case 2:
			if (kbd_event) {
				kbd_event = false;
				*(bool*)result = true;
			} else {
				*(bool*)result = false;
			}
			break;

		case 3:
			*(int*)result = inb(*(int*)param);
			break;

		case 4:
			outb(*(int*)param, *(int*)result);
			break;

		case 5: // read dir
			i = *(int *)param;
			node = fs_readdir(ird_root, i);
			if (!node) {
				*(int *) result = 0;
			} else {
				*(char *)result = node->name;
			}
			break;

		case 6:
			tty_attr((int)param);
			break;

		case 7:
			*(int*)result = timer_ticks;
			break;

		default:
			break;
	}
}
예제 #8
0
파일: storage.c 프로젝트: sunkaizhu/zephyr
static int unlink_recursive(char path[STORAGE_PATH_MAX])
{
	size_t path_len;
	fs_dir_t dir;
	int err;

	err = fs_opendir(&dir, path);
	if (err) {
		return err;
	}

	/* We calculate this up-front so we can keep reusing the same
	 * buffer for the path when recursing.
	 */
	path_len = strlen(path);

	while (1) {
		struct fs_dirent entry;

		err = fs_readdir(&dir, &entry);
		if (err) {
			break;
		}

		if (entry.name[0] == '\0') {
			break;
		}

		snprintk(path + path_len, STORAGE_PATH_MAX - path_len, "/%s",
			 entry.name);

		if (entry.type == FS_DIR_ENTRY_DIR) {
			err = unlink_recursive(path);
		} else {
			err = fs_unlink(path);
		}

		if (err) {
			break;
		}
	}

	fs_closedir(&dir);

	/* Return to the original value */
	path[path_len] = '\0';

	fs_unlink(path);

	return err;
}
예제 #9
0
int netcfg_load(netcfg_t * out) {
    file_t f;
    dirent_t * d;
    char buf[64];

    // Scan for VMUs
    f = fs_open("/vmu", O_RDONLY | O_DIR);

    if(f >= 0) {
        for(; ;) {
            d = fs_readdir(f);

            if(!d) {
                fs_close(f);
                break;
            }

            sprintf(buf, "/vmu/%s/net.cfg", d->name);

            if(netcfg_load_from(buf, out) >= 0) {
                out->src = NETCFG_SRC_VMU;
                fs_close(f);
                return 0;
            }
        }
    }

    // Couldn't find anything. Try reading the config
    // from flash.
    if(netcfg_load_flash(out) >= 0) {
        out->src = NETCFG_SRC_FLASH;
        return 0;
    }

    // Didn't work out->. try the current dir.
    if(netcfg_load_from("net.cfg", out) >= 0) {
        out->src = NETCFG_SRC_CWD;
        return 0;
    }

    // Finally, try the CD
    if(netcfg_load_from("/cd/net.cfg", out) >= 0) {
        out->src = NETCFG_SRC_CDROOT;
        return 0;
    }

    return -1;
}
예제 #10
0
static void *load_song_list(void * p) {
    file_t d;

    d = fs_open(curdir, O_RDONLY | O_DIR);

    if(!d) {
        strcpy(curdir, "/");
        d = fs_open(curdir, O_RDONLY | O_DIR);

        if(!d) {
            mutex_lock(mut);
            num_entries = 1;
            strcpy(entries[0].fn, "Error!");
            entries[0].size = 0;
            mutex_unlock(mut);
            return NULL;
        }
    }

    {
        dirent_t *de;
        num_entries = 0;

        if(strcmp(curdir, "/")) {
            mutex_lock(mut);
            strcpy(entries[0].fn, "<..>");
            entries[0].size = -1;
            num_entries++;
            mutex_unlock(mut);
        }

        while((de = fs_readdir(d)) && num_entries < 200) {
            printf("read entry '%s'\n", de->name);

            if(strcmp(de->name, ".") && strcmp(de->name, "..")) {
                mutex_lock(mut);
                strcpy(entries[num_entries].fn, de->name);
                entries[num_entries].size = de->size;
                num_entries++;
                mutex_unlock(mut);
            }
        }
    }

    fs_close(d);
    load_queued = 0;
    return NULL;
}
예제 #11
0
void cmd_find(void) {
  WORD n;
  FILINFO2 info;              
  
  // Принимаем путь
  recvString();

  // Принимаем макс кол-во элементов
  recvBin((uint8_t*)&n, 2);

  // Режим передачи и подтверждение
  sendStart(ERR_WAIT);
  if(lastError) return;

  // Открываем папку
  if(buf[0] != ':') {
    if(fs_opendir()) return;
  }

  for(; n; --n) {
    /* Читаем очереной описатель */
    if(fs_readdir()) return;

    /* Конец */
    if(FS_DIRENTRY[0] == 0) {
      lastError = ERR_OK_CMD;
      return;
    }

    /* Сжимаем ответ для компьютера */
    memcpy(info.fname, FS_DIRENTRY+DIR_Name, 12);
    memcpy(&info.fsize, FS_DIRENTRY+DIR_FileSize, 4);
    memcpy(&info.ftimedate, FS_DIRENTRY+DIR_WrtTime, 4);
    //memcpy(memcpy(memcpy(info.fname, FS_DIRENTRY+DIR_Name, 12, FS_DIRENTRY+DIR_FileSize, 4), FS_DIRENTRY+DIR_WrtTime, 4);

    /* Отправляем */
    send(ERR_OK_ENTRY);
    sendBin((uint8_t*)&info, sizeof(info));
    send(ERR_WAIT);
  }

  /* Ограничение по размеру */  
  lastError = ERR_MAX_FILES; /*! Надо опеределать, что бы не было ложных ошибок */
}
예제 #12
0
int do_dirlist(const char * name, http_state_t * hs, file_t f) {
	char * dl, *dlout;
	dirent_t * d;
	int dlsize, r;

	dl = malloc(65536);
	dlout = dl;

	sprintf(dlout, "<html><head><title>Listing of %s</title></head></html>\n<body bgcolor=\"white\">\n", name);
	dlout += strlen(dlout);

	sprintf(dlout, "<h4>Listing of %s</h4>\n<hr>\n<table>\n", name);
	dlout += strlen(dlout);

	while ((d = fs_readdir(f))) {
		if (d->size >= 0) {
			sprintf(dlout, "<tr><td><a href=\"%s\">%s</a></td><td>%d</td></tr>\n", d->name, d->name, d->size);
			dlout += strlen(dlout);
		} else {
			sprintf(dlout, "<tr><td><a href=\"%s/\">%s/</a></td><td>%d</td></tr>\n", d->name, d->name, d->size);
			dlout += strlen(dlout);
		}
	}

	sprintf(dlout, "</table>\n<hr>\nKOSHttp/1.0 server\n</body></html>\n");
	dlout += strlen(dlout);

	dlsize = strlen(dl);

	send_ok(hs, "text/html");
	dlout = dl;
	while (dlsize > 0) {
		r = write(hs->socket, dlout, dlsize);
		if (r <= 0)
			return -1;
		dlsize -= r;
		dlout += r;
	}

	free(dl);

	return 0;
}
예제 #13
0
int netcfg_save(const netcfg_t * cfg) {
    file_t f;
    dirent_t * d;
    char buf[64];

    // Scan for a VMU
    f = fs_open("/vmu", O_RDONLY | O_DIR);

    if(f < 0)
        return -1;

    d = fs_readdir(f);

    if(!d) {
        fs_close(f);
        return -1;
    }

    sprintf(buf, "/vmu/%s/net.cfg", d->name);
    fs_close(f);

    return netcfg_save_to(buf, cfg);
}
예제 #14
0
파일: utils.c 프로젝트: WinCoder/DreamShell
int CopyDirectory(const char *src_path, const char *dest_path, int verbose) {
	
	file_t fd = fs_open(src_path, O_RDONLY | O_DIR);

	if(fd != FILEHND_INVALID) {
		
		char Path[MAX_FN_LEN], *EndPtr = Path;
		char PathDest[MAX_FN_LEN], *EndDestPtr = PathDest;
		dirent_t *e;
		
		strcpy(Path, src_path);
		Path[strlen(src_path)] = '/';
		EndPtr += (strlen(src_path)+1);
		
		strcpy(PathDest, dest_path);
		
		if(!DirExists(PathDest)) {
			
			if(verbose) {
				ds_printf("DS_PROCESS: Making directory: %s\n", PathDest);
			}
			
			if(fs_mkdir(PathDest)) {
				ds_printf("DS_ERROR: Can't make directory %s\n", PathDest);
				fs_close(fd);
				return 0;
			}
		}
		
		PathDest[strlen(dest_path)] = '/';
		EndDestPtr += (strlen(dest_path)+1);

		while((e = fs_readdir(fd)) != NULL) {

			strcpy(EndPtr, e->name);
			strcpy(EndDestPtr, e->name);
			
			if(e->attr == O_DIR) {
				
				if(verbose) {
					ds_printf("DS_PROCESS: Making directory: %s\n", PathDest);
				}
				
				if(!fs_mkdir(PathDest)) {
					CopyDirectory(Path, PathDest, verbose);
				} else {
					ds_printf("DS_ERROR: Can't make directory %s\n", PathDest);
					fs_close(fd);
					return 0;
				}
			} else {
				if(!CopyFile(Path, PathDest, verbose)) {
					fs_close(fd);
					return 0;
				}
			}
		}
		
		fs_close(fd);
		return 1;
	}
	
	return 0;
}
예제 #15
0
static efi_status_t dir_read(struct file_handle *fh, u64 *buffer_size,
		void *buffer)
{
	struct efi_file_info *info = buffer;
	struct fs_dirent *dent;
	unsigned int required_size;

	if (!fh->dirs) {
		assert(fh->offset == 0);
		fh->dirs = fs_opendir(fh->path);
		if (!fh->dirs)
			return EFI_DEVICE_ERROR;
	}

	/*
	 * So this is a bit awkward.  Since fs layer is stateful and we
	 * can't rewind an entry, in the EFI_BUFFER_TOO_SMALL case below
	 * we might have to return without consuming the dent.. so we
	 * have to stash it for next call.
	 */
	if (fh->dent) {
		dent = fh->dent;
		fh->dent = NULL;
	} else {
		dent = fs_readdir(fh->dirs);
	}


	if (!dent) {
		/* no more files in directory: */
		/* workaround shim.efi bug/quirk.. as find_boot_csv()
		 * loops through directory contents, it initially calls
		 * read w/ zero length buffer to find out how much mem
		 * to allocate for the EFI_FILE_INFO, then allocates,
		 * and then calls a 2nd time.  If we return size of
		 * zero the first time, it happily passes that to
		 * AllocateZeroPool(), and when that returns NULL it
		 * thinks it is EFI_OUT_OF_RESOURCES.  So on first
		 * call return a non-zero size:
		 */
		if (*buffer_size == 0)
			*buffer_size = sizeof(*info);
		else
			*buffer_size = 0;
		return EFI_SUCCESS;
	}

	/* check buffer size: */
	required_size = sizeof(*info) + 2 * (strlen(dent->name) + 1);
	if (*buffer_size < required_size) {
		*buffer_size = required_size;
		fh->dent = dent;
		return EFI_BUFFER_TOO_SMALL;
	}

	*buffer_size = required_size;
	memset(info, 0, required_size);

	info->size = required_size;
	info->file_size = dent->size;
	info->physical_size = dent->size;

	if (dent->type == FS_DT_DIR)
		info->attribute |= EFI_FILE_DIRECTORY;

	ascii2unicode((u16 *)info->file_name, dent->name);

	fh->offset++;

	return EFI_SUCCESS;
}
예제 #16
0
/**
 * Load the file list from the current path on the window
 * @param app pointer to a Files application
 */
static void win_load_file_list(lv_app_inst_t * app)
{
    my_app_data_t * app_data = app->app_data;
    my_win_data_t * win_data = app->win_data;

    /*Create a new list*/
    win_create_list(app);

    fs_res_t res = FS_RES_OK;

      /*At empty path show the drivers */
    lv_obj_t * liste;
    if(app_data->path[0] == '\0') {
        char drv[16];
        char buf[2];
        fs_get_letters(drv);
        uint8_t i;
        for(i = 0; drv[i] != '\0'; i++) {
            buf[0] = drv[i];
            buf[1] = '\0';
            liste = lv_list_add(win_data->file_list, SYMBOL_DRIVE, buf, win_drv_action);
            lv_obj_set_free_p(liste, app);
        }
    }
    /*List the files/folders with fs interface*/
    else {
        liste = lv_list_add(win_data->file_list, SYMBOL_UP, "Up", win_up_action);
        lv_obj_set_free_p(liste, app);

        fs_readdir_t rd;
        res = fs_readdir_init(&rd, app_data->path);
        if(res != FS_RES_OK) {
            lv_app_notice_add("Can not read the\npath in Files");
        return;
        }

        /*At not first page add prev. page button */
        if(app_data->file_cnt != 0) {
            liste = lv_list_add(win_data->file_list, SYMBOL_LEFT, "Previous page", win_prev_action);
            lv_obj_set_free_p(liste, app);
        }

        char fn[LV_APP_FILES_FN_MAX_LEN];

        /*Read the files from the previous pages*/
        uint16_t file_cnt = 0;
        while(file_cnt <= app_data->file_cnt) {
            res = fs_readdir(&rd, fn);
            if(res != FS_RES_OK ){
                lv_app_notice_add("Can not read\nthe path in Files");
                return;
            }
            file_cnt ++;
        }

        /*Add list elements from the files and folders*/
        while(res == FS_RES_OK && fn[0] != '\0') {
            if(fn[0] == '/') { /*Add a folder*/
                lv_obj_t * liste;
                liste = lv_list_add(win_data->file_list, SYMBOL_FOLDER, &fn[1], win_folder_action);
                lv_obj_set_free_p(liste, app);
                app_data->file_cnt ++;
            }
            /*Add a file*/
            else {
                liste = lv_list_add(win_data->file_list, SYMBOL_FILE, fn, win_file_action);
                lv_obj_set_free_p(liste, app);
                app_data->file_cnt ++;
            }

            /*Get the next element*/
            res = fs_readdir(&rd, fn);

            /*Show only LV_APP_FSEL_MAX_FILE elements and add a Next page button*/
            if(app_data->file_cnt != 0 && app_data->file_cnt % LV_APP_FILES_PAGE_SIZE == 0) {
                liste = lv_list_add(win_data->file_list, SYMBOL_RIGHT, "Next page", win_next_action);
                lv_obj_set_free_p(liste, app);
                break;
            }
        }

      /*Close the read directory*/
      fs_readdir_close(&rd);
    }

    if(res != FS_RES_OK) {
        lv_app_notice_add("Can not read\nthe path in Files");
    }

    /*Focus to the top of the list*/
    lv_obj_set_y(lv_page_get_scrl(win_data->file_list), 0);
    return;
}
예제 #17
0
파일: fs_main.c 프로젝트: alkap007/ali3606
void usb_fs_unmount(UINT32 nodeid)
{
	int i;
	char mount_name[16];	
	int result;
	int devid;
	struct statvfs sfs;
	char dirbuf[sizeof(struct dirent) + 32];	
	struct dirent *dire = (struct dirent *)dirbuf;
	int fd;
	struct stat st;
	UINT32 msg_code = 0;

	int lunlist[16];
	
	INT32 lun_num = usb_hdd_get_lunlist(nodeid, lunlist, 16);

#ifdef USB_SUPPORT_HUB
	struct fs_sto_param fs_param;
	fs_param.type = MNT_TYPE_USB;
	fs_param.id = 0;
	fs_param.partition_id = 0;
#endif

	unlink_device("/c", MNT_TYPE_USB);
#if (SYS_CHIP_MODULE != ALI_S3602)
	unlink_device("/r", MNT_TYPE_USB);
#endif

	for( i = 0; i<lun_num; ++i)
	{
		devid = usb_hdd_get_dev(nodeid, lunlist[i]);
		if(devid < 0) continue;
			
#ifdef USB_SUPPORT_HUB
		fs_param.id = devid;
#endif		

		fd = fs_opendir("/mnt");
		while(fs_readdir(fd, dire) > 0)
		{
			fs_get_mount_name(MNT_TYPE_USB, devid, 0, mount_name);
			if(!MEMCMP(&dire->d_name, &mount_name[5], 3)) 
			{
				STRCPY(mount_name, "/mnt/");
				strcat(mount_name, dire->d_name);

				FS_PRINTF("unmount: %s ...", mount_name);
				result = fs_statvfs(mount_name, &sfs);
				if(result < 0)
				{
					FS_PRINTF("the %s is not mounted!\n", mount_name);
#if (SYS_CHIP_MODULE == ALI_S3602)
	#ifdef USB_SUPPORT_HUB
					FS_NOTICE_MESSAGE(MP_FS_UNMOUNT, MNT_MSG_PARAM(UNMNT_FAILED, fs_param.type, fs_param.id));
	#else
					FS_NOTICE_MESSAGE(MP_FS_UNMOUNT, MNT_MSG_PARAM(UNMNT_FAILED, MNT_TYPE_USB, 0));
//					USB_MESSAGE(MP_FS_UNMOUNT, UNMNT_FAILED);
	#endif
#else
	#ifdef USB_SUPPORT_HUB
					fs_param.msg_code = UNMNT_FAILED;
					msg_code = fs_param.type<<24 | fs_param.id<<16 | fs_param.partition_id<<8 | fs_param.msg_code;
	#else
					msg_code = 1;
	#endif		
					FS_NOTICE_MESSAGE(MP_FS_UNMOUNT, msg_code);
#endif			
					continue;
				}

				result = fs_unmount(mount_name, 1);
				if(result < 0)
				{
					FS_PRINTF("the %s is unmounted failed!\n", mount_name);
#if (SYS_CHIP_MODULE == ALI_S3602)
	#ifdef USB_SUPPORT_HUB
					FS_NOTICE_MESSAGE(MP_FS_UNMOUNT, MNT_MSG_PARAM(UNMNT_FAILED, fs_param.type, fs_param.id));
	#else
					FS_NOTICE_MESSAGE(MP_FS_UNMOUNT, MNT_MSG_PARAM(UNMNT_FAILED, MNT_TYPE_USB, 0));
//					USB_MESSAGE(MP_FS_UNMOUNT, UNMNT_FAILED);
	#endif
#else
	#ifdef USB_SUPPORT_HUB
					fs_param.msg_code = UNMNT_FAILED;
					msg_code = fs_param.type<<24 | fs_param.id<<16 | fs_param.partition_id<<8 | fs_param.msg_code;
	#else
					msg_code = 1;
	#endif		
					FS_NOTICE_MESSAGE(MP_FS_UNMOUNT, msg_code);
#endif							
					FS_PRINTF("failed! err = %d\n", result);
				}
				else
				{
					FS_PRINTF("successed!\n");
				}
				
				fs_rmdir(mount_name);
			}
		}

		//FS_PRINTF("fs_unmount ok!\n");

#ifdef USB_SUPPORT_HUB	//fix for usb with multi-device, every device should notify APP				
#if (SYS_CHIP_MODULE != ALI_S3602)
		fs_param.msg_code = UNMNT_PLUGOUT;
		msg_code = fs_param.type<<24 | fs_param.id<<16 | fs_param.partition_id<<8 | fs_param.msg_code;
		FS_NOTICE_MESSAGE(MP_FS_UNMOUNT, msg_code);
		fs_param.msg_code = UNMNT_UNMOUNT;
		msg_code = fs_param.type<<24 | fs_param.id<<16 | fs_param.partition_id<<8 | fs_param.msg_code;
		FS_NOTICE_MESSAGE(MP_FS_UNMOUNT, msg_code);
#endif
#endif
		fs_closedir(fd);
		usb_hdd_cleanup(nodeid, lunlist[i]);
		
#if (SYS_CHIP_MODULE == ALI_S3602)
	#ifdef USB_SUPPORT_HUB
		FS_NOTICE_MESSAGE(MP_FS_UNMOUNT, MNT_MSG_PARAM(UNMNT_UNMOUNT_OK, fs_param.type, fs_param.id));
	#else
		FS_NOTICE_MESSAGE(MP_FS_UNMOUNT, MNT_MSG_PARAM(UNMNT_UNMOUNT_OK, MNT_TYPE_USB, 0));
	#endif
#endif
	}

#ifndef USB_SUPPORT_HUB
#if (SYS_CHIP_MODULE != ALI_S3602)
#ifdef USB_SUPPORT_HUB
	fs_param.msg_code = UNMNT_PLUGOUT;
	msg_code = fs_param.type<<24 | fs_param.id<<16 | fs_param.partition_id<<8 | fs_param.msg_code;
#else
	msg_code = 0;
#endif		
	FS_NOTICE_MESSAGE(MP_FS_UNMOUNT, msg_code);
#ifdef USB_SUPPORT_HUB
	fs_param.msg_code = UNMNT_UNMOUNT;
	msg_code = fs_param.type<<24 | fs_param.id<<16 | fs_param.partition_id<<8 | fs_param.msg_code;
#else
	msg_code = 2;
#endif		
	FS_NOTICE_MESSAGE(MP_FS_UNMOUNT, msg_code);
#endif
#endif
}
예제 #18
0
/*
 * Traverse the file system in the level-order way.  The description
 * and example is in the header file.
 */
int
traverse_level(struct fs_traverse *ftp)
{
	char path[PATH_MAX + 1];	/* full path name of the current dir */
	char nm[NAME_MAX + 1];	/* directory entry name */
	char *lp;		/* last position on the path */
	int next_dir, rv;
	int pl, el;		/* path and directory entry length */

	cstack_t *sp;
	fs_fhandle_t pfh, efh;
	struct stat64 pst, est;
	traverse_state_t *tsp;
	struct fst_node pn, en;  /* parent and entry nodes */
	dent_arg_t darg;

	if (!ftp || !ftp->ft_path || !*ftp->ft_path || !ftp->ft_callbk) {
		NDMP_LOG(LOG_DEBUG, "Invalid argument");
		errno = EINVAL;
		return (-1);
	}
	/* set the default log function if it's not already set */
	if (!ftp->ft_logfp) {
		ftp->ft_logfp = (ft_log_t)syslog;
		NDMP_LOG(LOG_DEBUG, "Log to system log \"%s\"", ftp->ft_path);
	}
	if (!ftp->ft_lpath) {
		NDMP_LOG(LOG_DEBUG,
		    "report the same paths \"%s\"", ftp->ft_path);
		ftp->ft_lpath = ftp->ft_path;
	}

	pl = strlen(ftp->ft_lpath);
	if (pl + 1 > PATH_MAX) { /* +1 for the '/' */
		NDMP_LOG(LOG_DEBUG, "lpath too long \"%s\"", ftp->ft_path);
		errno = ENAMETOOLONG;
		return (-1);
	}
	(void) strcpy(path, ftp->ft_lpath);
	(void) memset(&pfh, 0, sizeof (pfh));
	rv = fs_getstat(ftp->ft_lpath, &pfh, &pst);
	if (rv != 0) {
		NDMP_LOG(LOG_DEBUG,
		    "Error %d on fs_getstat(%s)", rv, ftp->ft_path);
		return (-1);
	}

	en.tn_path = NULL;
	en.tn_fh = NULL;
	en.tn_st = NULL;
	if (!S_ISDIR(pst.st_mode)) {
		pn.tn_path = ftp->ft_lpath;
		pn.tn_fh = &pfh;
		pn.tn_st = &pst;
		rv = CALLBACK(&pn, &en);
		if (VERBOSE(ftp))
			NDMP_LOG(LOG_DEBUG, "CALLBACK(%s): %d", pn.tn_path, rv);

		free(pfh.fh_fpath);
		return (rv);
	}

	sp = cstack_new();
	if (!sp) {
		free(pfh.fh_fpath);
		errno = ENOMEM;
		return (-1);
	}
	tsp = new_tsp(path);
	if (!tsp) {
		cstack_delete(sp);
		free(pfh.fh_fpath);
		errno = ENOMEM;
		return (-1);
	}

	darg.da_buf = ndmp_malloc(MAX_DENT_BUF_SIZE);
	if (!darg.da_buf) {
		cstack_delete(sp);
		free(pfh.fh_fpath);
		free(tsp);
		errno = ENOMEM;
		return (-1);
	}
	darg.da_size = MAX_DENT_BUF_SIZE;

	tsp->ts_ent = tsp->ts_end;
	tsp->ts_fh = pfh;
	tsp->ts_st = pst;
	pn.tn_path = path;
	pn.tn_fh = &tsp->ts_fh;
	pn.tn_st = &tsp->ts_st;

	/* call the callback function on the path itself */
	traverse_stats.fss_dir_calls++;
	rv = CALLBACK(&pn, &en);
	if (rv < 0) {
		free(tsp);
		goto end;
	}
	if (rv == FST_SKIP) {
		traverse_stats.fss_dir_skipped++;
		free(tsp);
		rv = 0;
		goto end;
	}

	rv = 0;
	next_dir = 1;
	do {
		if (next_dir) {
			traverse_stats.fss_newdirs++;

			*tsp->ts_end = '\0';
			if (VERBOSE(ftp))
				NDMP_LOG(LOG_DEBUG, "pl %d \"%s\"", pl, path);

			rv = traverse_level_nondir(ftp, tsp, &pn, &darg);
			if (rv < 0) {
				NEGATE(rv);
				free(tsp->ts_fh.fh_fpath);
				free(tsp);
				break;
			}
			/*
			 * If skipped by the callback function or
			 * error happened reading the information
			 */
			if (rv == FST_SKIP || rv == SKIP_ENTRY) {
				/*
				 * N.B. next_dir should be set to 0 as
				 * well. This prevents the infinite loop.
				 * If it's not set the same directory will
				 * be poped from the stack and will be
				 * scanned again.
				 */
				next_dir = 0;
				rv = 0;
				goto skip_dir;
			}

			/* re-start reading entries of the directory */
			tsp->ts_dpos = 0;
		}

		next_dir = 0;
		do {
			el = NAME_MAX;
			rv = fs_readdir(&tsp->ts_fh, pn.tn_path,
			    &tsp->ts_dpos, nm, &el, &efh,
			    &est);
			if (rv != 0) {
				traverse_stats.fss_readdir_err++;

				NDMP_LOG(LOG_DEBUG,
				    "Error %d on readdir(%s) pos %d",
				    rv, path, tsp->ts_dpos);
				if (STOP_ONERR(ftp))
					break;
				rv = SKIP_ENTRY;
				continue;
			}

			/* done with this directory */
			if (el == 0)
				break;

			nm[el] = '\0';

			if (rootfs_dot_or_dotdot(nm)) {
				free(efh.fh_fpath);
				continue;
			}

			if (VERBOSE(ftp))
				NDMP_LOG(LOG_DEBUG, "%u dname: \"%s\"",
				    tsp->ts_dpos, nm);

			if (pl + 1 + el > PATH_MAX) {
				/*
				 * The long paths were already encountered
				 * when processing non-dir entries in.
				 * traverse_level_nondir.
				 * We don't increase fss_longpath_err
				 * counter for them again here.
				 */
				NDMP_LOG(LOG_ERR, "Path %s/%s is too long.",
				    path, nm);
				if (STOP_ONLONG(ftp))
					rv = ENAMETOOLONG;
				free(efh.fh_fpath);
				continue;
			}

			if (!S_ISDIR(est.st_mode))
				continue;

			/*
			 * Call the callback function for the new
			 * directory found, then push the current
			 * directory on to the stack.  Then dive
			 * into the entry found.
			 */
			traverse_stats.fss_dir_calls++;
			en.tn_path = nm;
			en.tn_fh = &efh;
			en.tn_st = &est;
			rv = CALLBACK(&pn, &en);

			if (rv < 0) {
				NEGATE(rv);
				free(efh.fh_fpath);
				break;
			}
			if (rv == FST_SKIP) {
				traverse_stats.fss_dir_skipped++;
				free(efh.fh_fpath);
				rv = 0;
				continue;
			}

			/*
			 * Push the current directory on to the stack and
			 * dive into the entry found.
			 */
			if (cstack_push(sp, tsp, 0)) {
				rv = ENOMEM;
			} else {
				traverse_stats.fss_pushes++;

				lp = tsp->ts_end;
				*tsp->ts_end = '/';
				(void) strcpy(tsp->ts_end + 1, nm);

				tsp = new_tsp(path);
				if (!tsp)
					rv = ENOMEM;
				else {
					next_dir = 1;
					pl += el + 1;
					tsp->ts_fh = efh;
					tsp->ts_st = est;
					tsp->ts_ent = lp;
					pn.tn_fh = &tsp->ts_fh;
					pn.tn_st = &tsp->ts_st;
				}
			}
			break;

		} while (rv == 0);

		/*
		 * A new directory must be processed, go to the start of
		 * the loop, open it and process it.
		 */
		if (next_dir)
			continue;
skip_dir:
		if (tsp) {
			free(tsp->ts_fh.fh_fpath);
			free(tsp);
		}

		if (rv == SKIP_ENTRY)
			rv = 0;

		if (rv == 0) {
			if (cstack_pop(sp, (void **)&tsp, (int *)NULL))
				break;

			traverse_stats.fss_pops++;

			if (VERBOSE(ftp))
				NDMP_LOG(LOG_DEBUG,
				    "Poped pl %d \"%s\"", pl, path);

			*tsp->ts_end = '\0';
			pl = tsp->ts_end - path;
			pn.tn_fh = &tsp->ts_fh;
			pn.tn_st = &tsp->ts_st;
		}
	} while (rv == 0);

	/*
	 * Pop and free all the remaining entries on the stack.
	 */
	while (!cstack_pop(sp, (void **)&tsp, (int *)NULL)) {
		traverse_stats.fss_stack_residue++;

		free(tsp->ts_fh.fh_fpath);
		free(tsp);
	}
end:
	free(darg.da_buf);
	cstack_delete(sp);
	return (rv);
}
예제 #19
0
int DC_CheckForMaps(char *path) {
    file_t dir;
    dirent_t *dirent;
    char fpath[1024];
    int disc_status;

    for(;;) {
        SDL_Delay(5);
        disc_status = DC_CheckDrive();
#ifdef SPEAR
        DC_DrawString(4, 1, "Sod4SDL\\DC");
#else
        DC_DrawString(4, 1, "Wolf4SDL\\DC");
#endif
        switch(disc_status) {
            //case CD_STATUS_BUSY:
            //case CD_STATUS_OPEN:
            //    DC_DrawString(4, 6, "Please insert your Wolfenstein 3D CD.");
            //    break;
            default:
                dir = fs_open(path, O_DIR);
                while(dirent = fs_readdir(dir)) {
#ifdef SPEAR
#ifdef SPEARDEMO
                    if(!strcmp(dirent->name, "AUDIOHED.SDM")) {
                        fs_close(dir);
                        strcpy(dcwolf3dpath, path);
                        return 0;
                    }
#else
                    if(!strcmp(dirent->name, "AUDIOHED.SOD")) {
                        fs_close(dir);
                        strcpy(dcwolf3dpath, path);
                        param_mission = DC_SetMission(path);
                        return 0;
                    }
#endif
#else
#ifdef UPLOAD
                    if(!strcmp(dirent->name, "AUDIOHED.WL1")) {
                        fs_close(dir);
                        strcpy(dcwolf3dpath, path);
                        return 0;
                    }
#else
                    if(!strcmp(dirent->name, "AUDIOHED.WL6")) {
                        fs_close(dir);
                        strcpy(dcwolf3dpath, path);
                        return 0;
                    }
#endif
#endif
                    strcpy(fpath, path);
                    sprintf(fpath, "%s/%s", fpath, dirent->name);
                    DC_CheckForMaps(fpath);
                }
                fs_close(dir);
                return -1;
        }
        DC_Flip();
    }
}
예제 #20
0
파일: fs_main.c 프로젝트: alkap007/ali3606
void ide_fs_mount(UINT32 param)
{
	int result = -EIO; 
	int vol_ns = 0;

	char dirbuf[sizeof(struct dirent) + 32];	
	struct dirent *dire = (struct dirent *)dirbuf;
	char dev_name[16], vol_name[16];
	int fd;

	//install the hdd
	if(ide_hdd_init(0) != 0)
	{
		FS_PRINTF("ide hdd init failed!\n");
#if (SYS_CHIP_MODULE == ALI_S3602)
		FS_NOTICE_MESSAGE(MP_FS_MOUNT, MNT_MSG_PARAM(MNT_FAILED, MNT_TYPE_IDE, 0));
//		IDE_MESSAGE(MP_FS_MOUNT, MNT_FAILED);
#else
		FS_NOTICE_MESSAGE(MP_FS_MOUNT, 1+100);
#endif
		return;
	}

#if (SYS_CHIP_MODULE == ALI_S3602)
	FS_NOTICE_MESSAGE(MP_FS_MOUNT, MNT_MSG_PARAM(MNT_MOUNT, MNT_TYPE_IDE, 0));
//	IDE_MESSAGE(MP_FS_MOUNT, MNT_MOUNT);
#else
	FS_NOTICE_MESSAGE(MP_FS_MOUNT, 2+100);
#endif
	
	//FS_NOTICE_MESSAGE(MP_FS_IDE_MOUNT_NAME, (UINT32)mount_name);

	//loop the /dev try to mount all the device
	fd = fs_opendir("/dev");
	while(fs_readdir(fd, dire) > 0)
	{
		fs_get_mount_name(MNT_TYPE_IDE, 0, 0, dev_name);
		if((STRLEN(dire->d_name) == 4) && !MEMCMP(&dire->d_name, &dev_name[5], 3)) 
		{
			STRCPY(dev_name, "/dev/");
			strcat(dev_name, dire->d_name);
			
			STRCPY(vol_name, "/mnt/");
			strcat(vol_name, dire->d_name);
			
			//mount the device
			result = mount_device(dev_name, vol_name);
			if(result >= 0)
			{
				link_device(vol_name, "/c");
#if (SYS_CHIP_MODULE != ALI_S3602)
				link_device(vol_name, "/r");
#endif
				vol_ns++; 
			}
		}
	}

	fs_closedir(fd);
	
	if(vol_ns == 0)
	{
		FS_PRINTF("fs mount failed!\n");
#if (SYS_CHIP_MODULE == ALI_S3602)
		FS_NOTICE_MESSAGE(MP_FS_MOUNT, MNT_MSG_PARAM(MNT_FAILED, MNT_TYPE_IDE, 0));
//		IDE_MESSAGE(MP_FS_MOUNT, MNT_FAILED);
#else
		FS_NOTICE_MESSAGE(MP_FS_MOUNT, 100 + 1);
#endif		
		return;
	}

#if (SYS_CHIP_MODULE == ALI_S3602)
	FS_NOTICE_MESSAGE(MP_FS_MOUNT, MNT_MSG_PARAM(MNT_MOUNT_OK, MNT_TYPE_IDE, 0));
//	IDE_MESSAGE(MP_FS_MOUNT, MNT_MOUNT_OK);
#else
	FS_NOTICE_MESSAGE(MP_FS_MOUNT, 3+100);
#endif
		
	return;
}
예제 #21
0
파일: fs_main.c 프로젝트: alkap007/ali3606
void sata_fs_unmount(UINT32 param)
{
	int i;
	char mount_name[16];	
	int result;
	struct statvfs sfs;
	int fd;
	
	char dirbuf[sizeof(struct dirent) + 32];	
	struct dirent *dire = (struct dirent *)dirbuf;

	struct fs_sto_param fs_param;
	
	fs_param.type = MNT_TYPE_SATA;
	fs_param.id = 0;
	fs_param.partition_id = 0;

	fd = fs_opendir("/mnt");

	while (fs_readdir(fd, dire) > 0)
	{
		fs_get_mount_name(MNT_TYPE_SATA, 0, 0, mount_name);
		if(!MEMCMP(&dire->d_name, &mount_name[5], 3))
		{
			STRCPY(mount_name, "/mnt/");
			strcat(mount_name, dire->d_name);

			FS_PRINTF("unmount: %s ...\n", mount_name);
			result = fs_statvfs(mount_name, &sfs);
			if (result < 0)
			{
				FS_PRINTF("%s is not mounted! err = %d\n", mount_name, result);
				fs_param.msg_code = UNMNT_FAILED;
				PUT_MESSAGE(MP_FS_UNMOUNT, fs_param);
				continue;
			}

			result = fs_unmount(mount_name, 1);
			if (result < 0)
			{
				FS_PRINTF("%s unmounted failed! err = %d\n", mount_name, result);
				fs_param.msg_code = UNMNT_FAILED;
				PUT_MESSAGE(MP_FS_UNMOUNT, fs_param);
			}
			else
			{
				FS_PRINTF("%s unmounted successed!\n", mount_name);
			}

	        result = fs_rmdir(mount_name);
			if (result < 0)
			{
	            FS_PRINTF("remove dir %s failed! err = %d\n", mount_name, result);
			}
		}	
	}	

	fs_closedir(fd);
    sata_hdd_cleanup(0);
	fs_param.msg_code = UNMNT_UNMOUNT_OK;
	PUT_MESSAGE(MP_FS_UNMOUNT, fs_param);

	return;
}
예제 #22
0
파일: fs_main.c 프로젝트: alkap007/ali3606
void sata_fs_mount(UINT32 param)
{
	int result = -EIO; 
	int vol_ns = 0;

	char dirbuf[sizeof(struct dirent) + 32];	
	struct dirent *dire = (struct dirent *)dirbuf;
	char dev_name[16], vol_name[16];
	int fd;

	struct fs_sto_param fs_param;
	
	fs_param.type = MNT_TYPE_SATA;
	fs_param.id = 0;
	fs_param.partition_id = 0;

	//install the sata hdd
	if(sata_hdd_init(0) != 0)
	{
		FS_PRINTF("sata hdd init failed!\n");
		
		fs_param.msg_code = MNT_FAILED;
		PUT_MESSAGE(MP_FS_MOUNT, fs_param);
		return;
	}

	fs_param.msg_code = MNT_MOUNT;
	PUT_MESSAGE(MP_FS_MOUNT, fs_param);
	
	//loop the /dev try to mount all the device
	fd = fs_opendir("/dev");
	while(fs_readdir(fd, dire) > 0)
	{
		fs_get_mount_name(MNT_TYPE_SATA, 0, 0, dev_name);
		if((STRLEN(dire->d_name) == 4) && !MEMCMP(&dire->d_name, &dev_name[5], 3)) 
		{
			STRCPY(dev_name, "/dev/");
			strcat(dev_name, dire->d_name);
			
			STRCPY(vol_name, "/mnt/");
			strcat(vol_name, dire->d_name);
			
			//mount the device
			result = mount_device(dev_name, vol_name);
			if(result >= 0)
			{
#if (SYS_CHIP_MODULE != ALI_S3602)
#ifdef PVR_MULTI_VOLUME_SUPPORT
				link_device(vol_name, "/r");
#endif
#endif
				vol_ns++; 
			}
		}
	}

	fs_closedir(fd);
	
	if(vol_ns == 0)
	{
		FS_PRINTF("fs mount failed!\n");
		fs_param.msg_code = MNT_FAILED;
		PUT_MESSAGE(MP_FS_MOUNT, fs_param);
		return;
	}

	fs_param.msg_code = MNT_MOUNT_OK;
	PUT_MESSAGE(MP_FS_MOUNT, fs_param);
		
	return;
}
예제 #23
0
void MyMainWindow::scanFolder() {

    const std::string &m_file = m_player->file();
    const char *f = strrchr(m_file.c_str(), '/');

    if(!f)
        return;

    ++f;

    m_playFile = m_file;

    char folder[128];
    memcpy(folder, m_file.c_str(), f-m_file.c_str());
    folder[f-m_file.c_str()] = 0;

    m_workFolder = folder;

    int h = fs_opendir(folder);

    printf("open %s - %d\n", folder, h);

    std::string fname = path2name(m_playFile);

    if(h > 0) {
        FS_INFO info;
        while(!fs_readdir(h, &info)) {

            if(!(info.attr & FS_ATTR_FOLDER)) {

                ListMenuItem *mi = 0;
                m_mediaList.scrollArea().addItem(
                           (mi = new ListMenuItem(&m_mediaList, m_mediaList.rect().w(), 40, info.name)) );

                if(info.name == fname) {
                    mi->setIcon( &resource_manager->image("played") );
                    m_currentPlayedItem = mi;

                } else
                    mi->setIcon( &resource_manager->image("music_small") );

                mi->onReleasedSignal().connect( [this](ListMenuItem *i) {
                    m_playFile = m_workFolder + i->text();
                    m_player->play(m_playFile);
                    m_headText.setText(i->text());
                    m_headText.start(200);

                    m_currentPlayedItem->setIcon( &resource_manager->image("music_small") );
                    i->setIcon( &resource_manager->image("played") );

                    m_currentPlayedItem = i;
                    eventManager()->updateAfterEvent();
                });
            }
        }

        fs_closedir(h);
    }



    m_mediaList.scrollArea().setLinesCount(m_mediaList.scrollArea().items().size());
}
예제 #24
0
파일: fs_main.c 프로젝트: alkap007/ali3606
void usb_fs_mount(UINT32 nodeid)
{
	int result = -EIO; 
	int hdd_ns = 0;
	int vol_ns = 0;

	int i = 0;
	int j = 0;

	char dirbuf[sizeof(struct dirent) + 32];	
	struct dirent *dire = (struct dirent *)dirbuf;
	char dev_name[16], vol_name[16];
	int fd;
	struct stat st;
	int devid;
	UINT32 msg_code = 0;
    INT32 lun_num;
	
	lun_num = usb_get_max_lun(nodeid);
	
#ifdef USB_SUPPORT_HUB
	struct fs_sto_param fs_param;
	fs_param.type = MNT_TYPE_USB;
	fs_param.id = 0;
	fs_param.partition_id = 0;
#endif	
	FS_PRINTF("USB lun_num = %d\n", lun_num);
	//firstly create all the device and partitions    
	for( i = 0; i< lun_num; ++i)
	{
		if(usb_check_lun_ready(nodeid, i))
		{			
			result = usb_dev_fs_init(nodeid, i);
			if(result == 0)
			{
				/* usb hdd is ready, we should send message to UI */
				int hdd_vol_ns = 0; // how many volume of this hdd mount success 
				hdd_ns++;

				//loop the /dev try to mount all the device
				devid = usb_hdd_get_dev(nodeid, i);
#ifdef USB_SUPPORT_HUB
				fs_param.id = devid;
#endif
				fd = fs_opendir("/dev");
				while(fs_readdir(fd, dire) > 0)
				{
					fs_get_mount_name(MNT_TYPE_USB, devid, 0, dev_name);
					if((STRLEN(dire->d_name) == 4) && !MEMCMP(&dire->d_name, &dev_name[5], 3)) 
					{
						STRCPY(dev_name, "/dev/");
						strcat(dev_name, dire->d_name);
						
						STRCPY(vol_name, "/mnt/");
						strcat(vol_name, dire->d_name);
						
						//mount the device
						result = mount_device(dev_name, vol_name);
						if(result >= 0)
						{
							link_device(vol_name, "/c");
#if (SYS_CHIP_MODULE != ALI_S3602)
							link_device(vol_name, "/r");
#endif
							vol_ns++; 
							hdd_vol_ns++;
#if (defined(FS_MAX_USB_VOLUME_SUPPORT))
							if (hdd_vol_ns >= FS_MAX_USB_VOLUME_SUPPORT)
								break;
#elif ((SYS_SDRAM_SIZE == 64) && (defined(M36F_CHIP_MODE)||defined(S3811_CHIP_MODE)))
							if (hdd_vol_ns >= 4)
								break;
#endif							  
						}
					}
				}

				fs_closedir(fd);
				
#if (SYS_CHIP_MODULE == ALI_S3602)
				int mnt_status = (hdd_vol_ns > 0) ? MNT_MOUNT_OK : MNT_FAILED;
	#ifdef USB_SUPPORT_HUB
				FS_NOTICE_MESSAGE(MP_FS_MOUNT, MNT_MSG_PARAM(mnt_status, fs_param.type, fs_param.id));
	#else
				FS_NOTICE_MESSAGE(MP_FS_MOUNT, MNT_MSG_PARAM(mnt_status, MNT_TYPE_USB, 0));
	#endif
#endif
			}
			else
			{
				FS_PRINTF("device lun = %d init failed! err = %d\n", i, result);
			}
		}
	}

	if(hdd_ns == 0)
	{
		FS_PRINTF("all the device are inited failed!\n");
#if (SYS_CHIP_MODULE != ALI_S3602)
	#ifdef USB_SUPPORT_HUB
		fs_param.msg_code = MNT_NO_PARTITION;
		msg_code = fs_param.type<<24 | fs_param.id<<16 | fs_param.partition_id<<8 | fs_param.msg_code;
	#else
		msg_code = 11;
	#endif		
		FS_NOTICE_MESSAGE(MP_FS_MOUNT, msg_code);
#endif		
		return;		
	}
	
	if(vol_ns == 0)
	{
		FS_PRINTF("fs mount failed!\n");
#if (SYS_CHIP_MODULE != ALI_S3602)
	#ifdef USB_SUPPORT_HUB
		fs_param.msg_code = MNT_FAILED;
		msg_code = fs_param.type<<24 | fs_param.id<<16 | fs_param.partition_id<<8 | fs_param.msg_code;
	#else
		msg_code = 1;
	#endif		
		FS_NOTICE_MESSAGE(MP_FS_MOUNT, msg_code);
#endif		
		return;
	}

#if (SYS_CHIP_MODULE != ALI_S3602)
#ifdef USB_SUPPORT_HUB
	fs_param.msg_code = MNT_MOUNT_OK;
	msg_code = fs_param.type<<24 | fs_param.id<<16 | fs_param.partition_id<<8 | fs_param.msg_code;
#else
	msg_code = 3;
#endif		
	FS_NOTICE_MESSAGE(MP_FS_MOUNT, msg_code);
#endif
	
	return;
}
예제 #25
0
/*
 * Traverse the file system in the post-order way.  The description
 * and example is in the header file.
 *
 * The callback function should return 0, on success and non-zero on
 * failure.  If the callback function returns non-zero return value,
 * the traversing stops.
 */
int
traverse_post(struct fs_traverse *ftp)
{
	char path[PATH_MAX + 1]; /* full path name of the current dir */
	char nm[NAME_MAX + 1]; /* directory entry name */
	char *lp; /* last position on the path */
	int next_dir, rv;
	int pl, el; /* path and directory entry length */
	cstack_t *sp;
	fs_fhandle_t pfh, efh;
	struct stat64 pst, est;
	traverse_state_t *tsp;
	struct fst_node pn, en; /* parent and entry nodes */

	if (!ftp || !ftp->ft_path || !*ftp->ft_path || !ftp->ft_callbk) {
		NDMP_LOG(LOG_DEBUG, "Invalid argument");
		errno = EINVAL;
		return (-1);
	}

	/* set the default log function if it's not already set */
	if (!ftp->ft_logfp) {
		ftp->ft_logfp = (ft_log_t)syslog;
		NDMP_LOG(LOG_DEBUG, "Log to system log \"%s\"", ftp->ft_path);
	}

	/* set the logical path to physical path if it's not already set */
	if (!ftp->ft_lpath) {
		NDMP_LOG(LOG_DEBUG,
		    "report the same paths: \"%s\"", ftp->ft_path);
		ftp->ft_lpath = ftp->ft_path;
	}

	pl = strlen(ftp->ft_lpath);
	if (pl + 1 > PATH_MAX) { /* +1 for the '/' */
		NDMP_LOG(LOG_DEBUG, "lpath too long \"%s\"", ftp->ft_path);
		errno = ENAMETOOLONG;
		return (-1);
	}
	(void) strcpy(path, ftp->ft_lpath);
	(void) memset(&pfh, 0, sizeof (pfh));
	rv = fs_getstat(ftp->ft_lpath, &pfh, &pst);

	if (rv != 0) {
		NDMP_LOG(LOG_DEBUG,
		    "Error %d on fs_getstat(%s)", rv, ftp->ft_path);
		return (rv);
	}

	if (!S_ISDIR(pst.st_mode)) {
		pn.tn_path = ftp->ft_lpath;
		pn.tn_fh = &pfh;
		pn.tn_st = &pst;
		en.tn_path = NULL;
		en.tn_fh = NULL;
		en.tn_st = NULL;
		rv = CALLBACK(&pn, &en);
		if (VERBOSE(ftp))
			NDMP_LOG(LOG_DEBUG, "CALLBACK(%s): %d", pn.tn_path, rv);
		free(pfh.fh_fpath);
		return (rv);
	}

	sp = cstack_new();
	if (!sp) {
		errno = ENOMEM;
		free(pfh.fh_fpath);
		return (-1);
	}
	tsp = new_tsp(path);
	if (!tsp) {
		cstack_delete(sp);
		errno = ENOMEM;
		free(pfh.fh_fpath);
		return (-1);
	}
	tsp->ts_ent = tsp->ts_end;
	tsp->ts_fh = pfh;
	tsp->ts_st = pst;
	pn.tn_path = path;
	pn.tn_fh = &tsp->ts_fh;
	pn.tn_st = &tsp->ts_st;

	rv = 0;
	next_dir = 1;
	do {
		if (next_dir) {
			traverse_stats.fss_newdirs++;

			*tsp->ts_end = '\0';
			if (VERBOSE(ftp))
				NDMP_LOG(LOG_DEBUG, "pl %d \"%s\"", pl, path);
		}

		next_dir = 0;
		do {
			el = NAME_MAX;
			rv = fs_readdir(&tsp->ts_fh, pn.tn_path,
			    &tsp->ts_dpos, nm, &el,
			    &efh, &est);

			if (rv != 0) {
				free(efh.fh_fpath);
				traverse_stats.fss_readdir_err++;

				NDMP_LOG(LOG_DEBUG,
				    "Error %d on readdir(%s) pos %d",
				    rv, path, tsp->ts_dpos);
				if (STOP_ONERR(ftp))
					break;
				rv = SKIP_ENTRY;

				continue;
			}

			/* done with this directory */
			if (el == 0) {
				if (VERBOSE(ftp))
					NDMP_LOG(LOG_DEBUG,
					    "Done(%s)", pn.tn_path);
				break;
			}
			nm[el] = '\0';

			if (rootfs_dot_or_dotdot(nm)) {
				free(efh.fh_fpath);
				continue;
			}

			if (VERBOSE(ftp))
				NDMP_LOG(LOG_DEBUG, "%u dname: \"%s\"",
				    tsp->ts_dpos, nm);

			if (pl + 1 + el > PATH_MAX) {
				traverse_stats.fss_longpath_err++;

				NDMP_LOG(LOG_ERR, "Path %s/%s is too long.",
				    path, nm);
				if (STOP_ONLONG(ftp))
					rv = ENAMETOOLONG;
				free(efh.fh_fpath);
				continue;
			}

			/*
			 * Push the current directory on to the stack and
			 * dive into the entry found.
			 */
			if (S_ISDIR(est.st_mode)) {

				assert(tsp != NULL);
				if (cstack_push(sp, tsp, 0)) {
					rv = ENOMEM;
					free(efh.fh_fpath);
					break;
				}
				traverse_stats.fss_pushes++;

				/*
				 * Concatenate the current entry with the
				 * current path.  This will be the path of
				 * the new directory to be scanned.
				 *
				 * Note:
				 * sprintf(tsp->ts_end, "/%s", de->d_name);
				 * could be used here, but concatenating
				 * strings like this might be faster.
				 * The length of the new path has been
				 * checked above.  So strcpy() can be
				 * safe and should not lead to a buffer
				 * over-run.
				 */
				lp = tsp->ts_end;
				*tsp->ts_end = '/';
				(void) strcpy(tsp->ts_end + 1, nm);

				tsp = new_tsp(path);
				if (!tsp) {
					free(efh.fh_fpath);
					rv = ENOMEM;
				} else {
					next_dir = 1;
					pl += el;
					tsp->ts_fh = efh;
					tsp->ts_st = est;
					tsp->ts_ent = lp;
					pn.tn_fh = &tsp->ts_fh;
					pn.tn_st = &tsp->ts_st;
				}
				break;
			} else {
				/*
				 * The entry is not a directory so the
				 * callback function must be called.
				 */
				traverse_stats.fss_nondir_calls++;

				en.tn_path = nm;
				en.tn_fh = &efh;
				en.tn_st = &est;
				rv = CALLBACK(&pn, &en);
				free(efh.fh_fpath);
				if (VERBOSE(ftp))
					NDMP_LOG(LOG_DEBUG,
					    "CALLBACK(%s/%s): %d",
					    pn.tn_path, en.tn_path, rv);

				if (rv != 0)
					break;
			}
		} while (rv == 0);

		/*
		 * A new directory must be processed, go to the start of
		 * the loop, open it and process it.
		 */
		if (next_dir)
			continue;

		if (rv == SKIP_ENTRY)
			rv = 0; /* We should skip the current directory */

		if (rv == 0) {
			/*
			 * Remove the ent from the end of path and send it
			 * as an entry of the path.
			 */
			lp = tsp->ts_ent;
			*lp = '\0';
			efh = tsp->ts_fh;
			est = tsp->ts_st;
			free(tsp);
			if (cstack_pop(sp, (void **)&tsp, (int *)NULL))
				break;

			assert(tsp != NULL);
			pl = tsp->ts_end - path;

			if (VERBOSE(ftp))
				NDMP_LOG(LOG_DEBUG, "poped pl %d 0x%p \"%s\"",
				    pl, tsp, path);

			traverse_stats.fss_pops++;
			traverse_stats.fss_dir_calls++;

			pn.tn_fh = &tsp->ts_fh;
			pn.tn_st = &tsp->ts_st;
			en.tn_path = lp + 1;
			en.tn_fh = &efh;
			en.tn_st = &est;

			rv = CALLBACK(&pn, &en);
			free(efh.fh_fpath);
			if (VERBOSE(ftp))
				NDMP_LOG(LOG_DEBUG, "CALLBACK(%s/%s): %d",
				    pn.tn_path, en.tn_path, rv);
			/*
			 * Does not need to free tsp here.  It will be released
			 * later.
			 */
		}

		if (rv != 0 && tsp) {
			free(tsp->ts_fh.fh_fpath);
			free(tsp);
		}

	} while (rv == 0);

	/*
	 * For the 'ftp->ft_path' directory itself.
	 */
	if (rv == 0) {
		traverse_stats.fss_dir_calls++;

		pn.tn_fh = &efh;
		pn.tn_st = &est;
		en.tn_path = NULL;
		en.tn_fh = NULL;
		en.tn_st = NULL;
		rv = CALLBACK(&pn, &en);
		if (VERBOSE(ftp))
			NDMP_LOG(LOG_DEBUG, "CALLBACK(%s): %d", pn.tn_path, rv);
	}

	/*
	 * Pop and free all the remaining entries on the stack.
	 */
	while (!cstack_pop(sp, (void **)&tsp, (int *)NULL)) {
		traverse_stats.fss_stack_residue++;

		free(tsp->ts_fh.fh_fpath);
		free(tsp);
	}

	cstack_delete(sp);
	return (rv);
}
예제 #26
0
파일: module.c 프로젝트: i-rom/DreamShell
void gd_ripper_StartRip() {
	file_t fd;
	CDROM_TOC toc ;
	int status, disc_type ,cdcr ,start ,s_end ,nsec ,type ,tn ,session,terr=0;
	char dst_folder[MAX_FN_LEN];
	char dst_file[MAX_FN_LEN];
	char riplabel[64];
	char text[MAX_FN_LEN];
	uint64 stoptimer , starttimer , riptime;
	
	starttimer = timer_ms_gettime64 (); // timer
	cdrom_reinit();
	snprintf(text ,MAX_FN_LEN,"%s", GUI_TextEntryGetText(self.gname));
	if(GUI_WidgetGetState(self.sd_c)) {
		snprintf(dst_folder, MAX_FN_LEN, "/sd/%s", text);
	}else if(GUI_WidgetGetState(self.hdd_c)) {
		snprintf(dst_folder, MAX_FN_LEN, "/ide/%s", text);
	}else if(GUI_WidgetGetState(self.net_c)) {
		snprintf(dst_folder, MAX_FN_LEN, "/net/%s", text);
	}
//ds_printf("Dst file1 %s\n" ,dst_folder);	
getstatus:	
	if((cdcr = cdrom_get_status(&status, &disc_type)) != ERR_OK) {
		switch (cdcr){
			case ERR_NO_DISC :
				ds_printf("DS_ERROR: Disk not inserted\n");
				return;
			case ERR_DISC_CHG :
				cdrom_reinit();
				goto getstatus;
			case CD_STATUS_BUSY :
				thd_sleep(200);
				goto getstatus;
			case CD_STATUS_SEEKING :
				thd_sleep(200);
				goto getstatus;
			case CD_STATUS_SCANNING :
				thd_sleep(200);
				goto getstatus;
			default:
				ds_printf("DS_ERROR: GD-rom error\n");
				return;
		}
	}
	if (disc_type == CD_CDROM_XA){
	rname:
			snprintf(dst_file,MAX_FN_LEN, "%s.iso", dst_folder);
			if ((fd=fs_open(dst_file , O_RDONLY)) != FILEHND_INVALID) {
				fs_close(fd); strcpy(dst_file,"\0"); 
				strcat(dst_folder , "0"); 
				goto rname ;
			} else disc_type = 1;
	} else if (disc_type == CD_GDROM){
	rname1:
			if ((fd=fs_open (dst_folder , O_DIR)) != FILEHND_INVALID) {
				fs_close(fd); 
				strcat(dst_folder , "0"); 
				goto rname1 ;
			} else {strcpy(dst_file,"\0");
			snprintf(dst_file,MAX_FN_LEN,"%s", dst_folder); 
			disc_type = 2; 
			fs_mkdir(dst_file);
			}
			
			while(cdrom_read_toc(&toc, 1) != CMD_OK) { 
				terr++;
				cdrom_reinit();
				if (terr > 100){
				ds_printf("DS_ERROR: Toc read error for gdlast\n");
				fs_rmdir(dst_folder); 
				return; 
				}
			}
			terr=0;
			self.lastgdtrack = TOC_TRACK(toc.last);
	} else {
			ds_printf("DS_ERROR: This is not game disk\nInserted %d disk\n",disc_type);
			return;
	}
//ds_printf("Dst file %s\n" ,dst_file);
	
	for (session=0; session < disc_type; session++) {
		cdrom_set_sector_size(2048);
		while(cdrom_read_toc(&toc, session) != CMD_OK) {
			terr++; 
			if(terr==5) cdrom_reinit(); 
			thd_sleep(500); 
			if (terr > 10) { 
				ds_printf("DS_ERROR: Toc read error\n");
			if (disc_type == 1) {
				if(fs_unlink(dst_file) != 0) 
				ds_printf("Error delete file: %s\n" ,dst_file);
			}else {
					if ((fd=fs_open (dst_folder , O_DIR)) == FILEHND_INVALID) {
						ds_printf("Error folder '%s' not found\n" ,dst_folder); 
						return;
					}
					dirent_t *dir;
					while ((dir = fs_readdir(fd))){
						if (!strcmp(dir->name,".") || !strcmp(dir->name,"..")) continue;
						strcpy(dst_file,"\0");
						snprintf(dst_file, MAX_FN_LEN, "%s/%s", dst_folder, dir->name);
						fs_unlink(dst_file);
					}
					fs_close(fd);
					fs_rmdir(dst_folder);
				} 
				return; 
			}
		}
		terr = 0;
		int first = TOC_TRACK(toc.first);
		int last = TOC_TRACK(toc.last);
		for (tn=first; tn <= last; tn++ ) {
			if (disc_type == 1) tn = last;
			type = TOC_CTRL(toc.entry[tn-1]);
			if (disc_type == 2) {
				strcpy(dst_file,"\0"); 
				snprintf(dst_file,MAX_FN_LEN,"%s/track%02d.%s", dst_folder, tn, (type == 4 ? "iso" : "raw"));
			}
			
			start = TOC_LBA(toc.entry[tn-1]);
			s_end = TOC_LBA((tn == last ? toc.leadout_sector : toc.entry[tn]));
			nsec = s_end - start;
			
			if (disc_type == 1 && type == 4) nsec -= 2 ;
			else if (session==1 && tn != last && type != TOC_CTRL(toc.entry[tn])) nsec -= 150;
			else if (session==0 && type == 4) nsec -= 150;
			
			if (disc_type == 2 && session == 0) {
				strcpy(riplabel,"\0"); 
				sprintf(riplabel,"Track %d of %d\n",tn ,self.lastgdtrack );
			} else if (disc_type == 2 && session == 1 && tn != self.lastgdtrack) {
				strcpy(riplabel,"\0"); 
				sprintf(riplabel,"Track %d of %d\n",tn ,self.lastgdtrack );
			} else {
				strcpy(riplabel,"\0"); 
				sprintf(riplabel,"Last track\n");
			}
			
			GUI_LabelSetText(self.track_label, riplabel);
			
			if (rip_sec(tn, start, nsec, type, dst_file, disc_type) != CMD_OK) {
				GUI_LabelSetText(self.track_label, " ");
				stoptimer = timer_ms_gettime64 (); // timer
				GUI_ProgressBarSetPosition(self.pbar, 0.0);
				cdrom_spin_down();
				if (disc_type == 1) {
					if(fs_unlink(dst_file) != 0) ds_printf("Error delete file: %s\n" ,dst_file);
				} else {
					if ((fd=fs_open (dst_folder , O_DIR)) == FILEHND_INVALID) {
						ds_printf("Error folder '%s' not found\n" ,dst_folder); 
						return;
					}
					
					dirent_t *dir;
					while ((dir = fs_readdir(fd))){
						if (!strcmp(dir->name,".") || !strcmp(dir->name,"..")) continue;
						strcpy(dst_file,"\0");
						snprintf(dst_file, MAX_FN_LEN, "%s/%s", dst_folder, dir->name);
						fs_unlink(dst_file);
					}
					fs_close(fd);
					fs_rmdir(dst_folder);
				}
				return ;
			}
			GUI_LabelSetText(self.track_label, " ");
			GUI_ProgressBarSetPosition(self.pbar, 0.0);
		}
	}
	GUI_LabelSetText(self.track_label, " ");
	GUI_WidgetMarkChanged(self.app->body);
	if (disc_type == 2){
		if (gdfiles(dst_folder, dst_file, text) != CMD_OK){
			cdrom_spin_down();
			if ((fd=fs_open (dst_folder , O_DIR)) == FILEHND_INVALID) {
				ds_printf("Error folder '%s' not found\n" ,dst_folder); 
				return;
			}
			
			dirent_t *dir;
			
			while ((dir = fs_readdir(fd))){
				if (!strcmp(dir->name,".") || !strcmp(dir->name,"..")) continue;
				strcpy(dst_file,"\0");
				snprintf(dst_file, MAX_FN_LEN, "%s/%s", dst_folder, dir->name);
				fs_unlink(dst_file);
			}
			fs_close(fd);
			fs_rmdir(dst_folder);
			return;	
		}
		
		
	}
	GUI_ProgressBarSetPosition(self.pbar, 0.0);
	cdrom_spin_down();
	stoptimer = timer_ms_gettime64 (); // timer
	riptime = stoptimer - starttimer;
	int ripmin = riptime / 60000 ;
	int ripsec = riptime % 60 ;
	ds_printf("DS_OK: End ripping. Save at %d:%d\n",ripmin,ripsec);
}
예제 #27
0
파일: fs_main.c 프로젝트: alkap007/ali3606
void sd_fs_unmount(UINT32 param)
{
	int i;
	char mount_name[16];	
	int result;
	struct statvfs sfs;
	int fd;
	struct stat st;
	char dirbuf[sizeof(struct dirent) + 32];	
	struct dirent *dire = (struct dirent *)dirbuf;
#ifdef USB_SUPPORT_HUB
	UINT32 msg_code = 0;
	struct fs_sto_param fs_param;
	fs_param.type = MNT_TYPE_SD;
	fs_param.id = 0;
	fs_param.partition_id = 0;
#endif	
	

#if (SYS_CHIP_MODULE != ALI_S3602)
	unlink_device("/c", MNT_TYPE_SD);
	unlink_device("/r", MNT_TYPE_SD);
#endif

	fd = fs_opendir("/mnt");

	while(fs_readdir(fd, dire) > 0)
	{
		fs_get_mount_name(MNT_TYPE_SD, 0, 0, mount_name);
		if(!MEMCMP(&dire->d_name, &mount_name[5], 3))
		{
			STRCPY(mount_name, "/mnt/");
			strcat(mount_name, dire->d_name);

			FS_PRINTF("unmount: %s ...", mount_name);
			result = fs_statvfs(mount_name, &sfs);
			if(result < 0)
			{
				FS_PRINTF("the %s is not mounted!\n", mount_name);
#if (SYS_CHIP_MODULE == ALI_S3602)
				FS_NOTICE_MESSAGE(MP_FS_UNMOUNT, MNT_MSG_PARAM(UNMNT_FAILED, MNT_TYPE_SD, 0));
//				SD_MESSAGE(MP_FS_UNMOUNT, UNMNT_FAILED);
#else
#ifdef USB_SUPPORT_HUB
				fs_param.msg_code = UNMNT_FAILED;
				msg_code = fs_param.type<<24 | fs_param.id<<16 | fs_param.partition_id<<8 | fs_param.msg_code;
#else
				msg_code = 1;
#endif		
				FS_NOTICE_MESSAGE(MP_FS_UNMOUNT, msg_code);
#endif				
				continue;
			}

			result = fs_unmount(mount_name, 1);
			if(result < 0)
			{
				FS_PRINTF("the %s is unmounted failed!\n", mount_name);
#if (SYS_CHIP_MODULE == ALI_S3602)
				FS_NOTICE_MESSAGE(MP_FS_UNMOUNT, MNT_MSG_PARAM(UNMNT_FAILED, MNT_TYPE_SD, 0));
//				SD_MESSAGE(MP_FS_UNMOUNT, UNMNT_FAILED);
#else
#ifdef USB_SUPPORT_HUB
				fs_param.msg_code = UNMNT_FAILED;
				msg_code = fs_param.type<<24 | fs_param.id<<16 | fs_param.partition_id<<8 | fs_param.msg_code;
#else
				msg_code = 1;
#endif		
				FS_NOTICE_MESSAGE(MP_FS_UNMOUNT, msg_code);
#endif				
				FS_PRINTF("failed! err = %d\n", result);
			}
			else
			{
				FS_PRINTF("successed!\n");
			}

	        result = fs_rmdir(mount_name);
			if (result < 0)
			{
	            FS_PRINTF("remove dir %s failed! err = %d\n", mount_name, result);
			}
		}
	}


#if (SYS_CHIP_MODULE != ALI_S3602)
#ifdef USB_SUPPORT_HUB
	fs_param.msg_code = UNMNT_PLUGOUT;
	msg_code = fs_param.type<<24 | fs_param.id<<16 | fs_param.partition_id<<8 | fs_param.msg_code;
#else
	msg_code = 0;
#endif		
	FS_NOTICE_MESSAGE(MP_FS_UNMOUNT, msg_code);
#ifdef USB_SUPPORT_HUB
	fs_param.msg_code = 102;
	msg_code = fs_param.type<<24 | fs_param.id<<16 | fs_param.partition_id<<8 | fs_param.msg_code;
#else
	msg_code = 102;
#endif		
	FS_NOTICE_MESSAGE(MP_FS_UNMOUNT, msg_code);	
#endif
	
	fs_closedir(fd);
	sdio_hdd_cleanup(0);
#if (SYS_CHIP_MODULE == ALI_S3602)
	FS_NOTICE_MESSAGE(MP_FS_UNMOUNT, MNT_MSG_PARAM(UNMNT_UNMOUNT_OK, MNT_TYPE_SD, 0));
//	SD_MESSAGE(MP_FS_UNMOUNT, UNMNT_UNMOUNT_OK);
#endif
}
예제 #28
0
static int dm_update(UINT32 dev_type, UINT32 dev_id)
{
	char disk_name[8];
	char dev_path[16];
	char vol_path[16];
	DiskInfo *p_disk = NULL;
	DiskInfo **pp_disk = NULL;
	int ret = -1;
	
	if (((dev_type == MNT_TYPE_USB) && (dev_id >= MAX_USB_DISK_NUM)) ||
		((dev_type == MNT_TYPE_SD)  && (dev_id >= MAX_SD_DISK_NUM))  ||
		((dev_type == MNT_TYPE_SATA)  && (dev_id >= MAX_SATA_DISK_NUM))  ||
		((dev_type == MNT_TYPE_IDE) && (dev_id >= MAX_IDE_DISK_NUM)))
	{
		DM_ERROR("Unsupport device (%d, %d)\n", dev_type, dev_id);
		return ret;
	}

	DM_DEBUG("DM update device (%d, %d)\n", dev_type, dev_id);
	DMLock();

	do {
		switch (dev_type)
		{
			case MNT_TYPE_USB:
				sprintf(disk_name, "ud%c", dev_id+'a');
				pp_disk = &g_dm.UsbDisks[dev_id];
				break;
			case MNT_TYPE_SD:
				sprintf(disk_name, "sd%c", dev_id+'a');
				pp_disk = &g_dm.SdDisks[dev_id];
				break;
			case MNT_TYPE_IDE:
				sprintf(disk_name, "hd%c", dev_id+'a');
				pp_disk = &g_dm.IdeDisks[dev_id];
				break;
			case MNT_TYPE_SATA:
				sprintf(disk_name, "sh%c", dev_id+'a');
				pp_disk = &g_dm.SataDisks[dev_id];
				break;
			default:
				disk_name[0] = 0;
				break;
		}

		if (disk_name[0] == 0)
		{
			DM_DEBUG("Unknown device (%d, %d)\n", dev_type, dev_id);
			break;
		}

		if (*pp_disk != NULL)
		{
#if (DM_DEBUG_LEVEL & DM_DEBUG_MALLOC_FREE)
			dm_malloc_cnt--;
#endif
			FREE(*pp_disk);
			*pp_disk = NULL;
		}
		
		if ((p_disk = (DiskInfo *)MALLOC(sizeof(DiskInfo))) ==  NULL)
		{
#if (DM_DEBUG_LEVEL & DM_DEBUG_MALLOC_FREE)
			dm_malloc_cnt++;
#endif
			DM_DEBUG("Memory exhausted!\n", dev_type, dev_id);
			break;
		}

		MEMSET(p_disk, 0, sizeof(DiskInfo));
		sprintf(dev_path, "/dev/%s", disk_name);

		int fd, fd_dir;
		device_geometry geo;
		char dirbuf[sizeof(struct dirent) + 32];
		struct dirent *pdir = (struct dirent *)dirbuf;

		/* get disk info */
		fd = fs_open(dev_path, O_RDONLY, 0);
		if (fd < 0)
		{
			DM_DEBUG("device %s not exist!\n", dev_path);
			break;
		}
		
		if (fs_ioctl(fd, IOCTL_GET_DEVICE_GEOMETRY, &geo, sizeof(struct device_geometry)) < 0)
		{
			fs_close(fd);
			break;	
		}
		p_disk->DiskSize = geo.sector_count * geo.bytes_per_sector;
		fs_close(fd);
		
	    if ((fd_dir = fs_opendir("/dev")) < 0)
	    {
			DM_DEBUG("open /dev failed!\n");
			break;
	    }
		
		ret = 0; /* get necessary disk info successfully */

		int part_idx;
		while (fs_readdir(fd_dir, pdir) > 0)
		{
			/* find partitions */
	        if ((STRLEN(pdir->d_name) == 4) && (strncmp(pdir->d_name, disk_name, 3) == 0))
				
			{
				part_idx = pdir->d_name[3] - '1';
				if ((part_idx < 0) || (part_idx >= MAX_PARTS_IN_DISK))
				{
					continue;
				}
				sprintf(dev_path, "/dev/%s", pdir->d_name);
				sprintf(vol_path, "/mnt/%s", pdir->d_name);

				/* get part info */
				fd = fs_open(dev_path, O_RDONLY, 0);
				if (fs_ioctl(fd, IOCTL_GET_DEVICE_GEOMETRY, &geo, sizeof(struct device_geometry)) < 0)
				{
					fs_close(fd);
					continue;	
				}
				fs_close(fd);
				
				p_disk->parts[part_idx].PartExist = 1;
	 			p_disk->parts[part_idx].FileSystemType = dm_get_fs_type(vol_path);
				p_disk->parts[part_idx].PartSize = geo.sector_count * geo.bytes_per_sector;
				p_disk->part_num++;
				if (p_disk->parts[part_idx].FileSystemType != PED_FS_TYPE_NONE)
					p_disk->vol_num++;
			}
		}
		fs_closedir(fd_dir);
	} while(0);

	if (ret == 0)
	{
		*pp_disk = p_disk;
//		p_disk = NULL;
	}
	else if (p_disk != NULL)
	{
#if (DM_DEBUG_LEVEL & DM_DEBUG_MALLOC_FREE)
		dm_malloc_cnt--;
#endif
		FREE(p_disk);
	}

	DMUnlock();
	
	return ret;
}
예제 #29
0
/*
 * backup_work
 *
 * Start the NDMP backup (V2 only).
 */
int
backup_work(char *bk_path, tlm_job_stats_t *job_stats,
    ndmp_run_args_t *np, tlm_commands_t *commands,
    ndmp_lbr_params_t *nlp)
{
	struct full_dir_info dir_info; /* the blob to push/pop with cstack_t */
	struct full_dir_info *t_dir_info, *p_dir_info;
	struct stat64 ret_attr; /* attributes of current file name */
	fs_fhandle_t ret_fh;
	char *first_name; /* where the first name is located */
	char *dname;
	int erc;
	int retval;
	cstack_t *stk;
	unsigned long fileid;
	tlm_acls_t tlm_acls;
	int dname_size;
	longlong_t fsize;
	bk_selector_t bks;
	tlm_cmd_t *local_commands;
	long 	dpos;

	NDMP_LOG(LOG_DEBUG, "nr_chkpnted %d nr_ldate: %u bk_path: \"%s\"",
	    NLP_ISCHKPNTED(nlp), nlp->nlp_ldate, bk_path);

	/* Get every name in this directory */
	dname = ndmp_malloc(TLM_MAX_PATH_NAME);
	if (dname == NULL)
		return (-ENOMEM);

	local_commands = commands->tcs_command;
	retval = 0;
	(void) memset(&bks, 0, sizeof (bks));
	bks.bs_cookie = (void *)nlp;
	bks.bs_level = nlp->nlp_clevel;
	bks.bs_ldate = nlp->nlp_ldate;
	bks.bs_fn = timecmp;

	/*
	 * should we skip the whole thing?
	 */
	if (tlm_is_excluded("", bk_path, np->nr_excls)) {
		NDMP_LOG(LOG_DEBUG, "%s excluded", bk_path);
		free(dname);
		return (0);
	}

	/*
	 * Search for the top-level file-directory
	 */
	if (NLP_ISCHKPNTED(nlp)) {
		first_name = np->nr_chkp_nm;
		(void) strlcpy(first_name, bk_path, TLM_MAX_PATH_NAME);
	} else {
		first_name = tlm_build_snapshot_name(bk_path, np->nr_chkp_nm,
		    nlp->nlp_jstat->js_job_name);
	}

	(void) memset(&ret_fh, 0, sizeof (ret_fh));
	erc = fs_getstat(first_name, &ret_fh, &ret_attr);
	if (erc != 0) {
		NDMP_LOG(LOG_ERR, "Path %s not found.", first_name);
		free(dname);
		return (-EINVAL);
	}

	if ((stk = cstack_new()) == NULL) {
		free(dname);
		NDMP_LOG(LOG_DEBUG, "cstack_new failed");
		return (-ENOMEM);
	}
	(void) strlcpy(dir_info.fd_dir_name, first_name, TLM_MAX_PATH_NAME);
	(void) memcpy(&dir_info.fd_dir_fh, &ret_fh, sizeof (fs_fhandle_t));
	p_dir_info = dup_dir_info(&dir_info);

	/*
	 * Push the first name onto the stack so that we can pop it back
	 * off as part of the normal cycle
	 */
	if (cstack_push(stk, p_dir_info, 0)) {
		free(dname);
		free(p_dir_info);
		cstack_delete(stk);
		NDMP_LOG(LOG_DEBUG, "cstack_push failed");
		return (-ENOMEM);
	}

	(void) memset(&tlm_acls, 0, sizeof (tlm_acls));
	/*
	 * Did NDMP create a checkpoint?
	 */
	if (NLP_ISCHKPNTED(nlp) || fs_is_rdonly(bk_path)) {
		tlm_acls.acl_checkpointed = FALSE;
	} else {
		/* Use the checkpoint created by NDMP */
		tlm_acls.acl_checkpointed = TRUE;
	}

	/*
	 * This is level-backup.  It never resets the archive bit.
	 */
	tlm_acls.acl_clear_archive = FALSE;

	NDMP_LOG(LOG_DEBUG, "acls.chkpnt: %c acls.clear_arcbit: %c",
	    NDMP_YORN(tlm_acls.acl_checkpointed),
	    NDMP_YORN(tlm_acls.acl_clear_archive));

	while (commands->tcs_reader == TLM_BACKUP_RUN &&
	    local_commands->tc_reader == TLM_BACKUP_RUN &&
	    cstack_pop(stk, (void **)&p_dir_info, 0) == 0) {

		if (NLP_ISCHKPNTED(nlp))
			(void) strlcpy(np->nr_unchkp_nm,
			    p_dir_info->fd_dir_name, TLM_MAX_PATH_NAME);
		else
			(void) tlm_remove_checkpoint(p_dir_info->fd_dir_name,
			    np->nr_unchkp_nm);

		(void) backup_dir(np->nr_unchkp_nm, &tlm_acls, local_commands,
		    job_stats, &bks);


		while (commands->tcs_reader == TLM_BACKUP_RUN &&
		    local_commands->tc_reader == TLM_BACKUP_RUN) {

			dname_size = TLM_MAX_PATH_NAME - 1;

			NDMP_LOG(LOG_DEBUG,
			    "dir_name: %s", p_dir_info->fd_dir_name);

			(void) memset(&ret_fh, 0, sizeof (ret_fh));
			erc = fs_readdir(&p_dir_info->fd_dir_fh,
			    p_dir_info->fd_dir_name, &dpos,
			    dname, &dname_size, &ret_fh, &ret_attr);
			if (erc == 0) {
				fileid = ret_fh.fh_fid;
			} else {
				NDMP_LOG(LOG_DEBUG,
				    "Filesystem readdir in [%s]",
				    p_dir_info->fd_dir_name);
				retval = -ENOENT;
				break;
			}

			/* an empty name size marks the end of the list */
			if (dname_size == 0)
				break;
			dname[dname_size] = '\0';

			NDMP_LOG(LOG_DEBUG, "dname: \"%s\"", dname);

			/*
			 * If name refers to a directory, push its file
			 *   handle onto the stack  (skip "." and "..").
			 */
			if (rootfs_dot_or_dotdot(dname)) {
				fileid = 0;
				continue;
			}

			/*
			 * Skip the:
			 * non-dir entries which should not be backed up
			 * Or
			 * dir-type entries which have have nothing under
			 * their hierarchy to be backed up.
			 */
			if (!dbm_getone(nlp->nlp_bkmap, (u_longlong_t)fileid)) {
				NDMP_LOG(LOG_DEBUG, "Skipping %s/%s",
				    p_dir_info->fd_dir_name, dname);
				fileid = 0;
				continue;
			}

			if (tlm_is_excluded(np->nr_unchkp_nm, dname,
			    np->nr_excls)) {
				fileid = 0;
				continue;
			}
			if (S_ISDIR(ret_attr.st_mode)) {
				/*
				 * only directories get pushed onto this stack,
				 * so we do not have to test for regular files.
				 */
				t_dir_info = tlm_new_dir_info(&ret_fh,
				    p_dir_info->fd_dir_name, dname);
				if (t_dir_info == NULL) {
					NDMP_LOG(LOG_DEBUG,
					    "While backing up [%s][%s]",
					    p_dir_info->fd_dir_name, dname);
				} else if (cstack_push(stk, t_dir_info,
				    0) != 0) {
					NDMP_LOG(LOG_DEBUG,
					    "No enough memory stack_push");
					retval = -ENOMEM;
					break;
				}
			} else if (S_ISREG(ret_attr.st_mode) ||
			    S_ISLNK(ret_attr.st_mode)) {

				fsize = backup_file(np->nr_unchkp_nm, dname,
				    &tlm_acls, commands, local_commands,
				    job_stats, &bks);

				if (fsize >= 0) {
					job_stats->js_files_so_far++;
					job_stats->js_bytes_total += fsize;
				} else
					job_stats->js_errors++;
				fileid = 0;
			}
		}
		fileid = 0;
		free(p_dir_info);
		if (retval != 0)
			break;
	}

	free(dname);

	while (cstack_pop(stk, (void **)&p_dir_info, 0) == 0) {
		free(p_dir_info);
	}

	cstack_delete(stk);
	return (retval);
}
예제 #30
0
파일: fs_main.c 프로젝트: alkap007/ali3606
void sd_fs_mount(UINT32 param)
{
	
	int result = -EIO; 
	int hdd_ns = 0;
	int vol_ns = 0;

	int i = 0;
	int j = 0;

	char dirbuf[sizeof(struct dirent) + 32];	
	struct dirent *dire = (struct dirent *)dirbuf;
	char dev_name[16], vol_name[16];
	int fd;
	struct stat st;
	
#ifdef USB_SUPPORT_HUB
	UINT32 msg_code = 0;
	struct fs_sto_param fs_param;
	fs_param.type = MNT_TYPE_SD;
	fs_param.id = 0;
	fs_param.partition_id = 0;
#endif	

#if (SYS_CHIP_MODULE == ALI_S3602)
	FS_NOTICE_MESSAGE(MP_FS_MOUNT, MNT_MSG_PARAM(MNT_MOUNT, MNT_TYPE_SD, 0));
//	SD_MESSAGE(MP_FS_MOUNT, MNT_MOUNT);
#endif

	//firstly create all the device and partitions    
	//INT32 lun_num = sdio_hdd_get_partition_number(0);
	result = sdio_hdd_init(0);
	if(result == 0)
		hdd_ns++;
	else
		FS_PRINTF("device lun = %d init failed! err = %d\n", i, result);


	if(hdd_ns == 0)
	{
		FS_PRINTF("all the device are inited failed!\n");
#if (SYS_CHIP_MODULE == ALI_S3602)
		FS_NOTICE_MESSAGE(MP_FS_MOUNT, MNT_MSG_PARAM(MNT_FAILED, MNT_TYPE_SD, 0));
//		SD_MESSAGE(MP_FS_MOUNT, MNT_FAILED);
#else
#ifdef USB_SUPPORT_HUB
		fs_param.msg_code = MNT_NO_PARTITION;
		msg_code = fs_param.type<<24 | fs_param.id<<16 | fs_param.partition_id<<8 | fs_param.msg_code;
#else
		msg_code = 11;
#endif		
		FS_NOTICE_MESSAGE(MP_FS_MOUNT, msg_code);
#endif		
		return;		
	}
	
	//loop the /dev try to mount all the device
	fd = fs_opendir("/dev");
	while(fs_readdir(fd, dire) > 0)
	{
		fs_get_mount_name(MNT_TYPE_SD, 0, 0, dev_name);
		if((STRLEN(dire->d_name) == 4) && !MEMCMP(&dire->d_name, &dev_name[5], 3)) 
		{
			STRCPY(dev_name, "/dev/");
			strcat(dev_name, dire->d_name);
			
			STRCPY(vol_name, "/mnt/");
			strcat(vol_name, dire->d_name);
			
			
			//mount the device
			result = mount_device(dev_name, vol_name);
			if(result >= 0)
			{
				link_device(vol_name, "/c");
#if (SYS_CHIP_MODULE != ALI_S3602)
				link_device(vol_name, "/r");
#endif
				vol_ns++; 
			}
		}
	}

	fs_closedir(fd);

	if(vol_ns == 0)
	{
		FS_PRINTF("fs mount failed!\n");
#if (SYS_CHIP_MODULE == ALI_S3602)
		FS_NOTICE_MESSAGE(MP_FS_MOUNT, MNT_MSG_PARAM(MNT_FAILED, MNT_TYPE_SD, 0));
//		SD_MESSAGE(MP_FS_MOUNT, MNT_FAILED);
#else
#ifdef USB_SUPPORT_HUB
		fs_param.msg_code = MNT_FAILED;
		msg_code = fs_param.type<<24 | fs_param.id<<16 | fs_param.partition_id<<8 | fs_param.msg_code;
#else
		msg_code = 1;
#endif		
		FS_NOTICE_MESSAGE(MP_FS_MOUNT, msg_code);
#endif		
		return;
	}

#if (SYS_CHIP_MODULE == ALI_S3602)
	FS_NOTICE_MESSAGE(MP_FS_MOUNT, MNT_MSG_PARAM(MNT_MOUNT_OK, MNT_TYPE_SD, 0));
//	SD_MESSAGE(MP_FS_MOUNT, MNT_MOUNT_OK);
#else
#ifdef USB_SUPPORT_HUB
	fs_param.msg_code = MNT_MOUNT_OK;
	msg_code = fs_param.type<<24 | fs_param.id<<16 | fs_param.partition_id<<8 | fs_param.msg_code;
#else
	msg_code = 3;
#endif		
	FS_NOTICE_MESSAGE(MP_FS_MOUNT, msg_code);
#endif
	
	return;
}