void end_swap_bio_read(struct bio *bio, int err) { const int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); struct page *page = bio->bi_io_vec[0].bv_page; if (!uptodate) { SetPageError(page); ClearPageUptodate(page); printk(KERN_ALERT "Read-error on swap-device (%u:%u:%Lu)\n", imajor(bio->bi_bdev->bd_inode), iminor(bio->bi_bdev->bd_inode), (unsigned long long)bio->bi_sector); goto out; } SetPageUptodate(page); /* * There is no guarantee that the page is in swap cache - the software * suspend code (at least) uses end_swap_bio_read() against a non- * swapcache page. So we must check PG_swapcache before proceeding with * this optimization. */ if (likely(PageSwapCache(page))) { /* * The swap subsystem performs lazy swap slot freeing, * expecting that the page will be swapped out again. * So we can avoid an unnecessary write if the page * isn't redirtied. * This is good for real swap storage because we can * reduce unnecessary I/O and enhance wear-leveling * if an SSD is used as the as swap device. * But if in-memory swap device (eg zram) is used, * this causes a duplicated copy between uncompressed * data in VM-owned memory and compressed data in * zram-owned memory. So let's free zram-owned memory * and make the VM-owned decompressed page *dirty*, * so the page should be swapped out somewhere again if * we again wish to reclaim it. */ struct gendisk *disk = bio->bi_bdev->bd_disk; if (disk->fops->swap_slot_free_notify) { swp_entry_t entry; unsigned long offset; entry.val = page_private(page); offset = swp_offset(entry); SetPageDirty(page); disk->fops->swap_slot_free_notify(bio->bi_bdev, offset); } } out: unlock_page(page); bio_put(bio); }
asmlinkage int solaris_putmsg(unsigned int fd, u32 arg1, u32 arg2, u32 arg3) { struct file *filp; struct inode *ino; struct strbuf __user *ctlptr; struct strbuf __user *datptr; struct strbuf ctl, dat; int flags = (int) arg3; int error = -EBADF; struct fdtable *fdt; SOLD("entry"); lock_kernel(); if(fd >= NR_OPEN) goto out; fdt = files_fdtable(current->files); filp = fdt->fd[fd]; if(!filp) goto out; ino = filp->f_path.dentry->d_inode; if (!ino) goto out; if (!S_ISSOCK(ino->i_mode) && (imajor(ino) != 30 || iminor(ino) != 1)) goto out; ctlptr = A(arg1); datptr = A(arg2); error = -EFAULT; if (ctlptr) { if (copy_from_user(&ctl,ctlptr,sizeof(ctl))) goto out; if (ctl.len < 0 && flags) { error = -EINVAL; goto out; } } else { ctl.len = 0; ctl.buf = 0; } if (datptr) { if (copy_from_user(&dat,datptr,sizeof(dat))) goto out; } else { dat.len = 0; dat.buf = 0; } error = timod_putmsg(fd,A(ctl.buf),ctl.len, A(dat.buf),dat.len,flags); out: unlock_kernel(); SOLD("done"); return error; }
static int BT_open(struct inode *inode, struct file *file) { BT_INFO_FUNC("%s: major %d minor %d (pid %d)\n", __func__, imajor(inode), iminor(inode), current->pid ); #if 1 /* GeorgeKuo: turn on function before check stp ready */ /* turn on BT */ if (MTK_WCN_BOOL_FALSE == mtk_wcn_wmt_func_on(WMTDRV_TYPE_BT)) { BT_WARN_FUNC("WMT turn on BT fail!\n"); return -ENODEV; }else{ retflag = 0; mtk_wcn_wmt_msgcb_reg(WMTDRV_TYPE_BT, bt_cdev_rst_cb); BT_INFO_FUNC("WMT register BT rst cb!\n"); } #endif if (mtk_wcn_stp_is_ready()) { #if 0 /* GeorgeKuo: turn on function before check stp ready */ /* turn on BT */ if (MTK_WCN_BOOL_FALSE == mtk_wcn_wmt_func_on(WMTDRV_TYPE_BT)) { BT_WARN_FUNC("WMT turn on BT fail!\n"); return -ENODEV; } #endif mtk_wcn_stp_set_bluez(0); BT_INFO_FUNC("Now it's in MTK Bluetooth Mode\n"); BT_INFO_FUNC("WMT turn on BT OK!\n"); BT_INFO_FUNC("STP is ready!\n"); platform_load_nvram_data(BT_NVRAM_CUSTOM_NAME, (char *)&g_nvram_btdata, sizeof(g_nvram_btdata)); BT_INFO_FUNC("Read NVRAM : BD address %02x%02x%02x%02x%02x%02x Cap 0x%02x Codec 0x%02x\n", g_nvram_btdata[0], g_nvram_btdata[1], g_nvram_btdata[2], g_nvram_btdata[3], g_nvram_btdata[4], g_nvram_btdata[5], g_nvram_btdata[6], g_nvram_btdata[7]); mtk_wcn_stp_register_event_cb(BT_TASK_INDX, BT_event_cb); BT_INFO_FUNC("mtk_wcn_stp_register_event_cb finish\n"); } else { BT_ERR_FUNC("STP is not ready\n"); /*return error code*/ return -ENODEV; } // init_MUTEX(&wr_mtx); sema_init(&wr_mtx, 1); // init_MUTEX(&rd_mtx); sema_init(&rd_mtx, 1); BT_INFO_FUNC("finish\n"); return 0; }
int char_open(struct inode *inode, struct file *file) { pr_alert("In char_open, manjor: %d, minor: %d\n", imajor(inode), iminor(inode)); file->private_data = (void *)inode; return 0; }
/*------------------------------------------------------------------------------ * Context: process */ int oz_cdev_open(struct inode *inode, struct file *filp) { struct oz_cdev *dev; oz_trace("oz_cdev_open()\n"); oz_trace("major = %d minor = %d\n", imajor(inode), iminor(inode)); dev = container_of(inode->i_cdev, struct oz_cdev, cdev); filp->private_data = dev; return 0; }
/* * a note on stream states used: * we use follwing states in the compressed core * SNDRV_PCM_STATE_OPEN: When stream has been opened. * SNDRV_PCM_STATE_SETUP: When stream has been initialized. This is done by * calling SNDRV_COMPRESS_SET_PARAMS. running streams will come to this * state at stop by calling SNDRV_COMPRESS_STOP, or at end of drain. * SNDRV_PCM_STATE_RUNNING: When stream has been started and is * decoding/encoding and rendering/capturing data. * SNDRV_PCM_STATE_DRAINING: When stream is draining current data. This is done * by calling SNDRV_COMPRESS_DRAIN. * SNDRV_PCM_STATE_PAUSED: When stream is paused. This is done by calling * SNDRV_COMPRESS_PAUSE. It can be stopped or resumed by calling * SNDRV_COMPRESS_STOP or SNDRV_COMPRESS_RESUME respectively. */ static int snd_compr_open(struct inode *inode, struct file *f) { struct snd_compr *compr; struct snd_compr_file *data; struct snd_compr_runtime *runtime; enum snd_compr_direction dirn; int maj = imajor(inode); int ret; if ((f->f_flags & O_ACCMODE) == O_WRONLY) dirn = SND_COMPRESS_PLAYBACK; else if ((f->f_flags & O_ACCMODE) == O_RDONLY) dirn = SND_COMPRESS_CAPTURE; else return -EINVAL; if (maj == snd_major) compr = snd_lookup_minor_data(iminor(inode), SNDRV_DEVICE_TYPE_COMPRESS); else return -EBADFD; if (compr == NULL) { pr_err("no device data!!!\n"); return -ENODEV; } if (dirn != compr->direction) { pr_err("this device doesn't support this direction\n"); return -EINVAL; } data = kzalloc(sizeof(*data), GFP_KERNEL); if (!data) return -ENOMEM; data->stream.ops = compr->ops; data->stream.direction = dirn; data->stream.private_data = compr->private_data; data->stream.device = compr; runtime = kzalloc(sizeof(*runtime), GFP_KERNEL); if (!runtime) { kfree(data); return -ENOMEM; } runtime->state = SNDRV_PCM_STATE_OPEN; init_waitqueue_head(&runtime->sleep); data->stream.runtime = runtime; f->private_data = (void *)data; mutex_lock(&compr->lock); ret = compr->ops->open(&data->stream); mutex_unlock(&compr->lock); if (ret) { kfree(runtime); kfree(data); } return ret; }
static int pn547_dev_open(struct inode *inode, struct file *filp) { struct pn547_dev *pn547_dev = i2c_get_clientdata(pn547_client); filp->private_data = pn547_dev; pn547_enable_irq(pn547_dev); pr_debug("%s : %d,%d\n", __func__, imajor(inode), iminor(inode)); return 0; }
static int p3_dev_open(struct inode *inode, struct file *filp) { struct p3_dev *p3_dev = container_of(filp->private_data, struct p3_dev, p3_device); /* GPIO ctrl for Power */ int ret = 0; /* for defence MULTI-OPEN */ if (p3_dev->enabled_clk) { P3_ERR_MSG("%s - ALREADY opened!\n", __func__); return -EBUSY; } /* power ON at probe */ ret = p3_regulator_onoff(p3_dev, 1); if(ret < 0) P3_ERR_MSG(" test: failed to turn on LDO()\n"); usleep_range(5000, 5500); /*p3_dev->spi->max_speed_hz = 100000L; p3_dev->spi->mode = SPI_MODE_3; ret = spi_setup(p3_dev->spi); if (ret < 0) P3_ERR_MSG(" test: failed to do spi_setup-0()\n"); */ gpio_set_value(p3_dev->cs_gpio, 1); #ifdef ENABLE_ESE_P3_EXYNO_SPI if(s3c64xx_spi_change_gpio(ESE_DEFAULT) < 0) { P3_ERR_MSG("fail to set pinctrl default\n"); } else P3_ERR_MSG("ok to set pinctrl default\n"); #endif filp->private_data = p3_dev; P3_DBG_MSG("%s : Major No: %d, Minor No: %d\n", __func__, imajor(inode), iminor(inode)); p3_dev->null_buffer = kmalloc(DEFAULT_BUFFER_SIZE, GFP_KERNEL); if (p3_dev->null_buffer == NULL) { P3_ERR_MSG("%s null_buffer == NULL, -ENOMEM\n", __func__); return -ENOMEM; } p3_dev->buffer = kmalloc(DEFAULT_BUFFER_SIZE, GFP_KERNEL); if (p3_dev->buffer == NULL) { kfree(p3_dev->null_buffer); P3_ERR_MSG("%s : buffer == NULL, -ENOMEM\n", __func__); return -ENOMEM; } return 0; }
/* minor device 0 (simple access) structures */ static int dt330_flat_open(struct inode *inode, struct file *filp) { struct cardinfo *cp; cp= search_cardlist(imajor(inode)); if (!cp) return -ENODEV; if (cp->iocard_opened) return -EBUSY; cp->iocard_opened = 1; filp->private_data = (void *)cp; /* store card info in file structure */ return 0; }
int main() { int i; #ifdef CONFIG_INPUT_MOUSEDEV_PSAUX if (imajor(inode) == MISC_MAJOR) i = MOUSEDEV_MIX; else #endif i = iminor(inode) - MOUSEDEV_MINOR_BASE; }
/*************************************************************************** * * MTK-WIFI Device Operations * ***************************************************************************/ static int WIFI_open(struct inode *inode, struct file *file) { WIFI_INFO_FUNC("%s: major %d minor %d (pid %d)\n", __func__, imajor(inode), iminor(inode), current->pid ); return 0; }
static int devone_close(struct inode *inode, struct file *file) { printk("%s: major %d minor %d (pid %d)\n", __func__, imajor(inode), iminor(inode), current->pid ); return 0; }
static int pn547_dev_open(struct inode *inode, struct file *filp) { struct pn547_dev *pn547_dev = container_of(filp->private_data, struct pn547_dev, pn547_device); filp->private_data = pn547_dev; pr_debug("%s : %d,%d\n", __func__, imajor(inode), iminor(inode)); return 0; }
static int WMT_close(struct inode *inode, struct file *file) { WMT_INFO_FUNC("major %d minor %d (pid %d)\n", imajor(inode), iminor(inode), current->pid); if (atomic_dec_return(&gWmtRefCnt) == 0) { WMT_INFO_FUNC("last call\n"); } return 0; }
static int wmt_detect_open(struct inode *inode, struct file *file) { WMT_DETECT_INFO_FUNC("open major %d minor %d (pid %d)\n", imajor(inode), iminor(inode), current->pid ); return 0; }
//==================================================================== static ssize_t undelete_read (struct file *filp, char __user *buf, size_t count, loff_t *offp) { // Grab our context struct undelete_dev *dev = (struct undelete_dev *)filp->private_data; size_t bytes_to_read; DBG("%s called on dev %d, %d\n", __func__, imajor(filp->f_dentry->d_inode), iminor(filp->f_dentry->d_inode)); *offp = 0; // cuz we can't really seek... // TODO: // - From undelete_read, scan the file system for deleted inodes, writing // blocks of data to the shared buffer. You will either need to obtain a // reference to the file in which the file system is stored, or else // modify the fs/ext2/* parts of the kernel to support an "undelete" // super operation (see struct super_operations in include/linux/fs.h // and ext2_sops in fs/ext2/super.c) that interprets the file system at // a more abstract level. Note that you will only be able to invoke // kernel functions from this module that have been exposed via the // EXPORT_SYMBOL macro. // // - For each file that has been deleted, you should: // - Write a tar header for the file (see tar_utils.h) // - Write the data blocks of the file in TAR_BLOCKSIZE increments. // - Pad the final data block to a multiple of TAR_BLOCKSIZE bytes. // - Finally, write two empty blocks of size TAR_BLOCKSIZE to indicate the // end of the archive. // // Note that you will have to keep some state around to determine where // in the undelete operation you were during the previous call to // undelete_read. // Check that user memory is valid to write to and perform the write if (unlikely(!access_ok(VERIFY_WRITE, buf, count))) { return -EFAULT; } // Writes could cause this process to sleep if memory pages need to be // swapped in. Thus, undelete_read needs to be reentrant. We also make // sure that all the bytes were actually written. bytes_to_read = dev->buffer_write_offset - dev->buffer_read_offset; if (count < bytes_to_read) { bytes_to_read = count; } if (copy_to_user(buf, &dev->buffer[dev->buffer_read_offset], bytes_to_read) != 0) { ALERT("Couldn't finish copy_to_user."); return -EFAULT; } else { dev->buffer_read_offset += bytes_to_read; } return bytes_to_read; }
static int mymouse_open(struct inode *inode, struct file *file) { printk(KERN_INFO " OPENING my_mouse device: %s:", MYDEV_NAME); printk(KERN_INFO " MAJOR number = %d, MINOR number = %d\n", imajor(inode), iminor(inode)); atomic_set(&my_state.ready, 0); /* set Xserver pid */ user_pid = current->tgid; return 0; }
/*********************************************************************************** * MODULE : catsdrv_adc_open * ABSTRACT : CATS/FPGA デバイス・ファイル・[open] 操作 * FUNCTION : * ARGUMENT : * NOTE : * RETURN : 正常終了で「0」を返す。 * CREATE : 2009/08/24 新規作成 * UPDATE : ***********************************************************************************/ int catsdrv_adc_open( struct inode *inode, struct file *file ) { #if 0 printk(KERN_INFO "===== cats_module_adc: open\n"); printk(KERN_INFO "===== cats_module_adc: Major %d Minor %d (pid %d)\n", imajor(inode), iminor(inode), current->pid ); #endif return 0; }
/** * This function is called when a user wants to use this device * and has called the open function. * * The function will keep a count of how many people * tried to open it and increments it each time * this function is called * * The function prints out two pieces of information * 1. Number of times open() was called on this device * 2. Number of processes accessing this device right now * * Return value * Always returns SUCCESS * */ static int char_dev_open(struct inode *inode, struct file *file) { static int counter = 0; counter++; printk(KERN_INFO "Number of times open() was called: %d\n", counter); printk (KERN_INFO " MAJOR number = %d, MINOR number = %d\n",imajor (inode), iminor (inode)); printk(KERN_INFO "Process id of the current process: %d\n",current->pid ); printk (KERN_INFO "ref=%d\n", module_refcount(THIS_MODULE)); return SUCCESS; }
static int SMT113J_SPI_open(struct inode *inode, struct file *filp) { int ret = 0; unsigned int majorno = 0, minorno = 0; unsigned char *devarea = NULL; DEBUG_PRINT("SMT113J_SPI_open << Start >>"); majorno = imajor(filp->f_dentry->d_inode); minorno = iminor(filp->f_dentry->d_inode); if (( majorno != NODE_MAJOR ) || ( minorno != NODE_MINOR )) { ERROR_PRINT ("SMT113J_SPI_open Error : << No MAJOR(%d) or No MINOR(%d)", majorno, minorno ); return ( -ENODEV ); } /*** Private Data Area MALLOC Stataus Check ***/ if ( NULL != ( devarea = (unsigned char *)filp->private_data )) { ERROR_PRINT( "SMT113J_SPI_open Error : << Used Private Data Area[0x%08x] >>", (int)devarea ); return ( -ENODEV ); } /*** Private Data Area Alloc ***/ if ( NULL == ( devarea = (unsigned char *)kmalloc ( sizeof(smt113j_ioctl_data), GFP_KERNEL ))) { ERROR_PRINT( "SMT113J_SPI_open Error : << Used Private Data Area Alloc Error"); return ( -ENOMEM ) ; } memset ( devarea, 0, sizeof ( smt113j_ioctl_data )); filp->private_data = (void *)devarea; /*** buffer clear ***/ memset ( rx_pkt_buffer, 0, MAX_BUFFER_PKT * PAKCET_SIZE ); pwrite = 0; pread = 0; spi_open_cnt++; DEBUG_PRINT("SMT113J_SPI_open << End >>"); return ( ret ); }
static ssize_t mod_open(struct inode * i, struct file * f) { pr_info("skeleton : open operation, major version : %d, minor version : %d\n", imajor(i), iminor(i)); if((f->f_mode & (FMODE_READ | FMODE_WRITE)) != 0) pr_info("skeleton : opened for reading and writing...\n"); else if ((f->f_mode & (FMODE_READ)) != 0) pr_info("skeleton : opened for reading only\n"); else if ((f->f_mode & (FMODE_WRITE)) != 0) pr_info("skeleton : opened for writing only\n"); return 0; }
static int vdev_dev_open(struct inode *inode, struct file *filp) { struct vdev_dev_t *vdev_dev = container_of(filp->private_data, struct vdev_dev_t, vdev_device); filp->private_data = vdev_dev; printk("%s success: imajor:%d, iminor%d\n", __func__, imajor(inode), iminor(inode)); return 0; }
static int sanity_check_pcm(struct file *file) { unsigned short minor; if (imajor(file->f_dentry->d_inode) != snd_major) return -ENOTTY; minor = iminor(file->f_dentry->d_inode); if (minor >= 256 || minor % SNDRV_MINOR_DEVICES < SNDRV_MINOR_PCM_PLAYBACK) return -ENOTTY; return 0; }
static int irdaeg_fop_release(struct inode *inode, struct file *file) { printk( "%s: major %d minor %d (pid %d)\n", __func__, imajor(inode), iminor(inode), current->pid); /* Set Normal mode at the UART_PM2 register at MSM86550 */ iowrite32( UARTDM2_MODE_NORMAL , uart_dm2+UARTDM2_IRDA_ADDR ) ; iounmap( uart_dm2 ); printk( "%s:%d\n", __func__, __LINE__ ); return 0; }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - int hello_open(struct inode *inode, struct file *filp) { struct cdev *device = NULL; dev_t dev_num = 0; /* Obteniendo MAJOR y MINOR de la estructura INODE */ dev_num = MKDEV( imajor(inode) , iminor(inode) ) ; device = kmalloc(sizeof(struct cdev), GFP_KERNEL); //Normal allocation device->dev = dev_num; filp->private_data = device; return 0; }
int ads7870_cdrv_release(struct inode *inode, struct file *filep) { int major = imajor(inode); int minor = iminor(inode); printk("Closing ADS7870 Device [major], [minor]: %i, %i\n", major, minor); if (minor > NBR_ADC_CH-1) return -ENODEV; return 0; }
static int pn54x_dev_release(struct inode *inode, struct file *filp) { // struct pn54x_dev *pn54x_dev = container_of(filp->private_data, // struct pn54x_dev, // pn54x_device); pr_info("%s : closing %d,%d\n", __func__, imajor(inode), iminor(inode)); // pn544_disable(pn54x_dev); return 0; }
int psoc4_cdrv_release(struct inode *inode, struct file *filep) { int major = imajor(inode); int minor = iminor(inode); printk("cdrv_release: Closing psoc4 Device [major], [minor]: %i, %i\n", major, minor); if ((minor > psoc4_DEVICE-1) || !(psoc4_spi_device=psoc4_get_device())) return -ENODEV; return 0; }
/* * checks if the right device trys to access the queue * * returns: * ENODEV if the opening device node has the wrong major or minor number * 0 on success */ static int dev_open(struct inode* inode, struct file* filp) { if (imajor(inode) != MAJOR(dev_no) || iminor(inode) != MINOR(dev_no)) { printk(KERN_INFO "---- %s: dev_open failed, wrong device number(s)!\n", mod_name); return ENODEV; } filp->private_data = &fifo; return 0; }
static int pn547_dev_open(struct inode *inode, struct file *filp) { struct pn547_dev *pn547_dev = i2c_get_clientdata(pn547_client); filp->private_data = pn547_dev; #ifdef CONFIG_LGE_NFC_SET_IRQ_WAKEUP #else pn547_enable_irq(pn547_dev); #endif pr_debug("%s : %d,%d\n", __func__, imajor(inode), iminor(inode)); return 0; }