static int _linux_ntfs_mkdir(struct inode *dir, struct dentry* d, int mode) { int error; struct inode *r = 0; ntfs_volume *vol; ntfs_inode *ino; ntfs_attribute *si; ntfs_debug (DEBUG_DIR1, "mkdir %s in %x\n",d->d_name.name, dir->i_ino); error = ENAMETOOLONG; if (d->d_name.len > /* FIXME */255) goto out; error = EIO; r = get_empty_inode(); if (!r) goto out; vol = NTFS_INO2VOL(dir); #ifdef NTFS_IN_LINUX_KERNEL ino = NTFS_LINO2NINO(r); #else ino = ntfs_malloc(sizeof(ntfs_inode)); error = ENOMEM; if(!ino) goto out; r->u.generic_ip = ino; #endif error = ntfs_mkdir(NTFS_LINO2NINO(dir), d->d_name.name, d->d_name.len, ino); if(error) goto out; r->i_uid = vol->uid; r->i_gid = vol->gid; r->i_nlink = 1; r->i_sb = dir->i_sb; si = ntfs_find_attr(ino,vol->at_standard_information,NULL); if(si){ char *attr = si->d.data; r->i_atime = ntfs_ntutc2unixutc(NTFS_GETU64(attr+0x18)); r->i_ctime = ntfs_ntutc2unixutc(NTFS_GETU64(attr)); r->i_mtime = ntfs_ntutc2unixutc(NTFS_GETU64(attr+8)); } /* It's a directory */ r->i_op = &ntfs_dir_inode_operations; r->i_mode = S_IFDIR|S_IRUGO|S_IXUGO; #ifdef CONFIG_NTFS_RW r->i_mode|=S_IWUGO; #endif r->i_mode &= ~vol->umask; insert_inode_hash(r); d_instantiate(d, r); error = 0; out: ntfs_debug (DEBUG_DIR1, "mkdir returns %d\n", -error); return -error; }
static int ntfs_create(struct inode* dir, struct dentry *d, int mode) { struct inode *r = 0; ntfs_inode *ino = 0; ntfs_volume *vol; int error = 0; ntfs_attribute *si; r = new_inode(dir->i_sb); if (!r) { error = -ENOMEM; goto fail; } ntfs_debug(DEBUG_OTHER, "ntfs_create %s\n", d->d_name.name); vol = NTFS_INO2VOL(dir); ino = NTFS_LINO2NINO(r); error = ntfs_alloc_file(NTFS_LINO2NINO(dir), ino, (char*)d->d_name.name, d->d_name.len); if (error) { ntfs_error("ntfs_alloc_file FAILED: error = %i", error); goto fail; } /* Not doing this one was causing a huge amount of corruption! Now the * bugger bytes the dust! (-8 (AIA) */ r->i_ino = ino->i_number; error = ntfs_update_inode(ino); if (error) goto fail; error = ntfs_update_inode(NTFS_LINO2NINO(dir)); if (error) goto fail; r->i_uid = vol->uid; r->i_gid = vol->gid; /* FIXME: dirty? dev? */ /* Get the file modification times from the standard information. */ si = ntfs_find_attr(ino, vol->at_standard_information, NULL); if (si) { char *attr = si->d.data; r->i_atime = ntfs_ntutc2unixutc(NTFS_GETU64(attr + 0x18)); r->i_ctime = ntfs_ntutc2unixutc(NTFS_GETU64(attr)); r->i_mtime = ntfs_ntutc2unixutc(NTFS_GETU64(attr + 8)); } /* It's not a directory */ r->i_op = &ntfs_inode_operations; r->i_fop = &ntfs_file_operations; r->i_mode = S_IFREG | S_IRUGO; #ifdef CONFIG_NTFS_RW r->i_mode |= S_IWUGO; #endif r->i_mode &= ~vol->umask; insert_inode_hash(r); d_instantiate(d, r); return 0; fail: if (r) iput(r); return error; }
static int _linux_ntfs_mkdir(struct inode *dir, struct dentry* d, int mode) { int error; struct inode *r = 0; ntfs_volume *vol; ntfs_inode *ino; ntfs_attribute *si; ntfs_debug (DEBUG_DIR1, "mkdir %s in %x\n", d->d_name.name, dir->i_ino); error = -ENAMETOOLONG; if (d->d_name.len > /* FIXME: */ 255) goto out; error = -EIO; r = new_inode(dir->i_sb); if (!r) goto out; vol = NTFS_INO2VOL(dir); ino = NTFS_LINO2NINO(r); error = ntfs_mkdir(NTFS_LINO2NINO(dir), d->d_name.name, d->d_name.len, ino); if (error) goto out; /* Not doing this one was causing a huge amount of corruption! Now the * bugger bytes the dust! (-8 (AIA) */ r->i_ino = ino->i_number; r->i_uid = vol->uid; r->i_gid = vol->gid; si = ntfs_find_attr(ino, vol->at_standard_information, NULL); if (si) { char *attr = si->d.data; r->i_atime = ntfs_ntutc2unixutc(NTFS_GETU64(attr + 0x18)); r->i_ctime = ntfs_ntutc2unixutc(NTFS_GETU64(attr)); r->i_mtime = ntfs_ntutc2unixutc(NTFS_GETU64(attr + 8)); } /* It's a directory. */ r->i_op = &ntfs_dir_inode_operations; r->i_fop = &ntfs_dir_operations; r->i_mode = S_IFDIR | S_IRUGO | S_IXUGO; #ifdef CONFIG_NTFS_RW r->i_mode |= S_IWUGO; #endif r->i_mode &= ~vol->umask; insert_inode_hash(r); d_instantiate(d, r); error = 0; out: ntfs_debug (DEBUG_DIR1, "mkdir returns %d\n", error); return error; }
static void ntfs_write_inode(struct inode *ino, int unused) { lock_kernel(); ntfs_debug(DEBUG_LINUX, "ntfs_write_inode 0x%x\n", ino->i_ino); ntfs_update_inode(NTFS_LINO2NINO(ino)); unlock_kernel(); }
static ssize_t ntfs_read(struct file * filp, char *buf, size_t count, loff_t *off) { int error; ntfs_io io; ntfs_inode *ino=NTFS_LINO2NINO(filp->f_dentry->d_inode); /* inode is not properly initialized */ if(!ino)return -EINVAL; ntfs_debug(DEBUG_OTHER, "ntfs_read %x,%x,%x ->", (unsigned)ino->i_number,(unsigned)*off,(unsigned)count); /* inode has no unnamed data attribute */ if(!ntfs_find_attr(ino,ino->vol->at_data,NULL)) return -EINVAL; /* read the data */ io.fn_put=ntfs_putuser; io.fn_get=0; io.param=buf; io.size=count; error=ntfs_read_attr(ino,ino->vol->at_data,NULL,*off,&io); if(error && !io.size)return -error; *off+=io.size; return io.size; }
static struct dentry *ntfs_lookup(struct inode *dir, struct dentry *d) { struct inode *res=0; char *item=0; ntfs_iterate_s walk; int error; ntfs_debug(DEBUG_NAME1, "Looking up %s in %x\n",d->d_name.name, (unsigned)dir->i_ino); /* convert to wide string */ error=ntfs_decodeuni(NTFS_INO2VOL(dir),(char*)d->d_name.name, d->d_name.len,&walk.name,&walk.namelen); if(error) return ERR_PTR(-error); item=ntfs_malloc(ITEM_SIZE); if( !item ) return ERR_PTR(-ENOMEM); /* ntfs_getdir will place the directory entry into item, and the first long long is the MFT record number */ walk.type=BY_NAME; walk.dir=NTFS_LINO2NINO(dir); walk.result=item; if(ntfs_getdir_byname(&walk)) { res=iget(dir->i_sb,NTFS_GETU32(item)); } d_add(d,res); ntfs_free(item); ntfs_free(walk.name); /* Always return success, the dcache will handle negative entries. */ return NULL; }
static int ntfs_bmap(struct inode *ino,int block) { int ret=ntfs_vcn_to_lcn(NTFS_LINO2NINO(ino),block); ntfs_debug(DEBUG_OTHER, "bmap of %lx,block %x is %x\n", ino->i_ino,block,ret); return (ret==-1) ? 0:ret; }
static ssize_t ntfs_write(struct file *filp, const char *buf, size_t count, loff_t *pos) { int err; struct inode *vfs_ino = filp->f_dentry->d_inode; ntfs_inode *ntfs_ino = NTFS_LINO2NINO(vfs_ino); ntfs_attribute *data; ntfs_io io; struct ntfs_getuser_update_vm_s param; if (!ntfs_ino) return -EINVAL; ntfs_debug(DEBUG_LINUX, __FUNCTION__ "(): Entering for inode 0x%lx, " "*pos 0x%Lx, count 0x%x.\n", ntfs_ino->i_number, *pos, count); /* Allows to lock fs ro at any time. */ if (vfs_ino->i_sb->s_flags & MS_RDONLY) return -EROFS; data = ntfs_find_attr(ntfs_ino, ntfs_ino->vol->at_data, NULL); if (!data) return -EINVAL; /* Evaluating O_APPEND is the file system's job... */ if (filp->f_flags & O_APPEND) *pos = vfs_ino->i_size; if (!data->resident && *pos + count > data->allocated) { err = ntfs_extend_attr(ntfs_ino, data, *pos + count); if (err < 0) return err; } param.user = buf; param.ino = vfs_ino; param.off = *pos; io.fn_put = 0; io.fn_get = ntfs_getuser_update_vm; io.param = ¶m; io.size = count; io.do_read = 0; err = ntfs_readwrite_attr(ntfs_ino, data, *pos, &io); ntfs_debug(DEBUG_LINUX, __FUNCTION__ "(): Returning %i\n", -err); if (!err) { *pos += io.size; if (*pos > vfs_ino->i_size) vfs_ino->i_size = *pos; mark_inode_dirty(vfs_ino); return io.size; } return err; }
/* readdir returns '..', then '.', then the directory entries in sequence As the root directory contains a entry for itself, '.' is not emulated for the root directory */ static int ntfs_readdir(struct file* filp, void *dirent, filldir_t filldir) { struct ntfs_filldir cb; int error; struct inode *dir=filp->f_dentry->d_inode; ntfs_debug(DEBUG_OTHER, "ntfs_readdir ino %x mode %x\n", (unsigned)dir->i_ino,(unsigned int)dir->i_mode); ntfs_debug(DEBUG_OTHER, "readdir: Looking for file %x dircount %d\n", (unsigned)filp->f_pos,atomic_read(&dir->i_count)); cb.pl=filp->f_pos & 0xFFFF; cb.ph=filp->f_pos >> 16; /* end of directory */ if(cb.ph==0xFFFF){ /* FIXME: Maybe we can return those with the previous call */ switch(cb.pl){ case 0: filldir(dirent,".",1,filp->f_pos,dir->i_ino,DT_DIR); filp->f_pos=0xFFFF0001; return 0; /* FIXME: parent directory */ case 1: filldir(dirent,"..",2,filp->f_pos,0,DT_DIR); filp->f_pos=0xFFFF0002; return 0; } ntfs_debug(DEBUG_OTHER, "readdir: EOD\n"); return 0; } cb.dir=dir; cb.filldir=filldir; cb.dirent=dirent; cb.type=NTFS_INO2VOL(dir)->ngt; do{ ntfs_debug(DEBUG_OTHER,"looking for next file\n"); error=ntfs_getdir_unsorted(NTFS_LINO2NINO(dir),&cb.ph,&cb.pl, ntfs_printcb,&cb); }while(!error && cb.ph!=0xFFFFFFFF); filp->f_pos=(cb.ph<<16)|cb.pl; ntfs_debug(DEBUG_OTHER, "new position %x\n",(unsigned)filp->f_pos); /* -EINVAL is on user buffer full. This is not considered as an error by sys_getdents */ if(error<0) error=0; /* Otherwise (device error, inconsistent data), switch the sign */ return -error; }
static ssize_t ntfs_write(struct file *filp,const char* buf,size_t count,loff_t *pos) { int ret; ntfs_io io; struct inode *inode = filp->f_dentry->d_inode; ntfs_inode *ino = NTFS_LINO2NINO(inode); struct ntfs_getuser_update_vm_s param; if (!ino) return -EINVAL; ntfs_debug (DEBUG_LINUX, "ntfs_write %x,%x,%x ->\n", (unsigned)ino->i_number, (unsigned)*pos, (unsigned)count); /* Allows to lock fs ro at any time */ if (inode->i_sb->s_flags & MS_RDONLY) return -ENOSPC; if (!ntfs_find_attr(ino,ino->vol->at_data,NULL)) return -EINVAL; /* Evaluating O_APPEND is the file system's job... */ if (filp->f_flags & O_APPEND) *pos = inode->i_size; param.user = buf; param.ino = inode; param.off = *pos; io.fn_put = 0; io.fn_get = ntfs_getuser_update_vm; io.param = ¶m; io.size = count; ret = ntfs_write_attr (ino, ino->vol->at_data, NULL, *pos, &io); ntfs_debug (DEBUG_LINUX, "write -> %x\n", ret); if(ret<0) return -EINVAL; *pos += io.size; if (*pos > inode->i_size) inode->i_size = *pos; mark_inode_dirty (filp->f_dentry->d_inode); return io.size; }
/* loff_t is 64 bit signed, so is cool. */ static ssize_t ntfs_read(struct file *filp, char *buf, size_t count,loff_t *off) { int error; ntfs_io io; ntfs_attribute *attr; ntfs_inode *ino = NTFS_LINO2NINO(filp->f_dentry->d_inode); /* Inode is not properly initialized. */ if (!ino) return -EINVAL; ntfs_debug(DEBUG_OTHER, "ntfs_read %x, %Lx, %x ->", (unsigned)ino->i_number, (unsigned long long)*off, (unsigned)count); attr = ntfs_find_attr(ino, ino->vol->at_data, NULL); /* Inode has no unnamed data attribute. */ if (!attr) { ntfs_debug(DEBUG_OTHER, "ntfs_read: $DATA not found!\n"); return -EINVAL; } if (attr->flags & ATTR_IS_ENCRYPTED) return -EACCES; /* Read the data. */ io.fn_put = ntfs_putuser; io.fn_get = 0; io.param = buf; io.size = count; error = ntfs_read_attr(ino, ino->vol->at_data, NULL, *off, &io); if (error && !io.size) { ntfs_debug(DEBUG_OTHER, "ntfs_read: read_attr failed with " "error %i, io size %u.\n", error, io.size); return error; } *off += io.size; ntfs_debug(DEBUG_OTHER, "ntfs_read: finished. read %u bytes.\n", io.size); return io.size; }
static struct dentry *ntfs_lookup(struct inode *dir, struct dentry *d) { struct inode *res = 0; char *item = 0; ntfs_iterate_s walk; int err; ntfs_debug(DEBUG_NAME1, __FUNCTION__ "(): Looking up %s in directory " "ino 0x%x.\n", d->d_name.name, (unsigned)dir->i_ino); walk.name = NULL; walk.namelen = 0; /* Convert to wide string. */ err = ntfs_decodeuni(NTFS_INO2VOL(dir), (char*)d->d_name.name, d->d_name.len, &walk.name, &walk.namelen); if (err) goto err_ret; item = ntfs_malloc(ITEM_SIZE); if (!item) { err = -ENOMEM; goto err_ret; } /* ntfs_getdir will place the directory entry into item, and the first * long long is the MFT record number. */ walk.type = BY_NAME; walk.dir = NTFS_LINO2NINO(dir); walk.result = item; if (ntfs_getdir_byname(&walk)) res = iget(dir->i_sb, NTFS_GETU32(item)); d_add(d, res); ntfs_free(item); ntfs_free(walk.name); /* Always return success, the dcache will handle negative entries. */ return NULL; err_ret: ntfs_free(walk.name); return ERR_PTR(err); }
/* * readdir returns '.', then '..', then the directory entries in sequence. * As the root directory contains an entry for itself, '.' is not emulated for * the root directory. */ static int ntfs_readdir(struct file* filp, void *dirent, filldir_t filldir) { struct inode *dir = filp->f_dentry->d_inode; int err; struct ntfs_filldir cb; cb.ret_code = 0; cb.pl = filp->f_pos & 0xffff; cb.ph = (filp->f_pos >> 16) & 0x7fff; filp->f_pos = (loff_t)(cb.ph << 16) | cb.pl; ntfs_debug(DEBUG_OTHER, __FUNCTION__ "(): Entering for inode %lu, " "f_pos 0x%Lx, i_mode 0x%x, i_count %lu.\n", dir->i_ino, filp->f_pos, (unsigned int)dir->i_mode, atomic_read(&dir->i_count)); if (!cb.ph) { /* Start of directory. Emulate "." and "..". */ if (!cb.pl) { ntfs_debug(DEBUG_OTHER, __FUNCTION__ "(): Calling " "filldir for . with len 1, f_pos 0x%Lx, " "inode %lu, DT_DIR.\n", filp->f_pos, dir->i_ino); cb.ret_code = filldir(dirent, ".", 1, filp->f_pos, dir->i_ino, DT_DIR); if (cb.ret_code) goto done; cb.pl++; filp->f_pos = (loff_t)(cb.ph << 16) | cb.pl; } if (cb.pl == (u32)1) { ntfs_debug(DEBUG_OTHER, __FUNCTION__ "(): Calling " "filldir for .. with len 2, f_pos 0x%Lx, " "inode %lu, DT_DIR.\n", filp->f_pos, filp->f_dentry->d_parent->d_inode->i_ino); cb.ret_code = filldir(dirent, "..", 2, filp->f_pos, filp->f_dentry->d_parent->d_inode->i_ino, DT_DIR); if (cb.ret_code) goto done; cb.pl++; filp->f_pos = (loff_t)(cb.ph << 16) | cb.pl; } } else if (cb.ph >= 0x7fff) /* End of directory. */ goto done; cb.dir = dir; cb.filldir = filldir; cb.dirent = dirent; cb.type = NTFS_INO2VOL(dir)->ngt; do { ntfs_debug(DEBUG_OTHER, __FUNCTION__ "(): Looking for next " "file using ntfs_getdir_unsorted(), f_pos " "0x%Lx.\n", (loff_t)(cb.ph << 16) | cb.pl); err = ntfs_getdir_unsorted(NTFS_LINO2NINO(dir), &cb.ph, &cb.pl, ntfs_printcb, &cb); } while (!err && !cb.ret_code && cb.ph < 0x7fff); filp->f_pos = (loff_t)(cb.ph << 16) | cb.pl; ntfs_debug(DEBUG_OTHER, __FUNCTION__ "(): After ntfs_getdir_unsorted()" " calls, f_pos 0x%Lx.\n", filp->f_pos); if (!err) { done: #ifdef DEBUG if (!cb.ret_code) ntfs_debug(DEBUG_OTHER, __FUNCTION__ "(): EOD, f_pos " "0x%Lx, returning 0.\n", filp->f_pos); else ntfs_debug(DEBUG_OTHER, __FUNCTION__ "(): filldir " "returned %i, returning 0, f_pos " "0x%Lx.\n", cb.ret_code, filp->f_pos); #endif return 0; } ntfs_debug(DEBUG_OTHER, __FUNCTION__ "(): Returning %i, f_pos 0x%Lx.\n", err, filp->f_pos); return err; }
static int ntfs_create(struct inode* dir,struct dentry *d,int mode) { struct inode *r=0; ntfs_inode *ino=0; ntfs_volume *vol; int error=0; ntfs_attribute *si; r=new_inode(dir->i_sb); if(!r){ error=ENOMEM; goto fail; } ntfs_debug(DEBUG_OTHER, "ntfs_create %s\n",d->d_name.name); vol=NTFS_INO2VOL(dir); #ifdef NTFS_IN_LINUX_KERNEL ino=NTFS_LINO2NINO(r); #else ino=ntfs_malloc(sizeof(ntfs_inode)); if(!ino){ error=ENOMEM; goto fail; } r->u.generic_ip=ino; #endif error=ntfs_alloc_file(NTFS_LINO2NINO(dir),ino,(char*)d->d_name.name, d->d_name.len); if(error)goto fail; error=ntfs_update_inode(ino); if(error)goto fail; error=ntfs_update_inode(NTFS_LINO2NINO(dir)); if(error)goto fail; r->i_uid=vol->uid; r->i_gid=vol->gid; /* FIXME: dirty? dev? */ /* get the file modification times from the standard information */ si=ntfs_find_attr(ino,vol->at_standard_information,NULL); if(si){ char *attr=si->d.data; r->i_atime=ntfs_ntutc2unixutc(NTFS_GETU64(attr+0x18)); r->i_ctime=ntfs_ntutc2unixutc(NTFS_GETU64(attr)); r->i_mtime=ntfs_ntutc2unixutc(NTFS_GETU64(attr+8)); } /* It's not a directory */ r->i_op=&ntfs_inode_operations_nobmap; r->i_fop=&ntfs_file_operations_nommap, r->i_mode=S_IFREG|S_IRUGO; #ifdef CONFIG_NTFS_RW r->i_mode|=S_IWUGO; #endif r->i_mode &= ~vol->umask; insert_inode_hash(r); d_instantiate(d,r); return 0; fail: #ifndef NTFS_IN_LINUX_KERNEL if(ino)ntfs_free(ino); #endif if(r)iput(r); return -error; }
static void ntfs_write_inode (struct inode *ino) { ntfs_debug (DEBUG_LINUX, "ntfs:write inode %x\n", ino->i_ino); ntfs_update_inode (NTFS_LINO2NINO (ino)); }