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 8751141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:59:24+00:00 2026-06-13T12:59:24+00:00

I am trying to overwrite all the data in a file in a kernel

  • 0

I am trying to overwrite all the data in a file in a kernel system call (Yes I know I shouldnt do a file read/write in kernel but I am just trying it out! ) based on the answer here How to read/write files within a Linux kernel module?

Here is the code:

int sys_mycompleteerase(const char __user * inputFileUser)  {

    struct file* filp = NULL;   
    int err = 0,count = 0;
    unsigned long long offset =0;

    mm_segment_t old_fs;
    old_fs = get_fs();
    set_fs(KERNEL_DS);

    filp = filp_open(inputFileUser, O_WRONLY, 0644);
    if(IS_ERR(filp)) {
        err = PTR_ERR(filp);
        return NULL;
    }
    do {
        count = vfs_write(filp," ",sizeof(" "), &offset);
        offset+=sizeof(" ");
    }while(count > 0);
    filp_close(filp, NULL);

    set_fs(old_fs);

    return 0;

}

If I give a proper file name in the user space program, it just keeps on writing without stopping. Why?

  • 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-13T12:59:25+00:00Added an answer on June 13, 2026 at 12:59 pm

    It looks like you are continually writing to a file, so the file length is growing. There is no reason for the vfs_write to fail. If I understand correctly, what you want to do is overwrite the entire file. So you would have to first find the size of the file, then write that many bytes to the file, then close the file. As it stands you are just growing the file with the ‘space’ character.

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

Sidebar

Related Questions

I am trying to bypass the call JNIEnv->DefineClass method with all necessary parameter but
I'm trying to overwrite the initWithFileURL of an UIDocument as I need to call
I'm trying to overwrite certain pieces in kernel memory (Linux 2.6.31, Ubuntu 9.10) in
I have an application where I am trying to implement a safe file overwrite
I'm trying to extract data from an xml file. A sample of my code
I am trying to write some variable data back to a database table when
I'm trying to write some code to write to a text file. I had
hi all i am trying to upload image file from sdcard to php server
What I'am trying to do: Overwrite QFileSystemModel's setData and data to implement Caching of
Using Android (Eclipse) I am trying to read a .csv file and dynamically populate

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.