00001
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "tarfs_util.h"
00020 #include "tarfs_common.h"
00021
00029 unsigned long hcc(unsigned long nom, unsigned long denom)
00030 {
00031 if (nom == 0) {
00032 return 0;
00033 }
00034 return (nom - 1) / denom + 1;
00035 }
00036
00047 int read_block(struct super_block* s, unsigned long i, void* blok)
00048 {
00049 struct buffer_head* bh;
00050
00051 bh = sb_bread(s, i);
00052 if (!bh) {
00053 return 0;
00054 }
00055 memcpy(blok, (void*) bh->b_data, TARFS_BLKSIZE);
00056 brelse(bh);
00057 return 1;
00058 }
00059
00060
00068 int is_nullblock(void *blok, unsigned long size)
00069 {
00070 unsigned long i;
00071
00072 if(!blok) {
00073 return 0;
00074 }
00075
00076 for(i = 0;i<size;i++) {
00077 if(((unsigned char*)blok)[i]) {
00078 return 0;
00079 }
00080 }
00081
00082 return 1;
00083 }
00084
00096 int name_comparator(void* a, void* b, int first_length)
00097 {
00098 int i;
00099 char* aa = a;
00100 char* bb = b;
00101
00102
00103 for (i = 0; i < first_length; i++) {
00104 if (aa[i] != bb[i]) {
00105
00106 return 0;
00107 }
00108 if (aa[i] == 0 || bb[i] == 0) {
00109 if(!aa[i] && !bb[i]) {
00110 return 1;
00111 }
00112 break;
00113 }
00114 }
00115 if (bb[i] != 0) {
00116
00117 return 0;
00118 }
00119 if (i < first_length) {
00120
00121 return 0;
00122 }
00123 return 1;
00124 }
00125
00126
00139 int name_comparator2(void* a, void* b, unsigned int first_length, unsigned int second_length)
00140 {
00141 unsigned int i;
00142 char* aa = a;
00143 char* bb = b;
00144
00145 if (first_length < second_length || first_length > second_length + 1) {
00146 return 0;
00147 }
00148
00149
00150 for(i = 0; i < second_length; i++) {
00151 if(aa[i] != bb[i]) {
00152
00153 return 0;
00154 }
00155 }
00156
00157 if (i == first_length || aa[first_length - 1] == '/') {
00158 return 1;
00159 }
00160 return 0;
00161 }
00162
00176 int is_right_prefix(char* dname, unsigned int dsize, char* fname, unsigned int fsize)
00177 {
00178 unsigned int i;
00179
00180 if (dsize >= fsize) {
00181 return TARFS_CAN_ADD;
00182 }
00183
00184 for (i = 0; i < dsize; i++) {
00185 if (dname[i] != fname[i]) {
00186 return TARFS_CAN_ADD;
00187 }
00188 }
00189
00190
00191 for(; i < fsize - 1; i++) {
00192 if (fname[i] == '/') {
00193 return -1;
00194 }
00195 }
00196 return 1;
00197 }
00198
00205 int is_octal(char ch) {
00206 return(ch - '0' >= 0 && ch - '0' < 8);
00207 }
00208
00209
00219 unsigned long oct_to_dec(void* what, unsigned int length)
00220 {
00221 unsigned long sum = 0;
00222 int i;
00223
00224 if (length < 1) {
00225 return TARFS_EVAL;
00226 }
00227
00228 for (i = 0; i < length; i++) {
00229 if (!is_octal(*(char*) what)) {
00230 return TARFS_EVAL;
00231 }
00232
00233 sum = sum << 3;
00234 sum += ((char*)what)[i]-'0';
00235 }
00236 return sum;
00237 }
00238
00245 unsigned int short_name_size(char* name)
00246 {
00247 unsigned int i;
00248
00249 for (i = 0; i < 100; i++) {
00250 if(!name[i]) {
00251 break;
00252 }
00253 }
00254
00255 return i;
00256 }
00257