diff mbox series

[U-Boot,03/17] fs: fat: make directory iterator global for write use

Message ID 20180720025723.6736-4-takahiro.akashi@linaro.org
State Changes Requested
Delegated to: Tom Rini
Headers show
Series fs: fat: extend FAT write operations | expand

Commit Message

AKASHI Takahiro July 20, 2018, 2:57 a.m. UTC
Directory iterator was introduced in major re-work of read operation by
Rob. We want to use it for write operation extensively as well.
This patch makes relevant functions, as well as iterator defition, visible
outside of fat.c.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
---
 fs/fat/fat.c  | 39 ++++++---------------------------------
 include/fat.h | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 33 deletions(-)

Comments

Heinrich Schuchardt July 20, 2018, 6:02 p.m. UTC | #1
On 07/20/2018 04:57 AM, AKASHI Takahiro wrote:
> Directory iterator was introduced in major re-work of read operation by
> Rob. We want to use it for write operation extensively as well.
> This patch makes relevant functions, as well as iterator defition, visible
> outside of fat.c.
> 
> Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
> ---
>  fs/fat/fat.c  | 39 ++++++---------------------------------
>  include/fat.h | 32 ++++++++++++++++++++++++++++++++
>  2 files changed, 38 insertions(+), 33 deletions(-)
> 
> diff --git a/fs/fat/fat.c b/fs/fat/fat.c
> index fd6523c66b..0f82cbe1bd 100644
> --- a/fs/fat/fat.c
> +++ b/fs/fat/fat.c
> @@ -634,25 +634,6 @@ static int get_fs_info(fsdata *mydata)
>   * For more complete example, see fat_itr_resolve()
>   */
>  
> -typedef struct {
> -	fsdata    *fsdata;        /* filesystem parameters */
> -	unsigned   clust;         /* current cluster */
> -	int        last_cluster;  /* set once we've read last cluster */
> -	int        is_root;       /* is iterator at root directory */
> -	int        remaining;     /* remaining dent's in current cluster */
> -
> -	/* current iterator position values: */
> -	dir_entry *dent;          /* current directory entry */
> -	char       l_name[VFAT_MAXLEN_BYTES];    /* long (vfat) name */
> -	char       s_name[14];    /* short 8.3 name */
> -	char      *name;          /* l_name if there is one, else s_name */
> -
> -	/* storage for current cluster in memory: */
> -	u8         block[MAX_CLUSTSIZE] __aligned(ARCH_DMA_MINALIGN);
> -} fat_itr;
> -
> -static int fat_itr_isdir(fat_itr *itr);
> -
>  /**
>   * fat_itr_root() - initialize an iterator to start at the root
>   * directory
> @@ -661,7 +642,7 @@ static int fat_itr_isdir(fat_itr *itr);
>   * @fsdata: filesystem data for the partition
>   * @return 0 on success, else -errno
>   */
> -static int fat_itr_root(fat_itr *itr, fsdata *fsdata)
> +int fat_itr_root(fat_itr *itr, fsdata *fsdata)
>  {
>  	if (get_fs_info(fsdata))
>  		return -ENXIO;
> @@ -693,7 +674,7 @@ static int fat_itr_root(fat_itr *itr, fsdata *fsdata)
>   * @parent: the iterator pointing at a directory entry in the
>   *    parent directory of the directory to iterate
>   */
> -static void fat_itr_child(fat_itr *itr, fat_itr *parent)
> +void fat_itr_child(fat_itr *itr, fat_itr *parent)
>  {
>  	fsdata *mydata = parent->fsdata;  /* for silly macros */
>  	unsigned clustnum = START(parent->dent);
> @@ -713,7 +694,7 @@ static void fat_itr_child(fat_itr *itr, fat_itr *parent)
>  	itr->last_cluster = 0;
>  }
>  
> -static void *next_cluster(fat_itr *itr)
> +void *next_cluster(fat_itr *itr)
>  {
>  	fsdata *mydata = itr->fsdata;  /* for silly macros */
>  	int ret;
> @@ -834,7 +815,7 @@ static dir_entry *extract_vfat_name(fat_itr *itr)
>   * @return boolean, 1 if success or 0 if no more entries in the
>   *    current directory
>   */
> -static int fat_itr_next(fat_itr *itr)
> +int fat_itr_next(fat_itr *itr)
>  {
>  	dir_entry *dent;
>  
> @@ -879,19 +860,11 @@ static int fat_itr_next(fat_itr *itr)
>   * @itr: the iterator
>   * @return true if cursor is at a directory
>   */
> -static int fat_itr_isdir(fat_itr *itr)
> +int fat_itr_isdir(fat_itr *itr)
>  {
>  	return !!(itr->dent->attr & ATTR_DIR);
>  }
>  
> -/*
> - * Helpers:
> - */
> -
> -#define TYPE_FILE 0x1
> -#define TYPE_DIR  0x2
> -#define TYPE_ANY  (TYPE_FILE | TYPE_DIR)
> -
>  /**
>   * fat_itr_resolve() - traverse directory structure to resolve the
>   * requested path.
> @@ -907,7 +880,7 @@ static int fat_itr_isdir(fat_itr *itr)
>   * @type: bitmask of allowable file types
>   * @return 0 on success or -errno
>   */
> -static int fat_itr_resolve(fat_itr *itr, const char *path, unsigned type)
> +int fat_itr_resolve(fat_itr *itr, const char *path, unsigned type)
>  {
>  	const char *next;
>  
> diff --git a/include/fat.h b/include/fat.h
> index 0c88b59a4a..577e6b4592 100644
> --- a/include/fat.h
> +++ b/include/fat.h
> @@ -187,6 +187,38 @@ static inline u32 sect_to_clust(fsdata *fsdata, int sect)
>  	return (sect - fsdata->data_begin) / fsdata->clust_size;
>  }
>  
> +/*
> + * Directory iterator
> + */
> +
> +#define TYPE_FILE 0x1
> +#define TYPE_DIR  0x2
> +#define TYPE_ANY  (TYPE_FILE | TYPE_DIR)

Please, rename these to something more specific like FS_ITER_ANY.

TYPE_ANY already is defined in fs/reiserfs/reiserfs_private.h:

fs/reiserfs/reiserfs_private.h:160:#define TYPE_ANY 15

Best regards

Heinrich

> +
> +typedef struct {
> +	fsdata    *fsdata;        /* filesystem parameters */
> +	unsigned   clust;         /* current cluster */
> +	int        last_cluster;  /* set once we've read last cluster */
> +	int        is_root;       /* is iterator at root directory */
> +	int        remaining;     /* remaining dent's in current cluster */
> +
> +	/* current iterator position values: */
> +	dir_entry *dent;          /* current directory entry */
> +	char       l_name[VFAT_MAXLEN_BYTES];    /* long (vfat) name */
> +	char       s_name[14];    /* short 8.3 name */
> +	char      *name;          /* l_name if there is one, else s_name */
> +
> +	/* storage for current cluster in memory: */
> +	u8         block[MAX_CLUSTSIZE] __aligned(ARCH_DMA_MINALIGN);
> +} fat_itr;
> +
> +int fat_itr_root(fat_itr *itr, fsdata *fsdata);
> +void fat_itr_child(fat_itr *itr, fat_itr *parent);
> +void *next_cluster(fat_itr *itr);
> +int fat_itr_next(fat_itr *itr);
> +int fat_itr_isdir(fat_itr *itr);
> +int fat_itr_resolve(fat_itr *itr, const char *path, unsigned type);
> +
>  int file_fat_detectfs(void);
>  int fat_exists(const char *filename);
>  int fat_size(const char *filename, loff_t *size);
>
AKASHI Takahiro July 23, 2018, 8:06 a.m. UTC | #2
On Fri, Jul 20, 2018 at 08:02:57PM +0200, Heinrich Schuchardt wrote:
> On 07/20/2018 04:57 AM, AKASHI Takahiro wrote:
> > Directory iterator was introduced in major re-work of read operation by
> > Rob. We want to use it for write operation extensively as well.
> > This patch makes relevant functions, as well as iterator defition, visible
> > outside of fat.c.
> > 
> > Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
> > ---
> >  fs/fat/fat.c  | 39 ++++++---------------------------------
> >  include/fat.h | 32 ++++++++++++++++++++++++++++++++
> >  2 files changed, 38 insertions(+), 33 deletions(-)
> > 
> > diff --git a/fs/fat/fat.c b/fs/fat/fat.c
> > index fd6523c66b..0f82cbe1bd 100644
> > --- a/fs/fat/fat.c
> > +++ b/fs/fat/fat.c
> > @@ -634,25 +634,6 @@ static int get_fs_info(fsdata *mydata)
> >   * For more complete example, see fat_itr_resolve()
> >   */
> >  
> > -typedef struct {
> > -	fsdata    *fsdata;        /* filesystem parameters */
> > -	unsigned   clust;         /* current cluster */
> > -	int        last_cluster;  /* set once we've read last cluster */
> > -	int        is_root;       /* is iterator at root directory */
> > -	int        remaining;     /* remaining dent's in current cluster */
> > -
> > -	/* current iterator position values: */
> > -	dir_entry *dent;          /* current directory entry */
> > -	char       l_name[VFAT_MAXLEN_BYTES];    /* long (vfat) name */
> > -	char       s_name[14];    /* short 8.3 name */
> > -	char      *name;          /* l_name if there is one, else s_name */
> > -
> > -	/* storage for current cluster in memory: */
> > -	u8         block[MAX_CLUSTSIZE] __aligned(ARCH_DMA_MINALIGN);
> > -} fat_itr;
> > -
> > -static int fat_itr_isdir(fat_itr *itr);
> > -
> >  /**
> >   * fat_itr_root() - initialize an iterator to start at the root
> >   * directory
> > @@ -661,7 +642,7 @@ static int fat_itr_isdir(fat_itr *itr);
> >   * @fsdata: filesystem data for the partition
> >   * @return 0 on success, else -errno
> >   */
> > -static int fat_itr_root(fat_itr *itr, fsdata *fsdata)
> > +int fat_itr_root(fat_itr *itr, fsdata *fsdata)
> >  {
> >  	if (get_fs_info(fsdata))
> >  		return -ENXIO;
> > @@ -693,7 +674,7 @@ static int fat_itr_root(fat_itr *itr, fsdata *fsdata)
> >   * @parent: the iterator pointing at a directory entry in the
> >   *    parent directory of the directory to iterate
> >   */
> > -static void fat_itr_child(fat_itr *itr, fat_itr *parent)
> > +void fat_itr_child(fat_itr *itr, fat_itr *parent)
> >  {
> >  	fsdata *mydata = parent->fsdata;  /* for silly macros */
> >  	unsigned clustnum = START(parent->dent);
> > @@ -713,7 +694,7 @@ static void fat_itr_child(fat_itr *itr, fat_itr *parent)
> >  	itr->last_cluster = 0;
> >  }
> >  
> > -static void *next_cluster(fat_itr *itr)
> > +void *next_cluster(fat_itr *itr)
> >  {
> >  	fsdata *mydata = itr->fsdata;  /* for silly macros */
> >  	int ret;
> > @@ -834,7 +815,7 @@ static dir_entry *extract_vfat_name(fat_itr *itr)
> >   * @return boolean, 1 if success or 0 if no more entries in the
> >   *    current directory
> >   */
> > -static int fat_itr_next(fat_itr *itr)
> > +int fat_itr_next(fat_itr *itr)
> >  {
> >  	dir_entry *dent;
> >  
> > @@ -879,19 +860,11 @@ static int fat_itr_next(fat_itr *itr)
> >   * @itr: the iterator
> >   * @return true if cursor is at a directory
> >   */
> > -static int fat_itr_isdir(fat_itr *itr)
> > +int fat_itr_isdir(fat_itr *itr)
> >  {
> >  	return !!(itr->dent->attr & ATTR_DIR);
> >  }
> >  
> > -/*
> > - * Helpers:
> > - */
> > -
> > -#define TYPE_FILE 0x1
> > -#define TYPE_DIR  0x2
> > -#define TYPE_ANY  (TYPE_FILE | TYPE_DIR)
> > -
> >  /**
> >   * fat_itr_resolve() - traverse directory structure to resolve the
> >   * requested path.
> > @@ -907,7 +880,7 @@ static int fat_itr_isdir(fat_itr *itr)
> >   * @type: bitmask of allowable file types
> >   * @return 0 on success or -errno
> >   */
> > -static int fat_itr_resolve(fat_itr *itr, const char *path, unsigned type)
> > +int fat_itr_resolve(fat_itr *itr, const char *path, unsigned type)
> >  {
> >  	const char *next;
> >  
> > diff --git a/include/fat.h b/include/fat.h
> > index 0c88b59a4a..577e6b4592 100644
> > --- a/include/fat.h
> > +++ b/include/fat.h
> > @@ -187,6 +187,38 @@ static inline u32 sect_to_clust(fsdata *fsdata, int sect)
> >  	return (sect - fsdata->data_begin) / fsdata->clust_size;
> >  }
> >  
> > +/*
> > + * Directory iterator
> > + */
> > +
> > +#define TYPE_FILE 0x1
> > +#define TYPE_DIR  0x2
> > +#define TYPE_ANY  (TYPE_FILE | TYPE_DIR)
> 
> Please, rename these to something more specific like FS_ITER_ANY.
> 
> TYPE_ANY already is defined in fs/reiserfs/reiserfs_private.h:
> 
> fs/reiserfs/reiserfs_private.h:160:#define TYPE_ANY 15

Good catch though the definition above comes directly from Rob's
original patch.

Since there is only one occurrence of TYPE_ANY in fs/fat,
I'd rather expand it without introducing another definition.

Thanks,
-Takahiro AKASHI


> Best regards
> 
> Heinrich
> 
> > +
> > +typedef struct {
> > +	fsdata    *fsdata;        /* filesystem parameters */
> > +	unsigned   clust;         /* current cluster */
> > +	int        last_cluster;  /* set once we've read last cluster */
> > +	int        is_root;       /* is iterator at root directory */
> > +	int        remaining;     /* remaining dent's in current cluster */
> > +
> > +	/* current iterator position values: */
> > +	dir_entry *dent;          /* current directory entry */
> > +	char       l_name[VFAT_MAXLEN_BYTES];    /* long (vfat) name */
> > +	char       s_name[14];    /* short 8.3 name */
> > +	char      *name;          /* l_name if there is one, else s_name */
> > +
> > +	/* storage for current cluster in memory: */
> > +	u8         block[MAX_CLUSTSIZE] __aligned(ARCH_DMA_MINALIGN);
> > +} fat_itr;
> > +
> > +int fat_itr_root(fat_itr *itr, fsdata *fsdata);
> > +void fat_itr_child(fat_itr *itr, fat_itr *parent);
> > +void *next_cluster(fat_itr *itr);
> > +int fat_itr_next(fat_itr *itr);
> > +int fat_itr_isdir(fat_itr *itr);
> > +int fat_itr_resolve(fat_itr *itr, const char *path, unsigned type);
> > +
> >  int file_fat_detectfs(void);
> >  int fat_exists(const char *filename);
> >  int fat_size(const char *filename, loff_t *size);
> > 
>
AKASHI Takahiro July 23, 2018, 8:18 a.m. UTC | #3
On Mon, Jul 23, 2018 at 05:06:46PM +0900, AKASHI Takahiro wrote:
> On Fri, Jul 20, 2018 at 08:02:57PM +0200, Heinrich Schuchardt wrote:
> > On 07/20/2018 04:57 AM, AKASHI Takahiro wrote:
> > > Directory iterator was introduced in major re-work of read operation by
> > > Rob. We want to use it for write operation extensively as well.
> > > This patch makes relevant functions, as well as iterator defition, visible
> > > outside of fat.c.
> > > 
> > > Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
> > > ---
> > >  fs/fat/fat.c  | 39 ++++++---------------------------------
> > >  include/fat.h | 32 ++++++++++++++++++++++++++++++++
> > >  2 files changed, 38 insertions(+), 33 deletions(-)
> > > 
> > > diff --git a/fs/fat/fat.c b/fs/fat/fat.c
> > > index fd6523c66b..0f82cbe1bd 100644
> > > --- a/fs/fat/fat.c
> > > +++ b/fs/fat/fat.c
> > > @@ -634,25 +634,6 @@ static int get_fs_info(fsdata *mydata)
> > >   * For more complete example, see fat_itr_resolve()
> > >   */
> > >  
> > > -typedef struct {
> > > -	fsdata    *fsdata;        /* filesystem parameters */
> > > -	unsigned   clust;         /* current cluster */
> > > -	int        last_cluster;  /* set once we've read last cluster */
> > > -	int        is_root;       /* is iterator at root directory */
> > > -	int        remaining;     /* remaining dent's in current cluster */
> > > -
> > > -	/* current iterator position values: */
> > > -	dir_entry *dent;          /* current directory entry */
> > > -	char       l_name[VFAT_MAXLEN_BYTES];    /* long (vfat) name */
> > > -	char       s_name[14];    /* short 8.3 name */
> > > -	char      *name;          /* l_name if there is one, else s_name */
> > > -
> > > -	/* storage for current cluster in memory: */
> > > -	u8         block[MAX_CLUSTSIZE] __aligned(ARCH_DMA_MINALIGN);
> > > -} fat_itr;
> > > -
> > > -static int fat_itr_isdir(fat_itr *itr);
> > > -
> > >  /**
> > >   * fat_itr_root() - initialize an iterator to start at the root
> > >   * directory
> > > @@ -661,7 +642,7 @@ static int fat_itr_isdir(fat_itr *itr);
> > >   * @fsdata: filesystem data for the partition
> > >   * @return 0 on success, else -errno
> > >   */
> > > -static int fat_itr_root(fat_itr *itr, fsdata *fsdata)
> > > +int fat_itr_root(fat_itr *itr, fsdata *fsdata)
> > >  {
> > >  	if (get_fs_info(fsdata))
> > >  		return -ENXIO;
> > > @@ -693,7 +674,7 @@ static int fat_itr_root(fat_itr *itr, fsdata *fsdata)
> > >   * @parent: the iterator pointing at a directory entry in the
> > >   *    parent directory of the directory to iterate
> > >   */
> > > -static void fat_itr_child(fat_itr *itr, fat_itr *parent)
> > > +void fat_itr_child(fat_itr *itr, fat_itr *parent)
> > >  {
> > >  	fsdata *mydata = parent->fsdata;  /* for silly macros */
> > >  	unsigned clustnum = START(parent->dent);
> > > @@ -713,7 +694,7 @@ static void fat_itr_child(fat_itr *itr, fat_itr *parent)
> > >  	itr->last_cluster = 0;
> > >  }
> > >  
> > > -static void *next_cluster(fat_itr *itr)
> > > +void *next_cluster(fat_itr *itr)
> > >  {
> > >  	fsdata *mydata = itr->fsdata;  /* for silly macros */
> > >  	int ret;
> > > @@ -834,7 +815,7 @@ static dir_entry *extract_vfat_name(fat_itr *itr)
> > >   * @return boolean, 1 if success or 0 if no more entries in the
> > >   *    current directory
> > >   */
> > > -static int fat_itr_next(fat_itr *itr)
> > > +int fat_itr_next(fat_itr *itr)
> > >  {
> > >  	dir_entry *dent;
> > >  
> > > @@ -879,19 +860,11 @@ static int fat_itr_next(fat_itr *itr)
> > >   * @itr: the iterator
> > >   * @return true if cursor is at a directory
> > >   */
> > > -static int fat_itr_isdir(fat_itr *itr)
> > > +int fat_itr_isdir(fat_itr *itr)
> > >  {
> > >  	return !!(itr->dent->attr & ATTR_DIR);
> > >  }
> > >  
> > > -/*
> > > - * Helpers:
> > > - */
> > > -
> > > -#define TYPE_FILE 0x1
> > > -#define TYPE_DIR  0x2
> > > -#define TYPE_ANY  (TYPE_FILE | TYPE_DIR)
> > > -
> > >  /**
> > >   * fat_itr_resolve() - traverse directory structure to resolve the
> > >   * requested path.
> > > @@ -907,7 +880,7 @@ static int fat_itr_isdir(fat_itr *itr)
> > >   * @type: bitmask of allowable file types
> > >   * @return 0 on success or -errno
> > >   */
> > > -static int fat_itr_resolve(fat_itr *itr, const char *path, unsigned type)
> > > +int fat_itr_resolve(fat_itr *itr, const char *path, unsigned type)
> > >  {
> > >  	const char *next;
> > >  
> > > diff --git a/include/fat.h b/include/fat.h
> > > index 0c88b59a4a..577e6b4592 100644
> > > --- a/include/fat.h
> > > +++ b/include/fat.h
> > > @@ -187,6 +187,38 @@ static inline u32 sect_to_clust(fsdata *fsdata, int sect)
> > >  	return (sect - fsdata->data_begin) / fsdata->clust_size;
> > >  }
> > >  
> > > +/*
> > > + * Directory iterator
> > > + */
> > > +
> > > +#define TYPE_FILE 0x1
> > > +#define TYPE_DIR  0x2
> > > +#define TYPE_ANY  (TYPE_FILE | TYPE_DIR)
> > 
> > Please, rename these to something more specific like FS_ITER_ANY.
> > 
> > TYPE_ANY already is defined in fs/reiserfs/reiserfs_private.h:
> > 
> > fs/reiserfs/reiserfs_private.h:160:#define TYPE_ANY 15
> 
> Good catch though the definition above comes directly from Rob's
> original patch.

Oops, looking at the code closely, the duplication will never be hit
because reiserfs_private.h is a private header.

> Since there is only one occurrence of TYPE_ANY in fs/fat,
> I'd rather expand it without introducing another definition.

I will put this change on hold unless a maintainer sticks to this idea.

> Thanks,
> -Takahiro AKASHI
> 
> 
> > Best regards
> > 
> > Heinrich
> > 
> > > +
> > > +typedef struct {
> > > +	fsdata    *fsdata;        /* filesystem parameters */
> > > +	unsigned   clust;         /* current cluster */
> > > +	int        last_cluster;  /* set once we've read last cluster */
> > > +	int        is_root;       /* is iterator at root directory */
> > > +	int        remaining;     /* remaining dent's in current cluster */
> > > +
> > > +	/* current iterator position values: */
> > > +	dir_entry *dent;          /* current directory entry */
> > > +	char       l_name[VFAT_MAXLEN_BYTES];    /* long (vfat) name */
> > > +	char       s_name[14];    /* short 8.3 name */
> > > +	char      *name;          /* l_name if there is one, else s_name */
> > > +
> > > +	/* storage for current cluster in memory: */
> > > +	u8         block[MAX_CLUSTSIZE] __aligned(ARCH_DMA_MINALIGN);
> > > +} fat_itr;
> > > +
> > > +int fat_itr_root(fat_itr *itr, fsdata *fsdata);
> > > +void fat_itr_child(fat_itr *itr, fat_itr *parent);
> > > +void *next_cluster(fat_itr *itr);
> > > +int fat_itr_next(fat_itr *itr);
> > > +int fat_itr_isdir(fat_itr *itr);
> > > +int fat_itr_resolve(fat_itr *itr, const char *path, unsigned type);
> > > +
> > >  int file_fat_detectfs(void);
> > >  int fat_exists(const char *filename);
> > >  int fat_size(const char *filename, loff_t *size);
> > > 
> >
Heinrich Schuchardt Aug. 11, 2018, 1:34 p.m. UTC | #4
On 07/20/2018 04:57 AM, AKASHI Takahiro wrote:
> Directory iterator was introduced in major re-work of read operation by
> Rob. We want to use it for write operation extensively as well.
> This patch makes relevant functions, as well as iterator defition, visible
> outside of fat.c.
> 
> Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
> ---
>  fs/fat/fat.c  | 39 ++++++---------------------------------
>  include/fat.h | 32 ++++++++++++++++++++++++++++++++
>  2 files changed, 38 insertions(+), 33 deletions(-)
> 
> diff --git a/fs/fat/fat.c b/fs/fat/fat.c
> index fd6523c66b..0f82cbe1bd 100644
> --- a/fs/fat/fat.c
> +++ b/fs/fat/fat.c
> @@ -634,25 +634,6 @@ static int get_fs_info(fsdata *mydata)
>   * For more complete example, see fat_itr_resolve()
>   */
>  
> -typedef struct {
> -	fsdata    *fsdata;        /* filesystem parameters */
> -	unsigned   clust;         /* current cluster */
> -	int        last_cluster;  /* set once we've read last cluster */
> -	int        is_root;       /* is iterator at root directory */
> -	int        remaining;     /* remaining dent's in current cluster */
> -
> -	/* current iterator position values: */
> -	dir_entry *dent;          /* current directory entry */
> -	char       l_name[VFAT_MAXLEN_BYTES];    /* long (vfat) name */
> -	char       s_name[14];    /* short 8.3 name */
> -	char      *name;          /* l_name if there is one, else s_name */
> -
> -	/* storage for current cluster in memory: */
> -	u8         block[MAX_CLUSTSIZE] __aligned(ARCH_DMA_MINALIGN);
> -} fat_itr;
> -
> -static int fat_itr_isdir(fat_itr *itr);
> -
>  /**
>   * fat_itr_root() - initialize an iterator to start at the root
>   * directory
> @@ -661,7 +642,7 @@ static int fat_itr_isdir(fat_itr *itr);
>   * @fsdata: filesystem data for the partition
>   * @return 0 on success, else -errno
>   */
> -static int fat_itr_root(fat_itr *itr, fsdata *fsdata)
> +int fat_itr_root(fat_itr *itr, fsdata *fsdata)
>  {
>  	if (get_fs_info(fsdata))
>  		return -ENXIO;
> @@ -693,7 +674,7 @@ static int fat_itr_root(fat_itr *itr, fsdata *fsdata)
>   * @parent: the iterator pointing at a directory entry in the
>   *    parent directory of the directory to iterate
>   */
> -static void fat_itr_child(fat_itr *itr, fat_itr *parent)
> +void fat_itr_child(fat_itr *itr, fat_itr *parent)
>  {
>  	fsdata *mydata = parent->fsdata;  /* for silly macros */
>  	unsigned clustnum = START(parent->dent);
> @@ -713,7 +694,7 @@ static void fat_itr_child(fat_itr *itr, fat_itr *parent)
>  	itr->last_cluster = 0;
>  }
>  
> -static void *next_cluster(fat_itr *itr)
> +void *next_cluster(fat_itr *itr)
>  {
>  	fsdata *mydata = itr->fsdata;  /* for silly macros */
>  	int ret;
> @@ -834,7 +815,7 @@ static dir_entry *extract_vfat_name(fat_itr *itr)
>   * @return boolean, 1 if success or 0 if no more entries in the
>   *    current directory
>   */
> -static int fat_itr_next(fat_itr *itr)
> +int fat_itr_next(fat_itr *itr)
>  {
>  	dir_entry *dent;
>  
> @@ -879,19 +860,11 @@ static int fat_itr_next(fat_itr *itr)
>   * @itr: the iterator
>   * @return true if cursor is at a directory
>   */
> -static int fat_itr_isdir(fat_itr *itr)
> +int fat_itr_isdir(fat_itr *itr)
>  {
>  	return !!(itr->dent->attr & ATTR_DIR);
>  }
>  
> -/*
> - * Helpers:
> - */
> -
> -#define TYPE_FILE 0x1
> -#define TYPE_DIR  0x2
> -#define TYPE_ANY  (TYPE_FILE | TYPE_DIR)
> -
>  /**
>   * fat_itr_resolve() - traverse directory structure to resolve the
>   * requested path.
> @@ -907,7 +880,7 @@ static int fat_itr_isdir(fat_itr *itr)
>   * @type: bitmask of allowable file types
>   * @return 0 on success or -errno
>   */
> -static int fat_itr_resolve(fat_itr *itr, const char *path, unsigned type)
> +int fat_itr_resolve(fat_itr *itr, const char *path, unsigned type)
>  {
>  	const char *next;
>  
> diff --git a/include/fat.h b/include/fat.h
> index 0c88b59a4a..577e6b4592 100644
> --- a/include/fat.h
> +++ b/include/fat.h
> @@ -187,6 +187,38 @@ static inline u32 sect_to_clust(fsdata *fsdata, int sect)
>  	return (sect - fsdata->data_begin) / fsdata->clust_size;
>  }
>  
> +/*
> + * Directory iterator
> + */
> +
> +#define TYPE_FILE 0x1
> +#define TYPE_DIR  0x2
> +#define TYPE_ANY  (TYPE_FILE | TYPE_DIR)
> +
> +typedef struct {
> +	fsdata    *fsdata;        /* filesystem parameters */
> +	unsigned   clust;         /* current cluster */
> +	int        last_cluster;  /* set once we've read last cluster */
> +	int        is_root;       /* is iterator at root directory */
> +	int        remaining;     /* remaining dent's in current cluster */
> +
> +	/* current iterator position values: */
> +	dir_entry *dent;          /* current directory entry */
> +	char       l_name[VFAT_MAXLEN_BYTES];    /* long (vfat) name */
> +	char       s_name[14];    /* short 8.3 name */
> +	char      *name;          /* l_name if there is one, else s_name */
> +
> +	/* storage for current cluster in memory: */
> +	u8         block[MAX_CLUSTSIZE] __aligned(ARCH_DMA_MINALIGN);

If CONFIG_FAT is not set, MAX_CLUSTSIZE is empty. And you get a build error:

  CC      fs/fs.o
In file included from fs/fs.c:12:0:
include/fat.h:20:23: error: ‘CONFIG_FS_FAT_MAX_CLUSTSIZE’ undeclared
here (not in a function); did you mean ‘CONFIG_SYS_MAX_FLASH_SECT’?
 #define MAX_CLUSTSIZE CONFIG_FS_FAT_MAX_CLUSTSIZE
                       ^
include/fat.h:214:19: note: in expansion of macro ‘MAX_CLUSTSIZE’
  u8         block[MAX_CLUSTSIZE] __aligned(ARCH_DMA_MINALIGN);
                   ^~~~~~~~~~~~~
make[1]: *** [scripts/Makefile.build:279: fs/fs.o] Error 1

We should not assume that every board uses FAT.

Best regards

Heinrich

> +} fat_itr;
> +
> +int fat_itr_root(fat_itr *itr, fsdata *fsdata);
> +void fat_itr_child(fat_itr *itr, fat_itr *parent);
> +void *next_cluster(fat_itr *itr);
> +int fat_itr_next(fat_itr *itr);
> +int fat_itr_isdir(fat_itr *itr);
> +int fat_itr_resolve(fat_itr *itr, const char *path, unsigned type);
> +
>  int file_fat_detectfs(void);
>  int fat_exists(const char *filename);
>  int fat_size(const char *filename, loff_t *size);
>
AKASHI Takahiro Aug. 20, 2018, 4:45 a.m. UTC | #5
On Sat, Aug 11, 2018 at 03:34:20PM +0200, Heinrich Schuchardt wrote:
> On 07/20/2018 04:57 AM, AKASHI Takahiro wrote:
> > Directory iterator was introduced in major re-work of read operation by
> > Rob. We want to use it for write operation extensively as well.
> > This patch makes relevant functions, as well as iterator defition, visible
> > outside of fat.c.
> > 
> > Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
> > ---
> >  fs/fat/fat.c  | 39 ++++++---------------------------------
> >  include/fat.h | 32 ++++++++++++++++++++++++++++++++
> >  2 files changed, 38 insertions(+), 33 deletions(-)
> > 
> > diff --git a/fs/fat/fat.c b/fs/fat/fat.c
> > index fd6523c66b..0f82cbe1bd 100644
> > --- a/fs/fat/fat.c
> > +++ b/fs/fat/fat.c
> > @@ -634,25 +634,6 @@ static int get_fs_info(fsdata *mydata)
> >   * For more complete example, see fat_itr_resolve()
> >   */
> >  
> > -typedef struct {
> > -	fsdata    *fsdata;        /* filesystem parameters */
> > -	unsigned   clust;         /* current cluster */
> > -	int        last_cluster;  /* set once we've read last cluster */
> > -	int        is_root;       /* is iterator at root directory */
> > -	int        remaining;     /* remaining dent's in current cluster */
> > -
> > -	/* current iterator position values: */
> > -	dir_entry *dent;          /* current directory entry */
> > -	char       l_name[VFAT_MAXLEN_BYTES];    /* long (vfat) name */
> > -	char       s_name[14];    /* short 8.3 name */
> > -	char      *name;          /* l_name if there is one, else s_name */
> > -
> > -	/* storage for current cluster in memory: */
> > -	u8         block[MAX_CLUSTSIZE] __aligned(ARCH_DMA_MINALIGN);
> > -} fat_itr;
> > -
> > -static int fat_itr_isdir(fat_itr *itr);
> > -
> >  /**
> >   * fat_itr_root() - initialize an iterator to start at the root
> >   * directory
> > @@ -661,7 +642,7 @@ static int fat_itr_isdir(fat_itr *itr);
> >   * @fsdata: filesystem data for the partition
> >   * @return 0 on success, else -errno
> >   */
> > -static int fat_itr_root(fat_itr *itr, fsdata *fsdata)
> > +int fat_itr_root(fat_itr *itr, fsdata *fsdata)
> >  {
> >  	if (get_fs_info(fsdata))
> >  		return -ENXIO;
> > @@ -693,7 +674,7 @@ static int fat_itr_root(fat_itr *itr, fsdata *fsdata)
> >   * @parent: the iterator pointing at a directory entry in the
> >   *    parent directory of the directory to iterate
> >   */
> > -static void fat_itr_child(fat_itr *itr, fat_itr *parent)
> > +void fat_itr_child(fat_itr *itr, fat_itr *parent)
> >  {
> >  	fsdata *mydata = parent->fsdata;  /* for silly macros */
> >  	unsigned clustnum = START(parent->dent);
> > @@ -713,7 +694,7 @@ static void fat_itr_child(fat_itr *itr, fat_itr *parent)
> >  	itr->last_cluster = 0;
> >  }
> >  
> > -static void *next_cluster(fat_itr *itr)
> > +void *next_cluster(fat_itr *itr)
> >  {
> >  	fsdata *mydata = itr->fsdata;  /* for silly macros */
> >  	int ret;
> > @@ -834,7 +815,7 @@ static dir_entry *extract_vfat_name(fat_itr *itr)
> >   * @return boolean, 1 if success or 0 if no more entries in the
> >   *    current directory
> >   */
> > -static int fat_itr_next(fat_itr *itr)
> > +int fat_itr_next(fat_itr *itr)
> >  {
> >  	dir_entry *dent;
> >  
> > @@ -879,19 +860,11 @@ static int fat_itr_next(fat_itr *itr)
> >   * @itr: the iterator
> >   * @return true if cursor is at a directory
> >   */
> > -static int fat_itr_isdir(fat_itr *itr)
> > +int fat_itr_isdir(fat_itr *itr)
> >  {
> >  	return !!(itr->dent->attr & ATTR_DIR);
> >  }
> >  
> > -/*
> > - * Helpers:
> > - */
> > -
> > -#define TYPE_FILE 0x1
> > -#define TYPE_DIR  0x2
> > -#define TYPE_ANY  (TYPE_FILE | TYPE_DIR)
> > -
> >  /**
> >   * fat_itr_resolve() - traverse directory structure to resolve the
> >   * requested path.
> > @@ -907,7 +880,7 @@ static int fat_itr_isdir(fat_itr *itr)
> >   * @type: bitmask of allowable file types
> >   * @return 0 on success or -errno
> >   */
> > -static int fat_itr_resolve(fat_itr *itr, const char *path, unsigned type)
> > +int fat_itr_resolve(fat_itr *itr, const char *path, unsigned type)
> >  {
> >  	const char *next;
> >  
> > diff --git a/include/fat.h b/include/fat.h
> > index 0c88b59a4a..577e6b4592 100644
> > --- a/include/fat.h
> > +++ b/include/fat.h
> > @@ -187,6 +187,38 @@ static inline u32 sect_to_clust(fsdata *fsdata, int sect)
> >  	return (sect - fsdata->data_begin) / fsdata->clust_size;
> >  }
> >  
> > +/*
> > + * Directory iterator
> > + */
> > +
> > +#define TYPE_FILE 0x1
> > +#define TYPE_DIR  0x2
> > +#define TYPE_ANY  (TYPE_FILE | TYPE_DIR)
> > +
> > +typedef struct {
> > +	fsdata    *fsdata;        /* filesystem parameters */
> > +	unsigned   clust;         /* current cluster */
> > +	int        last_cluster;  /* set once we've read last cluster */
> > +	int        is_root;       /* is iterator at root directory */
> > +	int        remaining;     /* remaining dent's in current cluster */
> > +
> > +	/* current iterator position values: */
> > +	dir_entry *dent;          /* current directory entry */
> > +	char       l_name[VFAT_MAXLEN_BYTES];    /* long (vfat) name */
> > +	char       s_name[14];    /* short 8.3 name */
> > +	char      *name;          /* l_name if there is one, else s_name */
> > +
> > +	/* storage for current cluster in memory: */
> > +	u8         block[MAX_CLUSTSIZE] __aligned(ARCH_DMA_MINALIGN);
> 
> If CONFIG_FAT is not set, MAX_CLUSTSIZE is empty. And you get a build error:
> 
>   CC      fs/fs.o
> In file included from fs/fs.c:12:0:
> include/fat.h:20:23: error: ‘CONFIG_FS_FAT_MAX_CLUSTSIZE’ undeclared
> here (not in a function); did you mean ‘CONFIG_SYS_MAX_FLASH_SECT’?
>  #define MAX_CLUSTSIZE CONFIG_FS_FAT_MAX_CLUSTSIZE
>                        ^
> include/fat.h:214:19: note: in expansion of macro ‘MAX_CLUSTSIZE’
>   u8         block[MAX_CLUSTSIZE] __aligned(ARCH_DMA_MINALIGN);
>                    ^~~~~~~~~~~~~
> make[1]: *** [scripts/Makefile.build:279: fs/fs.o] Error 1

Thank you for catching this.

> We should not assume that every board uses FAT.

The contents of include/fat.h is totally private to fat implementation.
So I'd like to guard this include file like:

#ifndef _FAT_H
#define _FAT_H

#ifdef CONFIG_FS_FAT

<fat definitions>...

#endif /* CONFIG_FS_FAT */

#endif /* _FAT_H */

-Takahiro AKASHI

> Best regards
> 
> Heinrich
> 
> > +} fat_itr;
> > +
> > +int fat_itr_root(fat_itr *itr, fsdata *fsdata);
> > +void fat_itr_child(fat_itr *itr, fat_itr *parent);
> > +void *next_cluster(fat_itr *itr);
> > +int fat_itr_next(fat_itr *itr);
> > +int fat_itr_isdir(fat_itr *itr);
> > +int fat_itr_resolve(fat_itr *itr, const char *path, unsigned type);
> > +
> >  int file_fat_detectfs(void);
> >  int fat_exists(const char *filename);
> >  int fat_size(const char *filename, loff_t *size);
> > 
>
diff mbox series

Patch

diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index fd6523c66b..0f82cbe1bd 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -634,25 +634,6 @@  static int get_fs_info(fsdata *mydata)
  * For more complete example, see fat_itr_resolve()
  */
 
-typedef struct {
-	fsdata    *fsdata;        /* filesystem parameters */
-	unsigned   clust;         /* current cluster */
-	int        last_cluster;  /* set once we've read last cluster */
-	int        is_root;       /* is iterator at root directory */
-	int        remaining;     /* remaining dent's in current cluster */
-
-	/* current iterator position values: */
-	dir_entry *dent;          /* current directory entry */
-	char       l_name[VFAT_MAXLEN_BYTES];    /* long (vfat) name */
-	char       s_name[14];    /* short 8.3 name */
-	char      *name;          /* l_name if there is one, else s_name */
-
-	/* storage for current cluster in memory: */
-	u8         block[MAX_CLUSTSIZE] __aligned(ARCH_DMA_MINALIGN);
-} fat_itr;
-
-static int fat_itr_isdir(fat_itr *itr);
-
 /**
  * fat_itr_root() - initialize an iterator to start at the root
  * directory
@@ -661,7 +642,7 @@  static int fat_itr_isdir(fat_itr *itr);
  * @fsdata: filesystem data for the partition
  * @return 0 on success, else -errno
  */
-static int fat_itr_root(fat_itr *itr, fsdata *fsdata)
+int fat_itr_root(fat_itr *itr, fsdata *fsdata)
 {
 	if (get_fs_info(fsdata))
 		return -ENXIO;
@@ -693,7 +674,7 @@  static int fat_itr_root(fat_itr *itr, fsdata *fsdata)
  * @parent: the iterator pointing at a directory entry in the
  *    parent directory of the directory to iterate
  */
-static void fat_itr_child(fat_itr *itr, fat_itr *parent)
+void fat_itr_child(fat_itr *itr, fat_itr *parent)
 {
 	fsdata *mydata = parent->fsdata;  /* for silly macros */
 	unsigned clustnum = START(parent->dent);
@@ -713,7 +694,7 @@  static void fat_itr_child(fat_itr *itr, fat_itr *parent)
 	itr->last_cluster = 0;
 }
 
-static void *next_cluster(fat_itr *itr)
+void *next_cluster(fat_itr *itr)
 {
 	fsdata *mydata = itr->fsdata;  /* for silly macros */
 	int ret;
@@ -834,7 +815,7 @@  static dir_entry *extract_vfat_name(fat_itr *itr)
  * @return boolean, 1 if success or 0 if no more entries in the
  *    current directory
  */
-static int fat_itr_next(fat_itr *itr)
+int fat_itr_next(fat_itr *itr)
 {
 	dir_entry *dent;
 
@@ -879,19 +860,11 @@  static int fat_itr_next(fat_itr *itr)
  * @itr: the iterator
  * @return true if cursor is at a directory
  */
-static int fat_itr_isdir(fat_itr *itr)
+int fat_itr_isdir(fat_itr *itr)
 {
 	return !!(itr->dent->attr & ATTR_DIR);
 }
 
-/*
- * Helpers:
- */
-
-#define TYPE_FILE 0x1
-#define TYPE_DIR  0x2
-#define TYPE_ANY  (TYPE_FILE | TYPE_DIR)
-
 /**
  * fat_itr_resolve() - traverse directory structure to resolve the
  * requested path.
@@ -907,7 +880,7 @@  static int fat_itr_isdir(fat_itr *itr)
  * @type: bitmask of allowable file types
  * @return 0 on success or -errno
  */
-static int fat_itr_resolve(fat_itr *itr, const char *path, unsigned type)
+int fat_itr_resolve(fat_itr *itr, const char *path, unsigned type)
 {
 	const char *next;
 
diff --git a/include/fat.h b/include/fat.h
index 0c88b59a4a..577e6b4592 100644
--- a/include/fat.h
+++ b/include/fat.h
@@ -187,6 +187,38 @@  static inline u32 sect_to_clust(fsdata *fsdata, int sect)
 	return (sect - fsdata->data_begin) / fsdata->clust_size;
 }
 
+/*
+ * Directory iterator
+ */
+
+#define TYPE_FILE 0x1
+#define TYPE_DIR  0x2
+#define TYPE_ANY  (TYPE_FILE | TYPE_DIR)
+
+typedef struct {
+	fsdata    *fsdata;        /* filesystem parameters */
+	unsigned   clust;         /* current cluster */
+	int        last_cluster;  /* set once we've read last cluster */
+	int        is_root;       /* is iterator at root directory */
+	int        remaining;     /* remaining dent's in current cluster */
+
+	/* current iterator position values: */
+	dir_entry *dent;          /* current directory entry */
+	char       l_name[VFAT_MAXLEN_BYTES];    /* long (vfat) name */
+	char       s_name[14];    /* short 8.3 name */
+	char      *name;          /* l_name if there is one, else s_name */
+
+	/* storage for current cluster in memory: */
+	u8         block[MAX_CLUSTSIZE] __aligned(ARCH_DMA_MINALIGN);
+} fat_itr;
+
+int fat_itr_root(fat_itr *itr, fsdata *fsdata);
+void fat_itr_child(fat_itr *itr, fat_itr *parent);
+void *next_cluster(fat_itr *itr);
+int fat_itr_next(fat_itr *itr);
+int fat_itr_isdir(fat_itr *itr);
+int fat_itr_resolve(fat_itr *itr, const char *path, unsigned type);
+
 int file_fat_detectfs(void);
 int fat_exists(const char *filename);
 int fat_size(const char *filename, loff_t *size);