David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 1 | /* inode.c: /proc/openprom handling routines |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * |
| 3 | * Copyright (C) 1996-1999 Jakub Jelinek (jakub@redhat.com) |
| 4 | * Copyright (C) 1998 Eddie C. Dost (ecd@skynet.be) |
| 5 | */ |
| 6 | |
| 7 | #include <linux/module.h> |
| 8 | #include <linux/types.h> |
| 9 | #include <linux/string.h> |
| 10 | #include <linux/fs.h> |
| 11 | #include <linux/openprom_fs.h> |
| 12 | #include <linux/init.h> |
| 13 | #include <linux/slab.h> |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 14 | #include <linux/seq_file.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
| 16 | #include <asm/openprom.h> |
| 17 | #include <asm/oplib.h> |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 18 | #include <asm/prom.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <asm/uaccess.h> |
| 20 | |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 21 | static DEFINE_MUTEX(op_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 23 | #define OPENPROM_ROOT_INO 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 25 | enum op_inode_type { |
| 26 | op_inode_node, |
| 27 | op_inode_prop, |
| 28 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 30 | union op_inode_data { |
| 31 | struct device_node *node; |
| 32 | struct property *prop; |
| 33 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 35 | struct op_inode_info { |
| 36 | struct inode vfs_inode; |
| 37 | enum op_inode_type type; |
| 38 | union op_inode_data u; |
| 39 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 41 | static inline struct op_inode_info *OP_I(struct inode *inode) |
Jan Engelhardt | a04ee14 | 2006-06-25 05:47:36 -0700 | [diff] [blame] | 42 | { |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 43 | return container_of(inode, struct op_inode_info, vfs_inode); |
Jan Engelhardt | a04ee14 | 2006-06-25 05:47:36 -0700 | [diff] [blame] | 44 | } |
| 45 | |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 46 | static int is_string(unsigned char *p, int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | { |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 48 | int i; |
| 49 | |
| 50 | for (i = 0; i < len; i++) { |
| 51 | unsigned char val = p[i]; |
| 52 | |
| 53 | if ((i && !val) || |
| 54 | (val >= ' ' && val <= '~')) |
| 55 | continue; |
| 56 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | return 0; |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | } |
| 62 | |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 63 | static int property_show(struct seq_file *f, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | { |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 65 | struct property *prop = f->private; |
| 66 | void *pval; |
| 67 | int len; |
| 68 | |
| 69 | len = prop->length; |
| 70 | pval = prop->value; |
| 71 | |
| 72 | if (is_string(pval, len)) { |
| 73 | while (len > 0) { |
| 74 | int n = strlen(pval); |
| 75 | |
| 76 | seq_printf(f, "%s", (char *) pval); |
| 77 | |
| 78 | /* Skip over the NULL byte too. */ |
| 79 | pval += n + 1; |
| 80 | len -= n + 1; |
| 81 | |
| 82 | if (len > 0) |
| 83 | seq_printf(f, " + "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | } else { |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 86 | if (len & 3) { |
| 87 | while (len) { |
| 88 | len--; |
| 89 | if (len) |
| 90 | seq_printf(f, "%02x.", |
| 91 | *(unsigned char *) pval); |
| 92 | else |
| 93 | seq_printf(f, "%02x", |
| 94 | *(unsigned char *) pval); |
| 95 | pval++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | } |
| 97 | } else { |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 98 | while (len >= 4) { |
| 99 | len -= 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 101 | if (len) |
| 102 | seq_printf(f, "%08x.", |
| 103 | *(unsigned int *) pval); |
| 104 | else |
| 105 | seq_printf(f, "%08x", |
| 106 | *(unsigned int *) pval); |
| 107 | pval += 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | } |
| 109 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | } |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 111 | seq_printf(f, "\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | return 0; |
| 114 | } |
| 115 | |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 116 | static void *property_start(struct seq_file *f, loff_t *pos) |
| 117 | { |
| 118 | if (*pos == 0) |
| 119 | return pos; |
| 120 | return NULL; |
| 121 | } |
| 122 | |
| 123 | static void *property_next(struct seq_file *f, void *v, loff_t *pos) |
| 124 | { |
| 125 | (*pos)++; |
| 126 | return NULL; |
| 127 | } |
| 128 | |
| 129 | static void property_stop(struct seq_file *f, void *v) |
| 130 | { |
| 131 | /* Nothing to do */ |
| 132 | } |
| 133 | |
| 134 | static struct seq_operations property_op = { |
| 135 | .start = property_start, |
| 136 | .next = property_next, |
| 137 | .stop = property_stop, |
| 138 | .show = property_show |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | }; |
| 140 | |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 141 | static int property_open(struct inode *inode, struct file *file) |
| 142 | { |
| 143 | struct op_inode_info *oi = OP_I(inode); |
| 144 | int ret; |
| 145 | |
| 146 | BUG_ON(oi->type != op_inode_prop); |
| 147 | |
| 148 | ret = seq_open(file, &property_op); |
| 149 | if (!ret) { |
| 150 | struct seq_file *m = file->private_data; |
| 151 | m->private = oi->u.prop; |
| 152 | } |
| 153 | return ret; |
| 154 | } |
| 155 | |
| 156 | static const struct file_operations openpromfs_prop_ops = { |
| 157 | .open = property_open, |
| 158 | .read = seq_read, |
| 159 | .llseek = seq_lseek, |
| 160 | .release = seq_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | }; |
| 162 | |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 163 | static int openpromfs_readdir(struct file *, void *, filldir_t); |
| 164 | |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 165 | static const struct file_operations openprom_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | .read = generic_read_dir, |
| 167 | .readdir = openpromfs_readdir, |
| 168 | }; |
| 169 | |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 170 | static struct dentry *openpromfs_lookup(struct inode *, struct dentry *, struct nameidata *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | |
| 172 | static struct inode_operations openprom_inode_operations = { |
| 173 | .lookup = openpromfs_lookup, |
| 174 | }; |
| 175 | |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 176 | static struct dentry *openpromfs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | { |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 178 | struct op_inode_info *ent_oi, *oi = OP_I(dir); |
| 179 | struct device_node *dp, *child; |
| 180 | struct property *prop; |
| 181 | enum op_inode_type ent_type; |
| 182 | union op_inode_data ent_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | const char *name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | struct inode *inode; |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 185 | unsigned int ino; |
| 186 | int len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 188 | BUG_ON(oi->type != op_inode_node); |
| 189 | |
| 190 | dp = oi->u.node; |
| 191 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | name = dentry->d_name.name; |
| 193 | len = dentry->d_name.len; |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 194 | |
| 195 | mutex_lock(&op_mutex); |
| 196 | |
| 197 | child = dp->child; |
| 198 | while (child) { |
| 199 | int n = strlen(child->path_component_name); |
| 200 | |
| 201 | if (len == n && |
| 202 | !strncmp(child->path_component_name, name, len)) { |
| 203 | ent_type = op_inode_node; |
| 204 | ent_data.node = child; |
| 205 | ino = child->unique_id; |
| 206 | goto found; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | } |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 208 | child = child->sibling; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | } |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 210 | |
| 211 | prop = dp->properties; |
| 212 | while (prop) { |
| 213 | int n = strlen(prop->name); |
| 214 | |
| 215 | if (len == n && !strncmp(prop->name, name, len)) { |
| 216 | ent_type = op_inode_prop; |
| 217 | ent_data.prop = prop; |
| 218 | ino = prop->unique_id; |
| 219 | goto found; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | } |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 221 | |
| 222 | prop = prop->next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | } |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 224 | |
| 225 | mutex_unlock(&op_mutex); |
| 226 | return ERR_PTR(-ENOENT); |
| 227 | |
| 228 | found: |
| 229 | inode = iget(dir->i_sb, ino); |
| 230 | mutex_unlock(&op_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | if (!inode) |
| 232 | return ERR_PTR(-EINVAL); |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 233 | ent_oi = OP_I(inode); |
| 234 | ent_oi->type = ent_type; |
| 235 | ent_oi->u = ent_data; |
| 236 | |
| 237 | switch (ent_type) { |
| 238 | case op_inode_node: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO; |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 240 | inode->i_op = &openprom_inode_operations; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | inode->i_fop = &openprom_operations; |
| 242 | inode->i_nlink = 2; |
| 243 | break; |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 244 | case op_inode_prop: |
| 245 | if (!strcmp(dp->name, "options") && (len == 17) && |
| 246 | !strncmp (name, "security-password", 17)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | inode->i_mode = S_IFREG | S_IRUSR | S_IWUSR; |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 248 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | inode->i_mode = S_IFREG | S_IRUGO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | inode->i_fop = &openpromfs_prop_ops; |
| 251 | inode->i_nlink = 1; |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 252 | inode->i_size = ent_oi->u.prop->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | break; |
| 254 | } |
| 255 | |
| 256 | inode->i_gid = 0; |
| 257 | inode->i_uid = 0; |
| 258 | |
| 259 | d_add(dentry, inode); |
| 260 | return NULL; |
| 261 | } |
| 262 | |
| 263 | static int openpromfs_readdir(struct file * filp, void * dirent, filldir_t filldir) |
| 264 | { |
| 265 | struct inode *inode = filp->f_dentry->d_inode; |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 266 | struct op_inode_info *oi = OP_I(inode); |
| 267 | struct device_node *dp = oi->u.node; |
| 268 | struct device_node *child; |
| 269 | struct property *prop; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | unsigned int ino; |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 271 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 273 | mutex_lock(&op_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | |
| 275 | ino = inode->i_ino; |
| 276 | i = filp->f_pos; |
| 277 | switch (i) { |
| 278 | case 0: |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 279 | if (filldir(dirent, ".", 1, i, ino, DT_DIR) < 0) |
| 280 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | i++; |
| 282 | filp->f_pos++; |
| 283 | /* fall thru */ |
| 284 | case 1: |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 285 | if (filldir(dirent, "..", 2, i, |
| 286 | (dp->parent == NULL ? |
| 287 | OPENPROM_ROOT_INO : |
| 288 | dp->parent->unique_id), DT_DIR) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | goto out; |
| 290 | i++; |
| 291 | filp->f_pos++; |
| 292 | /* fall thru */ |
| 293 | default: |
| 294 | i -= 2; |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 295 | |
| 296 | /* First, the children nodes as directories. */ |
| 297 | child = dp->child; |
| 298 | while (i && child) { |
| 299 | child = child->sibling; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | i--; |
| 301 | } |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 302 | while (child) { |
| 303 | if (filldir(dirent, |
| 304 | child->path_component_name, |
| 305 | strlen(child->path_component_name), |
| 306 | filp->f_pos, child->unique_id, DT_DIR) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | goto out; |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 308 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | filp->f_pos++; |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 310 | child = child->sibling; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | } |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 312 | |
| 313 | /* Next, the properties as files. */ |
| 314 | prop = dp->properties; |
| 315 | while (i && prop) { |
| 316 | prop = prop->next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | i--; |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 318 | } |
| 319 | while (prop) { |
| 320 | if (filldir(dirent, prop->name, strlen(prop->name), |
| 321 | filp->f_pos, prop->unique_id, DT_REG) < 0) |
| 322 | goto out; |
| 323 | |
| 324 | filp->f_pos++; |
| 325 | prop = prop->next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | } |
| 327 | } |
| 328 | out: |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 329 | mutex_unlock(&op_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | return 0; |
| 331 | } |
| 332 | |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 333 | static kmem_cache_t *op_inode_cachep; |
| 334 | |
| 335 | static struct inode *openprom_alloc_inode(struct super_block *sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | { |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 337 | struct op_inode_info *oi; |
| 338 | |
| 339 | oi = kmem_cache_alloc(op_inode_cachep, SLAB_KERNEL); |
| 340 | if (!oi) |
| 341 | return NULL; |
| 342 | |
| 343 | return &oi->vfs_inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | } |
| 345 | |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 346 | static void openprom_destroy_inode(struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | { |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 348 | kmem_cache_free(op_inode_cachep, OP_I(inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | static void openprom_read_inode(struct inode * inode) |
| 352 | { |
| 353 | inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; |
| 354 | if (inode->i_ino == OPENPROM_ROOT_INO) { |
| 355 | inode->i_op = &openprom_inode_operations; |
| 356 | inode->i_fop = &openprom_operations; |
| 357 | inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | static int openprom_remount(struct super_block *sb, int *flags, char *data) |
| 362 | { |
| 363 | *flags |= MS_NOATIME; |
| 364 | return 0; |
| 365 | } |
| 366 | |
| 367 | static struct super_operations openprom_sops = { |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 368 | .alloc_inode = openprom_alloc_inode, |
| 369 | .destroy_inode = openprom_destroy_inode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | .read_inode = openprom_read_inode, |
| 371 | .statfs = simple_statfs, |
| 372 | .remount_fs = openprom_remount, |
| 373 | }; |
| 374 | |
| 375 | static int openprom_fill_super(struct super_block *s, void *data, int silent) |
| 376 | { |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 377 | struct inode *root_inode; |
| 378 | struct op_inode_info *oi; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | |
| 380 | s->s_flags |= MS_NOATIME; |
| 381 | s->s_blocksize = 1024; |
| 382 | s->s_blocksize_bits = 10; |
| 383 | s->s_magic = OPENPROM_SUPER_MAGIC; |
| 384 | s->s_op = &openprom_sops; |
| 385 | s->s_time_gran = 1; |
| 386 | root_inode = iget(s, OPENPROM_ROOT_INO); |
| 387 | if (!root_inode) |
| 388 | goto out_no_root; |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 389 | |
| 390 | oi = OP_I(root_inode); |
| 391 | oi->type = op_inode_node; |
| 392 | oi->u.node = of_find_node_by_path("/"); |
| 393 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | s->s_root = d_alloc_root(root_inode); |
| 395 | if (!s->s_root) |
| 396 | goto out_no_root; |
| 397 | return 0; |
| 398 | |
| 399 | out_no_root: |
| 400 | printk("openprom_fill_super: get root inode failed\n"); |
| 401 | iput(root_inode); |
| 402 | return -ENOMEM; |
| 403 | } |
| 404 | |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 405 | static int openprom_get_sb(struct file_system_type *fs_type, |
| 406 | int flags, const char *dev_name, void *data, struct vfsmount *mnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | { |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 408 | return get_sb_single(fs_type, flags, data, openprom_fill_super, mnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | static struct file_system_type openprom_fs_type = { |
| 412 | .owner = THIS_MODULE, |
| 413 | .name = "openpromfs", |
| 414 | .get_sb = openprom_get_sb, |
| 415 | .kill_sb = kill_anon_super, |
| 416 | }; |
| 417 | |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 418 | static void op_inode_init_once(void *data, kmem_cache_t * cachep, unsigned long flags) |
| 419 | { |
| 420 | struct op_inode_info *oi = (struct op_inode_info *) data; |
| 421 | |
| 422 | if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) == |
| 423 | SLAB_CTOR_CONSTRUCTOR) |
| 424 | inode_init_once(&oi->vfs_inode); |
| 425 | } |
| 426 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | static int __init init_openprom_fs(void) |
| 428 | { |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 429 | int err; |
| 430 | |
| 431 | op_inode_cachep = kmem_cache_create("op_inode_cache", |
| 432 | sizeof(struct op_inode_info), |
| 433 | 0, |
| 434 | (SLAB_RECLAIM_ACCOUNT | |
| 435 | SLAB_MEM_SPREAD), |
| 436 | op_inode_init_once, NULL); |
| 437 | if (!op_inode_cachep) |
| 438 | return -ENOMEM; |
| 439 | |
| 440 | err = register_filesystem(&openprom_fs_type); |
| 441 | if (err) |
| 442 | kmem_cache_destroy(op_inode_cachep); |
| 443 | |
| 444 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | static void __exit exit_openprom_fs(void) |
| 448 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | unregister_filesystem(&openprom_fs_type); |
David S. Miller | 3d824a4 | 2006-06-25 23:19:14 -0700 | [diff] [blame] | 450 | kmem_cache_destroy(op_inode_cachep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | module_init(init_openprom_fs) |
| 454 | module_exit(exit_openprom_fs) |
| 455 | MODULE_LICENSE("GPL"); |