int bta_ma_co_open(const char *p_path, int oflags) { struct stat file_stat; int fd; /* Convert BTA oflags into MFS */ oflags = bta_fs_convert_bta_oflags(oflags); if ((fd = open (p_path, oflags | O_NONBLOCK, 0666)) < 0) { APPL_TRACE_ERROR2("%s: Error opening file: error code %d", __FUNCTION__, fd); return BTA_FS_INVALID_FD; } else { if(fstat(fd, &file_stat) == 0) { if (oflags & O_CREAT) { fchown(fd, BT_UID, BT_GID); APPL_TRACE_DEBUG0("\n ******CHANGED OWNERSHIP SUCCESSFULLY**********"); } } return fd; } }
void bta_fs_co_open(const char *p_path, int oflags, UINT32 size, UINT16 evt, UINT8 app_id) { tBTA_FS_CO_STATUS status; UINT32 file_size = 0; struct stat file_stat; int fd = -1; int err = 0; /* Convert BTA oflags into os specific flags */ oflags = bta_fs_convert_bta_oflags(oflags); /* check available space in case of write access. oflags are in OS format! */ if (oflags & (O_RDWR|O_WRONLY)) { err = btapp_fs_check_space(p_path, size, app_id); } if ( 0==err ) { if ((fd = open(p_path, oflags | O_NONBLOCK, 0666)) >= 0) { if (fstat(fd, &file_stat) == 0) { file_size = file_stat.st_size; if (oflags & O_CREAT) { fchown(fd, BT_UID, BT_GID); BTIF_TRACE_DEBUG("\n ******CHANGED OWNERSHIP SUCCESSFULLY**********"); } } } else { err = errno; } } BTIF_TRACE_DEBUG("[CO] bta_fs_co_open: handle:%d err:%d, flags:%x, app id:%d", fd, err, oflags, app_id); BTIF_TRACE_DEBUG("file=%s", p_path); /* convert fs error into bta_fs err. erro is set by first call to enough space to a valid value * and needs only updating in case of error. This reports correct failure to remote obex! */ switch (err) { case 0: status = BTA_FS_CO_OK; break; case EACCES: status = BTA_FS_CO_EACCES; break; case EFBIG: /* file to big for available fs space */ status = BTA_FS_CO_ENOSPACE; break; default: status = BTA_FS_CO_FAIL; break; } bta_fs_ci_open(fd, status, file_size, evt); }