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