LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-06-2004, 07:02 AM   #1
miko3k
LQ Newbie
 
Registered: Dec 2004
Location: kremnica, slovakia, europe, earth, sol :)
Distribution: slackware
Posts: 13

Rep: Reputation: 0
Thumbs down write to /dev/full is successful !!! what the hell :)


t have written a simple program which writes 100 bytes to /dev/full and it works!!! what the hell ? see below how i figured it out...

Code:
miko@miko:~/tmp$ cat > a.c
#include <stdio.h>

int main(void)
{
  char str[100];
  FILE *f;

  if(!(f=fopen("/dev/full","w"))) {
    printf("fuck fuck fuck\n");
    return 1;
  }

  printf("%d\n",fwrite(str,1,100,f));
  return 0;
}
miko@miko:~/tmp$ gcc a.c
miko@miko:~/tmp$ ./a.out
100
miko@miko:~/tmp$ cat a.c  > /dev/full
cat: write error: No space left on device
what's wrong with my code ? please help me!!
 
Old 12-06-2004, 09:11 AM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
Do you mean /dev/null?
 
Old 12-06-2004, 10:46 AM   #3
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
I get the same result. It must be writing successfully to the "standard I/O buffer" instead of the actual device. The low level I/O functions don't seem to have the same shortcoming.
Code:
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>

int main(void)
{
  char str[100];
  int fd;

  if((fd = open("/dev/full", O_WRONLY)) < 0)
  {
    printf("fsck\n");
    return 1;
  }

  if(write(fd, str, 100) < 0)
    perror("write()");
  else
    puts("Data written successfully!");

  return 0;
}
Quote:
itsme@dreams:~/C$ ./full2
write(): No space left on device
 
Old 12-06-2004, 10:51 AM   #4
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
Ahh...I see. It doesn't fail until the standard I/O buffer if flushed:
Code:
#include <stdio.h>
#include <errno.h>

int main(void)
{
  char str[100];
  FILE *f;

  if(!(f = fopen("/dev/full", "w")))
  {
    printf("fsck\n");
    return 1;
  }

  printf("%d\n", fwrite(str, 1, 100, f));
  if(fflush(f))
    perror("fwrite()");
  return 0;
}
Quote:
itsme@dreams:~/C$ ./full
100
fwrite(): No space left on device
 
Old 12-07-2004, 07:39 AM   #5
miko3k
LQ Newbie
 
Registered: Dec 2004
Location: kremnica, slovakia, europe, earth, sol :)
Distribution: slackware
Posts: 13

Original Poster
Rep: Reputation: 0
yeah... thanks
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Full write access to vfat Rªdical_£D SUSE / openSUSE 2 03-18-2005 03:15 AM
write error (file system full?) naijaguy Linux - Newbie 2 02-10-2005 10:55 AM
Wine in combination with a full read/write xp partition steefje Linux - Software 3 02-07-2005 10:08 AM
ftp: write failed, filesystem is full kpachopoulos Linux - General 1 10-22-2004 02:21 PM
right to write at the /dev/parport tortue Linux - General 2 01-15-2004 02:07 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration