Mercurial > yaffs-ecoscentric
annotate yaffs_fs.c @ 38:14315c63b7a5
Set the correct uid/gid of newly created files when: use fsuid & fsgid and take care when the SGID bit is set on the parent directory.
This should solve the problem reported by Frank Lehmann (http://lists.aleph1.co.uk/pipermail/yaffs/2005q2/001178.html).
| author | luc |
|---|---|
| date | Fri, 29 Jul 2005 21:25:43 +0100 |
| parents | 95f802b86a29 |
| children | 48513a2b5762 |
| rev | line source |
|---|---|
| 7 | 1 /* |
| 2 * YAFFS: Yet another FFS. A NAND-flash specific file system. | |
| 3 * yaffs_fs.c | |
| 4 * | |
| 5 * Copyright (C) 2002 Aleph One Ltd. | |
| 6 * for Toby Churchill Ltd and Brightstar Engineering | |
| 7 * | |
| 8 * Created by Charles Manning <charles@aleph1.co.uk> | |
| 9 * | |
| 10 * This program is free software; you can redistribute it and/or modify | |
| 11 * it under the terms of the GNU General Public License version 2 as | |
| 12 * published by the Free Software Foundation. | |
| 13 * | |
| 14 * This is the file system front-end to YAFFS that hooks it up to | |
| 15 * the VFS. | |
| 16 * | |
| 17 * Special notes: | |
|
24
4ebabd859f38
Some improvements to garbage collection and st_xxx to yst_xxx changes
charles
parents:
21
diff
changeset
|
18 * >> 2.4: sb->u.generic_sbp points to the yaffs_Device associated with this superblock |
|
4ebabd859f38
Some improvements to garbage collection and st_xxx to yst_xxx changes
charles
parents:
21
diff
changeset
|
19 * >> 2.6: sb->s_fs_info points to the yaffs_Device associated with this superblock |
| 7 | 20 * >> inode->u.generic_ip points to the associated yaffs_Object. |
| 21 * | |
| 22 * | |
| 23 * Acknowledgements: | |
| 24 * * Luc van OostenRyck for numerous patches. | |
| 25 * * Nick Bane for numerous patches. | |
| 26 * * Nick Bane for 2.5/2.6 integration. | |
| 27 * * Andras Toth for mknod rdev issue. | |
| 28 * * Michael Fischer for finding the problem with inode inconsistency. | |
| 29 * * Some code bodily lifted from JFFS2. | |
| 30 */ | |
| 31 | |
| 32 | |
| 33 const char *yaffs_fs_c_version = "$Id$"; | |
| 34 extern const char *yaffs_guts_c_version; | |
| 35 | |
| 36 | |
| 10 | 37 |
| 7 | 38 #include <linux/config.h> |
| 39 #include <linux/kernel.h> | |
| 40 #include <linux/module.h> | |
| 41 #include <linux/version.h> | |
| 42 #include <linux/slab.h> | |
| 43 #include <linux/init.h> | |
| 44 #include <linux/list.h> | |
| 45 #include <linux/fs.h> | |
| 46 #include <linux/proc_fs.h> | |
| 29 | 47 #include <linux/smp_lock.h> |
| 7 | 48 #include <linux/pagemap.h> |
| 49 #include <linux/mtd/mtd.h> | |
| 50 #include <linux/interrupt.h> | |
| 51 #include <linux/string.h> | |
| 52 | |
| 53 | |
| 54 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) | |
| 55 | |
| 56 #include <linux/statfs.h> /* Added NCB 15-8-2003 */ | |
| 57 #include <asm/statfs.h> | |
| 58 #define UnlockPage(p) unlock_page(p) | |
| 59 #define Page_Uptodate(page) test_bit(PG_uptodate, &(page)->flags) | |
| 60 //#define kdevname(x) cdevname(to_kdev_t(x)) | |
| 61 #define kdevname(x) "(unavailable)" // temporary fix | |
| 62 | |
| 63 #else | |
| 64 | |
| 65 #include <linux/locks.h> | |
| 66 | |
| 67 #endif | |
| 68 | |
| 69 #include <asm/uaccess.h> | |
| 70 | |
| 71 #include "yportenv.h" | |
| 72 #include "yaffs_guts.h" | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 10 | 77 unsigned yaffs_traceMask = YAFFS_TRACE_ALWAYS | YAFFS_TRACE_BAD_BLOCKS; |
| 78 //unsigned yaffs_traceMask = 0xFFFFFFFF; | |
| 7 | 79 |
| 80 | |
| 81 #ifdef CONFIG_YAFFS_RAM_ENABLED | |
| 82 #include "yaffs_nandemul.h" | |
| 83 // 2 MB of RAM for emulation | |
| 84 #define YAFFS_RAM_EMULATION_SIZE 0x200000 | |
| 85 #endif //CONFIG_YAFFS_RAM_ENABLED | |
| 86 | |
| 87 #if CONFIG_YAFFS2_RAM_ENABLED | |
| 88 #include "yaffs_nandemul2k.h" | |
| 89 #endif | |
| 90 | |
| 91 #ifdef CONFIG_YAFFS_MTD_ENABLED | |
| 92 #include <linux/mtd/mtd.h> | |
| 93 #include "yaffs_mtdif.h" | |
| 94 #include "yaffs_mtdif2.h" | |
| 95 #endif //CONFIG_YAFFS_MTD_ENABLED | |
| 96 | |
| 97 //#define T(x) printk x | |
| 98 | |
| 99 | |
| 100 | |
| 101 #define yaffs_InodeToObject(iptr) ((yaffs_Object *)((iptr)->u.generic_ip)) | |
| 102 #define yaffs_DentryToObject(dptr) yaffs_InodeToObject((dptr)->d_inode) | |
| 103 //NCB #define yaffs_SuperToDevice(sb) ((yaffs_Device *)sb->u.generic_sbp) | |
| 104 | |
| 105 //#if defined(CONFIG_KERNEL_2_5) | |
| 106 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) | |
| 107 #define yaffs_SuperToDevice(sb) ((yaffs_Device *)sb->s_fs_info) | |
| 108 #else | |
| 109 #define yaffs_SuperToDevice(sb) ((yaffs_Device *)sb->u.generic_sbp) | |
| 110 #endif | |
| 111 | |
| 112 | |
| 113 static void yaffs_put_super(struct super_block *sb); | |
| 114 | |
| 115 #if 0 | |
| 116 static ssize_t yaffs_file_read(struct file *f, char *buf, size_t n, loff_t *pos); | |
| 117 #endif | |
| 118 | |
| 119 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n, loff_t *pos); | |
| 120 | |
| 121 static int yaffs_file_flush(struct file* file); | |
| 122 | |
| 123 static int yaffs_sync_object(struct file * file, struct dentry *dentry, int datasync); | |
| 124 | |
| 125 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir); | |
| 126 | |
| 127 //#if defined(CONFIG_KERNEL_2_5) /* Added NCB 185-8-2003 */ | |
| 128 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) | |
| 129 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *n); | |
| 130 static struct dentry * yaffs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *n); | |
| 131 #else | |
| 132 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode); | |
| 133 static struct dentry * yaffs_lookup(struct inode *dir, struct dentry *dentry); | |
| 134 #endif | |
| 135 static int yaffs_link(struct dentry *old_dentry, struct inode * dir, struct dentry * dentry); | |
| 136 static int yaffs_unlink(struct inode * dir, struct dentry *dentry); | |
| 137 static int yaffs_symlink(struct inode * dir, struct dentry *dentry, const char * symname); | |
| 138 static int yaffs_mkdir(struct inode * dir, struct dentry * dentry, int mode); | |
| 139 | |
| 140 //#if defined(CONFIG_KERNEL_2_5) | |
| 141 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) | |
| 142 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev); | |
| 143 #else | |
| 144 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, int dev); | |
| 145 #endif | |
| 146 static int yaffs_rename(struct inode * old_dir, struct dentry *old_dentry, struct inode * new_dir,struct dentry *new_dentry); | |
| 147 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr); | |
| 148 | |
| 149 //#if defined(CONFIG_KERNEL_2_5) /* Added NCB 185-8-2003 */ | |
| 150 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) | |
| 151 static int yaffs_statfs(struct super_block *sb, struct kstatfs *buf); | |
| 152 #else | |
| 153 static int yaffs_statfs(struct super_block *sb, struct statfs *buf); | |
| 154 #endif | |
| 155 static void yaffs_read_inode (struct inode *inode); | |
| 156 | |
| 157 static void yaffs_put_inode (struct inode *inode); | |
| 158 static void yaffs_delete_inode(struct inode *); | |
| 159 static void yaffs_clear_inode(struct inode *); | |
| 160 | |
| 161 static int yaffs_readpage(struct file *file, struct page * page); | |
| 25 | 162 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) |
| 163 static int yaffs_writepage(struct page *page, struct writeback_control *wbc); | |
| 164 #else | |
| 7 | 165 static int yaffs_writepage(struct page *page); |
| 25 | 166 #endif |
| 7 | 167 static int yaffs_prepare_write(struct file *f, struct page *pg, unsigned offset, unsigned to); |
| 168 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset, unsigned to); | |
| 169 | |
| 25 | 170 static int yaffs_readlink(struct dentry *dentry, char __user *buffer, int buflen); |
| 7 | 171 static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd); |
| 172 | |
| 173 | |
| 174 | |
| 175 static struct address_space_operations yaffs_file_address_operations = { | |
| 31 | 176 .readpage = yaffs_readpage, |
| 177 .writepage = yaffs_writepage, | |
| 178 .prepare_write = yaffs_prepare_write, | |
| 179 .commit_write = yaffs_commit_write, | |
| 7 | 180 }; |
| 181 | |
| 182 static struct file_operations yaffs_file_operations = { | |
| 31 | 183 .read = generic_file_read, |
| 184 .write = generic_file_write, | |
| 185 .mmap = generic_file_mmap, | |
| 186 .flush = yaffs_file_flush, | |
| 187 .fsync = yaffs_sync_object, | |
| 7 | 188 }; |
| 189 | |
| 190 static struct inode_operations yaffs_file_inode_operations = { | |
| 31 | 191 .setattr = yaffs_setattr, |
| 7 | 192 }; |
| 193 | |
| 31 | 194 struct inode_operations yaffs_symlink_inode_operations = { |
| 195 .readlink = yaffs_readlink, | |
| 196 .follow_link = yaffs_follow_link, | |
| 197 .setattr = yaffs_setattr, | |
| 7 | 198 }; |
| 199 | |
| 200 static struct inode_operations yaffs_dir_inode_operations = { | |
| 31 | 201 .create = yaffs_create, |
| 202 .lookup = yaffs_lookup, | |
| 203 .link = yaffs_link, | |
| 204 .unlink = yaffs_unlink, | |
| 205 .symlink = yaffs_symlink, | |
| 206 .mkdir = yaffs_mkdir, | |
| 207 .rmdir = yaffs_unlink, | |
| 208 .mknod = yaffs_mknod, | |
| 209 .rename = yaffs_rename, | |
| 210 .setattr = yaffs_setattr, | |
| 7 | 211 }; |
| 212 | |
| 213 static struct file_operations yaffs_dir_operations = { | |
| 31 | 214 .read = generic_read_dir, |
| 215 .readdir = yaffs_readdir, | |
| 216 .fsync = yaffs_sync_object, | |
| 7 | 217 }; |
| 218 | |
| 219 static struct super_operations yaffs_super_ops = { | |
| 31 | 220 .statfs = yaffs_statfs, |
| 221 .read_inode = yaffs_read_inode, | |
| 222 .put_inode = yaffs_put_inode, | |
| 223 .put_super = yaffs_put_super, | |
| 224 .delete_inode = yaffs_delete_inode, | |
| 225 .clear_inode = yaffs_clear_inode, | |
| 7 | 226 }; |
| 227 | |
| 228 | |
| 229 | |
| 230 static void yaffs_GrossLock(yaffs_Device *dev) | |
| 231 { | |
| 232 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs locking\n")); | |
| 233 | |
| 234 down(&dev->grossLock); | |
| 235 } | |
| 236 | |
| 237 static void yaffs_GrossUnlock(yaffs_Device *dev) | |
| 238 { | |
| 239 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs unlocking\n")); | |
| 240 up(&dev->grossLock); | |
| 241 | |
| 242 } | |
| 243 | |
| 25 | 244 static int yaffs_readlink(struct dentry *dentry, char __user *buffer, int buflen) |
| 7 | 245 { |
| 246 unsigned char *alias; | |
| 247 int ret; | |
| 248 | |
| 249 yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev; | |
| 250 | |
| 251 | |
| 252 yaffs_GrossLock(dev); | |
| 253 | |
| 254 alias = yaffs_GetSymlinkAlias(yaffs_DentryToObject(dentry)); | |
| 255 | |
| 256 yaffs_GrossUnlock(dev); | |
| 257 | |
| 258 if(!alias) | |
| 259 return -ENOMEM; | |
| 260 | |
| 261 ret = vfs_readlink(dentry, buffer, buflen, alias); | |
| 262 kfree(alias); | |
| 263 return ret; | |
| 264 } | |
| 265 | |
| 266 static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd) | |
| 267 { | |
| 268 unsigned char *alias; | |
| 269 int ret; | |
| 270 yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev; | |
| 271 | |
| 272 | |
| 273 yaffs_GrossLock(dev); | |
| 274 | |
| 275 alias = yaffs_GetSymlinkAlias(yaffs_DentryToObject(dentry)); | |
| 276 | |
| 277 yaffs_GrossUnlock(dev); | |
| 278 | |
| 279 if(!alias) | |
| 280 return -ENOMEM; | |
| 281 | |
| 282 ret = vfs_follow_link(nd,alias); | |
| 283 kfree(alias); | |
| 284 return ret; | |
| 285 } | |
| 286 | |
| 287 | |
| 288 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,yaffs_Object *obj); | |
| 289 | |
| 290 /* | |
| 291 * Lookup is used to find objects in the fs | |
| 292 */ | |
| 293 //#if defined(CONFIG_KERNEL_2_5) /* Added NCB 185-8-2003 */ | |
| 294 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) | |
| 295 | |
| 296 static struct dentry * yaffs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *n) | |
| 297 #else | |
| 298 static struct dentry * yaffs_lookup(struct inode *dir, struct dentry *dentry) | |
| 299 #endif | |
| 300 { | |
| 301 yaffs_Object *obj; | |
| 302 struct inode *inode = NULL; // NCB 2.5/2.6 needs NULL here | |
| 303 | |
| 304 yaffs_Device *dev = yaffs_InodeToObject(dir)->myDev; | |
| 305 | |
| 306 | |
| 307 yaffs_GrossLock(dev); | |
| 308 | |
| 309 | |
| 310 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_lookup for %d:%s\n",yaffs_InodeToObject(dir)->objectId,dentry->d_name.name)); | |
| 311 | |
| 312 obj = yaffs_FindObjectByName(yaffs_InodeToObject(dir),dentry->d_name.name); | |
| 313 | |
| 314 obj = yaffs_GetEquivalentObject(obj); // in case it was a hardlink | |
| 315 | |
| 316 | |
| 317 | |
| 318 if(obj) | |
| 319 { | |
| 320 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_lookup found %d\n",obj->objectId)); | |
| 321 | |
|
24
4ebabd859f38
Some improvements to garbage collection and st_xxx to yst_xxx changes
charles
parents:
21
diff
changeset
|
322 inode = yaffs_get_inode(dir->i_sb, obj->yst_mode,0,obj); |
| 7 | 323 |
| 324 if(inode) | |
| 325 { | |
| 326 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_loookup dentry \n")); | |
| 327 /* #if 0 asserted by NCB for 2.5/6 compatability - falls through to d_add even if NULL inode */ | |
| 328 #if 0 | |
| 329 //dget(dentry); // try to solve directory bug | |
| 330 d_add(dentry,inode); | |
| 331 | |
| 332 yaffs_GrossUnlock(dev); | |
| 333 | |
| 334 // return dentry; | |
| 335 return NULL; | |
| 336 #endif | |
| 337 } | |
| 338 | |
| 339 } | |
| 340 else | |
| 341 { | |
| 342 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_lookup not found\n")); | |
| 343 | |
| 344 } | |
| 345 yaffs_GrossUnlock(dev); | |
| 346 | |
| 347 /* added NCB for 2.5/6 compatability - forces add even if inode is NULL which creates dentry hash*/ | |
| 348 d_add(dentry,inode); | |
| 349 | |
| 350 return NULL; | |
| 351 // return (ERR_PTR(-EIO)); | |
| 352 | |
| 353 } | |
| 354 | |
| 355 // For now put inode is just for debugging | |
| 356 // Put inode is called when the inode **structure** is put. | |
| 357 static void yaffs_put_inode(struct inode *inode) | |
| 358 { | |
| 359 T(YAFFS_TRACE_OS,("yaffs_put_inode: ino %d, count %d\n",(int)inode->i_ino, atomic_read(&inode->i_count))); | |
| 360 | |
| 361 } | |
| 362 | |
| 363 // clear is called to tell the fs to release any per-inode data it holds | |
| 364 static void yaffs_clear_inode(struct inode *inode) | |
| 365 { | |
| 366 yaffs_Object *obj; | |
| 367 yaffs_Device *dev; | |
| 368 | |
| 369 obj = yaffs_InodeToObject(inode); | |
| 370 | |
| 371 T(YAFFS_TRACE_OS,("yaffs_clear_inode: ino %d, count %d %s\n",(int)inode->i_ino, atomic_read(&inode->i_count), | |
| 372 obj ? "object exists" : "null object")); | |
| 373 | |
| 374 if(obj) | |
| 375 { | |
| 376 dev = obj->myDev; | |
| 377 yaffs_GrossLock(dev); | |
| 378 | |
| 379 // Clear the association between the inode ant the yaffs_Object. | |
| 380 obj->myInode = NULL; | |
| 381 inode->u.generic_ip = NULL; | |
| 382 | |
| 383 // If the object freeing was deferred, then the real free happens now. | |
| 384 // This should fix the inode inconsistency problem. | |
| 385 | |
| 386 yaffs_HandleDeferedFree(obj); | |
| 387 | |
| 388 yaffs_GrossUnlock(dev); | |
| 389 } | |
| 390 | |
| 391 | |
| 392 } | |
| 393 | |
| 394 // delete is called when the link count is zero and the inode | |
| 395 // is put (ie. nobody wants to know about it anymore, time to | |
| 396 // delete the file). | |
| 397 // NB Must call clear_inode() | |
| 398 static void yaffs_delete_inode(struct inode *inode) | |
| 399 { | |
| 400 yaffs_Object *obj = yaffs_InodeToObject(inode); | |
| 401 yaffs_Device *dev; | |
| 402 | |
| 403 T(YAFFS_TRACE_OS,("yaffs_delete_inode: ino %d, count %d %s\n",(int)inode->i_ino, atomic_read(&inode->i_count), | |
| 404 obj ? "object exists" : "null object")); | |
| 405 | |
| 406 if(obj) | |
| 407 { | |
| 408 dev = obj->myDev; | |
| 409 yaffs_GrossLock(dev); | |
| 410 yaffs_DeleteFile(obj); | |
| 411 yaffs_GrossUnlock(dev); | |
| 412 } | |
| 413 clear_inode(inode); | |
| 414 } | |
| 415 | |
| 416 | |
| 417 static int yaffs_file_flush(struct file* file) | |
| 418 { | |
| 419 yaffs_Object *obj = yaffs_DentryToObject(file->f_dentry); | |
| 420 | |
| 421 yaffs_Device *dev = obj->myDev; | |
| 422 | |
| 423 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_flush object %d (%s)\n",obj->objectId, | |
| 424 obj->dirty ? "dirty" : "clean")); | |
| 425 | |
| 426 yaffs_GrossLock(dev); | |
| 427 | |
| 428 yaffs_FlushFile(obj,1); | |
| 429 | |
| 430 yaffs_GrossUnlock(dev); | |
| 431 | |
| 432 return 0; | |
| 433 } | |
| 434 | |
| 435 | |
| 436 | |
| 437 static int yaffs_readpage_nolock(struct file *f, struct page * pg) | |
| 438 { | |
| 439 // Lifted from jffs2 | |
| 440 | |
| 441 yaffs_Object *obj; | |
| 442 unsigned char *pg_buf; | |
| 443 int ret; | |
| 444 | |
| 445 yaffs_Device *dev; | |
| 446 | |
| 447 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readpage at %08x, size %08x\n", | |
| 448 (unsigned)(pg->index << PAGE_CACHE_SHIFT), (unsigned)PAGE_CACHE_SIZE)); | |
| 449 | |
| 450 obj = yaffs_DentryToObject(f->f_dentry); | |
| 451 | |
| 452 dev = obj->myDev; | |
| 453 | |
| 454 | |
| 25 | 455 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) |
| 456 BUG_ON(!PageLocked(pg)); | |
| 457 #else | |
| 7 | 458 if (!PageLocked(pg)) |
| 459 PAGE_BUG(pg); | |
| 25 | 460 #endif |
| 7 | 461 |
| 462 pg_buf = kmap(pg); | |
| 463 /* FIXME: Can kmap fail? */ | |
| 464 | |
| 465 yaffs_GrossLock(dev); | |
| 466 | |
| 467 ret = yaffs_ReadDataFromFile(obj, pg_buf, pg->index << PAGE_CACHE_SHIFT, PAGE_CACHE_SIZE); | |
| 468 | |
| 469 yaffs_GrossUnlock(dev); | |
| 470 | |
| 471 if(ret >= 0) ret = 0; | |
| 472 | |
| 473 if (ret) { | |
| 474 ClearPageUptodate(pg); | |
| 475 SetPageError(pg); | |
| 476 } else { | |
| 477 SetPageUptodate(pg); | |
| 478 ClearPageError(pg); | |
| 479 } | |
| 480 | |
| 481 flush_dcache_page(pg); | |
| 482 kunmap(pg); | |
| 483 | |
| 484 | |
| 485 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readpage done\n")); | |
| 486 return ret; | |
| 487 } | |
| 488 | |
| 489 static int yaffs_readpage_unlock(struct file *f, struct page *pg) | |
| 490 { | |
| 491 int ret = yaffs_readpage_nolock(f,pg); | |
| 492 UnlockPage(pg); | |
| 493 return ret; | |
| 494 } | |
| 495 | |
| 496 static int yaffs_readpage(struct file *f, struct page * pg) | |
| 497 { | |
| 498 return yaffs_readpage_unlock(f,pg); | |
| 499 } | |
| 500 | |
| 501 // writepage inspired by/stolen from smbfs | |
| 502 // | |
| 503 | |
| 25 | 504 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) |
| 505 static int yaffs_writepage(struct page *page, struct writeback_control *wbc) | |
| 506 #else | |
| 7 | 507 static int yaffs_writepage(struct page *page) |
| 25 | 508 #endif |
| 7 | 509 { |
| 510 struct address_space *mapping = page->mapping; | |
| 511 struct inode *inode; | |
| 512 unsigned long end_index; | |
| 513 char *buffer; | |
| 514 yaffs_Object *obj; | |
| 515 int nWritten = 0; | |
| 516 unsigned nBytes; | |
| 517 | |
| 518 if (!mapping) | |
| 519 BUG(); | |
| 520 inode = mapping->host; | |
| 521 if (!inode) | |
| 522 BUG(); | |
| 523 | |
| 524 end_index = inode->i_size >> PAGE_CACHE_SHIFT; | |
| 525 | |
| 526 /* easy case */ | |
| 527 if (page->index < end_index) | |
| 528 { | |
| 529 nBytes = PAGE_CACHE_SIZE; | |
| 530 } | |
| 531 else | |
| 532 { | |
| 533 nBytes = inode->i_size & (PAGE_CACHE_SIZE-1); | |
| 534 } | |
| 535 // What's happening here? | |
| 536 ///* OK, are we completely out? */ | |
| 537 //if (page->index >= end_index+1 || !offset) | |
| 538 // return -EIO; | |
| 539 | |
| 540 get_page(page); | |
| 541 | |
| 542 | |
| 543 buffer = kmap(page); | |
| 544 | |
| 545 obj = yaffs_InodeToObject(inode); | |
| 546 yaffs_GrossLock(obj->myDev); | |
| 547 | |
| 548 | |
| 20 | 549 nWritten = yaffs_WriteDataToFile(obj,buffer,page->index << PAGE_CACHE_SHIFT,nBytes,0); |
| 7 | 550 |
| 551 yaffs_GrossUnlock(obj->myDev); | |
| 552 | |
| 553 kunmap(page); | |
| 554 SetPageUptodate(page); | |
| 555 UnlockPage(page); | |
| 556 put_page(page); | |
| 557 | |
| 558 return (nWritten == nBytes) ? 0 : -ENOSPC; | |
| 559 } | |
| 560 | |
| 561 | |
| 562 | |
| 563 static int yaffs_prepare_write(struct file *f, struct page *pg, unsigned offset, unsigned to) | |
| 564 { | |
| 565 | |
| 566 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_prepair_write\n")); | |
| 567 if(!Page_Uptodate(pg) && (offset || to < PAGE_CACHE_SIZE)) | |
| 568 return yaffs_readpage_nolock(f,pg); | |
| 569 | |
| 570 return 0; | |
| 571 | |
| 572 } | |
| 573 | |
| 574 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset, unsigned to) | |
| 575 { | |
| 576 | |
| 577 void *addr = page_address(pg) + offset; | |
| 578 loff_t pos = (((loff_t)pg->index) << PAGE_CACHE_SHIFT) + offset; | |
| 579 int nBytes = to - offset; | |
| 580 int nWritten; | |
| 581 | |
| 582 unsigned spos = pos; | |
| 583 unsigned saddr = (unsigned)addr; | |
| 584 | |
| 585 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_commit_write addr %x pos %x nBytes %d\n",saddr,spos,nBytes)); | |
| 586 | |
| 587 nWritten = yaffs_file_write(f,addr, nBytes, &pos); | |
| 588 | |
| 589 if(nWritten != nBytes) | |
| 590 { | |
| 591 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_commit_write not same size nWritten %d nBytes %d\n",nWritten,nBytes)); | |
| 592 SetPageError(pg); | |
| 593 ClearPageUptodate(pg); | |
| 594 } | |
| 595 else | |
| 596 { | |
| 597 SetPageUptodate(pg); | |
| 598 } | |
| 599 | |
| 600 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_commit_write returning %d\n",nWritten)); | |
| 601 | |
| 602 return nWritten; | |
| 603 | |
| 604 } | |
| 605 | |
| 606 | |
| 607 | |
| 608 static void yaffs_FillInodeFromObject(struct inode *inode, yaffs_Object *obj) | |
| 609 { | |
| 610 if (inode && obj) | |
| 611 { | |
| 612 inode->i_ino = obj->objectId; | |
|
24
4ebabd859f38
Some improvements to garbage collection and st_xxx to yst_xxx changes
charles
parents:
21
diff
changeset
|
613 inode->i_mode = obj->yst_mode; |
|
4ebabd859f38
Some improvements to garbage collection and st_xxx to yst_xxx changes
charles
parents:
21
diff
changeset
|
614 inode->i_uid = obj->yst_uid; |
|
4ebabd859f38
Some improvements to garbage collection and st_xxx to yst_xxx changes
charles
parents:
21
diff
changeset
|
615 inode->i_gid = obj->yst_gid; |
| 7 | 616 inode->i_blksize = inode->i_sb->s_blocksize; |
| 617 //#if defined(CONFIG_KERNEL_2_5) | |
| 618 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) | |
| 619 | |
|
24
4ebabd859f38
Some improvements to garbage collection and st_xxx to yst_xxx changes
charles
parents:
21
diff
changeset
|
620 inode->i_rdev = old_decode_dev(obj->yst_rdev); |
|
4ebabd859f38
Some improvements to garbage collection and st_xxx to yst_xxx changes
charles
parents:
21
diff
changeset
|
621 inode->i_atime.tv_sec = (time_t)(obj->yst_atime); |
| 7 | 622 inode->i_atime.tv_nsec = 0; |
|
24
4ebabd859f38
Some improvements to garbage collection and st_xxx to yst_xxx changes
charles
parents:
21
diff
changeset
|
623 inode->i_mtime.tv_sec = (time_t)obj->yst_mtime; |
| 7 | 624 inode->i_mtime.tv_nsec =0; |
|
24
4ebabd859f38
Some improvements to garbage collection and st_xxx to yst_xxx changes
charles
parents:
21
diff
changeset
|
625 inode->i_ctime.tv_sec = (time_t)obj->yst_ctime; |
| 7 | 626 inode->i_ctime.tv_nsec = 0; |
| 627 #else | |
|
24
4ebabd859f38
Some improvements to garbage collection and st_xxx to yst_xxx changes
charles
parents:
21
diff
changeset
|
628 inode->i_rdev = obj->yst_rdev; |
|
4ebabd859f38
Some improvements to garbage collection and st_xxx to yst_xxx changes
charles
parents:
21
diff
changeset
|
629 inode->i_atime = obj->yst_atime; |
|
4ebabd859f38
Some improvements to garbage collection and st_xxx to yst_xxx changes
charles
parents:
21
diff
changeset
|
630 inode->i_mtime = obj->yst_mtime; |
|
4ebabd859f38
Some improvements to garbage collection and st_xxx to yst_xxx changes
charles
parents:
21
diff
changeset
|
631 inode->i_ctime = obj->yst_ctime; |
| 7 | 632 #endif |
| 633 inode->i_size = yaffs_GetObjectFileLength(obj); | |
| 634 inode->i_blocks = (inode->i_size + 511) >> 9; | |
| 635 | |
| 636 inode->i_nlink = yaffs_GetObjectLinkCount(obj); | |
| 637 | |
| 638 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_FillInode mode %x uid %d gid %d size %d count %d\n", | |
| 639 inode->i_mode, inode->i_uid, inode->i_gid, (int)inode->i_size, atomic_read(&inode->i_count))); | |
| 640 | |
|
24
4ebabd859f38
Some improvements to garbage collection and st_xxx to yst_xxx changes
charles
parents:
21
diff
changeset
|
641 switch (obj->yst_mode & S_IFMT) |
| 7 | 642 { |
| 643 default: // fifo, device or socket | |
| 13 | 644 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) |
|
24
4ebabd859f38
Some improvements to garbage collection and st_xxx to yst_xxx changes
charles
parents:
21
diff
changeset
|
645 init_special_inode(inode, obj->yst_mode,old_decode_dev(obj->yst_rdev)); |
| 13 | 646 #else |
|
24
4ebabd859f38
Some improvements to garbage collection and st_xxx to yst_xxx changes
charles
parents:
21
diff
changeset
|
647 init_special_inode(inode, obj->yst_mode,(dev_t)(obj->yst_rdev)); |
| 25 | 648 #endif |
| 649 break; | |
| 7 | 650 case S_IFREG: // file |
| 651 inode->i_op = &yaffs_file_inode_operations; | |
| 652 inode->i_fop = &yaffs_file_operations; | |
| 653 inode->i_mapping->a_ops = &yaffs_file_address_operations; | |
| 654 break; | |
| 655 case S_IFDIR: // directory | |
| 656 inode->i_op = &yaffs_dir_inode_operations; | |
| 657 inode->i_fop = &yaffs_dir_operations; | |
| 658 break; | |
| 659 case S_IFLNK: // symlink | |
| 660 inode->i_op = &yaffs_symlink_inode_operations; | |
| 661 break; | |
| 662 } | |
| 663 | |
| 664 | |
| 665 inode->u.generic_ip = obj; | |
| 666 obj->myInode = inode; | |
| 667 | |
| 668 } | |
| 669 else | |
| 670 { | |
| 671 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_FileInode invalid parameters\n")); | |
| 672 } | |
| 673 | |
| 674 } | |
| 675 | |
| 676 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,yaffs_Object *obj) | |
| 677 { | |
| 678 struct inode * inode; | |
| 679 | |
| 680 if(!sb) | |
| 681 { | |
| 682 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_get_inode for NULL super_block!!\n")); | |
| 683 return NULL; | |
| 684 | |
| 685 } | |
| 686 | |
| 687 if(!obj) | |
| 688 { | |
| 689 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_get_inode for NULL object!!\n")); | |
| 690 return NULL; | |
| 691 | |
| 692 } | |
| 693 | |
| 694 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_get_inode for object %d\n",obj->objectId)); | |
| 695 | |
| 696 inode = iget(sb,obj->objectId); | |
| 697 | |
| 698 // NB Side effect: iget calls back to yaffs_read_inode(). | |
| 699 // iget also increments the inode's i_count | |
| 700 | |
| 701 return inode; | |
| 702 } | |
| 703 | |
| 704 #if 0 | |
| 705 | |
| 706 // No longer used because we use generic rw */ | |
| 707 static ssize_t yaffs_file_read(struct file *f, char *buf, size_t n, loff_t *pos) | |
| 708 { | |
| 709 yaffs_Object *obj; | |
| 710 int nRead,ipos; | |
| 711 struct inode *inode; | |
| 712 yaffs_Device *dev; | |
| 713 | |
| 714 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_read\n")); | |
| 715 | |
| 716 obj = yaffs_DentryToObject(f->f_dentry); | |
| 717 | |
| 718 dev = obj->myDev; | |
| 719 | |
| 720 yaffs_GrossLock(dev); | |
| 721 | |
| 722 inode = f->f_dentry->d_inode; | |
| 723 | |
| 724 if (*pos < inode->i_size) | |
| 725 { | |
| 726 if (*pos + n > inode->i_size) | |
| 727 { | |
| 728 n = inode->i_size - *pos; | |
| 729 } | |
| 730 } | |
| 731 else | |
| 732 { | |
| 733 n = 0; | |
| 734 } | |
| 735 | |
| 736 nRead = yaffs_ReadDataFromFile(obj,buf,*pos,n); | |
| 737 if(nRead > 0) | |
| 738 { | |
| 739 f->f_pos += nRead; | |
| 740 } | |
| 741 | |
| 742 yaffs_GrossUnlock(dev); | |
| 743 | |
| 744 ipos = *pos; | |
| 745 | |
| 746 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_read read %d bytes, %d read at %d\n",n,nRead,ipos)); | |
| 747 return nRead; | |
| 748 | |
| 749 } | |
| 750 | |
| 751 #endif | |
| 752 | |
| 753 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n, loff_t *pos) | |
| 754 { | |
| 755 yaffs_Object *obj; | |
| 756 int nWritten,ipos; | |
| 757 struct inode *inode; | |
| 758 yaffs_Device *dev; | |
| 759 | |
| 760 | |
| 761 obj = yaffs_DentryToObject(f->f_dentry); | |
| 762 | |
| 763 dev = obj->myDev; | |
| 764 | |
| 765 yaffs_GrossLock(dev); | |
| 766 | |
| 767 inode = f->f_dentry->d_inode; | |
| 768 | |
| 769 if(!S_ISBLK(inode->i_mode) && f->f_flags & O_APPEND) | |
| 770 { | |
| 771 ipos = inode->i_size; | |
| 772 } | |
| 773 else | |
| 774 { | |
| 775 ipos = *pos; | |
| 776 } | |
| 777 | |
| 778 | |
| 779 if(!obj) | |
| 780 { | |
| 781 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_write: hey obj is null!\n")); | |
| 782 } | |
| 783 else | |
| 784 { | |
| 785 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_write about to write writing %d bytes to object %d at %d\n",n,obj->objectId,ipos)); | |
| 786 } | |
| 787 | |
| 20 | 788 nWritten = yaffs_WriteDataToFile(obj,buf,ipos,n,0); |
| 7 | 789 |
| 790 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_write writing %d bytes, %d written at %d\n",n,nWritten,ipos)); | |
| 791 if(nWritten > 0) | |
| 792 { | |
| 793 ipos += nWritten; | |
| 794 *pos = ipos; | |
| 795 if(ipos > inode->i_size) | |
| 796 { | |
| 797 inode->i_size = ipos; | |
| 798 inode->i_blocks = (ipos + 511)>>9; | |
| 799 | |
| 800 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_write size updated to %d bytes, %d blocks\n",ipos,(int)(inode->i_blocks))); | |
| 801 } | |
| 802 | |
| 803 } | |
| 804 yaffs_GrossUnlock(dev); | |
| 805 | |
| 806 return nWritten != n ? -ENOSPC : nWritten; | |
| 807 } | |
| 808 | |
| 809 | |
| 810 | |
| 811 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir) | |
| 812 { | |
| 813 yaffs_Object *obj; | |
| 814 yaffs_Device *dev; | |
| 815 struct inode *inode = f->f_dentry->d_inode; | |
| 816 unsigned long offset, curoffs; | |
| 817 struct list_head *i; | |
| 818 yaffs_Object *l; | |
| 819 | |
| 820 char name[YAFFS_MAX_NAME_LENGTH +1]; | |
| 821 | |
| 822 obj = yaffs_DentryToObject(f->f_dentry); | |
| 823 dev = obj->myDev; | |
| 824 | |
| 825 yaffs_GrossLock(dev); | |
| 826 | |
| 827 offset = f->f_pos; | |
| 828 | |
| 829 T(YAFFS_TRACE_OS,("yaffs_readdir: starting at %d\n",(int)offset)); | |
| 830 | |
| 831 if(offset == 0) | |
| 832 { | |
| 833 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readdir: entry . ino %d \n",(int)inode->i_ino)); | |
| 834 if(filldir(dirent,".",1,offset,inode->i_ino,DT_DIR) < 0) | |
| 835 { | |
| 836 goto out; | |
| 837 } | |
| 838 offset++; | |
| 839 f->f_pos++; | |
| 840 } | |
| 841 if(offset == 1) | |
| 842 { | |
| 843 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readdir: entry .. ino %d \n",(int)f->f_dentry->d_parent->d_inode->i_ino)); | |
| 844 if(filldir(dirent,"..",2,offset,f->f_dentry->d_parent->d_inode->i_ino,DT_DIR) < 0) | |
| 845 { | |
| 846 goto out; | |
| 847 } | |
| 848 offset++; | |
| 849 f->f_pos++; | |
| 850 } | |
| 851 | |
| 852 curoffs = 1; | |
| 853 | |
| 854 list_for_each(i,&obj->variant.directoryVariant.children) | |
| 855 { | |
| 856 curoffs++; | |
| 857 if(curoffs >= offset) | |
| 858 { | |
| 859 l = list_entry(i, yaffs_Object,siblings); | |
| 860 | |
| 861 yaffs_GetObjectName(l,name,YAFFS_MAX_NAME_LENGTH+1); | |
| 862 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readdir: %s inode %d\n",name,yaffs_GetObjectInode(l))); | |
| 863 | |
| 864 if(filldir(dirent, | |
| 865 name, | |
| 866 strlen(name), | |
| 867 offset, | |
| 868 yaffs_GetObjectInode(l), | |
| 869 yaffs_GetObjectType(l)) | |
| 870 < 0) | |
| 871 { | |
| 872 goto up_and_out; | |
| 873 } | |
| 874 | |
| 875 offset++; | |
| 876 f->f_pos++; | |
| 877 } | |
| 878 } | |
| 879 | |
| 880 up_and_out: | |
| 881 out: | |
| 882 | |
| 883 yaffs_GrossUnlock(dev); | |
| 884 | |
| 885 return 0; | |
| 886 } | |
| 887 | |
| 888 | |
| 889 /* | |
| 890 * File creation. Allocate an inode, and we're done.. | |
| 891 */ | |
| 892 //#if defined(CONFIG_KERNEL_2_5) | |
| 893 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) | |
| 894 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev) | |
| 895 #else | |
| 896 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, int rdev) | |
| 897 #endif | |
| 898 { | |
| 899 struct inode *inode; | |
| 900 | |
| 901 yaffs_Object *obj = NULL; | |
| 902 yaffs_Device *dev; | |
| 903 | |
| 904 yaffs_Object *parent = yaffs_InodeToObject(dir); | |
| 905 | |
| 906 int error = -ENOSPC; | |
|
38
14315c63b7a5
Set the correct uid/gid of newly created files when: use fsuid & fsgid and take care when the SGID bit is set on the parent directory.
luc
parents:
34
diff
changeset
|
907 uid_t uid = current->fsuid; |
|
14315c63b7a5
Set the correct uid/gid of newly created files when: use fsuid & fsgid and take care when the SGID bit is set on the parent directory.
luc
parents:
34
diff
changeset
|
908 gid_t gid = (dir->i_mode & S_ISGID) ? dir->i_gid : current->fsgid; |
| 7 | 909 |
| 910 if(parent) | |
| 911 { | |
| 912 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: parent object %d type %d\n", | |
| 913 parent->objectId,parent->variantType)); | |
| 914 } | |
| 915 else | |
| 916 { | |
| 917 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: could not get parent object\n")); | |
| 918 return -EPERM; | |
| 919 } | |
| 920 | |
| 921 T(YAFFS_TRACE_OS,("yaffs_mknod: making oject for %s, mode %x dev %x\n", | |
| 922 dentry->d_name.name, mode,rdev)); | |
| 923 | |
| 924 dev = parent->myDev; | |
| 925 | |
| 926 yaffs_GrossLock(dev); | |
| 927 | |
| 928 switch (mode & S_IFMT) | |
| 929 { | |
| 930 default: | |
| 931 // Special (socket, fifo, device...) | |
| 932 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: making special\n")); | |
| 13 | 933 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) |
|
38
14315c63b7a5
Set the correct uid/gid of newly created files when: use fsuid & fsgid and take care when the SGID bit is set on the parent directory.
luc
parents:
34
diff
changeset
|
934 obj = yaffs_MknodSpecial(parent,dentry->d_name.name,mode,uid, gid,old_encode_dev(rdev)); |
| 13 | 935 #else |
|
38
14315c63b7a5
Set the correct uid/gid of newly created files when: use fsuid & fsgid and take care when the SGID bit is set on the parent directory.
luc
parents:
34
diff
changeset
|
936 obj = yaffs_MknodSpecial(parent,dentry->d_name.name,mode,uid, gid,rdev); |
| 25 | 937 #endif |
| 938 break; | |
| 7 | 939 case S_IFREG: // file |
| 940 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: making file\n")); | |
|
38
14315c63b7a5
Set the correct uid/gid of newly created files when: use fsuid & fsgid and take care when the SGID bit is set on the parent directory.
luc
parents:
34
diff
changeset
|
941 obj = yaffs_MknodFile(parent,dentry->d_name.name,mode,uid, gid); |
| 7 | 942 break; |
| 943 case S_IFDIR: // directory | |
| 944 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: making directory\n")); | |
|
38
14315c63b7a5
Set the correct uid/gid of newly created files when: use fsuid & fsgid and take care when the SGID bit is set on the parent directory.
luc
parents:
34
diff
changeset
|
945 obj = yaffs_MknodDirectory(parent,dentry->d_name.name,mode,uid, gid); |
| 7 | 946 break; |
| 947 case S_IFLNK: // symlink | |
| 948 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: making file\n")); | |
| 949 obj = NULL; // Do we ever get here? | |
| 950 break; | |
| 951 } | |
| 952 | |
| 953 if(obj) | |
| 954 { | |
| 955 inode = yaffs_get_inode(dir->i_sb, mode, rdev, obj); | |
| 956 d_instantiate(dentry, inode); | |
| 957 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod created object %d count = %d\n",obj->objectId,atomic_read(&inode->i_count))); | |
| 958 error = 0; | |
| 959 } | |
| 960 else | |
| 961 { | |
| 962 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod failed making object\n")); | |
| 963 error = -ENOMEM; | |
| 964 } | |
| 965 | |
| 966 yaffs_GrossUnlock(dev); | |
| 967 | |
| 968 return error; | |
| 969 } | |
| 970 | |
| 971 static int yaffs_mkdir(struct inode * dir, struct dentry * dentry, int mode) | |
| 972 { | |
| 973 int retVal; | |
| 974 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mkdir\n")); | |
| 975 retVal = yaffs_mknod(dir, dentry, mode | S_IFDIR, 0); | |
| 976 #if 0 | |
| 977 // attempt to fix dir bug - didn't work | |
| 978 if(!retVal) | |
| 979 { | |
| 980 dget(dentry); | |
| 981 } | |
| 982 #endif | |
| 983 return retVal; | |
| 984 } | |
| 985 | |
| 986 //#if defined(CONFIG_KERNEL_2_5) /* Added NCB 185-8-2003 */ | |
| 987 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) | |
| 988 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *n) | |
| 989 #else | |
| 990 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode) | |
| 991 #endif | |
| 992 { | |
| 993 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_create\n")); | |
| 994 return yaffs_mknod(dir, dentry, mode | S_IFREG, 0); | |
| 995 } | |
| 996 | |
| 997 | |
| 998 static int yaffs_unlink(struct inode * dir, struct dentry *dentry) | |
| 999 { | |
| 1000 int retVal; | |
| 1001 | |
| 1002 yaffs_Device *dev; | |
| 1003 | |
| 1004 | |
| 1005 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_unlink %d:%s\n",(int)(dir->i_ino),dentry->d_name.name)); | |
| 1006 | |
| 1007 dev = yaffs_InodeToObject(dir)->myDev; | |
| 1008 | |
| 1009 yaffs_GrossLock(dev); | |
| 1010 | |
| 1011 | |
| 1012 retVal = yaffs_Unlink(yaffs_InodeToObject(dir),dentry->d_name.name); | |
| 1013 | |
| 1014 | |
| 1015 yaffs_GrossUnlock(dev); | |
| 1016 | |
| 1017 if( retVal == YAFFS_OK) | |
| 1018 { | |
| 1019 dentry->d_inode->i_nlink--; | |
| 1020 mark_inode_dirty(dentry->d_inode); | |
| 1021 return 0; | |
| 1022 } | |
| 1023 else | |
| 1024 { | |
| 1025 return -ENOTEMPTY; | |
| 1026 } | |
| 1027 } | |
| 1028 | |
| 1029 | |
| 1030 /* | |
| 1031 * Create a link... | |
| 1032 */ | |
| 1033 static int yaffs_link(struct dentry *old_dentry, struct inode * dir, struct dentry * dentry) | |
| 1034 { | |
| 1035 struct inode *inode = old_dentry->d_inode; | |
| 1036 yaffs_Object *obj = NULL; | |
| 1037 yaffs_Object *link=NULL; | |
| 1038 yaffs_Device *dev; | |
| 1039 | |
| 1040 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_link\n")); | |
| 1041 | |
| 1042 obj = yaffs_InodeToObject(inode); | |
| 1043 dev = obj->myDev; | |
| 1044 | |
| 1045 yaffs_GrossLock(dev); | |
| 1046 | |
| 1047 if (!S_ISDIR(inode->i_mode)) // Don't link directories | |
| 1048 { | |
| 1049 link = yaffs_Link(yaffs_InodeToObject(dir),dentry->d_name.name,obj); | |
| 1050 } | |
| 1051 | |
| 1052 | |
| 1053 if(link) | |
| 1054 { | |
| 1055 old_dentry->d_inode->i_nlink = yaffs_GetObjectLinkCount(obj); | |
| 1056 d_instantiate(dentry, old_dentry->d_inode); | |
| 1057 atomic_inc(&old_dentry->d_inode->i_count); | |
| 1058 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_link link count %d i_count %d\n", | |
| 1059 old_dentry->d_inode->i_nlink,atomic_read(&old_dentry->d_inode->i_count))); | |
| 1060 | |
| 1061 } | |
| 1062 | |
| 1063 yaffs_GrossUnlock(dev); | |
| 1064 | |
| 1065 | |
| 1066 if(link) | |
| 1067 { | |
| 1068 | |
| 1069 return 0; | |
| 1070 } | |
| 1071 | |
| 1072 | |
| 1073 return -EPERM; | |
| 1074 } | |
| 1075 | |
| 1076 | |
| 1077 static int yaffs_symlink(struct inode * dir, struct dentry *dentry, const char * symname) | |
| 1078 { | |
| 1079 yaffs_Object *obj; | |
| 1080 yaffs_Device *dev; | |
|
38
14315c63b7a5
Set the correct uid/gid of newly created files when: use fsuid & fsgid and take care when the SGID bit is set on the parent directory.
luc
parents:
34
diff
changeset
|
1081 uid_t uid = current->fsuid; |
|
14315c63b7a5
Set the correct uid/gid of newly created files when: use fsuid & fsgid and take care when the SGID bit is set on the parent directory.
luc
parents:
34
diff
changeset
|
1082 gid_t gid = (dir->i_mode & S_ISGID) ? dir->i_gid : current->fsgid; |
| 7 | 1083 |
| 1084 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_symlink\n")); | |
| 1085 | |
| 1086 dev = yaffs_InodeToObject(dir)->myDev; | |
| 1087 yaffs_GrossLock(dev); | |
| 1088 obj = yaffs_MknodSymLink(yaffs_InodeToObject(dir), dentry->d_name.name, | |
|
38
14315c63b7a5
Set the correct uid/gid of newly created files when: use fsuid & fsgid and take care when the SGID bit is set on the parent directory.
luc
parents:
34
diff
changeset
|
1089 S_IFLNK | S_IRWXUGO, uid, gid, |
| 7 | 1090 symname); |
| 1091 yaffs_GrossUnlock(dev); | |
| 1092 | |
| 1093 if(obj) | |
| 1094 { | |
| 1095 | |
| 1096 struct inode* inode; | |
| 1097 | |
|
24
4ebabd859f38
Some improvements to garbage collection and st_xxx to yst_xxx changes
charles
parents:
21
diff
changeset
|
1098 inode = yaffs_get_inode(dir->i_sb, obj->yst_mode, 0, obj); |
| 7 | 1099 d_instantiate(dentry, inode); |
| 1100 T(YAFFS_TRACE_OS,(KERN_DEBUG"symlink created OK\n")); | |
| 1101 return 0; | |
| 1102 } | |
| 1103 else | |
| 1104 { | |
| 1105 T(YAFFS_TRACE_OS,(KERN_DEBUG"symlink not created\n")); | |
| 1106 | |
| 1107 } | |
| 1108 | |
| 1109 return -ENOMEM; | |
| 1110 } | |
| 1111 | |
| 1112 static int yaffs_sync_object(struct file * file, struct dentry *dentry, int datasync) | |
| 1113 { | |
| 1114 | |
| 1115 yaffs_Object *obj; | |
| 1116 yaffs_Device *dev; | |
| 1117 | |
| 1118 obj = yaffs_DentryToObject(dentry); | |
| 1119 | |
| 1120 dev = obj->myDev; | |
| 1121 | |
| 1122 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_sync_object\n")); | |
| 1123 yaffs_GrossLock(dev); | |
| 1124 yaffs_FlushFile(obj,1); | |
| 1125 yaffs_GrossUnlock(dev); | |
| 1126 return 0; | |
| 1127 } | |
| 1128 | |
| 1129 /* | |
| 1130 * The VFS layer already does all the dentry stuff for rename. | |
| 1131 * | |
| 1132 * NB: POSIX says you can rename an object over an old object of the same name | |
| 1133 */ | |
| 1134 static int yaffs_rename(struct inode * old_dir, struct dentry *old_dentry, struct inode * new_dir,struct dentry *new_dentry) | |
| 1135 { | |
| 1136 yaffs_Device *dev; | |
| 1137 int retVal = YAFFS_FAIL; | |
| 1138 int removed = 0; | |
| 1139 yaffs_Object *target; | |
| 1140 | |
| 1141 dev = yaffs_InodeToObject(old_dir)->myDev; | |
| 1142 | |
| 1143 yaffs_GrossLock(dev); | |
| 1144 | |
| 1145 // Check if the target is an existing directory that is not empty. | |
| 1146 target = yaffs_FindObjectByName(yaffs_InodeToObject(new_dir),new_dentry->d_name.name); | |
| 1147 | |
| 1148 if(target && | |
| 1149 target->variantType == YAFFS_OBJECT_TYPE_DIRECTORY && | |
| 1150 !list_empty(&target->variant.directoryVariant.children)) | |
| 1151 { | |
| 1152 retVal = YAFFS_FAIL; | |
| 1153 } | |
| 1154 else | |
| 1155 { | |
| 1156 | |
| 1157 // Unlink the target if it exists | |
| 1158 removed = yaffs_Unlink(yaffs_InodeToObject(new_dir),new_dentry->d_name.name); | |
| 1159 | |
| 1160 | |
| 1161 retVal = yaffs_RenameObject(yaffs_InodeToObject(old_dir),old_dentry->d_name.name, | |
| 1162 yaffs_InodeToObject(new_dir),new_dentry->d_name.name); | |
| 1163 | |
| 1164 } | |
| 1165 yaffs_GrossUnlock(dev); | |
| 1166 | |
| 1167 if(retVal == YAFFS_OK) | |
| 1168 { | |
| 1169 if(removed == YAFFS_OK) | |
| 1170 { | |
| 1171 new_dentry->d_inode->i_nlink--; | |
| 1172 mark_inode_dirty(new_dentry->d_inode); | |
| 1173 } | |
| 1174 | |
| 1175 return 0; | |
| 1176 } | |
| 1177 else | |
| 1178 { | |
| 1179 return -ENOTEMPTY; | |
| 1180 } | |
| 1181 | |
| 1182 | |
| 1183 } | |
| 1184 | |
| 1185 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr) | |
| 1186 { | |
| 1187 struct inode *inode = dentry->d_inode; | |
| 1188 int error; | |
| 1189 yaffs_Device *dev; | |
| 1190 | |
| 1191 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_setattr of object %d\n",yaffs_InodeToObject(inode)->objectId)); | |
| 1192 | |
| 1193 if((error = inode_change_ok(inode,attr)) == 0) | |
| 1194 { | |
| 1195 | |
| 1196 dev = yaffs_InodeToObject(inode)->myDev; | |
| 1197 yaffs_GrossLock(dev); | |
| 1198 if(yaffs_SetAttributes(yaffs_InodeToObject(inode),attr) == YAFFS_OK) | |
| 1199 { | |
| 1200 error = 0; | |
| 1201 } | |
| 1202 else | |
| 1203 { | |
| 1204 error = -EPERM; | |
| 1205 } | |
| 1206 yaffs_GrossUnlock(dev); | |
| 25 | 1207 if (!error) |
| 1208 error = inode_setattr(inode,attr); | |
| 7 | 1209 } |
| 1210 return error; | |
| 1211 } | |
| 1212 | |
| 1213 //#if defined(CONFIG_KERNEL_2_5) /* Added NCB 185-8-2003 */ | |
| 1214 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) | |
| 1215 static int yaffs_statfs(struct super_block *sb, struct kstatfs *buf) | |
| 1216 #else | |
| 1217 static int yaffs_statfs(struct super_block *sb, struct statfs *buf) | |
| 1218 #endif | |
| 1219 { | |
| 16 | 1220 |
| 1221 | |
| 7 | 1222 yaffs_Device *dev = yaffs_SuperToDevice(sb); |
| 1223 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_statfs\n")); | |
| 1224 | |
| 1225 yaffs_GrossLock(dev); | |
| 1226 | |
| 16 | 1227 |
| 7 | 1228 buf->f_type = YAFFS_MAGIC; |
| 1229 buf->f_bsize = sb->s_blocksize; | |
| 1230 buf->f_namelen = 255; | |
| 16 | 1231 if(sb->s_blocksize > dev->nBytesPerChunk) |
| 1232 { | |
| 1233 | |
| 1234 buf->f_blocks = (dev->endBlock - dev->startBlock + 1) * dev->nChunksPerBlock/ | |
| 1235 (sb->s_blocksize/dev->nBytesPerChunk); | |
| 1236 buf->f_bfree = yaffs_GetNumberOfFreeChunks(dev)/ | |
| 1237 (sb->s_blocksize/dev->nBytesPerChunk); | |
| 1238 } | |
| 1239 else | |
| 1240 { | |
| 1241 | |
| 1242 buf->f_blocks = (dev->endBlock - dev->startBlock + 1) * dev->nChunksPerBlock * | |
| 1243 (dev->nBytesPerChunk/sb->s_blocksize); | |
| 1244 buf->f_bfree = yaffs_GetNumberOfFreeChunks(dev) * | |
| 1245 (dev->nBytesPerChunk/sb->s_blocksize); | |
| 1246 } | |
| 7 | 1247 buf->f_files = 0; |
| 1248 buf->f_ffree = 0; | |
| 1249 buf->f_bavail = buf->f_bfree; | |
| 1250 | |
| 1251 yaffs_GrossUnlock(dev); | |
| 1252 return 0; | |
| 1253 } | |
| 1254 | |
| 1255 static void yaffs_read_inode (struct inode *inode) | |
| 1256 { | |
| 1257 // NB This is called as a side effect of other functions and | |
| 1258 // thus gross locking should always be in place already. | |
| 1259 | |
| 1260 yaffs_Object *obj ; | |
| 1261 yaffs_Device *dev = yaffs_SuperToDevice(inode->i_sb); | |
| 1262 | |
| 1263 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_read_inode for %d\n",(int)inode->i_ino)); | |
| 1264 | |
| 1265 obj = yaffs_FindObjectByNumber(dev,inode->i_ino); | |
| 1266 | |
| 1267 yaffs_FillInodeFromObject(inode,obj); | |
| 1268 | |
| 1269 } | |
| 1270 | |
| 29 | 1271 static LIST_HEAD(yaffs_dev_list); |
| 7 | 1272 |
| 1273 static void yaffs_put_super(struct super_block *sb) | |
| 1274 { | |
| 1275 yaffs_Device *dev = yaffs_SuperToDevice(sb); | |
| 1276 | |
| 1277 yaffs_GrossLock(dev); | |
| 1278 if(dev->putSuperFunc) | |
| 1279 { | |
| 1280 dev->putSuperFunc(sb); | |
| 1281 } | |
| 1282 yaffs_Deinitialise(dev); | |
| 1283 yaffs_GrossUnlock(dev); | |
| 1284 | |
| 29 | 1285 /* we assume this is protected by lock_kernel() in mount/umount */ |
| 1286 list_del(&dev->devList); | |
| 1287 | |
| 7 | 1288 kfree(dev); |
| 1289 } | |
| 1290 | |
| 1291 | |
| 1292 #ifdef CONFIG_YAFFS_MTD_ENABLED | |
| 1293 | |
| 1294 static void yaffs_MTDPutSuper(struct super_block *sb) | |
| 1295 { | |
| 1296 | |
| 1297 struct mtd_info *mtd = yaffs_SuperToDevice(sb)->genericDevice; | |
| 1298 | |
| 1299 if(mtd->sync) | |
| 1300 { | |
| 1301 mtd->sync(mtd); | |
| 1302 } | |
| 1303 | |
| 1304 put_mtd_device(mtd); | |
| 1305 } | |
| 1306 | |
| 1307 #endif | |
| 1308 | |
| 1309 | |
| 1310 static struct super_block *yaffs_internal_read_super(int yaffsVersion,int useRam, struct super_block * sb, void * data, int silent) | |
| 1311 { | |
| 1312 int nBlocks; | |
| 1313 struct inode * inode = NULL; | |
| 1314 struct dentry * root; | |
| 29 | 1315 yaffs_Device *dev = 0; |
| 7 | 1316 int err; |
| 1317 | |
| 1318 sb->s_magic = YAFFS_MAGIC; | |
| 1319 sb->s_op = &yaffs_super_ops; | |
| 1320 | |
| 1321 if(!sb) | |
| 1322 printk(KERN_INFO"yaffs: sb is NULL\n"); | |
| 1323 else if(!sb->s_dev) | |
| 1324 printk(KERN_INFO"yaffs: sb->s_dev is NULL\n"); | |
| 1325 else if(! kdevname(sb->s_dev)) | |
| 1326 printk(KERN_INFO"yaffs: kdevname is NULL\n"); | |
| 1327 else | |
| 1328 printk(KERN_INFO"yaffs: dev is %d name is \"%s\"\n", sb->s_dev, kdevname(sb->s_dev)); | |
| 1329 | |
| 1330 | |
| 1331 | |
| 1332 #ifdef CONFIG_YAFFS_USE_CHUNK_SIZE | |
| 1333 sb->s_blocksize = YAFFS_BYTES_PER_CHUNK; | |
| 1334 sb->s_blocksize_bits = YAFFS_CHUNK_SIZE_SHIFT; | |
| 1335 #else | |
| 1336 sb->s_blocksize = PAGE_CACHE_SIZE; | |
| 1337 sb->s_blocksize_bits = PAGE_CACHE_SHIFT; | |
| 1338 #endif | |
| 1339 T(YAFFS_TRACE_OS,("yaffs_read_super: Using yaffs%d\n",yaffsVersion)); | |
| 1340 T(YAFFS_TRACE_OS,("yaffs_read_super: %s block size %d\n", useRam ? "RAM" : "MTD",(int)(sb->s_blocksize))); | |
| 1341 | |
| 1342 #ifdef CONFIG_YAFFS_DISABLE_WRITE_VERIFY | |
| 1343 T(YAFFS_TRACE_OS,("yaffs: Write verification disabled. All guarantees null and void\n")); | |
| 1344 #endif | |
| 1345 | |
| 1346 | |
| 1347 | |
| 1348 if(useRam) | |
| 1349 { | |
| 1350 | |
| 1351 #ifdef CONFIG_YAFFS_RAM_ENABLED | |
| 1352 // Set the yaffs_Device up for ram emulation | |
| 1353 | |
|
24
4ebabd859f38
Some improvements to garbage collection and st_xxx to yst_xxx changes
charles
parents:
21
diff
changeset
|
1354 |
|
4ebabd859f38
Some improvements to garbage collection and st_xxx to yst_xxx changes
charles
parents:
21
diff
changeset
|
1355 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) |
|
4ebabd859f38
Some improvements to garbage collection and st_xxx to yst_xxx changes
charles
parents:
21
diff
changeset
|
1356 sb->s_fs_info = dev = kmalloc(sizeof(yaffs_Device),GFP_KERNEL); |
|
4ebabd859f38
Some improvements to garbage collection and st_xxx to yst_xxx changes
charles
parents:
21
diff
changeset
|
1357 #else |
| 7 | 1358 sb->u.generic_sbp = dev = kmalloc(sizeof(yaffs_Device),GFP_KERNEL); |
|
24
4ebabd859f38
Some improvements to garbage collection and st_xxx to yst_xxx changes
charles
parents:
21
diff
changeset
|
1359 #endif |
|
4ebabd859f38
Some improvements to garbage collection and st_xxx to yst_xxx changes
charles
parents:
21
diff
changeset
|
1360 |
| 7 | 1361 if(!dev) |
| 1362 { | |
| 1363 // Deep shit could not allocate device structure | |
| 1364 T(YAFFS_TRACE_OS,("yaffs_read_super: Failed trying to allocate yaffs_Device.\n")); | |
| 1365 return NULL; | |
| 1366 } | |
| 1367 | |
| 1368 memset(dev,0,sizeof(yaffs_Device)); | |
| 1369 dev->genericDevice = NULL; // Not used for RAM emulation. | |
| 29 | 1370 dev->name = sb->s_type->name; |
| 7 | 1371 |
| 1372 nBlocks = YAFFS_RAM_EMULATION_SIZE / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK); | |
| 21 | 1373 dev->startBlock = 0; |
| 7 | 1374 dev->endBlock = nBlocks - 1; |
| 1375 dev->nChunksPerBlock = YAFFS_CHUNKS_PER_BLOCK; | |
| 1376 dev->nBytesPerChunk = YAFFS_BYTES_PER_CHUNK; | |
| 1377 dev->nReservedBlocks = 5; | |
| 1378 | |
| 1379 if(yaffsVersion == 2) | |
| 1380 { | |
| 1381 dev->writeChunkWithTagsToNAND = nandemul2k_WriteChunkWithTagsToNAND; | |
| 1382 dev->readChunkWithTagsFromNAND = nandemul2k_ReadChunkWithTagsFromNAND; | |
| 1383 dev->markNANDBlockBad = nandemul2k_MarkNANDBlockBad; | |
| 1384 dev->queryNANDBlock = nandemul2k_QueryNANDBlock; | |
| 1385 dev->eraseBlockInNAND = nandemul2k_EraseBlockInNAND; | |
| 1386 dev->initialiseNAND = nandemul2k_InitialiseNAND; | |
| 1387 dev->isYaffs2 = 1; | |
| 1388 dev->nChunksPerBlock = nandemul2k_GetChunksPerBlock(); | |
| 1389 dev->nBytesPerChunk = nandemul2k_GetBytesPerChunk();; | |
| 1390 nBlocks = nandemul2k_GetNumberOfBlocks(); | |
| 21 | 1391 dev->startBlock = 0; |
| 7 | 1392 dev->endBlock = nBlocks - 1; |
| 1393 } | |
| 1394 else | |
| 1395 { | |
| 1396 dev->writeChunkToNAND = nandemul_WriteChunkToNAND; | |
| 1397 dev->readChunkFromNAND = nandemul_ReadChunkFromNAND; | |
| 1398 dev->eraseBlockInNAND = nandemul_EraseBlockInNAND; | |
| 1399 dev->initialiseNAND = nandemul_InitialiseNAND; | |
| 1400 dev->isYaffs2 = 0; | |
| 1401 } | |
| 1402 #endif | |
| 1403 | |
| 1404 } | |
| 1405 else | |
| 1406 { | |
| 1407 #ifdef CONFIG_YAFFS_MTD_ENABLED | |
| 1408 struct mtd_info *mtd; | |
| 1409 | |
| 1410 T(YAFFS_TRACE_ALWAYS,("yaffs: Attempting MTD mount on %u.%u, \"%s\"\n", | |
| 1411 MAJOR(sb->s_dev),MINOR(sb->s_dev),kdevname(sb->s_dev))); | |
| 1412 | |
| 1413 // Check it's an mtd device..... | |
| 1414 if(MAJOR(sb->s_dev) != MTD_BLOCK_MAJOR) | |
| 1415 { | |
| 1416 return NULL; // This isn't an mtd device | |
| 1417 } | |
| 1418 | |
| 1419 // Get the device | |
| 1420 mtd = get_mtd_device(NULL, MINOR(sb->s_dev)); | |
| 1421 if (!mtd) | |
| 1422 { | |
| 1423 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device #%u doesn't appear to exist\n", MINOR(sb->s_dev))); | |
| 1424 return NULL; | |
| 1425 } | |
| 1426 | |
| 1427 // Check it's NAND | |
| 1428 if(mtd->type != MTD_NANDFLASH) | |
| 1429 { | |
| 1430 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device is not NAND it's type %d\n", mtd->type)); | |
| 1431 return NULL; | |
| 1432 } | |
| 1433 | |
| 25 | 1434 T(YAFFS_TRACE_OS,(" erase %p\n",mtd->erase)); |
| 1435 T(YAFFS_TRACE_OS,(" read %p\n",mtd->read)); | |
| 1436 T(YAFFS_TRACE_OS,(" write %p\n",mtd->write)); | |
| 1437 T(YAFFS_TRACE_OS,(" readoob %p\n",mtd->read_oob)); | |
| 1438 T(YAFFS_TRACE_OS,(" writeoob %p\n",mtd->write_oob)); | |
| 1439 T(YAFFS_TRACE_OS,(" block_isbad %p\n",mtd->block_isbad)); | |
| 1440 T(YAFFS_TRACE_OS,(" block_markbad %p\n",mtd->block_markbad)); | |
| 7 | 1441 T(YAFFS_TRACE_OS,(" oobblock %d\n",mtd->oobblock)); |
| 1442 T(YAFFS_TRACE_OS,(" oobsize %d\n",mtd->oobsize)); | |
| 1443 T(YAFFS_TRACE_OS,(" erasesize %d\n",mtd->erasesize)); | |
| 1444 T(YAFFS_TRACE_OS,(" size %d\n",mtd->size)); | |
| 1445 | |
| 1446 if(yaffsVersion == 2) | |
| 1447 { | |
| 1448 // Check for version 2 style functions | |
| 1449 if(!mtd->erase || | |
| 1450 !mtd->block_isbad || | |
| 1451 !mtd->block_markbad || | |
| 1452 !mtd->read || | |
| 1453 !mtd->write || | |
| 1454 #ifndef CONFIG_YAFFS_USE_OLD_MTD | |
| 1455 !mtd->write_ecc || | |
| 1456 !mtd->read_ecc || | |
| 1457 #endif | |
| 1458 !mtd->read_oob || | |
| 1459 !mtd->write_oob ) | |
| 1460 { | |
| 1461 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device does not support required functions\n"));; | |
| 1462 return NULL; | |
| 1463 } | |
| 1464 | |
| 1465 if(mtd->oobblock < YAFFS_MIN_YAFFS2_CHUNK_SIZE || | |
| 1466 mtd->oobsize < YAFFS_MIN_YAFFS2_SPARE_SIZE) | |
| 1467 { | |
| 1468 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device does not support have the right page sizes\n")); | |
| 1469 return NULL; | |
| 1470 } } | |
| 1471 else | |
| 1472 { | |
| 1473 // Check for V1 style functions | |
| 1474 if(!mtd->erase || | |
| 1475 !mtd->read || | |
| 1476 !mtd->write || | |
| 1477 #ifndef CONFIG_YAFFS_USE_OLD_MTD | |
| 1478 !mtd->write_ecc || | |
| 1479 !mtd->read_ecc || | |
| 1480 #endif | |
| 1481 !mtd->read_oob || | |
| 1482 !mtd->write_oob ) | |
| 1483 { | |
| 1484 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device does not support required functions\n"));; | |
| 1485 return NULL; | |
| 1486 } | |
| 1487 | |
| 1488 if(mtd->oobblock != YAFFS_BYTES_PER_CHUNK || | |
| 1489 mtd->oobsize != YAFFS_BYTES_PER_SPARE) | |
| 1490 { | |
| 1491 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device does not support have the right page sizes\n")); | |
| 1492 return NULL; | |
| 1493 } | |
| 1494 } | |
| 1495 | |
| 1496 | |
| 1497 // OK, so if we got here, we have an MTD that's NAND and looks | |
| 1498 // like it has the right capabilities | |
| 1499 // Set the yaffs_Device up for mtd | |
| 1500 | |
| 1501 //#if defined(CONFIG_KERNEL_2_5) | |
| 1502 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) | |
| 1503 sb->s_fs_info = dev = kmalloc(sizeof(yaffs_Device),GFP_KERNEL); | |
| 1504 #else | |
| 1505 sb->u.generic_sbp = dev = kmalloc(sizeof(yaffs_Device),GFP_KERNEL); | |
| 1506 #endif | |
| 1507 if(!dev) | |
| 1508 { | |
| 1509 // Deep shit could not allocate device structure | |
| 1510 T(YAFFS_TRACE_ALWAYS,("yaffs_read_super: Failed trying to allocate yaffs_Device. \n")); | |
| 1511 return NULL; | |
| 1512 } | |
| 1513 | |
| 1514 memset(dev,0,sizeof(yaffs_Device)); | |
| 1515 dev->genericDevice = mtd; | |
| 29 | 1516 dev->name = mtd->name; |
| 7 | 1517 |
| 1518 // Set up the memory size parameters.... | |
| 1519 | |
| 1520 nBlocks = mtd->size / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK); | |
| 21 | 1521 dev->startBlock = 0; |
| 7 | 1522 dev->endBlock = nBlocks - 1; |
| 1523 dev->nChunksPerBlock = YAFFS_CHUNKS_PER_BLOCK; | |
| 1524 dev->nBytesPerChunk = YAFFS_BYTES_PER_CHUNK; | |
| 1525 dev->nReservedBlocks = 5; | |
| 1526 dev->nShortOpCaches = 10; // Enable short op caching | |
| 1527 | |
| 1528 | |
| 1529 // ... and the functions. | |
| 1530 if(yaffsVersion == 2) | |
| 1531 { | |
| 1532 dev->writeChunkWithTagsToNAND = nandmtd2_WriteChunkWithTagsToNAND; | |
| 1533 dev->readChunkWithTagsFromNAND = nandmtd2_ReadChunkWithTagsFromNAND; | |
| 1534 dev->markNANDBlockBad = nandmtd2_MarkNANDBlockBad; | |
| 1535 dev->queryNANDBlock = nandmtd2_QueryNANDBlock; | |
| 1536 dev->spareBuffer = YMALLOC(mtd->oobsize); | |
| 1537 dev->isYaffs2 = 1; | |
| 1538 dev->nBytesPerChunk = mtd->oobblock; | |
| 1539 dev->nChunksPerBlock = mtd->erasesize / mtd->oobblock; | |
| 1540 nBlocks = mtd->size / mtd->erasesize; | |
| 21 | 1541 dev->startBlock = 0; |
| 7 | 1542 dev->endBlock = nBlocks - 1; |
| 1543 } | |
| 1544 else | |
| 1545 { | |
| 1546 dev->writeChunkToNAND = nandmtd_WriteChunkToNAND; | |
| 1547 dev->readChunkFromNAND = nandmtd_ReadChunkFromNAND; | |
| 1548 dev->isYaffs2 = 0; | |
| 1549 } | |
| 1550 // ... and common functions | |
| 1551 dev->eraseBlockInNAND = nandmtd_EraseBlockInNAND; | |
| 1552 dev->initialiseNAND = nandmtd_InitialiseNAND; | |
| 1553 | |
| 1554 dev->putSuperFunc = yaffs_MTDPutSuper; | |
| 1555 | |
| 1556 #ifdef CONFIG_YAFFS_USE_NANDECC | |
| 1557 dev->useNANDECC = 1; | |
| 1558 #endif | |
| 1559 #endif | |
| 1560 } | |
| 1561 | |
| 29 | 1562 /* we assume this is protected by lock_kernel() in mount/umount */ |
| 1563 list_add_tail(&dev->devList, &yaffs_dev_list); | |
| 1564 | |
| 7 | 1565 init_MUTEX(&dev->grossLock); |
| 1566 | |
| 1567 | |
| 1568 yaffs_GrossLock(dev); | |
| 1569 | |
| 1570 err = yaffs_GutsInitialise(dev); | |
| 1571 | |
| 1572 T(YAFFS_TRACE_OS,("yaffs_read_super: guts initialised %s\n", (err == YAFFS_OK) ? "OK" : "FAILED")); | |
| 1573 | |
| 1574 // Create root inode | |
| 1575 if(err == YAFFS_OK) | |
| 1576 inode = yaffs_get_inode(sb, S_IFDIR | 0755, 0,yaffs_Root(dev)); | |
| 1577 | |
| 1578 yaffs_GrossUnlock(dev); | |
| 1579 | |
| 1580 if (!inode) | |
| 1581 return NULL; | |
| 1582 | |
| 1583 // added NCB | |
| 1584 inode->i_op = & yaffs_dir_inode_operations; | |
| 1585 inode->i_fop = & yaffs_dir_operations; | |
| 1586 | |
| 1587 T(YAFFS_TRACE_OS,("yaffs_read_super: got root inode\n")); | |
| 1588 | |
| 1589 | |
| 1590 root = d_alloc_root(inode); | |
| 1591 | |
| 1592 T(YAFFS_TRACE_OS,("yaffs_read_super: d_alloc_root done\n")); | |
| 1593 | |
| 1594 if (!root) { | |
| 1595 iput(inode); | |
| 1596 return NULL; | |
| 1597 } | |
| 1598 sb->s_root = root; | |
| 1599 | |
| 1600 T(YAFFS_TRACE_OS,("yaffs_read_super: done\n")); | |
| 1601 return sb; | |
| 1602 } | |
| 1603 | |
| 1604 | |
|
34
95f802b86a29
Move the internals read_super() functions near the declaration of
luc
parents:
31
diff
changeset
|
1605 |
|
95f802b86a29
Move the internals read_super() functions near the declaration of
luc
parents:
31
diff
changeset
|
1606 #ifdef CONFIG_YAFFS_MTD_ENABLED |
|
95f802b86a29
Move the internals read_super() functions near the declaration of
luc
parents:
31
diff
changeset
|
1607 |
|
95f802b86a29
Move the internals read_super() functions near the declaration of
luc
parents:
31
diff
changeset
|
1608 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) |
| 7 | 1609 static int yaffs_internal_read_super_mtd(struct super_block * sb, void * data, int silent) |
| 1610 { | |
| 1611 return yaffs_internal_read_super(1,0,sb,data,silent) ? 0 : -1; | |
| 1612 } | |
| 1613 | |
| 1614 static struct super_block *yaffs_read_super(struct file_system_type * fs, int flags, const char *dev_name, void *data) | |
| 1615 { | |
| 1616 | |
| 1617 return get_sb_bdev(fs, flags, dev_name, data, yaffs_internal_read_super_mtd); | |
| 1618 } | |
| 1619 | |
| 1620 /* changes NCB 2.5.70 */ | |
| 1621 //static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super, FS_REQUIRES_DEV); | |
| 1622 static struct file_system_type yaffs_fs_type = { | |
| 1623 .owner = THIS_MODULE, | |
| 1624 .name = "yaffs", | |
| 1625 .get_sb = yaffs_read_super, | |
| 11 | 1626 .kill_sb = kill_block_super, |
| 1627 // .kill_sb = kill_litter_super, | |
| 7 | 1628 .fs_flags = FS_REQUIRES_DEV, |
| 1629 }; | |
| 1630 #else | |
| 1631 static struct super_block *yaffs_read_super(struct super_block * sb, void * data, int silent) | |
| 1632 { | |
| 1633 return yaffs_internal_read_super(1,0,sb,data,silent); | |
| 1634 } | |
| 1635 | |
| 1636 static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super, FS_REQUIRES_DEV); | |
| 1637 #endif | |
| 1638 | |
| 1639 #endif // CONFIG_YAFFS_MTD_ENABLED | |
| 1640 | |
| 1641 #ifdef CONFIG_YAFFS2_MTD_ENABLED | |
| 1642 | |
| 1643 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) | |
|
34
95f802b86a29
Move the internals read_super() functions near the declaration of
luc
parents:
31
diff
changeset
|
1644 static int yaffs2_internal_read_super_mtd(struct super_block * sb, void * data, int silent) |
|
95f802b86a29
Move the internals read_super() functions near the declaration of
luc
parents:
31
diff
changeset
|
1645 { |
|
95f802b86a29
Move the internals read_super() functions near the declaration of
luc
parents:
31
diff
changeset
|
1646 return yaffs_internal_read_super(2,0,sb,data,silent) ? 0 : -1; |
|
95f802b86a29
Move the internals read_super() functions near the declaration of
luc
parents:
31
diff
changeset
|
1647 } |
|
95f802b86a29
Move the internals read_super() functions near the declaration of
luc
parents:
31
diff
changeset
|
1648 |
| 7 | 1649 static struct super_block *yaffs2_read_super(struct file_system_type * fs, int flags, const char *dev_name, void *data) |
| 1650 { | |
| 1651 | |
| 1652 return get_sb_bdev(fs, flags, dev_name, data, yaffs2_internal_read_super_mtd); | |
| 1653 } | |
| 1654 | |
| 1655 /* changes NCB 2.5.70 */ | |
| 1656 //static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super, FS_REQUIRES_DEV); | |
| 1657 static struct file_system_type yaffs2_fs_type = { | |
| 1658 .owner = THIS_MODULE, | |
| 1659 .name = "yaffs2", | |
| 1660 .get_sb = yaffs2_read_super, | |
| 11 | 1661 .kill_sb = kill_block_super, |
| 1662 // .kill_sb = kill_litter_super, | |
| 7 | 1663 .fs_flags = FS_REQUIRES_DEV, |
| 1664 }; | |
| 1665 #else | |
| 1666 static struct super_block *yaffs2_read_super(struct super_block * sb, void * data, int silent) | |
| 1667 { | |
| 1668 return yaffs_internal_read_super(2,0,sb,data,silent); | |
| 1669 } | |
| 1670 | |
| 1671 static DECLARE_FSTYPE(yaffs2_fs_type, "yaffs2", yaffs2_read_super, FS_REQUIRES_DEV); | |
| 1672 #endif | |
| 1673 | |
| 1674 #endif // CONFIG_YAFFS2_MTD_ENABLED | |
| 1675 | |
| 1676 | |
| 1677 #ifdef CONFIG_YAFFS_RAM_ENABLED | |
| 1678 | |
| 1679 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) | |
|
34
95f802b86a29
Move the internals read_super() functions near the declaration of
luc
parents:
31
diff
changeset
|
1680 static int yaffs_internal_read_super_ram(struct super_block * sb, void * data, int silent) |
|
95f802b86a29
Move the internals read_super() functions near the declaration of
luc
parents:
31
diff
changeset
|
1681 { |
|
95f802b86a29
Move the internals read_super() functions near the declaration of
luc
parents:
31
diff
changeset
|
1682 return yaffs_internal_read_super(1,1,sb,data,silent) ? 0 : -1; |
|
95f802b86a29
Move the internals read_super() functions near the declaration of
luc
parents:
31
diff
changeset
|
1683 } |
|
95f802b86a29
Move the internals read_super() functions near the declaration of
luc
parents:
31
diff
changeset
|
1684 |
| 7 | 1685 static struct super_block *yaffs_ram_read_super(struct file_system_type * fs, int flags, const char *dev_name, void *data) |
| 1686 { | |
| 1687 | |
| 25 | 1688 return get_sb_nodev(fs, flags, data, yaffs_internal_read_super_ram); |
| 7 | 1689 } |
| 1690 | |
| 1691 | |
| 1692 static struct file_system_type yaffs_ram_fs_type = { | |
| 1693 .owner = THIS_MODULE, | |
| 1694 .name = "yaffsram", | |
| 1695 .get_sb = yaffs_ram_read_super, | |
| 25 | 1696 .kill_sb = kill_litter_super, |
|
24
4ebabd859f38
Some improvements to garbage collection and st_xxx to yst_xxx changes
charles
parents:
21
diff
changeset
|
1697 .fs_flags = 0 , |
| 7 | 1698 }; |
| 1699 #else | |
| 1700 static struct super_block *yaffs_ram_read_super(struct super_block * sb, void * data, int silent) | |
| 1701 { | |
| 1702 return yaffs_internal_read_super(1,1,sb,data,silent); | |
| 1703 } | |
| 1704 | |
| 1705 static DECLARE_FSTYPE(yaffs_ram_fs_type, "yaffsram", yaffs_ram_read_super, FS_SINGLE); | |
| 1706 #endif | |
| 1707 | |
| 1708 #endif // CONFIG_YAFFS_RAM_ENABLED | |
| 1709 | |
| 1710 #ifdef CONFIG_YAFFS2_RAM_ENABLED | |
| 1711 | |
| 1712 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) | |
|
34
95f802b86a29
Move the internals read_super() functions near the declaration of
luc
parents:
31
diff
changeset
|
1713 static int yaffs2_internal_read_super_ram(struct super_block * sb, void * data, int silent) |
|
95f802b86a29
Move the internals read_super() functions near the declaration of
luc
parents:
31
diff
changeset
|
1714 { |
|
95f802b86a29
Move the internals read_super() functions near the declaration of
luc
parents:
31
diff
changeset
|
1715 return yaffs_internal_read_super(2,1,sb,data,silent) ? 0 : -1; |
|
95f802b86a29
Move the internals read_super() functions near the declaration of
luc
parents:
31
diff
changeset
|
1716 } |
|
95f802b86a29
Move the internals read_super() functions near the declaration of
luc
parents:
31
diff
changeset
|
1717 |
| 7 | 1718 static struct super_block *yaffs2_ram_read_super(struct file_system_type * fs, int flags, const char *dev_name, void *data) |
| 1719 { | |
| 1720 | |
| 25 | 1721 return get_sb_nodev(fs, flags, data, yaffs2_internal_read_super_ram); |
| 7 | 1722 } |
| 1723 | |
| 1724 | |
| 1725 static struct file_system_type yaffs2_ram_fs_type = { | |
| 1726 .owner = THIS_MODULE, | |
| 1727 .name = "yaffs2ram", | |
| 1728 .get_sb = yaffs2_ram_read_super, | |
| 25 | 1729 .kill_sb = kill_litter_super, |
|
24
4ebabd859f38
Some improvements to garbage collection and st_xxx to yst_xxx changes
charles
parents:
21
diff
changeset
|
1730 .fs_flags = 0 , |
| 7 | 1731 }; |
| 1732 #else | |
| 1733 static struct super_block *yaffs2_ram_read_super(struct super_block * sb, void * data, int silent) | |
| 1734 { | |
| 1735 return yaffs_internal_read_super(2,1,sb,data,silent); | |
| 1736 } | |
| 1737 | |
| 1738 static DECLARE_FSTYPE(yaffs2_ram_fs_type, "yaffs2ram", yaffs2_ram_read_super, FS_SINGLE); | |
| 1739 #endif | |
| 1740 | |
| 1741 #endif // CONFIG_YAFFS2_RAM_ENABLED | |
| 1742 | |
| 1743 | |
| 1744 | |
| 1745 static struct proc_dir_entry *my_proc_entry; | |
| 1746 static struct proc_dir_entry *my_proc_ram_write_entry; | |
| 1747 | |
| 29 | 1748 static char * yaffs_dump_dev(char *buf,yaffs_Device *dev) |
| 7 | 1749 { |
| 1750 buf +=sprintf(buf,"startBlock......... %d\n",dev->startBlock); | |
| 1751 buf +=sprintf(buf,"endBlock........... %d\n",dev->endBlock); | |
| 1752 buf +=sprintf(buf,"chunkGroupBits..... %d\n",dev->chunkGroupBits); | |
| 1753 buf +=sprintf(buf,"chunkGroupSize..... %d\n",dev->chunkGroupSize); | |
| 1754 buf +=sprintf(buf,"nErasedBlocks...... %d\n",dev->nErasedBlocks); | |
| 1755 buf +=sprintf(buf,"nTnodesCreated..... %d\n",dev->nTnodesCreated); | |
| 1756 buf +=sprintf(buf,"nFreeTnodes........ %d\n",dev->nFreeTnodes); | |
| 1757 buf +=sprintf(buf,"nObjectsCreated.... %d\n",dev->nObjectsCreated); | |
| 1758 buf +=sprintf(buf,"nFreeObjects....... %d\n",dev->nFreeObjects); | |
| 1759 buf +=sprintf(buf,"nFreeChunks........ %d\n",dev->nFreeChunks); | |
| 1760 buf +=sprintf(buf,"nPageWrites........ %d\n",dev->nPageWrites); | |
| 1761 buf +=sprintf(buf,"nPageReads......... %d\n",dev->nPageReads); | |
| 1762 buf +=sprintf(buf,"nBlockErasures..... %d\n",dev->nBlockErasures); | |
| 1763 buf +=sprintf(buf,"nGCCopies.......... %d\n",dev->nGCCopies); | |
| 1764 buf +=sprintf(buf,"garbageCollections. %d\n",dev->garbageCollections); | |
| 1765 buf +=sprintf(buf,"passiveGCs......... %d\n",dev->passiveGarbageCollections); | |
| 1766 buf +=sprintf(buf,"nRetriedWrites..... %d\n",dev->nRetriedWrites); | |
| 1767 buf +=sprintf(buf,"nRetireBlocks...... %d\n",dev->nRetiredBlocks); | |
| 1768 buf +=sprintf(buf,"eccFixed........... %d\n",dev->eccFixed); | |
| 1769 buf +=sprintf(buf,"eccUnfixed......... %d\n",dev->eccUnfixed); | |
| 1770 buf +=sprintf(buf,"tagsEccFixed....... %d\n",dev->tagsEccFixed); | |
| 1771 buf +=sprintf(buf,"tagsEccUnfixed..... %d\n",dev->tagsEccUnfixed); | |
| 1772 buf +=sprintf(buf,"cacheHits.......... %d\n",dev->cacheHits); | |
| 1773 buf +=sprintf(buf,"nDeletedFiles...... %d\n",dev->nDeletedFiles); | |
| 1774 buf +=sprintf(buf,"nUnlinkedFiles..... %d\n",dev->nUnlinkedFiles); | |
| 1775 buf +=sprintf(buf,"nBackgroudDeletions %d\n",dev->nBackgroundDeletions); | |
| 1776 buf +=sprintf(buf,"useNANDECC......... %d\n",dev->useNANDECC); | |
| 1777 buf +=sprintf(buf,"isYaffs2........... %d\n",dev->isYaffs2); | |
| 1778 | |
| 1779 return buf; | |
| 1780 } | |
| 1781 | |
| 1782 static int yaffs_proc_read( | |
| 1783 char *page, | |
| 1784 char **start, | |
| 1785 off_t offset, | |
| 1786 int count, | |
| 1787 int *eof, | |
| 1788 void *data | |
| 1789 ) | |
| 1790 { | |
| 29 | 1791 struct list_head *item; |
| 1792 char *buf = page; | |
| 1793 int step = offset; | |
| 1794 int n = 0; | |
| 7 | 1795 |
| 29 | 1796 /* Get proc_file_read() to step 'offset' by one on each sucessive call. |
| 1797 * We use 'offset' (*ppos) to indicate where we are in devList. | |
| 1798 * This also assumes the user has posted a read buffer large | |
| 1799 * enough to hold the complete output; but that's life in /proc. | |
| 1800 */ | |
| 7 | 1801 |
| 29 | 1802 *(int *)start = 1; |
| 1803 | |
| 1804 /* Print header first */ | |
| 1805 if (step == 0) { | |
| 1806 buf += sprintf(buf, "YAFFS built:" __DATE__ " "__TIME__ | |
| 1807 "\n%s\n%s\n", yaffs_fs_c_version, yaffs_guts_c_version); | |
| 1808 } | |
| 7 | 1809 |
| 29 | 1810 /* hold lock_kernel while traversing yaffs_dev_list */ |
| 1811 lock_kernel(); | |
| 7 | 1812 |
| 29 | 1813 /* Locate and print the Nth entry. Order N-squared but N is small. */ |
| 1814 list_for_each(item, &yaffs_dev_list) { | |
| 1815 yaffs_Device *dev = list_entry(item, yaffs_Device, devList); | |
| 1816 if (n < step) { | |
| 1817 n++; | |
| 1818 continue; | |
| 1819 } | |
| 1820 buf += sprintf(buf,"\nDevice %d \"%s\"\n", n, dev->name); | |
| 1821 buf = yaffs_dump_dev(buf, dev); | |
| 1822 break; | |
| 1823 } | |
| 1824 unlock_kernel(); | |
| 1825 | |
| 1826 return buf-page < count ? buf-page : count; | |
| 7 | 1827 } |
| 1828 | |
| 1829 static int yaffs_proc_ram_write( | |
| 1830 char *page, | |
| 1831 char **start, | |
| 1832 off_t offset, | |
| 1833 int count, | |
| 1834 int *eof, | |
| 1835 void *data | |
| 1836 ) | |
| 1837 { | |
| 1838 | |
| 1839 printk(KERN_DEBUG "yaffs write size %d\n",count); | |
| 1840 return count; | |
| 1841 } | |
| 1842 | |
| 1843 | |
| 1844 | |
| 1845 // Stuff to handle installation of file systems | |
| 1846 struct file_system_to_install | |
| 1847 { | |
| 1848 struct file_system_type *fst; | |
| 1849 int installed; | |
| 1850 }; | |
| 1851 | |
| 1852 static struct file_system_to_install fs_to_install[] = | |
| 1853 { | |
| 1854 #ifdef CONFIG_YAFFS_RAM_ENABLED | |
| 1855 { &yaffs_ram_fs_type, 0}, | |
| 1856 #endif | |
| 1857 #ifdef CONFIG_YAFFS2_RAM_ENABLED | |
| 1858 { &yaffs2_ram_fs_type,0}, | |
| 1859 #endif | |
| 1860 #ifdef CONFIG_YAFFS_MTD_ENABLED | |
| 1861 { &yaffs_fs_type,0}, | |
| 1862 #endif | |
| 1863 #ifdef CONFIG_YAFFS2_MTD_ENABLED | |
| 1864 { &yaffs2_fs_type,0}, | |
| 1865 #endif | |
| 1866 { NULL,0} | |
| 1867 }; | |
| 1868 | |
| 1869 static int __init init_yaffs_fs(void) | |
| 1870 { | |
| 1871 int error = 0; | |
| 1872 struct file_system_to_install *fsinst; | |
| 1873 | |
| 1874 T(YAFFS_TRACE_ALWAYS,("yaffs " __DATE__ " " __TIME__ " Installing. \n")); | |
| 1875 | |
| 1876 | |
| 1877 | |
| 1878 /* Install the proc_fs entry */ | |
| 1879 my_proc_entry = create_proc_read_entry("yaffs", | |
| 1880 S_IRUGO | S_IFREG, | |
| 1881 &proc_root, | |
| 1882 yaffs_proc_read, | |
| 1883 NULL); | |
| 1884 if(!my_proc_entry) | |
| 1885 { | |
| 1886 return -ENOMEM; | |
| 1887 } | |
| 1888 | |
| 1889 | |
| 1890 | |
| 1891 // Now add the file system entries | |
| 1892 | |
| 1893 fsinst = fs_to_install; | |
| 1894 | |
| 1895 while(fsinst->fst && !error) | |
| 1896 { | |
| 1897 error = register_filesystem(fsinst->fst); | |
| 1898 if(!error) | |
| 1899 { | |
| 1900 fsinst->installed = 1; | |
| 1901 } | |
| 1902 fsinst++; | |
| 1903 } | |
| 1904 | |
| 1905 // Any errors? uninstall | |
| 1906 if(error) | |
| 1907 { | |
| 1908 fsinst = fs_to_install; | |
| 1909 | |
| 1910 while(fsinst->fst) | |
| 1911 { | |
| 1912 if(fsinst->installed) | |
| 1913 { | |
| 1914 unregister_filesystem(fsinst->fst); | |
| 1915 fsinst->installed = 0; | |
| 1916 } | |
| 1917 fsinst++; | |
| 1918 } | |
| 1919 } | |
| 1920 | |
| 1921 return error; | |
| 1922 } | |
| 1923 | |
| 1924 static void __exit exit_yaffs_fs(void) | |
| 1925 { | |
| 1926 | |
| 1927 struct file_system_to_install *fsinst; | |
| 1928 | |
| 1929 T(YAFFS_TRACE_ALWAYS,("yaffs " __DATE__ " " __TIME__ " removing. \n")); | |
| 1930 | |
| 1931 remove_proc_entry("yaffs",&proc_root); | |
| 1932 | |
| 1933 fsinst = fs_to_install; | |
| 1934 | |
| 1935 while(fsinst->fst) | |
| 1936 { | |
| 1937 if(fsinst->installed) | |
| 1938 { | |
| 1939 unregister_filesystem(fsinst->fst); | |
| 1940 fsinst->installed = 0; | |
| 1941 } | |
| 1942 fsinst++; | |
| 1943 } | |
| 1944 | |
| 1945 } | |
| 1946 | |
| 1947 module_init(init_yaffs_fs) | |
| 1948 module_exit(exit_yaffs_fs) | |
| 1949 | |
| 1950 MODULE_DESCRIPTION("YAFFS2 - a NAND specific flash file system"); | |
| 1951 MODULE_AUTHOR("Charles Manning, Aleph One Ltd., 2002,2003,2004"); | |
| 1952 MODULE_LICENSE("GPL"); | |
| 1953 | |
| 13 | 1954 |
