#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#define MAX_SIZE 1000
int main()
{
int fd;
ssize_t length_w;
ssize_t count;
char buffer_write[] = "This is my schoolnumber: 19407010204.";
if ( ( fd = open("./hello.txt", O_RDWR|O_CREAT, 0677) ) < 0 ){
printf("open failed \n");
printf("fd = %d\n", fd);
}
lseek (fd, 0, SEEK_END);
count = strlen(buffer_write);
length_w = write(fd, buffer_write, count);
if (length_w == -1){
printf("write failed!\n");
}else if (length_w != count){
printf("it's partial write !\n");
}else {
printf("Write OK!\n");
}
close(fd);
return 0;
}
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#define MAX_SIZE 1000
int main()
{
int fd;
ssize_t length_r = MAX_SIZE, ret;
char buffer_read[MAX_SIZE];
fd = open("./hello.txt", O_RDONLY);
if ( fd < 0 ){
printf("open failed! \n");
}
lseek ( fd, 0, SEEK_SET );
if ( ( ret = read(fd, buffer_read, length_r)) < 0 ){
printf("read failed ! \n");
}
printf("%s\n", buffer_read);
close(fd);
return 0;
}
sudo vi /etc/exports
/home/yuanxiao/Desktop *(rw,sync,no_root_squash)
sudo service nfs-kernel-server restart
mount -t nfs -o nolock 192.168.1.11:/home/yuanxiao/Desktop /mnt