vfs.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright (C) 2016 Namjae Jeon <linkinjeon@kernel.org>
  4. * Copyright (C) 2018 Samsung Electronics Co., Ltd.
  5. */
  6. #ifndef __KSMBD_VFS_H__
  7. #define __KSMBD_VFS_H__
  8. #include <linux/file.h>
  9. #include <linux/fs.h>
  10. #include <linux/namei.h>
  11. #include <uapi/linux/xattr.h>
  12. #include <linux/posix_acl.h>
  13. #include <linux/unicode.h>
  14. #include "smbacl.h"
  15. #include "xattr.h"
  16. /*
  17. * Enumeration for stream type.
  18. */
  19. enum {
  20. DATA_STREAM = 1, /* type $DATA */
  21. DIR_STREAM /* type $INDEX_ALLOCATION */
  22. };
  23. /* CreateOptions */
  24. #define CREATE_TREE_CONNECTION cpu_to_le32(0x00000080)
  25. #define FILE_RESERVE_OPFILTER_LE cpu_to_le32(0x00100000)
  26. #define CREATE_OPTION_READONLY 0x10000000
  27. /* system. NB not sent over wire */
  28. #define CREATE_OPTION_SPECIAL 0x20000000
  29. struct ksmbd_work;
  30. struct ksmbd_file;
  31. struct ksmbd_conn;
  32. struct ksmbd_dir_info {
  33. const char *name;
  34. char *wptr;
  35. char *rptr;
  36. int name_len;
  37. int out_buf_len;
  38. int num_scan;
  39. int num_entry;
  40. int data_count;
  41. int last_entry_offset;
  42. bool hide_dot_file;
  43. int flags;
  44. int last_entry_off_align;
  45. };
  46. struct ksmbd_readdir_data {
  47. struct dir_context ctx;
  48. union {
  49. void *private;
  50. char *dirent;
  51. };
  52. unsigned int used;
  53. unsigned int dirent_count;
  54. unsigned int file_attr;
  55. struct unicode_map *um;
  56. };
  57. /* ksmbd kstat wrapper to get valid create time when reading dir entry */
  58. struct ksmbd_kstat {
  59. struct kstat *kstat;
  60. unsigned long long create_time;
  61. __le32 file_attributes;
  62. };
  63. int ksmbd_vfs_lock_parent(struct dentry *parent, struct dentry *child);
  64. void ksmbd_vfs_query_maximal_access(struct mnt_idmap *idmap,
  65. struct dentry *dentry, __le32 *daccess);
  66. int ksmbd_vfs_create(struct ksmbd_work *work, const char *name, umode_t mode);
  67. int ksmbd_vfs_mkdir(struct ksmbd_work *work, const char *name, umode_t mode);
  68. int ksmbd_vfs_read(struct ksmbd_work *work, struct ksmbd_file *fp, size_t count,
  69. loff_t *pos, char *rbuf);
  70. int ksmbd_vfs_write(struct ksmbd_work *work, struct ksmbd_file *fp,
  71. char *buf, size_t count, loff_t *pos, bool sync,
  72. ssize_t *written);
  73. int ksmbd_vfs_fsync(struct ksmbd_work *work, u64 fid, u64 p_id);
  74. int ksmbd_vfs_remove_file(struct ksmbd_work *work, const struct path *path);
  75. int ksmbd_vfs_link(struct ksmbd_work *work,
  76. const char *oldname, const char *newname);
  77. int ksmbd_vfs_getattr(const struct path *path, struct kstat *stat);
  78. int ksmbd_vfs_rename(struct ksmbd_work *work, const struct path *old_path,
  79. char *newname, int flags);
  80. int ksmbd_vfs_truncate(struct ksmbd_work *work,
  81. struct ksmbd_file *fp, loff_t size);
  82. struct srv_copychunk;
  83. int ksmbd_vfs_copy_file_ranges(struct ksmbd_work *work,
  84. struct ksmbd_file *src_fp,
  85. struct ksmbd_file *dst_fp,
  86. struct srv_copychunk *chunks,
  87. unsigned int chunk_count,
  88. unsigned int *chunk_count_written,
  89. unsigned int *chunk_size_written,
  90. loff_t *total_size_written);
  91. ssize_t ksmbd_vfs_listxattr(struct dentry *dentry, char **list);
  92. ssize_t ksmbd_vfs_getxattr(struct mnt_idmap *idmap,
  93. struct dentry *dentry,
  94. char *xattr_name,
  95. char **xattr_buf);
  96. ssize_t ksmbd_vfs_casexattr_len(struct mnt_idmap *idmap,
  97. struct dentry *dentry, char *attr_name,
  98. int attr_name_len);
  99. int ksmbd_vfs_setxattr(struct mnt_idmap *idmap,
  100. const struct path *path, const char *attr_name,
  101. void *attr_value, size_t attr_size, int flags,
  102. bool get_write);
  103. int ksmbd_vfs_xattr_stream_name(char *stream_name, char **xattr_stream_name,
  104. size_t *xattr_stream_name_size, int s_type);
  105. int ksmbd_vfs_remove_xattr(struct mnt_idmap *idmap,
  106. const struct path *path, char *attr_name,
  107. bool get_write);
  108. int ksmbd_vfs_kern_path_locked(struct ksmbd_work *work, char *name,
  109. unsigned int flags, struct path *parent_path,
  110. struct path *path, bool caseless);
  111. void ksmbd_vfs_kern_path_unlock(struct path *parent_path, struct path *path);
  112. struct dentry *ksmbd_vfs_kern_path_create(struct ksmbd_work *work,
  113. const char *name,
  114. unsigned int flags,
  115. struct path *path);
  116. int ksmbd_vfs_empty_dir(struct ksmbd_file *fp);
  117. void ksmbd_vfs_set_fadvise(struct file *filp, __le32 option);
  118. int ksmbd_vfs_zero_data(struct ksmbd_work *work, struct ksmbd_file *fp,
  119. loff_t off, loff_t len);
  120. struct file_allocated_range_buffer;
  121. int ksmbd_vfs_fqar_lseek(struct ksmbd_file *fp, loff_t start, loff_t length,
  122. struct file_allocated_range_buffer *ranges,
  123. unsigned int in_count, unsigned int *out_count);
  124. int ksmbd_vfs_unlink(struct file *filp);
  125. void *ksmbd_vfs_init_kstat(char **p, struct ksmbd_kstat *ksmbd_kstat);
  126. int ksmbd_vfs_fill_dentry_attrs(struct ksmbd_work *work,
  127. struct mnt_idmap *idmap,
  128. struct dentry *dentry,
  129. struct ksmbd_kstat *ksmbd_kstat);
  130. void ksmbd_vfs_posix_lock_wait(struct file_lock *flock);
  131. int ksmbd_vfs_posix_lock_wait_timeout(struct file_lock *flock, long timeout);
  132. void ksmbd_vfs_posix_lock_unblock(struct file_lock *flock);
  133. int ksmbd_vfs_remove_acl_xattrs(struct mnt_idmap *idmap,
  134. const struct path *path);
  135. int ksmbd_vfs_remove_sd_xattrs(struct mnt_idmap *idmap, const struct path *path);
  136. int ksmbd_vfs_set_sd_xattr(struct ksmbd_conn *conn,
  137. struct mnt_idmap *idmap,
  138. const struct path *path,
  139. struct smb_ntsd *pntsd, int len,
  140. bool get_write);
  141. int ksmbd_vfs_get_sd_xattr(struct ksmbd_conn *conn,
  142. struct mnt_idmap *idmap,
  143. struct dentry *dentry,
  144. struct smb_ntsd **pntsd);
  145. int ksmbd_vfs_set_dos_attrib_xattr(struct mnt_idmap *idmap,
  146. const struct path *path,
  147. struct xattr_dos_attrib *da,
  148. bool get_write);
  149. int ksmbd_vfs_get_dos_attrib_xattr(struct mnt_idmap *idmap,
  150. struct dentry *dentry,
  151. struct xattr_dos_attrib *da);
  152. int ksmbd_vfs_set_init_posix_acl(struct mnt_idmap *idmap,
  153. struct path *path);
  154. int ksmbd_vfs_inherit_posix_acl(struct mnt_idmap *idmap,
  155. struct path *path,
  156. struct inode *parent_inode);
  157. #endif /* __KSMBD_VFS_H__ */