疑問解決!struct stat
@basile-starynkevitch のおかげで、 が異なるファイルで同じサイズではない
ことがわかりました!
では88 バイトですが<sys/stat.h>
、sizeof(struct stat)
fuse の lib では (-D_FILE_OFFSET_BITS=64
フラグの関係だと思います)、これは 96 バイトです。
したがって、リモート サーバーにヒューズ ライブラリを追加すると ( -D_FILE_OFFSET_BITS=64 /usr/local/lib/libfuse.so /usr/local/lib/libulockmgr.so
gcc にフラグを追加)、プログラムが正しく実行されます。
あなたの助けに感謝します!
私はヒューズでいくつかのプロジェクトを行っていますが、それは私を夢中にさせました。
リモートサーバーから struct stat *stbuf のデータを送信し、データはサーバーとクライアントの両方で正しいのですが、 memcpy を使用してデータを stbuf に複製すると、何もコピーされないようです。read(socked,stbuf,sizeof(struct stat)); も使用しようとしています。直接ですが、それも機能しません。
ここにコードがあります...(そのようなファイルがない場合、リモートサーバーは-ENOENTをst_inoに保存します)
static int rof_getattr(const char *path, struct stat *stbuf)
{
int res = 0;
struct cmd sndcmd;
struct stat buf;
memset(&sndcmd, 0, sizeof(struct cmd));
strcpy(sndcmd.cmd, "GETATTR");
strcpy(sndcmd.str, path);
memset(stbuf, 0, sizeof(struct stat));
GTTR_AGN:
memset(&buf, 0,sizeof(struct stat));
write(sockfd, &sndcmd, sizeof(struct cmd));
res=read(sockfd, &buf, sizeof(struct stat));
if(res!=sizeof(struct stat))
goto GTTR_AGN;
memcpy(stbuf,&buf,sizeof(buf));
if (buf.st_ino==-ENOENT)
return -ENOENT;
return 0;
}
gdb から取得したデータ:
39 res=read(sockfd, &buf, sizeof(struct stat));
3: (struct stat)stbuf = {st_dev = 694294557525955008, __pad1 = 0, __st_ino = 0,
st_mode = 0, st_nlink = 0, st_uid = 0, st_gid = 0, st_rdev = 0, __pad2 = 0,
st_size = 0, st_blksize = 0, st_blocks = 0, st_atim = {tv_sec = 0, tv_nsec = 0},
st_mtim = {tv_sec = 0, tv_nsec = 0}, st_ctim = {tv_sec = 0, tv_nsec = 0},
st_ino = 0}
1: buf = {st_dev = 0, __pad1 = 0, __st_ino = 0, st_mode = 0, st_nlink = 0,
st_uid = 0, st_gid = 0, st_rdev = 0, __pad2 = 0, st_size = 0, st_blksize = 0,
st_blocks = 0, st_atim = {tv_sec = 0, tv_nsec = 0}, st_mtim = {tv_sec = 0,
tv_nsec = 0}, st_ctim = {tv_sec = 0, tv_nsec = 0}, st_ino = 0}
read() の後、buf にデータを取得
(gdb) s
40 memcpy(stbuf,&buf,sizeof(buf));
3: (struct stat)stbuf = {st_dev = 694294557525955008, __pad1 = 2049, __st_ino = 0,
st_mode = 0, st_nlink = 943887, st_uid = 16877, st_gid = 2,
st_rdev = 4294967297000, __pad2 = 0, st_size = 0, st_blksize = 4096,
st_blocks = 34359742464, st_atim = {tv_sec = 1323833759, tv_nsec = 75415995},
st_mtim = {tv_sec = 1323729515, tv_nsec = 6514929}, st_ctim = {
tv_sec = 1323729515, tv_nsec = 6514929}, st_ino = 0}
1: buf = {st_dev = 2049, __pad1 = 0, __st_ino = 943887, st_mode = 16877,
st_nlink = 2, st_uid = 1000, st_gid = 1000, st_rdev = 0, __pad2 = 0,
st_size = 17592186048512, st_blksize = 8, st_blocks = 323909233444133279,
st_atim = {tv_sec = 1323729515, tv_nsec = 6514929}, st_mtim = {
tv_sec = 1323729515, tv_nsec = 6514929}, st_ctim = {tv_sec = 0, tv_nsec = 0},
st_ino = 0}
(gdb) s
データを stbuf にコピーする
41 if (stbuf->st_ino==-ENOENT)
3: (struct stat)stbuf = {st_dev = 694294557525955008, __pad1 = 2049, __st_ino = 0,
st_mode = 0, st_nlink = 943887, st_uid = 16877, st_gid = 2,
st_rdev = 4294967297000, __pad2 = 0, st_size = 0, st_blksize = 4096,
st_blocks = 34359742464, st_atim = {tv_sec = 1323833759, tv_nsec = 75415995},
st_mtim = {tv_sec = 1323729515, tv_nsec = 6514929}, st_ctim = {
tv_sec = 1323729515, tv_nsec = 6514929}, st_ino = 0}
1: buf = {st_dev = 2049, __pad1 = 0, __st_ino = 943887, st_mode = 16877,
st_nlink = 2, st_uid = 1000, st_gid = 1000, st_rdev = 0, __pad2 = 0,
st_size = 17592186048512, st_blksize = 8, st_blocks = 323909233444133279,
st_atim = {tv_sec = 1323729515, tv_nsec = 6514929}, st_mtim = {
tv_sec = 1323729515, tv_nsec = 6514929}, st_ctim = {tv_sec = 0, tv_nsec = 0},
st_ino = 0}
stbuf はまったく変化しません。
そのような現象について誰かが私に何か提案をしてもらえますか? いくつかの作業を行いましたが、まだ解決策が見つかりません。