From: "Artem B. Bityuckiy" <dedekind@yandex.ru>
To: rick@efn.org
Cc: linux-mtd@lists.infradead.org
Subject: Re: infinite loop in jffs2_flush_wbuf_gc()?
Date: Thu, 14 Jul 2005 21:18:17 +0400 [thread overview]
Message-ID: <42D69E59.7000901@yandex.ru> (raw)
In-Reply-To: <E1Dt4R6-0005UI-00@amazonia.client.comcast.net>
Oh, there was something nasty with indentation, here it is again.
/*
* JFFS2 file expansion test.
*/
#include <sys/vfs.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#define JFFS2_SUPER_MAGIC 0x72b6
#define FNAME "tmp"
void print_jffs_stat(char *path, struct statfs *fsinfo){
if (statfs(path, fsinfo) == -1){
perror("statfs() failed"); exit(1);
}
if (fsinfo->f_type != JFFS2_SUPER_MAGIC){
fprintf(stderr, "%s is not jffs2 file system\n", path); exit(1);
}
printf("--- JFFS2 stat ---\n");
printf("f_bsize = %d\n", fsinfo->f_bsize);
printf("f_blocks = %d\n", fsinfo->f_blocks);
printf("f_bfree = %d\n", fsinfo->f_bfree);
printf("f_bavail = %d\n", fsinfo->f_bavail);
printf("f_files = %d\n", fsinfo->f_files);
printf("f_ffree = %d\n", fsinfo->f_ffree);
printf("f_fsid = %d\n", fsinfo->f_fsid);
printf("f_namelen = %d\n", fsinfo->f_namelen);
}
int main(int argc, char *argv[]){
if (argc < 1){
fprintf(stderr, "%s jffs_root\n", argv[0]); return 1;
}
if (chdir(argv[1]) == -1){
perror("chdir to jffs2 root failed"); return 1;
}
struct statfs fsinfo;
struct stat fdinfo;
/* get initial jffs2 stat */
print_jffs_stat(argv[1], &fsinfo);
int i, fd, cnt;
off_t pos;
char buf[fsinfo.f_bsize];
printf("\ncreate file filled by zero with size more then flash\n");
printf("it should fit flash since it maybe compressed perfectly\n");
bzero(buf, fsinfo.f_bsize);
if ((fd = open(FNAME, O_WRONLY | O_CREAT, 0664)) == -1){
perror("can't open temporary file"); return 1;
}
unlink(FNAME);
for(i = 0; i < fsinfo.f_blocks ; i++){
cnt = write(fd, buf, fsinfo.f_bsize);
if (cnt != fsinfo.f_bsize){
fprintf(stderr, "write to tmp file failed\n"); return 1;
}
}
printf("\nfill the file with random data. Now in should not fit on
flash\n");
printf("so the error 'No space left on device' should appear\n");
srand(1); for(i = 0; i < fsinfo.f_bsize; i++) buf[i] = rand();
pos = lseek(fd, 0, SEEK_SET);
if (pos == (off_t)-1){
perror("lseek failed"); return 1;
}
for(i = 0; i < fsinfo.f_blocks ; i++){
cnt = write(fd, buf, fsinfo.f_bsize);
if (cnt != fsinfo.f_bsize) break;
}
if ((cnt != -1)||(errno != ENOSPC)){
perror("Warning!!! Expected ENOSPC:"); return 1;
}
fsync(fd);
printf("Ok. ENOSPC occured. Thats fine!\n");
close(fd);
}
--
Best Regards,
Artem B. Bityuckiy,
St.-Petersburg, Russia.
prev parent reply other threads:[~2005-07-14 17:19 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-07-08 16:26 infinite loop in jffs2_flush_wbuf_gc()? Rick Bronson
2005-07-08 16:32 ` Artem B. Bityuckiy
2005-07-08 16:59 ` Rick Bronson
2005-07-11 14:55 ` David Woodhouse
[not found] ` <E1Ds2ma-0005ta-00@amazonia.client.comcast.net>
[not found] ` <1121108481.27264.129.camel@hades.cambridge.redhat.com>
[not found] ` <E1Ds4AF-00063d-00@amazonia.client.comcast.net>
[not found] ` <1121115438.3430.6.camel@localhost.localdomain>
[not found] ` <E1DsMIp-0004U9-00@amazonia.client.comcast.net>
[not found] ` <1121181101.12169.4.camel@hades.cambridge.redhat.com>
[not found] ` <E1DsNHk-0004bq-00@amazonia.client.comcast.net>
[not found] ` <1121186381.12086.6.camel@localhost.localdomain>
[not found] ` <E1DsOD0-0004iT-00@amazonia.client.comcast.net>
[not found] ` <1121189272.12224.10.camel@localhost.localdomain>
[not found] ` <E1Dspqm-0003zl-00@amazonia.client.comcast.net>
[not found] ` <1121294622.12224.87.camel@localhost.localdomain>
2005-07-14 14:11 ` Rick Bronson
2005-07-14 14:39 ` David Woodhouse
2005-07-14 17:14 ` Artem B. Bityuckiy
2005-07-14 17:18 ` Artem B. Bityuckiy [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=42D69E59.7000901@yandex.ru \
--to=dedekind@yandex.ru \
--cc=linux-mtd@lists.infradead.org \
--cc=rick@efn.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox