2020-10-29 11:05:38

by Alejandro Colomar

[permalink] [raw]
Subject: Re: [PATCH] getdents.2: Use 'ssize_t' instead of 'int'

[[ CC += linux-kernel, libc-alpha ]]

Hi Michael,

On 2020-10-29 08:13, Michael Kerrisk (man-pages) wrote:
> Hi Alex,
>
> On 10/28/20 11:11 PM, Alejandro Colomar wrote:
>> The glibc wrapper for getdents64() uses ssize_t.
>
> It also changed the types for the arguments, so those need to be
> fixed too.

I saw that, but I sent an email to glibc asking if it was a bug.
I'll hold this patch, and I'll CC this list in that other thread.

>
>> And let's use it also for getdents().
>
> I actually think we should *not* change that. So long as their is
> no wrapper, we should show pretty much what the ABI exposes. (That
> makes me think that the return type should really be long; see
> what you think about DEFINE_SYSCALL3 in the kernel sources.)

Agreed; then getdents() (and all syscalls without a wrapper)
should use 'long', as you said.

BTW: My mind explodes when I try to read through SYSCALL_DEFINEx :)

>
> And you added an include for <sys/types.h>. I'm not sure
> whether that's needed, but it should be explained in the
> commit message.

Agreed.
I should be able to check if it's needed, in ssize_t(3) :p
... Actually it's not needed (<stdio.h> already provides it).

Thanks,

Alex


2020-10-29 13:46:05

by Alejandro Colomar

[permalink] [raw]
Subject: [PATCH v2] getdents.2: Use appropriate types

getdents():
This function has no glibc wrapper.
As such, we should use the same types the Linux kernel uses:
Use 'long' as the return type.

getdents64():
The glibc wrapper uses ssize_t for the return type,
and 'size_t' for the count argument.

