OMAP3 SRF: Fix crash on non-3430SDP platforms with DVFS/CPUFreq
[linux-ginger.git] / fs / adfs / dir_fplus.c
blob1796bb352d0541843043ba1e96bbee44dc36f381
1 /*
2 * linux/fs/adfs/dir_fplus.c
4 * Copyright (C) 1997-1999 Russell King
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10 #include <linux/buffer_head.h>
11 #include "adfs.h"
12 #include "dir_fplus.h"
14 static int
15 adfs_fplus_read(struct super_block *sb, unsigned int id, unsigned int sz, struct adfs_dir *dir)
17 struct adfs_bigdirheader *h;
18 struct adfs_bigdirtail *t;
19 unsigned long block;
20 unsigned int blk, size;
21 int i, ret = -EIO;
23 dir->nr_buffers = 0;
25 block = __adfs_block_map(sb, id, 0);
26 if (!block) {
27 adfs_error(sb, "dir object %X has a hole at offset 0", id);
28 goto out;
31 dir->bh[0] = sb_bread(sb, block);
32 if (!dir->bh[0])
33 goto out;
34 dir->nr_buffers += 1;
36 h = (struct adfs_bigdirheader *)dir->bh[0]->b_data;
37 size = le32_to_cpu(h->bigdirsize);
38 if (size != sz) {
39 printk(KERN_WARNING "adfs: adfs_fplus_read: directory header size\n"
40 " does not match directory size\n");
43 if (h->bigdirversion[0] != 0 || h->bigdirversion[1] != 0 ||
44 h->bigdirversion[2] != 0 || size & 2047 ||
45 h->bigdirstartname != cpu_to_le32(BIGDIRSTARTNAME))
46 goto out;
48 size >>= sb->s_blocksize_bits;
49 for (blk = 1; blk < size; blk++) {
50 block = __adfs_block_map(sb, id, blk);
51 if (!block) {
52 adfs_error(sb, "dir object %X has a hole at offset %d", id, blk);
53 goto out;
56 dir->bh[blk] = sb_bread(sb, block);
57 if (!dir->bh[blk])
58 goto out;
59 dir->nr_buffers = blk;
62 t = (struct adfs_bigdirtail *)(dir->bh[size - 1]->b_data + (sb->s_blocksize - 8));
64 if (t->bigdirendname != cpu_to_le32(BIGDIRENDNAME) ||
65 t->bigdirendmasseq != h->startmasseq ||
66 t->reserved[0] != 0 || t->reserved[1] != 0)
67 goto out;
69 dir->parent_id = le32_to_cpu(h->bigdirparent);
70 dir->sb = sb;
71 return 0;
72 out:
73 for (i = 0; i < dir->nr_buffers; i++)
74 brelse(dir->bh[i]);
75 dir->sb = NULL;
76 return ret;
79 static int
80 adfs_fplus_setpos(struct adfs_dir *dir, unsigned int fpos)
82 struct adfs_bigdirheader *h = (struct adfs_bigdirheader *)dir->bh[0]->b_data;
83 int ret = -ENOENT;
85 if (fpos <= le32_to_cpu(h->bigdirentries)) {
86 dir->pos = fpos;
87 ret = 0;
90 return ret;
93 static void
94 dir_memcpy(struct adfs_dir *dir, unsigned int offset, void *to, int len)
96 struct super_block *sb = dir->sb;
97 unsigned int buffer, partial, remainder;
99 buffer = offset >> sb->s_blocksize_bits;
100 offset &= sb->s_blocksize - 1;
102 partial = sb->s_blocksize - offset;
104 if (partial >= len)
105 memcpy(to, dir->bh[buffer]->b_data + offset, len);
106 else {
107 char *c = (char *)to;
109 remainder = len - partial;
111 memcpy(c, dir->bh[buffer]->b_data + offset, partial);
112 memcpy(c + partial, dir->bh[buffer + 1]->b_data, remainder);
116 static int
117 adfs_fplus_getnext(struct adfs_dir *dir, struct object_info *obj)
119 struct adfs_bigdirheader *h = (struct adfs_bigdirheader *)dir->bh[0]->b_data;
120 struct adfs_bigdirentry bde;
121 unsigned int offset;
122 int i, ret = -ENOENT;
124 if (dir->pos >= le32_to_cpu(h->bigdirentries))
125 goto out;
127 offset = offsetof(struct adfs_bigdirheader, bigdirname);
128 offset += ((le32_to_cpu(h->bigdirnamelen) + 4) & ~3);
129 offset += dir->pos * sizeof(struct adfs_bigdirentry);
131 dir_memcpy(dir, offset, &bde, sizeof(struct adfs_bigdirentry));
133 obj->loadaddr = le32_to_cpu(bde.bigdirload);
134 obj->execaddr = le32_to_cpu(bde.bigdirexec);
135 obj->size = le32_to_cpu(bde.bigdirlen);
136 obj->file_id = le32_to_cpu(bde.bigdirindaddr);
137 obj->attr = le32_to_cpu(bde.bigdirattr);
138 obj->name_len = le32_to_cpu(bde.bigdirobnamelen);
140 offset = offsetof(struct adfs_bigdirheader, bigdirname);
141 offset += ((le32_to_cpu(h->bigdirnamelen) + 4) & ~3);
142 offset += le32_to_cpu(h->bigdirentries) * sizeof(struct adfs_bigdirentry);
143 offset += le32_to_cpu(bde.bigdirobnameptr);
145 dir_memcpy(dir, offset, obj->name, obj->name_len);
146 for (i = 0; i < obj->name_len; i++)
147 if (obj->name[i] == '/')
148 obj->name[i] = '.';
150 dir->pos += 1;
151 ret = 0;
152 out:
153 return ret;
156 static int
157 adfs_fplus_sync(struct adfs_dir *dir)
159 int err = 0;
160 int i;
162 for (i = dir->nr_buffers - 1; i >= 0; i--) {
163 struct buffer_head *bh = dir->bh[i];
164 sync_dirty_buffer(bh);
165 if (buffer_req(bh) && !buffer_uptodate(bh))
166 err = -EIO;
169 return err;
172 static void
173 adfs_fplus_free(struct adfs_dir *dir)
175 int i;
177 for (i = 0; i < dir->nr_buffers; i++)
178 brelse(dir->bh[i]);
179 dir->sb = NULL;
182 struct adfs_dir_ops adfs_fplus_dir_ops = {
183 .read = adfs_fplus_read,
184 .setpos = adfs_fplus_setpos,
185 .getnext = adfs_fplus_getnext,
186 .sync = adfs_fplus_sync,
187 .free = adfs_fplus_free