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