@@ -2384,12 +2384,13 @@ int ltfs_write_index(char partition, char *reason, struct ltfs_volume *vol)
23842384 struct tape_offset old_selfptr , old_backptr ;
23852385 struct ltfs_timespec modtime_old = { .tv_sec = 0 , .tv_nsec = 0 };
23862386 bool generation_inc = false;
2387- struct tc_position physical_selfptr ;
2387+ struct tc_position physical_selfptr , current_position ;
23882388 char * cache_path_save = NULL ;
23892389 bool write_perm = (strcmp (reason , SYNC_WRITE_PERM ) == 0 );
23902390 bool update_vollock = false;
23912391 int volstat = -1 , new_volstat = 0 ;
23922392 char * bc_print = NULL ;
2393+ unsigned long long diff ;
23932394
23942395 CHECK_ARG_NULL (vol , - LTFS_NULL_ARG );
23952396
@@ -2506,6 +2507,22 @@ int ltfs_write_index(char partition, char *reason, struct ltfs_volume *vol)
25062507 vol -> index -> backptr = old_backptr ;
25072508 goto out_write_perm ;
25082509 }
2510+
2511+ /* Get the tape position from the tape drive by using the SCSI command READPOS*/
2512+ ret = tape_update_position (vol -> device , & current_position );
2513+ if (ret < 0 ) {
2514+ ltfsmsg (LTFS_ERR , 11081E , ret );
2515+ }
2516+
2517+ /* Prior to writing the index, compare the current location of the head position to the head location
2518+ that is kept in the cache of ltfs (physical_selfptr). If they are different return error (-1) */
2519+ ltfsmsg (LTFS_INFO , 11334 I , "compare offset" , (unsigned long long )physical_selfptr .block , (unsigned long long )current_position .block );
2520+ diff = ((unsigned long long )physical_selfptr .block - (unsigned long long )current_position .block );
2521+ if (abs (diff )) {
2522+ ltfsmsg (LTFS_DEBUG , 16503D , "diff not equal zero" , "" );
2523+ //return -1;
2524+ }
2525+
25092526 old_selfptr = vol -> index -> selfptr ;
25102527 vol -> index -> selfptr .partition = partition ;
25112528 vol -> index -> selfptr .partition = vol -> label -> part_num2id [physical_selfptr .partition ];
0 commit comments