- yaffs_GrossLock(dev);
-
- nFreeChunks = yaffs_GetNumberOfFreeChunks(dev);
-
- yaffs_GrossUnlock(dev);
-
- return (nFreeChunks > 20) ? 1 : 0;
-}
-
-static void yaffs_release_space(struct file *f)
-{
- yaffs_Object *obj;
- yaffs_Device *dev;
-
-
- obj = yaffs_DentryToObject(f->f_dentry);
-
- dev = obj->myDev;
-
- yaffs_GrossLock(dev);
-
-
- yaffs_GrossUnlock(dev);
-}
-
-
-static loff_t yaffs_dir_llseek(struct file *file, loff_t offset, int origin)
-{
- long long retval;
-
- lock_kernel();
-
- switch (origin){
- case 2:
- offset += i_size_read(file->f_path.dentry->d_inode);
- break;
- case 1:
- offset += file->f_pos;
- }
- retval = -EINVAL;
-
- if (offset >= 0){
- if (offset != file->f_pos)
- file->f_pos = offset;
-
- retval = offset;
- }
- unlock_kernel();
- return retval;
-}
-
-
-static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir)
-{
- yaffs_Object *obj;
- yaffs_Device *dev;
- struct yaffs_SearchContext *sc;
- struct inode *inode = f->f_dentry->d_inode;
- unsigned long offset, curoffs;
- yaffs_Object *l;
- int retVal = 0;
-
- char name[YAFFS_MAX_NAME_LENGTH + 1];
-
- obj = yaffs_DentryToObject(f->f_dentry);
- dev = obj->myDev;
-
- yaffs_GrossLock(dev);
-
- yaffs_DeviceToLC(dev)->readdirProcess = current;
-
- offset = f->f_pos;
-
- sc = yaffs_NewSearch(obj);
- if(!sc){
- retVal = -ENOMEM;
- goto out;
- }
-
- T(YAFFS_TRACE_OS, (TSTR("yaffs_readdir: starting at %d\n"), (int)offset));
-
- if (offset == 0) {
- T(YAFFS_TRACE_OS,
- (TSTR("yaffs_readdir: entry . ino %d \n"),
- (int)inode->i_ino));
- yaffs_GrossUnlock(dev);
- if (filldir(dirent, ".", 1, offset, inode->i_ino, DT_DIR) < 0){
- yaffs_GrossLock(dev);
- goto out;
- }
- yaffs_GrossLock(dev);
- offset++;
- f->f_pos++;
- }
- if (offset == 1) {
- T(YAFFS_TRACE_OS,
- (TSTR("yaffs_readdir: entry .. ino %d \n"),
- (int)f->f_dentry->d_parent->d_inode->i_ino));
- yaffs_GrossUnlock(dev);
- if (filldir(dirent, "..", 2, offset,
- f->f_dentry->d_parent->d_inode->i_ino, DT_DIR) < 0){
- yaffs_GrossLock(dev);
- goto out;
- }
- yaffs_GrossLock(dev);
- offset++;
- f->f_pos++;
- }
-
- curoffs = 1;
-
- /* If the directory has changed since the open or last call to
- readdir, rewind to after the 2 canned entries. */
- if (f->f_version != inode->i_version) {
- offset = 2;
- f->f_pos = offset;
- f->f_version = inode->i_version;
- }
-
- while(sc->nextReturn){
- curoffs++;
- l = sc->nextReturn;
- if (curoffs >= offset) {
- int this_inode = yaffs_GetObjectInode(l);
- int this_type = yaffs_GetObjectType(l);
-
- yaffs_GetObjectName(l, name,
- YAFFS_MAX_NAME_LENGTH + 1);
- T(YAFFS_TRACE_OS,
- (TSTR("yaffs_readdir: %s inode %d\n"),
- name, yaffs_GetObjectInode(l)));
-
- yaffs_GrossUnlock(dev);
-
- if (filldir(dirent,
- name,
- strlen(name),
- offset,
- this_inode,
- this_type) < 0){
- yaffs_GrossLock(dev);
- goto out;
- }
-
- yaffs_GrossLock(dev);
-
- offset++;
- f->f_pos++;
- }
- yaffs_SearchAdvance(sc);
- }
-
-out:
- yaffs_EndSearch(sc);
- yaffs_DeviceToLC(dev)->readdirProcess = NULL;
- yaffs_GrossUnlock(dev);
-
- return retVal;
-}
-
-
-
-/*
- * File creation. Allocate an inode, and we're done..
- */
-
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29)
-#define YCRED(x) x
-#else
-#define YCRED(x) (x->cred)
-#endif
-
-#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
-static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
- dev_t rdev)
-#else
-static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
- int rdev)
-#endif
-{
- struct inode *inode;
-
- yaffs_Object *obj = NULL;
- yaffs_Device *dev;
-
- yaffs_Object *parent = yaffs_InodeToObject(dir);
-
- int error = -ENOSPC;
- uid_t uid = YCRED(current)->fsuid;
- gid_t gid = (dir->i_mode & S_ISGID) ? dir->i_gid : YCRED(current)->fsgid;
-
- if ((dir->i_mode & S_ISGID) && S_ISDIR(mode))
- mode |= S_ISGID;
-
- if (parent) {
- T(YAFFS_TRACE_OS,
- (TSTR("yaffs_mknod: parent object %d type %d\n"),
- parent->objectId, parent->variantType));
- } else {
- T(YAFFS_TRACE_OS,
- (TSTR("yaffs_mknod: could not get parent object\n")));
- return -EPERM;
- }
-
- T(YAFFS_TRACE_OS, (TSTR("yaffs_mknod: making oject for %s, "
- "mode %x dev %x\n"),
- dentry->d_name.name, mode, rdev));
-
- dev = parent->myDev;
-
- yaffs_GrossLock(dev);