/* * Lookup the data. This is trivial - if the dentry didn't already * exist, we know it is negative. */ static struct dentry * ptpfs_root_lookup(struct inode *dir, struct dentry *dentry) { // printk(KERN_INFO "%s\n", __FUNCTION__); struct ptp_storage_ids storageids; int x; char fsname[256]; int typeCount[5]; memset(&storageids,0,sizeof(storageids)); //add by evan memset(typeCount,0,sizeof(typeCount)); if (ptp_getstorageids(PTPFSSB(dir->i_sb), &storageids)!=PTP_RC_OK) { printk(KERN_INFO "Error getting storage ids\n"); storageids.n = 0; storageids.storage = NULL; } int offset = 0; for (x = 0; x < storageids.n; x++) { struct ptp_storage_info storageinfo; if ((storageids.storage[x]&0x0000ffff)==0) continue; memset(&storageinfo,0,sizeof(storageinfo)); if (ptp_getstorageinfo(PTPFSSB(dir->i_sb), storageids.storage[x],&storageinfo)!=PTP_RC_OK) { printk(KERN_INFO "Error getting storage info\n"); } else { get_root_dir_name(&storageinfo,fsname,typeCount); offset++; if (!memcmp(fsname,dentry->d_name.name,dentry->d_name.len)) { struct inode *newi = ptpfs_get_inode(dir->i_sb, S_IFDIR | S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH , 0,storageids.storage[x]); PTPFSINO(newi)->parent = dir; //dir should be root directory //newi->i_fop = &ptpfs_stgdir_operations; //newi->i_op = &ptpfs_stgdir_inode_operations; PTPFSINO(newi)->type = INO_TYPE_STGDIR; PTPFSINO(newi)->storage = storageids.storage[x]; if (newi) d_add(dentry, newi); ptp_free_storage_ids(&storageids); ptp_free_storage_info(&storageinfo); return NULL; } ptp_free_storage_info(&storageinfo); } } ptp_free_storage_ids(&storageids); return NULL; }
static struct dentry * ptpfs_lookup(struct inode *dir, struct dentry *dentry) { int x; //printk(KERN_INFO "%s\n", __FUNCTION__); struct ptpfs_inode_data* ptpfs_data = PTPFSINO(dir); if (!ptpfs_get_dir_data(dir)) { d_add(dentry, NULL); return NULL; } if (ptpfs_data->type != INO_TYPE_DIR && ptpfs_data->type != INO_TYPE_STGDIR) { d_add(dentry, NULL); return NULL; } for (x = 0; x < ptpfs_data->data.dircache.num_files; x++) { if (!memcmp(ptpfs_data->data.dircache.file_info[x].filename,dentry->d_name.name,dentry->d_name.len)) { struct ptp_object_info object; if (ptp_getobjectinfo(PTPFSSB(dir->i_sb),ptpfs_data->data.dircache.file_info[x].handle,&object)!=PTP_RC_OK) { d_add(dentry, NULL); return NULL; } int mode = S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH; if (object.object_format==PTP_OFC_Association && object.association_type == PTP_AT_GenericFolder) { mode |= S_IFDIR; } else { mode |= S_IFREG; } struct inode *newi = ptpfs_get_inode(dir->i_sb, mode , 0,ptpfs_data->data.dircache.file_info[x].handle); PTPFSINO(newi)->parent = dir; ptpfs_set_inode_info(newi,&object); //atomic_inc(&newi->i_count); /* New dentry reference */ d_add(dentry, newi); ptp_free_object_info(&object); return NULL; } } d_add(dentry, NULL); return NULL; }
static int ptpfs_create(struct inode *dir,struct dentry *d,int i) { //printk(KERN_INFO "%s %s %d\n",__FUNCTION__,d->d_name.name,i); __u32 storage; __u32 parent; __u32 handle; struct ptp_object_info objectinfo; memset(&objectinfo,0,sizeof(objectinfo)); storage = PTPFSINO(dir)->storage; if (PTPFSINO(dir)->type == INO_TYPE_STGDIR) { parent = 0xffffffff; } else { parent = dir->i_ino; } objectinfo.filename = (unsigned char *)d->d_name.name; objectinfo.object_format=get_format((unsigned char *)d->d_name.name,d->d_name.len); objectinfo.object_compressed_size=0; int ret = ptp_sendobjectinfo(PTPFSSB(dir->i_sb), &storage, &parent, &handle, &objectinfo); if (ret == PTP_RC_OK) { struct ptp_data_buffer data; struct ptp_block block; unsigned char buf[10]; memset(&data,0,sizeof(data)); memset(&block,0,sizeof(block)); data.blocks=█ data.num_blocks = 1; block.block_size = 0; block.block = buf; ret = ptp_sendobject(PTPFSSB(dir->i_sb),&data,0); if (handle == 0) { //problem - it didn't return the right handle - need to do something find it struct ptp_object_handles objects; objects.n = 0; objects.handles = NULL; ptpfs_get_dir_data(dir); if (PTPFSINO(dir)->type == INO_TYPE_DIR) { ptp_getobjecthandles(PTPFSSB(dir->i_sb), PTPFSINO(dir)->storage, 0x000000, dir->i_ino,&objects); } else { ptp_getobjecthandles(PTPFSSB(dir->i_sb), dir->i_ino, 0x000000, 0xffffffff ,&objects); } int x,y; for (x = 0; x < objects.n && !handle; x++ ) { for (y = 0; y < PTPFSINO(dir)->data.dircache.num_files; y++) { if (PTPFSINO(dir)->data.dircache.file_info[y].handle == objects.handles[x]) { objects.handles[x] = 0; y = PTPFSINO(dir)->data.dircache.num_files; } } if (objects.handles[x]) { handle = objects.handles[x]; } } ptp_free_object_handles(&objects); } int mode = S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH | S_IFREG; struct inode *newi = ptpfs_get_inode(dir->i_sb, mode , 0,handle); PTPFSINO(newi)->parent = dir; ptpfs_set_inode_info(newi,&objectinfo); atomic_inc(&newi->i_count); /* New dentry reference */ d_instantiate(d, newi); objectinfo.filename = NULL; ptp_free_object_info(&objectinfo); ptpfs_free_inode_data(dir);//uncache dir->i_version++; newi->i_mtime = CURRENT_TIME; return 0; } objectinfo.filename = NULL; ptp_free_object_info(&objectinfo); return -EPERM; }