//--------------------------------------------------------------------------- int fs_ioctl(iop_file_t *fd, u32 request, void *data) { fat_driver* fatd; struct fs_dirent* dirent = (struct fs_dirent *) fd->privdata; //Remember to re-cast this to the right structure (either fs_rec or fs_dir)! int ret; if (dirent == NULL) return -EBADF; _fs_lock(); fatd = fat_getData(fd->unit); if (fatd == NULL) { _fs_unlock(); return -ENODEV; } switch (request) { case USBMASS_IOCTL_RENAME: ret = fat_renameFile(fatd, &dirent->fatdir, data); //No need to re-cast since this inner structure is a common one. FLUSH_SECTORS(fatd); break; default: ret = fs_dummy(); } _fs_unlock(); return ret; }
//--------------------------------------------------------------------------- static int fs_close(iop_file_t* fd) { fat_driver* fatd; fs_rec* rec = (fs_rec*)fd->privdata; if (rec == NULL) return -EBADF; _fs_lock(); if (rec->dirent.file_flag != FS_FILE_FLAG_FILE) { _fs_unlock(); return -EISDIR; } rec->dirent.file_flag = -1; fd->privdata = NULL; fatd = fat_getData(fd->unit); if (fatd == NULL) { _fs_unlock(); return -ENODEV; } if ((rec->mode & O_WRONLY)) { //update direntry size and time if (rec->sizeChange) { fat_updateSfn(fatd, rec->dirent.fatdir.size, rec->sfnSector, rec->sfnOffset); } FLUSH_SECTORS(fatd); } _fs_unlock(); return 0; }
//--------------------------------------------------------------------------- int fs_ioctl(iop_file_t *fd, int cmd, void *data) { fat_driver* fatd; struct fs_dirent* dirent = (struct fs_dirent *) fd->privdata; //Remember to re-cast this to the right structure (either fs_rec or fs_dir)! int ret; if (dirent == NULL) return -EBADF; _fs_lock(); fatd = fat_getData(fd->unit); if (fatd == NULL) { _fs_unlock(); return -ENODEV; } switch (cmd) { case USBMASS_IOCTL_RENAME: ret = fat_renameFile(fatd, &dirent->fatdir, data); //No need to re-cast since this inner structure is a common one. FLUSH_SECTORS(fatd); break; case USBMASS_IOCTL_GET_CLUSTER: ret = ((fs_rec *)fd->privdata)->dirent.fatdir.startCluster; break; case USBMASS_IOCTL_GET_LBA: ret = fat_cluster2sector(&fatd->partBpb, ((fs_rec *)fd->privdata)->dirent.fatdir.startCluster); break; default: ret = fs_dummy(); } _fs_unlock(); return ret; }
//--------------------------------------------------------------------------- static int fs_rmdir(iop_file_t *fd, const char *name) { fat_driver* fatd; int ret; _fs_lock(); fatd = fat_getData(fd->unit); if (fatd == NULL) { _fs_unlock(); return -ENODEV; } ret = fat_deleteFile(fatd, name, 1); FLUSH_SECTORS(fatd); _fs_unlock(); return ret; }
//--------------------------------------------------------------------------- static int fs_remove(iop_file_t *fd, const char *name) { fat_driver* fatd; fs_rec* rec; int result; unsigned int cluster; fat_dir fatdir; _fs_lock(); fatd = fat_getData(fd->unit); if (fatd == NULL) { result = -ENODEV; _fs_unlock(); return result; } cluster = 0; //allways start from root XPRINTF("USBHDFSD: Calling fat_getFileStartCluster from fs_remove\n"); result = fat_getFileStartCluster(fatd, name, &cluster, &fatdir); if (result < 0) { _fs_unlock(); return result; } rec = fs_findFileSlotByCluster(fatdir.startCluster); //file is opened - can't delete the file if (rec != NULL) { result = -EINVAL; _fs_unlock(); return result; } result = fat_deleteFile(fatd, name, 0); FLUSH_SECTORS(fatd); _fs_unlock(); return result; }
//--------------------------------------------------------------------------- static int fs_mkdir(iop_file_t *fd, const char *name) { fat_driver* fatd; int ret; int sfnOffset; unsigned int sfnSector; unsigned int cluster; _fs_lock(); fatd = fat_getData(fd->unit); if (fatd == NULL) { _fs_unlock(); return -ENODEV; } XPRINTF("USBHDFSD: fs_mkdir: name=%s \n",name); ret = fat_createFile(fatd, name, 1, 0, &cluster, &sfnSector, &sfnOffset); //directory of the same name already exist if (ret == 2) { ret = -EEXIST; } FLUSH_SECTORS(fatd); _fs_unlock(); return ret; }