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; }
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); }
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); }
int sys_IsUsbFormat() { DIR_POSIX *d; d = fs_opendir(FS_USBMSC_PATH); if (d == NULL) return 0; fs_closedir(d); return 1; }
/** * is_dir() - check if file handle points to directory * * We assume that set_blk_dev(fh) has been called already. * * @fh: file handle * Return: true if file handle points to a directory */ static int is_dir(struct file_handle *fh) { struct fs_dir_stream *dirs; dirs = fs_opendir(fh->path); if (!dirs) return 0; fs_closedir(dirs); return 1; }
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; }
static efi_status_t EFIAPI efi_file_setpos(struct efi_file_handle *file, efi_uintn_t pos) { struct file_handle *fh = to_fh(file); efi_status_t ret = EFI_SUCCESS; EFI_ENTRY("%p, %zu", file, pos); if (fh->isdir) { if (pos != 0) { ret = EFI_UNSUPPORTED; goto error; } fs_closedir(fh->dirs); fh->dirs = NULL; } if (pos == ~0ULL) { loff_t file_size; if (set_blk_dev(fh)) { ret = EFI_DEVICE_ERROR; goto error; } if (fs_size(fh->path, &file_size)) { ret = EFI_DEVICE_ERROR; goto error; } pos = file_size; } fh->offset = pos; error: return EFI_EXIT(ret); }
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; }
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; }
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()); }
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 }
static efi_status_t file_close(struct file_handle *fh) { fs_closedir(fh->dirs); free(fh); return EFI_SUCCESS; }
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; }
int fs_OpenDir(fs_char *fs_path, fs_romfs_char *path, u32 pathlen, fs_dir *dir) { //printf("init open dir\n"); int ret = 0; fs_DIR *dp; fs_entry *entry; //printf("check if path exists\n"); dp = fs_opendir(fs_path); if(!dp) { //wprintf(L"[!] Failed to open directory: \"%s\"\n",path); return -1; } //printf("do some more init\n"); fs_InitDir(path,pathlen,dir); //wprintf(L" rec: \"%s\" (%d)\n",dir->name,dir->name_len); //printf("chdir\n"); fs_chdir(fs_path); //printf("read entries\n"); while((entry = fs_GetEntry(dp))) { if(!entry) { ret = -1; break; } if(entry->IsDir) { //printf("Found Dir "); if(!fs_EntryIsDirNav(entry)) { #ifdef _WIN32 //wprintf(L"is a dir: \"%s\" (%d)\n",entry->fs_name,entry->name_len); #else //printf("is a dir: \"%s\" (%d)\n",entry->fs_name,entry->name_len); #endif ret = fs_AddDir(entry,dir); } else { //printf("Not wanted dir\n"); ret = 0; } } else { #ifdef _WIN32 //wprintf(L"is a file: \"%s\" (%d)\n",entry->fs_name,entry->name_len); #else //printf("is a file: \"%s\" (%d)\n",entry->fs_name,entry->name_len); #endif ret = fs_AddFile(entry,dir); } //printf("free entry\n"); fs_FreeEntry(entry); if(ret) { //printf("error parsing entry\n"); break; } } //printf("close dir ptr\n"); fs_closedir(dp); //printf("return up dir\n"); fs_chdirUp(); //printf("return from fs_OpenDir();\n"); return ret; }
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 }
void user_init(void) { uart_set_baud(0, 921600); printf("\n\nESP8266 UMAC\n\n"); bridge_init(); umac_cfg um_cfg = { .timer_fn = umac_impl_request_future_tick, .cancel_timer_fn = umac_impl_cancel_future_tick, .now_fn = umac_impl_now_tick, .tx_byte_fn = umac_impl_tx_byte, .tx_buf_fn = umac_impl_tx_buf, .rx_pkt_fn = umac_impl_rx_pkt, .rx_pkt_ack_fn = bridge_pkt_acked, .timeout_fn = bridge_timeout, .nonprotocol_data_fn = NULL }; umac_init(&um, &um_cfg, rx_buf); um_tim_hdl = xTimerCreate( (signed char *)"umac_tim", 10, false, (void *)um_tim_id, um_tim_cb); char ap_cred[128]; struct sdk_station_config config; bool setup_ap = true; systask_init(); device_id = 0; fs_init(); if (fs_mount() >= 0) { #if 0 spiffs_DIR d; struct spiffs_dirent e; struct spiffs_dirent *pe = &e; fs_opendir("/", &d); while ((pe = fs_readdir(&d, pe))) { printf("%s [%04x] size:%i\n", pe->name, pe->obj_id, pe->size); } fs_closedir(&d); #endif // read preferred ssid spiffs_file fd_ssid = fs_open(".ssid", SPIFFS_RDONLY, 0); if (fd_ssid > 0) { if (fs_read(fd_ssid, (uint8_t *)ap_cred, sizeof(ap_cred)) > 0) { fs_close(fd_ssid); char *nl_ix = strchr(ap_cred, '\n'); if (nl_ix > 0) { memset(&config, 0, sizeof(struct sdk_station_config)); strncpy((char *)&config.ssid, ap_cred, nl_ix - ap_cred); char *nl_ix2 = strchr(nl_ix + 1, '\n'); if (nl_ix2 > 0) { strncpy((char *)&config.password, nl_ix + 1, nl_ix2 - (nl_ix + 1)); setup_ap = false; } } printf("ssid:%s\n", config.ssid); } // if read else { printf("could not read .ssid\n"); } } // if fs_ssid else { printf("no .ssid found, running softAP\n"); } // find device id or create one spiffs_file fd_devid = fs_open(".devid", SPIFFS_RDONLY, 0); if (fd_devid < 0) { device_id = hwrand(); fd_devid = fs_open(".devid", SPIFFS_O_CREAT | SPIFFS_O_TRUNC | SPIFFS_O_WRONLY | SPIFFS_O_APPEND, 0); fs_write(fd_devid, &device_id, 4); printf("create devid\n"); } else { fs_read(fd_devid, &device_id, 4); } fs_close(fd_devid); printf("devid %08x\n", device_id); // remove previous scan results fs_remove(SYSTASK_AP_SCAN_FILENAME); } // if mount if (setup_ap) { sdk_wifi_set_opmode(SOFTAP_MODE); struct ip_info ap_ip; IP4_ADDR(&ap_ip.ip, 192, 169, 1, 1); IP4_ADDR(&ap_ip.gw, 0, 0, 0, 0); IP4_ADDR(&ap_ip.netmask, 255, 255, 255, 0); sdk_wifi_set_ip_info(1, &ap_ip); struct sdk_softap_config ap_cfg = { .ssid = "WISLEEP", .password = "", .ssid_len = 7, .channel = 1, .authmode = AUTH_OPEN, .ssid_hidden = false, .max_connection = 255, .beacon_interval = 100 }; sdk_wifi_softap_set_config(&ap_cfg); ip_addr_t first_client_ip; IP4_ADDR(&first_client_ip, 192, 169, 1, 100); dhcpserver_start(&first_client_ip, 4); } else { // required to call wifi_set_opmode before station_set_config sdk_wifi_set_opmode(STATION_MODE); sdk_wifi_station_set_config(&config); } server_init(server_actions); um_mutex = xSemaphoreCreateMutex(); xTaskCreate(uart_task, (signed char * )"uart_task", 512, NULL, 2, NULL); xTaskCreate(server_task, (signed char *)"server_task", 1024, NULL, 2, NULL); }
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; }
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; }
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; }