All of lore.kernel.org
 help / color / mirror / Atom feed
From: AKASHI Takahiro <takahiro.akashi@linaro.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 06/17] fs: fat: write returns error code instead of -1
Date: Mon, 23 Jul 2018 17:32:35 +0900	[thread overview]
Message-ID: <20180723083234.GT11258@linaro.org> (raw)
In-Reply-To: <b967a74b-a55b-0ebf-999a-9eb378ebc638@gmx.de>

On Fri, Jul 20, 2018 at 07:55:06PM +0200, Heinrich Schuchardt wrote:
> On 07/20/2018 04:57 AM, AKASHI Takahiro wrote:
> > It would be good that FAT write function return error code instead of
> > just returning -1 as fat_read_file() does.
> > This patch attempts to address this issue although it is 'best effort
> > (or estimate)' for now.
> > 
> > Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
> 
> Some of the error message are written with debug() others with printf().

Right, but as you know, there is already a mixture of debug() and
printf() in the existing code.
Here I tried to do my best to use either one so as to make the usage
consistent with existing code though I don't know the exact discipline.

> Shouldn't we switch everything to debug() so that the EFI console is not
> messed up?

Is this a different issue, isn't it?
(I suppose that one of Rob's patches tried to address this issue.)

So I'd like to listen to any opinion from other folks, too.

Thanks,
-Takahiro AKASHI

> Best regards
> 
> Heinrich
> 
> > ---
> >  fs/fat/fat_write.c | 19 +++++++++++++++----
> >  1 file changed, 15 insertions(+), 4 deletions(-)
> > 
> > diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c
> > index 6c715a70f4..1e4f5af910 100644
> > --- a/fs/fat/fat_write.c
> > +++ b/fs/fat/fat_write.c
> > @@ -956,7 +956,7 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size,
> >  
> >  	if (read_bootsectandvi(&bs, &volinfo, &mydata->fatsize)) {
> >  		debug("error: reading boot sector\n");
> > -		return -1;
> > +		return -EIO;
> >  	}
> >  
> >  	total_sector = bs.total_sect;
> > @@ -997,7 +997,7 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size,
> >  	mydata->fatbuf = memalign(ARCH_DMA_MINALIGN, FATBUFSIZE);
> >  	if (mydata->fatbuf == NULL) {
> >  		debug("Error: allocating memory\n");
> > -		return -1;
> > +		return -ENOMEM;
> >  	}
> >  
> >  	if (disk_read(cursect,
> > @@ -1005,6 +1005,7 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size,
> >  		(mydata->clust_size) :
> >  		PREFETCH_BLOCKS, do_fat_read_at_block) < 0) {
> >  		debug("Error: reading rootdir block\n");
> > +		ret = -EIO;
> >  		goto exit;
> >  	}
> >  	dentptr = (dir_entry *) do_fat_read_at_block;
> > @@ -1029,6 +1030,7 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size,
> >  							size);
> >  				if (ret) {
> >  					printf("Error: %llu overflow\n", size);
> > +					ret = -ENOSPC;
> >  					goto exit;
> >  				}
> >  			}
> > @@ -1036,6 +1038,7 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size,
> >  			ret = clear_fatent(mydata, start_cluster);
> >  			if (ret) {
> >  				printf("Error: clearing FAT entries\n");
> > +				ret = -EIO;
> >  				goto exit;
> >  			}
> >  
> > @@ -1045,12 +1048,14 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size,
> >  			ret = start_cluster = find_empty_cluster(mydata);
> >  			if (ret < 0) {
> >  				printf("Error: finding empty cluster\n");
> > +				ret = -ENOSPC;
> >  				goto exit;
> >  			}
> >  
> >  			ret = check_overflow(mydata, start_cluster, size);
> >  			if (ret) {
> >  				printf("Error: %llu overflow\n", size);
> > +				ret = -ENOSPC;
> >  				goto exit;
> >  			}
> >  
> > @@ -1065,12 +1070,14 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size,
> >  			ret = start_cluster = find_empty_cluster(mydata);
> >  			if (ret < 0) {
> >  				printf("Error: finding empty cluster\n");
> > +				ret = -ENOSPC;
> >  				goto exit;
> >  			}
> >  
> >  			ret = check_overflow(mydata, start_cluster, size);
> >  			if (ret) {
> >  				printf("Error: %llu overflow\n", size);
> > +				ret = -ENOSPC;
> >  				goto exit;
> >  			}
> >  		} else {
> > @@ -1087,6 +1094,7 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size,
> >  	ret = set_contents(mydata, retdent, buffer, size, actwrite);
> >  	if (ret < 0) {
> >  		printf("Error: writing contents\n");
> > +		ret = -EIO;
> >  		goto exit;
> >  	}
> >  	debug("attempt to write 0x%llx bytes\n", *actwrite);
> > @@ -1095,14 +1103,17 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size,
> >  	ret = flush_dirty_fat_buffer(mydata);
> >  	if (ret) {
> >  		printf("Error: flush fat buffer\n");
> > +		ret = -EIO;
> >  		goto exit;
> >  	}
> >  
> >  	/* Write directory table to device */
> >  	ret = set_cluster(mydata, dir_curclust, get_dentfromdir_block,
> >  			mydata->clust_size * mydata->sect_size);
> > -	if (ret)
> > +	if (ret) {
> >  		printf("Error: writing directory entry\n");
> > +		ret = -EIO;
> > +	}
> >  
> >  exit:
> >  	free(mydata->fatbuf);
> > @@ -1114,7 +1125,7 @@ int file_fat_write(const char *filename, void *buffer, loff_t offset,
> >  {
> >  	if (offset != 0) {
> >  		printf("Error: non zero offset is currently not supported.\n");
> > -		return -1;
> > +		return -EINVAL;
> >  	}
> >  
> >  	printf("writing %s\n", filename);
> > 
> 

  reply	other threads:[~2018-07-23  8:32 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-20  2:57 [U-Boot] [PATCH 00/17] fs: fat: extend FAT write operations AKASHI Takahiro
2018-07-20  2:57 ` [U-Boot] [PATCH 01/17] fs: fat: extend get_fs_info() for write use AKASHI Takahiro
2018-07-20 18:06   ` Heinrich Schuchardt
2018-07-22  7:43     ` Heinrich Schuchardt
2018-07-20  2:57 ` [U-Boot] [PATCH 02/17] fs: fat: handle "." and ".." of root dir correctly with fat_itr_resolve() AKASHI Takahiro
2018-07-20 18:09   ` Heinrich Schuchardt
2018-07-23  7:55     ` AKASHI Takahiro
2018-07-20  2:57 ` [U-Boot] [PATCH 03/17] fs: fat: make directory iterator global for write use AKASHI Takahiro
2018-07-20 18:02   ` Heinrich Schuchardt
2018-07-23  8:06     ` AKASHI Takahiro
2018-07-23  8:18       ` AKASHI Takahiro
2018-08-11 13:34   ` Heinrich Schuchardt
2018-08-20  4:45     ` AKASHI Takahiro
2018-07-20  2:57 ` [U-Boot] [PATCH 04/17] fs: fat: assure iterator's ->dent belongs to ->clust AKASHI Takahiro
2018-07-20  2:57 ` [U-Boot] [PATCH 05/17] fs: fat: check and normailze file name AKASHI Takahiro
2018-07-31  4:31   ` Heinrich Schuchardt
2018-07-20  2:57 ` [U-Boot] [PATCH 06/17] fs: fat: write returns error code instead of -1 AKASHI Takahiro
2018-07-20 17:55   ` Heinrich Schuchardt
2018-07-23  8:32     ` AKASHI Takahiro [this message]
2018-07-20  2:57 ` [U-Boot] [PATCH 07/17] fs: fat: support write with sub-directory path AKASHI Takahiro
2018-07-20  2:57 ` [U-Boot] [PATCH 08/17] fs: fat: refactor write interface for a file offset AKASHI Takahiro
2018-07-20  2:57 ` [U-Boot] [PATCH 09/17] fs: fat: support write with non-zero offset AKASHI Takahiro
2018-07-20 17:46   ` Heinrich Schuchardt
2018-07-23  8:41     ` AKASHI Takahiro
2018-07-20  2:57 ` [U-Boot] [PATCH 10/17] cmd: fat: add offset parameter to fatwrite AKASHI Takahiro
2018-07-20  2:57 ` [U-Boot] [PATCH 11/17] fs: add mkdir interface AKASHI Takahiro
2018-07-20 17:35   ` Heinrich Schuchardt
2018-07-23 23:48     ` Simon Glass
2018-07-23 23:56       ` Tom Rini
2018-07-24  1:45         ` AKASHI Takahiro
2018-07-25  2:45           ` Simon Glass
2018-07-24  0:56     ` AKASHI Takahiro
2018-07-20  2:57 ` [U-Boot] [PATCH 12/17] fs: fat: remember the starting cluster number of directory AKASHI Takahiro
2018-07-20  2:57 ` [U-Boot] [PATCH 13/17] fs: fat: support mkdir AKASHI Takahiro
2018-07-20 17:14   ` Heinrich Schuchardt
2018-07-24  2:01     ` AKASHI Takahiro
2018-07-20  2:57 ` [U-Boot] [PATCH 14/17] cmd: fat: add fatmkdir command AKASHI Takahiro
2018-07-20 17:09   ` Heinrich Schuchardt
2018-07-24  2:07     ` AKASHI Takahiro
2018-07-20  2:57 ` [U-Boot] [PATCH 15/17] efi_loader: file: support creating a directory AKASHI Takahiro
2018-07-20  2:57 ` [U-Boot] [PATCH 16/17] efi_loader: implement a pseudo "file delete" AKASHI Takahiro
2018-07-20  2:57 ` [U-Boot] [PATCH 17/17] fs-test: fix false positive error at Test Case 12 AKASHI Takahiro
2018-07-29  7:02   ` Heinrich Schuchardt
2018-07-31  7:55     ` AKASHI Takahiro
2018-07-20  9:48 ` [U-Boot] [PATCH 00/17] fs: fat: extend FAT write operations Heinrich Schuchardt
2018-07-22  6:44   ` Heinrich Schuchardt
2018-07-23  7:35     ` AKASHI Takahiro
2018-07-23 14:46     ` Tom Rini
2018-08-06 22:34       ` Heinrich Schuchardt
2018-08-07  5:38         ` AKASHI Takahiro
2018-08-07  5:52           ` AKASHI Takahiro
2018-08-07  5:53           ` Heinrich Schuchardt

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=20180723083234.GT11258@linaro.org \
    --to=takahiro.akashi@linaro.org \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.