Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
- Loading branch information
Showing
8 changed files
with
203 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */ | ||
/* | ||
Copyright (C) by Ronnie Sahlberg <ronniesahlberg@gmail.com> 2017 | ||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program; if not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#define _FILE_OFFSET_BITS 64 | ||
#define _GNU_SOURCE | ||
|
||
#include <fcntl.h> | ||
#include <inttypes.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <stdint.h> | ||
#include <string.h> | ||
#include <sys/types.h> | ||
|
||
#include "libnfs.h" | ||
|
||
void usage(void) | ||
{ | ||
fprintf(stderr, "Usage: prog_ftruncate <url> <cwd> <path> <offset>\n"); | ||
exit(1); | ||
} | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
struct nfs_context *nfs; | ||
struct nfsfh *nfsfh; | ||
struct nfs_url *url; | ||
uint64_t length; | ||
|
||
if (argc != 5) { | ||
usage(); | ||
} | ||
|
||
length = strtol(argv[4], NULL, 10); | ||
|
||
nfs = nfs_init_context(); | ||
if (nfs == NULL) { | ||
printf("failed to init context\n"); | ||
exit(1); | ||
} | ||
|
||
url = nfs_parse_url_full(nfs, argv[1]); | ||
if (url == NULL) { | ||
fprintf(stderr, "%s\n", nfs_get_error(nfs)); | ||
exit(1); | ||
} | ||
|
||
if (nfs_mount(nfs, url->server, url->path) != 0) { | ||
fprintf(stderr, "Failed to mount nfs share : %s\n", | ||
nfs_get_error(nfs)); | ||
exit(1); | ||
} | ||
|
||
if (nfs_chdir(nfs, argv[2]) != 0) { | ||
fprintf(stderr, "Failed to chdir to \"%s\" : %s\n", | ||
argv[2], nfs_get_error(nfs)); | ||
exit(1); | ||
} | ||
|
||
if (nfs_open(nfs, argv[3], O_WRONLY, &nfsfh)) { | ||
fprintf(stderr, "Failed to open file : %s\n", | ||
nfs_get_error(nfs)); | ||
exit(1); | ||
} | ||
|
||
if (nfs_ftruncate(nfs, nfsfh, length)) { | ||
fprintf(stderr, "Failed to ftruncate file : %s\n", | ||
nfs_get_error(nfs)); | ||
exit(1); | ||
} | ||
|
||
nfs_destroy_url(url); | ||
nfs_close(nfs, nfsfh); | ||
nfs_destroy_context(nfs); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/sh | ||
|
||
. ./functions.sh | ||
|
||
echo "NFSv${VERS} Basic nfs_ftruncate() test." | ||
|
||
start_share | ||
|
||
dd if=/dev/zero of=testdata/testfile count=1 bs=32768 2>/dev/null | ||
|
||
echo -n "test nfs_ftruncate() ... " | ||
./prog_ftruncate "${TESTURL}/?version=${VERS}" "." testfile 12377 || failure | ||
success | ||
|
||
echo -n "test nfs_fstat64() ... " | ||
./prog_fstat "${TESTURL}/?version=${VERS}" "." testfile > "${TESTDIR}/output" || failure | ||
success | ||
|
||
echo -n "verify nfs_size ... " | ||
grep "nfs_size:12377" "${TESTDIR}/output" >/dev/null || failure | ||
success | ||
|
||
stop_share | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/sh | ||
|
||
. ./functions.sh | ||
|
||
echo "NFSv${VERS} Basic valgrind leak check for nfs_ftruncate()." | ||
|
||
start_share | ||
|
||
dd if=/dev/zero of=testdata/testfile count=1 bs=32768 2>/dev/null | ||
|
||
echo -n "test nfs_ftruncate() (1) ... " | ||
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_ftruncate "${TESTURL}/?version=${VERS}" "." testfile 12377 >/dev/null 2>&1 || failure | ||
success | ||
|
||
stop_share | ||
|
||
exit 0 |