FreeCalypso > hg > tcs211-fcmodem
comparison g23m/condat/ms/src/atb/ATBPbFS.c @ 0:509db1a7b7b8
initial import: leo2moko-r1
author | Space Falcon <falcon@ivan.Harhan.ORG> |
---|---|
date | Mon, 01 Jun 2015 03:24:05 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:509db1a7b7b8 |
---|---|
1 #include "typedefs.h" | |
2 #include "vsi.h" | |
3 #include "pei.h" | |
4 #include "custom.h" | |
5 #include "gsm.h" | |
6 | |
7 #include <stdio.h> | |
8 #include <string.h> | |
9 | |
10 #include "mfw_mfw.h" | |
11 #include "mfw_sys.h" | |
12 | |
13 #include "cus_aci.h" | |
14 #include "prim.h" | |
15 #include "pcm.h" | |
16 | |
17 /* BEGIN ADD: Sumit : Req ID: : 31-Mar-2005*/ | |
18 #ifndef NEPTUNE_BOARD | |
19 /* END ADD: Sumit : Req ID: : 31-Mar-2005*/ | |
20 #include "ffs/ffs.h" | |
21 /* BEGIN ADD: Sumit : Req ID: : 31-Mar-2005*/ | |
22 #else | |
23 #include "ffs.h" | |
24 #endif | |
25 /* END ADD: Sumit : Req ID: : 31-Mar-2005*/ | |
26 | |
27 #include "ffs_coat.h" | |
28 #include "ATBPb.h" | |
29 #include "ATBPbFS.h" | |
30 | |
31 T_PB_FSDATA fsdata; | |
32 | |
33 UBYTE empty_rec[2] = {0xFF,0}; | |
34 | |
35 EXTERN T_HANDLE aci_handle; | |
36 #define hCommMMI aci_handle | |
37 | |
38 /******************************************************************************* | |
39 | |
40 $Function: FS_pb_GetPhonebook | |
41 | |
42 $Description: Checks to see if FFS phonebook is present, and if it is selected. If it | |
43 is not present, creates info file with default parameters. | |
44 | |
45 $Returns: PB_OK Action completed OK. | |
46 PB_EXCT Action currently executing, callback awaited. | |
47 PB_ERROR Error. | |
48 | |
49 $Arguments: phonebook_id The phonebook identifier | |
50 current_type Place to store type of phonebook selected. | |
51 | |
52 *******************************************************************************/ | |
53 | |
54 PB_RET FS_pb_GetPhonebook(SHORT phonebook_id, T_PB_TYPE *current_type) | |
55 { | |
56 T_PB_FSINFO info; | |
57 | |
58 tracefunction("FS_pb_GetPhonebook"); | |
59 | |
60 fsdata.info_file = FFS_open("/mmi/pbinfo", FFS_O_RDWR); | |
61 | |
62 if (fsdata.info_file<0) | |
63 { | |
64 /* File does not exist. Attempt to create it. */ | |
65 | |
66 fsdata.info_file = FFS_open("/mmi/pbinfo", FFS_O_RDWR | FFS_O_CREATE); | |
67 if (fsdata.info_file<0) | |
68 { | |
69 trace("** Cannot create file - flash phonebook not available **"); | |
70 return PB_FILEWRITEFAIL; | |
71 } | |
72 | |
73 /* Have opened file. Set phonebook to SIM and store setting. */ | |
74 | |
75 info.type_selected = PB_TYPE_SIM; | |
76 info.records_max = PB_RECORDS_MAX; | |
77 info.alpha_max = PB_ALPHATAG_MAX; | |
78 info.number_max = PB_NUMBER_MAX; | |
79 info.ext_max = PB_EXT_MAX; | |
80 | |
81 FFS_write(fsdata.info_file, (void *)&info, sizeof(T_PB_FSINFO)); | |
82 FFS_close(fsdata.info_file); | |
83 } | |
84 else | |
85 { | |
86 FFS_read(fsdata.info_file, (void *)&info, sizeof(T_PB_FSINFO)); | |
87 FFS_close(fsdata.info_file); | |
88 } | |
89 | |
90 /* Check to make sure parameters are in acceptable range */ | |
91 | |
92 if (info.records_max<0 || info.records_max>PB_RECORDS_UPPER_LIMIT) | |
93 info.records_max = PB_RECORDS_UPPER_LIMIT; | |
94 | |
95 if (info.alpha_max<0 || info.alpha_max>PB_ALPHATAG_UPPER_LIMIT) | |
96 info.alpha_max = PB_ALPHATAG_UPPER_LIMIT; | |
97 | |
98 if (info.number_max<0 || info.number_max>PB_NUMBER_UPPER_LIMIT) | |
99 info.number_max = PB_NUMBER_UPPER_LIMIT; | |
100 | |
101 if (info.ext_max<0 || info.ext_max>PB_EXT_UPPER_LIMIT) | |
102 info.ext_max = PB_EXT_UPPER_LIMIT; | |
103 | |
104 fsdata.records_max = info.records_max; | |
105 fsdata.alpha_max = info.alpha_max; | |
106 fsdata.number_max = info.number_max; | |
107 fsdata.ext_max = info.ext_max; | |
108 fsdata.record_size = info.alpha_max*sizeof(USHORT)+info.number_max/2+info.ext_max+sizeof(UBYTE); | |
109 | |
110 *current_type = info.type_selected; | |
111 | |
112 return PB_OK; | |
113 } | |
114 | |
115 | |
116 /******************************************************************************* | |
117 | |
118 $Function: FS_pb_SetPhonebook | |
119 | |
120 $Description: Select a phonebook | |
121 | |
122 $Returns: PB_OK Action completed OK. | |
123 PB_EXCT Action currently executing, callback awaited. | |
124 PB_ERROR Error. | |
125 | |
126 $Arguments: phonebook_id The phonebook identifier | |
127 current_type New value for selected phonebook | |
128 | |
129 *******************************************************************************/ | |
130 | |
131 PB_RET FS_pb_SetPhonebook(SHORT phonebook_id, T_PB_TYPE current_type) | |
132 { | |
133 T_PB_FSINFO info; | |
134 T_FFS_SIZE size; | |
135 T_FFS_RET fsret; | |
136 | |
137 tracefunction("FS_pb_SetPhonebook"); | |
138 | |
139 /* Have opened file. Read in current settings. */ | |
140 | |
141 size = FFS_file_read("/mmi/pbinfo", (void *)&info, sizeof(T_PB_FSINFO)); | |
142 | |
143 if (size<=0) | |
144 { | |
145 return PB_FILEREADFAIL; | |
146 } | |
147 | |
148 info.type_selected = current_type; | |
149 | |
150 fsret = FFS_file_write("/mmi/pbinfo", (void *)&info, sizeof(T_PB_FSINFO), FFS_O_TRUNC); | |
151 | |
152 if (fsret!=EFFS_OK) | |
153 return PB_FILEWRITEFAIL; | |
154 | |
155 return PB_OK; | |
156 } | |
157 | |
158 | |
159 /******************************************************************************* | |
160 | |
161 $Function: FS_pb_Initialise | |
162 | |
163 $Description: Creates the necessary phonebook file(s) if they do not already exist. | |
164 | |
165 $Returns: PB_OK Action completed OK. | |
166 PB_EXCT Action currently executing, callback awaited. | |
167 PB_FILEREADFAIL File read encountered an error | |
168 PB_FILEWRITEFAIL File write encountered an error | |
169 | |
170 | |
171 $Arguments: phonebook_id The phonebook identifier | |
172 type Type of phonebook. | |
173 records_max Indicates the maximum number of entries the | |
174 phonebook can hold. | |
175 alpha_max Maximum size of unicode alpha tag in characters | |
176 number_max Maximum size of phone number in characters | |
177 ext_max Maximum size of extended data in bytes | |
178 | |
179 *******************************************************************************/ | |
180 | |
181 PB_RET FS_pb_Initialise(SHORT phonebook_id, T_PB_TYPE type, SHORT records_max, | |
182 SHORT alpha_max, SHORT number_max, SHORT ext_max) | |
183 { | |
184 SHORT phys_index; | |
185 USHORT charIndex; | |
186 char filename[30]; | |
187 SHORT fileIndex; | |
188 SHORT recIndex; | |
189 UBYTE newfile; | |
190 T_FFS_RET retvalue; | |
191 T_FFS_SIZE sizevalue; | |
192 UBYTE *blankRec; | |
193 | |
194 tracefunction("FS_pb_Initialise"); | |
195 | |
196 fsdata.file = NULL; | |
197 fsdata.fileID = -1; | |
198 | |
199 /* Create blank record */ | |
200 | |
201 blankRec = (UBYTE *)mfwAlloc(fsdata.record_size); | |
202 memset(blankRec, 0xFF, fsdata.record_size); | |
203 | |
204 /* Create files */ | |
205 | |
206 trace("Creating files..."); | |
207 | |
208 for (phys_index = 0; phys_index<records_max; phys_index++) | |
209 { | |
210 FS_file_GetIndex(phys_index, &fileIndex, &recIndex); | |
211 | |
212 /* Check if we're starting a new file */ | |
213 | |
214 if (recIndex == 0 ) | |
215 { | |
216 if (fileIndex!=0) | |
217 { | |
218 retvalue = FFS_close(fsdata.file); | |
219 fsdata.file = NULL; | |
220 fsdata.fileID = -1; | |
221 trace_P2("Closing file %d, result %d",fsdata.file, retvalue); | |
222 } | |
223 | |
224 FS_file_GetName(filename, phonebook_id, fileIndex); | |
225 | |
226 fsdata.file = FFS_open(filename, FFS_O_RDWR); | |
227 trace_P2("Try to open file %s, result %d",filename, fsdata.file); | |
228 if (fsdata.file<0) | |
229 { | |
230 fsdata.file = FFS_open(filename, FFS_O_RDWR | FFS_O_CREATE); | |
231 fsdata.fileID = fileIndex; | |
232 trace_P2("Create file %s, result %d",filename, fsdata.file); | |
233 newfile = TRUE; | |
234 } | |
235 else | |
236 newfile = FALSE; | |
237 } | |
238 | |
239 if (newfile) | |
240 { | |
241 sizevalue = FFS_write(fsdata.file, (void *)blankRec, fsdata.record_size); | |
242 trace_P2("Writing record %d, result %d",phys_index, sizevalue); | |
243 } | |
244 } | |
245 | |
246 /* Close the last file */ | |
247 retvalue = FFS_close(fsdata.file); | |
248 trace_P2("Closing last file %d, result %d",fsdata.file, retvalue); | |
249 | |
250 fsdata.file = NULL; | |
251 fsdata.fileID = -1; | |
252 | |
253 /* Get rid of blank record */ | |
254 | |
255 mfwFree(blankRec, fsdata.record_size); | |
256 | |
257 #ifdef BLOCKING | |
258 return PB_OK; | |
259 #else | |
260 return PB_EXCT; | |
261 #endif | |
262 } | |
263 | |
264 | |
265 /******************************************************************************* | |
266 | |
267 $Function: FS_pb_ReadRec | |
268 | |
269 $Description: Reads a record from the physical position index. | |
270 | |
271 $Returns: PB_OK Action completed OK. | |
272 PB_EXCT Action currently executing, callback awaited. | |
273 PB_FILEREADFAIL File read encountered an error | |
274 | |
275 $Arguments: phonebook_id The phonebook identifier | |
276 phys_index Physical index of the record to read. | |
277 record Structure in which to store record data (allocated by | |
278 caller). | |
279 | |
280 *******************************************************************************/ | |
281 | |
282 PB_RET FS_pb_ReadRec(SHORT phonebook_id, SHORT phys_index, T_PB_RECORD *record) | |
283 { | |
284 SHORT charIndex; | |
285 UBYTE *recordstore; | |
286 SHORT fileIndex; | |
287 SHORT recIndex; | |
288 T_FFS_SIZE bytesRead; | |
289 T_FFS_RET ffsret; | |
290 USHORT *unicode; | |
291 | |
292 tracefunction("FS_pb_ReadRec"); | |
293 | |
294 /* Make sure record exists */ | |
295 | |
296 if (phys_index>=fsdata.records_max) | |
297 return PB_RECDOESNOTEXIST; | |
298 | |
299 /* Open the file */ | |
300 | |
301 recIndex = FS_file_OpenForRec(phonebook_id, phys_index); | |
302 | |
303 /* Find the record in the file */ | |
304 | |
305 FFS_seek(fsdata.file, fsdata.record_size*recIndex, FFS_SEEK_SET); | |
306 | |
307 /* Read the record */ | |
308 | |
309 recordstore = (UBYTE *)mfwAlloc(fsdata.record_size); | |
310 | |
311 bytesRead = FFS_read(fsdata.file, (void *)recordstore, fsdata.record_size); | |
312 | |
313 /* Copy alpha tag */ | |
314 | |
315 unicode = (USHORT *)recordstore; | |
316 charIndex = 0; | |
317 | |
318 do | |
319 { | |
320 record->alpha.data[charIndex] = unicode[charIndex]; | |
321 if (unicode[charIndex]!=0) | |
322 charIndex++; | |
323 } | |
324 while (unicode[charIndex]!=0 && unicode[charIndex]!=0xFFFF && charIndex<fsdata.alpha_max); | |
325 | |
326 | |
327 record->alpha.length = charIndex; | |
328 | |
329 /* Copy number */ | |
330 | |
331 memcpy((UBYTE *)record->number, (UBYTE *)&recordstore[fsdata.alpha_max*sizeof(USHORT)], fsdata.number_max/2); | |
332 | |
333 /* Copy ton/npi */ | |
334 | |
335 record->ton_npi = recordstore[fsdata.alpha_max*sizeof(USHORT)+fsdata.number_max/2]; | |
336 | |
337 mfwFree(recordstore, fsdata.record_size); | |
338 | |
339 #ifdef BLOCKING | |
340 return PB_OK; | |
341 #else | |
342 return PB_EXCT; | |
343 #endif | |
344 | |
345 } | |
346 | |
347 | |
348 /******************************************************************************* | |
349 | |
350 $Function: FS_pb_WriteRec | |
351 | |
352 $Description: Writes a record to the physical position index. | |
353 | |
354 $Returns: PB_OK Action completed OK. | |
355 PB_EXCT Action currently executing, callback awaited. | |
356 PB_FILEWRITEFAIL File write encountered an error | |
357 | |
358 $Arguments: phonebook_id The phonebook identifier | |
359 phys_index Physical index of the record to write. | |
360 record Record data to write to phonebook (allocated by caller). | |
361 | |
362 *******************************************************************************/ | |
363 | |
364 | |
365 PB_RET FS_pb_WriteRec(SHORT phonebook_id, SHORT phys_index, T_PB_RECORD *record) | |
366 { | |
367 SHORT charIndex; | |
368 UBYTE *recordstore; | |
369 SHORT recIndex; | |
370 USHORT *unicode; | |
371 T_FFS_SIZE size; | |
372 | |
373 /* Make sure record exists */ | |
374 | |
375 if (phys_index>=fsdata.records_max) | |
376 return PB_RECDOESNOTEXIST; | |
377 | |
378 /* Copy alpha tag */ | |
379 | |
380 recordstore = (UBYTE *)mfwAlloc(fsdata.record_size); | |
381 | |
382 unicode = (USHORT *)recordstore; | |
383 | |
384 for (charIndex=0; charIndex<record->alpha.length; charIndex++) | |
385 { | |
386 unicode[charIndex] = record->alpha.data[charIndex]; | |
387 } | |
388 | |
389 unicode[charIndex] = 0; | |
390 | |
391 /* Copy number */ | |
392 | |
393 memcpy(&recordstore[fsdata.alpha_max*sizeof(USHORT)], record->number, fsdata.number_max/2); | |
394 | |
395 /* Copy ton/npi */ | |
396 | |
397 recordstore[fsdata.alpha_max*sizeof(USHORT)+fsdata.number_max/2] = record->ton_npi; | |
398 | |
399 /* Open the file */ | |
400 | |
401 recIndex = FS_file_OpenForRec(phonebook_id, phys_index); | |
402 | |
403 /* Find the record in the file */ | |
404 | |
405 FFS_seek(fsdata.file, fsdata.record_size*recIndex, FFS_SEEK_SET); | |
406 | |
407 /* Write record */ | |
408 | |
409 size = FFS_write(fsdata.file, (void *)recordstore, fsdata.record_size); | |
410 | |
411 mfwFree(recordstore, fsdata.record_size); | |
412 | |
413 #ifdef BLOCKING | |
414 return PB_OK; | |
415 #else | |
416 return PB_EXCT; | |
417 #endif | |
418 | |
419 } | |
420 | |
421 | |
422 /******************************************************************************* | |
423 | |
424 $Function: FS_pb_DeleteRec | |
425 | |
426 $Description: Deletes a record at a physical position index. | |
427 | |
428 $Returns: PB_OK Action completed OK. | |
429 PB_EXCT Action currently executing, callback awaited. | |
430 PB_FILEWRITEFAIL File write encountered an error | |
431 | |
432 $Arguments: phonebook_id The phonebook identifier | |
433 phys_index Physical index of the record to delete. | |
434 | |
435 *******************************************************************************/ | |
436 | |
437 PB_RET FS_pb_DeleteRec(SHORT phonebook_id, SHORT phys_index) | |
438 { | |
439 UBYTE *recordstore; | |
440 char filename[30]; | |
441 SHORT fileIndex; | |
442 SHORT recIndex; | |
443 T_FFS_RET ffsret; | |
444 T_FFS_SIZE size; | |
445 | |
446 /* Make sure record exists */ | |
447 | |
448 if (phys_index>=fsdata.records_max) | |
449 return PB_RECDOESNOTEXIST; | |
450 | |
451 /* Allocate null buffer */ | |
452 | |
453 recordstore = (UBYTE *)mfwAlloc(fsdata.record_size); | |
454 memset(recordstore, 0xFF, fsdata.record_size); | |
455 | |
456 /* Open the file */ | |
457 | |
458 recIndex = FS_file_OpenForRec(phonebook_id, phys_index); | |
459 | |
460 /* Find the record in the file */ | |
461 | |
462 FFS_seek(fsdata.file, fsdata.record_size*recIndex, FFS_SEEK_SET); | |
463 | |
464 /* Write record */ | |
465 | |
466 size = FFS_write(fsdata.file, (void *)recordstore, fsdata.record_size); | |
467 | |
468 mfwFree(recordstore, fsdata.record_size); | |
469 | |
470 #ifdef BLOCKING | |
471 return PB_OK; | |
472 #else | |
473 return PB_EXCT; | |
474 #endif | |
475 } | |
476 | |
477 | |
478 /******************************************************************************* | |
479 | |
480 $Function: FS_pb_Finished | |
481 | |
482 $Description: Operation is over; close the last file. | |
483 | |
484 $Returns: PB_OK Action completed OK. | |
485 PB_ERROR Error. | |
486 | |
487 $Arguments: phonebook_id The phonebook identifier | |
488 | |
489 | |
490 *******************************************************************************/ | |
491 | |
492 PB_RET FS_pb_Finished(SHORT phonebook_id) | |
493 { | |
494 T_FFS_RET ret; | |
495 | |
496 if (fsdata.fileID!=-1 && fsdata.file) | |
497 { | |
498 ret = FFS_close(fsdata.file); | |
499 } | |
500 | |
501 fsdata.file = NULL; | |
502 fsdata.fileID = -1; | |
503 | |
504 return PB_OK; | |
505 } | |
506 | |
507 | |
508 /******************************************************************************* | |
509 | |
510 $Function: FS_pb_ReadTables | |
511 | |
512 $Description: Read in index table files | |
513 | |
514 $Returns: PB_OK Action completed OK. | |
515 PB_ERROR Error. | |
516 | |
517 $Arguments: phonebook_id The phonebook identifier | |
518 records_used Number of entries in phonebook | |
519 name_table Table of entries ordered by name | |
520 number_table Table of entries ordered by number | |
521 | |
522 *******************************************************************************/ | |
523 | |
524 PB_RET FS_pb_ReadTables(SHORT phonebook_id, SHORT *records_used, SHORT *name_table, SHORT *number_table) | |
525 { | |
526 T_FFS_RET ret; | |
527 T_FFS_FD file; | |
528 T_FFS_SIZE size; | |
529 | |
530 UBYTE writing; | |
531 | |
532 tracefunction("FS_pb_ReadTables"); | |
533 | |
534 /* Check if file wrote OK */ | |
535 | |
536 writing = 2; /* Dummy value to check for errors */ | |
537 size = FFS_file_read("/mmi/pbverify", (void *)&writing, sizeof(UBYTE)); | |
538 trace_P1("Try to read file /mmi/pbverify, size = %d", size); | |
539 | |
540 if (size<0) | |
541 { | |
542 ret = FFS_file_write("/mmi/pbverify", (void *)&writing, sizeof(UBYTE), FFS_O_CREATE); | |
543 trace_P1("Try to create file /mmi/pbverify, ret = %d", ret); | |
544 } | |
545 | |
546 trace_P1("Value of writing = %d", writing); | |
547 | |
548 if (writing==TRUE) /* Operation was aborted while reading tables file */ | |
549 { | |
550 trace("***ERROR - tables not written properly"); | |
551 return PB_FILEREADFAIL; | |
552 } | |
553 | |
554 /* Read in tables file */ | |
555 | |
556 file = FFS_open("/mmi/pbtables", FFS_O_RDWR); | |
557 trace_P1("Try to open file /mmi/pbtables, result %d", file); | |
558 | |
559 if (file<0) | |
560 { | |
561 return PB_FILEREADFAIL; | |
562 } | |
563 | |
564 FFS_read(file, (void *)records_used, sizeof(SHORT)); | |
565 FFS_read(file, (void *)name_table, fsdata.records_max*sizeof(SHORT)); | |
566 FFS_read(file, (void *)number_table, fsdata.records_max*sizeof(SHORT)); | |
567 | |
568 FFS_close(file); | |
569 | |
570 return PB_OK; | |
571 } | |
572 | |
573 | |
574 /******************************************************************************* | |
575 | |
576 $Function: FS_pb_WriteTables | |
577 | |
578 $Description: Update index table files | |
579 | |
580 $Returns: PB_OK Action completed OK. | |
581 PB_FILEWRITEFAIL | |
582 | |
583 $Arguments: phonebook_id The phonebook identifier | |
584 records_used Number of entries in phonebook | |
585 name_table Table of entries ordered by name | |
586 number_table Table of entries ordered by number | |
587 | |
588 *******************************************************************************/ | |
589 | |
590 PB_RET FS_pb_WriteTables(SHORT phonebook_id, SHORT records_used, SHORT *name_table, SHORT *number_table) | |
591 { | |
592 T_FFS_RET ret; | |
593 T_FFS_FD file; | |
594 UBYTE writing; | |
595 | |
596 tracefunction("FS_pb_WriteTables"); | |
597 | |
598 /* Indicate that file writing is in progress */ | |
599 | |
600 writing = TRUE; | |
601 ret = FFS_file_write("/mmi/pbverify", (void *)&writing, sizeof(UBYTE), FFS_O_TRUNC); | |
602 trace_P1("1. Try to write file /mmi/pbverify, result = %d", ret); | |
603 | |
604 /* Update tables file */ | |
605 | |
606 file = FFS_open("/mmi/pbtables", FFS_O_RDWR); | |
607 trace_P1("Try to open file /mmi/pbtables, result %d", file); | |
608 | |
609 if (file<0) | |
610 { | |
611 file = FFS_open("/mmi/pbtables", FFS_O_RDWR | FFS_O_CREATE); | |
612 trace_P1("Create file /mmi/pbtables, result %d", file); | |
613 if (file<0) | |
614 { | |
615 trace("** Cannot create file - flash phonebook not available **"); | |
616 return PB_FILEWRITEFAIL; | |
617 } | |
618 } | |
619 | |
620 FFS_write(file, (void *)&records_used, sizeof(SHORT)); | |
621 FFS_write(file, (void *)name_table, fsdata.records_max*sizeof(SHORT)); | |
622 FFS_write(file, (void *)number_table, fsdata.records_max*sizeof(SHORT)); | |
623 | |
624 FFS_close(file); | |
625 | |
626 /* Indicate that file was written OK */ | |
627 | |
628 writing = FALSE; | |
629 ret = FFS_file_write("/mmi/pbverify", (void *)&writing, sizeof(UBYTE), FFS_O_TRUNC); | |
630 trace_P1("2. Try to write file /mmi/pbverify, result = %d", ret); | |
631 | |
632 return PB_OK; | |
633 } | |
634 | |
635 | |
636 /******************************************************************************* | |
637 | |
638 $Function: FS_file_GetIndex | |
639 | |
640 $Description: For a given physical index, return the file and record number. | |
641 | |
642 $Returns: None | |
643 | |
644 $Arguments: phys_index The physical record index | |
645 fileIndex Pointer to variable to store file index | |
646 recIndex Pointer to variable to store record index | |
647 | |
648 | |
649 *******************************************************************************/ | |
650 | |
651 void FS_file_GetIndex(SHORT phys_index, SHORT *fileIndex, SHORT *recIndex) | |
652 { | |
653 *fileIndex = phys_index/PB_RECS_PER_FILE; | |
654 *recIndex = phys_index % PB_RECS_PER_FILE; | |
655 return; | |
656 } | |
657 | |
658 /******************************************************************************* | |
659 | |
660 $Function: FS_file_GetName | |
661 | |
662 $Description: For a given file index, return the filename. | |
663 | |
664 $Returns: None | |
665 | |
666 $Arguments: filename Pointer to string to store the filename | |
667 phonebook_id The identifier of the phonebook | |
668 fileIndex The index of the file | |
669 | |
670 | |
671 *******************************************************************************/ | |
672 | |
673 void FS_file_GetName(char *filename, SHORT phonebook_id, SHORT fileIndex) | |
674 { | |
675 sprintf(filename, "/mmi/pb%d", fileIndex); | |
676 return; | |
677 } | |
678 | |
679 /******************************************************************************* | |
680 | |
681 $Function: FS_file_OpenForRec | |
682 | |
683 $Description: Open the appropriate file to access a specific record | |
684 | |
685 $Returns: None | |
686 | |
687 $Arguments: phonebook_id The phonebook identifier | |
688 phys_index The physical record index | |
689 | |
690 | |
691 *******************************************************************************/ | |
692 | |
693 SHORT FS_file_OpenForRec(SHORT phonebook_id, SHORT phys_index) | |
694 { | |
695 SHORT fileIndex; | |
696 SHORT recIndex; | |
697 char filename[30]; | |
698 T_FFS_RET ffsret; | |
699 | |
700 /* Open file if it is not already open */ | |
701 | |
702 FS_file_GetIndex(phys_index, &fileIndex, &recIndex); | |
703 | |
704 if (fsdata.fileID!=fileIndex || fsdata.file==NULL) | |
705 { | |
706 /* Close currently open file */ | |
707 if (fsdata.file!=NULL) | |
708 { | |
709 ffsret = FFS_close(fsdata.file); | |
710 fsdata.file = NULL; | |
711 fsdata.fileID = -1; | |
712 } | |
713 | |
714 FS_file_GetName(filename, phonebook_id, fileIndex); | |
715 | |
716 fsdata.file = FFS_open(filename, FFS_O_RDWR); | |
717 trace_P2("Try to open file %s, result %d",filename, fsdata.file); | |
718 fsdata.fileID = fileIndex; | |
719 } | |
720 | |
721 return recIndex; | |
722 } | |
723 |