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