16 static void adfs_f_free(
struct adfs_dir *dir);
21 static inline unsigned int adfs_readval(
unsigned char *
p,
int len)
26 case 4: val |= p[3] << 24;
27 case 3: val |= p[2] << 16;
28 case 2: val |= p[1] << 8;
34 static inline void adfs_writeval(
unsigned char *p,
int len,
unsigned int val)
37 case 4: p[3] = val >> 24;
38 case 3: p[2] = val >> 16;
39 case 2: p[1] = val >> 8;
44 static inline int adfs_readname(
char *
buf,
char *
ptr,
int maxlen)
48 while ((
unsigned char)*ptr >=
' ' && maxlen--) {
59 #define ror13(v) ((v >> 13) | (v << 19))
62 ({ int _buf = idx >> blocksize_bits; \
63 int _off = idx - (_buf << blocksize_bits);\
64 *(u8 *)(bh[_buf]->b_data + _off); \
67 #define dir_u32(idx) \
68 ({ int _buf = idx >> blocksize_bits; \
69 int _off = idx - (_buf << blocksize_bits);\
70 *(__le32 *)(bh[_buf]->b_data + _off); \
73 #define bufoff(_bh,_idx) \
74 ({ int _buf = _idx >> blocksize_bits; \
75 int _off = _idx - (_buf << blocksize_bits);\
76 (u8 *)(_bh[_buf]->b_data + _off); \
85 adfs_dir_checkbyte(
const struct adfs_dir *dir)
87 struct buffer_head *
const *bh = dir->
bh;
88 const int blocksize_bits = dir->
sb->s_blocksize_bits;
105 }
while (i < (last & ~3));
106 }
while (
dir_u8(last) != 0);
114 end.ptr8 = ptr.ptr8 + last -
i;
117 dircheck = *ptr.ptr8++ ^
ror13(dircheck);
118 }
while (ptr.ptr8 < end.ptr8);
128 ptr.ptr8 =
bufoff(bh, 2008);
129 end.ptr8 = ptr.ptr8 + 36;
134 }
while (ptr.ptr32 < end.ptr32);
136 return (dircheck ^ (dircheck >> 8) ^ (dircheck >> 16) ^ (dircheck >> 24)) & 0xff;
156 size >>= blocksize_bits;
161 for (blk = 0; blk <
size; blk++) {
164 phys = __adfs_block_map(sb, object_id, blk);
166 adfs_error(sb,
"dir object %lX has a hole at offset %d",
168 goto release_buffers;
171 dir->
bh[
blk] = sb_bread(sb, phys);
173 goto release_buffers;
187 if (adfs_dir_checkbyte(dir) != dir->
dirtail.
new.dircheckbyte)
195 adfs_error(sb,
"corrupted directory fragment %lX",
198 for (blk -= 1; blk >= 0; blk -= 1)
199 brelse(dir->
bh[blk]);
226 (0xfff00000 == (0xfff00000 & obj->
loadaddr))) {
230 if (ADFS_SB(dir->
sb)->s_ftsuffix)
232 append_filetype_suffix(
272 memcpy(&de, dir->
bh[buffer]->b_data + offset, thissize);
274 memcpy(((
char *)&de) + thissize, dir->
bh[buffer + 1]->b_data,
280 adfs_dir2obj(dir, obj, &de);
305 memcpy(&de, dir->
bh[buffer]->b_data + offset, thissize);
307 memcpy(((
char *)&de) + thissize, dir->
bh[buffer + 1]->b_data,
313 adfs_obj2dir(&de, obj);
318 memcpy(dir->
bh[buffer]->b_data + offset, &de, thissize);
320 memcpy(dir->
bh[buffer + 1]->b_data, ((
char *)&de) + thissize,
331 adfs_dir_find_entry(
struct adfs_dir *dir,
unsigned long object_id)
340 if (!__adfs_dir_get(dir, pos, &obj))
343 if (obj.
file_id == object_id) {
353 adfs_f_read(
struct super_block *sb,
unsigned int id,
unsigned int sz,
struct adfs_dir *dir)
360 ret = adfs_dir_read(sb,
id, sz, dir);
370 adfs_f_setpos(
struct adfs_dir *dir,
unsigned int fpos)
372 if (fpos >= ADFS_NUM_DIR_ENTRIES)
375 dir->
pos = 5 + fpos * 26;
384 ret = __adfs_dir_get(dir, dir->
pos, obj);
397 ret = adfs_dir_find_entry(dir, obj->
file_id);
399 adfs_error(dir->
sb,
"unable to locate entry to update");
403 __adfs_dir_put(dir, ret, obj);
408 dir->
bh[0]->b_data[0] += 1;
411 ret = adfs_dir_checkbyte(dir);
432 if (adfs_dir_checkbyte(dir) != dir->
dirtail.
new.dircheckbyte)
456 struct buffer_head *bh = dir->
bh[
i];
458 if (buffer_req(bh) && !buffer_uptodate(bh))
481 .setpos = adfs_f_setpos,
482 .getnext = adfs_f_getnext,
483 .update = adfs_f_update,