Re: [PATCH -V6 0/8] Generic name to handle and open by handle syscalls

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2010-04-27, at 10:13, Aneesh Kumar K.V wrote:
> Changes from V5:
> a) added sys_name_to_handle_at syscall which takes AT_SYMLINK_NOFOLLOW flag 
>   instead of two syscalls sys_name_to_handle and sys_lname_to_handle.
> 
> #define AT_FDCWD		-100
> #define AT_SYMLINK_NOFOLLOW	0x100
> 
> static int name_to_handle(const char *name, struct file_handle  *fh)
> {
> 	return syscall(338, AT_FDCWD, name, fh, 0);
> }
> 
> static int lname_to_handle(const char *name, struct file_handle  *fh)
> {
> 	return syscall(338, AT_FDCWD, name, fh, AT_SYMLINK_NOFOLLOW);
> }
> 
> static int open_by_handle(struct file_handle *fh,  int flags)
> {
> 	return syscall(339, fh, flags);
> }
> 
> static int freadlink(int fd, char *buf, size_t bufsiz)
> {
> 	return syscall(340, fd, buf, bufsiz);
> }

Your example, while #defining the AT_* stuff, did not actually change to use the _at() interface.

> #define BUFSZ 100
> int main(int argc, char *argv[])
> {
>        int ret;
> 	int handle_sz;
> 	struct stat bufstat;
>        int fd, dirfd;
>        char buf[BUFSZ];
>        struct file_handle *fh = NULL;;
> again:
> 	if (fh && fh->handle_size) {
> 		handle_sz = fh->handle_size;
> 		free(fh);
> 		fh = malloc(sizeof(struct file_handle) + handle_sz);
> 		fh->handle_size = handle_sz;
> 	} else {
> 		fh = malloc(sizeof(struct file_handle));
> 		fh->handle_size = 0;
> 	}
>        errno  = 0;
>        ret = lname_to_handle(argv[1], fh);
>        if (ret && errno == EOVERFLOW) {
>                perror("Error:");
> 		printf("Found the handle size needed to be %d\n", fh->handle_size);
> 		printf("Trying again..\n");
> 		goto again;
>        } else if (ret) {
>                perror("Error:");
> 		exit(1);
> 	}
>        fd = open_by_handle(fh, O_RDONLY);
>        if (fd <= 0 ) {
>                perror("Error:");
>                exit(1);
>        }
> 	fstat(fd, &bufstat);
> 	ret = S_ISLNK(bufstat.st_mode);
> 	if (ret) {
> 	        memset(buf, 0 , BUFSZ);
> 		freadlink(fd, buf, BUFSZ);
> 		printf("%s is a symlink pointing to %s\n", argv[1], buf);
> 	}
>        memset(buf, 0 , BUFSZ);
> 	while (1) {
> 		ret = read(fd, buf, BUFSZ -1);
> 		if (ret <= 0)
> 			break;
> 		buf[ret] = '\0';
>                printf("%s", buf);
>                memset(buf, 0 , BUFSZ);
>        }
>        return 0;
> }


Cheers, Andreas
--
Andreas Dilger
Lustre Technical Lead
Oracle Corporation Canada Inc.

--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]
  Powered by Linux