"\\SystemRoot\\", NULL};
/*
- * cfs_filp_open
+ * filp_open
* To open or create a file in kernel mode
*
* Arguments:
* err: error code
*
* Return Value:
- * the pointer to the cfs_file_t or NULL if it fails
+ * the pointer to the struct file or NULL if it fails
*
- * Notes:
+ * Notes:
* N/A
*/
#define is_drv_letter_valid(x) (((x) >= 0 && (x) <= 9) || \
( ((x)|0x20) <= 'z' && ((x)|0x20) >= 'a'))
-cfs_file_t *cfs_filp_open(const char *name, int flags, int mode, int *err)
+struct file *filp_open(const char *name, int flags, int mode, int *err)
{
- cfs_file_t * fp = NULL;
+ struct file *fp = NULL;
NTSTATUS Status;
/* Initialize the unicode path name for the specified file */
NameLength = (USHORT)strlen(name);
- /* Check file & path name */
- if (name[0] != '\\') {
- if (NameLength < 1 || name[1] != ':' || !is_drv_letter_valid(name[0])) {
- /* invalid file path name */
- if (err) *err = -EINVAL;
- return NULL;
- }
- PrefixLength = (USHORT)strlen(dos_file_prefix[0]);
- } else {
- int i, j;
- for (i=0; i < 3 && dos_file_prefix[i] != NULL; i++) {
- j = strlen(dos_file_prefix[i]);
- if (NameLength > j && _strnicmp(dos_file_prefix[i], name, j) == 0) {
- break;
- }
- }
- if (i >= 3) {
- if (err) *err = -EINVAL;
- return NULL;
- }
- }
-
- AnsiString = cfs_alloc( sizeof(CHAR) * (NameLength + PrefixLength + 1),
- CFS_ALLOC_ZERO);
- if (NULL == AnsiString) {
- if (err) *err = -ENOMEM;
- return NULL;
- }
-
- UnicodeString = cfs_alloc( sizeof(WCHAR) * (NameLength + PrefixLength + 1),
- CFS_ALLOC_ZERO);
- if (NULL == UnicodeString) {
- if (err) *err = -ENOMEM;
- cfs_free(AnsiString);
- return NULL;
- }
+ /* Check file & path name */
+ if (name[0] != '\\') {
+ if (NameLength < 1 || name[1] != ':' ||
+ !is_drv_letter_valid(name[0])) {
+ /* invalid file path name */
+ return ERR_PTR(-EINVAL);
+ }
+ PrefixLength = (USHORT)strlen(dos_file_prefix[0]);
+ } else {
+ int i, j;
+ for (i = 0; i < 3 && dos_file_prefix[i] != NULL; i++) {
+ j = strlen(dos_file_prefix[i]);
+ if (NameLength > j &&
+ _strnicmp(dos_file_prefix[i], name, j) == 0)
+ break;
+ }
+ if (i >= 3)
+ return ERR_PTR(-EINVAL);
+ }
+
+ AnsiString = kmalloc(sizeof(CHAR) * (NameLength + PrefixLength + 1),
+ __GFP_ZERO);
+ if (NULL == AnsiString)
+ return ERR_PTR(-ENOMEM);
+
+ UnicodeString =
+ kmalloc(sizeof(WCHAR) * (NameLength + PrefixLength + 1),
+ __GFP_ZERO);
+ if (NULL == UnicodeString) {
+ kfree(AnsiString);
+ return ERR_PTR(-ENOMEM);
+ }
if (PrefixLength) {
RtlCopyMemory(&AnsiString[0], dos_file_prefix[0], PrefixLength);
NULL,
0 );
- /* Check the returned status of IoStatus... */
- if (!NT_SUCCESS(IoStatus.Status)) {
- if (err) {
- *err = cfs_error_code(IoStatus.Status);
- }
- cfs_free(UnicodeString);
- cfs_free(AnsiString);
- return NULL;
- }
+ /* Check the returned status of IoStatus... */
+ if (!NT_SUCCESS(IoStatus.Status)) {
+ kfree(UnicodeString);
+ kfree(AnsiString);
+ return ERR_PTR(cfs_error_code(IoStatus.Status));
+ }
- /* Allocate the cfs_file_t: libcfs file object */
- fp = cfs_alloc(sizeof(cfs_file_t) + NameLength, CFS_ALLOC_ZERO);
+ /* Allocate the file_t: libcfs file object */
+ fp = kmalloc(sizeof(*fp) + NameLength, __GFP_ZERO);
- if (NULL == fp) {
- Status = ZwClose(FileHandle);
- ASSERT(NT_SUCCESS(Status));
- if (err) {
- *err = -ENOMEM;
- }
- cfs_free(UnicodeString);
- cfs_free(AnsiString);
- return NULL;
- }
+ if (NULL == fp) {
+ Status = ZwClose(FileHandle);
+ ASSERT(NT_SUCCESS(Status));
+ kfree(UnicodeString);
+ kfree(AnsiString);
+ return ERR_PTR(-ENOMEM);
+ }
fp->f_handle = FileHandle;
strcpy(fp->f_name, name);
fp->f_flags = flags;
fp->f_mode = (mode_t)mode;
fp->f_count = 1;
- if (err) {
- *err = 0;
- }
- /* free the memory of temporary name strings */
- cfs_free(UnicodeString);
- cfs_free(AnsiString);
+ /* free the memory of temporary name strings */
+ kfree(UnicodeString);
+ kfree(AnsiString);
- return fp;
+ return fp;
}
/*
- * cfs_filp_close
+ * filp_close
* To close the opened file and release the filp structure
*
* Arguments:
- * fp: the pointer of the cfs_file_t strcture
+ * fp: the pointer of the file structure
*
* Return Value:
* ZERO: on success
* Non-Zero: on failure
*
- * Notes:
+ * Notes:
* N/A
*/
-int cfs_filp_close(cfs_file_t *fp)
+int filp_close(file_t *fp, void *id)
{
NTSTATUS Status;
Status = ZwClose(fp->f_handle);
ASSERT(NT_SUCCESS(Status));
- /* free the file flip structure */
- cfs_free(fp);
- return 0;
+ /* free the file flip structure */
+ kfree(fp);
+ return 0;
}
}
/*
- * cfs_filp_read
+ * filp_read
* To read data from the opened file
*
* Arguments:
- * fp: the pointer of the cfs_file_t strcture
+ * fp: the pointer of the file strcture
* buf: pointer to the buffer to contain the data
* nbytes: size in bytes to be read from the file
* pos: offset in file where reading starts, if pos
* Notes:
* N/A
*/
-
-int cfs_filp_read(cfs_file_t *fp, void *buf, size_t nbytes, loff_t *pos)
+int filp_read(struct file *fp, void *buf, size_t nbytes, loff_t *pos)
{
LARGE_INTEGER offset;
NTSTATUS status;
* To write specified data to the opened file
*
* Arguments:
- * fp: the pointer of the cfs_file_t strcture
+ * fp: the pointer of the file strcture
* buf: pointer to the buffer containing the data
* nbytes: size in bytes to be written to the file
* pos: offset in file where writing starts, if pos
* N/A
*/
-int cfs_filp_write(cfs_file_t *fp, void *buf, size_t nbytes, loff_t *pos)
+int filp_write(struct file *fp, void *buf, size_t nbytes, loff_t *pos)
{
LARGE_INTEGER offset;
NTSTATUS status;
}
/*
- * cfs_filp_fsync
+ * filp_fsync
* To sync the dirty data of the file to disk
*
* Arguments:
- * fp: the pointer of the cfs_file_t strcture
+ * fp: the pointer of the file strcture
*
* Return Value:
* Zero: in success case
* we must allocate our own Irp and issue it to the file
* system driver.
*/
-
-int cfs_filp_fsync(cfs_file_t *fp)
+int filp_fsync(struct file *fp)
{
-
PFILE_OBJECT FileObject;
PDEVICE_OBJECT DeviceObject;
}
/*
- * cfs_get_file
+ * get_file
* To increase the reference of the file object
*
* Arguments:
- * fp: the pointer of the cfs_file_t strcture
+ * fp: the pointer of the file strcture
*
* Return Value:
* Zero: in success case
* N/A
*/
-int cfs_get_file(cfs_file_t *fp)
+int get_file(struct file *fp)
{
InterlockedIncrement(&(fp->f_count));
return 0;
/*
- * cfs_put_file
+ * fput
* To decrease the reference of the file object
*
* Arguments:
- * fp: the pointer of the cfs_file_t strcture
+ * fp: the pointer of the file strcture
*
* Return Value:
* Zero: in success case
* Non-Zero: in failure case
*
- * Notes:
+ * Notes:
* N/A
*/
-int cfs_put_file(cfs_file_t *fp)
+int fput(struct file *fp)
{
- if (InterlockedDecrement(&(fp->f_count)) == 0) {
- cfs_filp_close(fp);
- }
+ if (InterlockedDecrement(&(fp->f_count)) == 0)
+ filp_close(fp, NULL);
- return 0;
+ return 0;
}
/*
- * cfs_file_count
+ * file_count
* To query the reference count of the file object
*
* Arguments:
- * fp: the pointer of the cfs_file_t strcture
+ * fp: the pointer of the file strcture
*
* Return Value:
* the reference count of the file object
* N/A
*/
-int cfs_file_count(cfs_file_t *fp)
+int file_count(struct file *fp)
{
- return (int)(fp->f_count);
+ return (int)(fp->f_count);
}
struct dentry *dget(struct dentry *de)
return;
}
if (cfs_atomic_dec_and_test(&de->d_count)) {
- cfs_free(de);
+ kfree(de);
}
}