Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8068031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:31:29+00:00 2026-06-05T12:31:29+00:00

My program has a loop that runs initUSB() and then runs writeEssentials() multiple times.

  • 0

My program has a loop that runs initUSB() and then runs writeEssentials() multiple times.
initUSB() is a function that mounts the USB to a directory.
writeEssentials() is a function that opens a file, and appends it with data, and then closes the file.

After a minute or so after the initial run of the program, the program will report that the file system is “read only”, and will refuse to write anymore data, until initUSB() is run again. This happens weather or not I fprintf() into the file pointer. As a temporary solution, I made writeEssentials() remount the drive if it becomes read-only. This works, but I would rather not remount the drive every minute.

Why does this happen, and how can I fix this error?

The program is running on an Debian embedded Linux system, on a TS-7800.

InitUSB:

int initUSB(){
int i;
FILE * filecheck = fopen(HMITelemCheckFile, "r");
for(i = 0; i < 26; i++) {
    char usbMountFromPathTry[256];
    char sdanum[5];
    strcpy(usbMountFromPathTry, usbMountFromPath);
    sprintf(sdanum, "%c1", i+'a');
    strcat(usbMountFromPathTry, sdanum);
    if(!mount(usbMountFromPathTry, usbMountToPath, "vfat", (long)NULL, NULL)){
        printf("Mount successful\n");
        return 1;
    } else if(!mount(usbMountFromPathTry, usbMountToPath, "vfat", MS_REMOUNT, NULL)){
        printf("Mount successful\n");
        return 1;
    }
    printf("Mount error: ");
    printf("%s\n", usbMountFromPathTry);
}
printf("Mount ERROR\n");
return 0;
}

writeEssentials():

void writeEssentials(){
FILE * file = fopen(usbMountEssentials, "a+");
fflush(file);
perror("file");
if(file == NULL){
    initUSB();
    printf("null file\n");
    return;
}
fprintf(file, "\n%s, ", getDate());
fprintf(file, "%s, ", getTime());
fprintf(file, "%1.2f, ", getSpeed());
fprintf(file, "%d, ", getRPM());
fprintf(file, "%d, ", getRegen());
fprintf(file, "%d, ", getAirgap());
fprintf(file, "%d, ", getBattery());
fprintf(file, "%.2f, ", *(getADCTemps()+COMPUTER_BOX_TEMP_INDEX));
fprintf(file, "%.2f, ", *(getBMS()+BMS_TEMP_INDEX+(BMS_NUM_VAR*0)));
fprintf(file, "%.2f, ", *(getBMS()+BMS_TEMP_INDEX+(BMS_NUM_VAR*1)));
fprintf(file, "%.2f, ", *(getBMS()+BMS_TEMP_INDEX+(BMS_NUM_VAR*2)));
fprintf(file, "%.2f, ", *(getMPPT()+MPPT_TEMP_INDEX+(MPPT_NUM_VAR*0)));
fprintf(file, "%.2f, ", *(getMPPT()+MPPT_TEMP_INDEX+(MPPT_NUM_VAR*1)));
fprintf(file, "%.2f, ", *(getMPPT()+MPPT_TEMP_INDEX+(MPPT_NUM_VAR*2)));
fprintf(file, "%.2f, ", *(getMPPT()+MPPT_TEMP_INDEX+(MPPT_NUM_VAR*3)));
fprintf(file, "%s, ", getLat());
fprintf(file, "%s, ", getLong());
int i;
for(i = 0; i < getNumErrors(); i++){
    //fprintf(file, "%s, ", getErrorText(*(getErrors()+i)));
}
fclose(file);
perror("close file error");
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T12:31:31+00:00Added an answer on June 5, 2026 at 12:31 pm

    Check dmesg. Filesystems spontaneously going read-only is usually an indication that there’s some corruption that’s being detected, so the kernel is setting the FS as read-only to protect it from further damage.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program in Octave that has a loop - running a function
My program has to use certain files that reside in another directory. Right now
My C++ program has a main loop which runs until the program says it's
My Java program uses ProcessBuilder (with redirectErrorStream set true) and has a loop that
My program has two threads: Main execution thread that handles user input and queues
I have a vb.net 2.0 program, that has a batch/queue routine to execute tasks
I have a Python program that runs a series of experiments, with no data
I am trying to make a program which has a raw_input in a loop,
I apologise for posting a question that has been asked many times (I've just
I have a method in my algorithm that runs a very tight loop on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.