EXAMPLES: convert remaining nfs_[f]stat to nfs_[f]stat64

The old nfs_[f]stat calls are deprecated. Convert to the newer
nfs_[f]stat64 call that takes struct nfs_stat_64

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
libnfs-4.0.0-vitalif
Ronnie Sahlberg 2015-05-24 07:38:17 -07:00
parent 6f2727468d
commit ec3a3afeae
5 changed files with 99 additions and 76 deletions

View File

@ -422,28 +422,31 @@ int __fxstat(int ver, int fd, struct stat *buf)
{
if (nfs_fd_list[fd].is_nfs == 1) {
int ret;
struct stat64 st64;
struct nfs_stat_64 st64;
LD_NFS_DPRINTF(9, "__fxstat(%d)", fd);
if ((ret = nfs_fstat(nfs_fd_list[fd].nfs, nfs_fd_list[fd].fh,
if ((ret = nfs_fstat64(nfs_fd_list[fd].nfs, nfs_fd_list[fd].fh,
(void *)&st64)) < 0) {
errno = -ret;
return -1;
}
buf->st_dev = st64.st_dev;
buf->st_ino = st64.st_ino;
buf->st_mode = st64.st_mode;
buf->st_nlink = st64.st_nlink;
buf->st_uid = st64.st_uid;
buf->st_gid = st64.st_gid;
buf->st_rdev = st64.st_rdev;
buf->st_size = st64.st_size;
buf->st_blksize = st64.st_blksize;
buf->st_blocks = st64.st_blocks;
buf->st_atime = st64.st_atime;
buf->st_mtime = st64.st_mtime;
buf->st_ctime = st64.st_ctime;
buf->st_dev = st64.nfs_dev;
buf->st_ino = st64.nfs_ino;
buf->st_mode = st64.nfs_mode;
buf->st_nlink = st64.nfs_nlink;
buf->st_uid = st64.nfs_uid;
buf->st_gid = st64.nfs_gid;
buf->st_rdev = st64.nfs_rdev;
buf->st_size = st64.nfs_size;
buf->st_blksize = st64.nfs_blksize;
buf->st_blocks = st64.nfs_blocks;
buf->st_atim.tv_sec = st64.nfs_atime;
buf->st_atim.tv_usec = st64.nfs_atime_nsec / 1000;
buf->st_mtim.tv_sec = st64.nfs_mtime;
buf->st_mtim.tv_usec = st64.nfs_mtime_nsec / 1000;
buf->st_ctim.tv_sec = st64.nfs_ctime;
buf->st_ctim.tv_usec = st64.nfs_ctime_nsec / 1000;
LD_NFS_DPRINTF(9, "__fxstat(%d) success", fd);
return ret;
@ -458,28 +461,31 @@ int __fxstat64(int ver, int fd, struct stat64 *buf)
{
if (nfs_fd_list[fd].is_nfs == 1) {
int ret;
struct stat64 st64;
struct nfs_stat_64 st64;
LD_NFS_DPRINTF(9, "__fxstat64(%d)", fd);
if ((ret = nfs_fstat(nfs_fd_list[fd].nfs, nfs_fd_list[fd].fh,
if ((ret = nfs_fstat64(nfs_fd_list[fd].nfs, nfs_fd_list[fd].fh,
(void *)&st64)) < 0) {
errno = -ret;
return -1;
}
buf->st_dev = st64.st_dev;
buf->st_ino = st64.st_ino;
buf->st_mode = st64.st_mode;
buf->st_nlink = st64.st_nlink;
buf->st_uid = st64.st_uid;
buf->st_gid = st64.st_gid;
buf->st_rdev = st64.st_rdev;
buf->st_size = st64.st_size;
buf->st_blksize = st64.st_blksize;
buf->st_blocks = st64.st_blocks;
buf->st_atime = st64.st_atime;
buf->st_mtime = st64.st_mtime;
buf->st_ctime = st64.st_ctime;
buf->st_dev = st64.nfs_dev;
buf->st_ino = st64.nfs_ino;
buf->st_mode = st64.nfs_mode;
buf->st_nlink = st64.nfs_nlink;
buf->st_uid = st64.nfs_uid;
buf->st_gid = st64.nfs_gid;
buf->st_rdev = st64.nfs_rdev;
buf->st_size = st64.nfs_size;
buf->st_blksize = st64.nfs_blksize;
buf->st_blocks = st64.nfs_blocks;
buf->st_atim.tv_sec = st64.nfs_atime;
buf->st_atim.tv_usec = st64.nfs_atime_nsec / 1000;
buf->st_mtim.tv_sec = st64.nfs_mtime;
buf->st_mtim.tv_usec = st64.nfs_mtime_nsec / 1000;
buf->st_ctim.tv_sec = st64.nfs_ctime;
buf->st_ctim.tv_usec = st64.nfs_ctime_nsec / 1000;
LD_NFS_DPRINTF(9, "__fxstat64(%d) success", fd);
return ret;

View File

@ -91,7 +91,24 @@ fstat_file(struct file_context *fc, struct stat *st)
if (fc->is_nfs == 0) {
return fstat(fc->fd, st);
} else {
return nfs_fstat(fc->nfs, fc->nfsfh, st);
int res;
struct nfs_stat_64 nfs_st;
res = nfs_fstat64(fc->nfs, fc->nfsfh, &nfs_st);
st->st_dev = nfs_st.nfs_dev;
st->st_ino = nfs_st.nfs_ino;
st->st_mode = nfs_st.nfs_mode;
st->st_nlink = nfs_st.nfs_nlink;
st->st_uid = nfs_st.nfs_uid;
st->st_gid = nfs_st.nfs_gid;
st->st_rdev = nfs_st.nfs_rdev;
st->st_size = nfs_st.nfs_size;
st->st_blksize = nfs_st.nfs_blksize;
st->st_blocks = nfs_st.nfs_blocks;
st->st_atim.tv_sec = nfs_st.nfs_atime;
st->st_mtim.tv_sec = nfs_st.nfs_mtime;
st->st_ctim.tv_sec = nfs_st.nfs_ctime;
return res;
}
}

View File

@ -109,10 +109,10 @@ int main(int argc, char *argv[])
} else if (!strncmp(argv[1], "rmdir", 5)) {
ret = nfs_rmdir(nfs, url->file);
} else if (!strncmp(argv[1], "stat", 4)) {
struct stat st;
ret = nfs_stat(nfs, url->file, &st);
struct nfs_stat_64 st;
ret = nfs_stat64(nfs, url->file, &st);
if (!ret) {
switch (st.st_mode & S_IFMT) {
switch (st.nfs_mode & S_IFMT) {
#ifndef WIN32
case S_IFLNK:
printf("l");
@ -132,24 +132,24 @@ int main(int argc, char *argv[])
break;
}
printf("%c%c%c",
"-r"[!!(st.st_mode & S_IRUSR)],
"-w"[!!(st.st_mode & S_IWUSR)],
"-x"[!!(st.st_mode & S_IXUSR)]
"-r"[!!(st.nfs_mode & S_IRUSR)],
"-w"[!!(st.nfs_mode & S_IWUSR)],
"-x"[!!(st.nfs_mode & S_IXUSR)]
);
printf("%c%c%c",
"-r"[!!(st.st_mode & S_IRGRP)],
"-w"[!!(st.st_mode & S_IWGRP)],
"-x"[!!(st.st_mode & S_IXGRP)]
"-r"[!!(st.nfs_mode & S_IRGRP)],
"-w"[!!(st.nfs_mode & S_IWGRP)],
"-x"[!!(st.nfs_mode & S_IXGRP)]
);
printf("%c%c%c",
"-r"[!!(st.st_mode & S_IROTH)],
"-w"[!!(st.st_mode & S_IWOTH)],
"-x"[!!(st.st_mode & S_IXOTH)]
"-r"[!!(st.nfs_mode & S_IROTH)],
"-w"[!!(st.nfs_mode & S_IWOTH)],
"-x"[!!(st.nfs_mode & S_IXOTH)]
);
printf(" %2d", (int) st.st_nlink);
printf(" %5d", st.st_uid);
printf(" %5d", st.st_gid);
printf(" %12" PRId64, st.st_size);
printf(" %2d", (int)st.nfs_nlink);
printf(" %5d", (int)st.nfs_uid);
printf(" %5d", (int)st.nfs_gid);
printf(" %12" PRId64, st.nfs_size);
printf("\n");
}
} else {

View File

@ -121,10 +121,10 @@ void nfs_close_cb(int status, struct nfs_context *nfs, void *data, void *private
}
}
void nfs_fstat_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
void nfs_fstat64_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
{
struct client *client = private_data;
struct stat *st;
struct nfs_stat_64 *st;
if (status < 0) {
printf("fstat call failed with \"%s\"\n", (char *)data);
@ -132,10 +132,10 @@ void nfs_fstat_cb(int status, struct nfs_context *nfs, void *data, void *private
}
printf("Got reply from server for fstat(%s).\n", NFSFILE);
st = (struct stat *)data;
printf("Mode %04o\n", st->st_mode);
printf("Size %d\n", (int)st->st_size);
printf("Inode %04o\n", (int)st->st_ino);
st = (struct nfs_stat_64 *)data;
printf("Mode %04o\n", (int)st->nfs_mode);
printf("Size %d\n", (int)st->nfs_size);
printf("Inode %04o\n", (int)st->nfs_ino);
printf("Close file\n");
if (nfs_close_async(nfs, client->nfsfh, nfs_close_cb, client) != 0) {
@ -162,7 +162,7 @@ void nfs_read_cb(int status, struct nfs_context *nfs, void *data, void *private_
}
printf("\n");
printf("Fstat file :%s\n", NFSFILE);
if (nfs_fstat_async(nfs, client->nfsfh, nfs_fstat_cb, client) != 0) {
if (nfs_fstat64_async(nfs, client->nfsfh, nfs_fstat64_cb, client) != 0) {
printf("Failed to start async nfs fstat\n");
exit(10);
}
@ -188,10 +188,10 @@ void nfs_open_cb(int status, struct nfs_context *nfs, void *data, void *private_
}
}
void nfs_stat_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
void nfs_stat64_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
{
struct client *client = private_data;
struct stat *st;
struct nfs_stat_64 *st;
if (status < 0) {
printf("stat call failed with \"%s\"\n", (char *)data);
@ -200,9 +200,9 @@ void nfs_stat_cb(int status, struct nfs_context *nfs, void *data, void *private_
printf("Got reply from server for stat(%s).\n", NFSFILE);
st = (struct stat *)data;
printf("Mode %04o\n", st->st_mode);
printf("Size %d\n", (int)st->st_size);
printf("Inode %04o\n", (int)st->st_ino);
printf("Mode %04o\n", st->nfs_mode);
printf("Size %d\n", (int)st->nfs_size);
printf("Inode %04o\n", (int)st->nfs_ino);
printf("Open file for reading :%s\n", NFSFILE);
if (nfs_open_async(nfs, NFSFILE, O_RDONLY, nfs_open_cb, client) != 0) {
@ -222,7 +222,7 @@ void nfs_mount_cb(int status, struct nfs_context *nfs, void *data, void *private
printf("Got reply from server for MOUNT/MNT procedure.\n");
printf("Stat file :%s\n", NFSFILE);
if (nfs_stat_async(nfs, NFSFILE, nfs_stat_cb, client) != 0) {
if (nfs_stat64_async(nfs, NFSFILE, nfs_stat64_cb, client) != 0) {
printf("Failed to start async nfs stat\n");
exit(10);
}

View File

@ -77,7 +77,7 @@ int main(int argc, char *argv[])
int i, ret, res;
uint64_t offset;
struct client client;
struct stat st;
struct nfs_stat_64 st;
struct nfsfh *nfsfh;
struct nfsdir *nfsdir;
struct nfsdirent *nfsdirent;
@ -173,13 +173,13 @@ int main(int argc, char *argv[])
}
sprintf(path, "%s/%s", "/", nfsdirent->name);
ret = nfs_stat(nfs, path, &st);
ret = nfs_stat64(nfs, path, &st);
if (ret != 0) {
fprintf(stderr, "Failed to stat(%s) %s\n", path, nfs_get_error(nfs));
continue;
}
switch (st.st_mode & S_IFMT) {
switch (st.nfs_mode & S_IFMT) {
#ifndef WIN32
case S_IFLNK:
#endif
@ -197,24 +197,24 @@ int main(int argc, char *argv[])
break;
}
printf("%c%c%c",
"-r"[!!(st.st_mode & S_IRUSR)],
"-w"[!!(st.st_mode & S_IWUSR)],
"-x"[!!(st.st_mode & S_IXUSR)]
"-r"[!!(st.nfs_mode & S_IRUSR)],
"-w"[!!(st.nfs_mode & S_IWUSR)],
"-x"[!!(st.nfs_mode & S_IXUSR)]
);
printf("%c%c%c",
"-r"[!!(st.st_mode & S_IRGRP)],
"-w"[!!(st.st_mode & S_IWGRP)],
"-x"[!!(st.st_mode & S_IXGRP)]
"-r"[!!(st.nfs_mode & S_IRGRP)],
"-w"[!!(st.nfs_mode & S_IWGRP)],
"-x"[!!(st.nfs_mode & S_IXGRP)]
);
printf("%c%c%c",
"-r"[!!(st.st_mode & S_IROTH)],
"-w"[!!(st.st_mode & S_IWOTH)],
"-x"[!!(st.st_mode & S_IXOTH)]
"-r"[!!(st.nfs_mode & S_IROTH)],
"-w"[!!(st.nfs_mode & S_IWOTH)],
"-x"[!!(st.nfs_mode & S_IXOTH)]
);
printf(" %2d", (int)st.st_nlink);
printf(" %5d", st.st_uid);
printf(" %5d", st.st_gid);
printf(" %12" PRId64, st.st_size);
printf(" %2d", (int)st.nfs_nlink);
printf(" %5d", (int)st.nfs_uid);
printf(" %5d", (int)st.nfs_gid);
printf(" %12" PRId64, st.nfs_size);
printf(" %s\n", nfsdirent->name);
}