1 /* usmb - mount SMB shares via FUSE and Samba
2 * Copyright (C) 2006-2008 Geoff Johnstone
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include <sys/time.h> // struct timeval needed by libsmbclient.h
18 #include <libsmbclient.h>
32 int usmb_mkdir (const char *dirname
, mode_t mode
)
34 char *url
= make_url (dirname
);
38 DEBUG (fprintf (stderr
, "mkdir (%s)\n", url
));
39 int ret
= ctx
->mkdir (ctx
, url
, mode
) ? -errno
: 0;
45 int usmb_rmdir (const char *dirname
)
47 char *url
= make_url (dirname
);
51 DEBUG (fprintf (stderr
, "rmdir (%s)\n", url
));
52 int ret
= ctx
->rmdir (ctx
, url
) ? -errno
: 0;
58 int usmb_opendir (const char *dirname
, struct fuse_file_info
*fi
)
60 char *url
= make_url (dirname
);
64 DEBUG (fprintf (stderr
, "opendir (%s)", url
));
65 SMBCFILE
*file
= ctx
->opendir (ctx
, url
);
66 DEBUG (fprintf (stderr
, " = %p\n", (void *)file
));
68 int ret
= (NULL
== file
) ? -errno
: 0;
70 fi
->fh
= smbcfile_to_fd (file
);
76 int usmb_readdir (const char *path
, void *h
, fuse_fill_dir_t filler
,
77 off_t offset
, struct fuse_file_info
*fi
)
82 struct smbc_dirent
*dirent
;
84 SMBCFILE
*file
= fd_to_smbcfile (fi
->fh
);
86 DEBUG (fprintf (stderr
, "readdir (%s, %p)\n", path
, (void *)file
));
88 while (NULL
!= (dirent
= ctx
->readdir (ctx
, file
)))
92 switch (dirent
->smbc_type
)
95 stbuf
.st_mode
= DT_DIR
<< 12;
99 stbuf
.st_mode
= DT_REG
<< 12;
103 stbuf
.st_mode
= DT_LNK
<< 12;
110 if (1 == filler (h
, dirent
->name
, &stbuf
, 0)) /* if error */
118 int usmb_releasedir (const char *path
, struct fuse_file_info
*fi
)
122 SMBCFILE
*file
= fd_to_smbcfile (fi
->fh
);
123 DEBUG (fprintf (stderr
, "releasedir (%s, %p)\n", path
, (void *)file
));
124 return (ctx
->closedir (ctx
, file
) < 0) ? -errno
: 0;
128 int usmb_setxattr (const char *path
, const char *name
, const char *value
,
129 size_t size
, int flags
)
131 char *url
= make_url (path
);
135 DEBUG (fprintf (stderr
, "setxattr (%s, %s, %p, %u, %x)\n",
136 path
, url
, value
, size
, flags
));
137 int ret
= ctx
->setxattr (ctx
, url
, name
, value
, size
, flags
) ? -errno
: 0;
143 int usmb_getxattr (const char *path
, const char *name
, char *value
, size_t size
)
145 char *url
= make_url (path
);
149 DEBUG (fprintf (stderr
, "getxattr (%s, %s, %p, %u)\n",
150 path
, url
, value
, size
));
151 int ret
= ctx
->getxattr (ctx
, url
, name
, value
, size
) ? -errno
: 0;
157 int usmb_listxattr (const char *path
, char *list
, size_t size
)
159 char *url
= make_url (path
);
163 DEBUG (fprintf (stderr
, "listxattr (%s, %p, %u)\n", url
, list
, size
));
164 int ret
= ctx
->listxattr (ctx
, url
, list
, size
) ? -errno
: 0;
170 int usmb_removexattr (const char *path
, const char *name
)
172 char *url
= make_url (path
);
176 DEBUG (fprintf (stderr
, "removexattr (%s, %s)\n", url
, name
));
177 int ret
= ctx
->removexattr (ctx
, url
, name
) ? -errno
: 0;