5.4. jf_leave: leave a journal

Sometimes you have to update a journaled file with a tool that's not libjf enabled: there are a lot of them around the world... Take a look to this example:

tiian@linux:~/tutorial> echo "John" > jf_tut_foo-data3
tiian@linux:~/tutorial> echo "Patty" >> jf_tut_foo-data3
tiian@linux:~/tutorial> cat jf_tut_foo-data3
John
Patty
tiian@linux:~/tutorial> jf_join -j jf_tut_foo-journal jf_tut_foo-data3
tiian@linux:~/tutorial> jf_report -j jf_tut_foo-journal
<?xml version="1.0" encoding="UTF-8"?>
<journal>
  <header magic_number='0x41524153' version='1' file_id_mask='0x38' 
      file_id_mask_shift='3' size_mask='0xffffffc0' size_mask_shift='6' 
      file_size='4194304' file_num='3' rotation_threshold='0.800' 
      ctrl_recs='36' journal_recs='32980' />
  <journaled_file_table max_files='8' number_of_files='3' 
      file_table='0x804b170'>
    <file id='0' name='jf_tut_foo-journal' last_pos='32988' last_size='0' 
        status='0' last_uc_pos='0' last_uc_size='32988' stream='0x804b008' />
    <file id='1' name='jf_tut_foo-data2' last_pos='0' last_size='1075' 
        status='0' last_uc_pos='0' last_uc_size='0' stream='(nil)' />
    <file id='2' name='jf_tut_foo-data3' last_pos='0' last_size='11' 
        status='0' last_uc_pos='0' last_uc_size='0' stream='(nil)' />
  </journaled_file_table>
  <records>
    <rollback jrn_rec_off='32980' file_id='0'/>
    <rollback jrn_rec_off='32984' file_id='0'/>
  </records>
</journal>
    
one second after jf_join we have realized our journaled file jf_tut_foo-data3 must be fixed. We can not update the journaled file using shell tools because journal would not be aware of them: we have to temporarily detach the journaled file from journal:
tiian@linux:~/tutorial> jf_leave -j jf_tut_foo-journal jf_tut_foo-data3
tiian@linux:~/tutorial> jf_report -j jf_tut_foo-journal
<?xml version="1.0" encoding="UTF-8"?>
<journal>
  <header magic_number='0x41524153' version='1' file_id_mask='0x38' 
      file_id_mask_shift='3' size_mask='0xffffffc0' size_mask_shift='6' 
      file_size='4194304' file_num='3' rotation_threshold='0.800' 
      ctrl_recs='36' journal_recs='32980' />
  <journaled_file_table max_files='8' number_of_files='2' 
      file_table='0x804b170'>
    <file id='0' name='jf_tut_foo-journal' last_pos='32984' last_size='0' 
        status='0' last_uc_pos='0' last_uc_size='32984' stream='0x804b008' />
    <file id='1' name='jf_tut_foo-data2' last_pos='0' last_size='1075' 
        status='0' last_uc_pos='0' last_uc_size='0' stream='(nil)' />
  </journaled_file_table>
  <records>
    <rollback jrn_rec_off='32980' file_id='0'/>
  </records>
</journal>    
    
now we can update and join again:
tiian@linux:~/tutorial> echo "Roger" >> jf_tut_foo-data3
tiian@linux:~/tutorial> echo "Kelly" >> jf_tut_foo-data3
tiian@linux:~/tutorial> jf_join -j jf_tut_foo-journal jf_tut_foo-data3
tiian@linux:~/tutorial> jf_report -j jf_tut_foo-journal
<?xml version="1.0" encoding="UTF-8"?>
<journal>
  <header magic_number='0x41524153' version='1' file_id_mask='0x38' 
      file_id_mask_shift='3' size_mask='0xffffffc0' size_mask_shift='6' 
      file_size='4194304' file_num='3' rotation_threshold='0.800' 
      ctrl_recs='36' journal_recs='32980' />
  <journaled_file_table max_files='8' number_of_files='3' 
      file_table='0x804b170'>
    <file id='0' name='jf_tut_foo-journal' last_pos='32988' last_size='0' 
        status='0' last_uc_pos='0' last_uc_size='32988' stream='0x804b008' />
    <file id='1' name='jf_tut_foo-data2' last_pos='0' last_size='1075' 
        status='0' last_uc_pos='0' last_uc_size='0' stream='(nil)' />
    <file id='2' name='jf_tut_foo-data3' last_pos='0' last_size='22' 
        status='0' last_uc_pos='0' last_uc_size='0' stream='(nil)' />
  </journaled_file_table>
  <records>
    <rollback jrn_rec_off='32980' file_id='0'/>
    <rollback jrn_rec_off='32984' file_id='0'/>
  </records>
</journal>
    

Warning

If you update a journaled file with a program that does not use libjf API, your data can be loss when a libjf based application opens the journal and/or access the specific journaled file. If you are planning to use the files produced by libjf enabled application in a legacy environment, batch procedures to "leave & update & join" journal must be implemented.