Signed-off-by: Alejandro Colomar <[email protected]>
---
man2/getdents.2 | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/man2/getdents.2 b/man2/getdents.2
index a187fbcef..e14627e6e 100644
--- a/man2/getdents.2
+++ b/man2/getdents.2
@@ -33,14 +33,14 @@
getdents, getdents64 \- get directory entries
.SH SYNOPSIS
.nf
-.BI "int getdents(unsigned int " fd ", struct linux_dirent *" dirp ,
+.BI "long getdents(unsigned int " fd ", struct linux_dirent *" dirp ,
.BI " unsigned int " count );
.PP
.BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
.B #include <dirent.h>
.PP
-.BI "int getdents64(unsigned int " fd ", struct linux_dirent64 *" dirp ,
-.BI " unsigned int " count );
+.BI "ssize_t getdents64(unsigned int " fd ", struct linux_dirent64 *" dirp ,
+.BI " size_t " count );
.fi
.PP
.IR Note :
@@ -282,7 +282,8 @@ struct linux_dirent {
int
main(int argc, char *argv[])
{
- int fd, nread;
+ int fd;
+ long nread;
char buf[BUF_SIZE];
struct linux_dirent *d;
char d_type;
@@ -301,7 +302,7 @@ main(int argc, char *argv[])

printf("\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- nread=%d \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\en", nread);
printf("inode# file type d_reclen d_off d_name\en");
- for (int bpos = 0; bpos < nread;) {
+ for (long bpos = 0; bpos < nread;) {
d = (struct linux_dirent *) (buf + bpos);
printf("%8ld ", d\->d_ino);
d_type = *(buf + bpos + d\->d_reclen \- 1);
--
2.28.0

Subject: Re: [PATCH v2] getdents.2: Use appropriate types

Hi Alex,

On Thu, 29 Oct 2020 at 14:42, Alejandro Colomar <[email protected]> wrote:
>
> getdents():
> This function has no glibc wrapper.
> As such, we should use the same types the Linux kernel uses:
> Use 'long' as the return type.
>
> getdents64():
> The glibc wrapper uses ssize_t for the return type,
> and 'size_t' for the count argument.

Take a look in the header file at the argument types for getdents64();
there's still some changes needed.

Thanks,

Michael


> Signed-off-by: Alejandro Colomar <[email protected]>
> ---
> man2/getdents.2 | 11 ++++++-----
> 1 file changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/man2/getdents.2 b/man2/getdents.2
> index a187fbcef..e14627e6e 100644
> --- a/man2/getdents.2
> +++ b/man2/getdents.2
> @@ -33,14 +33,14 @@
> getdents, getdents64 \- get directory entries
> .SH SYNOPSIS
> .nf
> -.BI "int getdents(unsigned int " fd ", struct linux_dirent *" dirp ,
> +.BI "long getdents(unsigned int " fd ", struct linux_dirent *" dirp ,
> .BI " unsigned int " count );
> .PP
> .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
> .B #include <dirent.h>
> .PP
> -.BI "int getdents64(unsigned int " fd ", struct linux_dirent64 *" dirp ,
> -.BI " unsigned int " count );
> +.BI "ssize_t getdents64(unsigned int " fd ", struct linux_dirent64 *" dirp ,
> +.BI " size_t " count );
> .fi
> .PP
> .IR Note :
> @@ -282,7 +282,8 @@ struct linux_dirent {
> int
> main(int argc, char *argv[])
> {
> - int fd, nread;
> + int fd;
> + long nread;
> char buf[BUF_SIZE];
> struct linux_dirent *d;
> char d_type;
> @@ -301,7 +302,7 @@ main(int argc, char *argv[])
>
> printf("\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- nread=%d \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\en", nread);
> printf("inode# file type d_reclen d_off d_name\en");
> - for (int bpos = 0; bpos < nread;) {
> + for (long bpos = 0; bpos < nread;) {
> d = (struct linux_dirent *) (buf + bpos);
> printf("%8ld ", d\->d_ino);
> d_type = *(buf + bpos + d\->d_reclen \- 1);
> --
> 2.28.0
>


--
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/

2020-10-29 14:15:12

by Alejandro Colomar

[permalink] [raw]
Subject: [PATCH v3] getdents.2: Use appropriate types

getdents():
This function has no glibc wrapper.
As such, we should use the same types the Linux kernel uses:
Use 'long' as the return type.

getdents64():
The glibc wrapper uses:
ssize_t getdents64(int, void *, size_t);

Signed-off-by: Alejandro Colomar <[email protected]>
---

Hi Michael,

Sorry, I'm being a bit distracted these days :)
It should be good enough now, I think.

Cheers,

Alex

man2/getdents.2 | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/man2/getdents.2 b/man2/getdents.2
index a187fbcef..ed3bb40b1 100644
--- a/man2/getdents.2
+++ b/man2/getdents.2
@@ -33,14 +33,13 @@
getdents, getdents64 \- get directory entries
.SH SYNOPSIS
.nf
-.BI "int getdents(unsigned int " fd ", struct linux_dirent *" dirp ,
+.BI "long getdents(unsigned int " fd ", struct linux_dirent *" dirp ,
.BI " unsigned int " count );
.PP
.BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
.B #include <dirent.h>
.PP
-.BI "int getdents64(unsigned int " fd ", struct linux_dirent64 *" dirp ,
-.BI " unsigned int " count );
+.BI "ssize_t getdents64(int " fd ", void *" dirp ", size_t " count );
.fi
.PP
.IR Note :
@@ -282,7 +281,8 @@ struct linux_dirent {
int
main(int argc, char *argv[])
{
- int fd, nread;
+ int fd;
+ long nread;
char buf[BUF_SIZE];
struct linux_dirent *d;
char d_type;
@@ -301,7 +301,7 @@ main(int argc, char *argv[])

printf("\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- nread=%d \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\en", nread);
printf("inode# file type d_reclen d_off d_name\en");
- for (int bpos = 0; bpos < nread;) {
+ for (long bpos = 0; bpos < nread;) {
d = (struct linux_dirent *) (buf + bpos);
printf("%8ld ", d\->d_ino);
d_type = *(buf + bpos + d\->d_reclen \- 1);
--
2.28.0

Subject: Re: [PATCH v3] getdents.2: Use appropriate types

On 10/29/20 3:10 PM, Alejandro Colomar wrote:
> getdents():
> This function has no glibc wrapper.
> As such, we should use the same types the Linux kernel uses:
> Use 'long' as the return type.
>
> getdents64():
> The glibc wrapper uses:
> ssize_t getdents64(int, void *, size_t);
>
> Signed-off-by: Alejandro Colomar <[email protected]>

Thanks, Alex. Applied.

Cheers,

Michael


> ---
>
> Hi Michael,
>
> Sorry, I'm being a bit distracted these days :)
> It should be good enough now, I think.
>
> Cheers,
>
> Alex
>
> man2/getdents.2 | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/man2/getdents.2 b/man2/getdents.2
> index a187fbcef..ed3bb40b1 100644
> --- a/man2/getdents.2
> +++ b/man2/getdents.2
> @@ -33,14 +33,13 @@
> getdents, getdents64 \- get directory entries
> .SH SYNOPSIS
> .nf
> -.BI "int getdents(unsigned int " fd ", struct linux_dirent *" dirp ,
> +.BI "long getdents(unsigned int " fd ", struct linux_dirent *" dirp ,
> .BI " unsigned int " count );
> .PP
> .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
> .B #include <dirent.h>
> .PP
> -.BI "int getdents64(unsigned int " fd ", struct linux_dirent64 *" dirp ,
> -.BI " unsigned int " count );
> +.BI "ssize_t getdents64(int " fd ", void *" dirp ", size_t " count );
> .fi
> .PP
> .IR Note :
> @@ -282,7 +281,8 @@ struct linux_dirent {
> int
> main(int argc, char *argv[])
> {
> - int fd, nread;
> + int fd;
> + long nread;
> char buf[BUF_SIZE];
> struct linux_dirent *d;
> char d_type;
> @@ -301,7 +301,7 @@ main(int argc, char *argv[])
>
> printf("\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- nread=%d \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\en", nread);
> printf("inode# file type d_reclen d_off d_name\en");
> - for (int bpos = 0; bpos < nread;) {
> + for (long bpos = 0; bpos < nread;) {
> d = (struct linux_dirent *) (buf + bpos);
> printf("%8ld ", d\->d_ino);
> d_type = *(buf + bpos + d\->d_reclen \- 1);
>


--
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/