fs.c 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382
  1. /* Copyright (C) 2014 Stony Brook University
  2. This file is part of Graphene Library OS.
  3. Graphene Library OS is free software: you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public License
  5. as published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. Graphene Library OS is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  13. /*
  14. * fs.c
  15. *
  16. * This file contains codes for implementation of 'chroot' filesystem.
  17. */
  18. #include <shim_internal.h>
  19. #include <shim_thread.h>
  20. #include <shim_handle.h>
  21. #include <shim_vma.h>
  22. #include <shim_fs.h>
  23. #include <shim_utils.h>
  24. #include <shim_profile.h>
  25. #include <pal.h>
  26. #include <pal_error.h>
  27. #include <errno.h>
  28. #include <linux/stat.h>
  29. #include <linux/fcntl.h>
  30. #include <asm/fcntl.h>
  31. #include <asm/mman.h>
  32. #include <asm/unistd.h>
  33. #include <asm/prctl.h>
  34. #define URI_MAX_SIZE STR_SIZE
  35. #define TTY_FILE_MODE 0666
  36. #define FILE_BUFMAP_SIZE (PAL_CB(alloc_align) * 4)
  37. #define FILE_BUF_SIZE (PAL_CB(alloc_align))
  38. struct mount_data {
  39. size_t data_size;
  40. enum shim_file_type base_type;
  41. unsigned long ino_base;
  42. size_t root_uri_len;
  43. char root_uri[];
  44. };
  45. #define HANDLE_MOUNT_DATA(h) ((struct mount_data*)(h)->fs->data)
  46. #define DENTRY_MOUNT_DATA(d) ((struct mount_data*)(d)->fs->data)
  47. static int chroot_mount (const char * uri, void ** mount_data)
  48. {
  49. enum shim_file_type type;
  50. if (strstartswith_static(uri, URI_PREFIX_FILE)) {
  51. type = FILE_UNKNOWN;
  52. uri += 5;
  53. } else if (strstartswith_static(uri, URI_PREFIX_DEV)) {
  54. type = strstartswith_static(uri + static_strlen(URI_PREFIX_DEV), "tty") ? FILE_TTY : FILE_DEV;
  55. uri += 4;
  56. } else {
  57. return -EINVAL;
  58. }
  59. if (!(*uri))
  60. uri = ".";
  61. int uri_len = strlen(uri);
  62. int data_size = uri_len + 1 + sizeof(struct mount_data);
  63. struct mount_data * mdata = (struct mount_data *) malloc(data_size);
  64. mdata->data_size = data_size;
  65. mdata->base_type = type;
  66. mdata->ino_base = hash_path(uri, uri_len);
  67. mdata->root_uri_len = uri_len;
  68. memcpy(mdata->root_uri, uri, uri_len + 1);
  69. *mount_data = mdata;
  70. return 0;
  71. }
  72. static int chroot_unmount (void * mount_data)
  73. {
  74. free(mount_data);
  75. return 0;
  76. }
  77. static inline ssize_t concat_uri (char * buffer, size_t size, int type,
  78. const char * root, size_t root_len,
  79. const char * trim, size_t trim_len)
  80. {
  81. char * tmp = NULL;
  82. switch (type) {
  83. case FILE_UNKNOWN:
  84. case FILE_REGULAR:
  85. tmp = strcpy_static(buffer, URI_PREFIX_FILE, size);
  86. break;
  87. case FILE_DIR:
  88. tmp = strcpy_static(buffer, URI_PREFIX_DIR, size);
  89. break;
  90. case FILE_DEV:
  91. case FILE_TTY:
  92. tmp = strcpy_static(buffer, URI_PREFIX_DEV, size);
  93. break;
  94. default:
  95. return -EINVAL;
  96. }
  97. if (!tmp || tmp + root_len + trim_len + 2 > buffer + size)
  98. return -ENAMETOOLONG;
  99. if (root_len) {
  100. memcpy(tmp, root, root_len + 1);
  101. tmp += root_len;
  102. }
  103. if (trim_len) {
  104. *(tmp++) = '/';
  105. memcpy(tmp, trim, trim_len + 1);
  106. tmp += trim_len;
  107. }
  108. return tmp - buffer;
  109. }
  110. /* simply just create data, sometimes it is individually called when the
  111. handle is not linked to a dentry */
  112. static struct shim_file_data * __create_data (void)
  113. {
  114. struct shim_file_data * data = calloc(1, sizeof(struct shim_file_data));
  115. if (!data)
  116. return NULL;
  117. create_lock(&data->lock);
  118. return data;
  119. }
  120. static void __destroy_data (struct shim_file_data * data)
  121. {
  122. qstrfree(&data->host_uri);
  123. destroy_lock(&data->lock);
  124. free(data);
  125. }
  126. static ssize_t make_uri (struct shim_dentry * dent)
  127. {
  128. struct mount_data * mdata = DENTRY_MOUNT_DATA(dent);
  129. assert(mdata);
  130. struct shim_file_data * data = FILE_DENTRY_DATA(dent);
  131. char uri[URI_MAX_SIZE];
  132. ssize_t len = concat_uri(uri, URI_MAX_SIZE, data->type,
  133. mdata->root_uri,
  134. mdata->root_uri_len,
  135. qstrgetstr(&dent->rel_path),
  136. dent->rel_path.len);
  137. if (len >= 0)
  138. qstrsetstr(&data->host_uri, uri, len);
  139. return len;
  140. }
  141. /* create a data in the dentry and compose it's uri. dent->lock needs to
  142. be held */
  143. static int create_data (struct shim_dentry * dent, const char * uri, size_t len)
  144. {
  145. assert(locked(&dent->lock));
  146. if (dent->data)
  147. return 0;
  148. struct shim_file_data * data = __create_data();
  149. if (!data)
  150. return -ENOMEM;
  151. dent->data = data;
  152. struct mount_data * mdata = DENTRY_MOUNT_DATA(dent);
  153. assert(mdata);
  154. data->type = (dent->state & DENTRY_ISDIRECTORY) ?
  155. FILE_DIR : mdata->base_type;
  156. data->mode = NO_MODE;
  157. if (uri) {
  158. qstrsetstr(&data->host_uri, uri, len);
  159. } else {
  160. int ret = make_uri(dent);
  161. if (ret < 0)
  162. return ret;
  163. }
  164. atomic_set(&data->version, 0);
  165. return 0;
  166. }
  167. static int chroot_readdir (struct shim_dentry * dent,
  168. struct shim_dirent ** dirent);
  169. static int __query_attr (struct shim_dentry * dent,
  170. struct shim_file_data * data, PAL_HANDLE pal_handle)
  171. {
  172. PAL_STREAM_ATTR pal_attr;
  173. enum shim_file_type old_type = data->type;
  174. if (pal_handle ?
  175. !DkStreamAttributesQueryByHandle(pal_handle, &pal_attr) :
  176. !DkStreamAttributesQuery(qstrgetstr(&data->host_uri), &pal_attr))
  177. return -PAL_ERRNO;
  178. /* need to correct the data type */
  179. if (data->type == FILE_UNKNOWN)
  180. switch (pal_attr.handle_type) {
  181. case pal_type_file: data->type = FILE_REGULAR; if (dent) dent->type = S_IFREG; break;
  182. case pal_type_dir: data->type = FILE_DIR; if (dent) dent->type = S_IFDIR; break;
  183. case pal_type_dev: data->type = FILE_DEV; if (dent) dent->type = S_IFCHR; break;
  184. }
  185. data->mode = (pal_attr.readable ? S_IRUSR : 0) |
  186. (pal_attr.writable ? S_IWUSR : 0) |
  187. (pal_attr.runnable ? S_IXUSR : 0);
  188. atomic_set(&data->size, pal_attr.pending_size);
  189. if (data->type == FILE_DIR) {
  190. int ret;
  191. /* Move up the uri update; need to convert manifest-level file:
  192. * directives to 'dir:' uris */
  193. if (old_type != FILE_DIR) {
  194. dent->state |= DENTRY_ISDIRECTORY;
  195. if ((ret = make_uri(dent)) < 0) {
  196. unlock(&data->lock);
  197. return ret;
  198. }
  199. }
  200. /* DEP 3/18/17: If we have a directory, we need to find out how many
  201. * children it has by hand. */
  202. /* XXX: Keep coherent with rmdir/mkdir/creat, etc */
  203. struct shim_dirent *d, *dbuf = NULL;
  204. size_t nlink = 0;
  205. int rv = chroot_readdir(dent, &dbuf);
  206. if (rv != 0)
  207. return rv;
  208. if (dbuf) {
  209. for (d = dbuf; d; d = d->next)
  210. nlink++;
  211. free(dbuf);
  212. } else {
  213. nlink = 2; // Educated guess...
  214. }
  215. data->nlink = nlink;
  216. } else {
  217. /* DEP 3/18/17: Right now, we don't support hard links,
  218. * so just return 1;
  219. */
  220. data->nlink = 1;
  221. }
  222. data->queried = true;
  223. return 0;
  224. }
  225. /* do not need any lock */
  226. static void chroot_update_ino (struct shim_dentry * dent)
  227. {
  228. if (dent->state & DENTRY_INO_UPDATED)
  229. return;
  230. struct mount_data * mdata = DENTRY_MOUNT_DATA(dent);
  231. unsigned long ino = mdata->ino_base;
  232. if (!qstrempty(&dent->rel_path))
  233. ino = rehash_path(mdata->ino_base, qstrgetstr(&dent->rel_path),
  234. dent->rel_path.len);
  235. dent->ino = ino;
  236. dent->state |= DENTRY_INO_UPDATED;
  237. }
  238. static inline int try_create_data (struct shim_dentry * dent,
  239. const char * uri, size_t len,
  240. struct shim_file_data ** dataptr)
  241. {
  242. struct shim_file_data * data = FILE_DENTRY_DATA(dent);
  243. if (!data) {
  244. lock(&dent->lock);
  245. int ret = create_data(dent, uri, len);
  246. data = FILE_DENTRY_DATA(dent);
  247. unlock(&dent->lock);
  248. if (ret < 0) {
  249. return ret;
  250. }
  251. }
  252. *dataptr = data;
  253. return 0;
  254. }
  255. static int query_dentry (struct shim_dentry * dent, PAL_HANDLE pal_handle,
  256. mode_t * mode, struct stat * stat)
  257. {
  258. int ret = 0;
  259. struct shim_file_data * data;
  260. if ((ret = try_create_data(dent, NULL, 0, &data)) < 0)
  261. return ret;
  262. lock(&data->lock);
  263. if (!data->queried && (ret = __query_attr(dent, data, pal_handle)) < 0) {
  264. unlock(&data->lock);
  265. return ret;
  266. }
  267. if (mode)
  268. *mode = data->mode;
  269. if (stat) {
  270. struct mount_data * mdata = DENTRY_MOUNT_DATA(dent);
  271. chroot_update_ino(dent);
  272. memset(stat, 0, sizeof(struct stat));
  273. stat->st_mode = (mode_t) data->mode;
  274. stat->st_dev = (dev_t) mdata->ino_base;
  275. stat->st_ino = (ino_t) dent->ino;
  276. stat->st_size = (off_t) atomic_read(&data->size);
  277. stat->st_atime = (time_t) data->atime;
  278. stat->st_mtime = (time_t) data->mtime;
  279. stat->st_ctime = (time_t) data->ctime;
  280. stat->st_nlink = data->nlink;
  281. switch (data->type) {
  282. case FILE_REGULAR:
  283. stat->st_mode |= S_IFREG;
  284. break;
  285. case FILE_DIR:
  286. stat->st_mode |= S_IFDIR;
  287. break;
  288. case FILE_DEV:
  289. case FILE_TTY:
  290. stat->st_mode |= S_IFCHR;
  291. break;
  292. default: break;
  293. }
  294. }
  295. unlock(&data->lock);
  296. return 0;
  297. }
  298. static int chroot_mode (struct shim_dentry * dent, mode_t * mode)
  299. {
  300. return query_dentry(dent, NULL, mode, NULL);
  301. }
  302. static int chroot_stat (struct shim_dentry * dent, struct stat * statbuf)
  303. {
  304. return query_dentry(dent, NULL, NULL, statbuf);
  305. }
  306. static int chroot_lookup (struct shim_dentry * dent)
  307. {
  308. return query_dentry(dent, NULL, NULL, NULL);
  309. }
  310. static int __chroot_open (struct shim_dentry * dent,
  311. const char * uri, int flags, mode_t mode,
  312. struct shim_handle * hdl,
  313. struct shim_file_data * data)
  314. {
  315. int ret = 0;
  316. if (!uri) {
  317. uri = qstrgetstr(&data->host_uri);
  318. }
  319. int version = atomic_read(&data->version);
  320. int oldmode = flags & O_ACCMODE;
  321. int accmode = oldmode;
  322. int creat = flags & PAL_CREATE_MASK;
  323. int option = flags & PAL_OPTION_MASK;
  324. if ((data->type == FILE_REGULAR || data->type == FILE_UNKNOWN)
  325. && accmode == O_WRONLY)
  326. accmode = O_RDWR;
  327. PAL_HANDLE palhdl;
  328. if (hdl && hdl->pal_handle) {
  329. palhdl = hdl->pal_handle;
  330. } else {
  331. palhdl = DkStreamOpen(uri, accmode, mode, creat, option);
  332. if (!palhdl) {
  333. if (PAL_NATIVE_ERRNO == PAL_ERROR_DENIED &&
  334. accmode != oldmode)
  335. palhdl = DkStreamOpen(uri, oldmode, mode, creat, option);
  336. if (!palhdl)
  337. return -PAL_ERRNO;
  338. }
  339. /* If DENTRY_LISTED is set on the parent dentry, list_directory_dentry() will not update
  340. * dent's ino, so ino will be actively updated here. */
  341. if (creat)
  342. chroot_update_ino(dent);
  343. }
  344. if (!data->queried) {
  345. lock(&data->lock);
  346. ret = __query_attr(dent, data, palhdl);
  347. unlock(&data->lock);
  348. }
  349. if (!hdl) {
  350. DkObjectClose(palhdl);
  351. return 0;
  352. }
  353. hdl->pal_handle = palhdl;
  354. hdl->info.file.type = data->type;
  355. hdl->info.file.version = version;
  356. hdl->info.file.size = atomic_read(&data->size);
  357. hdl->info.file.data = data;
  358. return ret;
  359. }
  360. static int chroot_open (struct shim_handle * hdl, struct shim_dentry * dent,
  361. int flags)
  362. {
  363. int ret = 0;
  364. struct shim_file_data * data;
  365. if ((ret = try_create_data(dent, NULL, 0, &data)) < 0)
  366. return ret;
  367. if (dent->mode == NO_MODE) {
  368. lock(&data->lock);
  369. ret = __query_attr(dent, data, NULL);
  370. dent->mode = data->mode;
  371. unlock(&data->lock);
  372. }
  373. if ((ret = __chroot_open(dent, NULL, flags, dent->mode, hdl, data)) < 0)
  374. return ret;
  375. struct shim_file_handle * file = &hdl->info.file;
  376. off_t size = atomic_read(&data->size);
  377. /* initialize hdl, does not need a lock because no one is sharing */
  378. hdl->type = TYPE_FILE;
  379. file->marker = (flags & O_APPEND) ? size : 0;
  380. file->size = size;
  381. file->buf_type = (data->type == FILE_REGULAR) ? FILEBUF_MAP : FILEBUF_NONE;
  382. hdl->flags = flags;
  383. hdl->acc_mode = ACC_MODE(flags & O_ACCMODE);
  384. qstrcopy(&hdl->uri, &data->host_uri);
  385. return 0;
  386. }
  387. static int chroot_creat (struct shim_handle * hdl, struct shim_dentry * dir,
  388. struct shim_dentry * dent, int flags, mode_t mode)
  389. {
  390. int ret = 0;
  391. struct shim_file_data * data;
  392. if ((ret = try_create_data(dent, NULL, 0, &data)) < 0)
  393. return ret;
  394. if ((ret = __chroot_open(dent, NULL, flags|O_CREAT|O_EXCL, mode, hdl,
  395. data)) < 0)
  396. return ret;
  397. if (!hdl)
  398. return 0;
  399. struct shim_file_handle * file = &hdl->info.file;
  400. off_t size = atomic_read(&data->size);
  401. /* initialize hdl, does not need a lock because no one is sharing */
  402. hdl->type = TYPE_FILE;
  403. file->marker = (flags & O_APPEND) ? size : 0;
  404. file->size = size;
  405. file->buf_type = (data->type == FILE_REGULAR) ? FILEBUF_MAP : FILEBUF_NONE;
  406. hdl->flags = flags;
  407. hdl->acc_mode = ACC_MODE(flags & O_ACCMODE);
  408. qstrcopy(&hdl->uri, &data->host_uri);
  409. /* Increment the parent's link count */
  410. struct shim_file_data *parent_data = FILE_DENTRY_DATA(dir);
  411. if (parent_data) {
  412. lock(&parent_data->lock);
  413. if (parent_data->queried)
  414. parent_data->nlink++;
  415. unlock(&parent_data->lock);
  416. }
  417. return 0;
  418. }
  419. static int chroot_mkdir (struct shim_dentry * dir, struct shim_dentry * dent,
  420. mode_t mode)
  421. {
  422. int ret = 0;
  423. struct shim_file_data * data;
  424. if ((ret = try_create_data(dent, NULL, 0, &data)) < 0)
  425. return ret;
  426. if (data->type != FILE_DIR) {
  427. data->type = FILE_DIR;
  428. int ret = make_uri(dent);
  429. if (ret < 0)
  430. return ret;
  431. }
  432. ret = __chroot_open(dent, NULL, O_CREAT|O_EXCL, mode, NULL, data);
  433. /* Increment the parent's link count */
  434. struct shim_file_data *parent_data = FILE_DENTRY_DATA(dir);
  435. if (parent_data) {
  436. lock(&parent_data->lock);
  437. if (parent_data->queried)
  438. parent_data->nlink++;
  439. unlock(&parent_data->lock);
  440. }
  441. return ret;
  442. }
  443. #define NEED_RECREATE(hdl) (!FILE_HANDLE_DATA(hdl))
  444. static int chroot_recreate (struct shim_handle * hdl)
  445. {
  446. struct shim_file_data * data = FILE_HANDLE_DATA(hdl);
  447. int ret = 0;
  448. /* quickly bail out if the data is created */
  449. if (data)
  450. return 0;
  451. const char * uri = qstrgetstr(&hdl->uri);
  452. size_t len = hdl->uri.len;
  453. if (hdl->dentry) {
  454. if ((ret = try_create_data(hdl->dentry, uri, len, &data)) < 0)
  455. return ret;
  456. } else {
  457. data = __create_data();
  458. if (!data)
  459. return -ENOMEM;
  460. qstrsetstr(&data->host_uri, uri, len);
  461. }
  462. /*
  463. * when recreating a file handle after migration, the file should
  464. * not be created again.
  465. */
  466. return __chroot_open(hdl->dentry, uri, hdl->flags & ~(O_CREAT|O_EXCL),
  467. 0, hdl, data);
  468. }
  469. static inline bool check_version (struct shim_handle * hdl)
  470. {
  471. return atomic_read(&FILE_HANDLE_DATA(hdl)->version)
  472. == hdl->info.file.version;
  473. }
  474. static void chroot_update_size(struct shim_handle* hdl, struct shim_file_handle* file,
  475. struct shim_file_data* data) {
  476. if (check_version(hdl)) {
  477. off_t size;
  478. do {
  479. if ((size = atomic_read(&data->size)) >= file->size) {
  480. file->size = size;
  481. break;
  482. }
  483. } while ((off_t)atomic_cmpxchg(&data->size, size, file->size) != size);
  484. }
  485. }
  486. static int chroot_hstat (struct shim_handle * hdl, struct stat * stat)
  487. {
  488. int ret;
  489. if (NEED_RECREATE(hdl) && (ret = chroot_recreate(hdl)) < 0)
  490. return ret;
  491. if (!check_version(hdl) || !hdl->dentry) {
  492. struct shim_file_handle * file = &hdl->info.file;
  493. struct shim_dentry * dent = hdl->dentry;
  494. struct mount_data * mdata = dent ? DENTRY_MOUNT_DATA(dent) : NULL;
  495. if (dent)
  496. chroot_update_ino(dent);
  497. if (stat) {
  498. memset(stat, 0, sizeof(struct stat));
  499. stat->st_dev = mdata ? (dev_t) mdata->ino_base : 0;
  500. stat->st_ino = dent ? (ino_t) dent->ino : 0;
  501. stat->st_size = file->size;
  502. stat->st_mode |= (file->buf_type == FILEBUF_MAP) ? S_IFREG : S_IFCHR;
  503. }
  504. return 0;
  505. }
  506. return query_dentry(hdl->dentry, hdl->pal_handle, NULL, stat);
  507. }
  508. static void chroot_flush_map(struct shim_handle* hdl) {
  509. struct shim_file_handle* file = &hdl->info.file;
  510. if (file->buf_type == FILEBUF_MAP) {
  511. lock(&hdl->lock);
  512. void* mapbuf = file->mapbuf;
  513. size_t mapsize = file->mapsize;
  514. file->mapoffset = 0;
  515. file->mapbuf = NULL;
  516. unlock(&hdl->lock);
  517. if (mapbuf) {
  518. DkStreamUnmap(mapbuf, mapsize);
  519. if (bkeep_munmap(mapbuf, mapsize, VMA_INTERNAL) < 0)
  520. BUG();
  521. }
  522. }
  523. }
  524. static int chroot_flush(struct shim_handle* hdl) {
  525. int ret = DkStreamFlush(hdl->pal_handle);
  526. if (ret < 0)
  527. return ret;
  528. chroot_flush_map(hdl);
  529. return 0;
  530. }
  531. static int chroot_close(struct shim_handle* hdl) {
  532. chroot_flush_map(hdl);
  533. return 0;
  534. }
  535. static inline int __map_buffer (struct shim_handle * hdl, size_t size)
  536. {
  537. struct shim_file_handle * file = &hdl->info.file;
  538. if (file->mapbuf) {
  539. if (file->marker >= file->mapoffset &&
  540. file->marker + size <= file->mapoffset + file->mapsize)
  541. return 0;
  542. DkStreamUnmap(file->mapbuf, file->mapsize);
  543. if (bkeep_munmap(file->mapbuf, file->mapsize, VMA_INTERNAL) < 0)
  544. BUG();
  545. file->mapbuf = NULL;
  546. file->mapoffset = 0;
  547. }
  548. /* second, reallocate the buffer */
  549. size_t bufsize = file->mapsize ? : FILE_BUFMAP_SIZE;
  550. assert(IS_POWER_OF_2(bufsize));
  551. off_t mapoff = ALIGN_DOWN_POW2(file->marker, bufsize);
  552. size_t maplen = bufsize;
  553. int flags = MAP_FILE | MAP_PRIVATE | VMA_INTERNAL;
  554. int prot = PROT_READ;
  555. if (hdl->acc_mode & MAY_WRITE) {
  556. flags = MAP_FILE | MAP_SHARED | VMA_INTERNAL;
  557. prot |= PROT_WRITE;
  558. }
  559. while (mapoff + maplen < file->marker + size)
  560. maplen *= 2;
  561. /* Create the bookkeeping before allocating the memory. */
  562. void * mapbuf = bkeep_unmapped_any(maplen, prot, flags, mapoff, "filebuf");
  563. if (!mapbuf)
  564. return -ENOMEM;
  565. PAL_PTR mapped = DkStreamMap(hdl->pal_handle, mapbuf, PAL_PROT(prot, flags),
  566. mapoff, maplen);
  567. if (!mapped) {
  568. bkeep_munmap(mapbuf, maplen, flags);
  569. return -PAL_ERRNO;
  570. }
  571. assert((void*)mapped == mapbuf);
  572. file->mapbuf = mapbuf;
  573. file->mapoffset = mapoff;
  574. file->mapsize = maplen;
  575. return 0;
  576. }
  577. static ssize_t map_read (struct shim_handle * hdl, void * buf, size_t count)
  578. {
  579. struct shim_file_handle * file = &hdl->info.file;
  580. ssize_t ret = 0;
  581. lock(&hdl->lock);
  582. struct shim_file_data * data = FILE_HANDLE_DATA(hdl);
  583. off_t size = atomic_read(&data->size);
  584. if (check_version(hdl) &&
  585. file->size < size)
  586. file->size = size;
  587. off_t marker = file->marker;
  588. if (marker >= file->size) {
  589. count = 0;
  590. goto out;
  591. }
  592. if ((ret = __map_buffer(hdl, count)) < 0) {
  593. unlock(&hdl->lock);
  594. return ret;
  595. }
  596. size_t bytes_left;
  597. if (!__builtin_sub_overflow(file->size, marker, &bytes_left) && bytes_left < count)
  598. count = bytes_left;
  599. if (count) {
  600. memcpy(buf, file->mapbuf + (marker - file->mapoffset), count);
  601. file->marker = marker + count;
  602. }
  603. out:
  604. unlock(&hdl->lock);
  605. return count;
  606. }
  607. static ssize_t map_write (struct shim_handle * hdl, const void * buf, size_t count)
  608. {
  609. struct shim_file_handle * file = &hdl->info.file;
  610. ssize_t ret = 0;
  611. lock(&hdl->lock);
  612. struct shim_file_data * data = FILE_HANDLE_DATA(hdl);
  613. off_t marker = file->marker;
  614. off_t new_marker;
  615. if (__builtin_add_overflow(marker, count, &new_marker)) {
  616. // We can't handle this case reasonably.
  617. ret = -EFBIG;
  618. goto out;
  619. }
  620. if (new_marker > file->size) {
  621. file->size = new_marker;
  622. PAL_NUM pal_ret = DkStreamWrite(hdl->pal_handle, file->marker, count, (void *) buf, NULL);
  623. if (pal_ret == PAL_STREAM_ERROR) {
  624. ret = -PAL_ERRNO;
  625. goto out;
  626. }
  627. if (pal_ret < count) {
  628. file->size -= count - pal_ret;
  629. }
  630. chroot_update_size(hdl, file, data);
  631. if (__builtin_add_overflow(marker, pal_ret, &file->marker)) {
  632. // Should never happen. Even if it would, we couldn't recover from this condition.
  633. BUG();
  634. }
  635. ret = (ssize_t) pal_ret;
  636. goto out;
  637. }
  638. if ((ret = __map_buffer(hdl, count)) < 0)
  639. goto out;
  640. if (count) {
  641. memcpy(file->mapbuf + (marker - file->mapoffset), buf, count);
  642. file->marker = new_marker;
  643. }
  644. ret = count;
  645. out:
  646. unlock(&hdl->lock);
  647. return ret;
  648. }
  649. static ssize_t chroot_read (struct shim_handle * hdl, void * buf, size_t count)
  650. {
  651. ssize_t ret = 0;
  652. if (count == 0)
  653. goto out;
  654. if (NEED_RECREATE(hdl) && (ret = chroot_recreate(hdl)) < 0) {
  655. goto out;
  656. }
  657. if (!(hdl->acc_mode & MAY_READ)) {
  658. ret = -EBADF;
  659. goto out;
  660. }
  661. struct shim_file_handle * file = &hdl->info.file;
  662. off_t dummy_off_t;
  663. if (file->type != FILE_TTY && __builtin_add_overflow(file->marker, count, &dummy_off_t)) {
  664. ret = -EFBIG;
  665. goto out;
  666. }
  667. if (file->buf_type == FILEBUF_MAP) {
  668. ret = map_read(hdl, buf, count);
  669. if (ret != -EACCES)
  670. goto out;
  671. lock(&hdl->lock);
  672. file->buf_type = FILEBUF_NONE;
  673. } else {
  674. lock(&hdl->lock);
  675. }
  676. PAL_NUM pal_ret = DkStreamRead(hdl->pal_handle, file->marker, count, buf, NULL, 0);
  677. if (pal_ret != PAL_STREAM_ERROR) {
  678. if (__builtin_add_overflow(pal_ret, 0, &ret))
  679. BUG();
  680. if (file->type != FILE_TTY && __builtin_add_overflow(file->marker, pal_ret, &file->marker))
  681. BUG();
  682. } else {
  683. ret = PAL_NATIVE_ERRNO == PAL_ERROR_ENDOFSTREAM ? 0 : -PAL_ERRNO;
  684. }
  685. unlock(&hdl->lock);
  686. out:
  687. return ret;
  688. }
  689. static ssize_t chroot_write (struct shim_handle * hdl, const void * buf, size_t count)
  690. {
  691. ssize_t ret;
  692. if (count == 0)
  693. return 0;
  694. if (NEED_RECREATE(hdl) && (ret = chroot_recreate(hdl)) < 0) {
  695. goto out;
  696. }
  697. if (!(hdl->acc_mode & MAY_WRITE)) {
  698. ret = -EBADF;
  699. goto out;
  700. }
  701. struct shim_file_handle * file = &hdl->info.file;
  702. off_t dummy_off_t;
  703. if (file->type != FILE_TTY && __builtin_add_overflow(file->marker, count, &dummy_off_t)) {
  704. ret = -EFBIG;
  705. goto out;
  706. }
  707. if (hdl->info.file.buf_type == FILEBUF_MAP) {
  708. ret = map_write(hdl, buf, count);
  709. if (ret != -EACCES)
  710. goto out;
  711. lock(&hdl->lock);
  712. file->buf_type = FILEBUF_NONE;
  713. } else {
  714. lock(&hdl->lock);
  715. }
  716. PAL_NUM pal_ret = DkStreamWrite(hdl->pal_handle, file->marker, count, (void *) buf, NULL);
  717. if (pal_ret != PAL_STREAM_ERROR) {
  718. if (__builtin_add_overflow(pal_ret, 0, &ret))
  719. BUG();
  720. if (file->type != FILE_TTY && __builtin_add_overflow(file->marker, pal_ret, &file->marker))
  721. BUG();
  722. if (file->marker > file->size) {
  723. file->size = file->marker;
  724. chroot_update_size(hdl, file, FILE_HANDLE_DATA(hdl));
  725. }
  726. } else {
  727. ret = PAL_NATIVE_ERRNO == PAL_ERROR_ENDOFSTREAM ? 0 : -PAL_ERRNO;
  728. }
  729. unlock(&hdl->lock);
  730. out:
  731. return ret;
  732. }
  733. static int chroot_mmap (struct shim_handle * hdl, void ** addr, size_t size,
  734. int prot, int flags, off_t offset)
  735. {
  736. int ret;
  737. if (NEED_RECREATE(hdl) && (ret = chroot_recreate(hdl)) < 0)
  738. return ret;
  739. int pal_prot = PAL_PROT(prot, flags);
  740. #if MAP_FILE == 0
  741. if (flags & MAP_ANONYMOUS)
  742. #else
  743. if (!(flags & MAP_FILE))
  744. #endif
  745. return -EINVAL;
  746. void * alloc_addr =
  747. (void *) DkStreamMap(hdl->pal_handle, *addr, pal_prot, offset, size);
  748. if (!alloc_addr)
  749. return -PAL_ERRNO;
  750. *addr = alloc_addr;
  751. return 0;
  752. }
  753. static off_t chroot_seek (struct shim_handle * hdl, off_t offset, int wence)
  754. {
  755. off_t ret = -EINVAL;
  756. if (NEED_RECREATE(hdl) && (ret = chroot_recreate(hdl)) < 0)
  757. return ret;
  758. struct shim_file_handle * file = &hdl->info.file;
  759. lock(&hdl->lock);
  760. off_t marker = file->marker;
  761. off_t size = file->size;
  762. if (check_version(hdl)) {
  763. struct shim_file_data * data = FILE_HANDLE_DATA(hdl);
  764. if (data->type != FILE_REGULAR) {
  765. ret = -ESPIPE;
  766. goto out;
  767. }
  768. }
  769. switch (wence) {
  770. case SEEK_SET:
  771. if (offset < 0)
  772. goto out;
  773. marker = offset;
  774. break;
  775. case SEEK_CUR:
  776. marker += offset;
  777. break;
  778. case SEEK_END:
  779. marker = size + offset;
  780. break;
  781. }
  782. ret = file->marker = marker;
  783. out:
  784. unlock(&hdl->lock);
  785. return ret;
  786. }
  787. static int chroot_truncate (struct shim_handle * hdl, off_t len)
  788. {
  789. int ret = 0;
  790. if (NEED_RECREATE(hdl) && (ret = chroot_recreate(hdl)) < 0)
  791. return ret;
  792. if (!(hdl->acc_mode & MAY_WRITE))
  793. return -EINVAL;
  794. struct shim_file_handle * file = &hdl->info.file;
  795. lock(&hdl->lock);
  796. file->size = len;
  797. if (check_version(hdl)) {
  798. struct shim_file_data * data = FILE_HANDLE_DATA(hdl);
  799. atomic_set(&data->size, len);
  800. }
  801. PAL_NUM rv = DkStreamSetLength(hdl->pal_handle, len);
  802. if (rv) {
  803. // For an error, cast it back down to an int return code
  804. ret = -((int)rv);
  805. goto out;
  806. }
  807. // DEP 10/25/16: Truncate returns 0 on success, not the length
  808. ret = 0;
  809. if (file->marker > len)
  810. file->marker = len;
  811. out:
  812. unlock(&hdl->lock);
  813. return ret;
  814. }
  815. static int chroot_dput (struct shim_dentry * dent)
  816. {
  817. struct shim_file_data * data = FILE_DENTRY_DATA(dent);
  818. if (data) {
  819. __destroy_data(data);
  820. dent->data = NULL;
  821. }
  822. return 0;
  823. }
  824. static int chroot_readdir(struct shim_dentry* dent, struct shim_dirent** dirent) {
  825. struct shim_file_data* data = NULL;
  826. int ret = 0;
  827. PAL_HANDLE pal_hdl = NULL;
  828. size_t buf_size = MAX_PATH,
  829. dirent_buf_size = 0;
  830. char* buf = NULL;
  831. char* dirent_buf = NULL;
  832. if ((ret = try_create_data(dent, NULL, 0, &data)) < 0)
  833. return ret;
  834. chroot_update_ino(dent);
  835. const char* uri = qstrgetstr(&data->host_uri);
  836. assert(strstartswith_static(uri, URI_PREFIX_DIR));
  837. pal_hdl = DkStreamOpen(uri, PAL_ACCESS_RDONLY, 0, 0, 0);
  838. if (!pal_hdl)
  839. return -PAL_ERRNO;
  840. buf = malloc(buf_size);
  841. if (!buf) {
  842. ret = -ENOMEM;
  843. goto out;
  844. }
  845. while (1) {
  846. /* DkStreamRead for directory will return as many entries as fits into the buffer. */
  847. PAL_NUM bytes = DkStreamRead(pal_hdl, 0, buf_size, buf, NULL, 0);
  848. if (bytes == PAL_STREAM_ERROR) {
  849. if (PAL_NATIVE_ERRNO == PAL_ERROR_ENDOFSTREAM) {
  850. /* End of directory listing */
  851. ret = 0;
  852. break;
  853. }
  854. ret = -PAL_ERRNO;
  855. goto out;
  856. }
  857. /* Last entry must be null-terminated */
  858. assert(buf[bytes - 1] == '\0');
  859. size_t dirent_cur_off = dirent_buf_size;
  860. /* Calculate needed buffer size */
  861. size_t len = buf[0] != '\0' ? 1 : 0;
  862. for (size_t i = 1; i < bytes; i++) {
  863. if (buf[i] == '\0') {
  864. /* The PAL convention: if a name ends with '/', it is a directory.
  865. * struct shim_dirent has a field for a type, hence trailing slash
  866. * can be safely discarded. */
  867. if (buf[i - 1] == '/') {
  868. len--;
  869. }
  870. dirent_buf_size += SHIM_DIRENT_ALIGNED_SIZE(len + 1);
  871. len = 0;
  872. } else {
  873. len++;
  874. }
  875. }
  876. /* TODO: If realloc gets enabled delete following and uncomment rest */
  877. char* tmp = malloc(dirent_buf_size);
  878. if (!tmp) {
  879. ret = -ENOMEM;
  880. goto out;
  881. }
  882. memcpy(tmp, dirent_buf, dirent_cur_off);
  883. free(dirent_buf);
  884. dirent_buf = tmp;
  885. /*
  886. dirent_buf = realloc(dirent_buf, dirent_buf_size);
  887. if (!dirent_buf) {
  888. ret = -ENOMEM;
  889. goto out;
  890. }
  891. */
  892. size_t i = 0;
  893. while (i < bytes) {
  894. char* name = buf + i;
  895. size_t len = strnlen(name, bytes - i);
  896. i += len + 1;
  897. bool is_dir = false;
  898. /* Skipping trailing slash - explained above */
  899. if (name[len - 1] == '/') {
  900. is_dir = true;
  901. name[--len] = '\0';
  902. }
  903. struct shim_dirent* dptr = (struct shim_dirent*)(dirent_buf + dirent_cur_off);
  904. dptr->ino = rehash_name(dent->ino, name, len);
  905. dptr->type = is_dir ? LINUX_DT_DIR : LINUX_DT_REG;
  906. memcpy(dptr->name, name, len + 1);
  907. dirent_cur_off += SHIM_DIRENT_ALIGNED_SIZE(len + 1);
  908. }
  909. }
  910. *dirent = (struct shim_dirent*)dirent_buf;
  911. /*
  912. * Fix next field of struct shim_dirent to point to the next entry.
  913. * Since all entries are assumed to come from single allocation
  914. * (as free gets called just on the head of this list) this should have
  915. * been just entry size instead of a pointer (and probably needs to be
  916. * rewritten as such one day).
  917. */
  918. struct shim_dirent** last = NULL;
  919. for (size_t dirent_cur_off = 0; dirent_cur_off < dirent_buf_size; ) {
  920. struct shim_dirent* dptr = (struct shim_dirent*)(dirent_buf + dirent_cur_off);
  921. size_t len = SHIM_DIRENT_ALIGNED_SIZE(strlen(dptr->name) + 1);
  922. dptr->next = (struct shim_dirent*)(dirent_buf + dirent_cur_off + len);
  923. last = &dptr->next;
  924. dirent_cur_off += len;
  925. }
  926. if (last) {
  927. *last = NULL;
  928. }
  929. out:
  930. /* Need to free output buffer if error is returned */
  931. if (ret) {
  932. free(dirent_buf);
  933. }
  934. free(buf);
  935. DkObjectClose(pal_hdl);
  936. return ret;
  937. }
  938. static int chroot_checkout (struct shim_handle * hdl)
  939. {
  940. if (hdl->fs == &chroot_builtin_fs)
  941. hdl->fs = NULL;
  942. if (hdl->type == TYPE_FILE) {
  943. struct shim_file_data * data = FILE_HANDLE_DATA(hdl);
  944. if (data)
  945. hdl->info.file.data = NULL;
  946. }
  947. if (hdl->pal_handle) {
  948. /*
  949. * if the file still exists in the host, no need to send
  950. * the handle over RPC; otherwise, send it.
  951. */
  952. PAL_STREAM_ATTR attr;
  953. if (DkStreamAttributesQuery(qstrgetstr(&hdl->uri), &attr))
  954. hdl->pal_handle = NULL;
  955. }
  956. hdl->info.file.mapsize = 0;
  957. hdl->info.file.mapoffset = 0;
  958. hdl->info.file.mapbuf = NULL;
  959. return 0;
  960. }
  961. static ssize_t chroot_checkpoint (void ** checkpoint, void * mount_data)
  962. {
  963. struct mount_data * mdata = mount_data;
  964. *checkpoint = mount_data;
  965. return mdata->root_uri_len + sizeof(struct mount_data) + 1;
  966. }
  967. static int chroot_migrate (void * checkpoint, void ** mount_data)
  968. {
  969. struct mount_data * mdata = checkpoint;
  970. size_t alloc_len = mdata->root_uri_len + sizeof(struct mount_data) + 1;
  971. void * new_data = malloc(alloc_len);
  972. if (!new_data)
  973. return -ENOMEM;
  974. memcpy(new_data, mdata, alloc_len);
  975. *mount_data = new_data;
  976. return 0;
  977. }
  978. static int chroot_unlink (struct shim_dentry * dir, struct shim_dentry * dent)
  979. {
  980. int ret;
  981. struct shim_file_data * data;
  982. if ((ret = try_create_data(dent, NULL, 0, &data)) < 0)
  983. return ret;
  984. PAL_HANDLE pal_hdl = DkStreamOpen(qstrgetstr(&data->host_uri), 0, 0, 0, 0);
  985. if (!pal_hdl)
  986. return -PAL_ERRNO;
  987. DkStreamDelete(pal_hdl, 0);
  988. DkObjectClose(pal_hdl);
  989. dent->mode = NO_MODE;
  990. data->mode = 0;
  991. atomic_inc(&data->version);
  992. atomic_set(&data->size, 0);
  993. /* Drop the parent's link count */
  994. struct shim_file_data *parent_data = FILE_DENTRY_DATA(dir);
  995. if (parent_data) {
  996. lock(&parent_data->lock);
  997. if (parent_data->queried)
  998. parent_data->nlink--;
  999. unlock(&parent_data->lock);
  1000. }
  1001. return 0;
  1002. }
  1003. static off_t chroot_poll (struct shim_handle * hdl, int poll_type)
  1004. {
  1005. int ret;
  1006. if (NEED_RECREATE(hdl) && (ret = chroot_recreate(hdl)) < 0)
  1007. return ret;
  1008. struct shim_file_data * data = FILE_HANDLE_DATA(hdl);
  1009. off_t size = atomic_read(&data->size);
  1010. if (poll_type == FS_POLL_SZ)
  1011. return size;
  1012. lock(&hdl->lock);
  1013. struct shim_file_handle * file = &hdl->info.file;
  1014. if (check_version(hdl) &&
  1015. file->size < size)
  1016. file->size = size;
  1017. off_t marker = file->marker;
  1018. if (file->buf_type == FILEBUF_MAP) {
  1019. ret = poll_type & FS_POLL_WR;
  1020. if ((poll_type & FS_POLL_RD) && file->size > marker)
  1021. ret |= FS_POLL_RD;
  1022. goto out;
  1023. }
  1024. ret = -EAGAIN;
  1025. out:
  1026. unlock(&hdl->lock);
  1027. return ret;
  1028. }
  1029. static int chroot_rename(struct shim_dentry* old, struct shim_dentry* new) {
  1030. int ret;
  1031. struct shim_file_data* old_data;
  1032. if ((ret = try_create_data(old, NULL, 0, &old_data)) < 0) {
  1033. return ret;
  1034. }
  1035. struct shim_file_data* new_data;
  1036. if ((ret = try_create_data(new, NULL, 0, &new_data)) < 0) {
  1037. return ret;
  1038. }
  1039. PAL_HANDLE pal_hdl = DkStreamOpen(qstrgetstr(&old_data->host_uri), 0, 0, 0, 0);
  1040. if (!pal_hdl) {
  1041. return -PAL_ERRNO;
  1042. }
  1043. if (!DkStreamChangeName(pal_hdl, qstrgetstr(&new_data->host_uri))) {
  1044. DkObjectClose(pal_hdl);
  1045. return -PAL_ERRNO;
  1046. }
  1047. new->mode = new_data->mode = old_data->mode;
  1048. old->mode = NO_MODE;
  1049. old_data->mode = 0;
  1050. new->type = old->type;
  1051. DkObjectClose(pal_hdl);
  1052. atomic_inc(&old_data->version);
  1053. atomic_set(&old_data->size, 0);
  1054. atomic_inc(&new_data->version);
  1055. return 0;
  1056. }
  1057. static int chroot_chmod (struct shim_dentry * dent, mode_t mode)
  1058. {
  1059. int ret;
  1060. struct shim_file_data * data;
  1061. if ((ret = try_create_data(dent, NULL, 0, &data)) < 0)
  1062. return ret;
  1063. PAL_HANDLE pal_hdl = DkStreamOpen(qstrgetstr(&data->host_uri), 0, 0, 0, 0);
  1064. if (!pal_hdl)
  1065. return -PAL_ERRNO;
  1066. PAL_STREAM_ATTR attr = { .share_flags = mode };
  1067. if (!DkStreamAttributesSetByHandle(pal_hdl, &attr)) {
  1068. DkObjectClose(pal_hdl);
  1069. return -PAL_ERRNO;
  1070. }
  1071. DkObjectClose(pal_hdl);
  1072. dent->mode = data->mode = mode;
  1073. return 0;
  1074. }
  1075. struct shim_fs_ops chroot_fs_ops = {
  1076. .mount = &chroot_mount,
  1077. .unmount = &chroot_unmount,
  1078. .flush = &chroot_flush,
  1079. .close = &chroot_close,
  1080. .read = &chroot_read,
  1081. .write = &chroot_write,
  1082. .mmap = &chroot_mmap,
  1083. .seek = &chroot_seek,
  1084. .hstat = &chroot_hstat,
  1085. .truncate = &chroot_truncate,
  1086. .checkout = &chroot_checkout,
  1087. .checkpoint = &chroot_checkpoint,
  1088. .migrate = &chroot_migrate,
  1089. .poll = &chroot_poll,
  1090. };
  1091. struct shim_d_ops chroot_d_ops = {
  1092. .open = &chroot_open,
  1093. .mode = &chroot_mode,
  1094. .lookup = &chroot_lookup,
  1095. .creat = &chroot_creat,
  1096. .mkdir = &chroot_mkdir,
  1097. .stat = &chroot_stat,
  1098. .dput = &chroot_dput,
  1099. .readdir = &chroot_readdir,
  1100. .unlink = &chroot_unlink,
  1101. .rename = &chroot_rename,
  1102. .chmod = &chroot_chmod,
  1103. };
  1104. struct mount_data chroot_data = { .root_uri_len = 5,
  1105. .root_uri = URI_PREFIX_FILE, };
  1106. struct shim_mount chroot_builtin_fs = { .type = "chroot",
  1107. .fs_ops = &chroot_fs_ops,
  1108. .d_ops = &chroot_d_ops,
  1109. .data = &chroot_data, };