|
smb_devoptab with write support February 15, 2009 03:23AM | Registered: 17 years ago Posts: 78 |
/* Replace the existing function with this one */
int __smb_open(struct _reent *r, void *fileStruct, const char *path, int flags, int mode) {
SMBFILESTRUCT *file = (SMBFILESTRUCT*)fileStruct;
/* check connection ? can't get here? */
if (SMBCONNECTED == false) {
r->_errno = ENODEV;
return -1;
}
/* Strip of the device prefix */
char fixedpath[ MAXPATH ];
if (absolute_path_no_device(path, fixedpath) == NULL) {
r->_errno = EINVAL;
return -1;
}
SMBDIRENTRY dentry;
if ((flags & 0x03) == O_RDONLY) {
if (SMB_PathInfo(fixedpath, &dentry, smbconn) == SMB_SUCCESS) {
if (!(dentry.attributes & SMB_SRCH_DIRECTORY)) {
file->handle = SMB_OpenFile(fixedpath, SMB_OPEN_READING, SMB_OF_OPEN, smbconn);
} else {
/* Path points to a directory, not a file */
r->_errno = EISDIR;
return -1;
}
} else {
/* File doesn't exist */
r->_errno = ENOENT;
return -1;
}
} else if ((flags & 0x03) == O_WRONLY) {
SMB_PathInfo(fixedpath, &dentry, smbconn);
if (!(dentry.attributes & SMB_SRCH_DIRECTORY)) {
file->handle = SMB_OpenFile(fixedpath, SMB_OPEN_WRITING, SMB_OF_CREATE | SMB_OF_TRUNCATE, smbconn);
} else {
/* Path points to directory, not a file */
r->_errno = EISDIR;
return -1;
}
} else {
r->_errno = ENOENT;
return -1;
}
if (!file->handle) {
r->_errno = ENOENT;
return -1;
}
file->offset = 0;
file->len = dentry.size_low;
return 0;
}
/* Add this function under __smb_read */
int __smb_write(struct _reent *r, int fd, char *ptr, int len) {
SMBFILESTRUCT *file = (SMBFILESTRUCT*)fd;
if (file == NULL) {
r->_errno = EBADF;
return -1;
}
int bytesWritten = SMB_WriteFile(ptr, len, file->offset, file->handle);
file->offset += bytesWritten;
if (bytesWritten != len) {
r->_errno = EIO;
}
return byesWritten;
}
/* Modify this structure to include the new write function */
const devoptab_t dotab_smb = {
"smb",
sizeof(SMBFILESTRUCT),
__smb_open,
__smb_close,
__smb_write, /* New function */
__smb_read,
__smb_seek,
__smb_fstat,
__smb_stat,
NULL,
NULL,
__smb_chdir,
NULL,
NULL,
sizeof(SMBDIRSTATESTRUCT),
__smb_diropen,
__smb_dirreset,
__smb_dirnext,
__smb_dirclose,
NULL
};|
Re: smb_devoptab with write support February 15, 2009 06:47PM | Registered: 17 years ago Posts: 441 |
|
Re: smb_devoptab with write support February 15, 2009 10:27PM | Registered: 17 years ago Posts: 78 |