annotate ffstools/tiffs-rd/inode.c @ 232:73372cfdaf7f

tiffs IVA: object name validation implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 26 Jan 2014 08:42:59 +0000
parents 5ceacdbd4490
children ae9ff2d1e3da
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
231
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * This C module implements the reading and decoding of inode information.
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 */
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5 #include <sys/types.h>
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <endian.h>
232
73372cfdaf7f tiffs IVA: object name validation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 231
diff changeset
7 #include <ctype.h>
231
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <stdio.h>
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <stdlib.h>
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 #include <string.h>
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 #include <strings.h>
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 #include "types.h"
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 #include "struct.h"
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14 #include "globals.h"
232
73372cfdaf7f tiffs IVA: object name validation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 231
diff changeset
15 #include "pathname.h"
231
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17 u8 blank_flash_line[16] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20 alloc_inode_table()
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21 {
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 inode_info = malloc(sizeof(struct inode_info *) * inode_limit);
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 if (!inode_info) {
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 perror("malloc of inode table");
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 exit(1);
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 }
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 bzero(inode_info, sizeof(struct inode_info *) * inode_limit);
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 }
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 static int
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 convert_ptr(in, infp)
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 int in;
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 int *infp;
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 {
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 if (in == 0xFFFF) {
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 *infp = 0;
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 return(0);
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 }
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 if (in < 1 || in >= inode_limit)
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 return(-1);
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 *infp = in;
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 return(1);
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 }
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 validate_inode(ino)
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 {
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 struct inode_flash *fl;
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48 struct inode_info *inf;
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 if (ino < 1 || ino >= inode_limit)
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 return(0);
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 if (inode_info[ino])
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 return(1);
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 fl = (struct inode_flash *)inode_block + ino;
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 if (!bcmp(fl, blank_flash_line, sizeof blank_flash_line))
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 return(0);
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57 inf = malloc(sizeof(struct inode_info));
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 if (!inf) {
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 perror("malloc of struct inode_info");
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60 exit(1);
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 }
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 bzero(inf, sizeof(struct inode_info));
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 inf->len = le16toh(fl->len);
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 if (inf->len & 0xF) {
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 fprintf(stderr,
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66 "warning: inode #%x: invalid length, skipping\n", ino);
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67 free(inf);
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68 return(0);
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
69 }
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
70 inf->type = fl->type;
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
71 switch (inf->type) {
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
72 case 0x00:
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
73 break;
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
74 case 0xE1:
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
75 case 0xF1:
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
76 case 0xF2:
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
77 case 0xF3:
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
78 case 0xF4:
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
79 if (!inf->len) {
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
80 fprintf(stderr,
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
81 "warning: inode #%x: non-deleted object has zero length, skipping\n",
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
82 ino);
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
83 free(inf);
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
84 return(0);
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
85 }
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
86 break;
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
87 default:
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
88 fprintf(stderr,
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
89 "warning: inode #%x: unexpected object type %02X, skipping\n",
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
90 ino, inf->type);
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
91 free(inf);
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
92 return(0);
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
93 }
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
94 if (convert_ptr(le16toh(fl->descend), &inf->descend) < 0) {
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
95 fprintf(stderr,
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
96 "warning: inode #%x: invalid descend pointer, skipping\n",
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
97 ino);
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
98 free(inf);
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
99 return(0);
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
100 }
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
101 if (convert_ptr(le16toh(fl->sibling), &inf->sibling) < 0) {
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
102 fprintf(stderr,
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
103 "warning: inode #%x: invalid sibling pointer, skipping\n",
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
104 ino);
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
105 free(inf);
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
106 return(0);
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
107 }
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
108 if (inf->len) {
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
109 inf->rawloc = le32toh(fl->dataptr);
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
110 if (inf->rawloc > 0x0FFFFFFF) {
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
111 invdptr: fprintf(stderr,
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
112 "warning: inode #%x: invalid data pointer, skipping\n",
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
113 ino);
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
114 free(inf);
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
115 return(0);
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
116 }
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
117 inf->offset = inf->rawloc << 4;
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
118 if (inf->offset >= total_ffs_size)
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
119 goto invdptr;
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
120 if (inf->offset + inf->len > total_ffs_size) {
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
121 fprintf(stderr,
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
122 "warning: inode #%x: data pointer + length > FFS total size, skipping\n",
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
123 ino);
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
124 free(inf);
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
125 return(0);
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
126 }
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
127 inf->dataptr = image + inf->offset;
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
128 }
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
129 inode_info[ino] = inf;
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
130 return(1);
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
131 }
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
132
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
133 find_root_inode()
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
134 {
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
135 int ino;
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
136
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
137 if (root_inode) {
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
138 if (!validate_inode(root_inode)) {
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
139 fprintf(stderr,
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
140 "error: root inode specified with -r is invalid\n");
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
141 exit(1);
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
142 }
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
143 return(1);
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
144 }
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
145 for (ino = 1; ino < inode_limit; ino++) {
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
146 if (!validate_inode(ino))
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
147 continue;
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
148 if (inode_info[ino]->type != 0xF2)
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
149 continue;
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
150 if (*inode_info[ino]->dataptr != '/')
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
151 continue;
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
152 root_inode = ino;
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
153 if (verbose)
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
154 fprintf(stderr, "Found root inode at #%x\n", ino);
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
155 if (inode_info[ino]->sibling)
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
156 fprintf(stderr,
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
157 "warning: root inode #%x has a non-null sibling pointer\n",
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
158 ino);
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
159 return(0);
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
160 }
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
161 fprintf(stderr, "error: no root inode found; try -r\n");
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
162 exit(1);
5ceacdbd4490 tiffs IVA: finds the root inode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
163 }
232
73372cfdaf7f tiffs IVA: object name validation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 231
diff changeset
164
73372cfdaf7f tiffs IVA: object name validation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 231
diff changeset
165 validate_obj_name(ino, root_special)
73372cfdaf7f tiffs IVA: object name validation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 231
diff changeset
166 {
73372cfdaf7f tiffs IVA: object name validation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 231
diff changeset
167 struct inode_info *inf = inode_info[ino];
73372cfdaf7f tiffs IVA: object name validation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 231
diff changeset
168 u8 *p, *endp;
73372cfdaf7f tiffs IVA: object name validation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 231
diff changeset
169 int c;
73372cfdaf7f tiffs IVA: object name validation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 231
diff changeset
170
73372cfdaf7f tiffs IVA: object name validation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 231
diff changeset
171 if (!inf->len)
73372cfdaf7f tiffs IVA: object name validation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 231
diff changeset
172 return(0);
73372cfdaf7f tiffs IVA: object name validation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 231
diff changeset
173 p = inf->dataptr;
73372cfdaf7f tiffs IVA: object name validation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 231
diff changeset
174 endp = p + inf->len;
73372cfdaf7f tiffs IVA: object name validation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 231
diff changeset
175 for (; ; p++) {
73372cfdaf7f tiffs IVA: object name validation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 231
diff changeset
176 if (p >= endp)
73372cfdaf7f tiffs IVA: object name validation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 231
diff changeset
177 return(0);
73372cfdaf7f tiffs IVA: object name validation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 231
diff changeset
178 c = *p;
73372cfdaf7f tiffs IVA: object name validation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 231
diff changeset
179 if (!c)
73372cfdaf7f tiffs IVA: object name validation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 231
diff changeset
180 break;
73372cfdaf7f tiffs IVA: object name validation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 231
diff changeset
181 if (c < ' ' || c > '~')
73372cfdaf7f tiffs IVA: object name validation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 231
diff changeset
182 return(0);
73372cfdaf7f tiffs IVA: object name validation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 231
diff changeset
183 if (root_special || isalnum(c))
73372cfdaf7f tiffs IVA: object name validation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 231
diff changeset
184 continue;
73372cfdaf7f tiffs IVA: object name validation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 231
diff changeset
185 switch (c) {
73372cfdaf7f tiffs IVA: object name validation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 231
diff changeset
186 case '.':
73372cfdaf7f tiffs IVA: object name validation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 231
diff changeset
187 case ',':
73372cfdaf7f tiffs IVA: object name validation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 231
diff changeset
188 case '_':
73372cfdaf7f tiffs IVA: object name validation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 231
diff changeset
189 case '-':
73372cfdaf7f tiffs IVA: object name validation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 231
diff changeset
190 case '+':
73372cfdaf7f tiffs IVA: object name validation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 231
diff changeset
191 case '%':
73372cfdaf7f tiffs IVA: object name validation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 231
diff changeset
192 case '$':
73372cfdaf7f tiffs IVA: object name validation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 231
diff changeset
193 case '#':
73372cfdaf7f tiffs IVA: object name validation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 231
diff changeset
194 continue;
73372cfdaf7f tiffs IVA: object name validation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 231
diff changeset
195 default:
73372cfdaf7f tiffs IVA: object name validation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 231
diff changeset
196 return(0);
73372cfdaf7f tiffs IVA: object name validation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 231
diff changeset
197 }
73372cfdaf7f tiffs IVA: object name validation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 231
diff changeset
198 }
73372cfdaf7f tiffs IVA: object name validation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 231
diff changeset
199 c = p - inf->dataptr;
73372cfdaf7f tiffs IVA: object name validation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 231
diff changeset
200 if (c < 1 || c > MAX_FN_COMPONENT && !root_special)
73372cfdaf7f tiffs IVA: object name validation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 231
diff changeset
201 return(0);
73372cfdaf7f tiffs IVA: object name validation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 231
diff changeset
202 inf->byte_after_name = p + 1;
73372cfdaf7f tiffs IVA: object name validation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 231
diff changeset
203 return(1);
73372cfdaf7f tiffs IVA: object name validation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 231
diff changeset
204 }