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