Ejemplo n.º 1
0
CRYSTAX_LOCAL
int mount(const char *source, const char *target, const char *fstype,
    unsigned long flags, const void *data)
{
    DBG("source=%s, target=%s, fstype=%s, flags=%lu, data=%p",
        source, target, fstype, flags, data);

    scope_lock_t lock(mount_table_mutex);

    if (mount_table_pos >= MOUNT_TABLE_SIZE)
    {
        ERR("too much mount calls performed (max %d)", (int)MOUNT_TABLE_SIZE);
        errno = ENFILE;
        return -1;
    }

    abspath_t abspath(target);

    // Found underlying driver
    driver_t *underlying = system::driver_t::instance();
    for (size_t i = mount_table_pos; i > 0; --i)
    {
        driver_t *prev = mount_table[i - 1];
        if (abspath.subpath(prev->root()))
        {
            underlying = prev;
            break;
        }
    }

    driver_t *driver = load_driver(source, abspath.c_str(), fstype, flags, data, underlying);
    if (!driver)
        return system_mount(source, target, fstype, flags, data);

    DBG("load driver: %s (%s), underlying: %s (%s)", driver->name(), driver->info(), underlying->name(), underlying->info());

    mount_table[mount_table_pos] = driver;

    ++mount_table_pos;

    return 0;
}
Ejemplo n.º 2
0
u_int32_t uf_http_upload(struct sub_env_t *sub_env, WS_ENV *ws_env, WS_REQ_RES* ws_req_res)
{
    WS_PARA *para;
    u_int32_t sys_error_code = 0;
    char* http_filename;
    char cmd[300];
    char tmp_cmd[300], err_string[128];
    u_int32_t fileseize;
    const char* client_name;
    char* base_name;
    struct sys_partition_info part_info;
    unsigned int spare;
    char file_name[300];
    char dev_name[32];
    int is_dpx = 0;
    s32 dev_type;

    (void) sub_env;
    (void)ws_env;
    (void) ws_req_res;

    http_filename = "soft_file_download";
    if (HTTP_PARA_FOUND != http_get_upload_file_info(http_filename, &client_name, &fileseize))
    {
        return ws_send_soap_error(ws_env,   "File not exist!");
    }
    base_name = get_basename(client_name);

    (void)http_move_upload_file(http_filename, TEMP_IMAGE);

    sys_error_code = (u_int32_t)is_bootimage(TEMP_IMAGE);
    if(DRV_DEV_SUCCESS != sys_error_code)
    {
        snprintf(cmd, sizeof(cmd), "/bin/rm %s ", TEMP_IMAGE);
        system(cmd);
        return ws_send_soap_error(ws_env,  "The software version does not exist or is invalid!");
    }

    /*获取板子类型参数, 对于非dpx的设备,保持不变*/
    sys_error_code = ws_get_req_by_name(ws_env, ws_req_res, "type", &para);
    if (HTTP_PARA_FOUND != sys_error_code)
    {
        dev_type = g_dev_type;
    }
    else
    {
        dev_type = para->int_data;
    }

    if(0 == dev_type)       //下载版本时,防止下载到备主控上
    {
        return ERROR_SUCCESS;
    }

    if (dev_type == DPX_BOARD_MAIN || dev_type == DPX_BOARD_SPARE)
    {

        /*judging whether the /boot  has the same file as the upload file base_name :\DPtech-UAG3000MA-C11-B11007.bin*/
        system_mount();
        snprintf(file_name,sizeof(file_name),"%s%s",IMAGE_PATH,base_name);

        sys_error_code = (u_int32_t)is_bootimage(file_name);
        if(DRV_DEV_SUCCESS != sys_error_code)// not exist the same name
        {
            memset(&part_info, 0, sizeof(struct sys_partition_info));
            sys_error_code = (u_int32_t)sys_read_part_info(PARTITION_BOOT, &part_info);
            if(ERROR_SUCCESS != sys_error_code)
            {
                snprintf(cmd, sizeof(cmd), "/bin/rm -rf %s", TEMP_IMAGE);
                system(cmd);
                return (u32)ws_send_soap_error(ws_env, "Failed to get disk information!");
            }

            spare = (part_info.total - part_info.used)*1024;

            if (spare <fileseize)
            {
                snprintf(cmd, sizeof(cmd), "/bin/rm -rf %s", TEMP_IMAGE);
                system(cmd);
                return  (u32)ws_send_soap_error(ws_env, "No enough space!");
            }
        }

        //dpx备板升级软件版本,设备类型判断
        memset(dev_name, '\0', sizeof(dev_name));
        wrap_drv_get_device_type((s8 *)dev_name, sizeof(dev_name));

        if(0 == strncmp("DPX", dev_name, 3))//dpx存在备板
        {
            s32 is_exist;
            sys_error_code = cfg_get_remote_board_is_exist(&is_exist);
            if(0 != sys_error_code)
            {
                return  (u32)ws_send_soap_error(ws_env, "Get board info fail!");
            }
            if(SPARE_IS_EXIST == is_exist)
            {
                is_dpx = 1;
            }

        }

        if(1 == is_dpx)//dpx备板升级软件版本
        {
            snprintf(tmp_cmd, sizeof(tmp_cmd), "/bin/mv %s /tmp/%s", TEMP_IMAGE, base_name);
            system(tmp_cmd);

            snprintf(cmd, sizeof(cmd), "/bin/cp /tmp/%s %s%s", base_name, IMAGE_PATH, base_name);
            system(cmd);
        }
        else
        {
            snprintf(cmd, sizeof(cmd), "/bin/mv %s %s%s", TEMP_IMAGE, IMAGE_PATH, base_name);
            system(cmd);
        }

        WEB_SEND_EX_OPERLOG_QUICK(0, " Updated [%s] to [%s] software image.", client_name, "main");

        if(1 == is_dpx)//dpx备板升级软件版本
        {
            sprintf(cmd, "/usr/bin/cfg update_version %s", base_name);
            system(cmd);

            snprintf(tmp_cmd, sizeof(tmp_cmd), "/bin/rm -rf /tmp/%s", base_name);
            system(tmp_cmd);
        }
    }
    else
    {
        snprintf(tmp_cmd, sizeof(tmp_cmd), "/bin/mv %s /tmp/%s", TEMP_IMAGE, base_name);
        system(tmp_cmd);
        snprintf(file_name, sizeof(file_name), "/tmp/%s", base_name);
        sys_error_code = dpx_download_file(file_name, dev_type, err_string);

        snprintf(tmp_cmd, sizeof(tmp_cmd), "/bin/rm -rf %s", file_name);
        system(tmp_cmd);
        if (sys_error_code)
            return  (u32)ws_send_soap_error(ws_env, err_string);
    }
    return WS_OK;
}