Flash Chip problems

#include <SerialFlash.h>
#include <SPI.h>
#include "BMI088.h"

const int cspin = 10; // change this to match the chip select pin on your board
SerialFlashFile file;

struct mystructtype{ // size can be modified depending on what variables you want to log
  float ax;
  
} mystruct;

Bmi088Accel accel(Wire,0x18); // change based on your sensor
Bmi088Gyro gyro(Wire,0x68);
uint32_t prevMillis, currentMillis = 0;
const uint32_t sampleInterval = 1000;
float accel_reading;
void writedata(){
  currentMillis = millis();
  SerialFlash.create( "datafile.txt", 1024 ); // change the size of the text file if you need more space (which you will if you want multiple pieces of data)
  file = SerialFlash.open("datafile.txt");
  
  if ( currentMillis - prevMillis > sampleInterval ) {
    prevMillis = currentMillis;
    accel.readSensor();
    gyro.readSensor();   
    accel_reading = accel.getAccelX_mss();
    mystruct.ax = accel_reading; // whatever function is used to get data
    file.write( (uint8_t *)&mystruct, sizeof(mystruct) );  
  }
}

void readdata(){  
  file = SerialFlash.open("datafile.txt");
  file.read( (uint8_t *)&mystruct, sizeof(mystruct) );
  Serial.println( mystruct.ax );
}

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  SerialFlash.begin(cspin);
  accel.begin();
  gyro.begin();
  
}


void loop() {
  // put your main code here, to run repeatedly:
  writedata();
  readdata();
  delay(1000); // delay so that the serial monitor will be readable
}

why is this code not working?
library - GitHub - PaulStoffregen/SerialFlash: Library for using SPI Flash memory with a filesystem-like interface

What should it do and what does it actually do ?

This code should log the readings from my imu to my flash chip, but it only logs a couple pieces of data and then prints 2

Your code creates the file and opens it each time writeData() is called rather than appending data to it, and the file is never closed

Is that deliberate ?

You can also check the return values of those SerialFlash.xxxx() calls. You are most likely getting an error that you are just ignoring.

Performance oriented design does impose some usage limitations. Files are created with a fixed size which can never change or grow. Once created, files can not be renamed or deleted (except for erasing the entire chip). Files begin with all bytes erased (255). Each byte may be written only once. Files created as erasable may be fully erased, to allow new data to be written.

Looks like you are creating a file of 1024 bytes. That is not a very big log.

When you 'open' an existing file, file.position() is zero and file.size() is the size you specified so there is no easy way to know where the current 'end' of the written file is. If your data can't contain a 0xFF character you could read until you reach one and then file.seek() to the position of the first 0xFF to append new data.